Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * inode.c |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | /* |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | int |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 19 | befs_check_inode(struct super_block *sb, befs_inode *raw_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 29 | "Inode has a bad magic header - inode = %lu", |
| 30 | (unsigned long)inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 " |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 39 | "VFS: %lu, Inode %lu", (unsigned long) |
| 40 | inode, (unsigned long)iaddr2blockno(sb, &ino_num)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | return BEFS_BAD_INODE; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * check flag |
| 46 | */ |
| 47 | |
| 48 | if (!(flags & BEFS_INODE_IN_USE)) { |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 49 | befs_error(sb, "inode is not used - inode = %lu", |
| 50 | (unsigned long)inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return BEFS_BAD_INODE; |
| 52 | } |
| 53 | |
| 54 | return BEFS_OK; |
| 55 | } |