124 lines
3.0 KiB
C
124 lines
3.0 KiB
C
#ifndef _BOOT_LIBBOOT_FS_EXT2_LITE
|
|
#define _BOOT_LIBBOOT_FS_EXT2_LITE
|
|
|
|
#include <libboot/abi/drivers.h>
|
|
#include <libboot/types.h>
|
|
|
|
#define SUPERBLOCK_START 1024
|
|
#define SUPERBLOCK_LEN (sizeof(superblock_t))
|
|
typedef struct {
|
|
uint32_t inodes_count;
|
|
uint32_t blocks_count;
|
|
uint32_t r_blocks_count;
|
|
uint32_t free_blocks_count;
|
|
uint32_t free_inodes_count;
|
|
uint32_t first_data_block;
|
|
uint32_t log_block_size;
|
|
uint32_t log_frag_size;
|
|
uint32_t blocks_per_group;
|
|
uint32_t frags_per_group;
|
|
uint32_t inodes_per_group;
|
|
uint32_t mtime;
|
|
uint32_t wtime;
|
|
uint16_t mnt_count;
|
|
uint16_t max_mnt_count;
|
|
uint16_t magic;
|
|
uint16_t state;
|
|
uint16_t errors;
|
|
uint16_t minor_rev_level;
|
|
uint32_t lastcheck;
|
|
uint32_t checkinterval;
|
|
uint32_t creator_os;
|
|
uint32_t rev_level;
|
|
uint16_t def_resuid;
|
|
uint16_t def_resgid;
|
|
|
|
uint32_t first_ino;
|
|
uint16_t inode_size;
|
|
uint16_t block_group_nr;
|
|
uint32_t feature_compat;
|
|
uint32_t feature_incompat;
|
|
uint32_t feature_ro_compat;
|
|
uint8_t uuid[16];
|
|
uint8_t volume_name[16];
|
|
uint8_t last_mounted[64];
|
|
uint32_t algo_bitmap;
|
|
|
|
uint8_t prealloc_blocks;
|
|
uint8_t prealloc_dir_blocks;
|
|
|
|
// current jurnalling is unsupported
|
|
uint8_t unused[1024 - 206];
|
|
} superblock_t;
|
|
|
|
#define GROUP_LEN (sizeof(group_desc_t))
|
|
typedef struct {
|
|
uint32_t block_bitmap;
|
|
uint32_t inode_bitmap;
|
|
uint32_t inode_table;
|
|
uint16_t free_blocks_count;
|
|
uint16_t free_inodes_count;
|
|
uint16_t used_dirs_count;
|
|
uint16_t pad;
|
|
uint8_t reserved[12];
|
|
} group_desc_t;
|
|
|
|
#define S_IFSOCK 0xC000
|
|
#define S_IFLNK 0xA000
|
|
#define S_IFREG 0x8000
|
|
#define S_IFBLK 0x6000
|
|
#define S_IFDIR 0x4000
|
|
#define S_IFCHR 0x2000
|
|
#define S_IFIFO 0x1000
|
|
|
|
#define S_ISUID 0x0800
|
|
#define S_ISGID 0x0400
|
|
#define S_ISVTX 0x0200
|
|
|
|
#define S_IRUSR 0x0100
|
|
#define S_IWUSR 0x0080
|
|
#define S_IXUSR 0x0040
|
|
#define S_IRGRP 0x0020
|
|
#define S_IWGRP 0x0010
|
|
#define S_IXGRP 0x0008
|
|
#define S_IROTH 0x0004
|
|
#define S_IWOTH 0x0002
|
|
#define S_IXOTH 0x0001
|
|
|
|
#define INODE_LEN (sizeof(inode_t))
|
|
#define INODES_RESERVED 11
|
|
typedef struct {
|
|
uint16_t mode;
|
|
uint16_t uid;
|
|
uint32_t size;
|
|
uint32_t atime;
|
|
uint32_t ctime;
|
|
uint32_t mtime;
|
|
uint32_t dtime;
|
|
uint16_t gid;
|
|
uint16_t links_count;
|
|
uint32_t blocks;
|
|
uint32_t flags;
|
|
uint32_t osd1;
|
|
uint32_t block[15];
|
|
uint32_t generation;
|
|
uint32_t file_acl;
|
|
uint32_t dir_acl;
|
|
uint32_t faddr;
|
|
uint32_t osd2[3];
|
|
} inode_t;
|
|
|
|
typedef struct {
|
|
uint32_t inode;
|
|
uint16_t rec_len;
|
|
uint8_t name_len;
|
|
uint8_t file_type;
|
|
char* name; // may be a problematic for 64bit versions
|
|
} dir_entry_t;
|
|
|
|
int ext2_lite_init(drive_desc_t* drive_desc, fs_desc_t* fs_desc);
|
|
int ext2_lite_get_inode(drive_desc_t* drive_desc, const char* path, inode_t* file_inode);
|
|
int ext2_lite_read(drive_desc_t* drive_desc, const char* path, uint8_t* buf, uint32_t from, uint32_t len);
|
|
int ext2_lite_read_inode(drive_desc_t* drive_desc, inode_t* inode, uint8_t* buf, uint32_t from, uint32_t len);
|
|
|
|
#endif // _BOOT_LIBBOOT_FS_EXT2_LITE
|