lkml.org 
[lkml]   [2012]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] fs: Introducing Lanyard Filesystem
From
Hi,

On Sun, Aug 19, 2012 at 5:08 AM, Dan Luedtke <mail@danrl.de> wrote:

> +
> + /* allocate filesystem private data */
> + fsi = kzalloc(sizeof(*fsi), GFP_KERNEL);
> + if (!fsi)
> + return -ENOMEM;
> + spin_lock_init(&fsi->lock);
> + sb->s_fs_info = fsi;
> +
> + /* set blocksize to minimum size for fetching superblock */
> + if (!sb_set_blocksize(sb, 1 << LANYFS_MIN_BLOCKSIZE)) {
> + if (!silent)
> + lanyfs_err(sb, "error setting blocksize to %d bytes",
> + 1 << LANYFS_MIN_BLOCKSIZE);
> + return -EIO;
> + }
> +
> + /* fetch superblock */
> + bh = sb_bread(sb, LANYFS_SUPERBLOCK);
> + if (!bh) {
> + if (!silent)
> + lanyfs_err(sb, "error reading superblock");
> + return -EIO;
> + }
> + lanysb = (struct lanyfs_sb *) bh->b_data;
> +
> + /* check magic */
> + if (lanysb->magic != cpu_to_le32(LANYFS_SUPER_MAGIC)) {
> + if (!silent)
> + lanyfs_info(sb, "bad magic 0x%x",
> + lanysb->magic);
> + goto exit_invalid;
> + }
> + sb->s_magic = LANYFS_SUPER_MAGIC;
> +
> + /* check block type */
> + if (lanysb->type != LANYFS_TYPE_SB) {
> + if (!silent)
> + lanyfs_err(sb, "bad block type 0x%x", lanysb->type);
> + goto exit_invalid;
> + }
> +
> + /* check version */
> + if (lanysb->major > LANYFS_MAJOR_VERSION) {
> + if (!silent)
> + lanyfs_err(sb, "major version mismatch");
> + goto exit_invalid;
> + }
> +
> + /* check address length */
> + if (lanysb->addrlen < LANYFS_MIN_ADDRLEN ||
> + lanysb->addrlen > LANYFS_MAX_ADDRLEN) {
> + if (!silent)
> + lanyfs_err(sb, "unsupported address length");
> + goto exit_invalid;
> + }
> + fsi->addrlen = lanysb->addrlen;
> +
> + /* check blocksize */
> + if (lanysb->blocksize < LANYFS_MIN_BLOCKSIZE ||
> + lanysb->blocksize > LANYFS_MAX_BLOCKSIZE) {
> + if (!silent)
> + lanyfs_err(sb, "unsupported blocksize");
> + goto exit_invalid;
> + }
> + fsi->blocksize = lanysb->blocksize;
> +

> +
> + /* release block buffer */
> + brelse(bh);
> +
> + /* parse mount options */
> + save_mount_options(sb, options);
> + err = lanyfs_super_options(sb, (char *) options, silent);
> + if (err)
> + return err;
> +
> + /* set blocksize to correct size */
> + if (!sb_set_blocksize(sb, 1 << fsi->blocksize)) {
> + if (!silent)
> + lanyfs_err(sb, "error setting blocksize to %d bytes",
> + 1 << fsi->blocksize);
> + return -EIO;
> + }
> + /* default flags */
> + sb->s_maxbytes = 0xffffffff; /* TODO: hmmmmm */
> + sb->s_op = &lanyfs_super_operations;
> + sb->s_time_gran = 1;
> + sb->s_flags = MS_NOSUID | MS_NOATIME | MS_NODIRATIME;
> +
> + /* make root directory */
> + inode = lanyfs_iget(sb, fsi->rootdir);
> + if (!inode)
> + return -ENOMEM;
> +
> + sb->s_root = d_make_root(inode);
> + if (!sb->s_root) {
> + iput(inode);
> + return -ENOMEM;
> + }
> + return 0;
> +
> +exit_invalid:
> + brelse(bh);
> + if (!silent)
> + lanyfs_info(sb, "no valid lanyard filesystem found");
> + return -EINVAL;
> +}

You should free the memory for "fsi" on error.

Regards.


\
 
 \ /
  Last update: 2012-08-24 14:41    [W:0.086 / U:3.680 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site