source: mainline/uspace/lib/ext4/libext4_inode.h@ 2674db6

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

bugfixes in indirect block writing

  • Property mode set to 100644
File size: 8.3 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 acess_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 struct {
87 uint16_t reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
88 uint16_t file_acl_high;
89 uint32_t reserved2[2];
90 } masix2;
91 } __attribute__ ((packed)) osd2;
92
93 uint16_t extra_isize;
94 uint16_t pad1;
95 uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
96 uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
97 uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
98 uint32_t crtime; // File creation time
99 uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
100 uint32_t version_hi; // High 32 bits for 64-bit version
101} __attribute__ ((packed)) ext4_inode_t;
102
103#define EXT4_INODE_MODE_FIFO 0x1000
104#define EXT4_INODE_MODE_CHARDEV 0x2000
105#define EXT4_INODE_MODE_DIRECTORY 0x4000
106#define EXT4_INODE_MODE_BLOCKDEV 0x6000
107#define EXT4_INODE_MODE_FILE 0x8000
108#define EXT4_INODE_MODE_SOFTLINK 0xA000
109#define EXT4_INODE_MODE_SOCKET 0xC000
110#define EXT4_INODE_MODE_TYPE_MASK 0xF000
111
112/*
113 * Inode flags
114 */
115#define EXT4_INODE_FLAG_SECRM 0x00000001 // Secure deletion
116#define EXT4_INODE_FLAG_UNRM 0x00000002 // Undelete
117#define EXT4_INODE_FLAG_COMPR 0x00000004 // Compress file
118#define EXT4_INODE_FLAG_SYNC 0x00000008 // Synchronous updates
119#define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 // Immutable file
120#define EXT4_INODE_FLAG_APPEND 0x00000020 // writes to file may only append
121#define EXT4_INODE_FLAG_NODUMP 0x00000040 // do not dump file
122#define EXT4_INODE_FLAG_NOATIME 0x00000080 // do not update atime
123/* Compression flags */
124#define EXT4_INODE_FLAG_DIRTY 0x00000100
125#define EXT4_INODE_FLAG_COMPRBLK 0x00000200 // One or more compressed clusters
126#define EXT4_INODE_FLAG_NOCOMPR 0x00000400 // Don't compress
127#define EXT4_INODE_FLAG_ECOMPR 0x00000800 // Compression error
128/* End compression flags --- maybe not all used */
129#define EXT4_INODE_FLAG_INDEX 0x00001000 // hash-indexed directory
130#define EXT4_INODE_FLAG_IMAGIC 0x00002000 // AFS directory */
131#define EXT4_INODE_FLAG_JOURNAL_DATA 0x00004000 // File data should be journaled
132#define EXT4_INODE_FLAG_NOTAIL 0x00008000 // File tail should not be merged
133#define EXT4_INODE_FLAG_DIRSYNC 0x00010000 // Dirsync behaviour (directories only)
134#define EXT4_INODE_FLAG_TOPDIR 0x00020000 // Top of directory hierarchies
135#define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 // Set to each huge file
136#define EXT4_INODE_FLAG_EXTENTS 0x00080000 // Inode uses extents
137#define EXT4_INODE_FLAG_EA_INODE 0x00200000 // Inode used for large EA
138#define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 // Blocks allocated beyond EOF
139#define EXT4_INODE_FLAG_RESERVED 0x80000000 // reserved for ext4 lib
140
141#define EXT4_INODE_ROOT_INDEX 2
142
143typedef struct ext4_inode_ref {
144 block_t *block; // Reference to a block containing this inode
145 ext4_inode_t *inode;
146 uint32_t index; // Index number of this inode
147 bool dirty;
148} ext4_inode_ref_t;
149
150
151extern uint32_t ext4_inode_get_mode(ext4_superblock_t *, ext4_inode_t *);
152extern bool ext4_inode_is_type(ext4_superblock_t *, ext4_inode_t *, uint32_t);
153/*
154extern uint32_t ext4_inode_get_uid(ext4_inode_t *);
155*/
156extern uint64_t ext4_inode_get_size(ext4_superblock_t *, ext4_inode_t *);
157extern void ext4_inode_set_size(ext4_inode_t *, uint64_t);
158/*
159extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
160extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
161extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
162extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
163extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
164*/
165extern uint16_t ext4_inode_get_links_count(ext4_inode_t *);
166extern uint64_t ext4_inode_get_blocks_count(ext4_superblock_t *, ext4_inode_t *);
167extern int ext4_inode_set_blocks_count(ext4_superblock_t *, ext4_inode_t *, uint64_t);
168extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
169void ext4_inode_set_flags(ext4_inode_t *, uint32_t);
170extern uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint32_t);
171extern void ext4_inode_set_direct_block(ext4_inode_t *, uint32_t, uint32_t);
172extern uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint32_t);
173extern void ext4_inode_set_indirect_block(ext4_inode_t *, uint32_t, uint32_t);
174extern uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
175/*
176uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
177uint32_t generation;
178uint32_t file_acl_lo; // File ACL
179uint16_t extra_isize;
180uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
181uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
182uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
183uint32_t crtime; // File creation time
184uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
185uint32_t version_hi; // High 32 bits for 64-bit version
186*/
187
188extern ext4_extent_header_t * ext4_inode_get_extent_header(ext4_inode_t *);
189extern bool ext4_inode_has_flag(ext4_inode_t *, uint32_t);
190extern void ext4_inode_clear_flag(ext4_inode_t *, uint32_t);
191extern void ext4_inode_set_flag(ext4_inode_t *, uint32_t);
192extern bool ext4_inode_can_truncate(ext4_superblock_t *, ext4_inode_t *);
193
194#endif
195
196/**
197 * @}
198 */
Note: See TracBrowser for help on using the repository browser.