source: mainline/uspace/lib/ext4/libext4_superblock.c@ c83a55c

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

First part of reading htree directory index - the most important functionality (computing hashes) still missing

  • Property mode set to 100644
File size: 6.0 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/**
34 * @file libext4_superblock.c
35 * @brief Ext4 superblock operations.
36 */
37
38#include <byteorder.h>
39#include <errno.h>
40#include <libblock.h>
41#include <malloc.h>
42#include "libext4.h"
43
44uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
45{
46 return uint32_t_le2host(sb->inodes_count);
47}
48
49uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
50{
51 return ((uint64_t)uint32_t_le2host(sb->blocks_count_hi) << 32) |
52 uint32_t_le2host(sb->blocks_count_lo);
53}
54
55uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *sb)
56{
57 return ((uint64_t)uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
58 uint32_t_le2host(sb->reserved_blocks_count_lo);
59}
60
61uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *sb)
62{
63 return ((uint64_t)uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
64 uint32_t_le2host(sb->free_blocks_count_lo);
65}
66
67uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *sb)
68{
69 return uint32_t_le2host(sb->free_inodes_count);
70}
71
72uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *sb)
73{
74 return uint32_t_le2host(sb->first_data_block);
75}
76
77uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *sb)
78{
79 return uint32_t_le2host(sb->log_block_size);
80}
81
82uint32_t ext4_superblock_get_block_size(ext4_superblock_t *sb)
83{
84 return 1024 << ext4_superblock_get_log_block_size(sb);
85}
86
87
88uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *sb)
89{
90 return uint32_t_le2host(sb->blocks_per_group);
91}
92
93uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
94{
95 return uint32_t_le2host(sb->inodes_per_group);
96}
97
98uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *sb)
99{
100 return uint32_t_le2host(sb->mount_time);
101}
102
103uint32_t ext4_superblock_get_write_time(ext4_superblock_t *sb)
104{
105 return uint32_t_le2host(sb->write_time);
106}
107
108uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *sb)
109{
110 return uint16_t_le2host(sb->mount_count);
111}
112
113uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *sb)
114{
115 return uint16_t_le2host(sb->max_mount_count);
116}
117
118uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
119{
120 return uint16_t_le2host(sb->magic);
121}
122
123uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
124{
125 return uint16_t_le2host(sb->state);
126}
127
128uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
129{
130 return uint16_t_le2host(sb->errors);
131}
132
133
134uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
135{
136 return uint16_t_le2host(sb->minor_rev_level);
137}
138
139uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
140{
141 return uint32_t_le2host(sb->last_check_time);
142}
143
144uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb){
145 return uint32_t_le2host(sb->check_interval);
146}
147
148uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
149{
150 return uint32_t_le2host(sb->creator_os);
151}
152
153uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
154{
155 return uint32_t_le2host(sb->rev_level);
156}
157
158uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
159{
160 if (ext4_superblock_get_rev_level(sb) == 0) {
161 return EXT4_REV0_INODE_SIZE;
162 }
163 return uint16_t_le2host(sb->inode_size);
164}
165
166uint16_t ext4_superblock_get_block_group_number(ext4_superblock_t *sb)
167{
168 return uint16_t_le2host(sb->block_group_number);
169}
170
171uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
172{
173 return uint32_t_le2host(sb->features_compatible);
174}
175
176uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
177{
178 return uint32_t_le2host(sb->features_incompatible);
179}
180
181uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
182{
183 return uint32_t_le2host(sb->features_read_only);
184}
185
186
187uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
188{
189 return sb->hash_seed;
190}
191
192uint32_t ext4_superblock_get_flags(ext4_superblock_t *sb)
193{
194 return uint32_t_le2host(sb->flags);
195}
196
197
198/*
199 * More complex superblock functions
200 */
201
202bool ext4_superblock_has_flag(ext4_superblock_t *sb, uint32_t flag)
203{
204 if (ext4_superblock_get_flags(sb) & flag) {
205 return true;
206 }
207 return false;
208}
209
210int ext4_superblock_read_direct(service_id_t service_id,
211 ext4_superblock_t **superblock)
212{
213 void *data;
214 int rc;
215
216 data = malloc(EXT4_SUPERBLOCK_SIZE);
217 if (data == NULL) {
218 return ENOMEM;
219 }
220
221 rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
222 EXT4_SUPERBLOCK_SIZE, data);
223
224 if (rc != EOK) {
225 free(data);
226 return rc;
227 }
228
229 (*superblock) = data;
230
231 return EOK;
232}
233
234int ext4_superblock_check_sanity(ext4_superblock_t *sb)
235{
236 if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC) {
237 return ENOTSUP;
238 }
239
240 // TODO more checks !!!
241
242 return EOK;
243}
244
245/**
246 * @}
247 */
Note: See TracBrowser for help on using the repository browser.