From 52ed26a78b77e559555622a006f888a70cd84a0a Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 22 Jun 2009 02:35:32 -0700 Subject: fix warnings that will show up with GCC 4.4 (in master) --- include/utils/ResourceTypes.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include/utils') diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index 68f9233261..f1029b7bc1 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -71,7 +71,7 @@ namespace android { * The relative sizes of the stretchy segments indicates the relative * amount of stretchiness of the regions bordered by the segments. For * example, regions 3, 7 and 11 above will take up more horizontal space - * than regions 1, 5 and 9 since the horizonal segment associated with + * than regions 1, 5 and 9 since the horizontal segment associated with * the first set of regions is larger than the other set of regions. The * ratios of the amount of horizontal (or vertical) space taken by any * two stretchable slices is exactly the ratio of their corresponding @@ -87,7 +87,7 @@ namespace android { * the leftmost slices always start at x=0 and the rightmost slices * always end at the end of the image. So, for example, the regions 0, * 4 and 8 (which are fixed along the X axis) start at x value 0 and - * go to xDiv[0] amd slices 2, 6 and 10 start at xDiv[1] and end at + * go to xDiv[0] and slices 2, 6 and 10 start at xDiv[1] and end at * xDiv[2]. * * The array pointed to by the colors field lists contains hints for @@ -626,25 +626,25 @@ public: event_code_t next(); // These are available for all nodes: - const int32_t getCommentID() const; + int32_t getCommentID() const; const uint16_t* getComment(size_t* outLen) const; - const uint32_t getLineNumber() const; + uint32_t getLineNumber() const; // This is available for TEXT: - const int32_t getTextID() const; + int32_t getTextID() const; const uint16_t* getText(size_t* outLen) const; ssize_t getTextValue(Res_value* outValue) const; // These are available for START_NAMESPACE and END_NAMESPACE: - const int32_t getNamespacePrefixID() const; + int32_t getNamespacePrefixID() const; const uint16_t* getNamespacePrefix(size_t* outLen) const; - const int32_t getNamespaceUriID() const; + int32_t getNamespaceUriID() const; const uint16_t* getNamespaceUri(size_t* outLen) const; // These are available for START_TAG and END_TAG: - const int32_t getElementNamespaceID() const; + int32_t getElementNamespaceID() const; const uint16_t* getElementNamespace(size_t* outLen) const; - const int32_t getElementNameID() const; + int32_t getElementNameID() const; const uint16_t* getElementName(size_t* outLen) const; // Remaining methods are for retrieving information about attributes @@ -653,14 +653,14 @@ public: size_t getAttributeCount() const; // Returns -1 if no namespace, -2 if idx out of range. - const int32_t getAttributeNamespaceID(size_t idx) const; + int32_t getAttributeNamespaceID(size_t idx) const; const uint16_t* getAttributeNamespace(size_t idx, size_t* outLen) const; - const int32_t getAttributeNameID(size_t idx) const; + int32_t getAttributeNameID(size_t idx) const; const uint16_t* getAttributeName(size_t idx, size_t* outLen) const; - const uint32_t getAttributeNameResID(size_t idx) const; + uint32_t getAttributeNameResID(size_t idx) const; - const int32_t getAttributeValueStringID(size_t idx) const; + int32_t getAttributeValueStringID(size_t idx) const; const uint16_t* getAttributeStringValue(size_t idx, size_t* outLen) const; int32_t getAttributeDataType(size_t idx) const; -- cgit v1.2.3-59-g8ed1b From 9cda3e02c6154422abec1c3215b93cc6bb70d76a Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Thu, 18 Jun 2009 20:10:37 -0700 Subject: Helper API cleanup. Allows multiple helpers to function, because they'll always go in the same order, and this lets us not have to write headers to keep them paired. --- include/utils/BackupHelpers.h | 3 +++ libs/utils/BackupData.cpp | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'include/utils') diff --git a/include/utils/BackupHelpers.h b/include/utils/BackupHelpers.h index c78b99a8dc..a21359f55e 100644 --- a/include/utils/BackupHelpers.h +++ b/include/utils/BackupHelpers.h @@ -71,6 +71,8 @@ public: status_t WriteEntityHeader(const String8& key, size_t dataSize); status_t WriteEntityData(const void* data, size_t size); + void SetKeyPrefix(const String8& keyPrefix); + private: explicit BackupDataWriter(); status_t write_padding_for(int n); @@ -79,6 +81,7 @@ private: status_t m_status; ssize_t m_pos; int m_entityCount; + String8 m_keyPrefix; }; /** diff --git a/libs/utils/BackupData.cpp b/libs/utils/BackupData.cpp index 6a7f056464..0868cff6c1 100644 --- a/libs/utils/BackupData.cpp +++ b/libs/utils/BackupData.cpp @@ -99,10 +99,20 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize) return amt; } + String8 k; + if (m_keyPrefix.length() > 0) { + k = m_keyPrefix; + k += ":"; + k += key; + } else { + k = key; + } + LOGD("m_keyPrefix=%s key=%s k=%s", m_keyPrefix.string(), key.string(), k.string()); + entity_header_v1 header; ssize_t keyLen; - keyLen = key.length(); + keyLen = k.length(); header.type = tolel(BACKUP_HEADER_ENTITY_V1); header.keyLen = tolel(keyLen); @@ -115,7 +125,7 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize) } m_pos += amt; - amt = write(m_fd, key.string(), keyLen+1); + amt = write(m_fd, k.string(), keyLen+1); if (amt != keyLen+1) { m_status = errno; return m_status; @@ -148,6 +158,11 @@ BackupDataWriter::WriteEntityData(const void* data, size_t size) return NO_ERROR; } +void +BackupDataWriter::SetKeyPrefix(const String8& keyPrefix) +{ + m_keyPrefix = keyPrefix; +} BackupDataReader::BackupDataReader(int fd) @@ -298,7 +313,7 @@ BackupDataReader::ReadEntityData(void* data, size_t size) if (remaining <= 0) { return 0; } - if (size > remaining) { + if (((int)size) > remaining) { size = remaining; } //LOGD(" reading %d bytes", size); -- cgit v1.2.3-59-g8ed1b From ab2e9e81e187d427b22ac969f47900d3de041264 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 23 Jun 2009 13:03:00 -0700 Subject: Add file mode to the file-backup saved state blobs This change puts the file's access mode into the saved-state blob used by the file backup helpers. The tests have been updated for the new blob content format. What this change *doesn't* do is actually backup/restore the file mode. This change is a prerequisite for that, but mode preservation in backup/restore will require adding metadata to the backup data stream itself, so will be approached a bit more carefully. (Also fixed one outright bug in the test program: ReadEntityData() had been changed to return a ssize_t union of either a byte-count or a negative number indicating error, but the test program was still assuming that nonzero == error, and was spuriously failing.) --- include/utils/BackupHelpers.h | 1 + libs/utils/BackupHelpers.cpp | 73 +++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 31 deletions(-) (limited to 'include/utils') diff --git a/include/utils/BackupHelpers.h b/include/utils/BackupHelpers.h index a21359f55e..759a0cc6d5 100644 --- a/include/utils/BackupHelpers.h +++ b/include/utils/BackupHelpers.h @@ -43,6 +43,7 @@ struct SnapshotHeader { struct FileState { int modTime_sec; int modTime_nsec; + int mode; int size; int crc32; int nameLen; diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp index d65a457f39..67d07fed85 100644 --- a/libs/utils/BackupHelpers.cpp +++ b/libs/utils/BackupHelpers.cpp @@ -302,6 +302,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD r.s.modTime_sec = st.st_mtime; r.s.modTime_nsec = 0; // workaround sim breakage //r.s.modTime_nsec = st.st_mtime_nsec; + r.s.mode = st.st_mode; r.s.size = st.st_size; // we compute the crc32 later down below, when we already have the file open. @@ -349,12 +350,12 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD g.s.crc32 = compute_crc32(fd); LOGP("%s", q.string()); - LOGP(" new: modTime=%d,%d size=%-3d crc32=0x%08x", - f.modTime_sec, f.modTime_nsec, f.size, f.crc32); - LOGP(" old: modTime=%d,%d size=%-3d crc32=0x%08x", - g.s.modTime_sec, g.s.modTime_nsec, g.s.size, g.s.crc32); + LOGP(" new: modTime=%d,%d mode=%04o size=%-3d crc32=0x%08x", + f.modTime_sec, f.modTime_nsec, f.mode, f.size, f.crc32); + LOGP(" old: modTime=%d,%d mode=%04o size=%-3d crc32=0x%08x", + g.s.modTime_sec, g.s.modTime_nsec, g.s.mode, g.s.size, g.s.crc32); if (f.modTime_sec != g.s.modTime_sec || f.modTime_nsec != g.s.modTime_nsec - || f.size != g.s.size || f.crc32 != g.s.crc32) { + || f.mode != g.s.mode || f.size != g.s.size || f.crc32 != g.s.crc32) { write_update_file(dataStream, fd, p, g.file.string()); } @@ -450,6 +451,7 @@ RestoreHelperBase::WriteFile(const String8& filename, BackupDataReader* in) r.s.modTime_sec = st.st_mtime; r.s.modTime_nsec = 0; // workaround sim breakage //r.s.modTime_nsec = st.st_mtime_nsec; + r.s.mode = st.st_mode; r.s.size = st.st_size; r.s.crc32 = crc; @@ -623,6 +625,7 @@ backup_helper_test_four() states[0].modTime_sec = 0xfedcba98; states[0].modTime_nsec = 0xdeadbeef; + states[0].mode = 0777; // decimal 511, hex 0x000001ff states[0].size = 0xababbcbc; states[0].crc32 = 0x12345678; states[0].nameLen = -12; @@ -632,6 +635,7 @@ backup_helper_test_four() states[1].modTime_sec = 0x93400031; states[1].modTime_nsec = 0xdeadbeef; + states[1].mode = 0666; // decimal 438, hex 0x000001b6 states[1].size = 0x88557766; states[1].crc32 = 0x22334422; states[1].nameLen = -1; @@ -641,6 +645,7 @@ backup_helper_test_four() states[2].modTime_sec = 0x33221144; states[2].modTime_nsec = 0xdeadbeef; + states[2].mode = 0744; // decimal 484, hex 0x000001e4 states[2].size = 0x11223344; states[2].crc32 = 0x01122334; states[2].nameLen = 0; @@ -650,6 +655,7 @@ backup_helper_test_four() states[3].modTime_sec = 0x33221144; states[3].modTime_nsec = 0xdeadbeef; + states[3].mode = 0755; // decimal 493, hex 0x000001ed states[3].size = 0x11223344; states[3].crc32 = 0x01122334; states[3].nameLen = 0; @@ -669,35 +675,38 @@ backup_helper_test_four() static const unsigned char correct_data[] = { // header 0x53, 0x6e, 0x61, 0x70, 0x04, 0x00, 0x00, 0x00, - 0x46, 0x69, 0x6c, 0x65, 0xac, 0x00, 0x00, 0x00, + 0x46, 0x69, 0x6c, 0x65, 0xbc, 0x00, 0x00, 0x00, // bytes_of_padding 0x98, 0xba, 0xdc, 0xfe, 0xef, 0xbe, 0xad, 0xde, - 0xbc, 0xbc, 0xab, 0xab, 0x78, 0x56, 0x34, 0x12, - 0x10, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64, - 0x64, 0x69, 0x6e, 0x67, + 0xff, 0x01, 0x00, 0x00, 0xbc, 0xbc, 0xab, 0xab, + 0x78, 0x56, 0x34, 0x12, 0x10, 0x00, 0x00, 0x00, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6f, 0x66, + 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, // bytes_of_padding3 0x31, 0x00, 0x40, 0x93, 0xef, 0xbe, 0xad, 0xde, - 0x66, 0x77, 0x55, 0x88, 0x22, 0x44, 0x33, 0x22, - 0x11, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64, - 0x64, 0x69, 0x6e, 0x67, 0x33, 0xab, 0xab, 0xab, + 0xb6, 0x01, 0x00, 0x00, 0x66, 0x77, 0x55, 0x88, + 0x22, 0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6f, 0x66, + 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, + 0x33, 0xab, 0xab, 0xab, // bytes of padding2 0x44, 0x11, 0x22, 0x33, 0xef, 0xbe, 0xad, 0xde, - 0x44, 0x33, 0x22, 0x11, 0x34, 0x23, 0x12, 0x01, - 0x12, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64, - 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x32, 0xab, 0xab, + 0xe4, 0x01, 0x00, 0x00, 0x44, 0x33, 0x22, 0x11, + 0x34, 0x23, 0x12, 0x01, 0x12, 0x00, 0x00, 0x00, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6f, 0x66, + 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, + 0x5f, 0x32, 0xab, 0xab, // bytes of padding3 0x44, 0x11, 0x22, 0x33, 0xef, 0xbe, 0xad, 0xde, - 0x44, 0x33, 0x22, 0x11, 0x34, 0x23, 0x12, 0x01, - 0x13, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64, - 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x5f, 0x31, 0xab + 0xed, 0x01, 0x00, 0x00, 0x44, 0x33, 0x22, 0x11, + 0x34, 0x23, 0x12, 0x01, 0x13, 0x00, 0x00, 0x00, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6f, 0x66, + 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, + 0x5f, 0x5f, 0x31, 0xab }; err = compare_file(filename, correct_data, sizeof(correct_data)); @@ -731,14 +740,14 @@ backup_helper_test_four() const FileState state = readSnapshot.valueAt(i); if (name != filenames[i] || states[i].modTime_sec != state.modTime_sec - || states[i].modTime_nsec != state.modTime_nsec + || states[i].modTime_nsec != state.modTime_nsec || states[i].mode != state.mode || states[i].size != state.size || states[i].crc32 != states[i].crc32) { - fprintf(stderr, "state %d expected={%d/%d, 0x%08x, 0x%08x, %3d} '%s'\n" - " actual={%d/%d, 0x%08x, 0x%08x, %3d} '%s'\n", i, - states[i].modTime_sec, states[i].modTime_nsec, states[i].size, states[i].crc32, - name.length(), filenames[i].string(), - state.modTime_sec, state.modTime_nsec, state.size, state.crc32, state.nameLen, - name.string()); + fprintf(stderr, "state %d expected={%d/%d, 0x%08x, %04o, 0x%08x, %3d} '%s'\n" + " actual={%d/%d, 0x%08x, %04o, 0x%08x, %3d} '%s'\n", i, + states[i].modTime_sec, states[i].modTime_nsec, states[i].mode, states[i].size, + states[i].crc32, name.length(), filenames[i].string(), + state.modTime_sec, state.modTime_nsec, state.mode, state.size, state.crc32, + state.nameLen, name.string()); matched = false; } } @@ -839,6 +848,7 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str) size_t actualSize; bool done; int type; + ssize_t nRead; // printf("\n\n---------- test_read_header_and_entity -- %s\n\n", str); @@ -873,8 +883,9 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str) goto finished; } - err = reader.ReadEntityData(buf, bufSize); - if (err != NO_ERROR) { + nRead = reader.ReadEntityData(buf, bufSize); + if (nRead < 0) { + err = reader.Status(); fprintf(stderr, "ReadEntityData failed with %s\n", strerror(err)); goto finished; } -- cgit v1.2.3-59-g8ed1b From bd95c1d3af82e329ada195876348383b7859ce85 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 24 Jun 2009 13:57:29 -0700 Subject: Only report "unknown metadata" once per restore helper Also removes the auto-free object, replacing it with direct memory manipulation. --- include/utils/BackupHelpers.h | 1 + libs/utils/BackupHelpers.cpp | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'include/utils') diff --git a/include/utils/BackupHelpers.h b/include/utils/BackupHelpers.h index 759a0cc6d5..b1f504512f 100644 --- a/include/utils/BackupHelpers.h +++ b/include/utils/BackupHelpers.h @@ -137,6 +137,7 @@ public: private: void* m_buf; + bool m_loggedUnknownMetadata; KeyedVector m_files; }; diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp index b309dbf43e..99a4abcb6e 100644 --- a/libs/utils/BackupHelpers.cpp +++ b/libs/utils/BackupHelpers.cpp @@ -68,15 +68,6 @@ struct file_metadata_v1 { const static int CURRENT_METADATA_VERSION = 1; -// auto-free buffer management object -class StAutoFree { -public: - StAutoFree(void* buffer) { mBuf = buffer; } - ~StAutoFree() { free(mBuf); } -private: - void* mBuf; -}; - #if 1 // TEST_BACKUP_HELPERS #define LOGP(f, x...) printf(f "\n", x) #else @@ -230,8 +221,6 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& file_metadata_v1 metadata; char* buf = (char*)malloc(bufsize); - StAutoFree _autoFree(buf); - int crc = crc32(0L, Z_NULL, 0); @@ -245,6 +234,7 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& bytesLeft = fileSize + sizeof(metadata); err = dataStream->WriteEntityHeader(key, bytesLeft); if (err != 0) { + free(buf); return err; } @@ -254,6 +244,7 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& metadata.undefined_1 = metadata.undefined_2 = 0; err = dataStream->WriteEntityData(&metadata, sizeof(metadata)); if (err != 0) { + free(buf); return err; } bytesLeft -= sizeof(metadata); // bytesLeft should == fileSize now @@ -266,6 +257,7 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& } err = dataStream->WriteEntityData(buf, amt); if (err != 0) { + free(buf); return err; } } @@ -279,6 +271,7 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& bytesLeft -= amt; err = dataStream->WriteEntityData(buf, amt); if (err != 0) { + free(buf); return err; } } @@ -287,6 +280,7 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& " You aren't doing proper locking!", realFilename, fileSize, fileSize-bytesLeft); } + free(buf); return NO_ERROR; } @@ -318,8 +312,6 @@ compute_crc32(int fd) int amt; char* buf = (char*)malloc(bufsize); - StAutoFree _autoFree(buf); - int crc = crc32(0L, Z_NULL, 0); lseek(fd, 0, SEEK_SET); @@ -328,6 +320,7 @@ compute_crc32(int fd) crc = crc32(crc, (Bytef*)buf, amt); } + free(buf); return crc; } @@ -451,6 +444,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD RestoreHelperBase::RestoreHelperBase() { m_buf = malloc(RESTORE_BUF_SIZE); + m_loggedUnknownMetadata = false; } RestoreHelperBase::~RestoreHelperBase() @@ -489,8 +483,11 @@ RestoreHelperBase::WriteFile(const String8& filename, BackupDataReader* in) metadata.version = fromlel(metadata.version); metadata.mode = fromlel(metadata.mode); if (metadata.version > CURRENT_METADATA_VERSION) { - LOGW("Restoring file with unsupported metadata version %d (currently %d)", - metadata.version, CURRENT_METADATA_VERSION); + if (!m_loggedUnknownMetadata) { + m_loggedUnknownMetadata = true; + LOGW("Restoring file with unsupported metadata version %d (currently %d)", + metadata.version, CURRENT_METADATA_VERSION); + } } mode = metadata.mode; @@ -587,7 +584,6 @@ compare_file(const char* path, const unsigned char* data, int len) fprintf(stderr, "malloc(%d) failed\n", len); return ENOMEM; } - StAutoFree _autoFree(contents); bool sizesMatch = true; amt = lseek(fd, 0, SEEK_END); @@ -614,6 +610,7 @@ compare_file(const char* path, const unsigned char* data, int len) } } + free(contents); return contentsMatch && sizesMatch ? 0 : 1; } @@ -919,7 +916,6 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str) int err; int bufSize = strlen(str)+1; char* buf = (char*)malloc(bufSize); - StAutoFree _autoFree(buf); String8 string; int cookie = 0x11111111; size_t actualSize; @@ -981,6 +977,7 @@ finished: if (err != NO_ERROR) { fprintf(stderr, "test_read_header_and_entity failed with %s\n", strerror(err)); } + free(buf); return err; } -- cgit v1.2.3-59-g8ed1b