blob: 73b9989126c0ed7981e5162a75bffe47b494a298 [file] [log] [blame]
Joe Onorato8d626d62009-05-15 09:07:06 -04001/*
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 Onorato0c4863b2009-05-05 11:50:51 -070017#ifndef _UTILS_BACKUP_HELPERS_H
18#define _UTILS_BACKUP_HELPERS_H
19
Joe Onorato8d626d62009-05-15 09:07:06 -040020#include <utils/Errors.h>
21#include <utils/String8.h>
22
23namespace android {
24
Joe Onoratoc7bbc692009-05-13 18:57:29 -040025int back_up_files(int oldSnapshotFD, int oldDataStream, int newSnapshotFD,
Joe Onorato0c4863b2009-05-05 11:50:51 -070026 char const* fileBase, char const* const* files, int fileCount);
27
Joe Onorato8d626d62009-05-15 09:07:06 -040028/**
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 */
34class BackupDataWriter
35{
36public:
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
48private:
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 Onorato2a98fb92009-05-06 12:55:46 -040058#define TEST_BACKUP_HELPERS 0
Joe Onorato0c4863b2009-05-05 11:50:51 -070059
60#if TEST_BACKUP_HELPERS
61int backup_helper_test_empty();
62int backup_helper_test_four();
63int backup_helper_test_files();
Joe Onorato8d626d62009-05-15 09:07:06 -040064int backup_helper_test_data_writer();
Joe Onorato0c4863b2009-05-05 11:50:51 -070065#endif
66
Joe Onorato8d626d62009-05-15 09:07:06 -040067} // namespace android
68
Joe Onorato0c4863b2009-05-05 11:50:51 -070069#endif // _UTILS_BACKUP_HELPERS_H