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