patch-2.4.10 linux/fs/reiserfs/super.c
Next file: linux/fs/reiserfs/tail_conversion.c
Previous file: linux/fs/reiserfs/stree.c
Back to the patch index
Back to the overall index
- Lines: 254
- Date:
Sat Sep 8 12:05:32 2001
- Orig file:
v2.4.9/linux/fs/reiserfs/super.c
- Orig date:
Tue Jul 3 17:08:21 2001
diff -u --recursive --new-file v2.4.9/linux/fs/reiserfs/super.c linux/fs/reiserfs/super.c
@@ -11,8 +11,6 @@
* NO WARRANTY
*/
-#ifdef __KERNEL__
-
#include <linux/config.h>
#include <linux/module.h>
#include <linux/sched.h>
@@ -22,26 +20,10 @@
#include <linux/locks.h>
#include <linux/init.h>
-#else
-
-#include "nokernel.h"
-#include <stdlib.h> // for simple_strtoul
-
-#endif
-
-#define SUPPORT_OLD_FORMAT
-
#define REISERFS_OLD_BLOCKSIZE 4096
#define REISERFS_SUPER_MAGIC_STRING_OFFSET_NJ 20
-#if 0
-// this one is not used currently
-inline void reiserfs_mark_buffer_dirty (struct buffer_head * bh, int flag)
-{
- mark_buffer_dirty (bh, flag);
-}
-#endif
//
// a portion of this function, particularly the VFS interface portion,
@@ -367,98 +349,34 @@
free, SB_FREE_BLOCKS (s));
}
-#ifdef SUPPORT_OLD_FORMAT
-/* support old disk layout */
-static int read_old_super_block (struct super_block * s, int size)
-{
- struct buffer_head * bh;
- struct reiserfs_super_block * rs;
- printk("read_old_super_block: try to find super block in old location\n");
- /* there are only 4k-sized blocks in v3.5.10 */
- if (size != REISERFS_OLD_BLOCKSIZE)
- set_blocksize(s->s_dev, REISERFS_OLD_BLOCKSIZE);
- bh = bread (s->s_dev,
- REISERFS_OLD_DISK_OFFSET_IN_BYTES / REISERFS_OLD_BLOCKSIZE,
- REISERFS_OLD_BLOCKSIZE);
- if (!bh) {
- printk("read_old_super_block: unable to read superblock on dev %s\n", kdevname(s->s_dev));
- return 1;
- }
-
- rs = (struct reiserfs_super_block *)bh->b_data;
- if (strncmp (rs->s_magic, REISERFS_SUPER_MAGIC_STRING, strlen ( REISERFS_SUPER_MAGIC_STRING))) {
- /* pre-journaling version check */
- if(!strncmp((char*)rs + REISERFS_SUPER_MAGIC_STRING_OFFSET_NJ,
- REISERFS_SUPER_MAGIC_STRING, strlen(REISERFS_SUPER_MAGIC_STRING))) {
- printk("read_old_super_blockr: a pre-journaling reiserfs filesystem isn't suitable there.\n");
- brelse(bh);
- return 1;
- }
-
- brelse (bh);
- printk ("read_old_super_block: can't find a reiserfs filesystem on dev %s.\n", kdevname(s->s_dev));
- return 1;
- }
-
- if(REISERFS_OLD_BLOCKSIZE != le16_to_cpu (rs->s_blocksize)) {
- printk("read_old_super_block: blocksize mismatch, super block corrupted\n");
- brelse(bh);
- return 1;
- }
-
- s->s_blocksize = REISERFS_OLD_BLOCKSIZE;
- s->s_blocksize_bits = 0;
- while ((1 << s->s_blocksize_bits) != s->s_blocksize)
- s->s_blocksize_bits ++;
-
- SB_BUFFER_WITH_SB (s) = bh;
- SB_DISK_SUPER_BLOCK (s) = rs;
- s->s_op = &reiserfs_sops;
- return 0;
-}
-#endif
-
-//
-// FIXME: mounting old filesystems we _must_ change magic string to
-// make then unmountable by reiserfs of 3.5.x
-//
-static int read_super_block (struct super_block * s, int size)
+static int read_super_block (struct super_block * s, int size, int offset)
{
struct buffer_head * bh;
struct reiserfs_super_block * rs;
- bh = bread (s->s_dev, REISERFS_DISK_OFFSET_IN_BYTES / size, size);
+
+ bh = bread (s->s_dev, offset / size, size);
if (!bh) {
- printk("read_super_block: unable to read superblock on dev %s\n", kdevname(s->s_dev));
+ printk ("read_super_block: "
+ "bread failed (dev %s, block %d, size %d)\n",
+ kdevname (s->s_dev), offset / size, size);
return 1;
}
rs = (struct reiserfs_super_block *)bh->b_data;
if (!is_reiserfs_magic_string (rs)) {
- printk ("read_super_block: can't find a reiserfs filesystem on dev %s\n",
- kdevname(s->s_dev));
+ printk ("read_super_block: "
+ "can't find a reiserfs filesystem on (dev %s, block %lu, size %d)\n",
+ kdevname(s->s_dev), bh->b_blocknr, size);
brelse (bh);
return 1;
}
//
- // ok, reiserfs signature (old or new) found in 64-th 1k block of
- // the device
+ // ok, reiserfs signature (old or new) found in at the given offset
//
-
-#ifndef SUPPORT_OLD_FORMAT
- // with SUPPORT_OLD_FORMAT undefined - detect old format by
- // checking super block version
- if (le16_to_cpu (rs->s_version) != REISERFS_VERSION_2) {
- brelse (bh);
- printk ("read_super_block: unsupported version (%d) of reiserfs found on dev %s\n",
- le16_to_cpu (rs->s_version), kdevname(s->s_dev));
- return 1;
- }
-#endif
-
s->s_blocksize = le16_to_cpu (rs->s_blocksize);
s->s_blocksize_bits = 0;
while ((1 << s->s_blocksize_bits) != s->s_blocksize)
@@ -468,17 +386,22 @@
if (s->s_blocksize != size)
set_blocksize (s->s_dev, s->s_blocksize);
- bh = reiserfs_bread (s->s_dev, REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize, s->s_blocksize);
+
+ bh = bread (s->s_dev, offset / s->s_blocksize, s->s_blocksize);
if (!bh) {
- printk("read_super_block: unable to read superblock on dev %s\n", kdevname(s->s_dev));
+ printk ("read_super_block: "
+ "bread failed (dev %s, block %d, size %d)\n",
+ kdevname (s->s_dev), offset / size, size);
return 1;
}
rs = (struct reiserfs_super_block *)bh->b_data;
if (!is_reiserfs_magic_string (rs) ||
le16_to_cpu (rs->s_blocksize) != s->s_blocksize) {
+ printk ("read_super_block: "
+ "can't find a reiserfs filesystem on (dev %s, block %lu, size %d)\n",
+ kdevname(s->s_dev), bh->b_blocknr, size);
brelse (bh);
- printk ("read_super_block: can't find a reiserfs filesystem on dev %s.\n", kdevname(s->s_dev));
return 1;
}
/* must check to be sure we haven't pulled an old format super out
@@ -489,7 +412,8 @@
if (bh->b_blocknr >= le32_to_cpu(rs->s_journal_block) &&
bh->b_blocknr < (le32_to_cpu(rs->s_journal_block) + JOURNAL_BLOCK_COUNT)) {
brelse(bh) ;
- printk("super-459: read_super_block: super found at block %lu is within its own log. "
+ printk("super-459: read_super_block: "
+ "super found at block %lu is within its own log. "
"It must not be of this format type.\n", bh->b_blocknr) ;
return 1 ;
}
@@ -504,6 +428,8 @@
return 0;
}
+
+
/* after journal replay, reread all bitmap and super blocks */
static int reread_meta_blocks(struct super_block *s) {
int i ;
@@ -712,15 +638,12 @@
}
/* read block (64-th 1k block), which can contain reiserfs super block */
- if (read_super_block (s, size)) {
-#ifdef SUPPORT_OLD_FORMAT
+ if (read_super_block (s, size, REISERFS_DISK_OFFSET_IN_BYTES)) {
// try old format (undistributed bitmap, super block in 8-th 1k block of a device)
- if(read_old_super_block(s,size))
+ if (read_super_block (s, size, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
goto error;
else
old_format = 1;
-#endif
- goto error ;
}
s->u.reiserfs_sb.s_mount_state = le16_to_cpu (SB_DISK_SUPER_BLOCK (s)->s_state); /* journal victim */
@@ -779,16 +702,23 @@
if (!(s->s_flags & MS_RDONLY)) {
struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
+ int old_magic;
+
+ old_magic = strncmp (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING,
+ strlen ( REISER2FS_SUPER_MAGIC_STRING));
+ if( old_magic && le16_to_cpu(rs->s_version) != 0 ) {
+ dput(s->s_root) ;
+ s->s_root = NULL ;
+ reiserfs_warning("reiserfs: wrong version/magic combination in the super-block\n") ;
+ goto error ;
+ }
journal_begin(&th, s, 1) ;
reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
rs->s_state = cpu_to_le16 (REISERFS_ERROR_FS);
- if (strncmp (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING,
- strlen ( REISER2FS_SUPER_MAGIC_STRING))) {
- if (le16_to_cpu(rs->s_version) != 0)
- BUG ();
+ if ( old_magic ) {
// filesystem created under 3.5.x found
if (!old_format_only (s)) {
reiserfs_warning("reiserfs: converting 3.5.x filesystem to the new format\n") ;
@@ -866,8 +796,6 @@
return 0;
}
-#ifdef __KERNEL__
-
static DECLARE_FSTYPE_DEV(reiserfs_fs_type,"reiserfs",reiserfs_read_super);
//
@@ -890,8 +818,6 @@
module_init(init_reiserfs_fs) ;
module_exit(exit_reiserfs_fs) ;
-
-#endif
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)