[eb91db7] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Frantisek Princ
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libext4
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file libext4_inode.c
|
---|
[9875711] | 35 | * @brief Ext4 inode operations.
|
---|
[eb91db7] | 36 | */
|
---|
| 37 |
|
---|
[9c0c0e1] | 38 | #include <byteorder.h>
|
---|
[3711e7e] | 39 | #include "libext4.h"
|
---|
[6c501f8] | 40 |
|
---|
[9b9d37bb] | 41 | uint32_t ext4_inode_get_mode(ext4_superblock_t *sb, ext4_inode_t *inode)
|
---|
| 42 | {
|
---|
| 43 | if (ext4_superblock_get_creator_os(sb) == EXT4_SUPERBLOCK_OS_HURD) {
|
---|
| 44 | return ((uint32_t)uint16_t_le2host(inode->osd2.hurd2.mode_high)) << 16 |
|
---|
| 45 | ((uint32_t)uint16_t_le2host(inode->mode));
|
---|
| 46 | }
|
---|
| 47 | return uint16_t_le2host(inode->mode);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | bool ext4_inode_is_type(ext4_superblock_t *sb, ext4_inode_t *inode, uint32_t type)
|
---|
| 51 | {
|
---|
| 52 | uint32_t mode = ext4_inode_get_mode(sb, inode);
|
---|
| 53 | return (mode & EXT4_INODE_MODE_TYPE_MASK) == type;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[3712434] | 56 | /*
|
---|
| 57 | uint32_t ext4_inode_get_uid(ext4_inode_t *inode)
|
---|
| 58 | */
|
---|
| 59 |
|
---|
[9b9d37bb] | 60 | uint64_t ext4_inode_get_size(ext4_superblock_t *sb, ext4_inode_t *inode)
|
---|
[3712434] | 61 | {
|
---|
[9b9d37bb] | 62 | uint32_t major_rev = ext4_superblock_get_rev_level(sb);
|
---|
| 63 |
|
---|
| 64 | if (major_rev > 0 && ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)) {
|
---|
| 65 | return ((uint64_t)uint32_t_le2host(inode->size_hi)) << 32 |
|
---|
| 66 | ((uint64_t)uint32_t_le2host(inode->size_lo));
|
---|
| 67 | }
|
---|
| 68 | return uint32_t_le2host(inode->size_lo);
|
---|
[3712434] | 69 | }
|
---|
| 70 |
|
---|
| 71 | /*
|
---|
| 72 | extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
|
---|
| 73 | extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
|
---|
| 74 | extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
|
---|
| 75 | extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
|
---|
| 76 | extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | uint16_t ext4_inode_get_links_count(ext4_inode_t *inode)
|
---|
[6c501f8] | 80 | {
|
---|
[9c0c0e1] | 81 | return uint16_t_le2host(inode->links_count);
|
---|
[6c501f8] | 82 | }
|
---|
| 83 |
|
---|
[3712434] | 84 | /*
|
---|
| 85 | extern uint64_t ext4_inode_get_blocks_count(ext4_inode_t *);
|
---|
| 86 | extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
|
---|
| 87 | */
|
---|
[eb91db7] | 88 |
|
---|
[9b9d37bb] | 89 | uint32_t ext4_inode_get_direct_block(ext4_inode_t *inode, uint8_t idx)
|
---|
| 90 | {
|
---|
| 91 | assert(idx < EXT4_INODE_DIRECT_BLOCK_COUNT);
|
---|
| 92 | return uint32_t_le2host(inode->blocks[idx]);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | uint32_t ext4_inode_get_indirect_block(ext4_inode_t *inode, uint8_t idx)
|
---|
| 96 | {
|
---|
| 97 | assert(idx < EXT4_INODE_INDIRECT_BLOCK_COUNT);
|
---|
| 98 | return uint32_t_le2host(inode->blocks[idx + EXT4_INODE_INDIRECT_BLOCK]);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[eb91db7] | 101 | /**
|
---|
| 102 | * @}
|
---|
| 103 | */
|
---|