14 #include "closestream.h"
16 static void __attribute__ ((__noreturn__
)) usage(FILE * out
)
18 fputs(USAGE_HEADER
, out
);
19 fprintf(out
, _(" %s <disk device> <partition number> <length>\n"),
20 program_invocation_short_name
);
22 fputs(USAGE_SEPARATOR
, out
);
23 fputs(_("Tell the kernel about the new size of a partition.\n"), out
);
25 fputs(USAGE_OPTIONS
, out
);
26 fputs(USAGE_HELP
, out
);
27 fputs(USAGE_VERSION
, out
);
28 fprintf(out
, USAGE_MAN_TAIL("resizepart(8)"));
29 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
32 static int get_partition_start(int fd
, int partno
, uint64_t *start
)
35 struct sysfs_cxt disk
= UL_SYSFSCXT_EMPTY
,
36 part
= UL_SYSFSCXT_EMPTY
;
43 if (fstat(fd
, &st
) || !S_ISBLK(st
.st_mode
))
46 if (sysfs_init(&disk
, devno
, NULL
))
51 devno
= sysfs_partno_to_devno(&disk
, partno
);
54 if (sysfs_init(&part
, devno
, &disk
))
56 if (sysfs_read_u64(&part
, "start", start
))
66 int main(int argc
, char **argv
)
69 const char *wholedisk
;
72 static const struct option longopts
[] = {
73 {"help", no_argument
, NULL
, 'h'},
74 {"version", no_argument
, NULL
, 'V'},
78 setlocale(LC_ALL
, "");
79 bindtextdomain(PACKAGE
, LOCALEDIR
);
83 while ((c
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
86 printf(UTIL_LINUX_VERSION
);
91 errtryhelp(EXIT_FAILURE
);
98 partno
= strtou32_or_err(argv
[2], _("invalid partition number argument"));
100 if ((fd
= open(wholedisk
, O_RDONLY
)) < 0)
101 err(EXIT_FAILURE
, _("cannot open %s"), wholedisk
);
103 if (get_partition_start(fd
, partno
, &start
))
104 err(EXIT_FAILURE
, _("%s: failed to get start of the partition number %s"),
107 if (partx_resize_partition(fd
, partno
, start
,
108 strtou64_or_err(argv
[3], _("invalid length argument"))))
109 err(EXIT_FAILURE
, _("failed to resize partition"));
111 if (close_fd(fd
) != 0)
112 err(EXIT_FAILURE
, _("write failed"));