blob: c36745d2b45f8439793be8e6379388da5d1d919b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Beregalov2b3fffe2009-04-07 21:21:42 -070011#include <asm/page.h> /* for PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include "befs.h"
14#include "super.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16/**
Luis de Bethencourt10145d62016-07-23 22:36:42 +100017 * befs_load_sb -- Read from disk and properly byteswap all the fields
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * of the befs superblock
19 *
20 *
21 *
22 *
23 */
24int
25befs_load_sb(struct super_block *sb, befs_super_block * disk_sb)
26{
Fabian Frederick038428f2015-04-16 12:46:20 -070027 struct befs_sb_info *befs_sb = BEFS_SB(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 /* Check the byte order of the filesystem */
Harvey Harrison152b95a2008-10-15 22:04:03 -070030 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 befs_sb->byte_order = BEFS_BYTESEX_LE;
Harvey Harrison152b95a2008-10-15 22:04:03 -070032 else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
33 befs_sb->byte_order = BEFS_BYTESEX_BE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
36 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
37 befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
38 befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size);
39 befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift);
40 befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks);
41 befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks);
42 befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size);
43
44 befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag);
45 befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift);
46 befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags);
47
Salah Triki6ea45582016-08-09 14:46:04 +010048 befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks);
51 befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start);
52 befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end);
53
54 befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir);
55 befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices);
56 befs_sb->nls = NULL;
57
58 return BEFS_OK;
59}
60
61int
62befs_check_sb(struct super_block *sb)
63{
Fabian Frederick038428f2015-04-16 12:46:20 -070064 struct befs_sb_info *befs_sb = BEFS_SB(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /* Check magic headers of super block */
67 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
68 || (befs_sb->magic2 != BEFS_SUPER_MAGIC2)
69 || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) {
70 befs_error(sb, "invalid magic header");
71 return BEFS_ERR;
72 }
73
74 /*
75 * Check blocksize of BEFS.
76 *
77 * Blocksize of BEFS is 1024, 2048, 4096 or 8192.
78 */
79
80 if ((befs_sb->block_size != 1024)
81 && (befs_sb->block_size != 2048)
82 && (befs_sb->block_size != 4096)
83 && (befs_sb->block_size != 8192)) {
84 befs_error(sb, "invalid blocksize: %u", befs_sb->block_size);
85 return BEFS_ERR;
86 }
87
88 if (befs_sb->block_size > PAGE_SIZE) {
89 befs_error(sb, "blocksize(%u) cannot be larger"
90 "than system pagesize(%lu)", befs_sb->block_size,
91 PAGE_SIZE);
92 return BEFS_ERR;
93 }
94
95 /*
96 * block_shift and block_size encode the same information
97 * in different ways as a consistency check.
98 */
99
100 if ((1 << befs_sb->block_shift) != befs_sb->block_size) {
101 befs_error(sb, "block_shift disagrees with block_size. "
102 "Corruption likely.");
103 return BEFS_ERR;
104 }
105
Luis de Bethencourtbbe1bd02016-08-09 22:23:36 +0100106
107 /* ag_shift also encodes the same information as blocks_per_ag in a
108 * different way, non-fatal consistency check
109 */
110 if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag)
111 befs_error(sb, "ag_shift disagrees with blocks_per_ag.");
112
Salah Triki6ea45582016-08-09 14:46:04 +0100113 if (befs_sb->log_start != befs_sb->log_end || befs_sb->flags == BEFS_DIRTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 befs_error(sb, "Filesystem not clean! There are blocks in the "
115 "journal. You must boot into BeOS and mount this volume "
116 "to make it clean.");
117 return BEFS_ERR;
118 }
119
120 return BEFS_OK;
121}