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