Loading...
1/*
2 * inode.c
3 *
4 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
5 */
6
7#include <linux/fs.h>
8
9#include "befs.h"
10#include "inode.h"
11
12/*
13 Validates the correctness of the befs inode
14 Returns BEFS_OK if the inode should be used, otherwise
15 returns BEFS_BAD_INODE
16*/
17int
18befs_check_inode(struct super_block *sb, befs_inode * raw_inode,
19 befs_blocknr_t inode)
20{
21 u32 magic1 = fs32_to_cpu(sb, raw_inode->magic1);
22 befs_inode_addr ino_num = fsrun_to_cpu(sb, raw_inode->inode_num);
23 u32 flags = fs32_to_cpu(sb, raw_inode->flags);
24
25 /* check magic header. */
26 if (magic1 != BEFS_INODE_MAGIC1) {
27 befs_error(sb,
28 "Inode has a bad magic header - inode = %lu", inode);
29 return BEFS_BAD_INODE;
30 }
31
32 /*
33 * Sanity check2: inodes store their own block address. Check it.
34 */
35 if (inode != iaddr2blockno(sb, &ino_num)) {
36 befs_error(sb, "inode blocknr field disagrees with vfs "
37 "VFS: %lu, Inode %lu",
38 inode, iaddr2blockno(sb, &ino_num));
39 return BEFS_BAD_INODE;
40 }
41
42 /*
43 * check flag
44 */
45
46 if (!(flags & BEFS_INODE_IN_USE)) {
47 befs_error(sb, "inode is not used - inode = %lu", inode);
48 return BEFS_BAD_INODE;
49 }
50
51 return BEFS_OK;
52}
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * inode.c
4 *
5 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
6 */
7
8#include <linux/fs.h>
9
10#include "befs.h"
11#include "inode.h"
12
13/*
14 * Validates the correctness of the befs inode
15 * Returns BEFS_OK if the inode should be used, otherwise
16 * returns BEFS_BAD_INODE
17 */
18int
19befs_check_inode(struct super_block *sb, befs_inode *raw_inode,
20 befs_blocknr_t inode)
21{
22 u32 magic1 = fs32_to_cpu(sb, raw_inode->magic1);
23 befs_inode_addr ino_num = fsrun_to_cpu(sb, raw_inode->inode_num);
24 u32 flags = fs32_to_cpu(sb, raw_inode->flags);
25
26 /* check magic header. */
27 if (magic1 != BEFS_INODE_MAGIC1) {
28 befs_error(sb,
29 "Inode has a bad magic header - inode = %lu",
30 (unsigned long)inode);
31 return BEFS_BAD_INODE;
32 }
33
34 /*
35 * Sanity check2: inodes store their own block address. Check it.
36 */
37 if (inode != iaddr2blockno(sb, &ino_num)) {
38 befs_error(sb, "inode blocknr field disagrees with vfs "
39 "VFS: %lu, Inode %lu", (unsigned long)
40 inode, (unsigned long)iaddr2blockno(sb, &ino_num));
41 return BEFS_BAD_INODE;
42 }
43
44 /*
45 * check flag
46 */
47
48 if (!(flags & BEFS_INODE_IN_USE)) {
49 befs_error(sb, "inode is not used - inode = %lu",
50 (unsigned long)inode);
51 return BEFS_BAD_INODE;
52 }
53
54 return BEFS_OK;
55}