Creating mkfs for my custom filesystem

Tobias Boege tobias at gambas-buch.de
Fri Mar 29 10:01:06 EDT 2013


On Fri, 29 Mar 2013, Sankar P wrote:
> On Fri, Mar 29, 2013 at 3:28 PM, Tobias Boege <tobias at gambas-buch.de> wrote:
> > On Fri, 29 Mar 2013, Sankar P wrote:
> >> Hi,
> >>
> >> I am trying to write a simple filesystem to learn the basics of it.
> >>
> >> I have decided on a simple layout for my filesystem where the first
> >> block will be the super block and   will contain the version
> >> information etc. The second block will contain the list of inodes.
> >> Third block onwards will be data blocks. Each file can grow only up to
> >> a single block size. Thrid block will represent the first file, fourth
> >> block for the second file and so on. Directories will not be
> >> supported.
> >>
> >> Now I want to create a mkfs for my filesystem as mentioned above. But
> >> I am not able to find out how to do the mkfs for my filesystem such
> >> that the generic mkfs utility will understand my filesystem. What APIs
> >> should I be using ?
> >>
> >> Any help is appreciated. Thanks.
> >
> > According to my copy of the mkfs sources, you just have to create a program
> > named "mkfs.ID" where ID identifies your filesystem. Then put that program
> > in a location that the generic mkfs can find, i.e. under $PATH (mkfs seems
> > to make some additions to PATH but you should figure this out yourself).
> >
> > Finally, calling "mkfs -t ID" makes mkfs search for a program named
> > "mkfs.ID" - simple concatenation.
> >
> 
> oh okay. But how do I create the superblock ? What are the APIs
> available to do these block level operations from a user space
> application (my mkfs program ) ?
> 

Look at how other mkfs.* do it. In general, these programs seem to be fairly
complex. To interface with block devices from userspace: use the standard
system calls, open(), lseek(), write(), ...

For an example, you can look at the e2fsprogs source code. If you get
through the jungle of indirections you will eventually find just a plain
write() call in lib/ext2fs/unix_io.c:raw_write_blk() which is used for data
transfer.

Regards,
Tobi




More information about the Kernelnewbies mailing list