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