romfs in linux-2.1.47

Horst von Brand (vonbrand@sleipnir.valparaiso.cl)
Thu, 24 Jul 1997 22:30:18 -0400


I was trying to learn more about Linux' filesystems by updating romfs for
dcache et al, but you beat me to it. Learned a lot, though ;-) Many thanks!

The latest result of my efforts (retrofitted from my (almost working)
version to your version in 2.1.47) is given by the following patch. It is
all of 12 (twelve) bytes larger (as lsmod reports) than your version (i586,
gcc-2.7.2.2.f.2, -fno-strength-reduce omitted). I'd say they aren't worth
the extra complication ;-) Besides, there are some real changes:

- The checksumming function is called just once; by inlining it you'll
probably s(h)ave a couple of bytes.

- If the checksum doesn't turn out right, better leave and not mount a
probably corrupted filesystem

- I'd better not lie about the f_namelen in statfs(). One of my trial
versions did blow up because of that, I think...

- I believe you could unlock_super() twice in romfs_read_super. Besides,
I'd sleep sounder if the unlock_super() was _always_ done when you are
truly done with the superblock.

- Instead on kmallock()ing memory for the filenames (as you propose in the
TODO list), you could use alloca(), by way of the gcc-2.x builtin. Naughty,
but it should work even in the kernel and cost less than kmalloc()/kfree()
in code size...

- You might consider using the quicklist routines from linux/fs/namei.c for
allocating the link name. You'd gain some performance (probably not
really worth it, but would make a good example for later generations :)

--- linux-2.1.47/fs/romfs/inode.c.dist Thu Jul 24 18:39:55 1997
+++ linux-2.1.47/fs/romfs/inode.c Thu Jul 24 21:59:20 1997
@@ -26,7 +26,9 @@

/* todo:
* - see Documentation/filesystems/romfs.txt
- * - use malloced memory for file names?
+ * - Blow away . and .. in dirs (completely handled by dcache now)
+ * Changes the format of the filesystem!
+ * - use malloced memory for file names? [Or __builtin_alloca() ;-]
* - considering write access...
* - network (tftp) files?
* - in the ancient times something leaked to made umounts
@@ -55,14 +57,14 @@
return a<b ? a : b;
}

-static __s32
+static inline __s32
romfs_checksum(void *data, int size)
{
__s32 sum, *ptr;

sum = 0; ptr = data;
- size>>=2;
- while (size>0) {
+ size >>= 2;
+ while (size > 0) {
sum += ntohl(*ptr++);
size--;
}
@@ -103,9 +105,10 @@
"%s.\n", kdevname(dev));
goto out;
}
- if (romfs_checksum(rsb, min(sz,512))) {
+ if (romfs_checksum(rsb, min(sz, 512))) {
printk ("romfs: bad initial checksum on dev "
"%s.\n", kdevname(dev));
+ goto out;
}

s->s_magic = ROMFS_MAGIC;
@@ -123,23 +126,20 @@
s->s_op = &romfs_ops;
s->s_root = d_alloc_root(iget(s, sz), NULL);

- unlock_super(s);
-
if (!s->s_root)
goto outnobh;

- /* Ehrhm; sorry.. :) And thanks to Hans-Joachim Widmaier :) */
- if (0) {
-out:
- brelse(bh);
-outnobh:
- s->s_dev = 0;
- unlock_super(s);
- MOD_DEC_USE_COUNT;
- s = NULL;
- }
+ unlock_super(s);

return s;
+
+out:
+ brelse(bh);
+outnobh:
+ s->s_dev = 0;
+ unlock_super(s);
+ MOD_DEC_USE_COUNT;
+ return NULL;
}

/* Nothing to do.. */
@@ -165,7 +165,7 @@
tmp.f_type = ROMFS_MAGIC;
tmp.f_bsize = ROMBSIZE;
tmp.f_blocks = (sb->u.romfs_sb.s_maxsize+ROMBSIZE-1)>>ROMBSBITS;
- /* XXX tmp.f_namelen = relevant? */
+ tmp.f_namelen = ROMFS_MAXFN;
return copy_to_user(buf, &tmp, bufsize) ? -EFAULT : 0;
}

@@ -472,14 +472,15 @@
link[len] = 0;

dentry = lookup_dentry(link, base, 1);
+
kfree(link);

- if (0) {
+ return dentry;
+
out:
- kfree(link);
+ kfree(link);
outnobuf:
- dput(base);
- }
+ dput(base);
return dentry;
}

-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viņa del Mar, Chile                               +56 32 672616