2.1.110pre2: ROMfs cleanup

Horst von Brand (vonbrand@sleipnir.valparaiso.cl)
Sun, 19 Jul 1998 12:19:05 -0500


This patch adds proper levels to printk()s and cleans up some readability
problems.

--- linux/fs/romfs/inode.c.dist-2.1.110pre2 Wed Jun 24 17:30:10 1998
+++ linux/fs/romfs/inode.c Sun Jul 19 12:08:14 1998
@@ -30,6 +30,10 @@
* correct namelen for statfs
* spotted by Bill Hawes:
* readlink shouldn't iput()
+ * Jul 1998
+ * 2.1.110pre2
+ * Horst von Brand:
+ * Cleanups
*/

/* todo:
@@ -61,7 +65,7 @@

static int inline min(int a, int b)
{
- return a<b ? a : b;
+ return a < b ? a : b;
}

static __s32
@@ -99,7 +103,7 @@
bh = bread(dev, 0, ROMBSIZE);
if (!bh) {
/* XXX merge with other printk? */
- printk ("romfs: unable to read superblock\n");
+ printk (KERN_ERR "romfs: unable to read superblock\n");
goto outnobh;
}

@@ -108,12 +112,12 @@
if (rsb->word0 != ROMSB_WORD0 || rsb->word1 != ROMSB_WORD1
|| sz < ROMFH_SIZE) {
if (!silent)
- printk ("VFS: Can't find a romfs filesystem on dev "
+ printk (KERN_ERR "VFS: Can't find a romfs filesystem on dev "
"%s.\n", kdevname(dev));
goto out;
}
if (romfs_checksum(rsb, min(sz,512))) {
- printk ("romfs: bad initial checksum on dev "
+ printk (KERN_ERR "romfs: bad initial checksum on dev "
"%s.\n", kdevname(dev));
goto out;
}
@@ -137,18 +141,16 @@
goto outnobh;

unlock_super(s);
+ goto done;

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

@@ -230,7 +232,7 @@
if (offset >= maxsize || count > maxsize || offset+count>maxsize)
return -1;

- bh = bread(i->i_dev, offset>>ROMBSBITS, ROMBSIZE);
+ bh = bread(i->i_dev, offset >> ROMBSBITS, ROMBSIZE);
if (!bh)
return -1; /* error */

@@ -245,10 +247,10 @@
offset += maxsize;
dest += maxsize;

- bh = bread(i->i_dev, offset>>ROMBSBITS, ROMBSIZE);
+ bh = bread(i->i_dev, offset >> ROMBSBITS, ROMBSIZE);
if (!bh)
return -1;
- maxsize = min(count-res, ROMBSIZE);
+ maxsize = min(count - res, ROMBSIZE);
memcpy(dest, bh->b_data, maxsize);
brelse(bh);
res += maxsize;
@@ -292,12 +294,12 @@
if (romfs_copyfrom(i, &ri, offset, ROMFH_SIZE) <= 0)
return stored;

- j = romfs_strnlen(i, offset+ROMFH_SIZE, sizeof(fsname)-1);
+ j = romfs_strnlen(i, offset + ROMFH_SIZE, sizeof(fsname) - 1);
if (j < 0)
return stored;

fsname[j]=0;
- romfs_copyfrom(i, fsname, offset+ROMFH_SIZE, j);
+ romfs_copyfrom(i, fsname, offset + ROMFH_SIZE, j);

ino = offset;
nextfh = ntohl(ri.next);
@@ -346,19 +348,22 @@
goto out;

/* try to match the first 16 bytes of name */
- fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, ROMFH_SIZE);
+ fslen = romfs_strnlen(dir, offset + ROMFH_SIZE, ROMFH_SIZE);
if (len < ROMFH_SIZE) {
if (len == fslen) {
/* both are shorter, and same size */
- romfs_copyfrom(dir, fsname, offset+ROMFH_SIZE, len+1);
+ romfs_copyfrom(dir, fsname,
+ offset + ROMFH_SIZE, len + 1);
if (strncmp (name, fsname, len) == 0)
break;
}
} else if (fslen >= ROMFH_SIZE) {
/* both are longer; XXX optimize max size */
- fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, sizeof(fsname)-1);
+ fslen = romfs_strnlen(dir, offset + ROMFH_SIZE,
+ sizeof(fsname) - 1);
if (len == fslen) {
- romfs_copyfrom(dir, fsname, offset+ROMFH_SIZE, len+1);
+ romfs_copyfrom(dir, fsname,
+ offset + ROMFH_SIZE, len + 1);
if (strncmp(name, fsname, len) == 0)
break;
}
@@ -405,9 +410,12 @@
if (offset < inode->i_size) {
avail = inode->i_size-offset;
readlen = min(avail, PAGE_SIZE);
- if (romfs_copyfrom(inode, (void *)buf, inode->u.romfs_i.i_dataoffset+offset, readlen) == readlen) {
+ if (romfs_copyfrom(inode, (void *)buf,
+ inode->u.romfs_i.i_dataoffset + offset,
+ readlen) == readlen) {
if (readlen < PAGE_SIZE) {
- memset((void *)(buf+readlen),0,PAGE_SIZE-readlen);
+ memset((void *)(buf + readlen), 0,
+ PAGE_SIZE - readlen);
}
set_bit(PG_uptodate, &page->flags);
result = 0;
@@ -459,25 +467,25 @@
len = inode->i_size;

dentry = ERR_PTR(-EAGAIN); /* correct? */
- if (!(link = kmalloc(len+1, GFP_KERNEL)))
+ if (!(link = kmalloc(len + 1, GFP_KERNEL)))
goto outnobuf;

cnt = romfs_copyfrom(inode, link, inode->u.romfs_i.i_dataoffset, len);
if (len != cnt) {
dentry = ERR_PTR(-EIO);
goto out;
- } else
- link[len] = 0;
-
+ }
+
+ link[len] = 0;
dentry = lookup_dentry(link, base, 1);
kfree(link);
+ goto done;

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

@@ -584,7 +592,7 @@

static mode_t romfs_modemap[] =
{
- 0, S_IFDIR, S_IFREG, S_IFLNK+0777,
+ 0, S_IFDIR, S_IFREG, S_IFLNK + 0777,
S_IFBLK, S_IFCHR, S_IFSOCK, S_IFIFO
};

@@ -613,7 +621,8 @@
/* Loop for finding the real hard link */
for(;;) {
if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) {
- printk("romfs: read error for inode 0x%x\n", ino);
+ printk(KERN_ERR "romfs: read error for inode 0x%x\n",
+ ino);
return;
}
/* XXX: do romfs_checksum here too (with name) */
@@ -633,17 +642,17 @@
i->i_op = romfs_inoops[nextfh & ROMFH_TYPE];

/* Precalculate the data offset */
- ino = romfs_strnlen(i, ino+ROMFH_SIZE, ROMFS_MAXFN);
+ ino = romfs_strnlen(i, ino + ROMFH_SIZE, ROMFS_MAXFN);
if (ino >= 0)
- ino = ((ROMFH_SIZE+ino+1+ROMFH_PAD)&ROMFH_MASK);
+ ino = ((ROMFH_SIZE + ino + 1 + ROMFH_PAD) & ROMFH_MASK);
else
ino = 0;

i->u.romfs_i.i_metasize = ino;
- i->u.romfs_i.i_dataoffset = ino+(i->i_ino&ROMFH_MASK);
+ i->u.romfs_i.i_dataoffset = ino + (i->i_ino & ROMFH_MASK);

/* Compute permissions */
- ino = S_IRUGO|S_IWUSR;
+ ino = S_IRUGO | S_IWUSR;
ino |= romfs_modemap[nextfh & ROMFH_TYPE];
if (nextfh & ROMFH_EXEC) {
ino |= S_IXUGO;
@@ -655,9 +664,9 @@
else if (S_ISDIR(ino))
i->i_size = i->u.romfs_i.i_metasize;
else if (S_ISBLK(ino) || S_ISCHR(ino)) {
- i->i_mode &= ~(S_IRWXG|S_IRWXO);
+ i->i_mode &= ~(S_IRWXG | S_IRWXO);
ino = ntohl(ri.spec);
- i->i_rdev = MKDEV(ino>>16,ino&0xffff);
+ i->i_rdev = MKDEV(ino >> 16, ino & 0xffff);
}
}

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

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html