summaryrefslogtreecommitdiffstats
path: root/mount/lomount.c
diff options
context:
space:
mode:
authorKarel Zak2009-05-29 21:46:00 +0200
committerKarel Zak2009-05-29 21:46:00 +0200
commitd34ac93a61984a9144f832582aab99e0a70f4e3b (patch)
treedad9c7f1554c7e2948d3703be02a58befde6c890 /mount/lomount.c
parentmount: use TAG parsing function from libblkid (diff)
downloadkernel-qcow2-util-linux-d34ac93a61984a9144f832582aab99e0a70f4e3b.tar.gz
kernel-qcow2-util-linux-d34ac93a61984a9144f832582aab99e0a70f4e3b.tar.xz
kernel-qcow2-util-linux-d34ac93a61984a9144f832582aab99e0a70f4e3b.zip
losetup: add --set-capacity
The LOOP_SET_CAPACITY allows to resize loop device size. Example: # blockdev --getsize64 /dev/loop0 10485760 # dd if=/dev/zero of=/home/images/aaa.img count=10 bs=1M oflag=append conv=notrunc # blockdev --getsize64 /dev/loop0 10485760 # ./losetup --set-capacity /dev/loop0 # blockdev --getsize64 /dev/loop0 20971520 CC: J. R. Okajima <hooanon05@yahoo.co.jp> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/lomount.c')
-rw-r--r--mount/lomount.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/mount/lomount.c b/mount/lomount.c
index c173409ec..1b191ab71 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -349,6 +349,28 @@ done:
#ifdef MAIN
static int
+set_capacity(const char *device)
+{
+ int errsv;
+ int fd = open(device, O_RDONLY);
+
+ if (fd == -1)
+ goto err;
+
+ if (ioctl(fd, LOOP_SET_CAPACITY) != 0)
+ goto err;
+
+ return 0;
+err:
+ errsv = errno;
+ fprintf(stderr, _("loop: can't set capacity on device %s: %s\n"),
+ device, strerror (errsv));
+ if (fd != -1)
+ close(fd);
+ return 2;
+}
+
+static int
show_loop_fd(int fd, char *device) {
struct loop_info loopinfo;
struct loop_info64 loopinfo64;
@@ -877,6 +899,7 @@ usage(void) {
" %1$s -a | --all list all used\n"
" %1$s -d | --detach <loopdev> [<loopdev> ...] delete\n"
" %1$s -f | --find find unused\n"
+ " %1$s -c | --set-capacity <loopdev> resize\n"
" %1$s -j | --associated <file> [-o <num>] list all associated with <file>\n"
" %1$s [ options ] {-f|--find|loopdev} <file> setup\n"),
progname);
@@ -896,7 +919,7 @@ usage(void) {
int
main(int argc, char **argv) {
char *p, *offset, *sizelimit, *encryption, *passfd, *device, *file, *assoc;
- int delete, find, c, all;
+ int delete, find, c, all, capacity;
int res = 0;
int showdev = 0;
int ro = 0;
@@ -904,6 +927,7 @@ main(int argc, char **argv) {
unsigned long long off, slimit;
struct option longopts[] = {
{ "all", 0, 0, 'a' },
+ { "set-capacity", 0, 0, 'c' },
{ "detach", 0, 0, 'd' },
{ "encryption", 1, 0, 'e' },
{ "find", 0, 0, 'f' },
@@ -922,7 +946,7 @@ main(int argc, char **argv) {
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- delete = find = all = 0;
+ capacity = delete = find = all = 0;
off = 0;
slimit = 0;
assoc = offset = sizelimit = encryption = passfd = NULL;
@@ -931,12 +955,15 @@ main(int argc, char **argv) {
if ((p = strrchr(progname, '/')) != NULL)
progname = p+1;
- while ((c = getopt_long(argc, argv, "ade:E:fhj:o:p:rsv",
+ while ((c = getopt_long(argc, argv, "acde:E:fhj:o:p:rsv",
longopts, NULL)) != -1) {
switch (c) {
case 'a':
all = 1;
break;
+ case 'c':
+ capacity = 1;
+ break;
case 'r':
ro = 1;
break;
@@ -979,16 +1006,20 @@ main(int argc, char **argv) {
usage();
} else if (delete) {
if (argc < optind+1 || encryption || offset || sizelimit ||
- find || all || showdev || assoc || ro)
+ capacity || find || all || showdev || assoc || ro)
usage();
} else if (find) {
- if (all || assoc || argc < optind || argc > optind+1)
+ if (capacity || all || assoc || argc < optind || argc > optind+1)
usage();
} else if (all) {
if (argc > 2)
usage();
} else if (assoc) {
- if (encryption || showdev || passfd || ro)
+ if (capacity || encryption || showdev || passfd || ro)
+ usage();
+ } else if (capacity) {
+ if (argc != optind + 1 || encryption || offset || sizelimit ||
+ showdev || ro)
usage();
} else {
if (argc < optind+1 || argc > optind+2)
@@ -1027,6 +1058,8 @@ main(int argc, char **argv) {
if (delete) {
while (optind < argc)
res += del_loop(argv[optind++]);
+ } else if (capacity) {
+ res = set_capacity(device);
} else if (file == NULL)
res = show_loop(device);
else {