blob: 87ede0c0c631773d0c8d6a9d8b276221da499ec6 [file] [log] [blame]
Josh Gaoc7b74592018-07-25 15:55:25 -07001/*
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')
Josh Gao7b083072019-08-07 14:23:17 -070024
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
Josh Gaoc7b74592018-07-25 15:55:25 -070030#define ID_SEND MKID('S', 'E', 'N', 'D')
31#define ID_RECV MKID('R', 'E', 'C', 'V')
Josh Gaoc7b74592018-07-25 15:55:25 -070032#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
38struct 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
Josh Gaoe08589f2020-03-19 17:13:52 -070044struct __attribute__((packed)) sync_stat_v1 {
45 uint32_t id;
46 uint32_t mode;
47 uint32_t size;
48 uint32_t mtime;
49};
50
51struct __attribute__((packed)) sync_stat_v2 {
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};
65
66struct __attribute__((packed)) sync_dent_v1 {
67 uint32_t id;
68 uint32_t mode;
69 uint32_t size;
70 uint32_t mtime;
71 uint32_t namelen;
72}; // followed by `namelen` bytes of the name.
73
74struct __attribute__((packed)) sync_dent_v2 {
75 uint32_t id;
76 uint32_t error;
77 uint64_t dev;
78 uint64_t ino;
79 uint32_t mode;
80 uint32_t nlink;
81 uint32_t uid;
82 uint32_t gid;
83 uint64_t size;
84 int64_t atime;
85 int64_t mtime;
86 int64_t ctime;
87 uint32_t namelen;
88}; // followed by `namelen` bytes of the name.
89
90struct __attribute__((packed)) sync_data {
91 uint32_t id;
92 uint32_t size;
93}; // followed by `size` bytes of data.
94
95struct __attribute__((packed)) sync_status {
96 uint32_t id;
97 uint32_t msglen;
98}; // followed by `msglen` bytes of error message, if id == ID_FAIL.
99
Josh Gaoc7b74592018-07-25 15:55:25 -0700100union syncmsg {
Josh Gaoe08589f2020-03-19 17:13:52 -0700101 sync_stat_v1 stat_v1;
102 sync_stat_v2 stat_v2;
103 sync_dent_v1 dent_v1;
104 sync_dent_v2 dent_v2;
105 sync_data data;
106 sync_status status;
Josh Gaoc7b74592018-07-25 15:55:25 -0700107};
108
109#define SYNC_DATA_MAX (64 * 1024)