From 59d749c33136b85fc4a51a0af6c48cc97e3d1b31 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 15 Nov 2011 12:35:23 +0100 Subject: loopdev: support LO_FLAGS_PARTSCAN flag (kernel 3.2) Signed-off-by: Karel Zak --- partx/partx.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'partx/partx.c') diff --git a/partx/partx.c b/partx/partx.c index b4a3af7a2..befc0d027 100644 --- a/partx/partx.c +++ b/partx/partx.c @@ -94,23 +94,6 @@ static int partx_flags; static struct loopdev_cxt lc; static int loopdev; -/* - * Check if the kernel supports partitioned loop devices. - * In a near future (around linux 3.2, hopefully) this will come - * always out of the box, until then we need to check. - */ -static int loopmod_supports_parts(void) -{ - int rc, ret = 0; - FILE *f = fopen("/sys/module/loop/parameters/max_part", "r"); - - if (!f) - return 0; - rc = fscanf(f, "%d", &ret); - fclose(f); - return rc = 1 ? ret : 0; -} - static void assoc_loopdev(const char *fname) { int rc; @@ -392,9 +375,12 @@ static int add_parts(int fd, const char *device, if (errfirst) add_parts_warnx(device, errfirst, errlast); - /* the kernel adds *all* loopdev partitions, so we should delete - any extra, unwanted ones, when the -n option is passed */ - if (loopdev && (lower || upper)) { + /* + * The kernel with enabled partitions scanner for loop devices add *all* + * partitions, so we should delete any extra, unwanted ones, when the -n + * option is passed. + */ + if (loopdev && loopcxt_is_partscan(&lc) && (lower || upper)) { for (i = 0; i < nparts; i++) { blkid_partition par = blkid_partlist_get_partition(ls, i); int n = blkid_partition_get_partno(par); @@ -841,7 +827,7 @@ int main(int argc, char **argv) if (what == ACT_DELETE) errx(EXIT_FAILURE, _("%s: cannot delete partitions"), wholedisk); - if (!loopmod_supports_parts()) + if (!loopmod_supports_partscan()) errx(EXIT_FAILURE, _("%s: partitioned loop devices unsupported"), wholedisk); assoc_loopdev(wholedisk); -- cgit v1.2.3-55-g7522