diff options
author | Rob Landley <rob@landley.net> | 2018-03-23 19:28:40 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-03-23 19:28:40 -0500 |
commit | 7fe1c73cf9406c832474dba5352e6096b86b3ebf (patch) | |
tree | 52350fbb1966e2a941648f1b79df7a16af4928cb | |
parent | de28ab46e8ee63329959bd572ce1c3a54cabee60 (diff) | |
download | toybox-7fe1c73cf9406c832474dba5352e6096b86b3ebf.tar.gz |
Inline toys/e2fs.h into mke2fs.c. (Debris from the dawn of time.)
-rw-r--r-- | toys.h | 1 | ||||
-rw-r--r-- | toys/e2fs.h | 142 | ||||
-rw-r--r-- | toys/pending/mke2fs.c | 147 |
3 files changed, 142 insertions, 148 deletions
@@ -70,7 +70,6 @@ #include "lib/lib.h" #include "lib/lsm.h" #include "lib/toyflags.h" -#include "toys/e2fs.h" // Get list of function prototypes for all enabled command_main() functions. diff --git a/toys/e2fs.h b/toys/e2fs.h deleted file mode 100644 index 43594114..00000000 --- a/toys/e2fs.h +++ /dev/null @@ -1,142 +0,0 @@ -/* mke2fs.h - Headers for ext2 - * - * Copyright 2006 Rob Landley <rob@landley.net> - */ - -// Stuff defined in linux/ext2_fs.h - -#define EXT2_SUPER_MAGIC 0xEF53 - -struct ext2_superblock { - uint32_t inodes_count; // Inodes count - uint32_t blocks_count; // Blocks count - uint32_t r_blocks_count; // Reserved blocks count - uint32_t free_blocks_count; // Free blocks count - uint32_t free_inodes_count; // Free inodes count - uint32_t first_data_block; // First Data Block - uint32_t log_block_size; // Block size - uint32_t log_frag_size; // Fragment size - uint32_t blocks_per_group; // Blocks per group - uint32_t frags_per_group; // Fragments per group - uint32_t inodes_per_group; // Inodes per group - uint32_t mtime; // Mount time - uint32_t wtime; // Write time - uint16_t mnt_count; // Mount count - uint16_t max_mnt_count; // Maximal mount count - uint16_t magic; // Magic signature - uint16_t state; // File system state - uint16_t errors; // Behaviour when detecting errors - uint16_t minor_rev_level; // minor revision level - uint32_t lastcheck; // time of last check - uint32_t checkinterval; // max. time between checks - uint32_t creator_os; // OS - uint32_t rev_level; // Revision level - uint16_t def_resuid; // Default uid for reserved blocks - uint16_t def_resgid; // Default gid for reserved blocks - uint32_t first_ino; // First non-reserved inode - uint16_t inode_size; // size of inode structure - uint16_t block_group_nr; // block group # of this superblock - uint32_t feature_compat; // compatible feature set - uint32_t feature_incompat; // incompatible feature set - uint32_t feature_ro_compat; // readonly-compatible feature set - char uuid[16]; // 128-bit uuid for volume - char volume_name[16]; // volume name - char last_mounted[64]; // directory where last mounted - uint32_t alg_usage_bitmap; // For compression - // For EXT2_COMPAT_PREALLOC - uint8_t prealloc_blocks; // Nr of blocks to try to preallocate - uint8_t prealloc_dir_blocks; //Nr to preallocate for dirs - uint16_t padding1; - // For EXT3_FEATURE_COMPAT_HAS_JOURNAL - uint8_t journal_uuid[16]; // uuid of journal superblock - uint32_t journal_inum; // inode number of journal file - uint32_t journal_dev; // device number of journal file - uint32_t last_orphan; // start of list of inodes to delete - uint32_t hash_seed[4]; // HTREE hash seed - uint8_t def_hash_version; // Default hash version to use - uint8_t padding2[3]; - uint32_t default_mount_opts; - uint32_t first_meta_bg; // First metablock block group - uint32_t mkfs_time; // Creation timestamp - uint32_t jnl_blocks[17]; // Backup of journal inode - // uint32_t reserved[172]; // Padding to the end of the block -}; - -struct ext2_group -{ - uint32_t block_bitmap; // Block number of block bitmap - uint32_t inode_bitmap; // Block number of inode bitmap - uint32_t inode_table; // Block number of inode table - uint16_t free_blocks_count; // How many free blocks in this group? - uint16_t free_inodes_count; // How many free inodes in this group? - uint16_t used_dirs_count; // How many directories? - uint16_t reserved[7]; // pad to 32 bytes -}; - -struct ext2_dentry { - uint32_t inode; // Inode number - uint16_t rec_len; // Directory entry length - uint8_t name_len; // Name length - uint8_t file_type; - char name[0]; // File name -}; - -struct ext2_inode { - uint16_t mode; // File mode - uint16_t uid; // Low 16 bits of Owner Uid - uint32_t size; // Size in bytes - uint32_t atime; // Access time - uint32_t ctime; // Creation time - uint32_t mtime; // Modification time - uint32_t dtime; // Deletion Time - uint16_t gid; // Low 16 bits of Group Id - uint16_t links_count; // Links count - uint32_t blocks; // Blocks count - uint32_t flags; // File flags - uint32_t reserved1; - uint32_t block[15]; // Pointers to blocks - uint32_t generation; // File version (for NFS) - uint32_t file_acl; // File ACL - uint32_t dir_acl; // Directory ACL (or top bits of file length) - uint32_t faddr; // Last block in file - uint8_t frag; // Fragment number - uint8_t fsize; // Fragment size - uint16_t pad1; - uint16_t uid_high; // High bits of uid - uint16_t gid_high; // High bits of gid - uint32_t reserved2; -}; - -#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 -#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 -#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008 -#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010 -#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 - -#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 -#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 -#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 - -#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 -#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 -#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 -#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 - -#define EXT2_NAME_LEN 255 - -// Ext2 directory file types. Only the low 3 bits are used. The -// other bits are reserved for now. - -enum { - EXT2_FT_UNKNOWN, - EXT2_FT_REG_FILE, - EXT2_FT_DIR, - EXT2_FT_CHRDEV, - EXT2_FT_BLKDEV, - EXT2_FT_FIFO, - EXT2_FT_SOCK, - EXT2_FT_SYMLINK, - EXT2_FT_MAX -}; diff --git a/toys/pending/mke2fs.c b/toys/pending/mke2fs.c index b4c841ad..19ef5fb0 100644 --- a/toys/pending/mke2fs.c +++ b/toys/pending/mke2fs.c @@ -97,10 +97,146 @@ GLOBALS( unsigned nextblock; // Next data block to allocate unsigned nextgroup; // Next group we'll be allocating from int fsfd; // File descriptor of filesystem (to output to). - - struct ext2_superblock sb; ) +// Stuff defined in linux/ext2_fs.h + +#define EXT2_SUPER_MAGIC 0xEF53 + +struct ext2_superblock { + uint32_t inodes_count; // Inodes count + uint32_t blocks_count; // Blocks count + uint32_t r_blocks_count; // Reserved blocks count + uint32_t free_blocks_count; // Free blocks count + uint32_t free_inodes_count; // Free inodes count + uint32_t first_data_block; // First Data Block + uint32_t log_block_size; // Block size + uint32_t log_frag_size; // Fragment size + uint32_t blocks_per_group; // Blocks per group + uint32_t frags_per_group; // Fragments per group + uint32_t inodes_per_group; // Inodes per group + uint32_t mtime; // Mount time + uint32_t wtime; // Write time + uint16_t mnt_count; // Mount count + uint16_t max_mnt_count; // Maximal mount count + uint16_t magic; // Magic signature + uint16_t state; // File system state + uint16_t errors; // Behaviour when detecting errors + uint16_t minor_rev_level; // minor revision level + uint32_t lastcheck; // time of last check + uint32_t checkinterval; // max. time between checks + uint32_t creator_os; // OS + uint32_t rev_level; // Revision level + uint16_t def_resuid; // Default uid for reserved blocks + uint16_t def_resgid; // Default gid for reserved blocks + uint32_t first_ino; // First non-reserved inode + uint16_t inode_size; // size of inode structure + uint16_t block_group_nr; // block group # of this superblock + uint32_t feature_compat; // compatible feature set + uint32_t feature_incompat; // incompatible feature set + uint32_t feature_ro_compat; // readonly-compatible feature set + char uuid[16]; // 128-bit uuid for volume + char volume_name[16]; // volume name + char last_mounted[64]; // directory where last mounted + uint32_t alg_usage_bitmap; // For compression + // For EXT2_COMPAT_PREALLOC + uint8_t prealloc_blocks; // Nr of blocks to try to preallocate + uint8_t prealloc_dir_blocks; //Nr to preallocate for dirs + uint16_t padding1; + // For EXT3_FEATURE_COMPAT_HAS_JOURNAL + uint8_t journal_uuid[16]; // uuid of journal superblock + uint32_t journal_inum; // inode number of journal file + uint32_t journal_dev; // device number of journal file + uint32_t last_orphan; // start of list of inodes to delete + uint32_t hash_seed[4]; // HTREE hash seed + uint8_t def_hash_version; // Default hash version to use + uint8_t padding2[3]; + uint32_t default_mount_opts; + uint32_t first_meta_bg; // First metablock block group + uint32_t mkfs_time; // Creation timestamp + uint32_t jnl_blocks[17]; // Backup of journal inode + // uint32_t reserved[172]; // Padding to the end of the block +}; + +struct ext2_group +{ + uint32_t block_bitmap; // Block number of block bitmap + uint32_t inode_bitmap; // Block number of inode bitmap + uint32_t inode_table; // Block number of inode table + uint16_t free_blocks_count; // How many free blocks in this group? + uint16_t free_inodes_count; // How many free inodes in this group? + uint16_t used_dirs_count; // How many directories? + uint16_t reserved[7]; // pad to 32 bytes +}; + +struct ext2_dentry { + uint32_t inode; // Inode number + uint16_t rec_len; // Directory entry length + uint8_t name_len; // Name length + uint8_t file_type; + char name[0]; // File name +}; + +struct ext2_inode { + uint16_t mode; // File mode + uint16_t uid; // Low 16 bits of Owner Uid + uint32_t size; // Size in bytes + uint32_t atime; // Access time + uint32_t ctime; // Creation time + uint32_t mtime; // Modification time + uint32_t dtime; // Deletion Time + uint16_t gid; // Low 16 bits of Group Id + uint16_t links_count; // Links count + uint32_t blocks; // Blocks count + uint32_t flags; // File flags + uint32_t reserved1; + uint32_t block[15]; // Pointers to blocks + uint32_t generation; // File version (for NFS) + uint32_t file_acl; // File ACL + uint32_t dir_acl; // Directory ACL (or top bits of file length) + uint32_t faddr; // Last block in file + uint8_t frag; // Fragment number + uint8_t fsize; // Fragment size + uint16_t pad1; + uint16_t uid_high; // High bits of uid + uint16_t gid_high; // High bits of gid + uint32_t reserved2; +}; + +#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 +#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008 +#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010 +#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 + +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 + +#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 + +#define EXT2_NAME_LEN 255 + +// Ext2 directory file types. Only the low 3 bits are used. The +// other bits are reserved for now. + +enum { + EXT2_FT_UNKNOWN, + EXT2_FT_REG_FILE, + EXT2_FT_DIR, + EXT2_FT_CHRDEV, + EXT2_FT_BLKDEV, + EXT2_FT_FIFO, + EXT2_FT_SOCK, + EXT2_FT_SYMLINK, + EXT2_FT_MAX +}; + #define INODES_RESERVED 10 static uint32_t div_round_up(uint32_t a, uint32_t b) @@ -412,6 +548,7 @@ void mke2fs_main(void) off_t length; uint32_t usedblocks, usedinodes, dtiblk, dtbblk; struct dirtree *dti, *dtb; + struct ext2_superblock sb; // Handle command line arguments. @@ -491,7 +628,7 @@ void mke2fs_main(void) // Now we know all the TT data, initialize superblock structure. - init_superblock(&TT.sb); + init_superblock(&sb); // Start writing. Skip the first 1k to avoid the boot sector (if any). put_zeroes(1024); @@ -516,10 +653,10 @@ void mke2fs_main(void) struct ext2_group *bg = (struct ext2_group *)toybuf; int treeblocks = TT.treeblocks, treeinodes = TT.treeinodes; - TT.sb.block_group_nr = SWAP_LE16(i); + sb.block_group_nr = SWAP_LE16(i); // Write superblock and pad it up to block size - xwrite(TT.fsfd, &TT.sb, sizeof(struct ext2_superblock)); + xwrite(TT.fsfd, &sb, sizeof(struct ext2_superblock)); temp = TT.blocksize - sizeof(struct ext2_superblock); if (!i && TT.blocksize > 1024) temp -= 1024; memset(toybuf, 0, TT.blocksize); |