Joe Onorato | 8d626d6 | 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 | 0c4863b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 17 | #ifndef _UTILS_BACKUP_HELPERS_H |
| 18 | #define _UTILS_BACKUP_HELPERS_H |
| 19 | |
Joe Onorato | 8d626d6 | 2009-05-15 09:07:06 -0400 | [diff] [blame^] | 20 | #include <utils/Errors.h> |
| 21 | #include <utils/String8.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
Joe Onorato | c7bbc69 | 2009-05-13 18:57:29 -0400 | [diff] [blame] | 25 | int back_up_files(int oldSnapshotFD, int oldDataStream, int newSnapshotFD, |
Joe Onorato | 0c4863b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 26 | char const* fileBase, char const* const* files, int fileCount); |
| 27 | |
Joe Onorato | 8d626d6 | 2009-05-15 09:07:06 -0400 | [diff] [blame^] | 28 | /** |
| 29 | * Reads the data. |
| 30 | * |
| 31 | * If an error occurs, it poisons this object and all write calls will fail |
| 32 | * with the error that occurred. |
| 33 | */ |
| 34 | class BackupDataWriter |
| 35 | { |
| 36 | public: |
| 37 | BackupDataWriter(int fd); |
| 38 | // does not close fd |
| 39 | ~BackupDataWriter(); |
| 40 | |
| 41 | status_t WriteAppHeader(const String8& packageName); |
| 42 | |
| 43 | status_t WriteEntityHeader(const String8& key, size_t dataSize); |
| 44 | status_t WriteEntityData(const void* data, size_t size); |
| 45 | |
| 46 | status_t WriteAppFooter(); |
| 47 | |
| 48 | private: |
| 49 | explicit BackupDataWriter(); |
| 50 | status_t write_padding_for(int n); |
| 51 | |
| 52 | int m_fd; |
| 53 | status_t m_status; |
| 54 | ssize_t m_pos; |
| 55 | int m_entityCount; |
| 56 | }; |
| 57 | |
Joe Onorato | 2a98fb9 | 2009-05-06 12:55:46 -0400 | [diff] [blame] | 58 | #define TEST_BACKUP_HELPERS 0 |
Joe Onorato | 0c4863b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 59 | |
| 60 | #if TEST_BACKUP_HELPERS |
| 61 | int backup_helper_test_empty(); |
| 62 | int backup_helper_test_four(); |
| 63 | int backup_helper_test_files(); |
Joe Onorato | 8d626d6 | 2009-05-15 09:07:06 -0400 | [diff] [blame^] | 64 | int backup_helper_test_data_writer(); |
Joe Onorato | 0c4863b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 65 | #endif |
| 66 | |
Joe Onorato | 8d626d6 | 2009-05-15 09:07:06 -0400 | [diff] [blame^] | 67 | } // namespace android |
| 68 | |
Joe Onorato | 0c4863b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 69 | #endif // _UTILS_BACKUP_HELPERS_H |