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