14 #include "closestream.h"
16 static void __attribute__((__noreturn__
)) usage(void)
19 fputs(USAGE_HEADER
, out
);
20 fprintf(out
, _(" %s <disk device> <partition number> <length>\n"),
21 program_invocation_short_name
);
23 fputs(USAGE_SEPARATOR
, out
);
24 fputs(_("Tell the kernel about the new size of a partition.\n"), out
);
26 fputs(USAGE_OPTIONS
, out
);
27 printf(USAGE_HELP_OPTIONS(16));
28 printf(USAGE_MAN_TAIL("resizepart(8)"));
32 static int get_partition_start(int fd
, int partno
, uint64_t *start
)
35 struct path_cxt
*disk
= NULL
, *part
= NULL
;
42 if (fstat(fd
, &st
) || !S_ISBLK(st
.st_mode
))
45 disk
= ul_new_sysfs_path(devno
, NULL
, NULL
);
51 devno
= sysfs_blkdev_partno_to_devno(disk
, partno
);
55 part
= ul_new_sysfs_path(devno
, disk
, NULL
);
58 if (ul_path_read_u64(part
, start
, "start"))
68 int main(int argc
, char **argv
)
71 const char *wholedisk
;
74 static const struct option longopts
[] = {
75 {"help", no_argument
, NULL
, 'h'},
76 {"version", no_argument
, NULL
, 'V'},
80 setlocale(LC_ALL
, "");
81 bindtextdomain(PACKAGE
, LOCALEDIR
);
83 close_stdout_atexit();
85 while ((c
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
88 print_version(EXIT_SUCCESS
);
92 errtryhelp(EXIT_FAILURE
);
96 warnx(_("not enough arguments"));
97 errtryhelp(EXIT_FAILURE
);
101 partno
= strtou32_or_err(argv
[2], _("invalid partition number argument"));
103 if ((fd
= open(wholedisk
, O_RDONLY
)) < 0)
104 err(EXIT_FAILURE
, _("cannot open %s"), wholedisk
);
106 if (get_partition_start(fd
, partno
, &start
))
107 err(EXIT_FAILURE
, _("%s: failed to get start of the partition number %s"),
110 if (partx_resize_partition(fd
, partno
, start
,
111 strtou64_or_err(argv
[3], _("invalid length argument"))))
112 err(EXIT_FAILURE
, _("failed to resize partition"));
114 if (close_fd(fd
) != 0)
115 err(EXIT_FAILURE
, _("write failed"));