Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * inode.c |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | /* |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | int |
Luis de Bethencourt | 85a06b3 | 2016-08-14 17:29:47 +0100 | [diff] [blame] | 18 | befs_check_inode(struct super_block *sb, befs_inode *raw_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 28 | "Inode has a bad magic header - inode = %lu", |
| 29 | (unsigned long)inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | return BEFS_BAD_INODE; |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Sanity check2: inodes store their own block address. Check it. |
| 35 | */ |
| 36 | if (inode != iaddr2blockno(sb, &ino_num)) { |
| 37 | befs_error(sb, "inode blocknr field disagrees with vfs " |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 38 | "VFS: %lu, Inode %lu", (unsigned long) |
| 39 | inode, (unsigned long)iaddr2blockno(sb, &ino_num)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | return BEFS_BAD_INODE; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * check flag |
| 45 | */ |
| 46 | |
| 47 | if (!(flags & BEFS_INODE_IN_USE)) { |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 48 | befs_error(sb, "inode is not used - inode = %lu", |
| 49 | (unsigned long)inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return BEFS_BAD_INODE; |
| 51 | } |
| 52 | |
| 53 | return BEFS_OK; |
| 54 | } |