Changeset b65cae22 in mainline for uspace/lib/ext2
- Timestamp:
- 2011-02-16T20:21:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f483a15
- Parents:
- a2a1792
- Location:
- uspace/lib/ext2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext2/libext2_inode.c
ra2a1792 rb65cae22 36 36 #include "libext2.h" 37 37 #include "libext2_inode.h" 38 #include "libext2_superblock.h" 38 39 #include <byteorder.h> 39 40 … … 43 44 * @param inode pointer to inode 44 45 */ 45 inline uint 16_t ext2_inode_get_mode(ext2_inode_t *inode)46 inline uint32_t ext2_inode_get_mode(ext2_superblock_t *sb, ext2_inode_t *inode) 46 47 { 48 if (ext2_superblock_get_os(sb) == EXT2_SUPERBLOCK_OS_HURD) { 49 return ((uint32_t)uint16_t_le2host(inode->mode_high)) << 16 | 50 ((uint32_t)uint16_t_le2host(inode->mode)); 51 } 47 52 return uint16_t_le2host(inode->mode); 48 53 } … … 53 58 * @param inode pointer to inode 54 59 */ 55 inline uint32_t ext2_inode_get_user_id(ext2_ inode_t *inode)60 inline uint32_t ext2_inode_get_user_id(ext2_superblock_t *sb, ext2_inode_t *inode) 56 61 { 57 // TODO: use additional OS specific bits 62 uint32_t os = ext2_superblock_get_os(sb); 63 if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) { 64 return ((uint32_t)uint16_t_le2host(inode->user_id_high)) << 16 | 65 ((uint32_t)uint16_t_le2host(inode->user_id)); 66 } 58 67 return uint16_t_le2host(inode->user_id); 59 68 } … … 62 71 * Get size of file 63 72 * 73 * For regular files in revision 1 and later, the high 32 bits of 74 * file size are stored in inode->size_high and are 0 otherwise 75 * 64 76 * @param inode pointer to inode 65 77 */ 66 inline uint 32_t ext2_inode_get_size(ext2_inode_t *inode)78 inline uint64_t ext2_inode_get_size(ext2_superblock_t *sb, ext2_inode_t *inode) 67 79 { 68 // TODO: Directory ACLS! 69 return uint16_t_le2host(inode->size); 80 uint32_t major_rev = ext2_superblock_get_rev_major(sb); 81 uint32_t mode = ext2_inode_get_mode(sb, inode); 82 83 if (major_rev > 0 && mode & EXT2_INODE_MODE_FILE) { 84 return ((uint64_t)uint32_t_le2host(inode->size_high)) << 32 | 85 ((uint64_t)uint32_t_le2host(inode->size)); 86 } 87 return uint32_t_le2host(inode->size); 70 88 } 71 89 … … 73 91 * Get gid this inode belongs to 74 92 * 93 * For Linux and Hurd, the high 16 bits are stored in OS dependent part 94 * of inode structure 95 * 75 96 * @param inode pointer to inode 76 97 */ 77 inline uint32_t ext2_inode_get_group_id(ext2_ inode_t *inode)98 inline uint32_t ext2_inode_get_group_id(ext2_superblock_t *sb, ext2_inode_t *inode) 78 99 { 79 // TODO: use additional OS specific bits 100 uint32_t os = ext2_superblock_get_os(sb); 101 if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) { 102 return ((uint32_t)uint16_t_le2host(inode->group_id_high)) << 16 | 103 ((uint32_t)uint16_t_le2host(inode->group_id)); 104 } 80 105 return uint16_t_le2host(inode->group_id); 81 106 } … … 93 118 94 119 /** 95 * Get size of inode in 512 byte blocks 96 * TODO: clarify this 120 * Get number of 512-byte data blocks allocated for contents of the file 121 * represented by this inode. 122 * This should be multiple of block size unless fragments are used. 97 123 * 98 124 * @param inode pointer to inode … … 108 134 * @param inode pointer to inode 109 135 */ 110 111 136 inline uint32_t ext2_inode_get_flags(ext2_inode_t *inode) { 112 137 return uint32_t_le2host(inode->flags); -
uspace/lib/ext2/libext2_inode.h
ra2a1792 rb65cae22 38 38 39 39 #include <libblock.h> 40 #include "libext2_superblock.h" 40 41 41 42 typedef struct ext2_inode { … … 53 54 uint32_t double_indirect_block; 54 55 uint32_t triple_indirect_block; 55 } ext2_inode_t; 56 uint32_t version; 57 uint32_t file_acl; 58 union { 59 uint32_t dir_acl; 60 uint32_t size_high; // For regular files in version >= 1 61 } __attribute__ ((packed)); 62 uint8_t unused3[6]; 63 uint16_t mode_high; // Hurd only 64 uint16_t user_id_high; // Linux/Hurd only 65 uint16_t group_id_high; // Linux/Hurd only 66 } __attribute__ ((packed)) ext2_inode_t; 56 67 57 68 #define EXT2_INODE_MODE_FIFO 0x1000 … … 69 80 } ext2_inode_ref_t; 70 81 71 inline uint 16_t ext2_inode_get_mode(ext2_inode_t *);72 inline uint32_t ext2_inode_get_user_id(ext2_ inode_t *);73 inline uint 32_t ext2_inode_get_size(ext2_inode_t *);74 inline uint32_t ext2_inode_get_group_id(ext2_ inode_t *);82 inline uint32_t ext2_inode_get_mode(ext2_superblock_t *, ext2_inode_t *); 83 inline uint32_t ext2_inode_get_user_id(ext2_superblock_t *, ext2_inode_t *); 84 inline uint64_t ext2_inode_get_size(ext2_superblock_t *, ext2_inode_t *); 85 inline uint32_t ext2_inode_get_group_id(ext2_superblock_t *, ext2_inode_t *); 75 86 inline uint16_t ext2_inode_get_usage_count(ext2_inode_t *); 76 87 inline uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *); -
uspace/lib/ext2/libext2_superblock.h
ra2a1792 rb65cae22 78 78 #define EXT2_SUPERBLOCK_LAST_BYTE (EXT2_SUPERBLOCK_OFFSET + \ 79 79 EXT2_SUPERBLOCK_SIZE -1) 80 #define EXT2_SUPERBLOCK_OS_LINUX 0 81 #define EXT2_SUPERBLOCK_OS_HURD 1 80 82 81 83
Note:
See TracChangeset
for help on using the changeset viewer.