partprobe.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
  4. *
  5. * Licensed under GPLv2, see file LICENSE in this source tree.
  6. */
  7. //config:config PARTPROBE
  8. //config: bool "partprobe"
  9. //config: default y
  10. //config: select PLATFORM_LINUX
  11. //config: help
  12. //config: Ask kernel to rescan partition table.
  13. //applet:IF_PARTPROBE(APPLET(partprobe, BB_DIR_USR_SBIN, BB_SUID_DROP))
  14. //kbuild:lib-$(CONFIG_PARTPROBE) += partprobe.o
  15. #include <linux/fs.h>
  16. #include "libbb.h"
  17. #ifndef BLKRRPART
  18. # define BLKRRPART _IO(0x12,95)
  19. #endif
  20. //usage:#define partprobe_trivial_usage
  21. //usage: "DEVICE..."
  22. //usage:#define partprobe_full_usage "\n\n"
  23. //usage: "Ask kernel to rescan partition table"
  24. //
  25. // partprobe (GNU parted) 3.2:
  26. // -d, --dry-run Don't update the kernel
  27. // -s, --summary Show a summary of devices and their partitions
  28. int partprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  29. int partprobe_main(int argc UNUSED_PARAM, char **argv)
  30. {
  31. getopt32(argv, "");
  32. argv += optind;
  33. /* "partprobe" with no arguments just does nothing */
  34. while (*argv) {
  35. int fd = xopen(*argv, O_RDONLY);
  36. /*
  37. * Newer versions of parted scan partition tables themselves and
  38. * use BLKPG ioctl (BLKPG_DEL_PARTITION / BLKPG_ADD_PARTITION)
  39. * since this way kernel does not need to know
  40. * partition table formats.
  41. * We use good old BLKRRPART:
  42. */
  43. ioctl_or_perror_and_die(fd, BLKRRPART, NULL, "%s", *argv);
  44. close(fd);
  45. argv++;
  46. }
  47. return EXIT_SUCCESS;
  48. }