Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Alexander Beregalov | 2b3fffe | 2009-04-07 21:21:42 -0700 | [diff] [blame] | 11 | #include <asm/page.h> /* for PAGE_SIZE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #include "befs.h" |
| 14 | #include "super.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Luis de Bethencourt | 1167423 | 2016-08-09 22:24:09 +0100 | [diff] [blame] | 16 | /* |
Luis de Bethencourt | 10145d6 | 2016-07-23 22:36:42 +1000 | [diff] [blame] | 17 | * befs_load_sb -- Read from disk and properly byteswap all the fields |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * of the befs superblock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | int |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 21 | befs_load_sb(struct super_block *sb, befs_super_block *disk_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
Fabian Frederick | 038428f | 2015-04-16 12:46:20 -0700 | [diff] [blame] | 23 | struct befs_sb_info *befs_sb = BEFS_SB(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | /* Check the byte order of the filesystem */ |
Harvey Harrison | 152b95a | 2008-10-15 22:04:03 -0700 | [diff] [blame] | 26 | if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE) |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 27 | befs_sb->byte_order = BEFS_BYTESEX_LE; |
Harvey Harrison | 152b95a | 2008-10-15 22:04:03 -0700 | [diff] [blame] | 28 | else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE) |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 29 | befs_sb->byte_order = BEFS_BYTESEX_BE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Salah Triki | 6ea4558 | 2016-08-09 14:46:04 +0100 | [diff] [blame] | 44 | befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags); |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks); |
| 47 | befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start); |
| 48 | befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end); |
| 49 | |
| 50 | befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir); |
| 51 | befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices); |
| 52 | befs_sb->nls = NULL; |
| 53 | |
| 54 | return BEFS_OK; |
| 55 | } |
| 56 | |
| 57 | int |
| 58 | befs_check_sb(struct super_block *sb) |
| 59 | { |
Fabian Frederick | 038428f | 2015-04-16 12:46:20 -0700 | [diff] [blame] | 60 | struct befs_sb_info *befs_sb = BEFS_SB(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* Check magic headers of super block */ |
| 63 | if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1) |
| 64 | || (befs_sb->magic2 != BEFS_SUPER_MAGIC2) |
| 65 | || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) { |
| 66 | befs_error(sb, "invalid magic header"); |
| 67 | return BEFS_ERR; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Check blocksize of BEFS. |
| 72 | * |
| 73 | * Blocksize of BEFS is 1024, 2048, 4096 or 8192. |
| 74 | */ |
| 75 | |
| 76 | if ((befs_sb->block_size != 1024) |
| 77 | && (befs_sb->block_size != 2048) |
| 78 | && (befs_sb->block_size != 4096) |
| 79 | && (befs_sb->block_size != 8192)) { |
| 80 | befs_error(sb, "invalid blocksize: %u", befs_sb->block_size); |
| 81 | return BEFS_ERR; |
| 82 | } |
| 83 | |
| 84 | if (befs_sb->block_size > PAGE_SIZE) { |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 85 | befs_error(sb, "blocksize(%u) cannot be larger " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | "than system pagesize(%lu)", befs_sb->block_size, |
| 87 | PAGE_SIZE); |
| 88 | return BEFS_ERR; |
| 89 | } |
| 90 | |
| 91 | /* |
Luis de Bethencourt | 1167423 | 2016-08-09 22:24:09 +0100 | [diff] [blame] | 92 | * block_shift and block_size encode the same information |
| 93 | * in different ways as a consistency check. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | */ |
| 95 | |
| 96 | if ((1 << befs_sb->block_shift) != befs_sb->block_size) { |
| 97 | befs_error(sb, "block_shift disagrees with block_size. " |
| 98 | "Corruption likely."); |
| 99 | return BEFS_ERR; |
| 100 | } |
| 101 | |
Luis de Bethencourt | bbe1bd0 | 2016-08-09 22:23:36 +0100 | [diff] [blame] | 102 | |
| 103 | /* ag_shift also encodes the same information as blocks_per_ag in a |
| 104 | * different way, non-fatal consistency check |
| 105 | */ |
| 106 | if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag) |
| 107 | befs_error(sb, "ag_shift disagrees with blocks_per_ag."); |
| 108 | |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 109 | if (befs_sb->log_start != befs_sb->log_end || |
| 110 | befs_sb->flags == BEFS_DIRTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | befs_error(sb, "Filesystem not clean! There are blocks in the " |
Luis de Bethencourt | 103c0fb | 2016-08-09 22:51:44 +0100 | [diff] [blame] | 112 | "journal. You must boot into BeOS and mount this " |
| 113 | "volume to make it clean."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return BEFS_ERR; |
| 115 | } |
| 116 | |
| 117 | return BEFS_OK; |
| 118 | } |