From patchwork Fri Jul 5 20:15:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 1128229 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=HansenPartnership.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="UacpHspT"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="UacpHspT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45gR1D5DxVz9sNj for ; Sat, 6 Jul 2019 06:15:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727810AbfGEUPn (ORCPT ); Fri, 5 Jul 2019 16:15:43 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:59814 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfGEUPn (ORCPT ); Fri, 5 Jul 2019 16:15:43 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id BFDC68EE1F7; Fri, 5 Jul 2019 13:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357742; bh=e5/bI1Cum6ei0b0XE2xAlH9tdKUwuuduNp6TYLfFJUk=; h=Subject:From:To:Date:In-Reply-To:References:From; b=UacpHspTk63g49PxxaQvY4AK64Fl7otU2LHsf/gSImaJxyJ5QtBdcv0aICi3YDTbo C1JyOsLqCZNn0Zdb0dVsn3/jj8zKrGrBCs3Mdw87igIn6mmRKTHHE+8wkOaycNS6Nh KmlbMVMxl8apDdQeEk8tY68EK/UznMvXZOHLueqE= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ne0Xyb7bAnK0; Fri, 5 Jul 2019 13:15:42 -0700 (PDT) Received: from jarvis.lan (unknown [50.35.68.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 689E48EE0CF; Fri, 5 Jul 2019 13:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357742; bh=e5/bI1Cum6ei0b0XE2xAlH9tdKUwuuduNp6TYLfFJUk=; h=Subject:From:To:Date:In-Reply-To:References:From; b=UacpHspTk63g49PxxaQvY4AK64Fl7otU2LHsf/gSImaJxyJ5QtBdcv0aICi3YDTbo C1JyOsLqCZNn0Zdb0dVsn3/jj8zKrGrBCs3Mdw87igIn6mmRKTHHE+8wkOaycNS6Nh KmlbMVMxl8apDdQeEk8tY68EK/UznMvXZOHLueqE= Message-ID: <1562357740.10899.6.camel@HansenPartnership.com> Subject: [PATCH 1/4] iplboot: eliminate unused struct bootfs From: James Bottomley To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Parisc List Date: Fri, 05 Jul 2019 13:15:40 -0700 In-Reply-To: <1562357231.10899.5.camel@HansenPartnership.com> References: <1562357231.10899.5.camel@HansenPartnership.com> X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org It's only used locally in ext2.c to carry the blocksize, so make blocksize a static variable instead. Signed-off-by: James Bottomley --- ipl/bootloader.h | 13 --------- ipl/ext2.c | 80 ++++++++++++++++++++------------------------------------ 2 files changed, 29 insertions(+), 64 deletions(-) diff --git a/ipl/bootloader.h b/ipl/bootloader.h index 626ebd3..956b6ed 100644 --- a/ipl/bootloader.h +++ b/ipl/bootloader.h @@ -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); diff --git a/ipl/ext2.c b/ipl/ext2.c index 4679c13..9d198fe 100644 --- a/ipl/ext2.c +++ b/ipl/ext2.c @@ -26,7 +26,7 @@ #define MAX_OPEN_FILES 5 -extern struct bootfs ext2fs; +static int ext2_blocksize; static struct ext2_super_block sb; static struct ext2_group_desc *gds; @@ -242,26 +242,26 @@ int ext2_mount(long cons_dev, long p_offset, long quiet) gds = (struct ext2_group_desc *) malloc((size_t)(ngroups * sizeof(struct ext2_group_desc))); - ext2fs.blocksize = EXT2_BLOCK_SIZE(&sb); - if (Debug) printf("ext2 block size %d\n", ext2fs.blocksize); + ext2_blocksize = EXT2_BLOCK_SIZE(&sb); + if (Debug) printf("ext2 block size %d\n", ext2_blocksize); /* read in the group descriptors (immediately follows superblock) */ cons_read(dev, gds, ngroups * sizeof(struct ext2_group_desc), partition_offset + - ext2fs.blocksize * (EXT2_MIN_BLOCK_SIZE/ext2fs.blocksize + 1)); + ext2_blocksize * (EXT2_MIN_BLOCK_SIZE/ext2_blocksize + 1)); for (i = 0; i < ngroups; i++) { swapgrp(&gds[i]); } /* * Calculate direct/indirect block limits for this file system - * (blocksize dependent): + * (ext2_blocksize dependent): */ - ext2fs.blocksize = EXT2_BLOCK_SIZE(&sb); - if (Debug) printf("ext2 block size %d\n", ext2fs.blocksize); + ext2_blocksize = EXT2_BLOCK_SIZE(&sb); + if (Debug) printf("ext2 block size %d\n", ext2_blocksize); directlim = EXT2_NDIR_BLOCKS - 1; - ptrs_per_blk = ext2fs.blocksize/sizeof(unsigned int); + ptrs_per_blk = ext2_blocksize/sizeof(unsigned int); ind1lim = ptrs_per_blk + directlim; ind2lim = (ptrs_per_blk * ptrs_per_blk) + directlim; @@ -317,7 +317,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)ext2fs.blocksize) + + ((long) gds[group].bg_inode_table * (long)ext2_blocksize) + (((ino - 1) % EXT2_INODES_PER_GROUP(&sb)) * EXT2_INODE_SIZE(&sb)); #ifdef DEBUG @@ -325,7 +325,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, ext2fs.blocksize, + gds[group].bg_inode_table, ext2_blocksize, ino - 1, EXT2_INODES_PER_GROUP(&sb), EXT2_INODE_SIZE(&sb), ino, (int) (itp - inode_table)); #endif @@ -403,9 +403,9 @@ static int ext2_blkno(struct ext2_inode *ip, int blkoff) /* Read the indirect block */ if (cached_iblkno != iblkno) { - offset = partition_offset + (long)iblkno * (long)ext2fs.blocksize; - if (cons_read(dev, iblkbuf, ext2fs.blocksize, offset) - != ext2fs.blocksize) + offset = partition_offset + (long)iblkno * (long)ext2_blocksize; + if (cons_read(dev, iblkbuf, ext2_blocksize, offset) + != ext2_blocksize) { printf("ext2_blkno: error on iblk read\n"); return 0; @@ -430,9 +430,9 @@ static int ext2_blkno(struct ext2_inode *ip, int blkoff) /* Read in the double-indirect block */ if (cached_diblkno != diblkno) { - offset = partition_offset + (long) diblkno * (long) ext2fs.blocksize; - if (cons_read(dev, diblkbuf, ext2fs.blocksize, offset) - != ext2fs.blocksize) + offset = partition_offset + (long) diblkno * (long) ext2_blocksize; + if (cons_read(dev, diblkbuf, ext2_blocksize, offset) + != ext2_blocksize) { printf("ext2_blkno: err reading dindr blk\n"); return 0; @@ -451,9 +451,9 @@ static int ext2_blkno(struct ext2_inode *ip, int blkoff) /* Read the indirect block */ if (cached_iblkno != iblkno) { - offset = partition_offset + (long) iblkno * (long) ext2fs.blocksize; - if (cons_read(dev, iblkbuf, ext2fs.blocksize, offset) - != ext2fs.blocksize) + offset = partition_offset + (long) iblkno * (long) ext2_blocksize; + if (cons_read(dev, iblkbuf, ext2_blocksize, offset) + != ext2_blocksize) { printf("ext2_blkno: err on iblk read\n"); return 0; @@ -493,8 +493,8 @@ static int ext2_breadi(struct ext2_inode *ip, long blkno, long nblks, ip, blkno, nblks, buffer); tot_bytes = 0; - if ((blkno+nblks)*ext2fs.blocksize > ip->i_size) - nblks = (ip->i_size + ext2fs.blocksize) / ext2fs.blocksize - blkno; + if ((blkno+nblks)*ext2_blocksize > ip->i_size) + nblks = (ip->i_size + ext2_blocksize) / ext2_blocksize - blkno; if (Debug) printf("nblks = %ld\n", nblks); while (nblks) { @@ -507,7 +507,7 @@ static int ext2_breadi(struct ext2_inode *ip, long blkno, long nblks, if (Debug) printf("dev_blkno = %ld\n", dev_blkno); do { ++blkno; ++ncontig; --nblks; - nbytes += ext2fs.blocksize; + nbytes += ext2_blocksize; } while (nblks && print_ext2_blkno(ip, blkno) == dev_blkno + ncontig); @@ -518,7 +518,7 @@ static int ext2_breadi(struct ext2_inode *ip, long blkno, long nblks, memset(buffer, 0, nbytes); } else { /* Read it for real */ - offset = partition_offset + (long) dev_blkno* (long) ext2fs.blocksize; + offset = partition_offset + (long) dev_blkno* (long) ext2_blocksize; #ifdef DEBUG printf("ext2_bread: reading %ld bytes at offset %ld\n", nbytes, offset); @@ -557,8 +557,8 @@ static struct ext2_dir_entry_2 *ext2_readdiri(struct ext2_inode *dir_inode, printf("ext2_readdiri: blkoffset %d diroffset %d len %d\n", blockoffset, diroffset, dir_inode->i_size); #endif - if (blockoffset >= ext2fs.blocksize) { - diroffset += ext2fs.blocksize; + if (blockoffset >= ext2_blocksize) { + diroffset += ext2_blocksize; if (diroffset >= dir_inode->i_size) return NULL; #ifdef DEBUG @@ -567,7 +567,7 @@ static struct ext2_dir_entry_2 *ext2_readdiri(struct ext2_inode *dir_inode, #endif /* assume that this will read the whole block */ if (ext2_breadi(dir_inode, - diroffset / ext2fs.blocksize, + diroffset / ext2_blocksize, 1, blkbuf) < 0) return NULL; blockoffset = 0; @@ -668,16 +668,6 @@ static struct ext2_inode *ext2_namei(const char *name) } -/* - * Read block number "blkno" from the specified file. - */ -static int ext2_bread(int fd, long blkno, long nblks, char *buffer) -{ - struct ext2_inode * ip; - ip = &inode_table[fd].inode; - return ext2_breadi(ip, blkno, nblks, buffer); -} - /* * Note: don't mix any kind of file lookup or other I/O with this or * you will lose horribly (as it reuses blkbuf) @@ -785,8 +775,8 @@ static int ext2_read(int fd, char *buf, unsigned count, unsigned devaddr) fd, buf, count, devaddr); return ext2_breadi(ip, - devaddr / ext2fs.blocksize, - count / ext2fs.blocksize, + devaddr / ext2_blocksize, + count / ext2_blocksize, buf); } @@ -795,7 +785,7 @@ static void ext2_describe(int fd, int *bufalign, { describe(dev, bufalign, blocksize); if (blocksize != 0) - *blocksize = ext2fs.blocksize; + *blocksize = ext2_blocksize; } int ext2_open(const char *filename) @@ -830,15 +820,3 @@ void ext2_close(int fd) if (&inode_table[fd].inode != root_inode) ext2_iput(&inode_table[fd].inode); } - - -struct bootfs ext2fs = { - .fs_type = 0, - .blocksize = 0, - .mount = ext2_mount, - .open = ext2_open, - .bread = ext2_bread, - .close = ext2_close, - .readdir = ext2_readdir, - /* .fstat = ext2_fstat */ -}; From patchwork Fri Jul 5 20:16:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 1128230 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=HansenPartnership.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="OQ06i1uW"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="OQ06i1uW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45gR1q2m6Sz9sNj for ; Sat, 6 Jul 2019 06:16:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbfGEUQO (ORCPT ); Fri, 5 Jul 2019 16:16:14 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:59856 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfGEUQO (ORCPT ); Fri, 5 Jul 2019 16:16:14 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id C04938EE1F7; Fri, 5 Jul 2019 13:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357773; bh=hNezlm+tKjjepRRbkeWDFhPSjiQu4G01He97mHiT0ro=; h=Subject:From:To:Date:In-Reply-To:References:From; b=OQ06i1uWPuEJ5oLc9OUFAqyL/vWeAvkbOXkgB4UsEeLMLhvjia3HBUYwV3wKCQWzS evdBib1go28KInyz5hrneiPnoLjDhhPcZY79dJJlUT2Uk1Af5WL79ai4WsjMo5jFOL qaN4j0/JTGnn2ZwvnPgk1W+UeG380S6hmSb34itY= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lpEWYRgZOQ7U; Fri, 5 Jul 2019 13:16:13 -0700 (PDT) Received: from jarvis.lan (unknown [50.35.68.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 5B9458EE0CF; Fri, 5 Jul 2019 13:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357773; bh=hNezlm+tKjjepRRbkeWDFhPSjiQu4G01He97mHiT0ro=; h=Subject:From:To:Date:In-Reply-To:References:From; b=OQ06i1uWPuEJ5oLc9OUFAqyL/vWeAvkbOXkgB4UsEeLMLhvjia3HBUYwV3wKCQWzS evdBib1go28KInyz5hrneiPnoLjDhhPcZY79dJJlUT2Uk1Af5WL79ai4WsjMo5jFOL qaN4j0/JTGnn2ZwvnPgk1W+UeG380S6hmSb34itY= Message-ID: <1562357772.10899.7.camel@HansenPartnership.com> Subject: [PATCH 2/4] iplboot: update the ext2_fs.h header From: James Bottomley To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Parisc List Date: Fri, 05 Jul 2019 13:16:12 -0700 In-Reply-To: <1562357231.10899.5.camel@HansenPartnership.com> References: <1562357231.10899.5.camel@HansenPartnership.com> X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org A 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. Signed-off-by: James Bottomley --- ipl/ext2_fs.h | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/ipl/ext2_fs.h b/ipl/ext2_fs.h index 2d1db8f..f104880 100644 --- a/ipl/ext2_fs.h +++ b/ipl/ext2_fs.h @@ -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 */ From patchwork Fri Jul 5 20:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 1128231 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=HansenPartnership.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="LyrtSm3d"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="LyrtSm3d"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45gR2T08m1z9sNj for ; Sat, 6 Jul 2019 06:16:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbfGEUQs (ORCPT ); Fri, 5 Jul 2019 16:16:48 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:59890 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfGEUQs (ORCPT ); Fri, 5 Jul 2019 16:16:48 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id B89CA8EE1F7; Fri, 5 Jul 2019 13:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357807; bh=/fS6oDKd86mR68HLZIDsjxT25I9JNDvE3EMLthbo3Gw=; h=Subject:From:To:Date:In-Reply-To:References:From; b=LyrtSm3dlpYR3Dnij+N2oCfQNrTgwA5tI8si8INMhkMnEwYyD07PrXf3VhHEFQnvp U9wdArnWMZ6nMCmAsFwZnlYt8QraBFEqgh1zizUNxDUpkAUzO5Y38R/Wax6SEimuHQ YEY2EWbeRsRvFz25jzcOMJdwu5zypCu1RrB/0RoQ= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WTXfkHKjcD9J; Fri, 5 Jul 2019 13:16:47 -0700 (PDT) Received: from jarvis.lan (unknown [50.35.68.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 5A47B8EE0CF; Fri, 5 Jul 2019 13:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357807; bh=/fS6oDKd86mR68HLZIDsjxT25I9JNDvE3EMLthbo3Gw=; h=Subject:From:To:Date:In-Reply-To:References:From; b=LyrtSm3dlpYR3Dnij+N2oCfQNrTgwA5tI8si8INMhkMnEwYyD07PrXf3VhHEFQnvp U9wdArnWMZ6nMCmAsFwZnlYt8QraBFEqgh1zizUNxDUpkAUzO5Y38R/Wax6SEimuHQ YEY2EWbeRsRvFz25jzcOMJdwu5zypCu1RrB/0RoQ= Message-ID: <1562357806.10899.8.camel@HansenPartnership.com> Subject: [PATCH 3/4] iplboot: add ext4 support From: James Bottomley To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Parisc List Date: Fri, 05 Jul 2019 13:16:46 -0700 In-Reply-To: <1562357231.10899.5.camel@HansenPartnership.com> References: <1562357231.10899.5.camel@HansenPartnership.com> X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org For 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. Signed-off-by: James Bottomley --- ipl/ext2.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 7 deletions(-) diff --git a/ipl/ext2.c b/ipl/ext2.c index 9d198fe..31b8469 100644 --- a/ipl/ext2.c +++ b/ipl/ext2.c @@ -25,6 +25,7 @@ #include "bootloader.h" #define MAX_OPEN_FILES 5 +#define EXTENT_MAX_DEPTH 5 static 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; From patchwork Fri Jul 5 20:17:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 1128232 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=HansenPartnership.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="FOFnX6fs"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="FOFnX6fs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45gR366P0nz9sNj for ; Sat, 6 Jul 2019 06:17:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbfGEURV (ORCPT ); Fri, 5 Jul 2019 16:17:21 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:59920 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfGEURV (ORCPT ); Fri, 5 Jul 2019 16:17:21 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 7EED28EE1F7; Fri, 5 Jul 2019 13:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357841; bh=Rr0/c3YY6b7M6XGt7eOf4jjmV2d3TMURmcZoEpYrahY=; h=Subject:From:To:Date:In-Reply-To:References:From; b=FOFnX6fsexFCfW5mVUquzMC+bE32BwR1CPHjvlO4jFuhi/W5UwqdXK99onoRuLSlD vPV4PeI6GTA25+sQ+tDl9kUxG7ZGE8Bx6Owp9UlW/go1GD22tDCYa0f/VEnIOtJPql 9AAD+80Vj6CtXPqU0XebDXt9F4MGG3Vuj7/a/8Nk= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3-_X30Ba98IQ; Fri, 5 Jul 2019 13:17:21 -0700 (PDT) Received: from jarvis.lan (unknown [50.35.68.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 27D648EE0CF; Fri, 5 Jul 2019 13:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1562357841; bh=Rr0/c3YY6b7M6XGt7eOf4jjmV2d3TMURmcZoEpYrahY=; h=Subject:From:To:Date:In-Reply-To:References:From; b=FOFnX6fsexFCfW5mVUquzMC+bE32BwR1CPHjvlO4jFuhi/W5UwqdXK99onoRuLSlD vPV4PeI6GTA25+sQ+tDl9kUxG7ZGE8Bx6Owp9UlW/go1GD22tDCYa0f/VEnIOtJPql 9AAD+80Vj6CtXPqU0XebDXt9F4MGG3Vuj7/a/8Nk= Message-ID: <1562357840.10899.9.camel@HansenPartnership.com> Subject: [PATCH 4/4] palo: add support for formatting as ext4 From: James Bottomley To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Parisc List Date: Fri, 05 Jul 2019 13:17:20 -0700 In-Reply-To: <1562357231.10899.5.camel@HansenPartnership.com> References: <1562357231.10899.5.camel@HansenPartnership.com> X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Now that iplboot can read ext4 filesystem, allow palo to create them with the palo --format-as=4 option. Signed-off-by: James Bottomley --- palo/palo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/palo/palo.c b/palo/palo.c index e088993..26da01b 100644 --- a/palo/palo.c +++ b/palo/palo.c @@ -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;