[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] losetup -f
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2007-09-23 19:25:05
Message-ID: 200709232025.06029.vda.linux () googlemail ! com
[Download RAW message or body]
On Friday 21 September 2007 08:59, Loïc Grenié wrote:
> This is a trivial patch to add a -f option to losetup. losetup -f shows the
> first free loop device. After the patch executable size is not changed in
> two of three arch that I've tested:
>
> AMD64: unchanged
> i386: unchanged
> i386: +4060bytes (different version of gcc)
>
> The code is incorrect if 1) there are less than 10 loop devices and 2) they
> are all busy (but I don't know loop devices enough to correct...).
>
> I use a custom version of ubuntu initrd using busybox 1.6.1 for nearly all
> executables (resulting in a 700kb smaller initrd.gz). losetup -f is
> used during the boot, so that it'd be better if it got included in busybox.
Sorry for late reply.
Your patch doesn't apply to current svn. Please rediff.
I am attaching current svn's losetup.c to make it easier.
Please use diff -u.
--
vda
["losetup.c" (text/x-csrc)]
/* vi: set sw=4 ts=4: */
/*
* Mini losetup implementation for busybox
*
* Copyright (C) 2002 Matt Kraai.
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <getopt.h>
#include "libbb.h"
int losetup_main(int argc, char **argv);
int losetup_main(int argc, char **argv)
{
unsigned opt;
char *opt_o;
unsigned long long offset = 0;
opt = getopt32(argv, "do:", &opt_o);
argc -= optind;
argv += optind;
if (opt == 0x3) // -d + -o (illegal)
bb_show_usage();
if (opt == 0x1) { // -d
/* detach takes exactly one argument */
if (argc != 1)
bb_show_usage();
if (!del_loop(argv[0]))
return EXIT_SUCCESS;
bb_perror_nomsg_and_die();
}
if (opt == 0x2) // -o
offset = xatoull(opt_o);
/* -o or no option */
if (argc == 2) {
if (set_loop(&argv[0], argv[1], offset) < 0)
bb_perror_nomsg_and_die();
} else if (argc == 1) {
char *s = query_loop(argv[0]);
if (!s)
bb_perror_nomsg_and_die();
printf("%s: %s\n", argv[0], s);
if (ENABLE_FEATURE_CLEAN_UP)
free(s);
} else {
char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0";
char c;
for (c = '0'; c <= '9'; ++c) {
char *s;
dev[sizeof(LOOP_NAME"0")-2] = c;
s = query_loop(dev);
if (s) {
printf("%s: %s\n", dev, s);
if (ENABLE_FEATURE_CLEAN_UP)
free(s);
}
}
}
return EXIT_SUCCESS;
}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic