blob: 0e25974a161cf7a8afaf63cc7f4a75f34a52979a [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 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
17#ifndef _FILE_SYNC_SERVICE_H_
18#define _FILE_SYNC_SERVICE_H_
19
Elliott Hughesd236d072015-04-21 10:17:07 -070020#include <string>
Josh Gao05786772015-10-30 16:57:19 -070021#include <vector>
Elliott Hughesd236d072015-04-21 10:17:07 -070022
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023#define MKID(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080024
25#define ID_STAT MKID('S','T','A','T')
26#define ID_LIST MKID('L','I','S','T')
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080027#define ID_SEND MKID('S','E','N','D')
28#define ID_RECV MKID('R','E','C','V')
29#define ID_DENT MKID('D','E','N','T')
30#define ID_DONE MKID('D','O','N','E')
31#define ID_DATA MKID('D','A','T','A')
32#define ID_OKAY MKID('O','K','A','Y')
33#define ID_FAIL MKID('F','A','I','L')
34#define ID_QUIT MKID('Q','U','I','T')
35
Elliott Hughesaa245492015-08-03 10:38:08 -070036struct SyncRequest {
37 uint32_t id; // ID_STAT, et cetera.
38 uint32_t path_length; // <= 1024
39 // Followed by 'path_length' bytes of path (not NUL-terminated).
40} __attribute__((packed)) ;
41
Elliott Hughes2d4121c2015-04-17 09:47:42 -070042union syncmsg {
Elliott Hughesaa245492015-08-03 10:38:08 -070043 struct __attribute__((packed)) {
Josh Gao8d685912016-02-19 13:41:33 -080044 uint32_t id;
45 uint32_t mode;
46 uint32_t size;
47 uint32_t time;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048 } stat;
Elliott Hughesaa245492015-08-03 10:38:08 -070049 struct __attribute__((packed)) {
Josh Gao8d685912016-02-19 13:41:33 -080050 uint32_t id;
51 uint32_t mode;
52 uint32_t size;
53 uint32_t time;
54 uint32_t namelen;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080055 } dent;
Elliott Hughesaa245492015-08-03 10:38:08 -070056 struct __attribute__((packed)) {
Josh Gao8d685912016-02-19 13:41:33 -080057 uint32_t id;
58 uint32_t size;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059 } data;
Elliott Hughesaa245492015-08-03 10:38:08 -070060 struct __attribute__((packed)) {
Josh Gao8d685912016-02-19 13:41:33 -080061 uint32_t id;
62 uint32_t msglen;
Mark Lindner76f2a932014-03-11 17:55:59 -070063 } status;
Elliott Hughesaa245492015-08-03 10:38:08 -070064};
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065
Elliott Hughesaa245492015-08-03 10:38:08 -070066void file_sync_service(int fd, void* cookie);
67bool do_sync_ls(const char* path);
Josh Gao05786772015-10-30 16:57:19 -070068bool do_sync_push(const std::vector<const char*>& srcs, const char* dst);
69bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst,
Felipe Leme44a42672016-04-01 17:43:27 -070070 bool copy_attrs, const char* name=nullptr);
Josh Gao05786772015-10-30 16:57:19 -070071
Elliott Hughesaa245492015-08-03 10:38:08 -070072bool do_sync_sync(const std::string& lpath, const std::string& rpath, bool list_only);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080073
74#define SYNC_DATA_MAX (64*1024)
75
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080076#endif