2 partprobe - informs the OS kernel of partition layout
3 Copyright (C) 2001-2002, 2007-2012 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /* it's best to compile this with:
21 * CFLAGS=-Os ./configure --disable-nls --disable-shared --disable-debug
22 * --enable-discover-only
24 * And strip(1) afterwards!
29 #include <parted/parted.h>
36 #include "configmake.h"
38 #include "version-etc.h"
44 # define textdomain(Domainname) /* empty */
45 # undef bindtextdomain
46 # define bindtextdomain(Domainname, Dirname) /* empty */
50 #define _(msgid) gettext (msgid)
53 "<http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>"
55 /* The official name of this program (e.g., no `g' prefix). */
56 #define PROGRAM_NAME "partprobe"
58 static struct option const long_options[] =
60 /* Note: the --no-update option is deprecated, and deliberately
61 * not documented. FIXME: remove --no-update in 2009. */
62 {"no-update", no_argument, NULL, 'd'},
63 {"dry-run", no_argument, NULL, 'd'},
64 {"summary", no_argument, NULL, 's'},
65 {"help", no_argument, NULL, 'h'},
66 {"version", no_argument, NULL, 'v'},
70 /* initialized to 0 according to the language lawyers */
71 static int opt_no_inform;
72 static int opt_summary;
75 summary (PedDisk* disk)
79 printf ("%s: %s partitions", disk->dev->path, disk->type->name);
80 for (walk = disk->part_list; walk; walk = walk->next) {
81 if (!ped_partition_is_active (walk))
84 printf (" %d", walk->num);
85 if (walk->type & PED_PARTITION_EXTENDED) {
86 PedPartition* log_walk;
90 for (log_walk = walk->part_list; log_walk;
91 log_walk = log_walk->next) {
92 if (!ped_partition_is_active (log_walk))
96 printf ("%d", log_walk->num);
106 process_dev (PedDevice* dev)
108 PedDiskType* disk_type;
111 disk_type = ped_disk_probe (dev);
112 if (!disk_type || !strcmp (disk_type->name, "loop"))
115 disk = ped_disk_new (dev);
118 if (!opt_no_inform) {
119 if (!ped_disk_commit_to_os (disk))
120 goto error_destroy_disk;
124 ped_disk_destroy (disk);
128 ped_disk_destroy (disk);
136 if (status != EXIT_SUCCESS)
137 fprintf (stderr, _("Try `%s --help' for more information.\n"),
141 printf (_("Usage: %s [OPTION] [DEVICE]...\n"), PROGRAM_NAME);
143 Inform the operating system about partition table changes.\n\
145 -d, --dry-run do not actually inform the operating system\n\
146 -s, --summary print a summary of contents\n\
147 -h, --help display this help and exit\n\
148 -v, --version output version information and exit\n\
152 When no DEVICE is given, probe all partitions.\n\
154 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
160 main (int argc, char* argv[])
164 set_program_name (argv[0]);
166 setlocale (LC_ALL, "");
167 bindtextdomain (PACKAGE, LOCALEDIR);
168 textdomain (PACKAGE);
170 atexit (close_stdout);
173 while ((c = getopt_long (argc, argv, "dhsv", long_options, NULL)) != -1)
184 usage (EXIT_SUCCESS);
188 version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME,
189 VERSION, AUTHORS, (char *) NULL);
194 usage (EXIT_FAILURE);
197 int n_dev = argc - optind;
200 for (i = optind; i < argc; i++) {
201 PedDevice *dev = ped_device_get (argv[i]);
202 if (dev == NULL || process_dev (dev) == 0)
206 ped_device_probe_all ();
208 for (dev = ped_device_get_next (NULL); dev;
209 dev = ped_device_get_next (dev))
210 if (process_dev (dev) == 0)