| 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 | #ifndef LIBEXT4_LIBEXT4_INODE_H_
|
|---|
| 34 | #define LIBEXT4_LIBEXT4_INODE_H_
|
|---|
| 35 |
|
|---|
| 36 | #include <libblock.h>
|
|---|
| 37 | #include <sys/types.h>
|
|---|
| 38 |
|
|---|
| 39 | #define EXT4_DIRECT_BLOCK_COUNT 12
|
|---|
| 40 | #define EXT4_INDIRECT_BLOCK EXT4_DIRECT_BLOCK_COUNT
|
|---|
| 41 | #define EXT4_DOUBLE_INDIRECT_BLOCK (EXT4_INDIRECT_BLOCK + 1)
|
|---|
| 42 | #define EXT4_TRIPPLE_INDIRECT_BLOCK (EXT4_DOUBLE_INDIRECT_BLOCK + 1)
|
|---|
| 43 | #define EXT4_INODE_BLOCKS (EXT4_TRIPPLE_INDIRECT_BLOCK + 1)
|
|---|
| 44 |
|
|---|
| 45 | /*
|
|---|
| 46 | * Structure of an inode on the disk
|
|---|
| 47 | */
|
|---|
| 48 | typedef struct ext4_inode {
|
|---|
| 49 | uint16_t mode; // File mode
|
|---|
| 50 | uint16_t uid; // Low 16 bits of owner uid
|
|---|
| 51 | uint32_t size_lo; // Size in bytes
|
|---|
| 52 | uint32_t acess_time; // Access time
|
|---|
| 53 | uint32_t change_inode_time; // Inode change time
|
|---|
| 54 | uint32_t modification_time; // Modification time
|
|---|
| 55 | uint32_t deletion_time; // Deletion time
|
|---|
| 56 | uint16_t gid; // Low 16 bits of group id
|
|---|
| 57 | uint16_t links_count; // Links count
|
|---|
| 58 | uint32_t blocks_count_lo; // Blocks count
|
|---|
| 59 | uint32_t flags; // File flags
|
|---|
| 60 | uint32_t unused_osd1; // OS dependent - not used in HelenOS
|
|---|
| 61 | uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
|
|---|
| 62 | uint32_t generation; // File version (for NFS)
|
|---|
| 63 | uint32_t file_acl_lo; // File ACL
|
|---|
| 64 | uint32_t size_hi;
|
|---|
| 65 | uint32_t obso_faddr; // Obsoleted fragment address
|
|---|
| 66 | uint32_t unused_osd2[3]; // OS dependent - not used in HelenOS
|
|---|
| 67 | uint16_t extra_isize;
|
|---|
| 68 | uint16_t pad1;
|
|---|
| 69 | uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
|
|---|
| 70 | uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
|
|---|
| 71 | uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
|
|---|
| 72 | uint32_t crtime; // File creation time
|
|---|
| 73 | uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
|
|---|
| 74 | uint32_t version_hi; // High 32 bits for 64-bit version
|
|---|
| 75 | } __attribute__ ((packed)) ext4_inode_t;
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | #define EXT4_INODE_ROOT_INDEX 2
|
|---|
| 79 |
|
|---|
| 80 | typedef struct ext4_inode_ref {
|
|---|
| 81 | block_t *block; // Reference to a block containing this inode
|
|---|
| 82 | ext4_inode_t *inode;
|
|---|
| 83 | uint32_t index; // Index number of this inode
|
|---|
| 84 | } ext4_inode_ref_t;
|
|---|
| 85 |
|
|---|
| 86 | /*
|
|---|
| 87 | extern uint16_t ext4_inode_get_mode(ext4_inode_t *);
|
|---|
| 88 | extern uint32_t ext4_inode_get_uid(ext4_inode_t *);
|
|---|
| 89 | */
|
|---|
| 90 | extern uint64_t ext4_inode_get_size(ext4_inode_t *);
|
|---|
| 91 | /*
|
|---|
| 92 | extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
|
|---|
| 93 | extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
|
|---|
| 94 | extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
|
|---|
| 95 | extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
|
|---|
| 96 | extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
|
|---|
| 97 | */
|
|---|
| 98 | extern uint16_t ext4_inode_get_links_count(ext4_inode_t *);
|
|---|
| 99 | /*
|
|---|
| 100 | extern uint64_t ext4_inode_get_blocks_count(ext4_inode_t *);
|
|---|
| 101 | extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
|
|---|
| 102 | */
|
|---|
| 103 |
|
|---|
| 104 | /*
|
|---|
| 105 | uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
|
|---|
| 106 | uint32_t generation;
|
|---|
| 107 | uint32_t file_acl_lo; // File ACL
|
|---|
| 108 | uint16_t extra_isize;
|
|---|
| 109 | uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
|
|---|
| 110 | uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
|
|---|
| 111 | uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
|
|---|
| 112 | uint32_t crtime; // File creation time
|
|---|
| 113 | uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
|
|---|
| 114 | uint32_t version_hi; // High 32 bits for 64-bit version
|
|---|
| 115 | */
|
|---|
| 116 |
|
|---|
| 117 | #endif
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * @}
|
|---|
| 121 | */
|
|---|