2 * Copyright (c) 2012-2013 Paulo Alcantara <pcacjr@zytor.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "xfs_types.h"
28 #include "xfs_dinode.h"
30 xfs_dinode_t
*xfs_dinode_get_core(struct fs_info
*fs
, xfs_ino_t ino
)
36 xfs_debug("fs %p ino %lu", fs
, ino
);
38 blk
= ino_to_bytes(fs
, ino
) >> BLOCK_SHIFT(fs
);
39 offset
= XFS_INO_TO_OFFSET(XFS_INFO(fs
), ino
) << XFS_INFO(fs
)->inode_shift
;
40 if (offset
> BLOCK_SIZE(fs
)) {
41 xfs_error("Invalid inode offset in block!");
42 xfs_debug("offset: 0x%llx", offset
);
46 xfs_debug("blk %llu block offset 0x%llx", blk
, blk
<< BLOCK_SHIFT(fs
));
47 xfs_debug("inode offset in block (in bytes) is 0x%llx", offset
);
49 core
= (xfs_dinode_t
*)((uint8_t *)get_cache(fs
->fs_dev
, blk
) + offset
);
50 if (be16_to_cpu(core
->di_magic
) !=
51 be16_to_cpu(*(uint16_t *)XFS_DINODE_MAGIC
)) {
52 xfs_error("Inode core's magic number does not match!");
53 xfs_debug("magic number 0x%04x", (be16_to_cpu(core
->di_magic
)));