On Thu, Oct 18, 2018 at 12:31:46PM +0200, Jan Kara wrote: > Add test for setting partscan flag. > > Signed-off-by: Jan Kara <jack@xxxxxxx> Sorry I didn't notice this earlier, but loop/001 already does a partition rescan (via losetup -P). Does that cover this test case? > --- > src/Makefile | 3 ++- > src/loop_set_status_partscan.c | 45 ++++++++++++++++++++++++++++++++++++++++++ > tests/loop/006 | 33 +++++++++++++++++++++++++++++++ > tests/loop/006.out | 2 ++ > 4 files changed, 82 insertions(+), 1 deletion(-) > create mode 100644 src/loop_set_status_partscan.c > create mode 100755 tests/loop/006 > create mode 100644 tests/loop/006.out > > diff --git a/src/Makefile b/src/Makefile > index f89f61701179..6dadcbec8beb 100644 > --- a/src/Makefile > +++ b/src/Makefile > @@ -4,7 +4,8 @@ C_TARGETS := \ > openclose \ > sg/dxfer-from-dev \ > sg/syzkaller1 \ > - nbdsetsize > + nbdsetsize \ > + loop_set_status_partscan > > CXX_TARGETS := \ > discontiguous-io > diff --git a/src/loop_set_status_partscan.c b/src/loop_set_status_partscan.c > new file mode 100644 > index 000000000000..8873a12e4334 > --- /dev/null > +++ b/src/loop_set_status_partscan.c > @@ -0,0 +1,45 @@ > +#include <errno.h> > +#include <fcntl.h> > +#include <stdio.h> > +#include <stdlib.h> > +#include <string.h> > +#include <unistd.h> > +#include <sys/ioctl.h> > +#include <sys/stat.h> > +#include <sys/types.h> > +#include <linux/loop.h> > + > +void usage(const char *progname) > +{ > + fprintf(stderr, "usage: %s PATH\n", progname); > + exit(EXIT_FAILURE); > +} > + > +int main(int argc, char **argv) > +{ > + int ret; > + int fd; > + struct loop_info64 info; > + > + if (argc != 2) > + usage(argv[0]); > + > + fd = open(argv[1], O_RDONLY); > + if (fd == -1) { > + perror("open"); > + return EXIT_FAILURE; > + } > + > + memset(&info, 0, sizeof(info)); > + info.lo_flags = LO_FLAGS_PARTSCAN; > + memcpy(info.lo_file_name, "part", 5); What's the significance of this file name? > + ret = ioctl(fd, LOOP_SET_STATUS64, &info); > + if (ret == -1) { > + perror("ioctl"); > + close(fd); > + return EXIT_FAILURE; > + } > + close(fd); > + return EXIT_SUCCESS; > +} [snip]