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