Ext2fs: Device files inodes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Crumble14
Posts: 16
Joined: Tue Jan 01, 2019 4:10 pm
Location: Normandy, France

Ext2fs: Device files inodes

Post 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?
Student at School 42 Paris (FR: https://42.fr/)
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Ext2fs: Device files inodes

Post 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).
Crumble14
Posts: 16
Joined: Tue Jan 01, 2019 4:10 pm
Location: Normandy, France

Re: Ext2fs: Device files inodes

Post 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?
Student at School 42 Paris (FR: https://42.fr/)
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Ext2fs: Device files inodes

Post 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.
Crumble14
Posts: 16
Joined: Tue Jan 01, 2019 4:10 pm
Location: Normandy, France

Re: Ext2fs: Device files inodes

Post 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 :)
Student at School 42 Paris (FR: https://42.fr/)
Post Reply