Info Node: (libext2fs.info)Initializing a filesystem
(libext2fs.info)Initializing a filesystem
Initializing a filesystem
-------------------------
An ext2 filesystem is initializing by the `mke2fs' program. The two
functions described here, `ext2fs_initialize' and
`ext2fs_allocate_tables' do much of the initial work for setting up a
filesystem. However, they don't do the whole job. `mke2fs' calls
`ext2fs_initialize' to set up the filesystem superblock, and calls
`ext2fs_allocate_tables' to allocate space for the inode table, and the
inode and block bitmaps. In addition, `mke2fs' must also initialize
the inode tables by clearing them with zeros, create the root and
lost+found directories, and reserve the reserved inodes.
- Function: errcode_t ext2fs_initialize (const char *NAME, int FLAGS,
struct ext2_super_block *PARAM, io_manager MANAGER,
ext2_filsys *RET_FS)
This function is used by the `mke2fs' program to initialize a
filesystem. The `ext2fs_initialize' function creates a filesystem
handle which is returned in RET_FS that has been properly setup
for a filesystem to be located in NAME, using the io_manager
MANAGER. The prototype superblock in PARAM is used to supply
parameters such as the number of blocks in the filesystem, the
block size, etc.
The `ext2fs_initialize' function does not actually do any I/O; that
will be done when the application program calls `ext2fs_close' or
`ext2fs_flush'. Also, this function only initializes the
superblock and group descriptor structures. It does not create the
inode table or the root directory. This must be done by the
calling application, such as `mke2fs'.
The following values may be set in the PARAM prototype superblock;
if a value of 0 is found in a field, `ext2fs_initialize' will use a
default value. The calling application should zero out the
prototype entire superblock, and then fill in any appropriate
values.
`s_blocks_count'
The number of blocks in the filesystem. This parameter is
mandatory and must be set by the calling application.
`s_inodes_count'
The number of inodes in the filesystem. The default value is
determined by calculating the size of the filesystem, and
creating one inode for every 4096 bytes.
`s_r_blocks_count'
The number of blocks which should be reserved for the
superuser. The default value is zero blocks.
`s_log_block_size'
The blocksize of the filesystem. Valid values are 0 (1024
bytes), 1 (2048 bytes), or 2 (4096 bytes). The default
blocksize is 1024 bytes.
`s_log_frag_size'
The size of fragments. The ext2 filesystem does not support
fragments (and may never support fragments). Currently this
field must be the same as `s_log_block_size'.
`s_first_data_block'
The first data block for the filesystem. For filesystem with
a blocksize of 1024 bytes, this value must be at least 1,
since the superblock is located in block number 1. For
filesystems with larger blocksizes, the superblock is still
located at an offset of 1024 bytes, so the superblock is
located in block number 0. By default, this value is set to
1 for filesystems with a block size of 1024 bytes, or 0 for
filesystems with larger blocksizes.
`s_max_mnt_count'
This field defines the number of times that the filesystem
can be mounted before it should be checked using `e2fsck'.
When `e2fsck' is run without the `-f' option, `e2fsck' will
skip the filesystem check if the number of times that the
filesystem has been mounted is less than `s_max_mnt_count'
and if the interval between the last time a filesystem check
was performed and the current time is less than
`s_checkinterval' (see below). The default value of
`s_max_mnt_count' is 20.
`s_checkinterval'
This field defines the minimal interval between filesystem
checks. See the previous entry for a discussion of how this
field is used by `e2fsck'. The default value of this field
is 180 days (six months).
`s_errors'
This field defines the behavior which should be used by the
kernel of errors are detected in the filesystem. Possible
values include:
`EXT2_ERRORS_CONTINUE'
Continue execution when errors are detected.
`EXT2_ERRORS_RO'
Remount the filesystem read-only.
`EXT2_ERRORS_PANIC'
Panic.
The default behavior is `EXT2_ERRORS_CONTINUE'.
- Function: errcode_t ext2fs_allocate_tables (ext2_filsys FS)
Allocate space for the inode table and the block and inode
bitmaps. The inode tables and block and inode bitmaps aren't
actually initialized; this function just allocates the space for
them.