Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * inode.c
0004  *
0005  * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
0006  */
0007 
0008 #include <linux/fs.h>
0009 
0010 #include "befs.h"
0011 #include "inode.h"
0012 
0013 /*
0014  * Validates the correctness of the befs inode
0015  * Returns BEFS_OK if the inode should be used, otherwise
0016  * returns BEFS_BAD_INODE
0017  */
0018 int
0019 befs_check_inode(struct super_block *sb, befs_inode *raw_inode,
0020          befs_blocknr_t inode)
0021 {
0022     u32 magic1 = fs32_to_cpu(sb, raw_inode->magic1);
0023     befs_inode_addr ino_num = fsrun_to_cpu(sb, raw_inode->inode_num);
0024     u32 flags = fs32_to_cpu(sb, raw_inode->flags);
0025 
0026     /* check magic header. */
0027     if (magic1 != BEFS_INODE_MAGIC1) {
0028         befs_error(sb,
0029                "Inode has a bad magic header - inode = %lu",
0030                (unsigned long)inode);
0031         return BEFS_BAD_INODE;
0032     }
0033 
0034     /*
0035      * Sanity check2: inodes store their own block address. Check it.
0036      */
0037     if (inode != iaddr2blockno(sb, &ino_num)) {
0038         befs_error(sb, "inode blocknr field disagrees with vfs "
0039                "VFS: %lu, Inode %lu", (unsigned long)
0040                inode, (unsigned long)iaddr2blockno(sb, &ino_num));
0041         return BEFS_BAD_INODE;
0042     }
0043 
0044     /*
0045      * check flag
0046      */
0047 
0048     if (!(flags & BEFS_INODE_IN_USE)) {
0049         befs_error(sb, "inode is not used - inode = %lu",
0050                (unsigned long)inode);
0051         return BEFS_BAD_INODE;
0052     }
0053 
0054     return BEFS_OK;
0055 }