This is a preparation patch for adding get_minimal_alignment and get_optimal_alignment functions to linux's _PedDeviceArchOps. --- libparted/arch/linux.c | 75 ++++++++++++++++++------------------------------ libparted/arch/linux.h | 8 +++++ 2 files changed, 36 insertions(+), 47 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index d084b93..d261a04 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -52,10 +52,6 @@ # define _(String) (String) #endif /* ENABLE_NLS */ -#if HAVE_BLKID_BLKID_H -# include <blkid/blkid.h> -#endif - #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) #ifndef __NR__llseek @@ -598,47 +594,24 @@ _have_kern26 () return have_kern26 = kver >= KERNEL_VERSION (2,6,0) ? 1 : 0; } -/* Use libblkid to determine the kernel's idea of the - minimum_io_size for the device on which FD is open. - Upon success, store that value in *SZ and return 0. - Otherwise, don't modify *SZ, set errno and return -1. */ -static int -get_minimum_io_size (int fd, unsigned long *sz) -{ - int ret = -1; - #if USE_BLKID - blkid_probe pr = blkid_new_probe (); - if (!pr) - goto free_and_return; - - int saved_errno; - if (blkid_probe_set_device (pr, fd, 0, 0)) { - saved_errno = errno; - blkid_free_probe (pr); - goto free_and_return; - } - - blkid_topology tp = blkid_probe_get_topology (pr); - if (!tp) { - saved_errno = errno; - goto free_and_return; - } - - *sz = blkid_topology_get_minimum_io_size (tp); - ret = 0; +static void +get_blkid_topology (LinuxSpecific* arch_specific) +{ + arch_specific->topology = NULL; -free_and_return: + arch_specific->probe = blkid_new_probe (); + if (!arch_specific->probe) + return; - blkid_free_probe (pr); - if (ret) - errno = saved_errno; -#else - errno = ENOSYS; -#endif + if (blkid_probe_set_device (arch_specific->probe, + arch_specific->fd, 0, 0)) + return; - return ret; + arch_specific->topology = + blkid_probe_get_topology (arch_specific->probe); } +#endif static void _device_set_sector_size (PedDevice* dev) @@ -667,19 +640,21 @@ _device_set_sector_size (PedDevice* dev) dev->sector_size = (long long)sector_size; } - unsigned long min_io_size; - int err = get_minimum_io_size (arch_specific->fd, &min_io_size); - - if (err) { +#if USE_BLKID + get_blkid_topology(arch_specific); + if (!arch_specific->topology) { ped_exception_throw ( PED_EXCEPTION_WARNING, PED_EXCEPTION_OK, _("Could not determine minimum io size for %s: %s.\n" "Using the default size (%lld)."), dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT); - min_io_size = PED_SECTOR_SIZE_DEFAULT; + } else { + dev->phys_sector_size = + blkid_topology_get_minimum_io_size ( + arch_specific->topology); } - dev->phys_sector_size = min_io_size; +#endif /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */ if (dev->type == PED_DEVICE_DASD) { @@ -1394,7 +1369,13 @@ error: static void linux_destroy (PedDevice* dev) { - void *p = ((LinuxSpecific*)dev->arch_specific)->dmtype; + LinuxSpecific *arch_specific = LINUX_SPECIFIC (dev); + void *p = arch_specific->dmtype; + +#if USE_BLKID + if (arch_specific->probe) + blkid_free_probe (arch_specific->probe); +#endif free (p); free (dev->arch_specific); free (dev->path); diff --git a/libparted/arch/linux.h b/libparted/arch/linux.h index 9c08f40..62c1196 100644 --- a/libparted/arch/linux.h +++ b/libparted/arch/linux.h @@ -22,6 +22,10 @@ # include <parted/fdasd.h> #endif +#if HAVE_BLKID_BLKID_H +# include <blkid/blkid.h> +#endif + #define LINUX_SPECIFIC(dev) ((LinuxSpecific*) (dev)->arch_specific) typedef struct _LinuxSpecific LinuxSpecific; @@ -36,6 +40,10 @@ struct _LinuxSpecific { /* IBM internal dasd structure (i guess ;), required. */ struct fdasd_anchor *anchor; #endif +#if HAVE_BLKID_BLKID_H + blkid_probe probe; + blkid_topology topology; +#endif }; #endif /* PED_ARCH_LINUX_H_INCLUDED */ -- 1.6.5.1 _______________________________________________ bug-parted mailing list bug-parted@gnu.org http://lists.gnu.org/mailman/listinfo/bug-parted