source: mainline/uspace/lib/ext4/libext4_inode.h@ 1a7756a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1a7756a was 1a7756a, checked in by Frantisek Princ <frantisek.princ@…>, 14 years ago

support for reading more complex extents (tree with nonzero depth)

  • Property mode set to 100644
File size: 7.7 KB
Line 
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#include "libext4_extent.h"
39#include "libext4_superblock.h"
40
41
42#define EXT4_INODE_DIRECT_BLOCK_COUNT 12
43#define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
44#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
45#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
46#define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
47#define EXT4_INODE_INDIRECT_BLOCK_COUNT (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
48
49/*
50 * Structure of an inode on the disk
51 */
52typedef struct ext4_inode {
53 uint16_t mode; // File mode
54 uint16_t uid; // Low 16 bits of owner uid
55 uint32_t size_lo; // Size in bytes
56 uint32_t acess_time; // Access time
57 uint32_t change_inode_time; // Inode change time
58 uint32_t modification_time; // Modification time
59 uint32_t deletion_time; // Deletion time
60 uint16_t gid; // Low 16 bits of group id
61 uint16_t links_count; // Links count
62 uint32_t blocks_count_lo; // Blocks count
63 uint32_t flags; // File flags
64 uint32_t unused_osd1; // OS dependent - not used in HelenOS
65 uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
66 uint32_t generation; // File version (for NFS)
67 uint32_t file_acl_lo; // File ACL
68 uint32_t size_hi;
69 uint32_t obso_faddr; // Obsoleted fragment address
70 union {
71 struct {
72 uint16_t blocks_high; /* were l_i_reserved1 */
73 uint16_t file_acl_high;
74 uint16_t uid_high; /* these 2 fields */
75 uint16_t gid_high; /* were reserved2[0] */
76 uint32_t reserved2;
77 } linux2;
78 struct {
79 uint16_t reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
80 uint16_t mode_high;
81 uint16_t uid_high;
82 uint16_t gid_high;
83 uint32_t author;
84 } hurd2;
85 struct {
86 uint16_t reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
87 uint16_t file_acl_high;
88 uint32_t reserved2[2];
89 } masix2;
90 } __attribute__ ((packed)) osd2;
91
92 uint16_t extra_isize;
93 uint16_t pad1;
94 uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
95 uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
96 uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
97 uint32_t crtime; // File creation time
98 uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
99 uint32_t version_hi; // High 32 bits for 64-bit version
100} __attribute__ ((packed)) ext4_inode_t;
101
102#define EXT4_INODE_MODE_FIFO 0x1000
103#define EXT4_INODE_MODE_CHARDEV 0x2000
104#define EXT4_INODE_MODE_DIRECTORY 0x4000
105#define EXT4_INODE_MODE_BLOCKDEV 0x6000
106#define EXT4_INODE_MODE_FILE 0x8000
107#define EXT4_INODE_MODE_SOFTLINK 0xA000
108#define EXT4_INODE_MODE_SOCKET 0xC000
109#define EXT4_INODE_MODE_TYPE_MASK 0xF000
110
111/*
112 * Inode flags
113 */
114#define EXT4_INODE_FLAG_SECRM 0x00000001 // Secure deletion
115#define EXT4_INODE_FLAG_UNRM 0x00000002 // Undelete
116#define EXT4_INODE_FLAG_COMPR 0x00000004 // Compress file
117#define EXT4_INODE_FLAG_SYNC 0x00000008 // Synchronous updates
118#define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 // Immutable file
119#define EXT4_INODE_FLAG_APPEND 0x00000020 // writes to file may only append
120#define EXT4_INODE_FLAG_NODUMP 0x00000040 // do not dump file
121#define EXT4_INODE_FLAG_NOATIME 0x00000080 // do not update atime
122/* Compression flags */
123#define EXT4_INODE_FLAG_DIRTY 0x00000100
124#define EXT4_INODE_FLAG_COMPRBLK 0x00000200 // One or more compressed clusters
125#define EXT4_INODE_FLAG_NOCOMPR 0x00000400 // Don't compress
126#define EXT4_INODE_FLAG_ECOMPR 0x00000800 // Compression error
127/* End compression flags --- maybe not all used */
128#define EXT4_INODE_FLAG_INDEX 0x00001000 // hash-indexed directory
129#define EXT4_INODE_FLAG_IMAGIC 0x00002000 // AFS directory */
130#define EXT4_INODE_FLAG_JOURNAL_DATA 0x00004000 // File data should be journaled
131#define EXT4_INODE_FLAG_NOTAIL 0x00008000 // File tail should not be merged
132#define EXT4_INODE_FLAG_DIRSYNC 0x00010000 // Dirsync behaviour (directories only)
133#define EXT4_INODE_FLAG_TOPDIR 0x00020000 // Top of directory hierarchies
134#define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 // Set to each huge file
135#define EXT4_INODE_FLAG_EXTENTS 0x00080000 // Inode uses extents
136#define EXT4_INODE_FLAG_EA_INODE 0x00200000 // Inode used for large EA
137#define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 // Blocks allocated beyond EOF
138#define EXT4_INODE_FLAG_RESERVED 0x80000000 // reserved for ext4 lib
139
140#define EXT4_INODE_ROOT_INDEX 2
141
142typedef struct ext4_inode_ref {
143 block_t *block; // Reference to a block containing this inode
144 ext4_inode_t *inode;
145 uint32_t index; // Index number of this inode
146} ext4_inode_ref_t;
147
148
149extern uint32_t ext4_inode_get_mode(ext4_superblock_t *, ext4_inode_t *);
150extern bool ext4_inode_is_type(ext4_superblock_t *, ext4_inode_t *, uint32_t);
151/*
152extern uint32_t ext4_inode_get_uid(ext4_inode_t *);
153*/
154extern uint64_t ext4_inode_get_size(ext4_superblock_t *, ext4_inode_t *);
155/*
156extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
157extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
158extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
159extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
160extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
161*/
162extern uint16_t ext4_inode_get_links_count(ext4_inode_t *);
163/*
164extern uint64_t ext4_inode_get_blocks_count(ext4_inode_t *)
165*/
166extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
167
168uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
169uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
170uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
171/*
172uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
173uint32_t generation;
174uint32_t file_acl_lo; // File ACL
175uint16_t extra_isize;
176uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
177uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
178uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
179uint32_t crtime; // File creation time
180uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
181uint32_t version_hi; // High 32 bits for 64-bit version
182*/
183
184extern ext4_extent_header_t * ext4_inode_get_extent_header(ext4_inode_t *);
185extern bool ext4_inode_has_flag(ext4_inode_t *, uint32_t);
186
187#endif
188
189/**
190 * @}
191 */
Note: See TracBrowser for help on using the repository browser.