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