Creating mkfs for my custom filesystem

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Fri Mar 29 09:23:41 EDT 2013


On Fri, 29 Mar 2013 15:44:49 +0530, Sankar P said:

>> 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.

You *will* have to support at least the top-level directory, because
you'll need at least directory entries for "." and "..".  If your second
block is "list of inodes", then you have directories (and adding subdir
support isn't *that* hard).

You'll also want either a list or bitmap structure or some other way to
determine if a given block is allocated - trying to write a new file without
having a freelist to get blocks from is hard.  Oh, and don't forget to
add locking around the freelist operations and similar things - having
two processes both grab block 27 for the file they just created can suck :)

> 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 ) ?

struct foobar_suoper {
	int version;
	int num_files;
	int free_blocks;
	char padding[512-3*sizeof(int)];
};

struct foobar_super sb;

int disk;

	bzero(sb, sizeof struct foobar_super);
	sb.version = 1;
	sb.num_files= 0;
	sb.free_blocks = 999; /* should probably set to actual size of partition/file */

	disk = open(*diskorfilename, ....);  /* testing on loop mounts is useful */
	lseek ( disk, 0);
	write (disk, &sb, sizeof(sb)); /* congrats, you just wrote a superblock */

Yes, it's that simple :)  You want to write some empty inodes, add a
'struct inode' variable, initialize it, lseek to were the inode goes and
write it out.

Just open, lseek, write, close.  ;)  And yes, those operations *do* work
just fine on both files you then use woth 'mount -o loop' and with /dev/sd*
or /dev/mapper/* LVM.

You might want to look at the source for mkfs.vfat (part of dosfstools package)
for additional details.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130329/87bc7433/attachment.bin 


More information about the Kernelnewbies mailing list