Page 1 of 1
Ext2fs: Device files inodes
Posted: Thu Jun 17, 2021 5:16 am
by Crumble14
Hello,
Whilst I've been implementing the ext2 filesystem into my kernel, I've realized that I didn't know where were stored the device's major/minor numbers.
For example on Linux here, the major/minor are 8 and 0:
Code: Select all
$ ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 Jun 1 15:39 /dev/sda
Logically, I'd say that it should be stored in the inode's structure, but when reading the documentation it isn't mentioned anywhere.
Thus my question is: Where am I supposed to store the major/minor numbers?
Re: Ext2fs: Device files inodes
Posted: Thu Jun 17, 2021 5:52 am
by klange
Same as small symlinks, device file major and minor numbers are stored in the bytes that would normally make up the first direct block pointer in the inode (i_block at offset 40).
Re: Ext2fs: Device files inodes
Posted: Thu Jun 17, 2021 6:12 am
by Crumble14
klange wrote:Same as small symlinks, device file major and minor numbers are stored in the bytes that would normally make up the first direct block pointer in the inode (i_block at offset 40).
In the inode's structure itself?
Am I supposed to put the major first, then the minor, or the opposite?
What happens if a symlink is too big to fit in the structure? I guess it would then be written into blocks directly, but how is the fs driver supposed to know if it should interpret the bytes into the inode's structure as block addresses or as the link's data itself?
Re: Ext2fs: Device files inodes
Posted: Thu Jun 17, 2021 6:37 am
by klange
Crumble14 wrote:In the inode's structure itself?
Yes.
Crumble14 wrote:Am I supposed to put the major first, then the minor, or the opposite?
I can't find it specified in my copy of the spec...
Crumble14 wrote:What happens if a symlink is too big to fit in the structure? I guess it would then be written into blocks directly, but how is the fs driver supposed to know if it should interpret the bytes into the inode's structure as block addresses or as the link's data itself?
The size available within the inode is fixed at 60 bytes and the length of the symlink contents is the size of the file, so the filesystem implementation would be able know whether the i_block data is pointers or characters based on that size.
Random aside: I kinda despise the whole system of device special files. A pair of bytes is terribly insufficient for identifying interfaces to the myriad devices represented on a modern system. I opted not to implement them at all, instead implementing all device files as virtual files in the same way as a /proc or /sys.
Re: Ext2fs: Device files inodes
Posted: Thu Jun 17, 2021 9:59 am
by Crumble14
Thanks for you help, I'll try to implement it this way and I'll check if it's compatible with Linux to be sure