http://www.nondot.org/sabre/os/files/FileSystems/ext2fs/ext2fs_8.html#SEC8
Go to the previous,
next
section.
An inode uniquely describes a file. Here's what an inode looks like
on
disk:
struct ext2_inode {
unsigned short i_mode;
unsigned short i_uid;
unsigned long i_size;
unsigned long i_atime;
unsigned long i_ctime;
unsigned long i_mtime;
unsigned long i_dtime;
unsigned short i_gid;
unsigned short i_links_count;
unsigned long i_blocks;
unsigned long i_flags;
unsigned long i_reserved1;
unsigned long i_block[EXT2_N_BLOCKS];
unsigned long i_version;
unsigned long i_file_acl;
unsigned long i_dir_acl;
unsigned long i_faddr;
unsigned char i_frag;
unsigned char i_fsize;
unsigned short i_pad1;
unsigned long i_reserved2[2];
};
i_mode
- type of file (character, block, link, etc.) and access rights on
the
file.
i_uid
- uid of the owner of the file.
i_size
- logical size in bytes.
i_atime
- last time the file was accessed.
i_ctime
- last time the inode information of the file was changed.
i_mtime
- last time the file content was modified.
i_dtime
- when this file was deleted.
i_gid
- gid of the file.
i_links_count
- number of links pointing to this file.
i_blocks
- number of blocks allocated to this file counted in 512 bytes
units.
i_flags
- flags (see below).
i_reserved1
- reserved.
i_block
- pointers to blocks (see below).
i_version
- version of the file (used by NFS).
i_file_acl
- control access list of the file (not used yet).
i_dir_acl
- control access list of the directory (not used yet).
i_faddr
- block where the fragment of the file resides.
i_frag
- number of the fragment in the block.
i_size
- size of the fragment.
i_pad1
- padding.
i_reserved2
- reserved.
As you can see, the inode contains, EXT2_N_BLOCKS (15 in
ext2fs
0.5) pointers to block. Of theses pointers, the first
EXT2_NDIR_BLOCKS (12) are direct pointers to data. The
following entry
points to a block of pointers to data (indirect). The following entry
points to a block of pointers to blocks of pointers to data (double
indirection). The following entry points to a block of pointers to a
block of pointers to a block of pointers to data (triple indirection).
The inode flags may take one or more of the following or'ed values:
EXT2_SECRM_FL 0x0001
- secure deletion. This usually means that when this flag is set
and we
delete the file, random data is written in the blocks previously
allocated
to the file.
EXT2_UNRM_FL 0x0002
- undelete. When this flag is set and the file is being deleted,
the file
system code must store enough information to ensure the undeletion of
the file (to a certain extent).
EXT2_COMPR_FL 0x0004
- compress file. The content of the file is compressed, the file
system
code must use compression/decompression algorithms when accessing the
data of this file.
EXT2_SYNC_FL 0x0008
- synchronous updates. The disk representation of this file must be
kept
in sync with it's in core representation. Asynchronous I/O on this kind
of file is not possible. The synchronous updates only apply to the
inode
itself and to the indirect blocks. Data blocks are always written
asynchronously on the disk.
Some inodes have a special meaning:
EXT2_BAD_INO 1
- a file containing the list of bad blocks on the file system.
EXT2_ROOT_INO 2
- the root directory of the file system.
EXT2_ACL_IDX_INO 3
- ACL inode.
EXT2_ACL_DATA_INO 4
- ACL inode.
EXT2_BOOT_LOADER_INO 5
- the file containing the boot loader. (Not used yet it seems.)
EXT2_UNDEL_DIR_INO 6
- the undelete directory of the system.
EXT2_FIRST_INO 11
- this is the first inode that does not have a special meaning.
Go to the previous,
next
section.
Go to the previous,
next
section.
Here are the allocation algorithms that ext2 file system managers
must use. We are adamant on this point. Nowadays, many
users
use more than one operating system on the same computer. If more than
one operating system use the same ext2 partition, they have to use the
same allocation algorithms. If they do otherwise, what will happen is
that one file system manager will undo the work of the other file
system
manager. It is useless to have a manager that uses highly efficient
allocation algorithms if the other one does not bother with allocation
and uses quick and dirty algorithms.
Here are the rules used to allocate new inodes:
- the inode for a new file is allocated in the same group of the
inode of its parent directory.
- inodes are allocated equally between groups.
Here are the rules used to allocate new blocks:
- a new block is allocated in the same group as its inode.
- allocate consecutive sequences of blocks.
Of course, it may be sometimes impossible to abide by those rules. In
this case, the manager may allocate the block or inode anywhere.
Go to the previous,
next
section.
Go to the previous,
next
section.
This chapter describes how a standard ext2 file system must handle
errors. The superblock contains two parameters controlling the way
errors are handled. See section Superblock
The first of these is the s_mount_opt member of the
superblock
structure in memory. Its value is computed from the options specified
when the fs is mounted. Its error handling related values are:
EXT2_MOUNT_ERRORS_CONT
- continue even if an error occurs.
EXT2_MOUNT_ERRORS_RO
- remount the file system read only.
EXT2_MOUNT_ERRORS_PANIC
- the kernel panics on error.
The second of these is the s_errors member of the
superblock
structure on disk. It may take one of the following values:
EXT2_ERRORS_CONTINUE
- continue even if an error occurs.
EXT2_ERRORS_RO
- remount the file system read only.
EXT2_ERRORS_PANIC
- in which case the kernel simply panics.
EXT2_ERRORS_DEFAULT
- use the default behavior (as of 0.5a
EXT2_ERRORS_CONTINUE).
s_mount_opt has precedence on s_errors.
Go to the previous,
next
section.