Subject: bug#16338: [PATCH 2/2] Fix filesystem detection on non 512 byte sectors

From: "Brian C. Lane" <[email-masked]>
Date: Mon, 3 Mar 2014 11:45:24 -0800

On Sat, Jan 04, 2014 at 12:26:05AM -0500, Phillip Susi wrote:
> Enable probing for filesystems with non 512 byte sectors, and fix up each
> filesystem to correctly handle that.  Remove unused field from the fs type
> structure listing acceptable sector sizes.
> ---
>  NEWS                                 |  3 ++
>  include/parted/filesys.in.h          |  1 -
>  libparted/filesys.c                  |  5 ----
>  libparted/fs/amiga/affs.c            | 22 ++------------
>  libparted/fs/amiga/apfs.c            |  6 ++--
>  libparted/fs/amiga/asfs.c            |  3 +-
>  libparted/fs/ext2/interface.c        | 18 ++++-------
>  libparted/fs/fat/bootsector.c        | 58 ++++--------------------------------
>  libparted/fs/fat/bootsector.h        |  3 +-
>  libparted/fs/fat/fat.c               | 12 ++++----
>  libparted/fs/fat/fat.h               |  4 +--
>  libparted/fs/hfs/hfs.c               |  7 -----
>  libparted/fs/hfs/probe.c             | 13 ++++----
>  libparted/fs/jfs/jfs.c               | 29 +++++++-----------
>  libparted/fs/linux_swap/linux_swap.c | 41 +++++--------------------
>  libparted/fs/nilfs2/nilfs2.c         | 36 ++++++++--------------
>  libparted/fs/ntfs/ntfs.c             | 13 ++++----
>  libparted/fs/r/fat/bootsector.c      | 32 +++++++++++---------
>  libparted/fs/r/fat/bootsector.h      |  8 ++---
>  libparted/fs/r/fat/fat.c             | 29 ++++++++++--------
>  libparted/fs/r/fat/fat.h             |  4 +--
>  libparted/fs/r/fat/resize.c          |  4 +--
>  libparted/fs/r/fat/table.c           |  4 +--
>  libparted/fs/reiserfs/reiserfs.c     | 23 ++++++--------
>  libparted/fs/ufs/ufs.c               | 27 ++++++++---------
>  libparted/fs/xfs/xfs.c               | 26 +++++++---------
>  26 files changed, 149 insertions(+), 282 deletions(-)
> 
> diff --git a/NEWS b/NEWS
> index 816fb57..bc948bd 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -12,6 +12,9 @@ GNU parted NEWS                                    -*- outline -*-
>    boot partition type.
>  
>  ** Bug Fixes
> +
> +  Fix filesystem detection on non 512 byte sector sizes
> +

Do our tests already cover all of these filesystems?

> diff --git a/libparted/fs/ext2/interface.c b/libparted/fs/ext2/interface.c
> index 97220b7..ecafb62 100644
> --- a/libparted/fs/ext2/interface.c
> +++ b/libparted/fs/ext2/interface.c
> @@ -33,10 +33,12 @@ struct ext2_dev_handle* ext2_make_dev_handle_from_parted_geometry(PedGeometry* g
>  static PedGeometry*
>  _ext2_generic_probe (PedGeometry* geom, int expect_ext_ver)
>  {
> -	void *sb_v;
> -	if (!ped_geometry_read_alloc(geom, &sb_v, 2, 2))
> +	const int sectors = (4096 + geom->dev->sector_size - 1) /
> +			     geom->dev->sector_size;
> +	char *sb_v = alloca (sectors * geom->dev->sector_size);
> +	if (!ped_geometry_read(geom, sb_v, 0, sectors))
>  		return NULL;
> -	struct ext2_super_block *sb = sb_v;
> +	struct ext2_super_block *sb = (struct ext2_super_block *)(sb_v + 1024);

It would probably be more readable to just read_alloc the first 4 blocks
and then point *sb at +1024 inside that.

Also, I just realized that you are using alloca for these -- I'm not
sure we want to switch to using something that has undefined behavior on
failure.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)