public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] V7: Add support for non-PDP11 v7 filesystems
@ 2010-07-25 22:50 Lubomir Rintel
  2010-07-25 22:54 ` Lubomir Rintel
  0 siblings, 1 reply; 8+ messages in thread
From: Lubomir Rintel @ 2010-07-25 22:50 UTC (permalink / raw)
  To: Al Viro
  Cc: Linux Kernel Mailing List, Andrew Morton, Christoph Hellwig,
	Lubomir Rintel, Al Viro

A mount-time option was added that makes it possible to override the
endianness and an attempt is made to autodetect it (which seems easy,
given the disk addresses are 3-byte.

No attempt is made to detect big-endian filesystems -- were there any?
Tested with PDP-11 v7 filesystems and PC-IX maintenance floppy.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 fs/sysv/super.c |   74 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index ac7b008..0433f23 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -24,6 +24,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/buffer_head.h>
+#include <linux/parser.h>
 #include "sysv.h"
 
 /*
@@ -435,12 +436,46 @@ Ebadsize:
 	goto failed;
 }
 
-static int v7_fill_super(struct super_block *sb, void *data, int silent)
+static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)
 {
-	struct sysv_sb_info *sbi;
-	struct buffer_head *bh, *bh2 = NULL;
 	struct v7_super_block *v7sb;
 	struct sysv_inode *v7i;
+	struct buffer_head *bh2;
+	struct sysv_sb_info *sbi;
+
+	sbi = sb->s_fs_info;
+
+	/* plausibility check on superblock */
+	v7sb = (struct v7_super_block *) bh->b_data;
+	if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
+	    fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
+	    fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
+		return 0;
+
+	/* plausibility check on root inode: it is a directory,
+	   with a nonzero size that is a multiple of 16 */
+	if ((bh2 = sb_bread(sb, 2)) == NULL) {
+		return 0;
+	}
+
+	v7i = (struct sysv_inode *)(bh2->b_data + 64);
+	if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
+	    (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
+	    (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
+	    (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
+             sizeof (struct sysv_dir_entry))) {
+		brelse(bh2);
+		return 0;
+	}
+
+	brelse(bh2);
+	return 1;
+}
+
+static int v7_fill_super(struct super_block *sb, void *data, int silent)
+{
+	struct sysv_sb_info *sbi;
+	struct buffer_head *bh;
 
 	if (440 != sizeof (struct v7_super_block))
 		panic("V7 FS: bad super-block size");
@@ -454,7 +489,6 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
 	sbi->s_sb = sb;
 	sbi->s_block_base = 0;
 	sbi->s_type = FSTYPE_V7;
-	sbi->s_bytesex = BYTESEX_PDP;
 	sb->s_fs_info = sbi;
 	
 	sb_set_blocksize(sb, 512);
@@ -466,34 +500,26 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
 		goto failed;
 	}
 
-	/* plausibility check on superblock */
-	v7sb = (struct v7_super_block *) bh->b_data;
-	if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
-	    fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
-	    fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
-		goto failed;
+	/* Try PDP-11 UNIX */
+	sbi->s_bytesex = BYTESEX_PDP;
+	if (v7_sanity_check (sb, bh))
+		goto detected;
 
-	/* plausibility check on root inode: it is a directory,
-	   with a nonzero size that is a multiple of 16 */
-	if ((bh2 = sb_bread(sb, 2)) == NULL)
-		goto failed;
-	v7i = (struct sysv_inode *)(bh2->b_data + 64);
-	if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
-	    (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
-	    (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
-	    (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
-	     sizeof (struct sysv_dir_entry)))
-		goto failed;
-	brelse(bh2);
-	bh2 = NULL;
+	/* Try PC/IX, v7/x86 */
+	sbi->s_bytesex = BYTESEX_LE;
+	if (v7_sanity_check (sb, bh))
+		goto detected;
 
+	goto failed;
+
+detected:
 	sbi->s_bh1 = bh;
 	sbi->s_bh2 = bh;
 	if (complete_read_super(sb, silent, 1))
 		return 0;
 
 failed:
-	brelse(bh2);
+	printk("VFS: could not find a valid V7 on %s.\n", sb->s_id);
 	brelse(bh);
 	kfree(sbi);
 	return -EINVAL;
-- 
1.7.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] [fs/sysv] V7: Add support for non-PDP11 v7 filesystems
@ 2010-07-24 13:51 Al Viro
  2010-07-25 22:59 ` [PATCH] " Lubomir Rintel
  0 siblings, 1 reply; 8+ messages in thread
