source: mainline/uspace/lib/ext4/libext4_inode.h@ a872fc09

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

next bunch of getters and setters added

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