15 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
|
/* This file is from NetBSD. */ |
19 |
|
|
20 |
#ifndef _FS_EXT2FS_H |
#ifndef _FS_EXT2FS_H |
21 |
#define _FS_EXT2FS_H 1 |
#define _FS_EXT2FS_H 1 |
22 |
|
|
23 |
#include "vfs.h" |
#include "io-vfs.h" |
24 |
|
#include "io-vnode.h" |
25 |
|
|
26 |
/* |
/* Each disk drive contains some number of file systems. |
27 |
* Copyright (c) 1997 Manuel Bouyer. |
A file system consists of a number of cylinder groups. |
28 |
* Copyright (c) 1982, 1986, 1993 |
Each cylinder group has inodes and data. |
29 |
* The Regents of the University of California. All rights reserved. |
|
30 |
* |
A file system is described by its super-block, which in turn |
31 |
* Redistribution and use in source and binary forms, with or without |
describes the cylinder groups. The super-block is critical |
32 |
* modification, are permitted provided that the following conditions |
data and is replicated in each cylinder group to protect against |
33 |
* are met: |
catastrophic loss. This is done at `newfs' time and the critical |
34 |
* 1. Redistributions of source code must retain the above copyright |
super-block data does not change, so the copies need not be |
35 |
* notice, this list of conditions and the following disclaimer. |
referenced further unless disaster strikes. |
36 |
* 2. Redistributions in binary form must reproduce the above copyright |
|
37 |
* notice, this list of conditions and the following disclaimer in the |
The first boot and super blocks are given in absolute disk addresses. |
38 |
* documentation and/or other materials provided with the distribution. |
The byte-offset forms are preferred, as they don't imply a sector size. */ |
|
* 3. All advertising materials mentioning features or use of this software |
|
|
* must display the following acknowledgement: |
|
|
* This product includes software developed by the University of |
|
|
* California, Berkeley and its contributors. |
|
|
* 4. Neither the name of the University nor the names of its contributors |
|
|
* may be used to endorse or promote products derived from this software |
|
|
* without specific prior written permission. |
|
|
* |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
|
* SUCH DAMAGE. |
|
|
* |
|
|
* @(#)fs.h 8.10 (Berkeley) 10/27/94 |
|
|
* Modified for ext2fs by Manuel Bouyer. |
|
|
*/ |
|
39 |
|
|
|
/* |
|
|
* Each disk drive contains some number of file systems. |
|
|
* A file system consists of a number of cylinder groups. |
|
|
* Each cylinder group has inodes and data. |
|
|
* |
|
|
* A file system is described by its super-block, which in turn |
|
|
* describes the cylinder groups. The super-block is critical |
|
|
* data and is replicated in each cylinder group to protect against |
|
|
* catastrophic loss. This is done at `newfs' time and the critical |
|
|
* super-block data does not change, so the copies need not be |
|
|
* referenced further unless disaster strikes. |
|
|
* |
|
|
* The first boot and super blocks are given in absolute disk addresses. |
|
|
* The byte-offset forms are preferred, as they don't imply a sector size. |
|
|
*/ |
|
40 |
#define BBSIZE 1024 |
#define BBSIZE 1024 |
41 |
#define SBSIZE 1024 |
#define SBSIZE 1024 |
42 |
#define BBOFF ((off_t)(0)) |
#define BBOFF ((off_t)(0)) |
44 |
#define BBLOCK ((daddr_t)(0)) |
#define BBLOCK ((daddr_t)(0)) |
45 |
#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE)) |
#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE)) |
46 |
|
|
|
#ifndef ROOTINO /* XXX This was missing. */ |
|
47 |
#define ROOTINO ((ino_t)2) |
#define ROOTINO ((ino_t)2) |
|
#endif |
|
|
|
|
|
/* |
|
|
* Addresses stored in inodes are capable of addressing blocks |
|
|
* XXX |
|
|
*/ |
|
48 |
|
|
49 |
/* |
/* MINBSIZE is the smallest allowable block size. |
50 |
* MINBSIZE is the smallest allowable block size. |
MINBSIZE must be big enough to hold a cylinder group block, |
51 |
* MINBSIZE must be big enough to hold a cylinder group block, |
thus changes to (struct cg) must keep its size within MINBSIZE. |
52 |
* thus changes to (struct cg) must keep its size within MINBSIZE. |
Note that super blocks are always of size SBSIZE, |
53 |
* Note that super blocks are always of size SBSIZE, |
and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. */ |
|
* and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. |
|
|
*/ |
|
54 |
#define LOG_MINBSIZE 10 |
#define LOG_MINBSIZE 10 |
55 |
#define MINBSIZE (1 << LOG_MINBSIZE) |
#define MINBSIZE (1 << LOG_MINBSIZE) |
56 |
|
|
57 |
/* |
/* The path name on which the file system is mounted is maintained |
58 |
* The path name on which the file system is mounted is maintained |
in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in |
59 |
* in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in |
the super block for this name. */ |
|
* the super block for this name. |
|
|
*/ |
|
60 |
#define MAXMNTLEN 512 |
#define MAXMNTLEN 512 |
61 |
|
|
62 |
/* |
/* MINFREE gives the minimum acceptable percentage of file system |
63 |
* MINFREE gives the minimum acceptable percentage of file system |
blocks which may be free. If the freelist drops below this level |
64 |
* blocks which may be free. If the freelist drops below this level |
only the superuser may continue to allocate blocks. This may |
65 |
* only the superuser may continue to allocate blocks. This may |
be set to 0 if no reserve of free blocks is deemed necessary, |
66 |
* be set to 0 if no reserve of free blocks is deemed necessary, |
however throughput drops by fifty percent if the file system |
67 |
* however throughput drops by fifty percent if the file system |
is run at between 95% and 100% full; thus the minimum default |
68 |
* is run at between 95% and 100% full; thus the minimum default |
value of fs_minfree is 5%. However, to get good clustering |
69 |
* value of fs_minfree is 5%. However, to get good clustering |
performance, 10% is a better choice. hence we use 10% as our |
70 |
* performance, 10% is a better choice. hence we use 10% as our |
default value. With 10% free space, fragmentation is not a |
71 |
* default value. With 10% free space, fragmentation is not a |
problem, so we choose to optimize for time. */ |
|
* problem, so we choose to optimize for time. |
|
|
*/ |
|
72 |
#define MINFREE 5 |
#define MINFREE 5 |
73 |
|
|
74 |
/* |
|
75 |
* Super block for an ext2fs file system. |
/* Number of direct (and indirect) blocks in a disk inode. */ |
76 |
*/ |
#define NDIRECT 12 |
77 |
struct ext2fs { |
#define NINDIRECT 3 |
78 |
u_int32_t e2fs_icount; /* Inode count */ |
|
79 |
u_int32_t e2fs_bcount; /* blocks count */ |
/* Super block for an ext2fs file system. */ |
80 |
u_int32_t e2fs_rbcount; /* reserved blocks count */ |
struct ext2fs |
81 |
u_int32_t e2fs_fbcount; /* free blocks count */ |
{ |
82 |
u_int32_t e2fs_ficount; /* free inodes count */ |
u_int32_t e2fs_icount; /* Inode count */ |
83 |
u_int32_t e2fs_first_dblock; /* first data block */ |
u_int32_t e2fs_bcount; /* blocks count */ |
84 |
u_int32_t e2fs_log_bsize; /* block size = 1024*(2^e2fs_log_bsize) */ |
u_int32_t e2fs_rbcount; /* reserved blocks count */ |
85 |
u_int32_t e2fs_fsize; /* fragment size */ |
u_int32_t e2fs_fbcount; /* free blocks count */ |
86 |
u_int32_t e2fs_bpg; /* blocks per group */ |
u_int32_t e2fs_ficount; /* free inodes count */ |
87 |
u_int32_t e2fs_fpg; /* frags per group */ |
u_int32_t e2fs_first_dblock; /* first data block */ |
88 |
u_int32_t e2fs_ipg; /* inodes per group */ |
u_int32_t e2fs_log_bsize; /* block size = 1024*(2^e2fs_log_bsize) */ |
89 |
u_int32_t e2fs_mtime; /* mount time */ |
u_int32_t e2fs_fsize; /* fragment size */ |
90 |
u_int32_t e2fs_wtime; /* write time */ |
u_int32_t e2fs_bpg; /* blocks per group */ |
91 |
u_int16_t e2fs_mnt_count; /* mount count */ |
u_int32_t e2fs_fpg; /* frags per group */ |
92 |
u_int16_t e2fs_max_mnt_count; /* max mount count */ |
u_int32_t e2fs_ipg; /* inodes per group */ |
93 |
u_int16_t e2fs_magic; /* magic number */ |
u_int32_t e2fs_mtime; /* mount time */ |
94 |
u_int16_t e2fs_state; /* file system state */ |
u_int32_t e2fs_wtime; /* write time */ |
95 |
u_int16_t e2fs_beh; /* behavior on errors */ |
u_int16_t e2fs_mnt_count; /* mount count */ |
96 |
u_int16_t reserved; |
u_int16_t e2fs_max_mnt_count; /* max mount count */ |
97 |
u_int32_t e2fs_lastfsck; /* time of last fsck */ |
u_int16_t e2fs_magic; /* magic number */ |
98 |
u_int32_t e2fs_fsckintv; /* max time between fscks */ |
u_int16_t e2fs_state; /* file system state */ |
99 |
u_int32_t e2fs_creator; /* creator OS */ |
u_int16_t e2fs_beh; /* behavior on errors */ |
100 |
u_int32_t e2fs_rev; /* revision level */ |
u_int16_t reserved; |
101 |
u_int16_t e2fs_ruid; /* default uid for reserved blocks */ |
u_int32_t e2fs_lastfsck; /* time of last fsck */ |
102 |
u_int16_t e2fs_rgid; /* default gid for reserved blocks */ |
u_int32_t e2fs_fsckintv; /* max time between fscks */ |
103 |
u_int32_t reserved2[235]; |
u_int32_t e2fs_creator; /* creator OS */ |
104 |
|
u_int32_t e2fs_rev; /* revision level */ |
105 |
|
u_int16_t e2fs_ruid; /* default uid for reserved blocks */ |
106 |
|
u_int16_t e2fs_rgid; /* default gid for reserved blocks */ |
107 |
|
u_int32_t reserved2[235]; |
108 |
}; |
}; |
109 |
|
|
110 |
/* in-memory data for ext2fs */ |
/* in-memory data for ext2fs */ |
128 |
struct vfs *sc_vfs; |
struct vfs *sc_vfs; |
129 |
}; |
}; |
130 |
|
|
|
#define NDIRECT 12 |
|
|
#define NINDIRECT 3 |
|
|
|
|
131 |
struct ext2fs_dinode |
struct ext2fs_dinode |
132 |
{ |
{ |
133 |
u_int16_t mode; |
u_int16_t mode; |
152 |
u_int16_t linux_reserved2; |
u_int16_t linux_reserved2; |
153 |
u_int32_t linux_reserved3[2]; |
u_int32_t linux_reserved3[2]; |
154 |
}; |
}; |
155 |
|
#define EXT2_DINODE_SIZE (sizeof (struct ext2fs_dinode)) |
|
struct ext2fs_inode |
|
|
{ |
|
|
struct ext2fs_dinode dinode; |
|
|
struct ext2fs_softc *sc; |
|
|
}; |
|
156 |
|
|
157 |
struct ext2fs_dirent |
struct ext2fs_dirent |
158 |
{ |
{ |
159 |
u_int32_t ino; |
u_int32_t ino; |
160 |
u_int16_t reclen; |
u_int16_t reclen; |
161 |
u_int16_t namlen; |
u_int8_t namlen; |
162 |
|
u_int8_t file_type; |
163 |
char name[255]; |
char name[255]; |
164 |
}; |
}; |
165 |
|
|
166 |
/* |
/* The minimum length for a directory entry. |
167 |
* Filesystem identification |
XXX Does ext2fs need this? */ |
168 |
*/ |
#define EXT2FS_MINENT 12 |
169 |
|
|
170 |
|
|
171 |
|
/* Inode for a ext2fs vnode. In-memory sturcture. */ |
172 |
|
struct inode |
173 |
|
{ |
174 |
|
struct ext2fs_dinode i_dinode; |
175 |
|
struct ext2fs_softc *i_sc; |
176 |
|
ino_t i_number; |
177 |
|
}; |
178 |
|
|
179 |
|
|
180 |
|
/* Filesystem identification. */ |
181 |
#define E2FS_MAGIC 0xef53 /* the ext2fs magic number */ |
#define E2FS_MAGIC 0xef53 /* the ext2fs magic number */ |
182 |
#define E2FS_REV 0 /* revision level */ |
#define E2FS_REV 0 /* revision level */ |
183 |
|
|
184 |
/* |
/* OS identification. */ |
|
* OS identification |
|
|
*/ |
|
185 |
#define E2FS_OS_LINUX 0 |
#define E2FS_OS_LINUX 0 |
186 |
#define E2FS_OS_HURD 1 |
#define E2FS_OS_HURD 1 |
187 |
#define E2FS_OS_MASIX 2 |
#define E2FS_OS_MASIX 2 |
188 |
|
|
189 |
/* |
/* Filesystem clean flags. */ |
|
* Filesystem clean flags |
|
|
*/ |
|
190 |
#define E2FS_ISCLEAN 0x01 |
#define E2FS_ISCLEAN 0x01 |
191 |
#define E2FS_ERRORS 0x02 |
#define E2FS_ERRORS 0x02 |
192 |
|
|
193 |
/* ext2 file system block group descriptor */ |
/* Ext2 file system block group descriptor */ |
194 |
|
struct ext2_gd |
195 |
struct ext2_gd { |
{ |
196 |
u_int32_t ext2bgd_b_bitmap; /* blocks bitmap block */ |
u_int32_t ext2bgd_b_bitmap; /* blocks bitmap block */ |
197 |
u_int32_t ext2bgd_i_bitmap; /* inodes bitmap block */ |
u_int32_t ext2bgd_i_bitmap; /* inodes bitmap block */ |
198 |
u_int32_t ext2bgd_i_tables; /* inodes table block */ |
u_int32_t ext2bgd_i_tables; /* inodes table block */ |
199 |
u_int16_t ext2bgd_nbfree; /* number of free blocks */ |
u_int16_t ext2bgd_nbfree; /* number of free blocks */ |
200 |
u_int16_t ext2bgd_nifree; /* number of free inodes */ |
u_int16_t ext2bgd_nifree; /* number of free inodes */ |
201 |
u_int16_t ext2bgd_ndirs; /* number of directories */ |
u_int16_t ext2bgd_ndirs; /* number of directories */ |
202 |
u_int16_t reserved; |
u_int16_t reserved; |
203 |
u_int32_t reserved2[3]; |
u_int32_t reserved2[3]; |
204 |
}; |
}; |
205 |
|
|
206 |
/* |
/* Turn file system block numbers into disk block addresses. |
207 |
* Turn file system block numbers into disk block addresses. |
This maps file system blocks to device size blocks. */ |
|
* This maps file system blocks to device size blocks. |
|
|
*/ |
|
208 |
#define fsbtodb(fs, b) ((b) << (fs)->sc_fsbtodb) |
#define fsbtodb(fs, b) ((b) << (fs)->sc_fsbtodb) |
209 |
#define dbtofsb(fs, b) ((b) >> (fs)->sc_fsbtodb) |
#define dbtofsb(fs, b) ((b) >> (fs)->sc_fsbtodb) |
210 |
|
|
211 |
/* |
/* Macros for handling inode numbers: |
212 |
* Macros for handling inode numbers: |
inode number to file system block offset. |
213 |
* inode number to file system block offset. |
inode number to cylinder group number. |
214 |
* inode number to cylinder group number. |
inode number to file system block address. |
|
* inode number to file system block address. |
|
215 |
*/ |
*/ |
216 |
#define ino_to_cg(fs, x) (((x) - 1) / (fs)->sc_sb.e2fs_ipg) |
#define ino_to_cg(fs, x) (((x) - 1) / (fs)->sc_sb.e2fs_ipg) |
217 |
#define ino_to_fsba(fs, x) \ |
#define ino_to_fsba(fs, x) \ |
219 |
(((x)-1) % (fs)->sc_sb.e2fs_ipg)/(fs)->sc_ipb) |
(((x)-1) % (fs)->sc_sb.e2fs_ipg)/(fs)->sc_ipb) |
220 |
#define ino_to_fsbo(fs, x) (((x)-1) % (fs)->sc_ipb) |
#define ino_to_fsbo(fs, x) (((x)-1) % (fs)->sc_ipb) |
221 |
|
|
222 |
/* |
/* Give cylinder group number for a file system block. |
223 |
* Give cylinder group number for a file system block. |
Give cylinder group block number for a file system block. */ |
|
* Give cylinder group block number for a file system block. |
|
|
*/ |
|
224 |
#define dtog(fs, d) (((d) - (fs)->sc_sb.e2fs_first_dblock) / (fs)->sc_sb.e2fs_fpg) |
#define dtog(fs, d) (((d) - (fs)->sc_sb.e2fs_first_dblock) / (fs)->sc_sb.e2fs_fpg) |
225 |
#define dtogd(fs, d) \ |
#define dtogd(fs, d) \ |
226 |
(((d) - (fs)->sc_sb.e2fs_first_dblock) % (fs)->sc_sb.e2fs_fpg) |
(((d) - (fs)->sc_sb.e2fs_first_dblock) % (fs)->sc_sb.e2fs_fpg) |
227 |
|
|
228 |
/* |
/* The following macros optimize certain frequently calculated |
229 |
* The following macros optimize certain frequently calculated |
quantities by using shifts and masks in place of divisions |
230 |
* quantities by using shifts and masks in place of divisions |
modulos and multiplications. */ |
|
* modulos and multiplications. |
|
|
*/ |
|
231 |
#define blkoff(fs, loc) /* calculates (loc % fs->sc_bsize) */ \ |
#define blkoff(fs, loc) /* calculates (loc % fs->sc_bsize) */ \ |
232 |
((loc) & (fs)->sc_qbmask) |
((loc) & (fs)->sc_qbmask) |
233 |
#define lblktosize(fs, blk) /* calculates (blk * fs->sc_bsize) */ \ |
#define lblktosize(fs, blk) /* calculates (blk * fs->sc_bsize) */ \ |
238 |
(((size) + (fs)->sc_qbmask) & (fs)->sc_bmask) |
(((size) + (fs)->sc_qbmask) & (fs)->sc_bmask) |
239 |
#define fragroundup(fs, size) /* calculates roundup(size, fs->sc_bsize) */ \ |
#define fragroundup(fs, size) /* calculates roundup(size, fs->sc_bsize) */ \ |
240 |
(((size) + (fs)->sc_qbmask) & (fs)->sc_bmask) |
(((size) + (fs)->sc_qbmask) & (fs)->sc_bmask) |
241 |
/* |
|
242 |
* Determine the number of available frags given a |
/* Determine the number of available frags given a |
243 |
* percentage to hold in reserve. |
percentage to hold in reserve. */ |
|
*/ |
|
244 |
#define freespace(fs) \ |
#define freespace(fs) \ |
245 |
((fs)->sc_sb.e2fs_fbcount - (fs)->sc_sb.e2fs_rbcount) |
((fs)->sc_sb.e2fs_fbcount - (fs)->sc_sb.e2fs_rbcount) |
246 |
|
|
247 |
/* |
/* Number of indirects in a file system block. */ |
248 |
* Number of indirects in a file system block. |
#define NINDIR(fs) ((fs)->sc_bsize / sizeof(u_int32_t)) |
|
*/ |
|
|
#define NINDIR(fs) ((fs)->sc_bsize / sizeof(u_int32_t)) |
|
249 |
|
|
250 |
#endif /* fs-ext2.h */ |
#endif /* fs-ext2.h */ |