OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 4:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Ext2fs: Device files inodes
PostPosted: Thu Jun 17, 2021 5:16 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Ext2fs: Device files inodes
PostPosted: Thu Jun 17, 2021 5:52 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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).

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Ext2fs: Device files inodes
PostPosted: Thu Jun 17, 2021 6:12 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Ext2fs: Device files inodes
PostPosted: Thu Jun 17, 2021 6:37 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Ext2fs: Device files inodes
PostPosted: Thu Jun 17, 2021 9:59 am 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], SemrushBot [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group