aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h3
-rw-r--r--include/usage.h84
-rw-r--r--libbb/loop.c44
-rw-r--r--util-linux/losetup.c24
4 files changed, 65 insertions, 90 deletions
diff --git a/include/libbb.h b/include/libbb.h
index d1c6be670..96dc46a09 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -232,6 +232,7 @@ extern char *bb_askpass(int timeout, const char * prompt);
232 232
233extern int device_open(const char *device, int mode); 233extern int device_open(const char *device, int mode);
234 234
235extern char *query_loop(const char *device);
235extern int del_loop(const char *device); 236extern int del_loop(const char *device);
236extern int set_loop(char **device, const char *file, int offset); 237extern int set_loop(char **device, const char *file, int offset);
237 238
@@ -466,7 +467,7 @@ typedef struct {
466} procps_status_t; 467} procps_status_t;
467 468
468extern procps_status_t * procps_scan(int save_user_arg0); 469extern procps_status_t * procps_scan(int save_user_arg0);
469extern int compare_string_array(const char * const string_array[], const char *key); 470extern unsigned short compare_string_array(const char *string_array[], const char *key);
470 471
471extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); 472extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret);
472 473
diff --git a/include/usage.h b/include/usage.h
index 912a88f4e..53832b987 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1657,13 +1657,18 @@
1657 "\t-f\t\toutput data as the log grows" 1657 "\t-f\t\toutput data as the log grows"
1658 1658
1659#define losetup_trivial_usage \ 1659#define losetup_trivial_usage \
1660 "[OPTION]... LOOPDEVICE FILE\n" \ 1660 "[-od] LOOPDEVICE [FILE]\n"
1661 "or: losetup [OPTION]... -d LOOPDEVICE"
1662#define losetup_full_usage \ 1661#define losetup_full_usage \
1663 "Associate LOOPDEVICE with FILE.\n\n" \ 1662 "Associate LOOPDEVICE with FILE, or display current association.\n\n" \
1664 "Options:\n" \ 1663 "Options:\n" \
1665 "\t-d\t\tDisassociate LOOPDEVICE\n" \ 1664 "\t-d\t\tDisassociate LOOPDEVICE\n" \
1666 "\t-o OFFSET\tStart OFFSET bytes into FILE" 1665 "\t-o OFFSET\tStart OFFSET bytes into FILE"
1666#define losetup_notes_usage \
1667 "One argument (losetup /dev/loop1) will display the current association\n" \
1668 "(if any), or disassociate it (with -d). The display shows the offset\n" \
1669 "and filename of the file the loop device is currently bound to.\n\n" \
1670 "Two arguments (losetup /dev/loop1 file.img) create a new association,\n" \
1671 "with an optional offset (-o 12345). Encryption is not yet supported.\n\n"
1667 1672
1668#ifdef CONFIG_FEATURE_LS_TIMESTAMPS 1673#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
1669# define USAGE_LS_TIMESTAMPS(a) a 1674# define USAGE_LS_TIMESTAMPS(a) a
@@ -1946,74 +1951,18 @@
1946 "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" 1951 "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n"
1947 1952
1948#define modprobe_trivial_usage \ 1953#define modprobe_trivial_usage \
1949 "[-knqrsv] MODULE [symbol=value ...]" 1954 "[-knqrsv] [MODULE ...]"
1950#define modprobe_full_usage \ 1955#define modprobe_full_usage \
1956 "Used for high level module loading and unloading.\n\n" \
1951 "Options:\n" \ 1957 "Options:\n" \
1952 "\t-k\tMake module autoclean-able\n" \ 1958 "\t-k\tMake module autoclean-able\n" \
1953 "\t-n\tJust show what would be done\n" \ 1959 "\t-n\tJust show what would be done\n" \
1954 "\t-q\tQuiet output\n" \ 1960 "\t-q\tQuiet output\n" \
1955 "\t-r\tRemove module (stacks) or do autoclean\n" \ 1961 "\t-r\tRemove module (stacks) or do autoclean\n" \
1956 "\t-s\tReport via syslog instead of stderr\n" \ 1962 "\t-s\tReport via syslog instead of stderr\n" \
1957 "\t-v\tVerbose output\n\n" 1963 "\t-v\tVerbose output"
1958#define modprobe_notes_usage \
1959"modprobe can (un)load a stack of modules, passing each module options (when\n" \
1960"loading). modprobe uses a configuration file to determine what option(s) to\n" \
1961"pass each module it loads.\n" \
1962"\n" \
1963"The configuration file is searched (in order) amongst:\n" \
1964"\n" \
1965" /etc/modprobe.conf (2.6 only)\n" \
1966" /etc/modules.conf\n" \
1967" /etc/conf.modules (deprecated)\n" \
1968"\n" \
1969"They all have the same syntax (see below). If none is present, it is\n" \
1970"_not_ an error; each loaded module is then expected to load without\n" \
1971"options. Once a file is found, the others are tested for.\n" \
1972"\n" \
1973"/etc/modules.conf entry format:\n" \
1974"\n" \
1975" alias <alias_name> <mod_name>\n" \
1976" Makes it possible to modprobe alias_name, when there is no such module.\n" \
1977" It makes sense if your mod_name is long, or you want a more reprenstative\n" \
1978" name for that module (eg. 'scsi' in place of 'aha7xxx').\n" \
1979" This makes it also possible to use a different set of options (below) for\n" \
1980" the module and the alias.\n" \
1981" A module can be aliased more than once.\n" \
1982"\n" \
1983" options <mod_name|alias_name> <symbol=value ...>\n" \
1984" When loading module mod_name (or the module aliased by alias_name), pass\n" \
1985" the \"symbol=value\" pairs as option to that module.\n" \
1986"\n" \
1987"Sample /etc/modules.conf file:\n" \
1988"\n" \
1989" options tulip irq=3\n" \
1990" alias tulip tulip2\n" \
1991" options tulip2 irq=4 io=0x308\n" \
1992"\n" \
1993"Other functionality offered by 'classic' modprobe is not available in\n" \
1994"this implementation.\n" \
1995"\n" \
1996"If module options are present both in the config file, and on the command line,\n" \
1997"then the options from the command line will be passed to the module _after_\n" \
1998"the options from the config file. That way, you can have defaults in the config\n" \
1999"file, and override them for a specific usage from the command line.\n"
2000#define modprobe_example_usage \ 1964#define modprobe_example_usage \
2001 "(with the above /etc/modules.conf):\n\n" \ 1965 "$ modprobe cdrom\n"
2002 "$ modprobe tulip\n" \
2003 " will load the module 'tulip' with default option 'irq=3'\n\n" \
2004 "$ modprobe tulip irq=5\n" \
2005 " will load the module 'tulip' with option 'irq=5', thus overriding the default\n\n" \
2006 "$ modprobe tulip2\n" \
2007 " will load the module 'tulip' with default options 'irq=4 io=0x308',\n" \
2008 " which are the default for alias 'tulip2'\n\n" \
2009 "$ modprobe tulip2 irq=8\n" \
2010 " will load the module 'tulip' with default options 'irq=4 io=0x308 irq=8',\n" \
2011 " which are the default for alias 'tulip2' overriden by the option 'irq=8'\n\n" \
2012 " from the command line\n\n" \
2013 "$ modprobe tulip2 irq=2 io=0x210\n" \
2014 " will load the module 'tulip' with default options 'irq=4 io=0x308 irq=4 io=0x210',\n" \
2015 " which are the default for alias 'tulip2' overriden by the options 'irq=2 io=0x210'\n\n" \
2016 " from the command line\n"
2017 1966
2018#define more_trivial_usage \ 1967#define more_trivial_usage \
2019 "[FILE ...]" 1968 "[FILE ...]"
@@ -2054,12 +2003,13 @@
2054 "\tdev/nodev:\tAllow use of special device files / disallow them\n" \ 2003 "\tdev/nodev:\tAllow use of special device files / disallow them\n" \
2055 "\texec/noexec:\tAllow use of executable files / disallow them\n" \ 2004 "\texec/noexec:\tAllow use of executable files / disallow them\n" \
2056 USAGE_MOUNT_LOOP( \ 2005 USAGE_MOUNT_LOOP( \
2057 "\tloop:\t\tMounts a file via loop device\n" \ 2006 "\tloop:\t\t Ignored (loop devices are autodetected)\n" \
2058 ) \ 2007 ) \
2059 "\tsuid/nosuid:\tAllow set-user-id-root programs / disallow them\n" \ 2008 "\tsuid/nosuid:\tAllow set-user-id-root programs / disallow them\n" \
2060 "\tremount:\tRe-mount a mounted filesystem, changing its flags\n" \ 2009 "\tremount:\tRe-mount a mounted filesystem, changing its flags\n" \
2061 "\tro/rw:\t\tMount for read-only / read-write\n" \ 2010 "\tro/rw:\t\tMount for read-only / read-write\n" \
2062 "\tbind:\t\tUse the linux 2.4.x \"bind\" feature\n" \ 2011 "\tbind:\t\tBind a directory to an additional location\n" \
2012 "\tmove:\t\tRelocate an existing mount point.\n" \
2063 "\nThere are EVEN MORE flags that are specific to each filesystem\n" \ 2013 "\nThere are EVEN MORE flags that are specific to each filesystem\n" \
2064 "You'll have to see the written documentation for those filesystems" 2014 "You'll have to see the written documentation for those filesystems"
2065#define mount_example_usage \ 2015#define mount_example_usage \
@@ -2068,7 +2018,8 @@
2068 "proc on /proc type proc (rw)\n" \ 2018 "proc on /proc type proc (rw)\n" \
2069 "devpts on /dev/pts type devpts (rw)\n" \ 2019 "devpts on /dev/pts type devpts (rw)\n" \
2070 "$ mount /dev/fd0 /mnt -t msdos -o ro\n" \ 2020 "$ mount /dev/fd0 /mnt -t msdos -o ro\n" \
2071 "$ mount /tmp/diskimage /opt -t ext2 -o loop\n" 2021 "$ mount /tmp/diskimage /opt -t ext2 -o loop\n" \
2022 "$ mount cd_image.iso mydir\n"
2072 2023
2073#define mountpoint_trivial_usage \ 2024#define mountpoint_trivial_usage \
2074 "[-q] <[-d] DIR | -x DEVICE>" 2025 "[-q] <[-d] DIR | -x DEVICE>"
@@ -3008,7 +2959,6 @@
3008 "Telnetd listens for incoming TELNET connections on PORT.\n" \ 2959 "Telnetd listens for incoming TELNET connections on PORT.\n" \
3009 "Options:\n" \ 2960 "Options:\n" \
3010 "\t-p PORT\tlisten for connections on PORT (default 23)\n" \ 2961 "\t-p PORT\tlisten for connections on PORT (default 23)\n" \
3011 "\t-b ADDR\tlisten for connections on ADDR (default 0.0.0.0)\n"\
3012 "\t-l LOGIN\texec LOGIN on connect (default /bin/sh)\n" \ 2962 "\t-l LOGIN\texec LOGIN on connect (default /bin/sh)\n" \
3013 "\t-f issue_file\tDisplay issue_file instead of /etc/issue" 2963 "\t-f issue_file\tDisplay issue_file instead of /etc/issue"
3014#endif 2964#endif
diff --git a/libbb/loop.c b/libbb/loop.c
index 10217931b..00e3d6236 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -51,15 +51,30 @@ typedef struct {
51} bb_loop_info; 51} bb_loop_info;
52#endif 52#endif
53 53
54extern int del_loop(const char *device) 54char *query_loop(const char *device)
55{ 55{
56 int fd,rc=0; 56 int fd;
57 bb_loop_info loopinfo;
58 char *dev=0;
59
60 if ((fd = open(device, O_RDONLY)) < 0) return 0;
61 if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
62 dev=bb_xasprintf("%ld %s", (long) loopinfo.lo_offset,
63 loopinfo.lo_file_name);
64 close(fd);
57 65
58 if ((fd = open(device, O_RDONLY)) < 0) rc=1; 66 return dev;
59 else { 67}
60 if (ioctl(fd, LOOP_CLR_FD, 0) < 0) rc=1; 68
61 close(fd); 69
62 } 70int del_loop(const char *device)
71{
72 int fd, rc;
73
74 if ((fd = open(device, O_RDONLY)) < 0) return 1;
75 rc=ioctl(fd, LOOP_CLR_FD, 0);
76 close(fd);
77
63 return rc; 78 return rc;
64} 79}
65 80
@@ -69,9 +84,9 @@ extern int del_loop(const char *device)
69 search will re-use an existing loop device already bound to that 84 search will re-use an existing loop device already bound to that
70 file/offset if it finds one. 85 file/offset if it finds one.
71 */ 86 */
72extern int set_loop(char **device, const char *file, int offset) 87int set_loop(char **device, const char *file, int offset)
73{ 88{
74 char dev[20]; 89 char dev[20], *try;
75 bb_loop_info loopinfo; 90 bb_loop_info loopinfo;
76 struct stat statbuf; 91 struct stat statbuf;
77 int i, dfd, ffd, mode, rc=1; 92 int i, dfd, ffd, mode, rc=1;
@@ -81,20 +96,21 @@ extern int set_loop(char **device, const char *file, int offset)
81 return errno; 96 return errno;
82 97
83 /* Find a loop device. */ 98 /* Find a loop device. */
99 try=*device ? : dev;
84 for(i=0;rc;i++) { 100 for(i=0;rc;i++) {
85 sprintf(dev, LOOP_FORMAT, i++); 101 sprintf(dev, LOOP_FORMAT, i++);
86 /* Ran out of block devices, return failure. */ 102 /* Ran out of block devices, return failure. */
87 if(stat(*device ? *device : dev, &statbuf) || 103 if(stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) {
88 !S_ISBLK(statbuf.st_mode)) {
89 rc=ENOENT; 104 rc=ENOENT;
90 break; 105 break;
91 } 106 }
92 /* Open the sucker and check its loopiness. */ 107 /* Open the sucker and check its loopiness. */
93 if((dfd=open(dev, mode))<0 && errno==EROFS) 108 if((dfd=open(try, mode))<0 && errno==EROFS)
94 dfd=open(dev,mode=O_RDONLY); 109 dfd=open(try,mode=O_RDONLY);
95 if(dfd<0) continue; 110 if(dfd<0) continue;
96 111
97 rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); 112 rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);
113
98 /* If device free, claim it. */ 114 /* If device free, claim it. */
99 if(rc && errno==ENXIO) { 115 if(rc && errno==ENXIO) {
100 memset(&loopinfo, 0, sizeof(loopinfo)); 116 memset(&loopinfo, 0, sizeof(loopinfo));
@@ -110,7 +126,7 @@ extern int set_loop(char **device, const char *file, int offset)
110 without using losetup manually is problematic.) 126 without using losetup manually is problematic.)
111 */ 127 */
112 } else if(strcmp(file,loopinfo.lo_file_name) 128 } else if(strcmp(file,loopinfo.lo_file_name)
113 || offset!=loopinfo.lo_offset) rc=1; 129 || offset!=loopinfo.lo_offset) rc=-1;
114 close(dfd); 130 close(dfd);
115 if(*device) break; 131 if(*device) break;
116 } 132 }
diff --git a/util-linux/losetup.c b/util-linux/losetup.c
index 11bd66ebf..b2af63dc0 100644
--- a/util-linux/losetup.c
+++ b/util-linux/losetup.c
@@ -24,8 +24,7 @@
24 24
25#include "busybox.h" 25#include "busybox.h"
26 26
27int 27int losetup_main (int argc, char **argv)
28losetup_main (int argc, char **argv)
29{ 28{
30 int offset = 0; 29 int offset = 0;
31 30
@@ -34,18 +33,27 @@ losetup_main (int argc, char **argv)
34 switch(getopt(argc,argv, "do:")) { 33 switch(getopt(argc,argv, "do:")) {
35 case 'd': 34 case 'd':
36 /* detach takes exactly one argument */ 35 /* detach takes exactly one argument */
37 if(optind+1==argc) 36 if(optind+1==argc && !del_loop(argv[optind])) return EXIT_SUCCESS;
38 return del_loop(argv[optind]) ? EXIT_SUCCESS : EXIT_FAILURE; 37die_failed:
39 break; 38 bb_perror_msg_and_die("%s",argv[optind]);
40 39
41 case 'o': 40 case 'o':
42 offset = bb_xparse_number (optarg, NULL); 41 offset = bb_xparse_number (optarg, NULL);
43 /* Fall through to do the losetup */ 42 /* Fall through to do the losetup */
44 case -1: 43 case -1:
45 /* losetup takes two argument:, loop_device and file */ 44 /* losetup takes two argument:, loop_device and file */
46 if(optind+2==argc) 45 if(optind+2==argc) {
47 return set_loop(&argv[optind], argv[optind + 1], offset)<0 46 if(set_loop(&argv[optind], argv[optind + 1], offset)>=0)
48 ? EXIT_FAILURE : EXIT_SUCCESS; 47 return EXIT_SUCCESS;
48 else goto die_failed;
49 }
50 if(optind+1==argc) {
51 char *s=query_loop(argv[optind]);
52 if (!s) goto die_failed;
53 printf("%s: %s\n",argv[optind],s);
54 if(ENABLE_FEATURE_CLEAN_UP) free(s);
55 return EXIT_SUCCESS;
56 }
49 break; 57 break;
50 } 58 }
51 bb_show_usage(); 59 bb_show_usage();