Changeset 2226cc3 in mainline for uspace/lib/ext4/libext4_superblock.c


Ignore:
Timestamp:
2012-05-05T15:39:58Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2add9ec
Parents:
9fc72fb3
Message:

Superblock comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_superblock.c

    r9fc72fb3 r2226cc3  
    357357}
    358358
    359 /** TODO comment
    360  *
     359/** Get filesystem state.
     360 *
     361 * @param sb            superblock
     362 * @return                      filesystem state
    361363 */
    362364uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
     
    365367}
    366368
    367 /** TODO comment
    368  *
     369/** Set filesystem state.
     370 *
     371 * @param sb            superblock
     372 * @param state         filesystem state
    369373 */
    370374void ext4_superblock_set_state(ext4_superblock_t *sb, uint16_t state)
     
    373377}
    374378
    375 /** TODO comment
    376  *
     379/** Get behavior code when errors detected.
     380 *
     381 * @param sb            superblock
     382 * @return                      behavior code
    377383 */
    378384uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
     
    381387}
    382388
    383 /** TODO comment
    384  *
     389/** Set behavior code when errors detected.
     390 *
     391 * @param sb            superblock
     392 * @param errors        behavior code
    385393 */
    386394void ext4_superblock_set_errors(ext4_superblock_t *sb, uint16_t errors)
     
    389397}
    390398
    391 /** TODO comment
    392  *
     399/** Get minor revision level of the filesystem.
     400 *
     401 * @param sb            superblock
     402 * @return                      minor revision level
    393403 */
    394404uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
     
    397407}
    398408
    399 /** TODO comment
    400  *
     409/** Set minor revision level of the filesystem.
     410 *
     411 * @param sb            superblock
     412 * @param level         minor revision level
    401413 */
    402414void ext4_superblock_set_minor_rev_level(ext4_superblock_t *sb, uint16_t level)
     
    405417}
    406418
    407 /** TODO comment
    408  *
     419/** Get time of the last filesystem check.
     420 *
     421 * @param sb            superblock
     422 * @return                      time of the last check (POSIX)
    409423 */
    410424uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
     
    413427}
    414428
    415 /** TODO comment
    416  *
     429/** Set time of the last filesystem check.
     430 *
     431 * @param sb            superblock
     432 * @param time          time of the last check (POSIX)
    417433 */
    418434void ext4_superblock_set_last_check_time(ext4_superblock_t *sb, uint32_t time)
     
    421437}
    422438
    423 /** TODO comment
    424  *
     439/** Get maximum time interval between two filesystem checks.
     440 *
     441 * @param sb            superblock
     442 * @return                      time interval between two check (POSIX)
    425443 */
    426444uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb){
     
    428446}
    429447
    430 /** TODO comment
    431  *
     448/** Set maximum time interval between two filesystem checks.
     449 *
     450 * @param sb                    superblock
     451 * @param interval              time interval between two check (POSIX)
    432452 */
    433453void ext4_superblock_set_check_interval(ext4_superblock_t *sb, uint32_t interval)
     
    436456}
    437457
    438 /** TODO comment
    439  *
     458/** Get operation system identifier, on which the filesystem was created.
     459 *
     460 * @param sb            superblock
     461 * @return                      operation system identifier
    440462 */
    441463uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
     
    444466}
    445467
    446 /** TODO comment
    447  *
     468/** Set operation system identifier, on which the filesystem was created.
     469 *
     470 * @param sb            superblock
     471 * @param os            operation system identifier
    448472 */
    449473void ext4_superblock_set_creator_os(ext4_superblock_t *sb, uint32_t os)
     
    452476}
    453477
    454 /** TODO comment
    455  *
     478/** Get revision level of the filesystem.
     479 *
     480 * @param sb            superblock
     481 * @return                      revision level
    456482 */
    457483uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
     
    460486}
    461487
    462 /** TODO comment
    463  *
     488/** Set revision level of the filesystem.
     489 *
     490 * @param sb            superblock
     491 * @param level         revision level
    464492 */
    465493void ext4_superblock_set_rev_level(ext4_superblock_t *sb, uint32_t level)
     
    468496}
    469497
    470 /** TODO comment
    471  *
     498/** Get default user id for reserved blocks.
     499 *
     500 * @param sb            superblock
     501 * @return                      default user id for reserved blocks.
    472502 */
    473503uint16_t ext4_superblock_get_def_resuid(ext4_superblock_t *sb)
     
    476506}
    477507
    478 /** TODO comment
    479  *
     508/** Set default user id for reserved blocks.
     509 *
     510 * @param sb            superblock
     511 * @param uid           default user id for reserved blocks.
    480512 */
    481513void ext4_superblock_set_def_resuid(ext4_superblock_t *sb, uint16_t uid)
     
    484516}
    485517
    486 /** TODO comment
    487  *
     518/** Get default group id for reserved blocks.
     519 *
     520 * @param sb            superblock
     521 * @return                      default group id for reserved blocks.
    488522 */
    489523uint16_t ext4_superblock_get_def_resgid(ext4_superblock_t *sb)
     
    492526}
    493527
    494 /** TODO comment
    495  *
     528/** Set default group id for reserved blocks.
     529 *
     530 * @param sb            superblock
     531 * @param gid           default group id for reserved blocks.
    496532 */
    497533void ext4_superblock_set_def_resgid(ext4_superblock_t *sb, uint16_t gid)
     
    500536}
    501537
    502 /** TODO comment
    503  *
     538/** Get index of the first i-node, which can be used for allocation.
     539 *
     540 * @param sb            superblock
     541 * @return                      i-node index
    504542 */
    505543uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *sb)
     
    508546}
    509547
    510 /** TODO comment
    511  *
     548/** Set index of the first i-node, which can be used for allocation.
     549 *
     550 * @param sb                    superblock
     551 * @param first_inode   i-node index
    512552 */
    513553void ext4_superblock_set_first_inode(ext4_superblock_t *sb, uint32_t first_inode)
     
    516556}
    517557
    518 /** TODO comment
    519  *
     558/** Get size of i-node structure.
     559 *
     560 * For the oldest revision return constant number.
     561 *
     562 * @param sb                    superblock
     563 * @return                              size of i-node structure
    520564 */
    521565uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
     
    527571}
    528572
    529 /** TODO comment
    530  *
     573/** Set size of i-node structure.
     574 *
     575 * @param sb                    superblock
     576 * @param size                  size of i-node structure
    531577 */
    532578void ext4_superblock_set_inode_size(ext4_superblock_t *sb, uint16_t size)
     
    535581}
    536582
    537 /** TODO comment
    538  *
    539  */
    540 uint16_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  */
    548 void 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  *
     583/** Get index of block group, where superblock copy is located.
     584 *
     585 * @param sb                    superblock
     586 * @return                              block group index
     587 */
     588uint16_t ext4_superblock_get_block_group_index(ext4_superblock_t *sb)
     589{
     590        return uint16_t_le2host(sb->block_group_index);
     591}
     592
     593/** Set index of block group, where superblock copy is located.
     594 *
     595 * @param sb                    superblock
     596 * @param bgid                  block group index
     597 */
     598void ext4_superblock_set_block_group_index(ext4_superblock_t *sb, uint16_t bgid)
     599{
     600        sb->block_group_index = host2uint16_t_le(bgid);
     601}
     602
     603/** Get compatible features supported by the filesystem.
     604 *
     605 * @param sb            superblock
     606 * @return                      compatible features bitmap
    555607 */
    556608uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
     
    559611}
    560612
    561 /** TODO comment
    562  *
     613/** Set compatible features supported by the filesystem.
     614 *
     615 * @param sb                    superblock
     616 * @param features              compatible features bitmap
    563617 */
    564618void ext4_superblock_set_features_compatible(ext4_superblock_t *sb, uint32_t features)
     
    567621}
    568622
    569 /** TODO comment
    570  *
     623/** Get incompatible features supported by the filesystem.
     624 *
     625 * @param sb            superblock
     626 * @return                      incompatible features bitmap
    571627 */
    572628uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
     
    575631}
    576632
    577 /** TODO comment
    578  *
     633/** Set incompatible features supported by the filesystem.
     634 *
     635 * @param sb                    superblock
     636 * @param features              incompatible features bitmap
    579637 */
    580638void ext4_superblock_set_features_incompatible(ext4_superblock_t *sb, uint32_t features)
     
    583641}
    584642
    585 /** TODO comment
    586  *
     643/** Get compatible features supported by the filesystem.
     644 *
     645 * @param sb            superblock
     646 * @return                      read-only compatible features bitmap
    587647 */
    588648uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
     
    591651}
    592652
    593 /** TODO comment
    594  *
     653/** Set compatible features supported by the filesystem.
     654 *
     655 * @param sb                    superblock
     656 * @param feature               read-only compatible features bitmap
    595657 */
    596658void ext4_superblock_set_features_read_only(ext4_superblock_t *sb, uint32_t features)
     
    599661}
    600662
    601 /** TODO comment
    602  *
     663/** Get UUID of the filesystem.
     664 *
     665 * @param sb            superblock
     666 * @return                      pointer to UUID array
    603667 */
    604668const uint8_t * ext4_superblock_get_uuid(ext4_superblock_t *sb)
     
    607671}
    608672
    609 /** TODO comment
    610  *
     673/** Set UUID of the filesystem.
     674 *
     675 * @param sb            superblock
     676 * @param uuid          pointer to UUID array
    611677 */
    612678void ext4_superblock_set_uuid(ext4_superblock_t *sb, const uint8_t *uuid)
     
    615681}
    616682
     683/** Get name of the filesystem volume.
     684 *
     685 * @param sb            superblock
     686 * @return                      name of the volume
     687 */
    617688const char * ext4_superblock_get_volume_name(ext4_superblock_t *sb)
    618689{
     
    620691}
    621692
    622 /** TODO comment
    623  *
     693/** Set name of the filesystem volume.
     694 *
     695 * @param sb            superblock
     696 * @param name          new name of the volume
    624697 */
    625698void ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
     
    628701}
    629702
    630 /** TODO comment
    631  *
     703/** Get name of the directory, where this filesystem was mounted at last.
     704 *
     705 * @param sb            superblock
     706 * @return                      directory name
    632707 */
    633708const char * ext4_superblock_get_last_mounted(ext4_superblock_t *sb)
     
    636711}
    637712
    638 /** TODO comment
    639  *
     713/** Set name of the directory, where this filesystem was mounted at last.
     714 *
     715 * @param sb            superblock
     716 * @param last          directory name
    640717 */
    641718void ext4_superblock_set_last_mounted(ext4_superblock_t *sb, const char *last)
     
    644721}
    645722
    646 /** TODO comment
    647  *
     723/** Get last orphaned i-node index.
     724 *
     725 * Orphans are stored in linked list.
     726 *
     727 * @param sb            superblock
     728 * @return                      last orphaned i-node index
    648729 */
    649730uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *sb)
     
    652733}
    653734
    654 /** TODO comment
    655  *
     735/** Set last orphaned i-node index.
     736 *
     737 * Orphans are stored in linked list.
     738 *
     739 * @param sb                    superblock
     740 * @param last_orphan   last orphaned i-node index
    656741 */
    657742void ext4_superblock_set_last_orphan(ext4_superblock_t *sb, uint32_t last_orphan)
     
    660745}
    661746
    662 /** TODO comment
    663  *
    664  */
    665 uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
     747/** Get hash seed for directory index hash function.
     748 *
     749 * @param sb            superblock
     750 * @return                      hash seed pointer
     751 */
     752const uint32_t * ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
    666753{
    667754        return sb->hash_seed;
    668755}
    669756
    670 /** TODO comment
    671  *
     757/** Set hash seed for directory index hash function.
     758 *
     759 * @param sb            superblock
     760 * @param seed          hash seed pointer
     761 */
     762void ext4_superblock_set_hash_seed(ext4_superblock_t *sb, const uint32_t *seed)
     763{
     764        memcpy(sb->hash_seed, seed, sizeof(sb->hash_seed));
     765}
     766
     767/** Get default version of the hash algorithm version for directory index.
     768 *
     769 * @param sb            superblock
     770 * @return                      default hash version
    672771 */
    673772uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb)
     
    676775}
    677776
    678 /** TODO comment
    679  *
     777/** Set default version of the hash algorithm version for directory index.
     778 *
     779 * @param sb            superblock
     780 * @param version       default hash version
    680781 */
    681782void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb, uint8_t version)
     
    684785}
    685786
    686 /** TODO comment
    687  *
     787/** Get size of block group descriptor structure.
     788 *
     789 * Output value is checked for minimal size.
     790 *
     791 * @param sb            superblock
     792 * @return                      size of block group descriptor
    688793 */
    689794uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb)
     
    698803}
    699804
    700 /** TODO comment
    701  *
     805/** Set size of block group descriptor structure.
     806 *
     807 * Input value is checked for minimal size.
     808 *
     809 * @param sb            superblock
     810 * @param size          size of block group descriptor
    702811 */
    703812void ext4_superblock_set_desc_size(ext4_superblock_t *sb, uint16_t size)
    704813{
     814        if (size < EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     815                sb->desc_size = host2uint16_t_le(EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE);
     816        }
     817
    705818        sb->desc_size = host2uint16_t_le(size);
    706819}
    707820
    708 /** TODO comment
    709  *
     821/** Get superblock flags.
     822 *
     823 * @param sb            superblock
     824 * @return                      flags from the superblock
    710825 */
    711826uint32_t ext4_superblock_get_flags(ext4_superblock_t *sb)
     
    714829}
    715830
    716 /** TODO comment
    717  *
     831/** Set superblock flags.
     832 *
     833 * @param sb            superblock
     834 * @param flags         flags for the superblock
    718835 */
    719836void ext4_superblock_set_flags(ext4_superblock_t *sb, uint32_t flags)
     
    721838        sb->flags = host2uint32_t_le(flags);
    722839}
    723 
    724840
    725841/*
     
    727843 */
    728844
    729 /** TODO comment
    730  *
     845/** Check if superblock has specified flag.
     846 *
     847 * @param sb                    superblock
     848 * @param flag                  flag to be checked
     849 * @return                              true, if superblock has the flag
    731850 */
    732851bool ext4_superblock_has_flag(ext4_superblock_t *sb, uint32_t flag)
     
    738857}
    739858
    740 /** TODO comment
    741  *
     859/** Check if filesystem supports compatible feature.
     860 *
     861 * @param sb                    superblock
     862 * @param feature               feature to be checked
     863 * @return                              true, if filesystem supports the feature
    742864 */
    743865bool ext4_superblock_has_feature_compatible(ext4_superblock_t *sb, uint32_t feature)
     
    749871}
    750872
    751 /** TODO comment
    752  *
     873/** Check if filesystem supports incompatible feature.
     874 *
     875 * @param sb                    superblock
     876 * @param feature               feature to be checked
     877 * @return                              true, if filesystem supports the feature
    753878 */
    754879bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *sb, uint32_t feature)
     
    760885}
    761886
    762 /** TODO comment
    763  *
     887/** Check if filesystem supports read-only compatible feature.
     888 *
     889 * @param sb                    superblock
     890 * @param feature               feature to be checked
     891 * @return                              true, if filesystem supports the feature
    764892 */
    765893bool ext4_superblock_has_feature_read_only(ext4_superblock_t *sb, uint32_t feature)
     
    771899}
    772900
    773 /** TODO comment
    774  *
     901/** Read superblock directly from block device.
     902 *
     903 * @param service_id            block device identifier
     904 * @param sb                            output pointer to memory structure
     905 * @return                                      error code.
    775906 */
    776907int ext4_superblock_read_direct(service_id_t service_id,
    777     ext4_superblock_t **superblock)
     908    ext4_superblock_t **sb)
    778909{
    779910        int rc;
    780911
     912        // Allocated memory for superblock structure
    781913        void *data = malloc(EXT4_SUPERBLOCK_SIZE);
    782914        if (data == NULL) {
     
    784916        }
    785917
     918        // Read data from block device
    786919        rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
    787920            EXT4_SUPERBLOCK_SIZE, data);
     
    792925        }
    793926
    794         (*superblock) = data;
     927        // Set output value
     928        (*sb) = data;
    795929
    796930        return EOK;
    797931}
    798932
    799 /** TODO comment
    800  *
     933/** Write superblock structure directly to block device.
     934 *
     935 * @param service_id            block device identifier
     936 * @param sb                            superblock to be written
     937 * @return                                      error code
    801938 */
    802939int ext4_superblock_write_direct(service_id_t service_id,
     
    806943        uint32_t phys_block_size;
    807944
     945        // Load physical block size from block device
    808946        rc = block_get_bsize(service_id, &phys_block_size);
    809947        if (rc != EOK) {
    810                 // TODO error
    811948                return rc;
    812949        }
    813950
     951        // Compute address of the first block
    814952        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
     953        // Compute number of block to write
    815954        uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
    816955
     956        // Check alignment
    817957        if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
    818958                block_count++;
    819959        }
    820960
     961        // Write data
    821962        return block_write_direct(service_id, first_block, block_count, sb);
    822963
     
    841982}
    842983
    843 /** TODO comment
    844  *
     984/** Compute number of block groups in the filesystem.
     985 *
     986 * @param sb            superblock
     987 * @return                      number of block groups
    845988 */
    846989uint32_t ext4_superblock_get_block_group_count(ext4_superblock_t *sb)
     
    8591002}
    8601003
    861 /** TODO comment
    862  *
     1004/** Compute number of blocks in specified block group.
     1005 *
     1006 * @param sb                    superblock
     1007 * @param bgid                  block group index
     1008 * @return                              number of blocks
    8631009 */
    8641010uint32_t ext4_superblock_get_blocks_in_group(ext4_superblock_t *sb, uint32_t bgid)
     
    8761022}
    8771023
    878 /** TODO comment
    879  *
     1024/** Compute number of i-nodes in specified block group.
     1025 *
     1026 * @param sb            superblock
     1027 * @param bgid          block group index
     1028 * @return                      number of i-nodes
    8801029 */
    8811030uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *sb, uint32_t bgid)
Note: See TracChangeset for help on using the changeset viewer.