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