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