]> git.wh0rd.org - dump.git/blob - compat/include/bsdcompat.h
Added EA/ACL support in dump and restore.
[dump.git] / compat / include / bsdcompat.h
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 *
8 * $Id: bsdcompat.h,v 1.24 2005/05/02 15:10:45 stelian Exp $
9 */
10
11 #include <config.h>
12 #include <sys/time.h>
13 #include <dirent.h>
14 #include <ext2fs/ext2fs.h>
15
16 #define __dead volatile
17 #define UNUSED(x) x __attribute__ ((unused))
18
19 #ifndef NBBY
20 #define NBBY 8
21 #endif
22
23 #ifndef MIN
24 #define MIN(a,b) ((a < b) ? a : b)
25 #endif
26
27 #define WINO 1
28 #define DEV_BSIZE 512
29 #define DEV_BSHIFT 9
30
31 #ifndef sunos
32 #define MAXBSIZE EXT2_MAX_BLOCK_SIZE
33 #define ROOTINO EXT2_ROOT_INO
34 #else
35 #define ROOTINO 2
36 #endif
37 #ifdef EXT2_NODUMP_FL
38 #define UF_NODUMP EXT2_NODUMP_FL
39 #endif
40
41 #ifndef howmany
42 #define howmany(x,y) (((x)+((y)-1))/(y))
43 #endif
44 #ifndef roundup
45 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
46 #endif
47 #ifndef powerof2
48 #define powerof2(x) ((((x)-1)&(x))==0)
49 #endif
50
51 #define fsbtodb(sb,b) ((ext2_loff_t)(((long long)(b) * EXT2_BLOCK_SIZE((sb)->super)) / DEV_BSIZE))
52 #define dbtofsb(sb,b) ((int)(((long long)(b) * DEV_BSIZE) / EXT2_BLOCK_SIZE((sb)->super)))
53
54 #define sblock fs
55 #define fs_fsize fragsize
56 #define fs_bsize blocksize
57 #define fs_size super->s_blocks_count
58
59 #define IFMT S_IFMT
60 #define IFLNK S_IFLNK
61 #define IFREG S_IFREG
62 #define IFDIR S_IFDIR
63 #define IFCHR S_IFCHR
64 #define IFBLK S_IFBLK
65 #define IFSOCK S_IFSOCK
66 #define IFIFO S_IFIFO
67
68 #if 0
69 typedef __s64 quad_t;
70 typedef __u64 u_quad_t;
71 #endif
72
73 /*
74 * The BSD dump format reserves 4 bytes for a time_t, but other architectures
75 * (notably axp) have larger time_t. ctime4() is a modified ctime() which
76 * always accepts short 4-byte times.
77 */
78 #define ctime4(timep) ({ time_t t = *(timep); ctime(&t); })
79
80 /*
81 * This is the ext2_inode structure but the fields have been renamed
82 * to match 4.4BSD's names
83 */
84 #define NDADDR 12
85 #define NIADDR 3
86
87 #define NINDIR(fs) EXT2_ADDR_PER_BLOCK(fs->super)
88
89 #ifdef sunos
90 typedef uint8_t __u8;
91 typedef uint16_t __u16;
92 typedef uint32_t __u32;
93 typedef int8_t __s8;
94 typedef int16_t __s16;
95 typedef int32_t __s32;
96 #ifndef u_int
97 typedef unsigned int u_int;
98 #endif
99 #ifndef u_int16_t
100 typedef unsigned short u_int16_t;
101 #endif
102 #ifndef u_char
103 typedef unsigned char u_char;
104 #endif
105 typedef int64_t quad_t;
106 #endif /* sunos */
107
108 struct dinode {
109 __u16 di_mode;
110 __u16 di_uid;
111 __u32 di_size;
112 __u32 di_atime;
113 __u32 di_ctime;
114 __u32 di_mtime;
115 __u32 di_dtime;
116 __u16 di_gid;
117 __u16 di_nlink;
118 __u32 di_blocks;
119 __u32 di_flags;
120 __u32 di_reserved1;
121 __u32 di_db[NDADDR];
122 __u32 di_ib[NIADDR];
123 __u32 di_gen;
124 __u32 di_file_acl;
125 __u32 di_dir_acl;
126 __u32 di_faddr;
127 __u8 di_frag;
128 __u8 di_fsize;
129 __u16 di_pad1;
130 __u16 di_uidhigh;
131 __u16 di_gidhigh;
132 __u32 di_spare;
133 __u16 di_extraisize;
134 __u16 di_pad2;
135 };
136
137 #define di_rdev di_db[0]
138 /* #define di_ouid di_uid */
139 /* #define di_ogid di_gid */
140 #define di_size_high di_dir_acl
141
142 /*
143 * This is the ext2_dir_entry structure but the fields have been renamed
144 * to match 4.4BSD's names
145 *
146 * This is the 4.4BSD directory entry structure
147 */
148 #define DIRBLKSIZ DEV_BSIZE
149 #ifndef MAXNAMLEN
150 #define MAXNAMLEN 255
151 #endif
152
153 #ifdef sunos
154 #define MAXNAMLEN 255
155 #endif
156
157 /*
158 * For old libc.
159 */
160 #ifndef DT_UNKNOWN
161 #define DT_UNKNOWN 0
162 #define DT_FIFO 1
163 #define DT_CHR 2
164 #define DT_DIR 4
165 #define DT_BLK 6
166 #define DT_REG 8
167 #define DT_LNK 10
168 #define DT_SOCK 12
169
170 #ifdef sunos
171 #define DT_WHT 14
172 #endif
173 #endif
174
175 #ifndef d_fileno
176 #define d_fileno d_ino
177 #endif
178
179 /*
180 * The direct structure used by dump/restore.
181 */
182 struct direct {
183 __u32 d_ino;
184 __u16 d_reclen;
185 __u8 d_type;
186 __u8 d_namlen;
187 char d_name[MAXNAMLEN + 1];
188 };
189 /*
190 * Convert between stat structure types and directory types.
191 */
192 #define IFTODT(mode) (((mode) & 0170000) >> 12)
193 #define DTTOIF(dirtype) ((dirtype) << 12)
194
195 /*
196 * The DIRSIZ macro gives the minimum record length which will hold
197 * the directory entry. This requires the amount of space in struct direct
198 * without the d_name field, plus enough space for the name with a terminating
199 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
200 */
201 #ifdef __linux__
202 #if 0
203 #if (BYTE_ORDER == LITTLE_ENDIAN)
204 #define DIRSIZ(oldfmt, dp) \
205 ((oldfmt) ? \
206 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
207 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
208 #else /* BYTE_ORDER */
209 #define DIRSIZ(oldfmt, dp) \
210 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
211 #endif
212 #else /* 0 */
213 #define DIRSIZ(oldfmt,dp) EXT2_DIR_REC_LEN(((dp)->d_namlen & 0xff) + 1)
214 #endif
215 #else /* __linux__ */
216 #define DIRSIZ(oldfmt, dp) \
217 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
218 #endif
219
220 /*
221 * This is the old (Net/2) BSD inode structure
222 * copied from the FreeBSD 1.1.5.1 <ufs/dinode.h> include file
223 */
224 #define MAXFASTLINK (((NDADDR + NIADDR) * sizeof(unsigned long)) - 1)
225
226 struct old_bsd_inode {
227 __u16 di_mode;
228 __s16 di_nlink;
229 __u16 di_uid;
230 __u16 di_gid;
231 #if 1
232 union {
233 u_quad_t v;
234 __u32 val[2];
235 } di_qsize;
236 #else
237 u_quad_t di_size;
238 #endif
239 __u32 di_atime;
240 __s32 di_atspare;
241 __u32 di_mtime;
242 __s32 di_mtspare;
243 __u32 di_ctime;
244 __s32 di_ctspare;
245 #if 0
246 union {
247 struct {
248 daddr_t di_udb[NDADDR];
249 daddr_t di_uib[NIADDR];
250 } di_addr;
251 char di_usymlink[MAXFASTLINK + 1];
252 } di_un;
253 #else
254 __u32 di_db[NDADDR];
255 __u32 di_ib[NIADDR];
256 #endif
257 __s32 di_flags;
258 __s32 di_blocks;
259 __s32 di_gen;
260 __u32 di_spare[4];
261 };
262
263 struct bsdtimeval { /* XXX alpha-*-linux is deviant */
264 __u32 tv_sec;
265 __u32 tv_usec;
266 };
267
268 /*
269 * This is the new (4.4) BSD inode structure
270 * copied from the FreeBSD 2.0 <ufs/ufs/dinode.h> include file
271 */
272 struct new_bsd_inode {
273 __u16 di_mode;
274 __s16 di_nlink;
275 union {
276 __u16 oldids[2];
277 __u32 inumber;
278 } di_u;
279 u_quad_t di_size;
280 struct bsdtimeval di_atime;
281 struct bsdtimeval di_mtime;
282 struct bsdtimeval di_ctime;
283 __u32 di_db[NDADDR];
284 __u32 di_ib[NIADDR];
285 __u32 di_flags;
286 __s32 di_blocks;
287 __s32 di_gen;
288 __u32 di_uid;
289 __u32 di_gid;
290 __s32 di_spare[2];
291 };
292
293 #define di_ouid di_u.oldids[0]
294 #define di_ogid di_u.oldids[1]