Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * super.c
0003  *
0004  * Copyright (C) 2001-2002 Will Dyson <will_dyson@pobox.com>
0005  *
0006  * Licensed under the GNU GPL. See the file COPYING for details.
0007  *
0008  */
0009 
0010 #include <linux/fs.h>
0011 #include <asm/page.h> /* for PAGE_SIZE */
0012 
0013 #include "befs.h"
0014 #include "super.h"
0015 
0016 /*
0017  * befs_load_sb -- Read from disk and properly byteswap all the fields
0018  * of the befs superblock
0019  */
0020 int
0021 befs_load_sb(struct super_block *sb, befs_super_block *disk_sb)
0022 {
0023     struct befs_sb_info *befs_sb = BEFS_SB(sb);
0024 
0025     /* Check the byte order of the filesystem */
0026     if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
0027         befs_sb->byte_order = BEFS_BYTESEX_LE;
0028     else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
0029         befs_sb->byte_order = BEFS_BYTESEX_BE;
0030 
0031     befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
0032     befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
0033     befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
0034     befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size);
0035     befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift);
0036     befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks);
0037     befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks);
0038     befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size);
0039 
0040     befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag);
0041     befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift);
0042     befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags);
0043 
0044     befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags);
0045 
0046     befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks);
0047     befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start);
0048     befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end);
0049 
0050     befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir);
0051     befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices);
0052     befs_sb->nls = NULL;
0053 
0054     return BEFS_OK;
0055 }
0056 
0057 int
0058 befs_check_sb(struct super_block *sb)
0059 {
0060     struct befs_sb_info *befs_sb = BEFS_SB(sb);
0061 
0062     /* Check magic headers of super block */
0063     if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
0064         || (befs_sb->magic2 != BEFS_SUPER_MAGIC2)
0065         || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) {
0066         befs_error(sb, "invalid magic header");
0067         return BEFS_ERR;
0068     }
0069 
0070     /*
0071      * Check blocksize of BEFS.
0072      *
0073      * Blocksize of BEFS is 1024, 2048, 4096 or 8192.
0074      */
0075 
0076     if ((befs_sb->block_size != 1024)
0077         && (befs_sb->block_size != 2048)
0078         && (befs_sb->block_size != 4096)
0079         && (befs_sb->block_size != 8192)) {
0080         befs_error(sb, "invalid blocksize: %u", befs_sb->block_size);
0081         return BEFS_ERR;
0082     }
0083 
0084     if (befs_sb->block_size > PAGE_SIZE) {
0085         befs_error(sb, "blocksize(%u) cannot be larger "
0086                "than system pagesize(%lu)", befs_sb->block_size,
0087                PAGE_SIZE);
0088         return BEFS_ERR;
0089     }
0090 
0091     /*
0092      * block_shift and block_size encode the same information
0093      * in different ways as a consistency check.
0094      */
0095 
0096     if ((1 << befs_sb->block_shift) != befs_sb->block_size) {
0097         befs_error(sb, "block_shift disagrees with block_size. "
0098                "Corruption likely.");
0099         return BEFS_ERR;
0100     }
0101 
0102 
0103     /* ag_shift also encodes the same information as blocks_per_ag in a
0104      * different way, non-fatal consistency check
0105      */
0106     if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag)
0107         befs_error(sb, "ag_shift disagrees with blocks_per_ag.");
0108 
0109     if (befs_sb->log_start != befs_sb->log_end ||
0110         befs_sb->flags == BEFS_DIRTY) {
0111         befs_error(sb, "Filesystem not clean! There are blocks in the "
0112                "journal. You must boot into BeOS and mount this "
0113                "volume to make it clean.");
0114         return BEFS_ERR;
0115     }
0116 
0117     return BEFS_OK;
0118 }