partprobe.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 (3.5 kb)"
  9. //config: default y
  10. //config: help
  11. //config: Ask kernel to rescan partition table.
  12. //applet:IF_PARTPROBE(APPLET_NOEXEC(partprobe, partprobe, BB_DIR_USR_SBIN, BB_SUID_DROP, partprobe))
  13. //kbuild:lib-$(CONFIG_PARTPROBE) += partprobe.o
  14. #include <linux/fs.h>
  15. #include "libbb.h"
  16. #ifndef BLKRRPART
  17. # define BLKRRPART _IO(0x12,95)
  18. #endif
  19. //usage:#define partprobe_trivial_usage
  20. //usage: "DEVICE..."
  21. //usage:#define partprobe_full_usage "\n\n"
  22. //usage: "Ask kernel to rescan partition table"
  23. //
  24. // partprobe (GNU parted) 3.2:
  25. // -d, --dry-run Don't update the kernel
  26. // -s, --summary Show a summary of devices and their partitions
  27. int partprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  28. int partprobe_main(int argc UNUSED_PARAM, char **argv)
  29. {
  30. getopt32(argv, "");
  31. argv += optind;
  32. /* "partprobe" with no arguments just does nothing */
  33. while (*argv) {
  34. int fd = xopen(*argv, O_RDONLY);
  35. /*
  36. * Newer versions of parted scan partition tables themselves and
  37. * use BLKPG ioctl (BLKPG_DEL_PARTITION / BLKPG_ADD_PARTITION)
  38. * since this way kernel does not need to know
  39. * partition table formats.
  40. * We use good old BLKRRPART:
  41. */
  42. ioctl_or_perror_and_die(fd, BLKRRPART, NULL, "%s", *argv);
  43. close(fd);
  44. argv++;
  45. }
  46. return EXIT_SUCCESS;
  47. }