kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu (Valdis.Kletnieks at vt.edu)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Creating mkfs for my custom filesystem
Date: Fri, 29 Mar 2013 09:23:41 -0400	[thread overview]
Message-ID: <30366.1364563421@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Fri, 29 Mar 2013 15:44:49 +0530." <CAMSEaH6W11vgFQ-7ZzO_u-npyq+_OMDnopREusWyn3m1TDoBeQ@mail.gmail.com>

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 

  reply	other threads:[~2013-03-29 13:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-29  8:27 Creating mkfs for my custom filesystem Sankar P
2013-03-29  9:58 ` Tobias Boege
2013-03-29 10:14   ` Sankar P
2013-03-29 13:23     ` Valdis.Kletnieks at vt.edu [this message]
2013-03-29 14:01     ` Tobias Boege
2013-03-29 15:45       ` Sankar P
     [not found] ` <CA+aCy1EC-tRUCVuP-h=UV0k0bPnhcs9mu+cGFSJt_wRxCKuD-w@mail.gmail.com>
2013-03-29 10:26   ` Fwd: " Pranay Srivastava
2013-03-29 10:48     ` Sankar P
2013-03-29 13:23       ` Madper
2013-03-29 17:27 ` Manish Katiyar
2013-03-29 18:17   ` Sankar P

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30366.1364563421@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).