How big is an inode?
Inodes are metadata that contain information about a file / directory, etc. The size of the inode structure is 128 bytes per inode in a non modified standard kernel.
Inode Structure
The output from tune2fs says its 256 for my system, so is that 256 byes?
When you make your filesystem, you can change the inode size. Some Linux distributions may change that value and some ext2 creation tools have other inode sizes by default. mke2fs, for example, has a default of 256.
Manually you can do:
mke2fs -I 128
to get the 128 bytes value. Never less than that. You can change that value with -O resize_inode
To sum up all of that: minimum 128 bytes.
How are large directories stored? From what I understand, a directory is represented on the filesystem as an inode who's contents are a list of filenames and inode numbers that represent the contents of the directory. Are the contents stored in the inode itself, or in this case are they stored as "data" the same way file data is stored?
A directory is marked to be a directory in the first value of the ext2 inode struct, which is "i_mode". In the kernel:
struct ext2_inode {
__le16 i_mode; /* File mode */
︙
[fs/ext2/ext2.h in the kernel describes everything]
And that variable can take those values:
/* inode: i_mode */
#define EXT2_S_IFMT 0xF000 /* format mask */
#define EXT2_S_IFSOCK 0xC000 /* socket */
#define EXT2_S_IFLNK 0xA000 /* symbolic link */
#define EXT2_S_IFREG 0x8000 /* regular file */
#define EXT2_S_IFBLK 0x6000 /* block device */
#define EXT2_S_IFDIR 0x4000 /* directory */
#define EXT2_S_IFCHR 0x2000 /* character device */
#define EXT2_S_IFIFO 0x1000 /* fifo */
The directory inode points to a list, which is in the data part, that contains a list of directory entry structures. Each one of this structs contains 5 variables:
- inode -> the inode number of that entry.
- rec_len -> for alignment.
- file_type -> the file type, more or less the same types that I pasted before :D.
- name_len -> the length in bytes of the name.
- name -> with a maximum length of 255 bytes.
That structure repeats as many times as there are files in the directory.
Sorry if there are any grammar mistakes :D