Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 17 | #define LOG_TAG "backup_data" |
| 18 | |
Mathias Agopian | 8ae2335 | 2009-06-04 13:53:57 -0700 | [diff] [blame] | 19 | #include <utils/BackupHelpers.h> |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 20 | #include <utils/ByteOrder.h> |
| 21 | |
| 22 | #include <stdio.h> |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 23 | #include <string.h> |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 26 | #include <cutils/log.h> |
| 27 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 30 | static const bool DEBUG = false; |
| 31 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 32 | /* |
| 33 | * File Format (v1): |
| 34 | * |
| 35 | * All ints are stored little-endian. |
| 36 | * |
| 37 | * - An app_header_v1 struct. |
| 38 | * - The name of the package, utf-8, null terminated, padded to 4-byte boundary. |
| 39 | * - A sequence of zero or more key/value paires (entities), each with |
| 40 | * - A entity_header_v1 struct |
| 41 | * - The key, utf-8, null terminated, padded to 4-byte boundary. |
| 42 | * - The value, padded to 4 byte boundary |
| 43 | */ |
| 44 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 45 | const static int ROUND_UP[4] = { 0, 3, 2, 1 }; |
| 46 | |
| 47 | static inline size_t |
| 48 | round_up(size_t n) |
| 49 | { |
| 50 | return n + ROUND_UP[n % 4]; |
| 51 | } |
| 52 | |
| 53 | static inline size_t |
| 54 | padding_extra(size_t n) |
| 55 | { |
| 56 | return ROUND_UP[n % 4]; |
| 57 | } |
| 58 | |
| 59 | BackupDataWriter::BackupDataWriter(int fd) |
| 60 | :m_fd(fd), |
| 61 | m_status(NO_ERROR), |
| 62 | m_pos(0), |
| 63 | m_entityCount(0) |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | BackupDataWriter::~BackupDataWriter() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | // Pad out anything they've previously written to the next 4 byte boundary. |
| 72 | status_t |
| 73 | BackupDataWriter::write_padding_for(int n) |
| 74 | { |
| 75 | ssize_t amt; |
| 76 | ssize_t paddingSize; |
| 77 | |
| 78 | paddingSize = padding_extra(n); |
| 79 | if (paddingSize > 0) { |
| 80 | uint32_t padding = 0xbcbcbcbc; |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 81 | if (DEBUG) LOGI("writing %d padding bytes for %d", paddingSize, n); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 82 | amt = write(m_fd, &padding, paddingSize); |
| 83 | if (amt != paddingSize) { |
| 84 | m_status = errno; |
| 85 | return m_status; |
| 86 | } |
| 87 | m_pos += amt; |
| 88 | } |
| 89 | return NO_ERROR; |
| 90 | } |
| 91 | |
| 92 | status_t |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 93 | BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize) |
| 94 | { |
| 95 | if (m_status != NO_ERROR) { |
| 96 | return m_status; |
| 97 | } |
| 98 | |
| 99 | ssize_t amt; |
| 100 | |
| 101 | amt = write_padding_for(m_pos); |
| 102 | if (amt != 0) { |
| 103 | return amt; |
| 104 | } |
| 105 | |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 106 | String8 k; |
| 107 | if (m_keyPrefix.length() > 0) { |
| 108 | k = m_keyPrefix; |
| 109 | k += ":"; |
| 110 | k += key; |
| 111 | } else { |
| 112 | k = key; |
| 113 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 114 | if (DEBUG) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 115 | ALOGD("Writing header: prefix='%s' key='%s' dataSize=%d", m_keyPrefix.string(), |
| 116 | key.string(), dataSize); |
Joe Onorato | 568bc32 | 2009-06-26 17:19:11 -0400 | [diff] [blame] | 117 | } |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 118 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 119 | entity_header_v1 header; |
| 120 | ssize_t keyLen; |
| 121 | |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 122 | keyLen = k.length(); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 123 | |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 124 | header.type = tolel(BACKUP_HEADER_ENTITY_V1); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 125 | header.keyLen = tolel(keyLen); |
| 126 | header.dataSize = tolel(dataSize); |
| 127 | |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 128 | if (DEBUG) LOGI("writing entity header, %d bytes", sizeof(entity_header_v1)); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 129 | amt = write(m_fd, &header, sizeof(entity_header_v1)); |
| 130 | if (amt != sizeof(entity_header_v1)) { |
| 131 | m_status = errno; |
| 132 | return m_status; |
| 133 | } |
| 134 | m_pos += amt; |
| 135 | |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 136 | if (DEBUG) LOGI("writing entity header key, %d bytes", keyLen+1); |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 137 | amt = write(m_fd, k.string(), keyLen+1); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 138 | if (amt != keyLen+1) { |
| 139 | m_status = errno; |
| 140 | return m_status; |
| 141 | } |
| 142 | m_pos += amt; |
| 143 | |
| 144 | amt = write_padding_for(keyLen+1); |
| 145 | |
| 146 | m_entityCount++; |
| 147 | |
| 148 | return amt; |
| 149 | } |
| 150 | |
| 151 | status_t |
| 152 | BackupDataWriter::WriteEntityData(const void* data, size_t size) |
| 153 | { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 154 | if (DEBUG) ALOGD("Writing data: size=%lu", (unsigned long) size); |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 155 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 156 | if (m_status != NO_ERROR) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 157 | if (DEBUG) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 158 | ALOGD("Not writing data - stream in error state %d (%s)", m_status, strerror(m_status)); |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 159 | } |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 160 | return m_status; |
| 161 | } |
| 162 | |
| 163 | // We don't write padding here, because they're allowed to call this several |
| 164 | // times with smaller buffers. We write it at the end of WriteEntityHeader |
| 165 | // instead. |
| 166 | ssize_t amt = write(m_fd, data, size); |
| 167 | if (amt != (ssize_t)size) { |
| 168 | m_status = errno; |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 169 | if (DEBUG) ALOGD("write returned error %d (%s)", m_status, strerror(m_status)); |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 170 | return m_status; |
| 171 | } |
| 172 | m_pos += amt; |
| 173 | return NO_ERROR; |
| 174 | } |
| 175 | |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 176 | void |
| 177 | BackupDataWriter::SetKeyPrefix(const String8& keyPrefix) |
| 178 | { |
| 179 | m_keyPrefix = keyPrefix; |
| 180 | } |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 181 | |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 182 | |
| 183 | BackupDataReader::BackupDataReader(int fd) |
| 184 | :m_fd(fd), |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 185 | m_done(false), |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 186 | m_status(NO_ERROR), |
| 187 | m_pos(0), |
| 188 | m_entityCount(0) |
| 189 | { |
| 190 | memset(&m_header, 0, sizeof(m_header)); |
| 191 | } |
| 192 | |
| 193 | BackupDataReader::~BackupDataReader() |
| 194 | { |
| 195 | } |
| 196 | |
| 197 | status_t |
| 198 | BackupDataReader::Status() |
| 199 | { |
| 200 | return m_status; |
| 201 | } |
| 202 | |
| 203 | #define CHECK_SIZE(actual, expected) \ |
| 204 | do { \ |
| 205 | if ((actual) != (expected)) { \ |
| 206 | if ((actual) == 0) { \ |
| 207 | m_status = EIO; \ |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 208 | m_done = true; \ |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 209 | } else { \ |
| 210 | m_status = errno; \ |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 211 | ALOGD("CHECK_SIZE(a=%ld e=%ld) failed at line %d m_status='%s'", \ |
Christopher Tate | 4cc86e1 | 2009-09-21 19:36:51 -0700 | [diff] [blame] | 212 | long(actual), long(expected), __LINE__, strerror(m_status)); \ |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 213 | } \ |
| 214 | return m_status; \ |
| 215 | } \ |
| 216 | } while(0) |
| 217 | #define SKIP_PADDING() \ |
| 218 | do { \ |
| 219 | status_t err = skip_padding(); \ |
| 220 | if (err != NO_ERROR) { \ |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 221 | ALOGD("SKIP_PADDING FAILED at line %d", __LINE__); \ |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 222 | m_status = err; \ |
| 223 | return err; \ |
| 224 | } \ |
| 225 | } while(0) |
| 226 | |
| 227 | status_t |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 228 | BackupDataReader::ReadNextHeader(bool* done, int* type) |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 229 | { |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 230 | *done = m_done; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 231 | if (m_status != NO_ERROR) { |
| 232 | return m_status; |
| 233 | } |
| 234 | |
| 235 | int amt; |
| 236 | |
Joe Onorato | 8d72569 | 2009-07-28 18:23:05 -0700 | [diff] [blame] | 237 | amt = skip_padding(); |
| 238 | if (amt == EIO) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 239 | *done = m_done = true; |
Joe Onorato | 8d72569 | 2009-07-28 18:23:05 -0700 | [diff] [blame] | 240 | return NO_ERROR; |
| 241 | } |
| 242 | else if (amt != NO_ERROR) { |
| 243 | return amt; |
| 244 | } |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 245 | amt = read(m_fd, &m_header, sizeof(m_header)); |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 246 | *done = m_done = (amt == 0); |
Joe Onorato | 8d72569 | 2009-07-28 18:23:05 -0700 | [diff] [blame] | 247 | if (*done) { |
| 248 | return NO_ERROR; |
| 249 | } |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 250 | CHECK_SIZE(amt, sizeof(m_header)); |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 251 | m_pos += sizeof(m_header); |
| 252 | if (type) { |
| 253 | *type = m_header.type; |
| 254 | } |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 255 | |
| 256 | // validate and fix up the fields. |
| 257 | m_header.type = fromlel(m_header.type); |
| 258 | switch (m_header.type) |
| 259 | { |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 260 | case BACKUP_HEADER_ENTITY_V1: |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 261 | { |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 262 | m_header.entity.keyLen = fromlel(m_header.entity.keyLen); |
| 263 | if (m_header.entity.keyLen <= 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 264 | ALOGD("Entity header at %d has keyLen<=0: 0x%08x\n", (int)m_pos, |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 265 | (int)m_header.entity.keyLen); |
| 266 | m_status = EINVAL; |
| 267 | } |
| 268 | m_header.entity.dataSize = fromlel(m_header.entity.dataSize); |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 269 | m_entityCount++; |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 270 | |
| 271 | // read the rest of the header (filename) |
| 272 | size_t size = m_header.entity.keyLen; |
| 273 | char* buf = m_key.lockBuffer(size); |
| 274 | if (buf == NULL) { |
| 275 | m_status = ENOMEM; |
| 276 | return m_status; |
| 277 | } |
| 278 | int amt = read(m_fd, buf, size+1); |
| 279 | CHECK_SIZE(amt, (int)size+1); |
| 280 | m_key.unlockBuffer(size); |
| 281 | m_pos += size+1; |
| 282 | SKIP_PADDING(); |
| 283 | m_dataEndPos = m_pos + m_header.entity.dataSize; |
| 284 | |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 285 | break; |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 286 | } |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 287 | default: |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 288 | ALOGD("Chunk header at %d has invalid type: 0x%08x", |
Christopher Tate | 28cdb9e | 2011-06-24 15:06:48 -0700 | [diff] [blame] | 289 | (int)(m_pos - sizeof(m_header)), (int)m_header.type); |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 290 | m_status = EINVAL; |
| 291 | } |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 292 | |
| 293 | return m_status; |
| 294 | } |
| 295 | |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 296 | bool |
| 297 | BackupDataReader::HasEntities() |
| 298 | { |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 299 | return m_status == NO_ERROR && m_header.type == BACKUP_HEADER_ENTITY_V1; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | status_t |
| 303 | BackupDataReader::ReadEntityHeader(String8* key, size_t* dataSize) |
| 304 | { |
| 305 | if (m_status != NO_ERROR) { |
| 306 | return m_status; |
| 307 | } |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 308 | if (m_header.type != BACKUP_HEADER_ENTITY_V1) { |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 309 | return EINVAL; |
| 310 | } |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 311 | *key = m_key; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 312 | *dataSize = m_header.entity.dataSize; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 313 | return NO_ERROR; |
| 314 | } |
| 315 | |
| 316 | status_t |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 317 | BackupDataReader::SkipEntityData() |
| 318 | { |
| 319 | if (m_status != NO_ERROR) { |
| 320 | return m_status; |
| 321 | } |
| 322 | if (m_header.type != BACKUP_HEADER_ENTITY_V1) { |
| 323 | return EINVAL; |
| 324 | } |
| 325 | if (m_header.entity.dataSize > 0) { |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 326 | int pos = lseek(m_fd, m_dataEndPos, SEEK_SET); |
Joe Onorato | ee5bbb7 | 2009-07-13 14:44:07 -0700 | [diff] [blame] | 327 | if (pos == -1) { |
| 328 | return errno; |
| 329 | } |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 330 | } |
Joe Onorato | ee5bbb7 | 2009-07-13 14:44:07 -0700 | [diff] [blame] | 331 | SKIP_PADDING(); |
| 332 | return NO_ERROR; |
Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Joe Onorato | efd0fab | 2009-06-17 16:20:55 -0700 | [diff] [blame] | 335 | ssize_t |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 336 | BackupDataReader::ReadEntityData(void* data, size_t size) |
| 337 | { |
| 338 | if (m_status != NO_ERROR) { |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 339 | return -1; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 340 | } |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 341 | int remaining = m_dataEndPos - m_pos; |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 342 | //ALOGD("ReadEntityData size=%d m_pos=0x%x m_dataEndPos=0x%x remaining=%d\n", |
Joe Onorato | efd0fab | 2009-06-17 16:20:55 -0700 | [diff] [blame] | 343 | // size, m_pos, m_dataEndPos, remaining); |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 344 | if (remaining <= 0) { |
| 345 | return 0; |
| 346 | } |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 347 | if (((int)size) > remaining) { |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 348 | size = remaining; |
| 349 | } |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 350 | //ALOGD(" reading %d bytes", size); |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 351 | int amt = read(m_fd, data, size); |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 352 | if (amt < 0) { |
| 353 | m_status = errno; |
| 354 | return -1; |
| 355 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 356 | if (amt == 0) { |
| 357 | m_status = EIO; |
| 358 | m_done = true; |
| 359 | } |
Joe Onorato | 5d605dc | 2009-06-18 18:23:43 -0700 | [diff] [blame] | 360 | m_pos += amt; |
Joe Onorato | efd0fab | 2009-06-17 16:20:55 -0700 | [diff] [blame] | 361 | return amt; |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | status_t |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 365 | BackupDataReader::skip_padding() |
| 366 | { |
| 367 | ssize_t amt; |
| 368 | ssize_t paddingSize; |
| 369 | |
| 370 | paddingSize = padding_extra(m_pos); |
| 371 | if (paddingSize > 0) { |
| 372 | uint32_t padding; |
| 373 | amt = read(m_fd, &padding, paddingSize); |
| 374 | CHECK_SIZE(amt, paddingSize); |
| 375 | m_pos += amt; |
| 376 | } |
| 377 | return NO_ERROR; |
| 378 | } |
| 379 | |
| 380 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 381 | } // namespace android |