1

I've been studying up on the ext2 file system and inodes, and I'm not quite understanding a few things.

How big is an inode? The output from tune2fs says its 256 for my system, so is that 256 byes?

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?

4

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

  • Your first paragraph is a little odd. First of all, why say “Inode is just metadata.”? That doesn’t answer any part of the question. Since the OP has “been studying up on the ext2 file system and inodes,” you might assume that he has a notion of what an inode is. Further, this is not 100% true; small files and symbolic links can be inlined in inodes. And then your statement, “The size of the inode structure is fixed to 128 bytes per inode.” is not clearly consistent with your subsequent statements that it can be larger. – G-Man Sep 5 '14 at 1:00
  • Can be larger but the information gathered in the struct is 128 bytes in a non modified kernel. Then, tools while creating the fs, can do whatever they want: usually set more size for the inodes, so changes can be made in the future. However, thats not the kernel standard. – allmy Sep 5 '14 at 1:05
  • OK, but if it can be larger, then it isn't fixed, is it? I suggest that you edit your answer and put your clarification there. – G-Man Sep 5 '14 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.