source: mainline/uspace/lib/ext4/libext4_superblock.c@ 9fc72fb3

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

added TODOs for comments and first part of superblock comments

  • Property mode set to 100644
File size: 19.3 KB
Line 
1/*
2 * Copyright (c) 2012 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
44/** Get number of i-nodes in the whole filesystem.
45 *
46 * @param sb superblock
47 * @return number of i-nodes
48 */
49uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
50{
51 return uint32_t_le2host(sb->inodes_count);
52}
53
54/** Set number of i-nodes in the whole filesystem.
55 *
56 * @param sb superblock
57 * @param count number of i-nodes
58 */
59void ext4_superblock_set_inodes_count(ext4_superblock_t *sb, uint32_t count)
60{
61 sb->inodes_count = host2uint32_t_le(count);
62}
63
64/** Get number of data blocks in the whole filesystem.
65 *
66 * @param sb superblock
67 * @return number of data blocks
68 */
69uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
70{
71 return ((uint64_t)uint32_t_le2host(sb->blocks_count_hi) << 32) |
72 uint32_t_le2host(sb->blocks_count_lo);
73}
74
75/** Set number of data blocks in the whole filesystem.
76 *
77 * @param sb superblock
78 * @param count number of data blocks
79 */
80void ext4_superblock_set_blocks_count(ext4_superblock_t *sb, uint64_t count)
81{
82 sb->blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
83 sb->blocks_count_hi = host2uint32_t_le(count >> 32);
84}
85
86/** Get number of reserved data blocks in the whole filesystem.
87 *
88 * @param sb superblock
89 * @return number of reserved data blocks
90 */
91uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *sb)
92{
93 return ((uint64_t)uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
94 uint32_t_le2host(sb->reserved_blocks_count_lo);
95}
96
97/** Set number of reserved data blocks in the whole filesystem.
98 *
99 * @param sb superblock
100 * @param count number of reserved data blocks
101 */
102void ext4_superblock_set_reserved_blocks_count(ext4_superblock_t *sb, uint64_t count)
103{
104 sb->reserved_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
105 sb->reserved_blocks_count_hi = host2uint32_t_le(count >> 32);
106}
107
108/** Get number of free data blocks in the whole filesystem.
109 *
110 * @param sb superblock
111 * @return number of free data blocks
112 */
113uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *sb)
114{
115 return ((uint64_t)uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
116 uint32_t_le2host(sb->free_blocks_count_lo);
117}
118
119/** Set number of free data blocks in the whole filesystem.
120 *
121 * @param sb superblock
122 * @param count number of free data blocks
123 */
124void ext4_superblock_set_free_blocks_count(ext4_superblock_t *sb, uint64_t count)
125{
126 sb->free_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
127 sb->free_blocks_count_hi = host2uint32_t_le(count >> 32);
128}
129
130/** Get number of free i-nodes in the whole filesystem.
131 *
132 * @param sb superblock
133 * @return number of free i-nodes
134 */
135uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *sb)
136{
137 return uint32_t_le2host(sb->free_inodes_count);
138}
139
140/** Set number of free i-nodes in the whole filesystem.
141 *
142 * @param sb superblock
143 * @param count number of free i-nodes
144 */
145void ext4_superblock_set_free_inodes_count(ext4_superblock_t *sb, uint32_t count)
146{
147 sb->free_inodes_count = host2uint32_t_le(count);
148}
149
150/** Get index of first data block (block, where is located superblock)
151 *
152 * @param sb superblock
153 * @return index of the first data block
154 */
155uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *sb)
156{
157 return uint32_t_le2host(sb->first_data_block);
158}
159
160/** Set index of first data block (block, where is located superblock)
161 *
162 * @param sb superblock
163 * @param first index of the first data block
164 */
165void ext4_superblock_set_first_data_block(ext4_superblock_t *sb, uint32_t first)
166{
167 sb->first_data_block = host2uint32_t_le(first);
168}
169
170/** Get logarithmic block size (1024 << size == block_size)
171 *
172 * @param sb superblock
173 * @return logarithmic block size
174 */
175uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *sb)
176{
177 return uint32_t_le2host(sb->log_block_size);
178}
179
180/** Set logarithmic block size (1024 << size == block_size)
181 *
182 * @param sb superblock
183 * @return logarithmic block size
184 */
185void ext4_superblock_set_log_block_size(ext4_superblock_t *sb, uint32_t log_size)
186{
187 sb->log_block_size = host2uint32_t_le(log_size);
188}
189
190/** Get size of data block (in bytes).
191 *
192 * @param sb superblock
193 * @return size of data block
194 */
195uint32_t ext4_superblock_get_block_size(ext4_superblock_t *sb)
196{
197 return 1024 << ext4_superblock_get_log_block_size(sb);
198}
199
200/** Set size of data block (in bytes).
201 *
202 * @param sb superblock
203 * @param size size of data block (must be power of 2, at least 1024)
204 */
205void ext4_superblock_set_block_size(ext4_superblock_t *sb, uint32_t size)
206{
207 uint32_t log = 0;
208 uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
209
210 tmp >>= 1;
211 while (tmp) {
212 log++;
213 tmp >>= 1;
214 }
215
216 ext4_superblock_set_log_block_size(sb, log);
217}
218
219/** Get number of data blocks per block group (except last BG)
220 *
221 * @param sb superblock
222 * @return data blocks per block group
223 */
224uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *sb)
225{
226 return uint32_t_le2host(sb->blocks_per_group);
227}
228
229/** Set number of data blocks per block group (except last BG)
230 *
231 * @param sb superblock
232 * @param blocks data blocks per block group
233 */
234void ext4_superblock_set_blocks_per_group(ext4_superblock_t *sb, uint32_t blocks)
235{
236 sb->blocks_per_group = host2uint32_t_le(blocks);
237}
238
239/** Get number of i-nodes per block group (except last BG)
240 *
241 * @param sb superblock
242 * @return i-nodes per block group
243 */
244uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
245{
246 return uint32_t_le2host(sb->inodes_per_group);
247}
248
249/** Set number of i-nodes per block group (except last BG)
250 *
251 * @param sb superblock
252 * @param inodes i-nodes per block group
253 */
254void ext4_superblock_set_inodes_per_group(ext4_superblock_t *sb, uint32_t inodes)
255{
256 sb->inodes_per_group = host2uint32_t_le(inodes);
257}
258
259/** Get time when filesystem was mounted (POSIX time).
260 *
261 * @param sb superblock
262 * @return mount time
263 */
264uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *sb)
265{
266 return uint32_t_le2host(sb->mount_time);
267}
268
269/** Set time when filesystem was mounted (POSIX time).
270 *
271 * @param sb superblock
272 * @param time mount time
273 */
274void ext4_superblock_set_mount_time(ext4_superblock_t *sb, uint32_t time)
275{
276 sb->mount_time = host2uint32_t_le(time);
277}
278
279/** Get time when filesystem was last accesed by write operation (POSIX time).
280 *
281 * @param sb superblock
282 * @return write time
283 */
284uint32_t ext4_superblock_get_write_time(ext4_superblock_t *sb)
285{
286 return uint32_t_le2host(sb->write_time);
287}
288
289/** Set time when filesystem was last accesed by write operation (POSIX time).
290 *
291 * @param sb superblock
292 * @param time write time
293 */
294void ext4_superblock_set_write_time(ext4_superblock_t *sb, uint32_t time)
295{
296 sb->write_time = host2uint32_t_le(time);
297}
298
299/** Get number of mount from last filesystem check.
300 *
301 * @param sb superblock
302 * @return number of mounts
303 */
304uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *sb)
305{
306 return uint16_t_le2host(sb->mount_count);
307}
308
309/** Set number of mount from last filesystem check.
310 *
311 * @param sb superblock
312 * @param count number of mounts
313 */
314void ext4_superblock_set_mount_count(ext4_superblock_t *sb, uint16_t count)
315{
316 sb->mount_count = host2uint16_t_le(count);
317}
318
319/** Get maximum number of mount from last filesystem check.
320 *
321 * @param sb superblock
322 * @return maximum number of mounts
323 */
324uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *sb)
325{
326 return uint16_t_le2host(sb->max_mount_count);
327}
328
329/** Set maximum number of mount from last filesystem check.
330 *
331 * @param sb superblock
332 * @param count maximum number of mounts
333 */
334void ext4_superblock_set_max_mount_count(ext4_superblock_t *sb, uint16_t count)
335{
336 sb->max_mount_count = host2uint16_t_le(count);
337}
338
339/** Get superblock magic value.
340 *
341 * @param sb superblock
342 * @return magic value
343 */
344uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
345{
346 return uint16_t_le2host(sb->magic);
347}
348
349/** Set superblock magic value.
350 *
351 * @param sb superblock
352 * @param magic value
353 */
354void ext4_superblock_set_magic(ext4_superblock_t *sb, uint16_t magic)
355{
356 sb->magic = host2uint16_t_le(magic);
357}
358
359/** TODO comment
360 *
361 */
362uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
363{
364 return uint16_t_le2host(sb->state);
365}
366
367/** TODO comment
368 *
369 */
370void ext4_superblock_set_state(ext4_superblock_t *sb, uint16_t state)
371{
372 sb->state = host2uint16_t_le(state);
373}
374
375/** TODO comment
376 *
377 */
378uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
379{
380 return uint16_t_le2host(sb->errors);
381}
382
383/** TODO comment
384 *
385 */
386void ext4_superblock_set_errors(ext4_superblock_t *sb, uint16_t errors)
387{
388 sb->errors = host2uint16_t_le(errors);
389}
390
391/** TODO comment
392 *
393 */
394uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
395{
396 return uint16_t_le2host(sb->minor_rev_level);
397}
398
399/** TODO comment
400 *
401 */
402void ext4_superblock_set_minor_rev_level(ext4_superblock_t *sb, uint16_t level)
403{
404 sb->minor_rev_level = host2uint16_t_le(level);
405}
406
407/** TODO comment
408 *
409 */
410uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
411{
412 return uint32_t_le2host(sb->last_check_time);
413}
414
415/** TODO comment
416 *
417 */
418void ext4_superblock_set_last_check_time(ext4_superblock_t *sb, uint32_t time)
419{
420 sb->state = host2uint32_t_le(time);
421}
422
423/** TODO comment
424 *
425 */
426uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb){
427 return uint32_t_le2host(sb->check_interval);
428}
429
430/** TODO comment
431 *
432 */
433void ext4_superblock_set_check_interval(ext4_superblock_t *sb, uint32_t interval)
434{
435 sb->check_interval = host2uint32_t_le(interval);
436}
437
438/** TODO comment
439 *
440 */
441uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
442{
443 return uint32_t_le2host(sb->creator_os);
444}
445
446/** TODO comment
447 *
448 */
449void ext4_superblock_set_creator_os(ext4_superblock_t *sb, uint32_t os)
450{
451 sb->creator_os = host2uint32_t_le(os);
452}
453
454/** TODO comment
455 *
456 */
457uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
458{
459 return uint32_t_le2host(sb->rev_level);
460}
461
462/** TODO comment
463 *
464 */
465void ext4_superblock_set_rev_level(ext4_superblock_t *sb, uint32_t level)
466{
467 sb->rev_level = host2uint32_t_le(level);
468}
469
470/** TODO comment
471 *
472 */
473uint16_t ext4_superblock_get_def_resuid(ext4_superblock_t *sb)
474{
475 return uint16_t_le2host(sb->def_resuid);
476}
477
478/** TODO comment
479 *
480 */
481void ext4_superblock_set_def_resuid(ext4_superblock_t *sb, uint16_t uid)
482{
483 sb->def_resuid = host2uint16_t_le(uid);
484}
485
486/** TODO comment
487 *
488 */
489uint16_t ext4_superblock_get_def_resgid(ext4_superblock_t *sb)
490{
491 return uint16_t_le2host(sb->def_resgid);
492}
493
494/** TODO comment
495 *
496 */
497void ext4_superblock_set_def_resgid(ext4_superblock_t *sb, uint16_t gid)
498{
499 sb->def_resgid = host2uint16_t_le(gid);
500}
501
502/** TODO comment
503 *
504 */
505uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *sb)
506{
507 return uint32_t_le2host(sb->first_inode);
508}
509
510/** TODO comment
511 *
512 */
513void ext4_superblock_set_first_inode(ext4_superblock_t *sb, uint32_t first_inode)
514{
515 sb->first_inode = host2uint32_t_le(first_inode);
516}
517
518/** TODO comment
519 *
520 */
521uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
522{
523 if (ext4_superblock_get_rev_level(sb) == 0) {
524 return EXT4_REV0_INODE_SIZE;
525 }
526 return uint16_t_le2host(sb->inode_size);
527}
528
529/** TODO comment
530 *
531 */
532void ext4_superblock_set_inode_size(ext4_superblock_t *sb, uint16_t size)
533{
534 sb->inode_size = host2uint16_t_le(size);
535}
536
537/** TODO comment
538 *
539 */
540uint16_t ext4_superblock_get_block_group_number(ext4_superblock_t *sb)
541{
542 return uint16_t_le2host(sb->block_group_number);
543}
544
545/** TODO comment
546 *
547 */
548void ext4_superblock_set_block_group_number(ext4_superblock_t *sb, uint16_t bg)
549{
550 sb->block_group_number = host2uint16_t_le(bg);
551}
552
553/** TODO comment
554 *
555 */
556uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
557{
558 return uint32_t_le2host(sb->features_compatible);
559}
560
561/** TODO comment
562 *
563 */
564void ext4_superblock_set_features_compatible(ext4_superblock_t *sb, uint32_t features)
565{
566 sb->features_compatible = host2uint32_t_le(features);
567}
568
569/** TODO comment
570 *
571 */
572uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
573{
574 return uint32_t_le2host(sb->features_incompatible);
575}
576
577/** TODO comment
578 *
579 */
580void ext4_superblock_set_features_incompatible(ext4_superblock_t *sb, uint32_t features)
581{
582 sb->features_incompatible = host2uint32_t_le(features);
583}
584
585/** TODO comment
586 *
587 */
588uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
589{
590 return uint32_t_le2host(sb->features_read_only);
591}
592
593/** TODO comment
594 *
595 */
596void ext4_superblock_set_features_read_only(ext4_superblock_t *sb, uint32_t features)
597{
598 sb->features_read_only = host2uint32_t_le(features);
599}
600
601/** TODO comment
602 *
603 */
604const uint8_t * ext4_superblock_get_uuid(ext4_superblock_t *sb)
605{
606 return sb->uuid;
607}
608
609/** TODO comment
610 *
611 */
612void ext4_superblock_set_uuid(ext4_superblock_t *sb, const uint8_t *uuid)
613{
614 memcpy(sb->uuid, uuid, sizeof(sb->uuid));
615}
616
617const char * ext4_superblock_get_volume_name(ext4_superblock_t *sb)
618{
619 return sb->volume_name;
620}
621
622/** TODO comment
623 *
624 */
625void ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
626{
627 memcpy(sb->volume_name, name, sizeof(sb->volume_name));
628}
629
630/** TODO comment
631 *
632 */
633const char * ext4_superblock_get_last_mounted(ext4_superblock_t *sb)
634{
635 return sb->last_mounted;
636}
637
638/** TODO comment
639 *
640 */
641void ext4_superblock_set_last_mounted(ext4_superblock_t *sb, const char *last)
642{
643 memcpy(sb->last_mounted, last, sizeof(sb->last_mounted));
644}
645
646/** TODO comment
647 *
648 */
649uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *sb)
650{
651 return uint32_t_le2host(sb->last_orphan);
652}
653
654/** TODO comment
655 *
656 */
657void ext4_superblock_set_last_orphan(ext4_superblock_t *sb, uint32_t last_orphan)
658{
659 sb->last_orphan = host2uint32_t_le(last_orphan);
660}
661
662/** TODO comment
663 *
664 */
665uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
666{
667 return sb->hash_seed;
668}
669
670/** TODO comment
671 *
672 */
673uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb)
674{
675 return sb->default_hash_version;
676}
677
678/** TODO comment
679 *
680 */
681void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb, uint8_t version)
682{
683 sb->default_hash_version = version;
684}
685
686/** TODO comment
687 *
688 */
689uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb)
690{
691 uint16_t size = uint16_t_le2host(sb->desc_size);
692
693 if (size < EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
694 size = EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE;
695 }
696
697 return size;
698}
699
700/** TODO comment
701 *
702 */
703void ext4_superblock_set_desc_size(ext4_superblock_t *sb, uint16_t size)
704{
705 sb->desc_size = host2uint16_t_le(size);
706}
707
708/** TODO comment
709 *
710 */
711uint32_t ext4_superblock_get_flags(ext4_superblock_t *sb)
712{
713 return uint32_t_le2host(sb->flags);
714}
715
716/** TODO comment
717 *
718 */
719void ext4_superblock_set_flags(ext4_superblock_t *sb, uint32_t flags)
720{
721 sb->flags = host2uint32_t_le(flags);
722}
723
724
725/*
726 * More complex superblock operations
727 */
728
729/** TODO comment
730 *
731 */
732bool ext4_superblock_has_flag(ext4_superblock_t *sb, uint32_t flag)
733{
734 if (ext4_superblock_get_flags(sb) & flag) {
735 return true;
736 }
737 return false;
738}
739
740/** TODO comment
741 *
742 */
743bool ext4_superblock_has_feature_compatible(ext4_superblock_t *sb, uint32_t feature)
744{
745 if (ext4_superblock_get_features_compatible(sb) & feature) {
746 return true;
747 }
748 return false;
749}
750
751/** TODO comment
752 *
753 */
754bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *sb, uint32_t feature)
755{
756 if (ext4_superblock_get_features_incompatible(sb) & feature) {
757 return true;
758 }
759 return false;
760}
761
762/** TODO comment
763 *
764 */
765bool ext4_superblock_has_feature_read_only(ext4_superblock_t *sb, uint32_t feature)
766{
767 if (ext4_superblock_get_features_read_only(sb) & feature) {
768 return true;
769 }
770 return false;
771}
772
773/** TODO comment
774 *
775 */
776int ext4_superblock_read_direct(service_id_t service_id,
777 ext4_superblock_t **superblock)
778{
779 int rc;
780
781 void *data = malloc(EXT4_SUPERBLOCK_SIZE);
782 if (data == NULL) {
783 return ENOMEM;
784 }
785
786 rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
787 EXT4_SUPERBLOCK_SIZE, data);
788
789 if (rc != EOK) {
790 free(data);
791 return rc;
792 }
793
794 (*superblock) = data;
795
796 return EOK;
797}
798
799/** TODO comment
800 *
801 */
802int ext4_superblock_write_direct(service_id_t service_id,
803 ext4_superblock_t *sb)
804{
805 int rc;
806 uint32_t phys_block_size;
807
808 rc = block_get_bsize(service_id, &phys_block_size);
809 if (rc != EOK) {
810 // TODO error
811 return rc;
812 }
813
814 uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
815 uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
816
817 if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
818 block_count++;
819 }
820
821 return block_write_direct(service_id, first_block, block_count, sb);
822
823}
824
825/** TODO comment
826 *
827 */
828int ext4_superblock_check_sanity(ext4_superblock_t *sb)
829{
830 if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC) {
831 return ENOTSUP;
832 }
833
834 // block size
835 // desc size
836
837
838 // TODO more checks !!!
839
840 return EOK;
841}
842
843/** TODO comment
844 *
845 */
846uint32_t ext4_superblock_get_block_group_count(ext4_superblock_t *sb)
847{
848 uint64_t blocks_count = ext4_superblock_get_blocks_count(sb);
849 uint32_t blocks_per_group = ext4_superblock_get_blocks_per_group(sb);
850
851 uint32_t block_groups_count = blocks_count / blocks_per_group;
852
853 if (blocks_count % blocks_per_group) {
854 block_groups_count++;
855 }
856
857 return block_groups_count;
858
859}
860
861/** TODO comment
862 *
863 */
864uint32_t ext4_superblock_get_blocks_in_group(ext4_superblock_t *sb, uint32_t bgid)
865{
866 uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
867 uint32_t blocks_per_group = ext4_superblock_get_blocks_per_group(sb);
868 uint64_t total_blocks = ext4_superblock_get_blocks_count(sb);
869
870 if (bgid < block_group_count - 1) {
871 return blocks_per_group;
872 } else {
873 return (total_blocks - ((block_group_count - 1) * blocks_per_group));
874 }
875
876}
877
878/** TODO comment
879 *
880 */
881uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *sb, uint32_t bgid)
882{
883 uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
884 uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
885 uint32_t total_inodes = ext4_superblock_get_inodes_count(sb);
886
887 if (bgid < block_group_count - 1) {
888 return inodes_per_group;
889 } else {
890 return (total_inodes - ((block_group_count - 1) * inodes_per_group));
891 }
892
893}
894
895/**
896 * @}
897 */
Note: See TracBrowser for help on using the repository browser.