The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | c5a12b2 | 2015-04-21 10:17:07 -0700 | [diff] [blame] | 20 | #include <string> |
Josh Gao | 5d093b2 | 2015-10-30 16:57:19 -0700 | [diff] [blame] | 21 | #include <vector> |
Elliott Hughes | c5a12b2 | 2015-04-21 10:17:07 -0700 | [diff] [blame] | 22 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 | #define MKID(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 25 | #define ID_LSTAT_V1 MKID('S','T','A','T') |
| 26 | #define ID_STAT_V2 MKID('S','T','A','2') |
| 27 | #define ID_LSTAT_V2 MKID('L','S','T','2') |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 28 | #define ID_LIST MKID('L','I','S','T') |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 29 | #define ID_SEND MKID('S','E','N','D') |
| 30 | #define ID_RECV MKID('R','E','C','V') |
| 31 | #define ID_DENT MKID('D','E','N','T') |
| 32 | #define ID_DONE MKID('D','O','N','E') |
| 33 | #define ID_DATA MKID('D','A','T','A') |
| 34 | #define ID_OKAY MKID('O','K','A','Y') |
| 35 | #define ID_FAIL MKID('F','A','I','L') |
| 36 | #define ID_QUIT MKID('Q','U','I','T') |
| 37 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 38 | struct SyncRequest { |
| 39 | uint32_t id; // ID_STAT, et cetera. |
| 40 | uint32_t path_length; // <= 1024 |
| 41 | // Followed by 'path_length' bytes of path (not NUL-terminated). |
| 42 | } __attribute__((packed)) ; |
| 43 | |
Elliott Hughes | fe7ff81 | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 44 | union syncmsg { |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 45 | struct __attribute__((packed)) { |
Josh Gao | c1ad2a1 | 2016-02-19 13:41:33 -0800 | [diff] [blame] | 46 | uint32_t id; |
| 47 | uint32_t mode; |
| 48 | uint32_t size; |
| 49 | uint32_t time; |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 50 | } stat_v1; |
| 51 | struct __attribute__((packed)) { |
| 52 | uint32_t id; |
| 53 | uint32_t error; |
| 54 | uint64_t dev; |
| 55 | uint64_t ino; |
| 56 | uint32_t mode; |
| 57 | uint32_t nlink; |
| 58 | uint32_t uid; |
| 59 | uint32_t gid; |
| 60 | uint64_t size; |
| 61 | int64_t atime; |
| 62 | int64_t mtime; |
| 63 | int64_t ctime; |
| 64 | } stat_v2; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 65 | struct __attribute__((packed)) { |
Josh Gao | c1ad2a1 | 2016-02-19 13:41:33 -0800 | [diff] [blame] | 66 | uint32_t id; |
| 67 | uint32_t mode; |
| 68 | uint32_t size; |
| 69 | uint32_t time; |
| 70 | uint32_t namelen; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 71 | } dent; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 72 | struct __attribute__((packed)) { |
Josh Gao | c1ad2a1 | 2016-02-19 13:41:33 -0800 | [diff] [blame] | 73 | uint32_t id; |
| 74 | uint32_t size; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 75 | } data; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 76 | struct __attribute__((packed)) { |
Josh Gao | c1ad2a1 | 2016-02-19 13:41:33 -0800 | [diff] [blame] | 77 | uint32_t id; |
| 78 | uint32_t msglen; |
Mark Lindner | 9f9d145 | 2014-03-11 17:55:59 -0700 | [diff] [blame] | 79 | } status; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 80 | }; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 81 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 82 | void file_sync_service(int fd, void* cookie); |
| 83 | bool do_sync_ls(const char* path); |
Josh Gao | 5d093b2 | 2015-10-30 16:57:19 -0700 | [diff] [blame] | 84 | bool do_sync_push(const std::vector<const char*>& srcs, const char* dst); |
| 85 | bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, |
Felipe Leme | b644703 | 2016-04-01 17:43:27 -0700 | [diff] [blame] | 86 | bool copy_attrs, const char* name=nullptr); |
Josh Gao | 5d093b2 | 2015-10-30 16:57:19 -0700 | [diff] [blame] | 87 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 88 | bool do_sync_sync(const std::string& lpath, const std::string& rpath, bool list_only); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 89 | |
| 90 | #define SYNC_DATA_MAX (64*1024) |
| 91 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 92 | #endif |