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