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