diff -up parted-1.9.0/libparted/arch/linux.c~ parted-1.9.0/libparted/arch/linux.c --- parted-1.9.0/libparted/arch/linux.c~ 2009-08-27 11:23:59.000000000 +0200 +++ parted-1.9.0/libparted/arch/linux.c 2009-08-27 14:28:47.000000000 +0200 @@ -586,6 +586,19 @@ _get_linux_version () return kver = KERNEL_VERSION (major, minor, teeny); } +static int +_have_kern26 () +{ + static int have_kern26 = -1; + int kver; + + if (have_kern26 != -1) + return have_kern26; + + kver = _get_linux_version(); + return have_kern26 = kver >= KERNEL_VERSION (2,6,0) ? 1 : 0; +} + static void _device_set_sector_size (PedDevice* dev) { @@ -1354,8 +1367,8 @@ linux_is_busy (PedDevice* dev) return 0; } -/* we need to flush the master device, and all the partition devices, - * because there is no coherency between the caches. +/* we need to flush the master device, and with kernel < 2.6 all the partition + * devices, because there is no coherency between the caches with old kernels. * We should only flush unmounted partition devices, because: * - there is never a need to flush them (we're not doing IO there) * - flushing a device that is mounted causes unnecessary IO, and can @@ -1373,21 +1386,23 @@ _flush_cache (PedDevice* dev) ioctl (arch_specific->fd, BLKFLSBUF); - for (i = 1; i < 16; i++) { - char* name; - int fd; + if (!_have_kern26()) { + for (i = 1; i < 16; i++) { + char* name; + int fd; - name = _device_get_part_path (dev, i); - if (!name) - break; - if (!_partition_is_mounted_by_path (name)) { - fd = open (name, WR_MODE, 0); - if (fd > 0) { - ioctl (fd, BLKFLSBUF); - close (fd); + name = _device_get_part_path (dev, i); + if (!name) + break; + if (!_partition_is_mounted_by_path (name)) { + fd = open (name, WR_MODE, 0); + if (fd > 0) { + ioctl (fd, BLKFLSBUF); + close (fd); + } } + free (name); } - free (name); } } @@ -1428,7 +1443,9 @@ retry: dev->read_only = 0; } - _flush_cache (dev); + /* With kernels < 2.6 flush cache for cache coherence issues */ + if (!_have_kern26()) + _flush_cache (dev); return 1; }