1/* 2 * super.c 3 * 4 * Copyright (C) 2001-2002 Will Dyson <will_dyson@pobox.com> 5 * 6 * Licensed under the GNU GPL. See the file COPYING for details. 7 * 8 */ 9 10#include <linux/fs.h> 11 12#include "befs_fs.h" 13#include "endian.h" 14 15/** 16 * load_befs_sb -- Read from disk and properly byteswap all the fields 17 * of the befs superblock 18 * 19 * 20 * 21 * 22 */ 23int 24befs_load_sb(struct super_block *sb, befs_super_block * disk_sb) 25{ 26 befs_sb_info *befs_sb = BEFS_SB(sb); 27 28 /* byte_order is special, no byte-swap */ 29 befs_sb->byte_order = disk_sb->fs_byte_order; 30 31 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1); 32 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2); 33 befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3); 34 befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size); 35 befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift); 36 befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks); 37 befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks); 38 befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size); 39 40 befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag); 41 befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift); 42 befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags); 43 44 befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks); 45 befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start); 46 befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end); 47 48 befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir); 49 befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices); 50 befs_sb->nls = NULL; 51 52 return BEFS_OK; 53} 54 55int 56befs_check_sb(struct super_block *sb) 57{ 58 befs_sb_info *befs_sb = BEFS_SB(sb); 59 60 /* Check magic headers of super block */ 61 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1) 62 || (befs_sb->magic2 != BEFS_SUPER_MAGIC2) 63 || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) { 64 befs_error(sb, "invalid magic header"); 65 return BEFS_ERR; 66 } 67 68 /* 69 * Check blocksize of BEFS. 70 * 71 * Blocksize of BEFS is 1024, 2048, 4096 or 8192. 72 */ 73 74 if ((befs_sb->block_size != 1024) 75 && (befs_sb->block_size != 2048) 76 && (befs_sb->block_size != 4096) 77 && (befs_sb->block_size != 8192)) { 78 befs_error(sb, "invalid blocksize: %u", befs_sb->block_size); 79 return BEFS_ERR; 80 } 81 82 if (befs_sb->block_size > PAGE_SIZE) { 83 befs_error(sb, "blocksize(%u) cannot be larger" 84 "than system pagesize(%lu)", befs_sb->block_size, 85 PAGE_SIZE); 86 return BEFS_ERR; 87 } 88 89 /* 90 * block_shift and block_size encode the same information 91 * in different ways as a consistency check. 92 */ 93 94 if ((1 << befs_sb->block_shift) != befs_sb->block_size) { 95 befs_error(sb, "block_shift disagrees with block_size. " 96 "Corruption likely."); 97 return BEFS_ERR; 98 } 99 100 if (befs_sb->log_start != befs_sb->log_end) { 101 befs_error(sb, "Filesystem not clean! There are blocks in the " 102 "journal. You must boot into BeOS and mount this volume " 103 "to make it clean."); 104 return BEFS_ERR; 105 } 106 107 return BEFS_OK; 108} 109