bring parisc linux into the modern age by adding ext4 support to the bootloader
cover bring parisc linux into the modern age by adding ext4 support to the bootloader
The parisc bootloader, palo, has understood how to read ext2/3 filesystems for decades. However, keeping an ext2/3 partition around simply to boot from is becoming a bit old, so add support for ext4 to the iplboot code. Note, this still doesn't fix ipl specific limitations, like the inability to read a disk beyond 2GB, so you will still need a low sector /boot partition for this.
The assumptions I've made adding ext4 are that the only additional variables over ext2/3 are the variable group descriptor size support, conditioned on the EXT4_FEATURE_INCOMPAT_64BIT flag and extent based inodes conditioned on the EXT3_EXTENTS_FL (it's been renamed to EXT4_EXTENTS_FL now in libext2fs).
Filesystem people interested in reviewing the extent handling code probably only need look at patch 3/4 iplboot: add ext4 support
James
---
James Bottomley (4):
iplboot: eliminate unused struct bootfs
iplboot: update the ext2_fs.h header
iplboot: add ext4 support
palo: add support for formatting as ext4
ipl/bootloader.h | 13 --- ipl/ext2.c | 256 +++++++++++++++++++++++++++++++++++++++++++------------ ipl/ext2_fs.h | 42 ++++++++- iplboot | Bin 45056 -> 45056 bytes palo/palo.c | 6 +- 5 files changed, 245 insertions(+), 72 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/4 iplboot: eliminate unused struct bootfs
It's only used locally in ext2.c to carry the blocksize, so make blocksize a static variable instead.
--- ipl/bootloader.h | 13 --------- ipl/ext2.c | 80 ++++++++++++++++++++------------------------------------ 2 files changed, 29 insertions(+), 64 deletions(-)
ipl/bootloader.h +0 -13
@@ -12,19 +12,6 @@#define MAX_FD 20 -struct bootfs { -int fs_type; -int blocksize; - -int (*mount)(long dev,long partition_start,long quiet); - -int (*open)(const char *filename); -int (*bread)(int fd,long blkno,long nblks,char *buf); -void (*close)(int fd); -const char * (*readdir)(int fd,int rewind); -}; - -/* pdc_misc.c */ void die (const char *);void firmware_init (int started_wide);
ipl/ext2.c +29 -51
186 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 2/4 iplboot: update the ext2_fs.h header
In reply to James BottomleyA lot has changed in libext2fs since this header was last imported, but most of it is irrelevant to simply reading files from ext2/3, so only import the additional changes absolutely necessary for reading from an ext4 filesystem.
--- ipl/ext2_fs.h | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
ipl/ext2_fs.h +41 -1
@@ -504,7 +504,7 @@ struct ext2_super_block {__u32 s_hash_seed[4 ];/* HTREE hash seed */ __u8 s_def_hash_version;/* Default hash version to use */ __u8 s_jnl_backup_type;/* Default type of journal backup */ -__u16 s_reserved_word_pad; +__u16 s_desc_size;__u32 s_default_mount_opts;__u32 s_first_meta_bg;/* First metablock group */ __u32 s_mkfs_time;/* When the filesystem was created */
@@ -565,6 +565,8 @@ struct ext2_super_block {#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008/* Journal device */ #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT2_FEATURE_COMPAT_SUPP 0
@@ -643,4 +645,42 @@ struct ext2_dir_entry_2 {#define EXT2_DIR_REC_LEN (name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ ~EXT2_DIR_ROUND) +/* from here we have additional structures from ext3_extents.h */ + +/* +* this is extent on-disk structure +* it's used at the bottom of the tree +*/ +struct ext3_extent { +__le32 ee_block;/* first logical block extent covers */ +__le16 ee_len;/* number of blocks covered by extent */ +__le16 ee_start_hi;/* high 16 bits of physical block */ +__le32 ee_start;/* low 32 bigs of physical block */ +}; + +/* +* this is index on-disk structure +* it's used at all the levels, but the bottom +*/ +struct ext3_extent_idx { +__le32 ei_block;/* index covers logical blocks from 'block' */ +__le32 ei_leaf;/* pointer to the physical block of the next * +* level. leaf or next index could bet here */ +__le16 ei_leaf_hi;/* high 16 bits of physical block */ +__le16 ei_unused; +}; + +/* +* each block (leaves and indexes), even inode-stored has header +*/ +struct ext3_extent_header { +__le16 eh_magic;/* probably will support different formats */ +__le16 eh_entries;/* number of valid entries */ +__le16 eh_max;/* capacity of store in entries */ +__le16 eh_depth;/* has tree real underlying blocks? */ +__le32 eh_generation;/* generation of the tree */ +}; + +#define EXT3_EXT_MAGIC 0xf30a +#endif /* _LINUX_EXT2_FS_H */
Signature · 1 line
2.16.4
PATCH 3/4 iplboot: add ext4 support
In reply to James BottomleyFor a read only filesystem, like iplboot, the only real additions for ext4 are allowing for extent based inodes and a variable group size.
The current block transformation scheme simply goes from filesystem block offset to absolute partition block employing a caching scheme for the indirect inodes. We can follow a similar scheme for the extent tree based on depth, relying on the fact that linear block loading will optimally keep the cache at a given depth until it's not needed.
--- ipl/ext2.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 7 deletions(-)
ipl/ext2.c +173 -7
@@ -25,6 +25,7 @@#include "bootloader.h" #define MAX_OPEN_FILES 5 +#define EXTENT_MAX_DEPTH 5static int ext2_blocksize;
@@ -32,6 +33,7 @@ static struct ext2_super_block sb;static struct ext2_group_desc *gds;static struct ext2_inode *root_inode =NULL ;static int ngroups =0 ; +static int group_size;static int directlim;/* Maximum direct blkno */ static int ind1lim;/* Maximum single-indir blkno */ static int ind2lim;/* Maximum double-indir blkno */
@@ -62,6 +64,11 @@ static struct inode_table_entry {#undef DEBUG#define Debug 0 +static struct ext3_extent_header *ext3_extent_header (struct ext2_inode *i) +{ +return (struct ext3_extent_header *)&i->i_block[0 ]; +} +static void swapsb (struct ext2_super_block *sb) {
@@ -104,6 +111,8 @@ static void swapsb(struct ext2_super_block *sb)inplace (__le32_to_cpu, sb->s_feature_ro_compat);inplace (__le32_to_cpu, sb->s_algorithm_usage_bitmap); +inplace (__le16_to_cpu, sb->s_desc_size); +/* whew! */ }
@@ -119,6 +128,15 @@ static void swapgrp(struct ext2_group_desc *g) } +static void swapextenthdr (struct ext3_extent_header *hdr) +{ +inplace (__le16_to_cpu, hdr->eh_magic); +inplace (__le16_to_cpu, hdr->eh_entries); +inplace (__le16_to_cpu, hdr->eh_max); +inplace (__le16_to_cpu, hdr->eh_depth); +inplace (__le32_to_cpu, hdr->eh_generation); +} +static void swapino (struct ext2_inode *i) {int n;
@@ -148,8 +166,18 @@ static void swapino(struct ext2_inode *i) } masix1; } osd1;/* OS dependent 1 */ #endif -for (n =0 ; n <EXT2_N_BLOCKS ; n++) { -inplace (__le32_to_cpu, i->i_block[n]); +if ((i->i_flags &EXT3_EXTENTS_FL )) { +/* the extent header is in the i_block array */ +struct ext3_extent_header *hdr =ext3_extent_header (i); + +swapextenthdr (hdr); +if (Debug) +printf ("ext4: extent based inode; depth %d, size %d\n" , + hdr->eh_depth, hdr->eh_entries); + }else { +for (n =0 ; n <EXT2_N_BLOCKS ; n++) { +inplace (__le32_to_cpu, i->i_block[n]); + } }inplace (__le32_to_cpu, i->i_generation);inplace (__le32_to_cpu, i->i_file_acl);
@@ -193,6 +221,13 @@ static void swapde(struct ext2_dir_entry_2 *de) de->name_len, de->name); } +static struct ext2_group_desc *ext2_gds (int i) +{ +char *ptr = (char *)gds; + +return (struct ext2_group_desc *)(ptr + group_size * i); +} +/* * Initialize an ext2 partition starting at offset P_OFFSET; this is * sort-of the same idea as "mounting" it. Read in the relevant
@@ -239,8 +274,14 @@ int ext2_mount(long cons_dev, long p_offset, long quiet) EXT2_BLOCKS_PER_GROUP(&sb) - 1) /EXT2_BLOCKS_PER_GROUP (&sb); - gds = (struct ext2_group_desc *) -malloc ((size_t )(ngroups *sizeof (struct ext2_group_desc ))); +if (sb.s_feature_incompat &EXT4_FEATURE_INCOMPAT_64BIT ) + group_size = sb.s_desc_size; +else + group_size =sizeof (struct ext2_group_desc ); + +printf ("filesystem group size %d\n" , group_size); + + gds = (struct ext2_group_desc *)malloc (ngroups * group_size); ext2_blocksize =EXT2_BLOCK_SIZE (&sb);if (Debug)printf ("ext2 block size %d\n" , ext2_blocksize);
@@ -251,7 +292,7 @@ int ext2_mount(long cons_dev, long p_offset, long quiet) ext2_blocksize * (EXT2_MIN_BLOCK_SIZE/ext2_blocksize + 1));for (i =0 ; i < ngroups; i++) { -swapgrp (&gds[i]); +swapgrp (ext2_gds (i)); }/* * Calculate direct/indirect block limits for this file system
@@ -317,7 +358,7 @@ static struct ext2_inode *ext2_iget(int ino)printf ("group is %d\n" , group);#endif offset = partition_offset - + ((long ) gds[group].bg_inode_table * (long )ext2_blocksize) + + ((long )ext2_gds (group)->bg_inode_table * (long )ext2_blocksize) + (((ino -1 ) %EXT2_INODES_PER_GROUP (&sb)) *EXT2_INODE_SIZE (&sb));#ifdef DEBUG
@@ -325,7 +366,7 @@ static struct ext2_inode *ext2_iget(int ino)"(%ld + (%d * %d) + ((%d) %% %d) * %d) " "(inode %d -> table %d)\n" ,sizeof (struct ext2_inode ), offset, partition_offset, - gds[group].bg_inode_table, ext2_blocksize, +ext2_gds (group)->bg_inode_table, ext2_blocksize, ino -1 ,EXT2_INODES_PER_GROUP (&sb),EXT2_INODE_SIZE (&sb), ino, (int) (itp - inode_table));#endif
@@ -338,6 +379,18 @@ static struct ext2_inode *ext2_iget(int ino)swapino (ip);if (Debug)printinode ("iget" , ip); +if (ip->i_flags &EXT3_EXTENTS_FL ) { +struct ext3_extent_header *hdr =ext3_extent_header (ip); + +if (hdr->eh_magic !=EXT3_EXT_MAGIC ) { +printf ("ext2_iget: wrong extent magic in inode\n" ); +return NULL ; + } +if (hdr->eh_depth >EXTENT_MAX_DEPTH ) { +printf ("ext2_iget: file has too deep an extent tree]n" ); +return NULL ; + } + } itp->free =0 ; itp->inumber = ino;
@@ -366,6 +419,116 @@ static void ext2_iput(struct ext2_inode *ip) itp->free =1 ; } +/* +* Recursive function to find the mapping of a block in the extent +* tree We make a load of assumptions here, firstly, since we're +* dealing with filesystems < 2GB we assume all the _hi elements are +* zero. Secondly we assume monotonic logical block traversal for +* kernel/initrd loading, so the cache is static per depth in the +* tree. +*/ + +static int ext3_extent_leaf_find (struct ext3_extent_header *hdr,int blkoff) +{ +struct ext3_extent *leaf = (struct ext3_extent *)(hdr +1 ); +int i; + +for (i =0 ; i < hdr->eh_entries; i++) { +__u32 block =__le32_to_cpu (leaf[i].ee_block); +__u16 len =__le16_to_cpu (leaf[i].ee_len); +__u32 start =__le32_to_cpu (leaf[i].ee_start); + +if (block <= blkoff && block + len > blkoff) +return blkoff - block + start; + } + +/* block is not in map: this means a hole */ +return 0 ; +} + +static int ext3_extent_load_find (struct ext2_inode *ip,int leaf,int d, +int blkoff); + +static int ext3_extent_node_find (struct ext2_inode *ip, +struct ext3_extent_header *hdr,int blkoff) +{ +struct ext3_extent_idx *node = (struct ext3_extent_idx *)(hdr +1 ); +struct ext3_extent_idx *prev = node; +int i; +__u32 start =__le32_to_cpu (prev->ei_block); +__u32 leaf =__le32_to_cpu (prev->ei_leaf); + +for (i =1 ; i < hdr->eh_entries; i++) { +__u32 block =__le32_to_cpu (node[i].ei_block); + +if (start <= blkoff && block > blkoff) +break ; + + prev = &node[i]; + start =__le32_to_cpu (prev->ei_block); + leaf =__le32_to_cpu (prev->ei_leaf); + } + +return ext3_extent_load_find (ip, leaf, hdr->eh_depth -1 , blkoff); +} + +static int ext3_extent_load_find (struct ext2_inode *ip,int leaf,int d, +int blkoff) +{ +static char blockbuf[EXTENT_MAX_DEPTH ][EXT2_MAX_BLOCK_SIZE ]; +static int cached_blockno[EXTENT_MAX_DEPTH ]; +struct ext3_extent_header *hdr; + + hdr = (struct ext3_extent_header *)blockbuf[d]; +if (cached_blockno[d] != leaf) { +printf ("load extent tree[%d] block at %d\n" , d, leaf); + +if (cons_read (dev, blockbuf[d],sizeof (blockbuf[d]), + leaf * ext2_blocksize) != +sizeof (blockbuf[d])) { +printf ("ext3_extent_load_find: read error\n" ); +return -1 ; + } + cached_blockno[d] = leaf; +swapextenthdr (hdr); + } + +/* these checks could be done once after load, but belt and braces */ +if (hdr->eh_magic !=EXT3_EXT_MAGIC ) { +printf ("ext3_extent_load_find: wrong extent magic in block\n" ); +return -1 ; + } +if (hdr->eh_depth != d) { +printf ("ext3_extent_load_find: wrong depth %d!=%d\n" , + hdr->eh_depth, d); +return -1 ; + } +if (sizeof (hdr) +sizeof (struct ext3_extent )*hdr->eh_entries > +sizeof (blockbuf[d])) { +printf ("ext3_extent_load_find: extent is larger than buffer\n" ); +return -1 ; + } + +if (hdr->eh_depth ==0 ) +return ext3_extent_leaf_find (hdr, blkoff); +else +return ext3_extent_node_find (ip, hdr, blkoff); +} + +/* +* Map a block using the extents tree +*/ +static int ext3_extent_blkno (struct ext2_inode *ip,int blkoff) +{ +struct ext3_extent_header *hdr =ext3_extent_header (ip); + + +if (hdr->eh_depth ==0 ) +return ext3_extent_leaf_find (hdr, blkoff); +else +return ext3_extent_node_find (ip, hdr, blkoff); +} +/* * Map a block offset into a file into an absolute block number.
@@ -385,6 +548,9 @@ static int ext2_blkno(struct ext2_inode *ip, int blkoff)int diblkno;unsigned long offset; +if (ip->i_flags &EXT3_EXTENTS_FL ) +return ext3_extent_blkno (ip, blkoff); + ilp = (unsigned int *)iblkbuf; dlp = (unsigned int *)diblkbuf;
Signature · 1 line
2.16.4
PATCH 4/4 palo: add support for formatting as ext4
In reply to James BottomleyNow that iplboot can read ext4 filesystem, allow palo to create them with the palo --format-as=4 option.
--- palo/palo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
palo/palo.c +4 -2
@@ -506,8 +506,8 @@ do_formatted(int init, int media, const char *medianame, int partition, } } -sprintf (cmd,"mke2fs %s -O^resize_inode -b %d -l %s %s" , do_format ==3 ?"-j" :"" , -EXT2_BLOCKSIZE , badblockfilename, partitionname); +sprintf (cmd,"mke2fs -t ext%d -O^resize_inode -b %d -l %s %s" , + do_format,EXT2_BLOCKSIZE , badblockfilename, partitionname);if (verbose)printf ("Executing: %s\n" , cmd);
@@ -868,6 +868,8 @@ main(int argc, char *argv[]) format_as =2 ; else if(strcmp(optarg, "3") == 0) format_as = 3; + else if (strcmp(optarg, "4") == 0) + format_as = 4; else error(0, argv[0]);break ;
Signature · 1 line
2.16.4