• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #define MKID(a, b, c, d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
20 
21 #define ID_LSTAT_V1 MKID('S', 'T', 'A', 'T')
22 #define ID_STAT_V2 MKID('S', 'T', 'A', '2')
23 #define ID_LSTAT_V2 MKID('L', 'S', 'T', '2')
24 
25 #define ID_LIST_V1 MKID('L', 'I', 'S', 'T')
26 #define ID_LIST_V2 MKID('L', 'I', 'S', '2')
27 #define ID_DENT_V1 MKID('D', 'E', 'N', 'T')
28 #define ID_DENT_V2 MKID('D', 'N', 'T', '2')
29 
30 #define ID_SEND_V1 MKID('S', 'E', 'N', 'D')
31 #define ID_SEND_V2 MKID('S', 'N', 'D', '2')
32 #define ID_RECV_V1 MKID('R', 'E', 'C', 'V')
33 #define ID_RECV_V2 MKID('R', 'C', 'V', '2')
34 #define ID_DONE MKID('D', 'O', 'N', 'E')
35 #define ID_DATA MKID('D', 'A', 'T', 'A')
36 #define ID_OKAY MKID('O', 'K', 'A', 'Y')
37 #define ID_FAIL MKID('F', 'A', 'I', 'L')
38 #define ID_QUIT MKID('Q', 'U', 'I', 'T')
39 
40 struct SyncRequest {
41     uint32_t id;           // ID_STAT, et cetera.
42     uint32_t path_length;  // <= 1024
43     // Followed by 'path_length' bytes of path (not NUL-terminated).
44 } __attribute__((packed));
45 
46 struct __attribute__((packed)) sync_stat_v1 {
47     uint32_t id;
48     uint32_t mode;
49     uint32_t size;
50     uint32_t mtime;
51 };
52 
53 struct __attribute__((packed)) sync_stat_v2 {
54     uint32_t id;
55     uint32_t error;
56     uint64_t dev;
57     uint64_t ino;
58     uint32_t mode;
59     uint32_t nlink;
60     uint32_t uid;
61     uint32_t gid;
62     uint64_t size;
63     int64_t atime;
64     int64_t mtime;
65     int64_t ctime;
66 };
67 
68 struct __attribute__((packed)) sync_dent_v1 {
69     uint32_t id;
70     uint32_t mode;
71     uint32_t size;
72     uint32_t mtime;
73     uint32_t namelen;
74 };  // followed by `namelen` bytes of the name.
75 
76 struct __attribute__((packed)) sync_dent_v2 {
77     uint32_t id;
78     uint32_t error;
79     uint64_t dev;
80     uint64_t ino;
81     uint32_t mode;
82     uint32_t nlink;
83     uint32_t uid;
84     uint32_t gid;
85     uint64_t size;
86     int64_t atime;
87     int64_t mtime;
88     int64_t ctime;
89     uint32_t namelen;
90 };  // followed by `namelen` bytes of the name.
91 
92 enum SyncFlag : uint32_t {
93     kSyncFlagNone = 0,
94     kSyncFlagBrotli = 1,
95 };
96 
97 // send_v1 sent the path in a buffer, followed by a comma and the mode as a string.
98 // send_v2 sends just the path in the first request, and then sends another syncmsg (with the
99 // same ID!) with details.
100 struct __attribute__((packed)) sync_send_v2 {
101     uint32_t id;
102     uint32_t mode;
103     uint32_t flags;
104 };
105 
106 // Likewise, recv_v1 just sent the path without any accompanying data.
107 struct __attribute__((packed)) sync_recv_v2 {
108     uint32_t id;
109     uint32_t flags;
110 };
111 
112 struct __attribute__((packed)) sync_data {
113     uint32_t id;
114     uint32_t size;
115 };  // followed by `size` bytes of data.
116 
117 struct __attribute__((packed)) sync_status {
118     uint32_t id;
119     uint32_t msglen;
120 };  // followed by `msglen` bytes of error message, if id == ID_FAIL.
121 
122 union syncmsg {
123     sync_stat_v1 stat_v1;
124     sync_stat_v2 stat_v2;
125     sync_dent_v1 dent_v1;
126     sync_dent_v2 dent_v2;
127     sync_data data;
128     sync_status status;
129     sync_send_v2 send_v2_setup;
130     sync_recv_v2 recv_v2_setup;
131 };
132 
133 #define SYNC_DATA_MAX (64 * 1024)
134