]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/befs/super.c
Linux 2.6.30-rc1
[net-next-2.6.git] / fs / befs / super.c
CommitLineData
1da177e4
LT
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.h"
13#include "super.h"
1da177e4
LT
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 /* Check the byte order of the filesystem */
152b95a1 29 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
1da177e4 30 befs_sb->byte_order = BEFS_BYTESEX_LE;
152b95a1
HH
31 else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
32 befs_sb->byte_order = BEFS_BYTESEX_BE;
1da177e4
LT
33
34 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
35 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
36 befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
37 befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size);
38 befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift);
39 befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks);
40 befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks);
41 befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size);
42
43 befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag);
44 befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift);
45 befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags);
46
47 befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks);
48 befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start);
49 befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end);
50
51 befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir);
52 befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices);
53 befs_sb->nls = NULL;
54
55 return BEFS_OK;
56}
57
58int
59befs_check_sb(struct super_block *sb)
60{
61 befs_sb_info *befs_sb = BEFS_SB(sb);
62
63 /* Check magic headers of super block */
64 if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
65 || (befs_sb->magic2 != BEFS_SUPER_MAGIC2)
66 || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) {
67 befs_error(sb, "invalid magic header");
68 return BEFS_ERR;
69 }
70
71 /*
72 * Check blocksize of BEFS.
73 *
74 * Blocksize of BEFS is 1024, 2048, 4096 or 8192.
75 */
76
77 if ((befs_sb->block_size != 1024)
78 && (befs_sb->block_size != 2048)
79 && (befs_sb->block_size != 4096)
80 && (befs_sb->block_size != 8192)) {
81 befs_error(sb, "invalid blocksize: %u", befs_sb->block_size);
82 return BEFS_ERR;
83 }
84
85 if (befs_sb->block_size > PAGE_SIZE) {
86 befs_error(sb, "blocksize(%u) cannot be larger"
87 "than system pagesize(%lu)", befs_sb->block_size,
88 PAGE_SIZE);
89 return BEFS_ERR;
90 }
91
92 /*
93 * block_shift and block_size encode the same information
94 * in different ways as a consistency check.
95 */
96
97 if ((1 << befs_sb->block_shift) != befs_sb->block_size) {
98 befs_error(sb, "block_shift disagrees with block_size. "
99 "Corruption likely.");
100 return BEFS_ERR;
101 }
102
103 if (befs_sb->log_start != befs_sb->log_end) {
104 befs_error(sb, "Filesystem not clean! There are blocks in the "
105 "journal. You must boot into BeOS and mount this volume "
106 "to make it clean.");
107 return BEFS_ERR;
108 }
109
110 return BEFS_OK;
111}