Changeset b65cae22 in mainline


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

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/ext2info/ext2info.c

    ra2a1792 rb65cae22  
    5757static void print_block_group(ext2_block_group_t *);
    5858static void print_inode_by_number(ext2_filesystem_t *, uint32_t);
    59 static void print_inode(ext2_inode_t *);
     59static void print_inode(ext2_filesystem_t *, ext2_inode_t *);
    6060
    6161#define ARG_SUPERBLOCK 1
     
    335335        }
    336336       
    337         print_inode(inode_ref->inode);
     337        print_inode(fs, inode_ref->inode);
    338338       
    339339        rc = ext2_filesystem_put_inode_ref(inode_ref);
     
    343343}
    344344
    345 void print_inode(ext2_inode_t *inode)
    346 {
    347         uint16_t mode;
     345void print_inode(ext2_filesystem_t *fs, ext2_inode_t *inode)
     346{
     347        uint32_t mode;
    348348        uint32_t user_id;
    349349        uint32_t group_id;
    350         uint32_t size;
     350        uint64_t size;
    351351        uint16_t usage_count;
    352352        uint32_t flags;
     
    357357        bool all_blocks = false;
    358358       
    359         mode = ext2_inode_get_mode(inode);
    360         user_id = ext2_inode_get_user_id(inode);
    361         group_id = ext2_inode_get_group_id(inode);
    362         size = ext2_inode_get_size(inode);
     359        mode = ext2_inode_get_mode(fs->superblock, inode);
     360        user_id = ext2_inode_get_user_id(fs->superblock, inode);
     361        group_id = ext2_inode_get_group_id(fs->superblock, inode);
     362        size = ext2_inode_get_size(fs->superblock, inode);
    363363        usage_count = ext2_inode_get_usage_count(inode);
    364364        flags = ext2_inode_get_flags(inode);
     
    389389        access = mode & EXT2_INODE_MODE_ACCESS_MASK;
    390390       
    391         printf("  Mode: %04x (Type: %s, Access bits: %04ho)\n", mode, type, access);
     391        printf("  Mode: %08x (Type: %s, Access bits: %04ho)\n", mode, type, access);
    392392        printf("  User ID: %u\n", user_id);
    393393        printf("  Group ID: %u\n", group_id);
    394         printf("  Size: %u\n", size);
     394        printf("  Size: %" PRIu64 "\n", size);
    395395        printf("  Usage (link) count: %u\n", usage_count);
    396396        printf("  Flags: %u\n", flags);
  • 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);
  • uspace/lib/ext2/libext2_inode.h

    ra2a1792 rb65cae22  
    3838
    3939#include <libblock.h>
     40#include "libext2_superblock.h"
    4041
    4142typedef struct ext2_inode {
     
    5354        uint32_t double_indirect_block;
    5455        uint32_t triple_indirect_block;
    55 } ext2_inode_t;
     56        uint32_t version;
     57        uint32_t file_acl;
     58        union {
     59                uint32_t dir_acl;
     60                uint32_t size_high; // For regular files in version >= 1
     61        } __attribute__ ((packed));
     62        uint8_t unused3[6];
     63        uint16_t mode_high; // Hurd only
     64        uint16_t user_id_high; // Linux/Hurd only
     65        uint16_t group_id_high; // Linux/Hurd only
     66} __attribute__ ((packed)) ext2_inode_t;
    5667
    5768#define EXT2_INODE_MODE_FIFO            0x1000
     
    6980} ext2_inode_ref_t;
    7081
    71 inline uint16_t ext2_inode_get_mode(ext2_inode_t *);
    72 inline uint32_t ext2_inode_get_user_id(ext2_inode_t *);
    73 inline uint32_t ext2_inode_get_size(ext2_inode_t *);
    74 inline uint32_t ext2_inode_get_group_id(ext2_inode_t *);
     82inline uint32_t ext2_inode_get_mode(ext2_superblock_t *, ext2_inode_t *);
     83inline uint32_t ext2_inode_get_user_id(ext2_superblock_t *, ext2_inode_t *);
     84inline uint64_t ext2_inode_get_size(ext2_superblock_t *, ext2_inode_t *);
     85inline uint32_t ext2_inode_get_group_id(ext2_superblock_t *, ext2_inode_t *);
    7586inline uint16_t ext2_inode_get_usage_count(ext2_inode_t *);
    7687inline uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *);
  • uspace/lib/ext2/libext2_superblock.h

    ra2a1792 rb65cae22  
    7878#define EXT2_SUPERBLOCK_LAST_BYTE       (EXT2_SUPERBLOCK_OFFSET + \
    7979                                                                         EXT2_SUPERBLOCK_SIZE -1)
     80#define EXT2_SUPERBLOCK_OS_LINUX        0
     81#define EXT2_SUPERBLOCK_OS_HURD         1
    8082
    8183
Note: See TracChangeset for help on using the changeset viewer.