Debian Codegraph @

compat/include/bsdcompat.h

raw symbols SCIP
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <[email protected]>, 1994-1997
5 * Stelian Pop <[email protected]>, 1999-2000
6 * Stelian Pop <[email protected]> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 */
8
9 #include "config.h" // IWYU pragma: keep
10 #include <sys/time.h>
11 #include <dirent.h>
12
13 #ifdef HAVE_STDINT_H
14 #include <stdint.h>
15 #endif
16 #ifdef HAVE_INTTYPES_H
17 #include <inttypes.h>
18 #endif
19
20 #ifdef HAVE_EXT2FS_EXT2_FS_H
21 #include <ext2fs/ext2_fs.h>
22 #else
23 #include <linux/ext2_fs.h>
24 #endif
25 #include <ext2fs/ext2fs.h>
26
27 #ifndef _BSDCOMPAT_H
28 #define _BSDCOMPAT_H 1
29
30 #define UNUSED(x) x __attribute__ ((unused))
31
32 #ifndef NBBY
33 #define NBBY 8
34 #endif
35
36 #ifndef MIN
37 #define MIN(a,b) ((a < b) ? a : b)
38 #endif
39
40 #define WINO 1
41 #define DEV_BSIZE 512
42 #define DEV_BSHIFT 9
43
44 #define MAXBSIZE EXT2_MAX_BLOCK_SIZE
45 #define ROOTINO EXT2_ROOT_INO
46 #ifdef EXT2_NODUMP_FL
47 #define UF_NODUMP EXT2_NODUMP_FL
48 #endif
49
50 #ifndef howmany
51 #define howmany(x,y) (((x)+((y)-1))/(y))
52 #endif
53 #ifndef roundup
54 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
55 #endif
56 #ifndef powerof2
57 #define powerof2(x) ((((x)-1)&(x))==0)
58 #endif
59
60 #define fsbtodb(sb,b) ((ext2_loff_t)(((long long)(b) * EXT2_BLOCK_SIZE((sb)->super)) / DEV_BSIZE))
61 #define dbtofsb(sb,b) ((int)(((long long)(b) * DEV_BSIZE) / EXT2_BLOCK_SIZE((sb)->super)))
62
63 #define sblock fs
64 #define fs_fsize fragsize
65 #define fs_bsize blocksize
66 #define fs_size super->s_blocks_count
67
68 #define IFMT S_IFMT
69 #define IFLNK S_IFLNK
70 #define IFREG S_IFREG
71 #define IFDIR S_IFDIR
72 #define IFCHR S_IFCHR
73 #define IFBLK S_IFBLK
74 #define IFSOCK S_IFSOCK
75 #define IFIFO S_IFIFO
76
77 /*
78 * The BSD dump format reserves 4 bytes for a time_t, but other architectures
79 * (notably axp) have larger time_t. ctime4() is a modified ctime() which
80 * always accepts short 4-byte times.
81 */
82 #define ctime4(timep) ({ time_t t = *(timep); ctime(&t); })
83
84 /*
85 * This is the ext2_inode structure but the fields have been renamed
86 * to match 4.4BSD's names
87 */
88 #define NDADDR 12
89 #define NIADDR 3
90
91 #define NINDIR(fs) EXT2_ADDR_PER_BLOCK(fs->super)
92
93 // This structure is written to tape as part of u_spcl.s_spcl
94 struct dinode_tape {
95 __u16 di_mode;
96 __u16 di_uid;
97 __u32 di_size;
98 __u32 di_atime;
99 __u32 di_ctime;
100 __u32 di_mtime;
101 __u32 di_dtime;
102 __u16 di_gid;
103 __u16 di_nlink;
104 __u32 di_blocks;
105 __u32 di_flags;
106 __u32 di_reserved1;
107 __u32 di_db[NDADDR];
108 __u32 di_ib[NIADDR];
109 __u32 di_gen;
110 __u32 di_file_acl;
111 __u32 di_dir_acl;
112 __u32 di_faddr;
113 __u8 di_frag;
114 __u8 di_fsize;
115 __u16 di_pad1;
116 __u16 di_uidhigh;
117 __u16 di_gidhigh;
118 __u32 di_spare;
119 #if 0
120 // Added in 0.4b40 when EA support was added.
121 __u16 di_extraisize;
122 __u16 di_pad2;
123 #endif
124 };
125
126 /*
127 * This is the ext2_dir_entry structure but the fields have been renamed
128 * to match 4.4BSD's names
129 *
130 * This is the 4.4BSD directory entry structure
131 */
132 #define DIRBLKSIZ DEV_BSIZE
133 #ifndef MAXNAMLEN
134 #define MAXNAMLEN 255
135 #endif
136
137 /*
138 * For old libc.
139 */
140 #ifndef DT_UNKNOWN
141 #define DT_UNKNOWN 0
142 #define DT_FIFO 1
143 #define DT_CHR 2
144 #define DT_DIR 4
145 #define DT_BLK 6
146 #define DT_REG 8
147 #define DT_LNK 10
148 #define DT_SOCK 12
149
150 #endif
151
152 /*
153 * The direct structure used by dump/restore.
154 */
155 struct direct {
156 __u32 d_ino;
157 __u16 d_reclen;
158 __u8 d_type;
159 __u8 d_namlen;
160 char d_name[MAXNAMLEN + 1];
161 };
162
163 /*
164 * The DIRSIZ macro gives the minimum record length which will hold
165 * the directory entry. This requires the amount of space in struct direct
166 * without the d_name field, plus enough space for the name with a terminating
167 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
168 */
169 #define DIRSIZ(oldfmt,dp) EXT2_DIR_REC_LEN(((dp)->d_namlen & 0xff) + 1)
170
171 struct bsdtimeval { /* XXX alpha-*-linux is deviant */
172 __u32 tv_sec;
173 __u32 tv_usec;
174 };
175
176 /*
177 * This is the new (4.4) BSD inode structure
178 * copied from the FreeBSD 2.0 <ufs/ufs/dinode.h> include file
179 */
180 struct new_bsd_inode {
181 __u16 di_mode;
182 __s16 di_nlink;
183 union {
184 __u16 oldids[2];
185 __u32 inumber;
186 } di_u;
187 uint64_t di_size;
188 struct bsdtimeval di_atime;
189 struct bsdtimeval di_mtime;
190 struct bsdtimeval di_ctime;
191 __u32 di_db[NDADDR];
192 __u32 di_ib[NIADDR];
193 __u32 di_flags;
194 __s32 di_blocks;
195 __s32 di_gen;
196 __u32 di_uid;
197 __u32 di_gid;
198 __s32 di_spare[2];
199 };
200
201 #define di_ouid di_u.oldids[0]
202 #define di_ogid di_u.oldids[1]
203 #endif /* _BSDCOMPAT_H */