Changeset b65cae22 in mainline for uspace/lib/ext2/libext2_inode.c


Ignore:
Timestamp:
2011-02-16T20:21:03Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f483a15
Parents:
a2a1792
Message:

Add support for some OS specific fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/libext2_inode.c

    ra2a1792 rb65cae22  
    3636#include "libext2.h"
    3737#include "libext2_inode.h"
     38#include "libext2_superblock.h"
    3839#include <byteorder.h>
    3940
     
    4344 * @param inode pointer to inode
    4445 */
    45 inline uint16_t ext2_inode_get_mode(ext2_inode_t *inode)
     46inline uint32_t ext2_inode_get_mode(ext2_superblock_t *sb, ext2_inode_t *inode)
    4647{
     48        if (ext2_superblock_get_os(sb) == EXT2_SUPERBLOCK_OS_HURD) {
     49                return ((uint32_t)uint16_t_le2host(inode->mode_high)) << 16 |
     50                    ((uint32_t)uint16_t_le2host(inode->mode));
     51        }
    4752        return uint16_t_le2host(inode->mode);
    4853}
     
    5358 * @param inode pointer to inode
    5459 */
    55 inline uint32_t ext2_inode_get_user_id(ext2_inode_t *inode)
     60inline uint32_t ext2_inode_get_user_id(ext2_superblock_t *sb, ext2_inode_t *inode)
    5661{
    57         // TODO: use additional OS specific bits
     62        uint32_t os = ext2_superblock_get_os(sb);
     63        if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) {
     64                return ((uint32_t)uint16_t_le2host(inode->user_id_high)) << 16 |
     65                    ((uint32_t)uint16_t_le2host(inode->user_id));
     66        }
    5867        return uint16_t_le2host(inode->user_id);
    5968}
     
    6271 * Get size of file
    6372 *
     73 * For regular files in revision 1 and later, the high 32 bits of
     74 * file size are stored in inode->size_high and are 0 otherwise
     75 *
    6476 * @param inode pointer to inode
    6577 */
    66 inline uint32_t ext2_inode_get_size(ext2_inode_t *inode)
     78inline uint64_t ext2_inode_get_size(ext2_superblock_t *sb, ext2_inode_t *inode)
    6779{
    68         // TODO: Directory ACLS!
    69         return uint16_t_le2host(inode->size);
     80        uint32_t major_rev = ext2_superblock_get_rev_major(sb);
     81        uint32_t mode = ext2_inode_get_mode(sb, inode);
     82       
     83        if (major_rev > 0 && mode & EXT2_INODE_MODE_FILE) {
     84                return ((uint64_t)uint32_t_le2host(inode->size_high)) << 32 |
     85                    ((uint64_t)uint32_t_le2host(inode->size));
     86        }
     87        return uint32_t_le2host(inode->size);
    7088}
    7189
     
    7391 * Get gid this inode belongs to
    7492 *
     93 * For Linux and Hurd, the high 16 bits are stored in OS dependent part
     94 * of inode structure
     95 *
    7596 * @param inode pointer to inode
    7697 */
    77 inline uint32_t ext2_inode_get_group_id(ext2_inode_t *inode)
     98inline uint32_t ext2_inode_get_group_id(ext2_superblock_t *sb, ext2_inode_t *inode)
    7899{
    79         // TODO: use additional OS specific bits
     100        uint32_t os = ext2_superblock_get_os(sb);
     101        if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) {
     102                return ((uint32_t)uint16_t_le2host(inode->group_id_high)) << 16 |
     103                    ((uint32_t)uint16_t_le2host(inode->group_id));
     104        }
    80105        return uint16_t_le2host(inode->group_id);
    81106}
     
    93118
    94119/**
    95  * Get size of inode in 512 byte blocks
    96  * TODO: clarify this
     120 * Get number of 512-byte data blocks allocated for contents of the file
     121 * represented by this inode.
     122 * This should be multiple of block size unless fragments are used.
    97123 *
    98124 * @param inode pointer to inode
     
    108134 * @param inode pointer to inode
    109135 */
    110 
    111136inline uint32_t ext2_inode_get_flags(ext2_inode_t *inode) {
    112137        return uint32_t_le2host(inode->flags);
Note: See TracChangeset for help on using the changeset viewer.