From: Al Viro @ 2010-07-24 13:51 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Lubomir Rintel, Linux Kernel Mailing List, Andrew Morton

On Mon, Jul 19, 2010 at 04:58:51PM +0200, Christoph Hellwig wrote:
> On Mon, Jul 19, 2010 at 07:16:42PM +0200, Lubomir Rintel wrote:
> > A mount-time option was added that makes it possible to override the
> > endianness and an attempt is made to autodetect it (which seems easy,
> > given the disk addresses are 3-byte.
> > 
> > No attempt is made to detect big-endian filesystems -- were there any?
> > Tested with PDP-11 v7 filesystems and PC-IX maintenance floppy.
> 
> Do you actually need the mount option?  We get away just fine with
> it for sysv filesystems.  And if not I'd be consistent and accept the
> options for both sysv and v7 filesystems.

Actually, it shouldn't be too hard to detect the damn thing even without magic.
Look - we always have the inode table starting at block 2, so on-disk root
inode is guaranteed to be found correctly.  Now, suppose we'd mistaken
l-e for pdp or vice versa; the half-words of i_size would get swapped.
What could pass both tests?  Suppose the right size is a * 65536 + b;
then we have: a and b are both multiples of 16 and at least one is non-zero.
So all we need is to reject root directories bigger than 1Mb.  And posted
patches do reject that (and lower than that, actually).

So I'd rather see a variant without that option.  Simply get both bh, then
try the same sanity checks with LE and PDP used for s_bytesex.  And use
one that works - we _know_ that it's impossible to have both pass at the
same time.

I'm fine with the rest of patch series as is; Lubomir, could you redo the
last one that way and resend?

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] [fs/sysv] V7: Add support for non-PDP11 v7 filesystems
@ 2010-07-22  1:17 Lubomir Rintel
  2010-07-22  1:18 ` [PATCH] " Lubomir Rintel
  0 siblings, 1 reply; 8+ messages in thread
From: Lubomir Rintel @ 2010-07-22  1:17 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Linux Kernel Mailing List, Andrew Morton

On Tue, 2010-07-20 at 12:41 +0200, Lubomir Rintel wrote:
> On Mon, 2010-07-19 at 16:58 +0200, Christoph Hellwig wrote:
... 
> > Do you actually need the mount option?  We get away just fine with
> > it for sysv filesystems.  And if not I'd be consistent and accept the
> > options for both sysv and v7 filesystems.
...
> Coherent seems to always use PDP-11 bytesex. I can not check at the
> time, but I'm almost sure it never run on such machines (was PC and 68k
> only?), so I suspect the coherent kernel might have always done the
> translation to native byte order. I think I have some coherent (for PC)
> floppies at home, so I can check tomorrow.

This was just partly correct. Coherent indeed run on PDP-11 (and not on
68k), but the PC version uses the very same bytesex as PDP-11 one,
translating the byte order on the fly (_canl() routine defined in
i386/as.inc file of Coherent 4.2.10 for i386 kernel is used).

Thus the mount option is really only useful with v7 filesystem and none
of those handled with sysv filesystem.

-- 
Flash is the Web2.0 version of blink and animated gifs.
                                     -- Stephen Smoogen


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-27  0:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-25 22:50 [PATCH] V7: Add support for non-PDP11 v7 filesystems Lubomir Rintel
2010-07-25 22:54 ` Lubomir Rintel
  -- strict thread matches above, loose matches on Subject: below --
2010-07-24 13:51 [PATCH 3/3] [fs/sysv] " Al Viro
2010-07-25 22:59 ` [PATCH] " Lubomir Rintel
2010-07-26  0:26   ` Randy Dunlap
2010-07-26 23:52   ` Andrew Morton
2010-07-27  0:19     ` Lubomir Rintel
2010-07-27  0:29       ` Andrew Morton
2010-07-22  1:17 [PATCH 3/3] [fs/sysv] " Lubomir Rintel
2010-07-22  1:18 ` [PATCH] " Lubomir Rintel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox