Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- Location:
- branches/3.2/mindi-busybox/util-linux
- Files:
-
- 66 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/util-linux/Config.src
r2725 r3232 11 11 bool "acpid" 12 12 default y 13 depends onPLATFORM_LINUX13 select PLATFORM_LINUX 14 14 help 15 15 acpid listens to ACPI events coming either in textual form from … … 34 34 bool "blkid" 35 35 default y 36 depends onPLATFORM_LINUX36 select PLATFORM_LINUX 37 37 select VOLUMEID 38 38 help … … 41 41 With all submodules selected, it will add ~8k to busybox. 42 42 43 config FEATURE_BLKID_TYPE 44 bool "Print filesystem type" 45 default n 46 depends on BLKID 47 help 48 Show TYPE="filesystem type" 49 43 50 config DMESG 44 51 bool "dmesg" 45 52 default y 46 depends onPLATFORM_LINUX53 select PLATFORM_LINUX 47 54 help 48 55 dmesg is used to examine or control the kernel ring buffer. When the … … 78 85 bool "fbset" 79 86 default y 80 depends onPLATFORM_LINUX87 select PLATFORM_LINUX 81 88 help 82 89 fbset is used to show or change the settings of a Linux frame buffer … … 107 114 bool "fdflush" 108 115 default y 109 depends onPLATFORM_LINUX116 select PLATFORM_LINUX 110 117 help 111 118 fdflush is only needed when changing media on slightly-broken … … 120 127 bool "fdformat" 121 128 default y 122 depends onPLATFORM_LINUX129 select PLATFORM_LINUX 123 130 help 124 131 fdformat is used to low-level format a floppy disk. … … 127 134 bool "fdisk" 128 135 default y 129 depends onPLATFORM_LINUX136 select PLATFORM_LINUX 130 137 help 131 138 The fdisk utility is used to divide hard disks into one or more … … 138 145 default y 139 146 depends on FDISK 147 depends on !LFS # with LFS no special code is needed 140 148 help 141 149 Enable this option to support large disks > 4GB. … … 203 211 bool "findfs" 204 212 default y 205 depends onPLATFORM_LINUX213 select PLATFORM_LINUX 206 214 select VOLUMEID 207 215 help … … 219 227 bool "freeramdisk" 220 228 default y 221 depends onPLATFORM_LINUX229 select PLATFORM_LINUX 222 230 help 223 231 Linux allows you to create ramdisks. This utility allows you to … … 242 250 bool "mkfs_ext2" 243 251 default y 244 depends onPLATFORM_LINUX252 select PLATFORM_LINUX 245 253 help 246 254 Utility to create EXT2 filesystems. … … 249 257 bool "mkfs_minix" 250 258 default y 251 depends onPLATFORM_LINUX259 select PLATFORM_LINUX 252 260 help 253 261 The minix filesystem is a nice, small, compact, read-write filesystem … … 267 275 bool "mkfs_reiser" 268 276 default n 269 depends onPLATFORM_LINUX277 select PLATFORM_LINUX 270 278 help 271 279 Utility to create ReiserFS filesystems. … … 275 283 bool "mkfs_vfat" 276 284 default y 277 depends onPLATFORM_LINUX285 select PLATFORM_LINUX 278 286 help 279 287 Utility to create FAT32 filesystems. … … 324 332 bool "hwclock" 325 333 default y 326 depends onPLATFORM_LINUX334 select PLATFORM_LINUX 327 335 help 328 336 The hwclock utility is used to read and set the hardware clock … … 363 371 bool "ipcs" 364 372 default y 365 depends onPLATFORM_LINUX373 select PLATFORM_LINUX 366 374 help 367 375 The ipcs utility is used to provide information on the currently … … 371 379 bool "losetup" 372 380 default y 373 depends onPLATFORM_LINUX381 select PLATFORM_LINUX 374 382 help 375 383 losetup is used to associate or detach a loop device with a regular … … 380 388 bool "lspci" 381 389 default y 382 # depends onPLATFORM_LINUX390 #select PLATFORM_LINUX 383 391 help 384 392 lspci is a utility for displaying information about PCI buses in the … … 390 398 bool "lsusb" 391 399 default y 392 # depends onPLATFORM_LINUX400 #select PLATFORM_LINUX 393 401 help 394 402 lsusb is a utility for displaying information about USB buses in the … … 396 404 397 405 This version uses sysfs (/sys/bus/usb/devices) only. 398 399 config MDEV400 bool "mdev"401 default y402 depends on PLATFORM_LINUX403 help404 mdev is a mini-udev implementation for dynamically creating device405 nodes in the /dev directory.406 407 For more information, please see docs/mdev.txt408 409 config FEATURE_MDEV_CONF410 bool "Support /etc/mdev.conf"411 default y412 depends on MDEV413 help414 Add support for the mdev config file to control ownership and415 permissions of the device nodes.416 417 For more information, please see docs/mdev.txt418 419 config FEATURE_MDEV_RENAME420 bool "Support subdirs/symlinks"421 default y422 depends on FEATURE_MDEV_CONF423 help424 Add support for renaming devices and creating symlinks.425 426 For more information, please see docs/mdev.txt427 428 config FEATURE_MDEV_RENAME_REGEXP429 bool "Support regular expressions substitutions when renaming device"430 default y431 depends on FEATURE_MDEV_RENAME432 help433 Add support for regular expressions substitutions when renaming434 device.435 436 config FEATURE_MDEV_EXEC437 bool "Support command execution at device addition/removal"438 default y439 depends on FEATURE_MDEV_CONF440 help441 This adds support for an optional field to /etc/mdev.conf for442 executing commands when devices are created/removed.443 444 For more information, please see docs/mdev.txt445 446 config FEATURE_MDEV_LOAD_FIRMWARE447 bool "Support loading of firmwares"448 default y449 depends on MDEV450 help451 Some devices need to load firmware before they can be usable.452 453 These devices will request userspace look up the files in454 /lib/firmware/ and if it exists, send it to the kernel for455 loading into the hardware.456 406 457 407 config MKSWAP … … 488 438 bool "mount" 489 439 default y 490 depends onPLATFORM_LINUX440 select PLATFORM_LINUX 491 441 help 492 442 All files and filesystems in Unix are arranged into one big directory … … 536 486 537 487 config FEATURE_MOUNT_NFS 538 bool "Support mounting NFS file systems "539 default y488 bool "Support mounting NFS file systems on Linux < 2.6.23" 489 default n 540 490 depends on MOUNT 541 491 select FEATURE_HAVE_RPC 542 492 select FEATURE_SYSLOG 543 493 help 544 Enable mounting of NFS file systems. 494 Enable mounting of NFS file systems on Linux kernels prior 495 to version 2.6.23. Note that in this case mounting of NFS 496 over IPv6 will not be possible. 497 498 Note that this option links in RPC support from libc, 499 which is rather large (~10 kbytes on uclibc). 545 500 546 501 config FEATURE_MOUNT_CIFS … … 571 526 bool "pivot_root" 572 527 default y 573 depends onPLATFORM_LINUX528 select PLATFORM_LINUX 574 529 help 575 530 The pivot_root utility swaps the mount points for the root filesystem … … 599 554 bool "readprofile" 600 555 default y 601 # depends onPLATFORM_LINUX556 #select PLATFORM_LINUX 602 557 help 603 558 This allows you to parse /proc/profile for basic profiling. … … 606 561 bool "rtcwake" 607 562 default y 608 depends onPLATFORM_LINUX563 select PLATFORM_LINUX 609 564 help 610 565 Enter a system sleep state until specified wakeup time. … … 626 581 bool "setarch" 627 582 default y 628 depends onPLATFORM_LINUX583 select PLATFORM_LINUX 629 584 help 630 585 The linux32 utility is used to create a 32bit environment for the … … 636 591 bool "swaponoff" 637 592 default y 638 depends onPLATFORM_LINUX593 select PLATFORM_LINUX 639 594 help 640 595 This option enables both the 'swapon' and the 'swapoff' utilities. … … 655 610 bool "switch_root" 656 611 default y 657 depends onPLATFORM_LINUX612 select PLATFORM_LINUX 658 613 help 659 614 The switch_root utility is used from initramfs to select a new … … 675 630 bool "umount" 676 631 default y 677 depends onPLATFORM_LINUX632 select PLATFORM_LINUX 678 633 help 679 634 When you want to remove a mounted filesystem from its current mount … … 780 735 TODO 781 736 737 config FEATURE_VOLUMEID_EXFAT 738 bool "exFAT filesystem" 739 default y 740 depends on VOLUMEID 741 help 742 exFAT (extended FAT) is a proprietary file system designed especially 743 for flash drives. It has many features from NTFS, but with less 744 overhead. exFAT is used on most SDXC cards for consumer electronics. 745 782 746 config FEATURE_VOLUMEID_HFS 783 747 bool "hfs filesystem" … … 808 772 TODO 809 773 774 config FEATURE_VOLUMEID_NILFS 775 bool "nilfs filesystem" 776 default y 777 depends on VOLUMEID 778 help 779 TODO 780 810 781 config FEATURE_VOLUMEID_NTFS 811 782 bool "ntfs filesystem" … … 870 841 help 871 842 TODO 843 844 config FEATURE_VOLUMEID_SQUASHFS 845 bool "SquashFS filesystem" 846 default y 847 depends on VOLUMEID && FEATURE_BLKID_TYPE 848 help 849 Squashfs is a compressed read-only filesystem for Linux. Squashfs is 850 intended for general read-only filesystem use and in constrained block 851 device/memory systems (e.g. embedded systems) where low overhead is 852 needed. 872 853 873 854 config FEATURE_VOLUMEID_SYSV -
branches/3.2/mindi-busybox/util-linux/Kbuild.src
r2725 r3232 27 27 lib-$(CONFIG_LSPCI) += lspci.o 28 28 lib-$(CONFIG_LSUSB) += lsusb.o 29 lib-$(CONFIG_MDEV) += mdev.o30 29 lib-$(CONFIG_MKFS_EXT2) += mkfs_ext2.o 31 30 lib-$(CONFIG_MKFS_MINIX) += mkfs_minix.o -
branches/3.2/mindi-busybox/util-linux/acpid.c
r2725 r3232 7 7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define acpid_trivial_usage 11 //usage: "[-df] [-c CONFDIR] [-l LOGFILE] [-a ACTIONFILE] [-M MAPFILE] [-e PROC_EVENT_FILE] [-p PIDFILE]" 12 //usage:#define acpid_full_usage "\n\n" 13 //usage: "Listen to ACPI events and spawn specific helpers on event arrival\n" 14 //usage: "\n -d Log to stderr, not log file (implies -f)" 15 //usage: "\n -f Run in foreground" 16 //usage: "\n -c DIR Config directory [/etc/acpi]" 17 //usage: "\n -e FILE /proc event file [/proc/acpi/event]" 18 //usage: "\n -l FILE Log file [/var/log/acpid.log]" 19 //usage: "\n -p FILE Pid file [/var/run/acpid.pid]" 20 //usage: "\n -a FILE Action file [/etc/acpid.conf]" 21 //usage: "\n -M FILE Map file [/etc/acpi.map]" 22 //usage: IF_FEATURE_ACPID_COMPAT( 23 //usage: "\n\nAccept and ignore compatibility options -g -m -s -S -v" 24 //usage: ) 25 //usage: 26 //usage:#define acpid_example_usage 27 //usage: "Without -e option, acpid uses all /dev/input/event* files\n" 28 //usage: "# acpid\n" 29 //usage: "# acpid -l /var/log/my-acpi-log\n" 30 //usage: "# acpid -e /proc/acpi/event\n" 31 9 32 #include "libbb.h" 10 33 #include <syslog.h> 11 34 #include <linux/input.h> 35 36 #ifndef EV_SW 37 # define EV_SW 0x05 38 #endif 39 #ifndef EV_KEY 40 # define EV_KEY 0x01 41 #endif 42 #ifndef SW_LID 43 # define SW_LID 0x00 44 #endif 45 #ifndef SW_RFKILL_ALL 46 # define SW_RFKILL_ALL 0x03 47 #endif 48 #ifndef KEY_POWER 49 # define KEY_POWER 116 /* SC System Power Down */ 50 #endif 51 #ifndef KEY_SLEEP 52 # define KEY_SLEEP 142 /* SC System Sleep */ 53 #endif 12 54 13 55 enum { … … 34 76 { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRF 00000080" }, 35 77 { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRB 00000080" }, 78 { "EV_SW", 0x05, "SW_LID", 0x00, 1, "button/lid LID0 00000080" }, 36 79 }; 37 80 … … 184 227 int acpid_main(int argc UNUSED_PARAM, char **argv) 185 228 { 186 struct input_event ev;187 229 int nfd; 188 230 int opts; … … 194 236 const char *opt_map = "/etc/acpi.map"; 195 237 #if ENABLE_FEATURE_PIDFILE 196 const char *opt_pidfile = "/var/run/acpid.pid";238 const char *opt_pidfile = CONFIG_PID_FILE_PATH "/acpid.pid"; 197 239 #endif 198 240 … … 207 249 208 250 if (!(opts & OPT_f)) { 251 /* No -f "Foreground", we go to background */ 209 252 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); 210 253 } 211 254 212 255 if (!(opts & OPT_d)) { 256 /* No -d "Debug", we log to log file. 257 * This includes any output from children. 258 */ 259 xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO); 260 xdup2(STDOUT_FILENO, STDERR_FILENO); 261 /* Also, acpid's messages (but not children) will go to syslog too */ 213 262 openlog(applet_name, LOG_PID, LOG_DAEMON); 214 263 logmode = LOGMODE_SYSLOG | LOGMODE_STDIO; 215 } else { 216 xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO); 217 } 264 } 265 /* else: -d "Debug", log is not redirected */ 218 266 219 267 parse_conf_file(opt_action); … … 222 270 xchdir(opt_dir); 223 271 272 /* We spawn children but don't wait for them. Prevent zombies: */ 224 273 bb_signals((1 << SIGCHLD), SIG_IGN); 225 bb_signals(BB_FATAL_SIGS, record_signo); 274 // If you enable this, (1) explain why, (2) 275 // make sure while(poll) loop below is still interruptible 276 // by SIGTERM et al: 277 //bb_signals(BB_FATAL_SIGS, record_signo); 226 278 227 279 pfd = NULL; … … 231 283 char *dev_event; 232 284 233 dev_event = xasprintf((opt ion_mask32& OPT_e) ? "%s" : "%s%u", opt_input, nfd);285 dev_event = xasprintf((opts & OPT_e) ? "%s" : "%s%u", opt_input, nfd); 234 286 fd = open(dev_event, O_RDONLY | O_NONBLOCK); 235 287 if (fd < 0) { … … 238 290 break; 239 291 } 292 free(dev_event); 240 293 pfd = xrealloc_vector(pfd, 1, nfd); 241 294 pfd[nfd].fd = fd; … … 246 299 write_pidfile(opt_pidfile); 247 300 248 while ( poll(pfd, nfd, -1) > 0) {301 while (safe_poll(pfd, nfd, -1) > 0) { 249 302 int i; 250 303 for (i = 0; i < nfd; i++) { 251 const char *event = NULL; 252 253 memset(&ev, 0, sizeof(ev)); 254 255 if (!(pfd[i].revents & POLLIN)) 256 continue; 257 304 const char *event; 305 306 if (!(pfd[i].revents & POLLIN)) { 307 if (pfd[i].revents == 0) 308 continue; /* this fd has nothing */ 309 310 /* Likely POLLERR, POLLHUP, POLLNVAL. 311 * Do not listen on this fd anymore. 312 */ 313 close(pfd[i].fd); 314 nfd--; 315 for (; i < nfd; i++) 316 pfd[i].fd = pfd[i + 1].fd; 317 break; /* do poll() again */ 318 } 319 320 event = NULL; 258 321 if (option_mask32 & OPT_e) { 259 322 char *buf; 260 323 int len; 261 324 262 buf = xmalloc_reads(pfd[i].fd, NULL , NULL);325 buf = xmalloc_reads(pfd[i].fd, NULL); 263 326 /* buf = "button/power PWRB 00000080 00000000" */ 264 327 len = strlen(buf) - 9; … … 266 329 buf[len] = '\0'; 267 330 event = find_action(NULL, buf); 331 free(buf); 268 332 } else { 333 struct input_event ev; 334 269 335 if (sizeof(ev) != full_read(pfd[i].fd, &ev, sizeof(ev))) 270 336 continue; … … 277 343 if (!event) 278 344 continue; 279 / / spawn event handler345 /* spawn event handler */ 280 346 process_event(event); 281 347 } … … 283 349 284 350 if (ENABLE_FEATURE_CLEAN_UP) { 285 while (nfd--) { 286 if (pfd[nfd].fd) { 287 close(pfd[nfd].fd); 288 } 289 } 351 while (nfd--) 352 close(pfd[nfd].fd); 290 353 free(pfd); 291 354 } -
branches/3.2/mindi-busybox/util-linux/blkid.c
r2725 r3232 8 8 */ 9 9 10 //usage:#define blkid_trivial_usage 11 //usage: "[BLOCKDEV]..." 12 //usage:#define blkid_full_usage "\n\n" 13 //usage: "Print UUIDs of all filesystems" 14 10 15 #include "libbb.h" 11 16 #include "volume_id.h" 12 17 13 18 int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14 int blkid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)19 int blkid_main(int argc UNUSED_PARAM, char **argv) 15 20 { 16 display_uuid_cache(); 21 int scan_devices = 1; 22 23 while (*++argv) { 24 /* Note: bogus device names don't cause any error messages */ 25 add_to_uuid_cache(*argv); 26 scan_devices = 0; 27 } 28 29 display_uuid_cache(scan_devices); 17 30 return 0; 18 31 } -
branches/3.2/mindi-busybox/util-linux/blockdev.c
r3085 r3232 7 7 */ 8 8 9 //applet:IF_BLOCKDEV(APPLET(blockdev, _BB_DIR_SBIN, _BB_SUID_DROP))9 //applet:IF_BLOCKDEV(APPLET(blockdev, BB_DIR_SBIN, BB_SUID_DROP)) 10 10 11 11 //kbuild:lib-$(CONFIG_BLOCKDEV) += blockdev.o … … 20 20 //usage: "OPTION BLOCKDEV" 21 21 //usage:#define blockdev_full_usage "\n\n" 22 //usage: "Options:" 23 //usage: "\n --setro Set ro" 22 //usage: " --setro Set ro" 24 23 //usage: "\n --setrw Set rw" 25 24 //usage: "\n --getro Get ro" … … 27 26 //usage: "\n --getbsz Get block size" 28 27 //usage: "\n --setbsz BYTES Set block size" 29 //usage: "\n --getsize Get device size in 512-byte sectors" 28 //usage: "\n --getsz Get device size in 512-byte sectors" 29 /*//usage: "\n --getsize Get device size in sectors (deprecated)"*/ 30 30 //usage: "\n --getsize64 Get device size in bytes" 31 31 //usage: "\n --flushbufs Flush buffers" … … 35 35 #include "libbb.h" 36 36 #include <linux/fs.h> 37 38 /* Patch bco to compile this busybox on rhel3 */39 #ifndef BLKGETSIZE6440 #define BLKGETSIZE64 _IOR(0x12,114,size_t)41 #endif42 37 43 38 enum { … … 51 46 FL_USRARG = 4, /* argument is provided by user */ 52 47 FL_NORESULT = 8, 48 FL_SCALE512 = 16, 53 49 }; 54 50 … … 91 87 .flags = ARG_INT + FL_NORESULT + FL_USRARG, 92 88 .argval = 0, 89 },{ 90 .ioc = BLKGETSIZE64, 91 .name = "getsz", 92 .flags = ARG_U64 + FL_SCALE512, 93 .argval = -1, 93 94 },{ 94 95 .ioc = BLKGETSIZE, … … 129 130 130 131 int blockdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 131 int blockdev_main(int argc , char **argv)132 int blockdev_main(int argc UNUSED_PARAM, char **argv) 132 133 { 133 134 const struct bdc *bdcmd; … … 140 141 } ioctl_val_on_stack; 141 142 142 if ((unsigned)(argc - 3) > 1) /* must have 2 or 3 args */ 143 argv++; 144 if (!argv[0] || !argv[1]) /* must have at least 2 args */ 143 145 bb_show_usage(); 144 146 145 bdcmd = find_cmd(* ++argv);147 bdcmd = find_cmd(*argv); 146 148 147 149 u64 = (int)bdcmd->argval; … … 149 151 u64 = xatoi_positive(*++argv); 150 152 151 if (!*++argv || argv[1]) 153 argv++; 154 if (!argv[0] || argv[1]) 152 155 bb_show_usage(); 153 fd = xopen( *argv, O_RDONLY);156 fd = xopen(argv[0], O_RDONLY); 154 157 155 158 ioctl_val_on_stack.u64 = u64; … … 179 182 u64 = ioctl_val_on_stack.u64; 180 183 184 if (bdcmd->flags & FL_SCALE512) 185 u64 >>= 9; 186 181 187 /* Zero- or one-extend the value if needed, then print */ 182 188 switch (bdcmd->flags & (ARG_MASK+FL_NORESULT)) { -
branches/3.2/mindi-busybox/util-linux/dmesg.c
r2725 r3232 9 9 * Licensed under GPLv2, see file LICENSE in this source tree. 10 10 */ 11 12 //usage:#define dmesg_trivial_usage 13 //usage: "[-c] [-n LEVEL] [-s SIZE]" 14 //usage:#define dmesg_full_usage "\n\n" 15 //usage: "Print or control the kernel ring buffer\n" 16 //usage: "\n -c Clear ring buffer after printing" 17 //usage: "\n -n LEVEL Set console logging level" 18 //usage: "\n -s SIZE Buffer size" 19 11 20 #include <sys/klog.h> 12 21 #include "libbb.h" … … 51 60 int in = 0; 52 61 53 /* Skip < #> at the start of lines */62 /* Skip <[0-9]+> at the start of lines */ 54 63 while (1) { 55 64 if (last == '\n' && buf[in] == '<') { 56 in += 3; 57 if (in >= len) 58 break; 65 while (buf[in++] != '>' && in < len) 66 ; 67 } else { 68 last = buf[in++]; 69 putchar(last); 59 70 } 60 last = buf[in];61 putchar(last);62 in++;63 71 if (in >= len) 64 72 break; -
branches/3.2/mindi-busybox/util-linux/fbset.c
r2725 r3232 12 12 * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be) 13 13 */ 14 15 //usage:#define fbset_trivial_usage 16 //usage: "[OPTIONS] [MODE]" 17 //usage:#define fbset_full_usage "\n\n" 18 //usage: "Show and modify frame buffer settings" 19 //usage: 20 //usage:#define fbset_example_usage 21 //usage: "$ fbset\n" 22 //usage: "mode \"1024x768-76\"\n" 23 //usage: " # D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz\n" 24 //usage: " geometry 1024 768 1024 768 16\n" 25 //usage: " timings 12714 128 32 16 4 128 4\n" 26 //usage: " accel false\n" 27 //usage: " rgba 5/11,6/5,5/0,0/0\n" 28 //usage: "endmode\n" 14 29 15 30 #include "libbb.h" … … 257 272 p = token[1]; 258 273 i = index_in_strings( 259 "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0 ",274 "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0rgba\0", 260 275 token[0]); 261 276 switch (i) { … … 328 343 //bb_info_msg("EXTSYNC[%s]", p); 329 344 break; 345 case 8: { 346 int red_offset, red_length; 347 int green_offset, green_length; 348 int blue_offset, blue_length; 349 int transp_offset, transp_length; 350 351 sscanf(p, "%d/%d,%d/%d,%d/%d,%d/%d", 352 &red_offset, &red_length, 353 &green_offset, &green_length, 354 &blue_offset, &blue_length, 355 &transp_offset, &transp_length); 356 base->red.offset = red_offset; 357 base->red.length = red_length; 358 base->red.msb_right = 0; 359 base->green.offset = green_offset; 360 base->green.length = green_length; 361 base->green.msb_right = 0; 362 base->blue.offset = blue_offset; 363 base->blue.length = blue_length; 364 base->blue.msb_right = 0; 365 base->transp.offset = transp_offset; 366 base->transp.length = transp_length; 367 base->transp.msb_right = 0; 368 } 330 369 } 331 370 } … … 371 410 OPT_SHOW = (1 << 1), 372 411 OPT_READMODE = (1 << 2), 373 OPT_ALL = (1 << 9),412 OPT_ALL = (1 << 3), 374 413 }; 375 414 struct fb_var_screeninfo var_old, var_set; … … 388 427 argc--; 389 428 for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) { 390 if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) { 429 if (thisarg[0] != '-') { 430 if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1) 431 bb_show_usage(); 432 mode = thisarg; 433 options |= OPT_READMODE; 434 goto contin; 435 } 436 for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) { 391 437 if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0) 392 438 continue; … … 457 503 goto contin; 458 504 } 459 if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1) 460 bb_show_usage(); 461 mode = *argv; 462 options |= OPT_READMODE; 505 bb_show_usage(); 463 506 contin: ; 464 507 } … … 472 515 bb_error_msg_and_die("unknown video mode '%s'", mode); 473 516 } 517 options |= OPT_CHANGE; 474 518 #endif 475 519 } -
branches/3.2/mindi-busybox/util-linux/fdformat.c
r2725 r3232 5 5 * Licensed under GPLv2, see file LICENSE in this source tree. 6 6 */ 7 8 //usage:#define fdformat_trivial_usage 9 //usage: "[-n] DEVICE" 10 //usage:#define fdformat_full_usage "\n\n" 11 //usage: "Format floppy disk\n" 12 //usage: "\n -n Don't verify after format" 7 13 8 14 #include "libbb.h" … … 111 117 while (--read_bytes >= 0) { 112 118 if (data[read_bytes] != FD_FILL_BYTE) { 113 119 printf("bad data in cyl %d\nContinuing... ", cyl); 114 120 } 115 121 } -
branches/3.2/mindi-busybox/util-linux/fdisk.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 /* Looks like someone forgot to add this to config system */ 11 //usage:#ifndef ENABLE_FEATURE_FDISK_BLKSIZE 12 //usage:# define ENABLE_FEATURE_FDISK_BLKSIZE 0 13 //usage:# define IF_FEATURE_FDISK_BLKSIZE(a) 14 //usage:#endif 15 //usage: 16 //usage:#define fdisk_trivial_usage 17 //usage: "[-ul" IF_FEATURE_FDISK_BLKSIZE("s") "] " 18 //usage: "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" 19 //usage:#define fdisk_full_usage "\n\n" 20 //usage: "Change partition table\n" 21 //usage: "\n -u Start and End are in sectors (instead of cylinders)" 22 //usage: "\n -l Show partition table for each DISK, then exit" 23 //usage: IF_FEATURE_FDISK_BLKSIZE( 24 //usage: "\n -s Show partition sizes in kb for each DISK, then exit" 25 //usage: ) 26 //usage: "\n -b 2048 (for certain MO disks) use 2048-byte sectors" 27 //usage: "\n -C CYLINDERS Set number of cylinders/heads/sectors" 28 //usage: "\n -H HEADS" 29 //usage: "\n -S SECTORS" 9 30 10 31 #ifndef _LARGEFILE64_SOURCE … … 549 570 int sz; 550 571 551 sz = read_line_input( prompt, line_buffer, sizeof(line_buffer), NULL);572 sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer), /*timeout*/ -1); 552 573 if (sz <= 0) 553 574 exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */ … … 2523 2544 2524 2545 static void 2525 write_table(void)2526 {2527 int i;2528 2529 if (LABEL_IS_DOS) {2530 for (i = 0; i < 3; i++)2531 if (ptes[i].changed)2532 ptes[3].changed = 1;2533 for (i = 3; i < g_partitions; i++) {2534 struct pte *pe = &ptes[i];2535 2536 if (pe->changed) {2537 write_part_table_flag(pe->sectorbuffer);2538 write_sector(pe->offset_from_dev_start, pe->sectorbuffer);2539 }2540 }2541 }2542 else if (LABEL_IS_SGI) {2543 /* no test on change? the printf below might be mistaken */2544 sgi_write_table();2545 }2546 else if (LABEL_IS_SUN) {2547 int needw = 0;2548 2549 for (i = 0; i < 8; i++)2550 if (ptes[i].changed)2551 needw = 1;2552 if (needw)2553 sun_write_table();2554 }2555 2556 printf("The partition table has been altered!\n\n");2557 reread_partition_table(1);2558 }2559 2560 static void2561 2546 reread_partition_table(int leave) 2562 2547 { … … 2565 2550 printf("Calling ioctl() to re-read partition table\n"); 2566 2551 sync(); 2567 /* sleep(2); Huh? */ 2552 /* Users with slow external USB disks on a 320MHz ARM system (year 2011) 2553 * report that sleep is needed, otherwise BLKRRPART may fail with -EIO: 2554 */ 2555 sleep(1); 2568 2556 i = ioctl_or_perror(dev_fd, BLKRRPART, NULL, 2569 2557 "WARNING: rereading partition table " … … 2582 2570 exit(i != 0); 2583 2571 } 2572 } 2573 2574 static void 2575 write_table(void) 2576 { 2577 int i; 2578 2579 if (LABEL_IS_DOS) { 2580 for (i = 0; i < 3; i++) 2581 if (ptes[i].changed) 2582 ptes[3].changed = 1; 2583 for (i = 3; i < g_partitions; i++) { 2584 struct pte *pe = &ptes[i]; 2585 if (pe->changed) { 2586 write_part_table_flag(pe->sectorbuffer); 2587 write_sector(pe->offset_from_dev_start, pe->sectorbuffer); 2588 } 2589 } 2590 } 2591 else if (LABEL_IS_SGI) { 2592 /* no test on change? the printf below might be mistaken */ 2593 sgi_write_table(); 2594 } 2595 else if (LABEL_IS_SUN) { 2596 for (i = 0; i < 8; i++) { 2597 if (ptes[i].changed) { 2598 sun_write_table(); 2599 break; 2600 } 2601 } 2602 } 2603 2604 printf("The partition table has been altered.\n"); 2605 reread_partition_table(1); 2584 2606 } 2585 2607 #endif /* FEATURE_FDISK_WRITABLE */ … … 2825 2847 } 2826 2848 2849 /* Is it a whole disk? The digit check is still useful 2850 for Xen devices for example. */ 2851 static int is_whole_disk(const char *disk) 2852 { 2853 unsigned len; 2854 int fd = open(disk, O_RDONLY); 2855 2856 if (fd != -1) { 2857 struct hd_geometry geometry; 2858 int err = ioctl(fd, HDIO_GETGEO, &geometry); 2859 close(fd); 2860 if (!err) 2861 return (geometry.start == 0); 2862 } 2863 2864 /* Treat "nameN" as a partition name, not whole disk */ 2865 /* note: mmcblk0 should work from the geometry check above */ 2866 len = strlen(disk); 2867 if (len != 0 && isdigit(disk[len - 1])) 2868 return 0; 2869 2870 return 1; 2871 } 2872 2827 2873 /* for fdisk -l: try all things in /proc/partitions 2828 2874 that look like a partition name (do not end in a digit) */ … … 2831 2877 { 2832 2878 FILE *procpt; 2833 char line[100], ptname[100], devname[120] , *s;2879 char line[100], ptname[100], devname[120]; 2834 2880 int ma, mi, sz; 2835 2881 … … 2840 2886 &ma, &mi, &sz, ptname) != 4) 2841 2887 continue; 2842 for (s = ptname; *s; s++) 2843 continue; 2844 /* note: excluding '0': e.g. mmcblk0 is not a partition name! */ 2845 if (s[-1] >= '1' && s[-1] <= '9') 2846 continue; 2888 2847 2889 sprintf(devname, "/dev/%s", ptname); 2848 open_list_and_close(devname, 0); 2890 if (is_whole_disk(devname)) 2891 open_list_and_close(devname, 0); 2849 2892 } 2850 2893 #if ENABLE_FEATURE_CLEAN_UP … … 2981 3024 sgi_get_bootfile()); 2982 3025 if (read_maybe_empty("Please enter the name of the " 2983 3026 "new boot file: ") == '\n') 2984 3027 printf("Boot file unchanged\n"); 2985 3028 else … … 3059 3102 break; 3060 3103 case 'w': 3061 write_table(); 3104 write_table(); /* does not return */ 3062 3105 break; 3063 3106 #if ENABLE_FEATURE_FDISK_ADVANCED -
branches/3.2/mindi-busybox/util-linux/fdisk_osf.c
r2725 r3232 44 44 #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec" 45 45 46 #if defined(i386) || defined(__sparc__) || defined(__arm__) \ 47 || defined(__m68k__) || defined(__mips__) || defined(__s390__) \ 48 || defined(__s390__) || defined(__s390x__) \ 49 || defined(__sh__) || defined(__x86_64__) || defined(__avr32__) \ 50 || defined(__nds32__) 51 # define BSD_LABELSECTOR 1 52 # define BSD_LABELOFFSET 0 53 #elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \ 46 #if defined(__alpha__) \ 47 || defined(__powerpc__) \ 48 || defined(__ia64__) \ 54 49 || defined(__hppa__) 55 50 # define BSD_LABELSECTOR 0 56 51 # define BSD_LABELOFFSET 64 57 52 #else 58 # error unknown architecture 53 # define BSD_LABELSECTOR 1 54 # define BSD_LABELOFFSET 0 59 55 #endif 60 56 … … 903 899 #else 904 900 d->d_npartitions = 3; 905 pp = &d->d_partitions[2]; /* Partition C should be 906 the whole disk */ 901 pp = &d->d_partitions[2]; /* Partition C should be the whole disk */ 907 902 pp->p_offset = 0; 908 903 pp->p_size = d->d_secperunit; … … 940 935 941 936 memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], 942 937 sizeof(struct xbsd_disklabel)); 943 938 944 939 if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) -
branches/3.2/mindi-busybox/util-linux/findfs.c
r2725 r3232 8 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define findfs_trivial_usage 12 //usage: "LABEL=label or UUID=uuid" 13 //usage:#define findfs_full_usage "\n\n" 14 //usage: "Find a filesystem device based on a label or UUID" 15 //usage: 16 //usage:#define findfs_example_usage 17 //usage: "$ findfs LABEL=MyDevice" 10 18 11 19 #include "libbb.h" -
branches/3.2/mindi-busybox/util-linux/flock.c
r2725 r3232 4 4 * This is free software, licensed under the GNU General Public License v2. 5 5 */ 6 7 //usage:#define flock_trivial_usage 8 //usage: "[-sxun] FD|{FILE [-c] PROG ARGS}" 9 //usage:#define flock_full_usage "\n\n" 10 //usage: "[Un]lock file descriptor, or lock FILE, run PROG\n" 11 //usage: "\n -s Shared lock" 12 //usage: "\n -x Exclusive lock (default)" 13 //usage: "\n -u Unlock FD" 14 //usage: "\n -n Fail rather than wait" 15 6 16 #include <sys/file.h> 7 17 #include "libbb.h" … … 20 30 21 31 #if ENABLE_LONG_OPTS 22 32 static const char getopt_longopts[] ALIGN1 = 23 33 "shared\0" No_argument "s" 24 34 "exclusive\0" No_argument "x" … … 36 46 fd = open(argv[0], O_RDONLY|O_NOCTTY|O_CREAT, 0666); 37 47 if (fd < 0 && errno == EISDIR) 38 48 fd = open(argv[0], O_RDONLY|O_NOCTTY); 39 49 if (fd < 0) 40 50 bb_perror_msg_and_die("can't open '%s'", argv[0]); -
branches/3.2/mindi-busybox/util-linux/freeramdisk.c
r2725 r3232 9 9 * Licensed under GPLv2, see file LICENSE in this source tree. 10 10 */ 11 12 //usage:#define freeramdisk_trivial_usage 13 //usage: "DEVICE" 14 //usage:#define freeramdisk_full_usage "\n\n" 15 //usage: "Free all memory used by the specified ramdisk" 16 //usage: 17 //usage:#define freeramdisk_example_usage 18 //usage: "$ freeramdisk /dev/ram2\n" 19 //usage: 20 //usage:#define fdflush_trivial_usage 21 //usage: "DEVICE" 22 //usage:#define fdflush_full_usage "\n\n" 23 //usage: "Force floppy disk drive to detect disk change" 24 11 25 #include <sys/mount.h> 12 26 #include "libbb.h" -
branches/3.2/mindi-busybox/util-linux/fsck_minix.c
r2725 r3232 14 14 * Sent out to the mailing-list for testing. 15 15 * 16 * 14.11.91 - 16 * 14.11.91 - Testing seems to have gone well. Added some 17 17 * correction-code, and changed some functions. 18 18 * … … 23 23 * things seem to work now. Yeah, sure. 24 24 * 25 * 26 * 19.04.92 - Had to start over again from this old version, as a 25 * 19.04.92 - Had to start over again from this old version, as a 27 26 * kernel bug ate my enhanced fsck in february. 28 27 * 29 * 28.02.93 - 28 * 28.02.93 - added support for different directory entry sizes.. 30 29 * 31 30 * Sat Mar 6 18:59:42 1993, faith@cs.unc.edu: Output namelen with … … 36 35 * 37 36 * Mon Jan 3 11:06:52 1994 - Dr. Wettstein (greg%wind.uucp@plains.nodak.edu) 38 * 39 * 40 * 41 * 42 * 43 * 30.10.94 - added support for v2 filesystem44 * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)45 * 46 * 10.12.94 - 47 * 48 * 37 * Added support for file system valid flag. Also 38 * added program_version variable and output of 39 * program name and version number when program 40 * is executed. 41 * 42 * 30.10.94 - added support for v2 filesystem 43 * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) 44 * 45 * 10.12.94 - added test to prevent checking of mounted fs adapted 46 * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck 47 * program. (Daniel Quinlan, quinlan@yggdrasil.com) 49 48 * 50 49 * 01.07.96 - Fixed the v2 fs stuff to use the right #defines and such 51 * 50 * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) 52 51 * 53 52 * 02.07.96 - Added C bit fiddling routines from rmk@ecs.soton.ac.uk 54 53 * (Russell King). He made them for ARM. It would seem 55 * 54 * that the ARM is powerful enough to do this in C whereas 56 55 * i386 and m64k must use assembly to get it fast >:-) 57 * 58 * 56 * This should make minix fsck system-independent. 57 * (janl@math.uio.no, Nicolai Langfeldt) 59 58 * 60 59 * 04.11.96 - Added minor fixes from Andreas Schwab to avoid compiler 61 60 * warnings. Added mc68k bitops from 62 * 61 * Joerg Dorchain <dorchain@mpi-sb.mpg.de>. 63 62 * 64 63 * 06.11.96 - Added v2 code submitted by Joerg Dorchain, but written by … … 87 86 * enforced (but it's not much fun on a character device :-). 88 87 */ 88 89 //usage:#define fsck_minix_trivial_usage 90 //usage: "[-larvsmf] BLOCKDEV" 91 //usage:#define fsck_minix_full_usage "\n\n" 92 //usage: "Check MINIX filesystem\n" 93 //usage: "\n -l List all filenames" 94 //usage: "\n -r Perform interactive repairs" 95 //usage: "\n -a Perform automatic repairs" 96 //usage: "\n -v Verbose" 97 //usage: "\n -s Output superblock information" 98 //usage: "\n -m Show \"mode not cleared\" warnings" 99 //usage: "\n -f Force file system check" 89 100 90 101 #include <mntent.h> … … 1120 1131 } 1121 1132 printf("Zone %d: %sin use, counted=%d\n", 1122 1133 i, zone_in_use(i) ? "" : "not ", zone_count[i]); 1123 1134 } 1124 1135 } … … 1172 1183 } 1173 1184 printf("Zone %d: %sin use, counted=%d\n", 1174 1185 i, zone_in_use(i) ? "" : "not ", zone_count[i]); 1175 1186 } 1176 1187 } … … 1242 1253 else if (OPT_repair) 1243 1254 printf("Filesystem on %s is dirty, needs checking\n", 1244 1255 device_name); 1245 1256 1246 1257 read_tables(); … … 1269 1280 free_cnt++; 1270 1281 printf("\n%6u inodes used (%u%%)\n", (INODES - free_cnt), 1271 1282 100 * (INODES - free_cnt) / INODES); 1272 1283 for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++) 1273 1284 if (!zone_in_use(i)) 1274 1285 free_cnt++; 1275 1286 printf("%6u zones used (%u%%)\n\n" 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1287 "%6u regular files\n" 1288 "%6u directories\n" 1289 "%6u character device files\n" 1290 "%6u block device files\n" 1291 "%6u links\n" 1292 "%6u symbolic links\n" 1293 "------\n" 1294 "%6u files\n", 1295 (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES, 1296 regular, directory, chardev, blockdev, 1297 links - 2 * directory + 1, symlinks, 1298 total - 2 * directory + 1); 1288 1299 } 1289 1300 if (changed) { -
branches/3.2/mindi-busybox/util-linux/getopt.c
r2725 r3232 26 26 * <misiek@misiek.eu.org>) 27 27 * Ported to Busybox - Alfred M. Szmidt <ams@trillian.itslinux.org> 28 * Removed --version/-V and --help/-h in28 * Removed --version/-V and --help/-h 29 29 * Removed parse_error(), using bb_error_msg() from Busybox instead 30 30 * Replaced our_malloc with xmalloc and our_realloc with xrealloc … … 32 32 */ 33 33 34 #include <getopt.h> 34 //usage:#define getopt_trivial_usage 35 //usage: "[OPTIONS] [--] OPTSTRING PARAMS" 36 //usage:#define getopt_full_usage "\n\n" 37 //usage: IF_LONG_OPTS( 38 //usage: " -a,--alternative Allow long options starting with single -" 39 //usage: "\n -l,--longoptions=LOPT[,...] Long options to be recognized" 40 //usage: "\n -n,--name=PROGNAME The name under which errors are reported" 41 //usage: "\n -o,--options=OPTSTRING Short options to be recognized" 42 //usage: "\n -q,--quiet Disable error reporting by getopt(3)" 43 //usage: "\n -Q,--quiet-output No normal output" 44 //usage: "\n -s,--shell=SHELL Set shell quoting conventions" 45 //usage: "\n -T,--test Test for getopt(1) version" 46 //usage: "\n -u,--unquoted Don't quote the output" 47 //usage: ) 48 //usage: IF_NOT_LONG_OPTS( 49 //usage: " -a Allow long options starting with single -" 50 //usage: "\n -l LOPT[,...] Long options to be recognized" 51 //usage: "\n -n PROGNAME The name under which errors are reported" 52 //usage: "\n -o OPTSTRING Short options to be recognized" 53 //usage: "\n -q Disable error reporting by getopt(3)" 54 //usage: "\n -Q No normal output" 55 //usage: "\n -s SHELL Set shell quoting conventions" 56 //usage: "\n -T Test for getopt(1) version" 57 //usage: "\n -u Don't quote the output" 58 //usage: ) 59 //usage: "\n" 60 //usage: "\nExample:" 61 //usage: "\n" 62 //usage: "\nO=`getopt -l bb: -- ab:c:: \"$@\"` || exit 1" 63 //usage: "\neval set -- \"$O\"" 64 //usage: "\nwhile true; do" 65 //usage: "\n case \"$1\" in" 66 //usage: "\n -a) echo A; shift;;" 67 //usage: "\n -b|--bb) echo \"B:'$2'\"; shift 2;;" 68 //usage: "\n -c) case \"$2\" in" 69 //usage: "\n \"\") echo C; shift 2;;" 70 //usage: "\n *) echo \"C:'$2'\"; shift 2;;" 71 //usage: "\n esac;;" 72 //usage: "\n --) shift; break;;" 73 //usage: "\n *) echo Error; exit 1;;" 74 //usage: "\n esac" 75 //usage: "\ndone" 76 //usage: 77 //usage:#define getopt_example_usage 78 //usage: "$ cat getopt.test\n" 79 //usage: "#!/bin/sh\n" 80 //usage: "GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \\\n" 81 //usage: " -n 'example.busybox' -- \"$@\"`\n" 82 //usage: "if [ $? != 0 ]; then exit 1; fi\n" 83 //usage: "eval set -- \"$GETOPT\"\n" 84 //usage: "while true; do\n" 85 //usage: " case $1 in\n" 86 //usage: " -a|--a-long) echo \"Option a\"; shift;;\n" 87 //usage: " -b|--b-long) echo \"Option b, argument '$2'\"; shift 2;;\n" 88 //usage: " -c|--c-long)\n" 89 //usage: " case \"$2\" in\n" 90 //usage: " \"\") echo \"Option c, no argument\"; shift 2;;\n" 91 //usage: " *) echo \"Option c, argument '$2'\"; shift 2;;\n" 92 //usage: " esac;;\n" 93 //usage: " --) shift; break;;\n" 94 //usage: " *) echo \"Internal error!\"; exit 1;;\n" 95 //usage: " esac\n" 96 //usage: "done\n" 97 98 #if ENABLE_FEATURE_GETOPT_LONG 99 # include <getopt.h> 100 #endif 35 101 #include "libbb.h" 36 102 … … 291 357 int getopt_main(int argc, char **argv) 292 358 { 359 int n; 293 360 char *optstr = NULL; 294 361 char *name = NULL; … … 303 370 compatible = getenv("GETOPT_COMPATIBLE"); /* used as yes/no flag */ 304 371 305 if ( argc == 1) {372 if (!argv[1]) { 306 373 if (compatible) { 307 374 /* For some reason, the original getopt gave no error 308 375 * when there were no arguments. */ 309 376 printf(" --\n"); 310 377 return 0; … … 314 381 315 382 if (argv[1][0] != '-' || compatible) { 316 char *s ;383 char *s = argv[1]; 317 384 318 385 option_mask32 |= OPT_u; /* quoting off */ 319 s = xstrdup( argv[1] + strspn(argv[1], "-+"));386 s = xstrdup(s + strspn(s, "-+")); 320 387 argv[1] = argv[0]; 321 388 return generate_output(argv+1, argc-1, s, long_options); … … 344 411 345 412 /* All options controlling the applet have now been parsed */ 413 n = optind - 1; 346 414 if (!optstr) { 347 if (optind >= argc) 415 optstr = argv[++n]; 416 if (!optstr) 348 417 bb_error_msg_and_die("missing optstring argument"); 349 optstr = argv[optind++]; 350 } 351 352 argv[optind-1] = name ? name : argv[0]; 353 return generate_output(argv+optind-1, argc-optind+1, optstr, long_options); 418 } 419 420 argv[n] = name ? name : argv[0]; 421 return generate_output(argv + n, argc - n, optstr, long_options); 354 422 } -
branches/3.2/mindi-busybox/util-linux/hexdump.c
r2725 r3232 9 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 */ 11 12 //usage:#define hexdump_trivial_usage 13 //usage: "[-bcCdefnosvx" IF_FEATURE_HEXDUMP_REVERSE("R") "] [FILE]..." 14 //usage:#define hexdump_full_usage "\n\n" 15 //usage: "Display FILEs (or stdin) in a user specified format\n" 16 //usage: "\n -b One-byte octal display" 17 //usage: "\n -c One-byte character display" 18 //usage: "\n -C Canonical hex+ASCII, 16 bytes per line" 19 //usage: "\n -d Two-byte decimal display" 20 //usage: "\n -e FORMAT_STRING" 21 //usage: "\n -f FORMAT_FILE" 22 //usage: "\n -n LENGTH Interpret only LENGTH bytes of input" 23 //usage: "\n -o Two-byte octal display" 24 //usage: "\n -s OFFSET Skip OFFSET bytes" 25 //usage: "\n -v Display all input data" 26 //usage: "\n -x Two-byte hexadecimal display" 27 //usage: IF_FEATURE_HEXDUMP_REVERSE( 28 //usage: "\n -R Reverse of 'hexdump -Cv'") 29 //usage: 30 //usage:#define hd_trivial_usage 31 //usage: "FILE..." 32 //usage:#define hd_full_usage "\n\n" 33 //usage: "hd is an alias for hexdump -C" 11 34 12 35 #include "libbb.h" -
branches/3.2/mindi-busybox/util-linux/hwclock.c
r2725 r3232 44 44 rtc_read_tm(&tm_time, fd); 45 45 gettimeofday(sys_tv, NULL); 46 if (before != tm_time.tm_sec)46 if (before != (int)tm_time.tm_sec) 47 47 break; 48 48 } … … 61 61 struct timeval sys_tv; 62 62 #endif 63 time_t t; 64 char *cp; 65 66 t = read_rtc(pp_rtcname, &sys_tv, utc); 67 cp = ctime(&t); 63 time_t t = read_rtc(pp_rtcname, &sys_tv, utc); 64 65 #if ENABLE_LOCALE_SUPPORT 66 /* Standard hwclock uses locale-specific output format */ 67 char cp[64]; 68 struct tm *ptm = localtime(&t); 69 strftime(cp, sizeof(cp), "%c", ptm); 70 #else 71 char *cp = ctime(&t); 68 72 strchrnul(cp, '\n')[0] = '\0'; 73 #endif 74 69 75 #if !SHOW_HWCLOCK_DIFF 70 76 printf("%s 0.000000 seconds\n", cp); … … 73 79 long diff = sys_tv.tv_sec - t; 74 80 if (diff < 0 /*&& tv.tv_usec != 0*/) { 75 /* Why ? */76 /* diff >= 0 is ok: 77 /* 45.520820 78 /* - 44.000000 79 /* = 1.520820 81 /* Why we need diff++? */ 82 /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */ 83 /* 45.520820 | 43.520820 */ 84 /* - 44.000000 | - 45.000000 */ 85 /* = 1.520820 | = -1.479180, not -2.520820! */ 80 86 diff++; 81 /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */87 /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ 82 88 sys_tv.tv_usec = 999999 - sys_tv.tv_usec; 83 89 } … … 224 230 } 225 231 232 /* 233 * At system boot, kernel may set system time from RTC, 234 * but it knows nothing about timezones. If RTC is in local time, 235 * then system time is wrong - it is offset by timezone. 236 * This option corrects system time if RTC is in local time, 237 * and (always) sets in-kernel timezone. 238 * 239 * This is an alternate option to --hctosys that does not read the 240 * hardware clock. 241 */ 242 static void set_system_clock_timezone(int utc) 243 { 244 struct timeval tv; 245 struct tm *broken; 246 struct timezone tz; 247 248 gettimeofday(&tv, NULL); 249 broken = localtime(&tv.tv_sec); 250 tz.tz_minuteswest = timezone / 60; 251 if (broken->tm_isdst) 252 tz.tz_minuteswest -= 60; 253 tz.tz_dsttime = 0; 254 gettimeofday(&tv, NULL); 255 if (!utc) 256 tv.tv_sec += tz.tz_minuteswest * 60; 257 if (settimeofday(&tv, &tz)) 258 bb_perror_msg_and_die("settimeofday"); 259 } 260 261 //usage:#define hwclock_trivial_usage 262 //usage: IF_FEATURE_HWCLOCK_LONG_OPTIONS( 263 //usage: "[-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz]" 264 //usage: " [-l|--localtime] [-u|--utc]" 265 //usage: " [-f|--rtc FILE]" 266 //usage: ) 267 //usage: IF_NOT_FEATURE_HWCLOCK_LONG_OPTIONS( 268 //usage: "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]" 269 //usage: ) 270 //usage:#define hwclock_full_usage "\n\n" 271 //usage: "Query and set hardware clock (RTC)\n" 272 //usage: "\n -r Show hardware clock time" 273 //usage: "\n -s Set system time from hardware clock" 274 //usage: "\n -w Set hardware clock from system time" 275 //usage: "\n -t Set in-kernel timezone, correct system time" 276 //usage: "\n if hardware clock is in local time" 277 //usage: "\n -u Assume hardware clock is kept in UTC" 278 //usage: "\n -l Assume hardware clock is kept in local time" 279 //usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)" 280 226 281 #define HWCLOCK_OPT_LOCALTIME 0x01 227 282 #define HWCLOCK_OPT_UTC 0x02 … … 229 284 #define HWCLOCK_OPT_HCTOSYS 0x08 230 285 #define HWCLOCK_OPT_SYSTOHC 0x10 231 #define HWCLOCK_OPT_RTCFILE 0x20 286 #define HWCLOCK_OPT_SYSTZ 0x20 287 #define HWCLOCK_OPT_RTCFILE 0x40 232 288 233 289 int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 240 296 #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS 241 297 static const char hwclock_longopts[] ALIGN1 = 242 "localtime\0" No_argument "l" 298 "localtime\0" No_argument "l" /* short opt is non-standard */ 243 299 "utc\0" No_argument "u" 244 300 "show\0" No_argument "r" 245 301 "hctosys\0" No_argument "s" 246 302 "systohc\0" No_argument "w" 247 "file\0" Required_argument "f" 303 "systz\0" No_argument "t" /* short opt is non-standard */ 304 "rtc\0" Required_argument "f" 248 305 ; 249 306 applet_long_options = hwclock_longopts; 250 307 #endif 251 opt_complementary = "r--ws :w--rs:s--wr:l--u:u--l";252 opt = getopt32(argv, "lursw f:", &rtcname);308 opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l"; 309 opt = getopt32(argv, "lurswtf:", &rtcname); 253 310 254 311 /* If -u or -l wasn't given check if we are using utc */ … … 262 319 else if (opt & HWCLOCK_OPT_SYSTOHC) 263 320 from_sys_clock(&rtcname, utc); 321 else if (opt & HWCLOCK_OPT_SYSTZ) 322 set_system_clock_timezone(utc); 264 323 else 265 324 /* default HWCLOCK_OPT_SHOW */ -
branches/3.2/mindi-busybox/util-linux/ipcrm.c
r2725 r3232 8 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define ipcrm_trivial_usage 12 //usage: "[-MQS key] [-mqs id]" 13 //usage:#define ipcrm_full_usage "\n\n" 14 //usage: "Upper-case options MQS remove an object by shmkey value.\n" 15 //usage: "Lower-case options remove an object by shmid value.\n" 16 //usage: "\n -mM Remove memory segment after last detach" 17 //usage: "\n -qQ Remove message queue" 18 //usage: "\n -sS Remove semaphore" 10 19 11 20 #include "libbb.h" … … 152 161 /* convert key to id */ 153 162 id = ((c == 'q') ? msgget(key, 0) : 154 163 (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0)); 155 164 156 165 if (id < 0) { … … 181 190 182 191 result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : 183 184 192 (c == 'm') ? shmctl(id, IPC_RMID, NULL) : 193 semctl(id, 0, IPC_RMID, arg)); 185 194 186 195 if (result) { -
branches/3.2/mindi-busybox/util-linux/ipcs.c
r2725 r3232 9 9 */ 10 10 11 //usage:#define ipcs_trivial_usage 12 //usage: "[[-smq] -i shmid] | [[-asmq] [-tcplu]]" 13 //usage:#define ipcs_full_usage "\n\n" 14 //usage: " -i Show specific resource" 15 //usage: "\nResource specification:" 16 //usage: "\n -m Shared memory segments" 17 //usage: "\n -q Message queues" 18 //usage: "\n -s Semaphore arrays" 19 //usage: "\n -a All (default)" 20 //usage: "\nOutput format:" 21 //usage: "\n -t Time" 22 //usage: "\n -c Creator" 23 //usage: "\n -p Pid" 24 //usage: "\n -l Limits" 25 //usage: "\n -u Summary" 26 11 27 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */ 12 28 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */ … … 40 56 struct shm_info { 41 57 int used_ids; 42 u long shm_tot; /* total allocated shm */43 u long shm_rss; /* total resident shm */44 u long shm_swp; /* total swapped shm */45 u long swap_attempts;46 u long swap_successes;58 unsigned long shm_tot; /* total allocated shm */ 59 unsigned long shm_rss; /* total resident shm */ 60 unsigned long shm_swp; /* total swapped shm */ 61 unsigned long swap_attempts; 62 unsigned long swap_successes; 47 63 }; 48 64 #endif … … 137 153 return; 138 154 /* glibc 2.1.3 and all earlier libc's have ints as fields 139 155 * of struct shminfo; glibc 2.1.91 has unsigned long; ach */ 140 156 printf("max number of segments = %lu\n" 141 142 143 144 145 146 147 157 "max seg size (kbytes) = %lu\n" 158 "max total shared memory (pages) = %lu\n" 159 "min seg size (bytes) = %lu\n", 160 (unsigned long) shminfo.shmmni, 161 (unsigned long) (shminfo.shmmax >> 10), 162 (unsigned long) shminfo.shmall, 163 (unsigned long) shminfo.shmmin); 148 164 return; 149 165 150 166 case STATUS: 151 167 printf("------ Shared Memory %s --------\n", "Status"); 152 printf( 153 154 155 156 157 158 159 160 161 168 printf("segments allocated %d\n" 169 "pages allocated %ld\n" 170 "pages resident %ld\n" 171 "pages swapped %ld\n" 172 "Swap performance: %ld attempts\t%ld successes\n", 173 shm_info.used_ids, 174 shm_info.shm_tot, 175 shm_info.shm_rss, 176 shm_info.shm_swp, 177 shm_info.swap_attempts, shm_info.swap_successes); 162 178 return; 163 179 164 180 case CREATOR: 165 181 printf("------ Shared Memory %s --------\n", "Segment Creators/Owners"); 166 printf( 167 182 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 183 "shmid", "perms", "cuid", "cgid", "uid", "gid"); 168 184 break; 169 185 170 186 case TIME: 171 187 printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times"); 172 printf( 173 188 printf("%-10s %-10s %-20s %-20s %-20s\n", 189 "shmid", "owner", "attached", "detached", "changed"); 174 190 break; 175 191 176 192 case PID: 177 193 printf("------ Shared Memory %s --------\n", "Creator/Last-op"); 178 printf( 179 194 printf("%-10s %-10s %-10s %-10s\n", 195 "shmid", "owner", "cpid", "lpid"); 180 196 break; 181 197 182 198 default: 183 199 printf("------ Shared Memory %s --------\n", "Segments"); 184 printf( 185 186 200 printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", 201 "key", "shmid", "owner", "perms", "bytes", "nattch", 202 "status"); 187 203 break; 188 204 } … … 205 221 /* ctime uses static buffer: use separate calls */ 206 222 printf(" %-20.16s", shmseg.shm_atime 207 223 ? ctime(&shmseg.shm_atime) + 4 : "Not set"); 208 224 printf(" %-20.16s", shmseg.shm_dtime 209 225 ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); 210 226 printf(" %-20.16s\n", shmseg.shm_ctime 211 227 ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); 212 228 break; 213 229 case PID: … … 226 242 printf("%-10d %-10d", shmid, ipcp->uid); 227 243 printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, 228 229 230 231 232 233 234 235 236 237 238 244 /* 245 * earlier: int, Austin has size_t 246 */ 247 (unsigned long) shmseg.shm_segsz, 248 /* 249 * glibc-2.1.3 and earlier has unsigned short; 250 * Austin has shmatt_t 251 */ 252 (long) shmseg.shm_nattch, 253 ipcp->mode & SHM_DEST ? "dest" : " ", 254 ipcp->mode & SHM_LOCKED ? "locked" : " "); 239 255 break; 240 256 } … … 252 268 union semun arg; 253 269 254 arg.array = (u short *) (void *) &seminfo;270 arg.array = (unsigned short *) (void *) &seminfo; 255 271 maxid = semctl(0, 0, SEM_INFO, arg); 256 272 if (maxid < 0) { … … 262 278 case LIMITS: 263 279 printf("------ Semaphore %s --------\n", "Limits"); 264 arg.array = (u short *) (void *) &seminfo; /* damn union */280 arg.array = (unsigned short *) (void *) &seminfo; /* damn union */ 265 281 if ((semctl(0, 0, IPC_INFO, arg)) < 0) 266 282 return; 267 283 printf("max number of arrays = %d\n" 268 269 270 271 272 273 274 284 "max semaphores per array = %d\n" 285 "max semaphores system wide = %d\n" 286 "max ops per semop call = %d\n" 287 "semaphore max value = %d\n", 288 seminfo.semmni, 289 seminfo.semmsl, 290 seminfo.semmns, seminfo.semopm, seminfo.semvmx); 275 291 return; 276 292 277 293 case STATUS: 278 294 printf("------ Semaphore %s --------\n", "Status"); 279 printf( 280 281 295 printf("used arrays = %d\n" 296 "allocated semaphores = %d\n", 297 seminfo.semusz, seminfo.semaem); 282 298 return; 283 299 284 300 case CREATOR: 285 301 printf("------ Semaphore %s --------\n", "Arrays Creators/Owners"); 286 printf( 287 302 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 303 "semid", "perms", "cuid", "cgid", "uid", "gid"); 288 304 break; 289 305 290 306 case TIME: 291 307 printf("------ Shared Memory %s --------\n", "Operation/Change Times"); 292 printf( 293 308 printf("%-8s %-10s %-26.24s %-26.24s\n", 309 "shmid", "owner", "last-op", "last-changed"); 294 310 break; 295 311 … … 299 315 default: 300 316 printf("------ Semaphore %s --------\n", "Arrays"); 301 printf( 302 317 printf("%-10s %-10s %-10s %-10s %-10s\n", 318 "key", "semid", "owner", "perms", "nsems"); 303 319 break; 304 320 } … … 322 338 /* ctime uses static buffer: use separate calls */ 323 339 printf(" %-26.24s", semary.sem_otime 324 340 ? ctime(&semary.sem_otime) : "Not set"); 325 341 printf(" %-26.24s\n", semary.sem_ctime 326 342 ? ctime(&semary.sem_ctime) : "Not set"); 327 343 break; 328 344 case PID: … … 336 352 printf("%-10d %-9d", semid, ipcp->uid); 337 353 printf(" %-10o %-10ld\n", ipcp->mode & 0777, 338 339 340 341 342 343 344 354 /* 355 * glibc-2.1.3 and earlier has unsigned short; 356 * glibc-2.1.91 has variation between 357 * unsigned short and unsigned long 358 * Austin prescribes unsigned short. 359 */ 360 (long) semary.sem_nsems); 345 361 break; 346 362 } … … 368 384 return; 369 385 printf("------ Message%s --------\n", "s: Limits"); 370 printf( 371 372 373 386 printf("max queues system wide = %d\n" 387 "max size of message (bytes) = %d\n" 388 "default max size of queue (bytes) = %d\n", 389 msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); 374 390 return; 375 391 376 392 case STATUS: 377 393 printf("------ Message%s --------\n", "s: Status"); 378 printf( 379 380 381 394 printf("allocated queues = %d\n" 395 "used headers = %d\n" 396 "used space = %d bytes\n", 397 msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); 382 398 return; 383 399 384 400 case CREATOR: 385 401 printf("------ Message%s --------\n", " Queues: Creators/Owners"); 386 printf( 387 402 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 403 "msqid", "perms", "cuid", "cgid", "uid", "gid"); 388 404 break; 389 405 390 406 case TIME: 391 407 printf("------ Message%s --------\n", " Queues Send/Recv/Change Times"); 392 printf( 393 408 printf("%-8s %-10s %-20s %-20s %-20s\n", 409 "msqid", "owner", "send", "recv", "change"); 394 410 break; 395 411 396 412 case PID: 397 413 printf("------ Message%s --------\n", " Queues PIDs"); 398 printf( 399 414 printf("%-10s %-10s %-10s %-10s\n", 415 "msqid", "owner", "lspid", "lrpid"); 400 416 break; 401 417 402 418 default: 403 419 printf("------ Message%s --------\n", " Queues"); 404 printf( 405 420 printf("%-10s %-10s %-10s %-10s %-12s %-12s\n", 421 "key", "msqid", "owner", "perms", "used-bytes", "messages"); 406 422 break; 407 423 } … … 423 439 printf("%-8d %-10d", msqid, ipcp->uid); 424 440 printf(" %-20.16s", msgque.msg_stime 425 441 ? ctime(&msgque.msg_stime) + 4 : "Not set"); 426 442 printf(" %-20.16s", msgque.msg_rtime 427 443 ? ctime(&msgque.msg_rtime) + 4 : "Not set"); 428 444 printf(" %-20.16s\n", msgque.msg_ctime 429 445 ? ctime(&msgque.msg_ctime) + 4 : "Not set"); 430 446 break; 431 447 case PID: … … 444 460 printf("%-10d %-10d", msqid, ipcp->uid); 445 461 printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, 446 447 448 449 450 451 452 462 /* 463 * glibc-2.1.3 and earlier has unsigned short; 464 * glibc-2.1.91 has variation between 465 * unsigned short, unsigned long 466 * Austin has msgqnum_t 467 */ 468 (long) msgque.msg_cbytes, (long) msgque.msg_qnum); 453 469 break; 454 470 } … … 468 484 469 485 printf("\nShared memory Segment shmid=%d\n" 470 471 472 473 474 475 476 477 486 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" 487 "mode=%#o\taccess_perms=%#o\n" 488 "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", 489 shmid, 490 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 491 ipcp->mode, ipcp->mode & 0777, 492 (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, 493 (long) shmds.shm_nattch); 478 494 printf("att_time=%-26.24s\n", 479 495 shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set"); 480 496 printf("det_time=%-26.24s\n", 481 497 shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set"); 482 498 printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime)); 483 499 } … … 495 511 496 512 printf("\nMessage Queue msqid=%d\n" 497 498 499 500 501 502 503 504 505 506 507 513 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" 514 "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", 515 msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, 516 /* 517 * glibc-2.1.3 and earlier has unsigned short; 518 * glibc-2.1.91 has variation between 519 * unsigned short, unsigned long 520 * Austin has msgqnum_t (for msg_qbytes) 521 */ 522 (long) buf.msg_cbytes, (long) buf.msg_qbytes, 523 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); 508 524 509 525 printf("send_time=%-26.24s\n", 510 526 buf.msg_stime ? ctime(&buf.msg_stime) : "Not set"); 511 527 printf("rcv_time=%-26.24s\n", 512 528 buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set"); 513 529 printf("change_time=%-26.24s\n\n", 514 530 buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set"); 515 531 } 516 532 … … 529 545 530 546 printf("\nSemaphore Array semid=%d\n" 531 532 533 534 535 536 537 538 539 547 "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" 548 "mode=%#o, access_perms=%#o\n" 549 "nsems = %ld\n" 550 "otime = %-26.24s\n", 551 semid, 552 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 553 ipcp->mode, ipcp->mode & 0777, 554 (long) semds.sem_nsems, 555 semds.sem_otime ? ctime(&semds.sem_otime) : "Not set"); 540 556 printf("ctime = %-26.24s\n" 541 542 543 557 "%-10s %-10s %-10s %-10s %-10s\n", 558 ctime(&semds.sem_ctime), 559 "semnum", "value", "ncount", "zcount", "pid"); 544 560 545 561 arg.val = 0; -
branches/3.2/mindi-busybox/util-linux/losetup.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define losetup_trivial_usage 11 //usage: "[-r] [-o OFS] LOOPDEV FILE - associate loop devices\n" 12 //usage: " losetup -d LOOPDEV - disassociate\n" 13 //usage: " losetup [-f] - show" 14 //usage:#define losetup_full_usage "\n\n" 15 //usage: " -o OFS Start OFS bytes into FILE" 16 //usage: "\n -r Read-only" 17 //usage: "\n -f Show first free loop device" 18 //usage: 19 //usage:#define losetup_notes_usage 20 //usage: "No arguments will display all current associations.\n" 21 //usage: "One argument (losetup /dev/loop1) will display the current association\n" 22 //usage: "(if any), or disassociate it (with -d). The display shows the offset\n" 23 //usage: "and filename of the file the loop device is currently bound to.\n\n" 24 //usage: "Two arguments (losetup /dev/loop1 file.img) create a new association,\n" 25 //usage: "with an optional offset (-o 12345). Encryption is not yet supported.\n" 26 //usage: "losetup -f will show the first loop free loop device\n\n" 9 27 10 28 #include "libbb.h" … … 21 39 OPT_o = (1 << 1), 22 40 OPT_f = (1 << 2), 41 OPT_r = (1 << 3), /* must be last */ 23 42 }; 24 43 25 /* max 2 args, allopts are mutually exclusive */44 /* max 2 args, -d,-o,-f opts are mutually exclusive */ 26 45 opt_complementary = "?2:d--of:o--df:f--do"; 27 opt = getopt32(argv, "do:f ", &opt_o);46 opt = getopt32(argv, "do:fr", &opt_o); 28 47 argv += optind; 29 48 … … 47 66 48 67 if (argv[1]) { 49 /* [- o OFS] BLOCKDEV FILE */50 if (set_loop(&argv[0], argv[1], offset ) < 0)68 /* [-r] [-o OFS] BLOCKDEV FILE */ 69 if (set_loop(&argv[0], argv[1], offset, (opt / OPT_r)) < 0) 51 70 bb_simple_perror_msg_and_die(argv[0]); 52 71 return EXIT_SUCCESS; 53 72 } 54 /* [- o OFS] BLOCKDEV */73 /* [-r] [-o OFS] BLOCKDEV */ 55 74 s = query_loop(argv[0]); 56 75 if (!s) … … 62 81 } 63 82 64 /* [- o OFS|-f] with no params */83 /* [-r] [-o OFS|-f] with no params */ 65 84 n = 0; 66 85 while (1) { -
branches/3.2/mindi-busybox/util-linux/lspci.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define lspci_trivial_usage 11 //usage: "[-mk]" 12 //usage:#define lspci_full_usage "\n\n" 13 //usage: "List all PCI devices" 14 //usage: "\n" 15 //usage: "\n -m Parsable output" 16 //usage: "\n -k Show driver" 17 9 18 #include "libbb.h" 10 19 … … 66 75 if (option_mask32 & OPT_m) { 67 76 printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"", 68 69 77 pci_slot_name, pci_class, pci_vid, pci_did, 78 pci_subsys_vid, pci_subsys_did); 70 79 } else { 71 80 printf("%s Class %04x: %04x:%04x", 72 81 pci_slot_name, pci_class, pci_vid, pci_did); 73 82 } 74 83 -
branches/3.2/mindi-busybox/util-linux/lsusb.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define lsusb_trivial_usage NOUSAGE_STR 11 //usage:#define lsusb_full_usage "" 12 9 13 #include "libbb.h" 10 14 -
branches/3.2/mindi-busybox/util-linux/mdev.c
r2725 r3232 8 8 * Licensed under GPLv2, see file LICENSE in this source tree. 9 9 */ 10 11 //config:config MDEV 12 //config: bool "mdev" 13 //config: default y 14 //config: select PLATFORM_LINUX 15 //config: help 16 //config: mdev is a mini-udev implementation for dynamically creating device 17 //config: nodes in the /dev directory. 18 //config: 19 //config: For more information, please see docs/mdev.txt 20 //config: 21 //config:config FEATURE_MDEV_CONF 22 //config: bool "Support /etc/mdev.conf" 23 //config: default y 24 //config: depends on MDEV 25 //config: help 26 //config: Add support for the mdev config file to control ownership and 27 //config: permissions of the device nodes. 28 //config: 29 //config: For more information, please see docs/mdev.txt 30 //config: 31 //config:config FEATURE_MDEV_RENAME 32 //config: bool "Support subdirs/symlinks" 33 //config: default y 34 //config: depends on FEATURE_MDEV_CONF 35 //config: help 36 //config: Add support for renaming devices and creating symlinks. 37 //config: 38 //config: For more information, please see docs/mdev.txt 39 //config: 40 //config:config FEATURE_MDEV_RENAME_REGEXP 41 //config: bool "Support regular expressions substitutions when renaming device" 42 //config: default y 43 //config: depends on FEATURE_MDEV_RENAME 44 //config: help 45 //config: Add support for regular expressions substitutions when renaming 46 //config: device. 47 //config: 48 //config:config FEATURE_MDEV_EXEC 49 //config: bool "Support command execution at device addition/removal" 50 //config: default y 51 //config: depends on FEATURE_MDEV_CONF 52 //config: help 53 //config: This adds support for an optional field to /etc/mdev.conf for 54 //config: executing commands when devices are created/removed. 55 //config: 56 //config: For more information, please see docs/mdev.txt 57 //config: 58 //config:config FEATURE_MDEV_LOAD_FIRMWARE 59 //config: bool "Support loading of firmwares" 60 //config: default y 61 //config: depends on MDEV 62 //config: help 63 //config: Some devices need to load firmware before they can be usable. 64 //config: 65 //config: These devices will request userspace look up the files in 66 //config: /lib/firmware/ and if it exists, send it to the kernel for 67 //config: loading into the hardware. 68 69 //applet:IF_MDEV(APPLET(mdev, BB_DIR_SBIN, BB_SUID_DROP)) 70 71 //kbuild:lib-$(CONFIG_MDEV) += mdev.o 72 73 //usage:#define mdev_trivial_usage 74 //usage: "[-s]" 75 //usage:#define mdev_full_usage "\n\n" 76 //usage: "mdev -s is to be run during boot to scan /sys and populate /dev.\n" 77 //usage: "\n" 78 //usage: "Bare mdev is a kernel hotplug helper. To activate it:\n" 79 //usage: " echo /sbin/mdev >/proc/sys/kernel/hotplug\n" 80 //usage: IF_FEATURE_MDEV_CONF( 81 //usage: "\n" 82 //usage: "It uses /etc/mdev.conf with lines\n" 83 //usage: " [-][ENV=regex;]...DEVNAME UID:GID PERM" 84 //usage: IF_FEATURE_MDEV_RENAME(" [>|=PATH]|[!]") 85 //usage: IF_FEATURE_MDEV_EXEC(" [@|$|*PROG]") 86 //usage: "\n" 87 //usage: "where DEVNAME is device name regex, @major,minor[-minor2], or\n" 88 //usage: "environment variable regex. A common use of the latter is\n" 89 //usage: "to load modules for hotplugged devices:\n" 90 //usage: " $MODALIAS=.* 0:0 660 @modprobe \"$MODALIAS\"\n" 91 //usage: ) 92 //usage: "\n" 93 //usage: "If /dev/mdev.seq file exists, mdev will wait for its value\n" 94 //usage: "to match $SEQNUM variable. This prevents plug/unplug races.\n" 95 //usage: "To activate this feature, create empty /dev/mdev.seq at boot.\n" 96 //usage: "\n" 97 //usage: "If /dev/mdev.log file exists, debug log will be appended to it." 98 10 99 #include "libbb.h" 11 100 #include "xregex.h" … … 28 117 * 29 118 * If /etc/mdev.conf exists, it may modify /dev/device_name's properties. 30 * /etc/mdev.conf file format:31 *32 * [-][subsystem/]device user:grp mode [>|=path] [@|$|*command args...]33 * [-]@maj,min[-min2] user:grp mode [>|=path] [@|$|*command args...]34 * [-]$envvar=val user:grp mode [>|=path] [@|$|*command args...]35 119 * 36 120 * Leading minus in 1st field means "don't stop on this line", otherwise 37 121 * search is stopped after the matching line is encountered. 38 122 * 39 * The device name or "subsystem/device" combo is matched against 1st field 40 * (which is a regex), or maj,min is matched against 1st field, 41 * or specified environment variable (as regex) is matched against 1st field. 42 * 43 * $envvar=val format is useful for loading modules for hot-plugged devices 123 * $envvar=regex format is useful for loading modules for hot-plugged devices 44 124 * which do not have driver loaded yet. In this case /sys/class/.../dev 45 125 * does not exist, but $MODALIAS is set to needed module's name … … 62 142 */ 63 143 144 /* Kernel's hotplug environment constantly changes. 145 * Here are new cases I observed on 3.1.0: 146 * 147 * Case with $DEVNAME and $DEVICE, not just $DEVPATH: 148 * ACTION=add 149 * BUSNUM=001 150 * DEVICE=/proc/bus/usb/001/003 151 * DEVNAME=bus/usb/001/003 152 * DEVNUM=003 153 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5 154 * DEVTYPE=usb_device 155 * MAJOR=189 156 * MINOR=2 157 * PRODUCT=18d1/4e12/227 158 * SUBSYSTEM=usb 159 * TYPE=0/0/0 160 * 161 * Case with $DEVICE, but no $DEVNAME - apparenty, usb iface notification? 162 * "Please load me a module" thing? 163 * ACTION=add 164 * DEVICE=/proc/bus/usb/001/003 165 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0 166 * DEVTYPE=usb_interface 167 * INTERFACE=8/6/80 168 * MODALIAS=usb:v18D1p4E12d0227dc00dsc00dp00ic08isc06ip50 169 * PRODUCT=18d1/4e12/227 170 * SUBSYSTEM=usb 171 * TYPE=0/0/0 172 * 173 * ACTION=add 174 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5 175 * DEVTYPE=scsi_host 176 * SUBSYSTEM=scsi 177 * 178 * ACTION=add 179 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/scsi_host/host5 180 * SUBSYSTEM=scsi_host 181 * 182 * ACTION=add 183 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0 184 * DEVTYPE=scsi_target 185 * SUBSYSTEM=scsi 186 * 187 * Case with strange $MODALIAS: 188 * ACTION=add 189 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0 190 * DEVTYPE=scsi_device 191 * MODALIAS=scsi:t-0x00 192 * SUBSYSTEM=scsi 193 * 194 * ACTION=add 195 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0 196 * SUBSYSTEM=scsi_disk 197 * 198 * ACTION=add 199 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_device/5:0:0:0 200 * SUBSYSTEM=scsi_device 201 * 202 * Case with explicit $MAJOR/$MINOR (no need to read /sys/$DEVPATH/dev?): 203 * ACTION=add 204 * DEVNAME=bsg/5:0:0:0 205 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/bsg/5:0:0:0 206 * MAJOR=253 207 * MINOR=1 208 * SUBSYSTEM=bsg 209 * 210 * ACTION=add 211 * DEVPATH=/devices/virtual/bdi/8:16 212 * SUBSYSTEM=bdi 213 * 214 * ACTION=add 215 * DEVNAME=sdb 216 * DEVPATH=/block/sdb 217 * DEVTYPE=disk 218 * MAJOR=8 219 * MINOR=16 220 * SUBSYSTEM=block 221 * 222 * Case with ACTION=change: 223 * ACTION=change 224 * DEVNAME=sdb 225 * DEVPATH=/block/sdb 226 * DEVTYPE=disk 227 * DISK_MEDIA_CHANGE=1 228 * MAJOR=8 229 * MINOR=16 230 * SUBSYSTEM=block 231 */ 232 233 #define DEBUG_LVL 2 234 235 #if DEBUG_LVL >= 1 236 # define dbg1(...) do { if (G.verbose) bb_error_msg(__VA_ARGS__); } while(0) 237 #else 238 # define dbg1(...) ((void)0) 239 #endif 240 #if DEBUG_LVL >= 2 241 # define dbg2(...) do { if (G.verbose >= 2) bb_error_msg(__VA_ARGS__); } while(0) 242 #else 243 # define dbg2(...) ((void)0) 244 #endif 245 #if DEBUG_LVL >= 3 246 # define dbg3(...) do { if (G.verbose >= 3) bb_error_msg(__VA_ARGS__); } while(0) 247 #else 248 # define dbg3(...) ((void)0) 249 #endif 250 251 252 static const char keywords[] ALIGN1 = "add\0remove\0"; // "change\0" 253 enum { OP_add, OP_remove }; 254 255 struct envmatch { 256 struct envmatch *next; 257 char *envname; 258 regex_t match; 259 }; 260 261 struct rule { 262 bool keep_matching; 263 bool regex_compiled; 264 mode_t mode; 265 int maj, min0, min1; 266 struct bb_uidgid_t ugid; 267 char *envvar; 268 char *ren_mov; 269 IF_FEATURE_MDEV_EXEC(char *r_cmd;) 270 regex_t match; 271 struct envmatch *envmatch; 272 }; 273 64 274 struct globals { 65 275 int root_major, root_minor; 276 smallint verbose; 66 277 char *subsystem; 278 char *subsys_env; /* for putenv("SUBSYSTEM=subsystem") */ 279 #if ENABLE_FEATURE_MDEV_CONF 280 const char *filename; 281 parser_t *parser; 282 struct rule **rule_vec; 283 unsigned rule_idx; 284 #endif 285 struct rule cur_rule; 286 char timestr[sizeof("60.123456")]; 67 287 } FIX_ALIASING; 68 288 #define G (*(struct globals*)&bb_common_bufsiz1) 289 #define INIT_G() do { \ 290 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \ 291 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \ 292 } while (0) 293 69 294 70 295 /* Prevent infinite loops in /sys symlinks */ 71 296 #define MAX_SYSFS_DEPTH 3 72 297 73 /* We use additional 64+ bytes in make_device() */ 74 #define SCRATCH_SIZE 80 298 /* We use additional bytes in make_device() */ 299 #define SCRATCH_SIZE 128 300 301 #if ENABLE_FEATURE_MDEV_CONF 302 303 static void make_default_cur_rule(void) 304 { 305 memset(&G.cur_rule, 0, sizeof(G.cur_rule)); 306 G.cur_rule.maj = -1; /* "not a @major,minor rule" */ 307 G.cur_rule.mode = 0660; 308 } 309 310 static void clean_up_cur_rule(void) 311 { 312 struct envmatch *e; 313 314 free(G.cur_rule.envvar); 315 free(G.cur_rule.ren_mov); 316 if (G.cur_rule.regex_compiled) 317 regfree(&G.cur_rule.match); 318 IF_FEATURE_MDEV_EXEC(free(G.cur_rule.r_cmd);) 319 e = G.cur_rule.envmatch; 320 while (e) { 321 free(e->envname); 322 regfree(&e->match); 323 e = e->next; 324 } 325 make_default_cur_rule(); 326 } 327 328 /* In later versions, endofname is in libbb */ 329 #define endofname mdev_endofname 330 static 331 const char* FAST_FUNC 332 endofname(const char *name) 333 { 334 #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) 335 #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) 336 if (!is_name(*name)) 337 return name; 338 while (*++name) { 339 if (!is_in_name(*name)) 340 break; 341 } 342 return name; 343 } 344 345 static char *parse_envmatch_pfx(char *val) 346 { 347 struct envmatch **nextp = &G.cur_rule.envmatch; 348 349 for (;;) { 350 struct envmatch *e; 351 char *semicolon; 352 char *eq = strchr(val, '='); 353 if (!eq /* || eq == val? */) 354 return val; 355 if (endofname(val) != eq) 356 return val; 357 semicolon = strchr(eq, ';'); 358 if (!semicolon) 359 return val; 360 /* ENVVAR=regex;... */ 361 *nextp = e = xzalloc(sizeof(*e)); 362 nextp = &e->next; 363 e->envname = xstrndup(val, eq - val); 364 *semicolon = '\0'; 365 xregcomp(&e->match, eq + 1, REG_EXTENDED); 366 *semicolon = ';'; 367 val = semicolon + 1; 368 } 369 } 370 371 static void parse_next_rule(void) 372 { 373 /* Note: on entry, G.cur_rule is set to default */ 374 while (1) { 375 char *tokens[4]; 376 char *val; 377 378 /* No PARSE_EOL_COMMENTS, because command may contain '#' chars */ 379 if (!config_read(G.parser, tokens, 4, 3, "# \t", PARSE_NORMAL & ~PARSE_EOL_COMMENTS)) 380 break; 381 382 /* Fields: [-]regex uid:gid mode [alias] [cmd] */ 383 dbg3("token1:'%s'", tokens[1]); 384 385 /* 1st field */ 386 val = tokens[0]; 387 G.cur_rule.keep_matching = ('-' == val[0]); 388 val += G.cur_rule.keep_matching; /* swallow leading dash */ 389 val = parse_envmatch_pfx(val); 390 if (val[0] == '@') { 391 /* @major,minor[-minor2] */ 392 /* (useful when name is ambiguous: 393 * "/sys/class/usb/lp0" and 394 * "/sys/class/printer/lp0") 395 */ 396 int sc = sscanf(val, "@%u,%u-%u", &G.cur_rule.maj, &G.cur_rule.min0, &G.cur_rule.min1); 397 if (sc < 2 || G.cur_rule.maj < 0) { 398 bb_error_msg("bad @maj,min on line %d", G.parser->lineno); 399 goto next_rule; 400 } 401 if (sc == 2) 402 G.cur_rule.min1 = G.cur_rule.min0; 403 } else { 404 char *eq = strchr(val, '='); 405 if (val[0] == '$') { 406 /* $ENVVAR=regex ... */ 407 val++; 408 if (!eq) { 409 bb_error_msg("bad $envvar=regex on line %d", G.parser->lineno); 410 goto next_rule; 411 } 412 G.cur_rule.envvar = xstrndup(val, eq - val); 413 val = eq + 1; 414 } 415 xregcomp(&G.cur_rule.match, val, REG_EXTENDED); 416 G.cur_rule.regex_compiled = 1; 417 } 418 419 /* 2nd field: uid:gid - device ownership */ 420 if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) { 421 bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno); 422 goto next_rule; 423 } 424 425 /* 3rd field: mode - device permissions */ 426 bb_parse_mode(tokens[2], &G.cur_rule.mode); 427 428 /* 4th field (opt): ">|=alias" or "!" to not create the node */ 429 val = tokens[3]; 430 if (ENABLE_FEATURE_MDEV_RENAME && val && strchr(">=!", val[0])) { 431 char *s = skip_non_whitespace(val); 432 G.cur_rule.ren_mov = xstrndup(val, s - val); 433 val = skip_whitespace(s); 434 } 435 436 if (ENABLE_FEATURE_MDEV_EXEC && val && val[0]) { 437 const char *s = "$@*"; 438 const char *s2 = strchr(s, val[0]); 439 if (!s2) { 440 bb_error_msg("bad line %u", G.parser->lineno); 441 goto next_rule; 442 } 443 IF_FEATURE_MDEV_EXEC(G.cur_rule.r_cmd = xstrdup(val);) 444 } 445 446 return; 447 next_rule: 448 clean_up_cur_rule(); 449 } /* while (config_read) */ 450 451 dbg3("config_close(G.parser)"); 452 config_close(G.parser); 453 G.parser = NULL; 454 455 return; 456 } 457 458 /* If mdev -s, we remember rules in G.rule_vec[]. 459 * Otherwise, there is no point in doing it, and we just 460 * save only one parsed rule in G.cur_rule. 461 */ 462 static const struct rule *next_rule(void) 463 { 464 struct rule *rule; 465 466 /* Open conf file if we didn't do it yet */ 467 if (!G.parser && G.filename) { 468 dbg3("config_open('%s')", G.filename); 469 G.parser = config_open2(G.filename, fopen_for_read); 470 G.filename = NULL; 471 } 472 473 if (G.rule_vec) { 474 /* mdev -s */ 475 /* Do we have rule parsed already? */ 476 if (G.rule_vec[G.rule_idx]) { 477 dbg3("< G.rule_vec[G.rule_idx:%d]=%p", G.rule_idx, G.rule_vec[G.rule_idx]); 478 return G.rule_vec[G.rule_idx++]; 479 } 480 make_default_cur_rule(); 481 } else { 482 /* not mdev -s */ 483 clean_up_cur_rule(); 484 } 485 486 /* Parse one more rule if file isn't fully read */ 487 rule = &G.cur_rule; 488 if (G.parser) { 489 parse_next_rule(); 490 if (G.rule_vec) { /* mdev -s */ 491 rule = memcpy(xmalloc(sizeof(G.cur_rule)), &G.cur_rule, sizeof(G.cur_rule)); 492 G.rule_vec = xrealloc_vector(G.rule_vec, 4, G.rule_idx); 493 G.rule_vec[G.rule_idx++] = rule; 494 dbg3("> G.rule_vec[G.rule_idx:%d]=%p", G.rule_idx, G.rule_vec[G.rule_idx]); 495 } 496 } 497 498 return rule; 499 } 500 501 static int env_matches(struct envmatch *e) 502 { 503 while (e) { 504 int r; 505 char *val = getenv(e->envname); 506 if (!val) 507 return 0; 508 r = regexec(&e->match, val, /*size*/ 0, /*range[]*/ NULL, /*eflags*/ 0); 509 if (r != 0) /* no match */ 510 return 0; 511 e = e->next; 512 } 513 return 1; 514 } 515 516 #else 517 518 # define next_rule() (&G.cur_rule) 519 520 #endif 521 522 static void mkdir_recursive(char *name) 523 { 524 /* if name has many levels ("dir1/dir2"), 525 * bb_make_directory() will create dir1 according to umask, 526 * not according to its "mode" parameter. 527 * Since we run with umask=0, need to temporarily switch it. 528 */ 529 umask(022); /* "dir1" (if any) will be 0755 too */ 530 bb_make_directory(name, 0755, FILEUTILS_RECUR); 531 umask(0); 532 } 75 533 76 534 /* Builds an alias path. … … 87 545 if (dest) { /* ">bar/[baz]" ? */ 88 546 *dest = '\0'; /* mkdir bar */ 89 bb_make_directory(alias, 0755, FILEUTILS_RECUR);547 mkdir_recursive(alias); 90 548 *dest = '/'; 91 549 if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */ … … 101 559 /* mknod in /dev based on a path like "/sys/block/hda/hda1" 102 560 * NB1: path parameter needs to have SCRATCH_SIZE scratch bytes 103 * after NUL, but we promise to not mangle (IOW: to restore if needed)561 * after NUL, but we promise to not mangle (IOW: to restore NUL if needed) 104 562 * path string. 105 563 * NB2: "mdev -s" may call us many times, do not leak memory/fds! 564 * 565 * device_name = $DEVNAME (may be NULL) 566 * path = /sys/$DEVPATH 106 567 */ 107 static void make_device(char *path, int delete) 108 { 109 char *device_name, *subsystem_slash_devname; 568 static void make_device(char *device_name, char *path, int operation) 569 { 110 570 int major, minor, type, len; 111 mode_t mode; 112 parser_t *parser; 571 char *path_end = path + strlen(path); 113 572 114 573 /* Try to read major/minor string. Note that the kernel puts \n after … … 118 577 */ 119 578 major = -1; 120 if (!delete) { 121 char *dev_maj_min = path + strlen(path); 122 123 strcpy(dev_maj_min, "/dev"); 124 len = open_read_close(path, dev_maj_min + 1, 64); 125 *dev_maj_min = '\0'; 579 if (operation == OP_add) { 580 strcpy(path_end, "/dev"); 581 len = open_read_close(path, path_end + 1, SCRATCH_SIZE - 1); 582 *path_end = '\0'; 126 583 if (len < 1) { 127 584 if (!ENABLE_FEATURE_MDEV_EXEC) … … 129 586 /* no "dev" file, but we can still run scripts 130 587 * based on device name */ 131 } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) != 2) { 588 } else if (sscanf(path_end + 1, "%u:%u", &major, &minor) == 2) { 589 dbg1("dev %u,%u", major, minor); 590 } else { 132 591 major = -1; 133 592 } … … 135 594 /* else: for delete, -1 still deletes the node, but < -1 suppresses that */ 136 595 137 /* Determine device name, type, major and minor */ 138 device_name = (char*) bb_basename(path); 139 /* http://kernel.org/doc/pending/hotplug.txt says that only 596 /* Determine device name */ 597 if (!device_name) { 598 /* 599 * There was no $DEVNAME envvar (for example, mdev -s never has). 600 * But it is very useful: it contains the *path*, not only basename, 601 * Thankfully, uevent file has it. 602 * Example of .../sound/card0/controlC0/uevent file on Linux-3.7.7: 603 * MAJOR=116 604 * MINOR=7 605 * DEVNAME=snd/controlC0 606 */ 607 strcpy(path_end, "/uevent"); 608 len = open_read_close(path, path_end + 1, SCRATCH_SIZE - 1); 609 if (len < 0) 610 len = 0; 611 *path_end = '\0'; 612 path_end[1 + len] = '\0'; 613 device_name = strstr(path_end + 1, "\nDEVNAME="); 614 if (device_name) { 615 device_name += sizeof("\nDEVNAME=")-1; 616 strchrnul(device_name, '\n')[0] = '\0'; 617 } else { 618 /* Fall back to just basename */ 619 device_name = (char*) bb_basename(path); 620 } 621 } 622 /* Determine device type */ 623 /* 624 * http://kernel.org/doc/pending/hotplug.txt says that only 140 625 * "/sys/block/..." is for block devices. "/sys/bus" etc is not. 141 626 * But since 2.6.25 block devices are also in /sys/class/block. 142 * We use strstr("/block/") to forestall future surprises. */ 627 * We use strstr("/block/") to forestall future surprises. 628 */ 143 629 type = S_IFCHR; 144 630 if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) 145 631 type = S_IFBLK; 146 632 147 /* Make path point to "subsystem/device_name" */ 148 subsystem_slash_devname = NULL; 149 /* Check for coldplug invocations first */ 150 if (strncmp(path, "/sys/block/", 11) == 0) /* legacy case */ 151 path += sizeof("/sys/") - 1; 152 else if (strncmp(path, "/sys/class/", 11) == 0) 153 path += sizeof("/sys/class/") - 1; 154 else { 155 /* Example of a hotplug invocation: 156 * SUBSYSTEM="block" 157 * DEVPATH="/sys" + "/devices/virtual/mtd/mtd3/mtdblock3" 158 * ("/sys" is added by mdev_main) 159 * - path does not contain subsystem 633 #if ENABLE_FEATURE_MDEV_CONF 634 G.rule_idx = 0; /* restart from the beginning (think mdev -s) */ 635 #endif 636 for (;;) { 637 const char *str_to_match; 638 regmatch_t off[1 + 9 * ENABLE_FEATURE_MDEV_RENAME_REGEXP]; 639 char *command; 640 char *alias; 641 char aliaslink = aliaslink; /* for compiler */ 642 char *node_name; 643 const struct rule *rule; 644 645 str_to_match = device_name; 646 647 rule = next_rule(); 648 649 #if ENABLE_FEATURE_MDEV_CONF 650 if (!env_matches(rule->envmatch)) 651 continue; 652 if (rule->maj >= 0) { /* @maj,min rule */ 653 if (major != rule->maj) 654 continue; 655 if (minor < rule->min0 || minor > rule->min1) 656 continue; 657 memset(off, 0, sizeof(off)); 658 goto rule_matches; 659 } 660 if (rule->envvar) { /* $envvar=regex rule */ 661 str_to_match = getenv(rule->envvar); 662 dbg3("getenv('%s'):'%s'", rule->envvar, str_to_match); 663 if (!str_to_match) 664 continue; 665 } 666 /* else: str_to_match = device_name */ 667 668 if (rule->regex_compiled) { 669 int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0); 670 dbg3("regex_match for '%s':%d", str_to_match, regex_match); 671 //bb_error_msg("matches:"); 672 //for (int i = 0; i < ARRAY_SIZE(off); i++) { 673 // if (off[i].rm_so < 0) continue; 674 // bb_error_msg("match %d: '%.*s'\n", i, 675 // (int)(off[i].rm_eo - off[i].rm_so), 676 // device_name + off[i].rm_so); 677 //} 678 679 if (regex_match != 0 680 /* regexec returns whole pattern as "range" 0 */ 681 || off[0].rm_so != 0 682 || (int)off[0].rm_eo != (int)strlen(str_to_match) 683 ) { 684 continue; /* this rule doesn't match */ 685 } 686 } 687 /* else: it's final implicit "match-all" rule */ 688 rule_matches: 689 dbg2("rule matched, line %d", G.parser ? G.parser->lineno : -1); 690 #endif 691 /* Build alias name */ 692 alias = NULL; 693 if (ENABLE_FEATURE_MDEV_RENAME && rule->ren_mov) { 694 aliaslink = rule->ren_mov[0]; 695 if (aliaslink == '!') { 696 /* "!": suppress node creation/deletion */ 697 major = -2; 698 } 699 else if (aliaslink == '>' || aliaslink == '=') { 700 if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) { 701 char *s; 702 char *p; 703 unsigned n; 704 705 /* substitute %1..9 with off[1..9], if any */ 706 n = 0; 707 s = rule->ren_mov; 708 while (*s) 709 if (*s++ == '%') 710 n++; 711 712 p = alias = xzalloc(strlen(rule->ren_mov) + n * strlen(str_to_match)); 713 s = rule->ren_mov + 1; 714 while (*s) { 715 *p = *s; 716 if ('%' == *s) { 717 unsigned i = (s[1] - '0'); 718 if (i <= 9 && off[i].rm_so >= 0) { 719 n = off[i].rm_eo - off[i].rm_so; 720 strncpy(p, str_to_match + off[i].rm_so, n); 721 p += n - 1; 722 s++; 723 } 724 } 725 p++; 726 s++; 727 } 728 } else { 729 alias = xstrdup(rule->ren_mov + 1); 730 } 731 } 732 } 733 dbg3("alias:'%s'", alias); 734 735 command = NULL; 736 IF_FEATURE_MDEV_EXEC(command = rule->r_cmd;) 737 if (command) { 738 /* Are we running this command now? 739 * Run @cmd on create, $cmd on delete, *cmd on any 740 */ 741 if ((command[0] == '@' && operation == OP_add) 742 || (command[0] == '$' && operation == OP_remove) 743 || (command[0] == '*') 744 ) { 745 command++; 746 } else { 747 command = NULL; 748 } 749 } 750 dbg3("command:'%s'", command); 751 752 /* "Execute" the line we found */ 753 node_name = device_name; 754 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 755 node_name = alias = build_alias(alias, device_name); 756 dbg3("alias2:'%s'", alias); 757 } 758 759 if (operation == OP_add && major >= 0) { 760 char *slash = strrchr(node_name, '/'); 761 if (slash) { 762 *slash = '\0'; 763 mkdir_recursive(node_name); 764 *slash = '/'; 765 } 766 if (ENABLE_FEATURE_MDEV_CONF) { 767 dbg1("mknod %s (%d,%d) %o" 768 " %u:%u", 769 node_name, major, minor, rule->mode | type, 770 rule->ugid.uid, rule->ugid.gid 771 ); 772 } else { 773 dbg1("mknod %s (%d,%d) %o", 774 node_name, major, minor, rule->mode | type 775 ); 776 } 777 if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) 778 bb_perror_msg("can't create '%s'", node_name); 779 if (ENABLE_FEATURE_MDEV_CONF) { 780 chmod(node_name, rule->mode); 781 chown(node_name, rule->ugid.uid, rule->ugid.gid); 782 } 783 if (major == G.root_major && minor == G.root_minor) 784 symlink(node_name, "root"); 785 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 786 if (aliaslink == '>') { 787 //TODO: on devtmpfs, device_name already exists and symlink() fails. 788 //End result is that instead of symlink, we have two nodes. 789 //What should be done? 790 dbg1("symlink: %s", device_name); 791 symlink(node_name, device_name); 792 } 793 } 794 } 795 796 if (ENABLE_FEATURE_MDEV_EXEC && command) { 797 /* setenv will leak memory, use putenv/unsetenv/free */ 798 char *s = xasprintf("%s=%s", "MDEV", node_name); 799 putenv(s); 800 dbg1("running: %s", command); 801 if (system(command) == -1) 802 bb_perror_msg("can't run '%s'", command); 803 bb_unsetenv_and_free(s); 804 } 805 806 if (operation == OP_remove && major >= -1) { 807 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 808 if (aliaslink == '>') { 809 dbg1("unlink: %s", device_name); 810 unlink(device_name); 811 } 812 } 813 dbg1("unlink: %s", node_name); 814 unlink(node_name); 815 } 816 817 if (ENABLE_FEATURE_MDEV_RENAME) 818 free(alias); 819 820 /* We found matching line. 821 * Stop unless it was prefixed with '-' 160 822 */ 161 subsystem_slash_devname = concat_path_file(G.subsystem, device_name); 162 path = subsystem_slash_devname; 163 } 164 165 /* If we have config file, look up user settings */ 166 if (ENABLE_FEATURE_MDEV_CONF) 167 parser = config_open2("/etc/mdev.conf", fopen_for_read); 168 169 do { 170 int keep_matching; 171 struct bb_uidgid_t ugid; 172 char *tokens[4]; 173 char *command = NULL; 174 char *alias = NULL; 175 char aliaslink = aliaslink; /* for compiler */ 176 177 /* Defaults in case we won't match any line */ 178 ugid.uid = ugid.gid = 0; 179 keep_matching = 0; 180 mode = 0660; 181 182 if (ENABLE_FEATURE_MDEV_CONF 183 && config_read(parser, tokens, 4, 3, "# \t", PARSE_NORMAL) 184 ) { 185 char *val; 186 char *str_to_match; 187 regmatch_t off[1 + 9 * ENABLE_FEATURE_MDEV_RENAME_REGEXP]; 188 189 val = tokens[0]; 190 keep_matching = ('-' == val[0]); 191 val += keep_matching; /* swallow leading dash */ 192 193 /* Match against either "subsystem/device_name" 194 * or "device_name" alone */ 195 str_to_match = strchr(val, '/') ? path : device_name; 196 197 /* Fields: regex uid:gid mode [alias] [cmd] */ 198 199 if (val[0] == '@') { 200 /* @major,minor[-minor2] */ 201 /* (useful when name is ambiguous: 202 * "/sys/class/usb/lp0" and 203 * "/sys/class/printer/lp0") */ 204 int cmaj, cmin0, cmin1, sc; 205 if (major < 0) 206 continue; /* no dev, no match */ 207 sc = sscanf(val, "@%u,%u-%u", &cmaj, &cmin0, &cmin1); 208 if (sc < 1 209 || major != cmaj 210 || (sc == 2 && minor != cmin0) 211 || (sc == 3 && (minor < cmin0 || minor > cmin1)) 212 ) { 213 continue; /* this line doesn't match */ 214 } 215 goto line_matches; 216 } 217 if (val[0] == '$') { 218 /* regex to match an environment variable */ 219 char *eq = strchr(++val, '='); 220 if (!eq) 221 continue; 222 *eq = '\0'; 223 str_to_match = getenv(val); 224 if (!str_to_match) 225 continue; 226 str_to_match -= strlen(val) + 1; 227 *eq = '='; 228 } 229 /* else: regex to match [subsystem/]device_name */ 230 231 { 232 regex_t match; 233 int result; 234 235 xregcomp(&match, val, REG_EXTENDED); 236 result = regexec(&match, str_to_match, ARRAY_SIZE(off), off, 0); 237 regfree(&match); 238 //bb_error_msg("matches:"); 239 //for (int i = 0; i < ARRAY_SIZE(off); i++) { 240 // if (off[i].rm_so < 0) continue; 241 // bb_error_msg("match %d: '%.*s'\n", i, 242 // (int)(off[i].rm_eo - off[i].rm_so), 243 // device_name + off[i].rm_so); 244 //} 245 246 /* If no match, skip rest of line */ 247 /* (regexec returns whole pattern as "range" 0) */ 248 if (result 249 || off[0].rm_so 250 || ((int)off[0].rm_eo != (int)strlen(str_to_match)) 251 ) { 252 continue; /* this line doesn't match */ 253 } 254 } 255 line_matches: 256 /* This line matches. Stop parsing after parsing 257 * the rest the line unless keep_matching == 1 */ 258 259 /* 2nd field: uid:gid - device ownership */ 260 if (get_uidgid(&ugid, tokens[1], 1) == 0) 261 bb_error_msg("unknown user/group %s on line %d", tokens[1], parser->lineno); 262 263 /* 3rd field: mode - device permissions */ 264 bb_parse_mode(tokens[2], &mode); 265 266 val = tokens[3]; 267 /* 4th field (opt): ">|=alias" or "!" to not create the node */ 268 269 if (ENABLE_FEATURE_MDEV_RENAME && val) { 270 char *a, *s, *st; 271 272 a = val; 273 s = strchrnul(val, ' '); 274 st = strchrnul(val, '\t'); 275 if (st < s) 276 s = st; 277 st = (s[0] && s[1]) ? s+1 : NULL; 278 279 aliaslink = a[0]; 280 if (aliaslink == '!' && s == a+1) { 281 val = st; 282 /* "!": suppress node creation/deletion */ 283 major = -2; 284 } 285 else if (aliaslink == '>' || aliaslink == '=') { 286 val = st; 287 s[0] = '\0'; 288 if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) { 289 char *p; 290 unsigned i, n; 291 292 /* substitute %1..9 with off[1..9], if any */ 293 n = 0; 294 s = a; 295 while (*s) 296 if (*s++ == '%') 297 n++; 298 299 p = alias = xzalloc(strlen(a) + n * strlen(str_to_match)); 300 s = a + 1; 301 while (*s) { 302 *p = *s; 303 if ('%' == *s) { 304 i = (s[1] - '0'); 305 if (i <= 9 && off[i].rm_so >= 0) { 306 n = off[i].rm_eo - off[i].rm_so; 307 strncpy(p, str_to_match + off[i].rm_so, n); 308 p += n - 1; 309 s++; 310 } 311 } 312 p++; 313 s++; 314 } 315 } else { 316 alias = xstrdup(a + 1); 317 } 318 } 319 } 320 321 if (ENABLE_FEATURE_MDEV_EXEC && val) { 322 const char *s = "$@*"; 323 const char *s2 = strchr(s, val[0]); 324 325 if (!s2) { 326 bb_error_msg("bad line %u", parser->lineno); 327 if (ENABLE_FEATURE_MDEV_RENAME) 328 free(alias); 329 continue; 330 } 331 332 /* Are we running this command now? 333 * Run $cmd on delete, @cmd on create, *cmd on both 334 */ 335 if (s2 - s != delete) { 336 /* We are here if: '*', 337 * or: '@' and delete = 0, 338 * or: '$' and delete = 1 339 */ 340 command = xstrdup(val + 1); 341 } 342 } 343 } 344 345 /* End of field parsing */ 346 347 /* "Execute" the line we found */ 348 { 349 const char *node_name; 350 351 node_name = device_name; 352 if (ENABLE_FEATURE_MDEV_RENAME && alias) 353 node_name = alias = build_alias(alias, device_name); 354 355 if (!delete && major >= 0) { 356 if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST) 357 bb_perror_msg("can't create '%s'", node_name); 358 if (major == G.root_major && minor == G.root_minor) 359 symlink(node_name, "root"); 360 if (ENABLE_FEATURE_MDEV_CONF) { 361 chmod(node_name, mode); 362 chown(node_name, ugid.uid, ugid.gid); 363 } 364 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 365 if (aliaslink == '>') 366 symlink(node_name, device_name); 367 } 368 } 369 370 if (ENABLE_FEATURE_MDEV_EXEC && command) { 371 /* setenv will leak memory, use putenv/unsetenv/free */ 372 char *s = xasprintf("%s=%s", "MDEV", node_name); 373 char *s1 = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem); 374 putenv(s); 375 putenv(s1); 376 if (system(command) == -1) 377 bb_perror_msg("can't run '%s'", command); 378 bb_unsetenv_and_free(s1); 379 bb_unsetenv_and_free(s); 380 free(command); 381 } 382 383 if (delete && major >= -1) { 384 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 385 if (aliaslink == '>') 386 unlink(device_name); 387 } 388 unlink(node_name); 389 } 390 391 if (ENABLE_FEATURE_MDEV_RENAME) 392 free(alias); 393 } 394 395 /* We found matching line. 396 * Stop unless it was prefixed with '-' */ 397 if (ENABLE_FEATURE_MDEV_CONF && !keep_matching) 823 if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching) 398 824 break; 399 400 /* end of "while line is read from /etc/mdev.conf" */ 401 } while (ENABLE_FEATURE_MDEV_CONF); 402 403 if (ENABLE_FEATURE_MDEV_CONF) 404 config_close(parser); 405 free(subsystem_slash_devname); 825 } /* for (;;) */ 406 826 } 407 827 … … 421 841 strcpy(scratch, fileName); 422 842 scratch[len] = '\0'; 423 make_device( scratch, /*delete:*/ 0);843 make_device(/*DEVNAME:*/ NULL, scratch, OP_add); 424 844 425 845 return TRUE; … … 436 856 if (1 == depth) { 437 857 free(G.subsystem); 858 if (G.subsys_env) { 859 bb_unsetenv_and_free(G.subsys_env); 860 G.subsys_env = NULL; 861 } 438 862 G.subsystem = strrchr(fileName, '/'); 439 if (G.subsystem) 863 if (G.subsystem) { 440 864 G.subsystem = xstrdup(G.subsystem + 1); 865 G.subsys_env = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem); 866 putenv(G.subsys_env); 867 } 441 868 } 442 869 … … 458 885 { 459 886 int cnt; 460 int firmware_fd, loading_fd , data_fd;887 int firmware_fd, loading_fd; 461 888 462 889 /* check for /lib/firmware/$FIRMWARE */ 463 890 xchdir("/lib/firmware"); 464 firmware_fd = xopen(firmware, O_RDONLY); 465 466 /* in case we goto out ... */ 467 data_fd = -1; 891 firmware_fd = open(firmware, O_RDONLY); /* can fail */ 468 892 469 893 /* check for /sys/$DEVPATH/loading ... give 30 seconds to appear */ … … 471 895 for (cnt = 0; cnt < 30; ++cnt) { 472 896 loading_fd = open("loading", O_WRONLY); 473 if (loading_fd != -1)897 if (loading_fd >= 0) 474 898 goto loading; 475 899 sleep(1); … … 478 902 479 903 loading: 480 /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */ 481 if (full_write(loading_fd, "1", 1) != 1) 482 goto out; 483 484 /* load firmware into /sys/$DEVPATH/data */ 485 data_fd = open("data", O_WRONLY); 486 if (data_fd == -1) 487 goto out; 488 cnt = bb_copyfd_eof(firmware_fd, data_fd); 489 490 /* tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" */ 904 cnt = 0; 905 if (firmware_fd >= 0) { 906 int data_fd; 907 908 /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */ 909 if (full_write(loading_fd, "1", 1) != 1) 910 goto out; 911 912 /* load firmware into /sys/$DEVPATH/data */ 913 data_fd = open("data", O_WRONLY); 914 if (data_fd < 0) 915 goto out; 916 cnt = bb_copyfd_eof(firmware_fd, data_fd); 917 if (ENABLE_FEATURE_CLEAN_UP) 918 close(data_fd); 919 } 920 921 /* Tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" 922 * Note: we emit -1 also if firmware file wasn't found. 923 * There are cases when otherwise kernel would wait for minutes 924 * before timing out. 925 */ 491 926 if (cnt > 0) 492 927 full_write(loading_fd, "0", 1); … … 495 930 496 931 out: 932 xchdir("/dev"); 497 933 if (ENABLE_FEATURE_CLEAN_UP) { 498 934 close(firmware_fd); 499 935 close(loading_fd); 500 close(data_fd); 936 } 937 } 938 939 static char *curtime(void) 940 { 941 struct timeval tv; 942 gettimeofday(&tv, NULL); 943 sprintf(G.timestr, "%u.%06u", (unsigned)tv.tv_sec % 60, (unsigned)tv.tv_usec); 944 return G.timestr; 945 } 946 947 static void open_mdev_log(const char *seq, unsigned my_pid) 948 { 949 int logfd = open("mdev.log", O_WRONLY | O_APPEND); 950 if (logfd >= 0) { 951 xmove_fd(logfd, STDERR_FILENO); 952 G.verbose = 2; 953 applet_name = xasprintf("%s[%s]", applet_name, seq ? seq : utoa(my_pid)); 954 } 955 } 956 957 /* If it exists, does /dev/mdev.seq match $SEQNUM? 958 * If it does not match, earlier mdev is running 959 * in parallel, and we need to wait. 960 * Active mdev pokes us with SIGCHLD to check the new file. 961 */ 962 static int 963 wait_for_seqfile(const char *seq) 964 { 965 /* We time out after 2 sec */ 966 static const struct timespec ts = { 0, 32*1000*1000 }; 967 int timeout = 2000 / 32; 968 int seq_fd = -1; 969 int do_once = 1; 970 sigset_t set_CHLD; 971 972 sigemptyset(&set_CHLD); 973 sigaddset(&set_CHLD, SIGCHLD); 974 sigprocmask(SIG_BLOCK, &set_CHLD, NULL); 975 976 for (;;) { 977 int seqlen; 978 char seqbuf[sizeof(int)*3 + 2]; 979 980 if (seq_fd < 0) { 981 seq_fd = open("mdev.seq", O_RDWR); 982 if (seq_fd < 0) 983 break; 984 } 985 seqlen = pread(seq_fd, seqbuf, sizeof(seqbuf) - 1, 0); 986 if (seqlen < 0) { 987 close(seq_fd); 988 seq_fd = -1; 989 break; 990 } 991 seqbuf[seqlen] = '\0'; 992 if (seqbuf[0] == '\n') { 993 /* seed file: write out seq ASAP */ 994 xwrite_str(seq_fd, seq); 995 xlseek(seq_fd, 0, SEEK_SET); 996 dbg2("first seq written"); 997 break; 998 } 999 if (strcmp(seq, seqbuf) == 0) { 1000 /* correct idx */ 1001 break; 1002 } 1003 if (do_once) { 1004 dbg2("%s waiting for '%s'", curtime(), seqbuf); 1005 do_once = 0; 1006 } 1007 if (sigtimedwait(&set_CHLD, NULL, &ts) >= 0) { 1008 dbg3("woken up"); 1009 continue; /* don't decrement timeout! */ 1010 } 1011 if (--timeout == 0) { 1012 dbg1("%s waiting for '%s'", "timed out", seqbuf); 1013 break; 1014 } 1015 } 1016 sigprocmask(SIG_UNBLOCK, &set_CHLD, NULL); 1017 return seq_fd; 1018 } 1019 1020 static void signal_mdevs(unsigned my_pid) 1021 { 1022 procps_status_t* p = NULL; 1023 while ((p = procps_scan(p, PSSCAN_ARGV0)) != NULL) { 1024 if (p->pid != my_pid 1025 && p->argv0 1026 && strcmp(bb_basename(p->argv0), "mdev") == 0 1027 ) { 1028 kill(p->pid, SIGCHLD); 1029 } 501 1030 } 502 1031 } … … 506 1035 { 507 1036 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE); 1037 1038 INIT_G(); 1039 1040 #if ENABLE_FEATURE_MDEV_CONF 1041 G.filename = "/etc/mdev.conf"; 1042 #endif 508 1043 509 1044 /* We can be called as hotplug helper */ … … 517 1052 518 1053 if (argv[1] && strcmp(argv[1], "-s") == 0) { 519 /* Scan:520 * mdev -s1054 /* 1055 * Scan: mdev -s 521 1056 */ 522 1057 struct stat st; 523 1058 1059 #if ENABLE_FEATURE_MDEV_CONF 1060 /* Same as xrealloc_vector(NULL, 4, 0): */ 1061 G.rule_vec = xzalloc((1 << 4) * sizeof(*G.rule_vec)); 1062 #endif 524 1063 xstat("/", &st); 525 1064 G.root_major = major(st.st_dev); 526 1065 G.root_minor = minor(st.st_dev); 1066 1067 putenv((char*)"ACTION=add"); 527 1068 528 1069 /* ACTION_FOLLOWLINKS is needed since in newer kernels … … 549 1090 char *seq; 550 1091 char *action; 551 char *env_path; 552 static const char keywords[] ALIGN1 = "remove\0add\0"; 553 enum { OP_remove = 0, OP_add }; 1092 char *env_devname; 1093 char *env_devpath; 1094 unsigned my_pid; 1095 int seq_fd; 554 1096 smalluint op; 555 1097 556 1098 /* Hotplug: 557 1099 * env ACTION=... DEVPATH=... SUBSYSTEM=... [SEQNUM=...] mdev 558 * ACTION can be "add" or "remove"1100 * ACTION can be "add", "remove", "change" 559 1101 * DEVPATH is like "/block/sda" or "/class/input/mice" 560 1102 */ 561 1103 action = getenv("ACTION"); 562 env_path = getenv("DEVPATH"); 1104 op = index_in_strings(keywords, action); 1105 env_devname = getenv("DEVNAME"); /* can be NULL */ 1106 env_devpath = getenv("DEVPATH"); 563 1107 G.subsystem = getenv("SUBSYSTEM"); 564 if (!action || !env_ path /*|| !G.subsystem*/)1108 if (!action || !env_devpath /*|| !G.subsystem*/) 565 1109 bb_show_usage(); 566 1110 fw = getenv("FIRMWARE"); 567 op = index_in_strings(keywords, action);568 /* If it exists, does /dev/mdev.seq match $SEQNUM?569 * If it does not match, earlier mdev is running570 * in parallel, and we need to wait */571 1111 seq = getenv("SEQNUM"); 572 if (seq) { 573 int timeout = 2000 / 32; /* 2000 msec */ 574 do { 575 int seqlen; 576 char seqbuf[sizeof(int)*3 + 2]; 577 578 seqlen = open_read_close("mdev.seq", seqbuf, sizeof(seqbuf-1)); 579 if (seqlen < 0) { 580 seq = NULL; 581 break; 582 } 583 seqbuf[seqlen] = '\0'; 584 if (seqbuf[0] == '\n' /* seed file? */ 585 || strcmp(seq, seqbuf) == 0 /* correct idx? */ 586 ) { 587 break; 588 } 589 usleep(32*1000); 590 } while (--timeout); 591 } 592 593 snprintf(temp, PATH_MAX, "/sys%s", env_path); 1112 1113 my_pid = getpid(); 1114 open_mdev_log(seq, my_pid); 1115 1116 seq_fd = seq ? wait_for_seqfile(seq) : -1; 1117 1118 dbg1("%s " 1119 "ACTION:%s SUBSYSTEM:%s DEVNAME:%s DEVPATH:%s" 1120 "%s%s", 1121 curtime(), 1122 action, G.subsystem, env_devname, env_devpath, 1123 fw ? " FW:" : "", fw ? fw : "" 1124 ); 1125 1126 snprintf(temp, PATH_MAX, "/sys%s", env_devpath); 594 1127 if (op == OP_remove) { 595 1128 /* Ignoring "remove firmware". It was reported … … 597 1130 * of device nodes. */ 598 1131 if (!fw) 599 make_device( temp, /*delete:*/ 1);600 } 601 else if (op == OP_add){602 make_device( temp, /*delete:*/ 0);1132 make_device(env_devname, temp, op); 1133 } 1134 else { 1135 make_device(env_devname, temp, op); 603 1136 if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) { 604 if ( fw)1137 if (op == OP_add && fw) 605 1138 load_firmware(fw, temp); 606 1139 } 607 1140 } 608 1141 609 if (seq) { 610 xopen_xwrite_close("mdev.seq", utoa(xatou(seq) + 1)); 1142 dbg1("%s exiting", curtime()); 1143 if (seq_fd >= 0) { 1144 xwrite_str(seq_fd, utoa(xatou(seq) + 1)); 1145 signal_mdevs(my_pid); 611 1146 } 612 1147 } -
branches/3.2/mindi-busybox/util-linux/mkfs_ext2.c
r2725 r3232 8 8 * Licensed under GPLv2, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define mkfs_ext2_trivial_usage 12 //usage: "[-Fn] " 13 /* //usage: "[-c|-l filename] " */ 14 //usage: "[-b BLK_SIZE] " 15 /* //usage: "[-f fragment-size] [-g blocks-per-group] " */ 16 //usage: "[-i INODE_RATIO] [-I INODE_SIZE] " 17 /* //usage: "[-j] [-J journal-options] [-N number-of-inodes] " */ 18 //usage: "[-m RESERVED_PERCENT] " 19 /* //usage: "[-o creator-os] [-O feature[,...]] [-q] " */ 20 /* //usage: "[r fs-revision-level] [-E extended-options] [-v] [-F] " */ 21 //usage: "[-L LABEL] " 22 /* //usage: "[-M last-mounted-directory] [-S] [-T filesystem-type] " */ 23 //usage: "BLOCKDEV [KBYTES]" 24 //usage:#define mkfs_ext2_full_usage "\n\n" 25 //usage: " -b BLK_SIZE Block size, bytes" 26 /* //usage: "\n -c Check device for bad blocks" */ 27 /* //usage: "\n -E opts Set extended options" */ 28 /* //usage: "\n -f size Fragment size in bytes" */ 29 //usage: "\n -F Force" 30 /* //usage: "\n -g N Number of blocks in a block group" */ 31 //usage: "\n -i RATIO Max number of files is filesystem_size / RATIO" 32 //usage: "\n -I BYTES Inode size (min 128)" 33 /* //usage: "\n -j Create a journal (ext3)" */ 34 /* //usage: "\n -J opts Set journal options (size/device)" */ 35 /* //usage: "\n -l file Read bad blocks list from file" */ 36 //usage: "\n -L LBL Volume label" 37 //usage: "\n -m PERCENT Percent of blocks to reserve for admin" 38 /* //usage: "\n -M dir Set last mounted directory" */ 39 //usage: "\n -n Dry run" 40 /* //usage: "\n -N N Number of inodes to create" */ 41 /* //usage: "\n -o os Set the 'creator os' field" */ 42 /* //usage: "\n -O features Dir_index/filetype/has_journal/journal_dev/sparse_super" */ 43 /* //usage: "\n -q Quiet" */ 44 /* //usage: "\n -r rev Set filesystem revision" */ 45 /* //usage: "\n -S Write superblock and group descriptors only" */ 46 /* //usage: "\n -T fs-type Set usage type (news/largefile/largefile4)" */ 47 /* //usage: "\n -v Verbose" */ 48 10 49 #include "libbb.h" 11 50 #include <linux/fs.h> 12 #include <linux/ext2_fs.h>51 #include "bb_e2fs_defs.h" 13 52 14 53 #define ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT 0 15 54 #define ENABLE_FEATURE_MKFS_EXT2_DIR_INDEX 1 16 17 // from e2fsprogs18 #define s_reserved_gdt_blocks s_padding119 #define s_mkfs_time s_reserved[0]20 #define s_flags s_reserved[22]21 55 22 56 #define EXT2_HASH_HALF_MD4 1 … … 444 478 STORE_LE(sb->s_inode_size, inodesize); 445 479 // set "Required extra isize" and "Desired extra isize" fields to 28 446 if (inodesize != sizeof(*inode)) 447 STORE_LE(sb->s_reserved[21], 0x001C001C); 480 if (inodesize != sizeof(*inode)) { 481 STORE_LE(sb->s_min_extra_isize, 0x001c); 482 STORE_LE(sb->s_want_extra_isize, 0x001c); 483 } 448 484 STORE_LE(sb->s_first_ino, EXT2_GOOD_OLD_FIRST_INO); 449 485 STORE_LE(sb->s_log_block_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE); … … 577 613 // zero boot sectors 578 614 memset(buf, 0, blocksize); 579 PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros 615 // Disabled: standard mke2fs doesn't do this, and 616 // on SPARC this destroys Sun disklabel. 617 // Users who need/want zeroing can easily do it with dd. 618 //PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros 619 580 620 // zero inode tables 581 621 for (i = 0; i < ngroups; ++i) -
branches/3.2/mindi-busybox/util-linux/mkfs_minix.c
r2725 r3232 63 63 * removed getopt based parser and added a hand rolled one. 64 64 */ 65 66 //usage:#define mkfs_minix_trivial_usage 67 //usage: "[-c | -l FILE] [-nXX] [-iXX] BLOCKDEV [KBYTES]" 68 //usage:#define mkfs_minix_full_usage "\n\n" 69 //usage: "Make a MINIX filesystem\n" 70 //usage: "\n -c Check device for bad blocks" 71 //usage: "\n -n [14|30] Maximum length of filenames" 72 //usage: "\n -i INODES Number of inodes for the filesystem" 73 //usage: "\n -l FILE Read bad blocks list from FILE" 74 //usage: "\n -v Make version 2 filesystem" 65 75 66 76 #include "libbb.h" -
branches/3.2/mindi-busybox/util-linux/mkfs_reiser.c
r2725 r3232 7 7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define mkfs_reiser_trivial_usage 11 //usage: "[-f] [-l LABEL] BLOCKDEV [4K-BLOCKS]" 12 //usage:#define mkfs_reiser_full_usage "\n\n" 13 //usage: "Make a ReiserFS V3 filesystem\n" 14 //usage: "\n -f Force" 15 //usage: "\n -l LBL Volume label" 16 9 17 #include "libbb.h" 10 18 #include <linux/fs.h> -
branches/3.2/mindi-busybox/util-linux/mkfs_vfat.c
r2725 r3232 8 8 * Licensed under GPLv2, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define mkfs_vfat_trivial_usage 12 //usage: "[-v] [-n LABEL] BLOCKDEV [KBYTES]" 13 /* Accepted but ignored: 14 "[-c] [-C] [-I] [-l bad-block-file] [-b backup-boot-sector] " 15 "[-m boot-msg-file] [-i volume-id] " 16 "[-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs] " 17 "[-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors] " 18 */ 19 //usage:#define mkfs_vfat_full_usage "\n\n" 20 //usage: "Make a FAT32 filesystem\n" 21 /* //usage: "\n -c Check device for bad blocks" */ 22 //usage: "\n -v Verbose" 23 /* //usage: "\n -I Allow to use entire disk device (e.g. /dev/hda)" */ 24 //usage: "\n -n LBL Volume label" 25 10 26 #include "libbb.h" 11 27 -
branches/3.2/mindi-busybox/util-linux/mkswap.c
r2725 r3232 6 6 * Licensed under GPLv2, see file LICENSE in this source tree. 7 7 */ 8 9 //usage:#define mkswap_trivial_usage 10 //usage: "[-L LBL] BLOCKDEV [KBYTES]" 11 //usage:#define mkswap_full_usage "\n\n" 12 //usage: "Prepare BLOCKDEV to be used as swap partition\n" 13 //usage: "\n -L LBL Label" 14 8 15 #include "libbb.h" 9 16 -
branches/3.2/mindi-busybox/util-linux/more.c
r2725 r3232 14 14 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 15 15 */ 16 17 //usage:#define more_trivial_usage 18 //usage: "[FILE]..." 19 //usage:#define more_full_usage "\n\n" 20 //usage: "View FILE (or stdin) one screenful at a time" 21 //usage: 22 //usage:#define more_example_usage 23 //usage: "$ dmesg | more\n" 16 24 17 25 #include "libbb.h" … … 78 86 getTermSettings(cin_fileno, &initial_settings); 79 87 new_settings = initial_settings; 80 new_settings.c_lflag &= ~ICANON; 81 new_settings.c_lflag &= ~ECHO; 88 new_settings.c_lflag &= ~(ICANON | ECHO); 82 89 new_settings.c_cc[VMIN] = 1; 83 90 new_settings.c_cc[VTIME] = 0; … … 114 121 if (input != 'r' && please_display_more_prompt) { 115 122 len = printf("--More-- "); 116 if (st.st_size > 0) { 123 if (st.st_size != 0) { 124 uoff_t d = (uoff_t)st.st_size / 100; 125 if (d == 0) 126 d = 1; 117 127 len += printf("(%u%% of %"OFF_FMT"u bytes)", 118 (int) ( ftello(file)*100 / st.st_size),128 (int) ((uoff_t)ftello(file) / d), 119 129 st.st_size); 120 130 } … … 160 170 * a bajillion times easier to deal with. */ 161 171 if (c == '\t') { 162 spaces = CONVERTED_TAB_SIZE - 1;172 spaces = ((unsigned)~len) % CONVERTED_TAB_SIZE; 163 173 c = ' '; 164 174 } … … 192 202 /* My small mind cannot fathom backspaces and UTF-8 */ 193 203 putchar(c); 204 die_if_ferror_stdout(); /* if tty was destroyed (closed xterm, etc) */ 194 205 } 195 206 fclose(file); -
branches/3.2/mindi-busybox/util-linux/mount.c
r2725 r3232 17 17 // mount_it_now() does the actual mount. 18 18 // 19 20 //usage:#define mount_trivial_usage 21 //usage: "[OPTIONS] [-o OPTS] DEVICE NODE" 22 //usage:#define mount_full_usage "\n\n" 23 //usage: "Mount a filesystem. Filesystem autodetection requires /proc.\n" 24 //usage: "\n -a Mount all filesystems in fstab" 25 //usage: IF_FEATURE_MOUNT_FAKE( 26 //usage: IF_FEATURE_MTAB_SUPPORT( 27 //usage: "\n -f Update /etc/mtab, but don't mount" 28 //usage: ) 29 //usage: IF_NOT_FEATURE_MTAB_SUPPORT( 30 //usage: "\n -f Dry run" 31 //usage: ) 32 //usage: ) 33 //usage: IF_FEATURE_MOUNT_HELPERS( 34 //usage: "\n -i Don't run mount helper" 35 //usage: ) 36 //usage: IF_FEATURE_MTAB_SUPPORT( 37 //usage: "\n -n Don't update /etc/mtab" 38 //usage: ) 39 //usage: IF_FEATURE_MOUNT_VERBOSE( 40 //usage: "\n -v Verbose" 41 //usage: ) 42 ////usage: "\n -s Sloppy (ignored)" 43 //usage: "\n -r Read-only mount" 44 //usage: "\n -w Read-write mount (default)" 45 //usage: "\n -t FSTYPE[,...] Filesystem type(s)" 46 //usage: "\n -O OPT Mount only filesystems with option OPT (-a only)" 47 //usage: "\n-o OPT:" 48 //usage: IF_FEATURE_MOUNT_LOOP( 49 //usage: "\n loop Ignored (loop devices are autodetected)" 50 //usage: ) 51 //usage: IF_FEATURE_MOUNT_FLAGS( 52 //usage: "\n [a]sync Writes are [a]synchronous" 53 //usage: "\n [no]atime Disable/enable updates to inode access times" 54 //usage: "\n [no]diratime Disable/enable atime updates to directories" 55 //usage: "\n [no]relatime Disable/enable atime updates relative to modification time" 56 //usage: "\n [no]dev (Dis)allow use of special device files" 57 //usage: "\n [no]exec (Dis)allow use of executable files" 58 //usage: "\n [no]suid (Dis)allow set-user-id-root programs" 59 //usage: "\n [r]shared Convert [recursively] to a shared subtree" 60 //usage: "\n [r]slave Convert [recursively] to a slave subtree" 61 //usage: "\n [r]private Convert [recursively] to a private subtree" 62 //usage: "\n [un]bindable Make mount point [un]able to be bind mounted" 63 //usage: "\n [r]bind Bind a file or directory [recursively] to another location" 64 //usage: "\n move Relocate an existing mount point" 65 //usage: ) 66 //usage: "\n remount Remount a mounted filesystem, changing flags" 67 //usage: "\n ro/rw Same as -r/-w" 68 //usage: "\n" 69 //usage: "\nThere are filesystem-specific -o flags." 70 //usage: 71 //usage:#define mount_example_usage 72 //usage: "$ mount\n" 73 //usage: "/dev/hda3 on / type minix (rw)\n" 74 //usage: "proc on /proc type proc (rw)\n" 75 //usage: "devpts on /dev/pts type devpts (rw)\n" 76 //usage: "$ mount /dev/fd0 /mnt -t msdos -o ro\n" 77 //usage: "$ mount /tmp/diskimage /opt -t ext2 -o loop\n" 78 //usage: "$ mount cd_image.iso mydir\n" 79 //usage:#define mount_notes_usage 80 //usage: "Returns 0 for success, number of failed mounts for -a, or errno for one mount." 81 19 82 #include <mntent.h> 20 83 #include <syslog.h> … … 55 118 # define MS_RELATIME (1 << 21) 56 119 #endif 120 #ifndef MS_STRICTATIME 121 # define MS_STRICTATIME (1 << 24) 122 #endif 123 124 /* Any ~MS_FOO value has this bit set: */ 125 #define BB_MS_INVERTED_VALUE (1u << 31) 57 126 58 127 #include "libbb.h" … … 160 229 IF_DESKTOP(/* "users" */ MOUNT_USERS,) 161 230 /* "_netdev" */ 0, 231 IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ 162 232 ) 163 233 … … 181 251 /* "relatime" */ MS_RELATIME, 182 252 /* "norelatime" */ ~MS_RELATIME, 253 /* "strictatime" */ MS_STRICTATIME, 183 254 /* "loud" */ ~MS_SILENT, 255 /* "rbind" */ MS_BIND|MS_RECURSIVE, 184 256 185 257 // action flags … … 193 265 /* "rshared" */ MS_SHARED|MS_RECURSIVE, 194 266 /* "rslave" */ MS_SLAVE|MS_RECURSIVE, 195 /* "rprivate" */ MS_ SLAVE|MS_RECURSIVE,267 /* "rprivate" */ MS_PRIVATE|MS_RECURSIVE, 196 268 /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE, 197 269 ) … … 216 288 IF_DESKTOP("users\0") 217 289 "_netdev\0" 290 IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ 218 291 ) 219 292 IF_FEATURE_MOUNT_FLAGS( … … 236 309 "relatime\0" 237 310 "norelatime\0" 311 "strictatime\0" 238 312 "loud\0" 313 "rbind\0" 239 314 240 315 // action flags … … 242 317 "bind\0" 243 318 "move\0" 244 " shared\0"245 " slave\0"246 " private\0"247 " unbindable\0"248 " rshared\0"249 " rslave\0"250 " rprivate\0"251 " runbindable\0"319 "make-shared\0" 320 "make-slave\0" 321 "make-private\0" 322 "make-unbindable\0" 323 "make-rshared\0" 324 "make-rslave\0" 325 "make-rprivate\0" 326 "make-runbindable\0" 252 327 ) 253 328 … … 279 354 #define fslist (G.fslist ) 280 355 #define getmntent_buf (G.getmntent_buf ) 281 356 #define INIT_G() do { } while (0) 357 358 #if ENABLE_FEATURE_MTAB_SUPPORT 359 /* 360 * update_mtab_entry_on_move() is used to update entry in case of mount --move. 361 * we are looking for existing entries mnt_dir which is equal to mnt_fsname of 362 * input mntent and replace it by new one. 363 */ 364 static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp) 365 { 366 struct mntent *entries, *m; 367 int i, count; 368 FILE *mountTable; 369 370 mountTable = setmntent(bb_path_mtab_file, "r"); 371 if (!mountTable) { 372 bb_perror_msg(bb_path_mtab_file); 373 return; 374 } 375 376 entries = NULL; 377 count = 0; 378 while ((m = getmntent(mountTable)) != NULL) { 379 entries = xrealloc_vector(entries, 3, count); 380 entries[count].mnt_fsname = xstrdup(m->mnt_fsname); 381 entries[count].mnt_dir = xstrdup(m->mnt_dir); 382 entries[count].mnt_type = xstrdup(m->mnt_type); 383 entries[count].mnt_opts = xstrdup(m->mnt_opts); 384 entries[count].mnt_freq = m->mnt_freq; 385 entries[count].mnt_passno = m->mnt_passno; 386 count++; 387 } 388 endmntent(mountTable); 389 390 mountTable = setmntent(bb_path_mtab_file, "w"); 391 if (mountTable) { 392 for (i = 0; i < count; i++) { 393 if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0) 394 addmntent(mountTable, &entries[i]); 395 else 396 addmntent(mountTable, mp); 397 } 398 endmntent(mountTable); 399 } else if (errno != EROFS) 400 bb_perror_msg(bb_path_mtab_file); 401 402 if (ENABLE_FEATURE_CLEAN_UP) { 403 for (i = 0; i < count; i++) { 404 free(entries[i].mnt_fsname); 405 free(entries[i].mnt_dir); 406 free(entries[i].mnt_type); 407 free(entries[i].mnt_opts); 408 } 409 free(entries); 410 } 411 } 412 #endif 282 413 283 414 #if ENABLE_FEATURE_MOUNT_VERBOSE … … 334 465 // Use the mount_options list to parse options into flags. 335 466 // Also update list of unrecognized options if unrecognized != NULL 336 static long parse_mount_options(char *options, char **unrecognized)337 { 338 long flags = MS_SILENT;467 static unsigned long parse_mount_options(char *options, char **unrecognized) 468 { 469 unsigned long flags = MS_SILENT; 339 470 340 471 // Loop through options … … 349 480 // Find this option in mount_options 350 481 for (i = 0; i < ARRAY_SIZE(mount_options); i++) { 351 if (strcasecmp(option_str, options) == 0) { 352 long fl = mount_options[i]; 353 if (fl < 0) 482 unsigned opt_len = strlen(option_str); 483 484 if (strncasecmp(option_str, options, opt_len) == 0 485 && (options[opt_len] == '\0' 486 /* or is it "comment=" thingy in fstab? */ 487 IF_FEATURE_MOUNT_FSTAB(IF_DESKTOP( || option_str[opt_len-1] == '=' )) 488 ) 489 ) { 490 unsigned long fl = mount_options[i]; 491 if (fl & BB_MS_INVERTED_VALUE) 354 492 flags &= fl; 355 493 else … … 357 495 goto found; 358 496 } 359 option_str += strlen(option_str)+ 1;497 option_str += opt_len + 1; 360 498 } 361 499 // We did not recognize this option. … … 406 544 while ((buf = xmalloc_fgetline(f)) != NULL) { 407 545 if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5])) 408 continue;546 goto next; 409 547 fs = skip_whitespace(buf); 410 548 if (*fs == '#' || *fs == '*' || !*fs) 411 continue;549 goto next; 412 550 413 551 llist_add_to_end(&list, xstrdup(fs)); 552 next: 414 553 free(buf); 415 554 } … … 431 570 // Perform actual mount of specific filesystem at specific location. 432 571 // NB: mp->xxx fields may be trashed on exit 433 static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)572 static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filteropts) 434 573 { 435 574 int rc = 0; … … 497 636 498 637 if (!mountTable) { 499 bb_ error_msg("no %s",bb_path_mtab_file);638 bb_perror_msg(bb_path_mtab_file); 500 639 goto ret; 501 640 } 502 641 503 642 // Add vfs string flags 504 505 643 for (i = 0; mount_options[i] != MS_REMOUNT; i++) { 506 644 if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) … … 510 648 511 649 // Remove trailing / (if any) from directory we mounted on 512 513 650 i = strlen(mp->mnt_dir) - 1; 514 if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0'; 651 while (i > 0 && mp->mnt_dir[i] == '/') 652 mp->mnt_dir[i--] = '\0'; 515 653 516 654 // Convert to canonical pathnames as needed 517 518 655 mp->mnt_dir = bb_simplify_path(mp->mnt_dir); 519 fsname = 0;656 fsname = NULL; 520 657 if (!mp->mnt_type || !*mp->mnt_type) { // bind mount 521 658 mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); … … 524 661 mp->mnt_freq = mp->mnt_passno = 0; 525 662 526 // Write and close. 527 528 addmntent(mountTable, mp); 663 // Write and close 664 #if ENABLE_FEATURE_MTAB_SUPPORT 665 if (vfsflags & MS_MOVE) 666 update_mtab_entry_on_move(mp); 667 else 668 #endif 669 addmntent(mountTable, mp); 529 670 endmntent(mountTable); 671 530 672 if (ENABLE_FEATURE_CLEAN_UP) { 531 673 free(mp->mnt_dir); … … 700 842 701 843 struct nfs2_fh { 702 char 844 char data[32]; 703 845 }; 704 846 struct nfs3_fh { 705 unsigned short 706 unsigned char 847 unsigned short size; 848 unsigned char data[64]; 707 849 }; 708 850 709 851 struct nfs_mount_data { 710 int version; 711 int fd; 712 struct nfs2_fh old_root; 713 int flags; 714 int rsize; 715 int wsize; 716 int timeo; 717 int retrans; 718 int acregmin; 719 int acregmax; 720 int acdirmin; 721 int acdirmax; 722 struct sockaddr_in addr; 723 char hostname[256]; 724 int namlen; 725 unsigned int bsize; 726 struct nfs3_fh root; 852 int version; /* 1 */ 853 int fd; /* 1 */ 854 struct nfs2_fh old_root; /* 1 */ 855 int flags; /* 1 */ 856 int rsize; /* 1 */ 857 int wsize; /* 1 */ 858 int timeo; /* 1 */ 859 int retrans; /* 1 */ 860 int acregmin; /* 1 */ 861 int acregmax; /* 1 */ 862 int acdirmin; /* 1 */ 863 int acdirmax; /* 1 */ 864 struct sockaddr_in addr; /* 1 */ 865 char hostname[256]; /* 1 */ 866 int namlen; /* 2 */ 867 unsigned int bsize; /* 3 */ 868 struct nfs3_fh root; /* 4 */ 727 869 }; 728 870 … … 739 881 NFS_MOUNT_KERBEROS = 0x0100, /* 3 */ 740 882 NFS_MOUNT_NONLM = 0x0200, /* 3 */ 883 NFS_MOUNT_NOACL = 0x0800, /* 4 */ 741 884 NFS_MOUNT_NORDIRPLUS = 0x4000 742 885 }; … … 792 935 { 793 936 if (!xdr_u_int(xdrs, &objp->fhs_status)) 794 937 return FALSE; 795 938 if (objp->fhs_status == 0) 796 939 return xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle); … … 806 949 { 807 950 return xdr_bytes(xdrs, (char **)&objp->fhandle3_val, 808 809 951 (unsigned int *) &objp->fhandle3_len, 952 FHSIZE3); 810 953 } 811 954 … … 815 958 return FALSE; 816 959 return xdr_array(xdrs, &(objp->auth_flavours.auth_flavours_val), 817 818 819 820 960 &(objp->auth_flavours.auth_flavours_len), 961 ~0, 962 sizeof(int), 963 (xdrproc_t) xdr_int); 821 964 } 822 965 … … 959 1102 960 1103 /* NB: mp->xxx fields may be trashed on exit */ 961 static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)1104 static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) 962 1105 { 963 1106 CLIENT *mclient; … … 1003 1146 int nordirplus; 1004 1147 int nolock; 1148 int noacl; 1005 1149 1006 1150 find_kernel_nfs_mount_version(); … … 1022 1166 *s = '\0'; 1023 1167 /* Ignore all but first hostname in replicated mounts 1024 1168 * until they can be fully supported. (mack@sgi.com) */ 1025 1169 s = strchr(hostname, ','); 1026 1170 if (s) { … … 1075 1219 noac = 0; 1076 1220 nordirplus = 0; 1221 noacl = 0; 1077 1222 retry = 10000; /* 10000 minutes ~ 1 week */ 1078 tcp = 0;1223 tcp = 1; /* nfs-utils uses tcp per default */ 1079 1224 1080 1225 mountprog = MOUNTPROG; … … 1130 1275 case 20: // "addr" - ignore 1131 1276 continue; 1277 case -1: // unknown 1278 if (vfsflags & MS_REMOUNT) 1279 continue; 1132 1280 } 1133 1281 … … 1210 1358 "udp\0" 1211 1359 "lock\0" 1212 "rdirplus\0"; 1360 "rdirplus\0" 1361 "acl\0"; 1213 1362 int val = 1; 1214 1363 if (!strncmp(opt, "no", 2)) { … … 1260 1409 nordirplus = !val; 1261 1410 break; 1411 case 12: // acl 1412 noacl = !val; 1413 break; 1262 1414 default: 1263 1415 bb_error_msg("unknown nfs mount option: %s%s", val ? "" : "no", opt); … … 1273 1425 | (nocto ? NFS_MOUNT_NOCTO : 0) 1274 1426 | (noac ? NFS_MOUNT_NOAC : 0) 1275 | (nordirplus ? NFS_MOUNT_NORDIRPLUS : 0); 1427 | (nordirplus ? NFS_MOUNT_NORDIRPLUS : 0) 1428 | (noacl ? NFS_MOUNT_NOACL : 0); 1276 1429 if (nfs_mount_version >= 2) 1277 1430 data.flags |= (tcp ? NFS_MOUNT_TCP : 0); … … 1377 1530 case IPPROTO_UDP: 1378 1531 mclient = clntudp_create(&mount_server_addr, 1379 1380 1381 1382 1532 pm_mnt.pm_prog, 1533 pm_mnt.pm_vers, 1534 retry_timeout, 1535 &msock); 1383 1536 if (mclient) 1384 1537 break; … … 1387 1540 case IPPROTO_TCP: 1388 1541 mclient = clnttcp_create(&mount_server_addr, 1389 1390 1391 1542 pm_mnt.pm_prog, 1543 pm_mnt.pm_vers, 1544 &msock, 0, 0); 1392 1545 break; 1393 1546 default: … … 1410 1563 if (pm_mnt.pm_vers == 3) 1411 1564 clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT, 1412 1413 1414 1415 1416 1565 (xdrproc_t) xdr_dirpath, 1566 (caddr_t) &pathname, 1567 (xdrproc_t) xdr_mountres3, 1568 (caddr_t) &status, 1569 total_timeout); 1417 1570 else 1418 1571 clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, 1419 1420 1421 1422 1423 1572 (xdrproc_t) xdr_dirpath, 1573 (caddr_t) &pathname, 1574 (xdrproc_t) xdr_fhstatus, 1575 (caddr_t) &status, 1576 total_timeout); 1424 1577 1425 1578 if (clnt_stat == RPC_SUCCESS) … … 1552 1705 /* Perform actual mount */ 1553 1706 do_mount: 1554 mp->mnt_type = (char*)"nfs";1555 1707 retval = mount_it_now(mp, vfsflags, (char*)&data); 1556 1708 goto ret; … … 1577 1729 #else // !ENABLE_FEATURE_MOUNT_NFS 1578 1730 1579 // Never called. Call should be optimized out. 1580 int nfsmount(struct mntent *mp, long vfsflags, char *filteropts); 1731 /* Linux 2.6.23+ supports nfs mounts with options passed as a string. 1732 * For older kernels, you must build busybox with ENABLE_FEATURE_MOUNT_NFS. 1733 * (However, note that then you lose any chances that NFS over IPv6 would work). 1734 */ 1735 static int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) 1736 { 1737 len_and_sockaddr *lsa; 1738 char *opts; 1739 char *end; 1740 char *dotted; 1741 int ret; 1742 1743 # if ENABLE_FEATURE_IPV6 1744 end = strchr(mp->mnt_fsname, ']'); 1745 if (end && end[1] == ':') 1746 end++; 1747 else 1748 # endif 1749 /* mount_main() guarantees that ':' is there */ 1750 end = strchr(mp->mnt_fsname, ':'); 1751 1752 *end = '\0'; 1753 lsa = xhost2sockaddr(mp->mnt_fsname, /*port:*/ 0); 1754 *end = ':'; 1755 dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); 1756 if (ENABLE_FEATURE_CLEAN_UP) free(lsa); 1757 opts = xasprintf("%s%saddr=%s", 1758 filteropts ? filteropts : "", 1759 filteropts ? "," : "", 1760 dotted 1761 ); 1762 if (ENABLE_FEATURE_CLEAN_UP) free(dotted); 1763 ret = mount_it_now(mp, vfsflags, opts); 1764 if (ENABLE_FEATURE_CLEAN_UP) free(opts); 1765 1766 return ret; 1767 } 1581 1768 1582 1769 #endif // !ENABLE_FEATURE_MOUNT_NFS … … 1588 1775 { 1589 1776 int rc = -1; 1590 long vfsflags;1777 unsigned long vfsflags; 1591 1778 char *loopFile = NULL, *filteropts = NULL; 1592 1779 llist_t *fl = NULL; … … 1638 1825 int len; 1639 1826 char c; 1827 char *hostname, *share; 1828 char *dotted, *ip; 1640 1829 len_and_sockaddr *lsa; 1641 char *hostname, *dotted, *ip; 1830 1831 // Parse mp->mnt_fsname of the form "//hostname/share[/dir1/dir2]" 1642 1832 1643 1833 hostname = mp->mnt_fsname + 2; 1644 1834 len = strcspn(hostname, "/\\"); 1645 if (len == 0 || hostname[len] == '\0') 1835 share = hostname + len + 1; 1836 if (len == 0 // 3rd char is a [back]slash (IOW: empty hostname) 1837 || share[-1] == '\0' // no [back]slash after hostname 1838 || share[0] == '\0' // empty share name 1839 ) { 1646 1840 goto report_error; 1647 c = hostname[len]; 1648 hostname[len] = '\0'; 1841 } 1842 c = share[-1]; 1843 share[-1] = '\0'; 1844 len = strcspn(share, "/\\"); 1845 1846 // "unc=\\hostname\share" option is mandatory 1847 // after CIFS option parsing was rewritten in Linux 3.4. 1848 // Must use backslashes. 1849 // If /dir1/dir2 is present, also add "prefixpath=dir1/dir2" 1850 { 1851 char *unc = xasprintf( 1852 share[len] != '\0' /* "/dir1/dir2" exists? */ 1853 ? "unc=\\\\%s\\%.*s,prefixpath=%s" 1854 : "unc=\\\\%s\\%.*s", 1855 hostname, 1856 len, share, 1857 share + len + 1 /* "dir1/dir2" */ 1858 ); 1859 parse_mount_options(unc, &filteropts); 1860 if (ENABLE_FEATURE_CLEAN_UP) free(unc); 1861 } 1862 1649 1863 lsa = host2sockaddr(hostname, 0); 1650 hostname[len] = c;1864 share[-1] = c; 1651 1865 if (!lsa) 1652 1866 goto report_error; … … 1660 1874 if (ENABLE_FEATURE_CLEAN_UP) free(ip); 1661 1875 1662 // "-o mand" is required [why?]1663 vfsflags |= MS_MANDLOCK;1664 1876 mp->mnt_type = (char*)"cifs"; 1665 1877 rc = mount_it_now(mp, vfsflags, filteropts); … … 1669 1881 1670 1882 // Might this be an NFS filesystem? 1671 if (ENABLE_FEATURE_MOUNT_NFS 1672 && (!mp->mnt_type || strcmp(mp->mnt_type, "nfs") == 0) 1883 if ((!mp->mnt_type || strncmp(mp->mnt_type, "nfs", 3) == 0) 1673 1884 && strchr(mp->mnt_fsname, ':') != NULL 1674 1885 ) { 1886 if (!mp->mnt_type) 1887 mp->mnt_type = (char*)"nfs"; 1675 1888 rc = nfsmount(mp, vfsflags, filteropts); 1676 1889 goto report_error; … … 1688 1901 loopFile = bb_simplify_path(mp->mnt_fsname); 1689 1902 mp->mnt_fsname = NULL; // will receive malloced loop dev name 1690 if (set_loop(&mp->mnt_fsname, loopFile, 0 ) < 0) {1903 if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ (vfsflags & MS_RDONLY)) < 0) { 1691 1904 if (errno == EPERM || errno == EACCES) 1692 1905 bb_error_msg(bb_msg_perm_denied_are_you_root); … … 1704 1917 // to the actual mount. 1705 1918 if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) { 1706 rc = mount_it_now(mp, vfsflags, filteropts); 1919 char *next; 1920 for (;;) { 1921 next = mp->mnt_type ? strchr(mp->mnt_type, ',') : NULL; 1922 if (next) 1923 *next = '\0'; 1924 rc = mount_it_now(mp, vfsflags, filteropts); 1925 if (rc == 0 || !next) 1926 break; 1927 mp->mnt_type = next + 1; 1928 } 1707 1929 } else { 1708 1930 // Loop through filesystem types until mount succeeds … … 1721 1943 mp->mnt_type = fl->data; 1722 1944 rc = mount_it_now(mp, vfsflags, filteropts); 1723 if ( !rc)1945 if (rc == 0) 1724 1946 break; 1725 1947 } … … 1817 2039 int i, j; 1818 2040 int rc = EXIT_SUCCESS; 2041 unsigned long cmdopt_flags; 1819 2042 unsigned opt; 1820 2043 struct mntent mtpair[2], *mtcur = mtpair; … … 1822 2045 1823 2046 IF_DESKTOP(int nonroot = ) sanitize_env_if_suid(); 2047 2048 INIT_G(); 1824 2049 1825 2050 // Parse long options, like --bind and --move. Note that -o option … … 1889 2114 // or "mount [opts] single_param" 1890 2115 1891 i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int"1892 if (nonroot && ( i& ~MS_SILENT)) // Non-root users cannot specify flags2116 cmdopt_flags = parse_mount_options(cmdopts, NULL); 2117 if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags 1893 2118 bb_error_msg_and_die(bb_msg_you_must_be_root); 1894 2119 1895 2120 // If we have a shared subtree flag, don't worry about fstab or mtab. 1896 2121 if (ENABLE_FEATURE_MOUNT_FLAGS 1897 && ( i& (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))2122 && (cmdopt_flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) 1898 2123 ) { 1899 2124 // verbose_mount(source, target, type, flags, data) 1900 rc = verbose_mount("", argv[0], "", i, "");2125 rc = verbose_mount("", argv[0], "", cmdopt_flags, ""); 1901 2126 if (rc) 1902 2127 bb_simple_perror_msg_and_die(argv[0]); … … 1906 2131 // Open either fstab or mtab 1907 2132 fstabname = "/etc/fstab"; 1908 if ( i& MS_REMOUNT) {2133 if (cmdopt_flags & MS_REMOUNT) { 1909 2134 // WARNING. I am not sure this matches util-linux's 1910 2135 // behavior. It's possible util-linux does not … … 2005 2230 // Were we looking for something specific? 2006 2231 if (argv[0]) { // yes 2007 long l;2232 unsigned long l; 2008 2233 2009 2234 // If we didn't find anything, complain -
branches/3.2/mindi-busybox/util-linux/pivot_root.c
r2725 r3232 9 9 * Licensed under GPLv2, see file LICENSE in this source tree. 10 10 */ 11 12 //usage:#define pivot_root_trivial_usage 13 //usage: "NEW_ROOT PUT_OLD" 14 //usage:#define pivot_root_full_usage "\n\n" 15 //usage: "Move the current root file system to PUT_OLD and make NEW_ROOT\n" 16 //usage: "the new root file system" 17 11 18 #include "libbb.h" 12 19 -
branches/3.2/mindi-busybox/util-linux/rdate.c
r2725 r3232 2 2 /* 3 3 * The Rdate command will ask a time server for the RFC 868 time 4 * 4 * and optionally set the system time. 5 5 * 6 6 * by Sterling Huxley <sterling@europa.com> … … 8 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define rdate_trivial_usage 12 //usage: "[-sp] HOST" 13 //usage:#define rdate_full_usage "\n\n" 14 //usage: "Get and possibly set the system date/time from a remote HOST\n" 15 //usage: "\n -s Set the system date/time (default)" 16 //usage: "\n -p Print the date/time" 10 17 11 18 #include "libbb.h" … … 29 36 fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); 30 37 31 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */38 if (safe_read(fd, &nett, 4) != 4) /* read time from server */ 32 39 bb_error_msg_and_die("%s did not send the complete time", host); 33 close(fd); 40 if (ENABLE_FEATURE_CLEAN_UP) 41 close(fd); 34 42 35 /* convert from network byte order to local byte order.43 /* Convert from network byte order to local byte order. 36 44 * RFC 868 time is the number of seconds 37 45 * since 00:00 (midnight) 1 January 1900 GMT 38 46 * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT 39 * Subtract the RFC 868 time to get Linux epoch 47 * Subtract the RFC 868 time to get Linux epoch. 40 48 */ 41 49 … … 47 55 { 48 56 time_t remote_time; 49 unsigned longflags;57 unsigned flags; 50 58 51 59 opt_complementary = "-1"; … … 54 62 remote_time = askremotedate(argv[optind]); 55 63 56 if ( (flags & 2) == 0) {64 if (!(flags & 2)) { /* no -p (-s may be present) */ 57 65 time_t current_time; 58 66 … … 65 73 } 66 74 67 if ( (flags & 1) == 0)75 if (flags != 1) /* not lone -s */ 68 76 printf("%s", ctime(&remote_time)); 69 77 -
branches/3.2/mindi-busybox/util-linux/rdev.c
r2725 r3232 10 10 */ 11 11 12 //usage:#define rdev_trivial_usage 13 //usage: "" 14 //usage:#define rdev_full_usage "\n\n" 15 //usage: "Print the device node associated with the filesystem mounted at '/'" 16 //usage: 17 //usage:#define rdev_example_usage 18 //usage: "$ rdev\n" 19 //usage: "/dev/mtdblock9 /\n" 20 12 21 #include "libbb.h" 13 22 … … 15 24 int rdev_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 16 25 { 17 c har const * constroot_device = find_block_device("/");26 const char *root_device = find_block_device("/"); 18 27 19 if (root_device != NULL) {28 if (root_device) { 20 29 printf("%s /\n", root_device); 21 30 return EXIT_SUCCESS; -
branches/3.2/mindi-busybox/util-linux/readprofile.c
r2725 r3232 32 32 * Paul Mundt <lethal@linux-sh.org>. 33 33 */ 34 35 //usage:#define readprofile_trivial_usage 36 //usage: "[OPTIONS]" 37 //usage:#define readprofile_full_usage "\n\n" 38 //usage: " -m mapfile (Default: /boot/System.map)" 39 //usage: "\n -p profile (Default: /proc/profile)" 40 //usage: "\n -M NUM Set the profiling multiplier to NUM" 41 //usage: "\n -i Print only info about the sampling step" 42 //usage: "\n -v Verbose" 43 //usage: "\n -a Print all symbols, even if count is 0" 44 //usage: "\n -b Print individual histogram-bin counts" 45 //usage: "\n -s Print individual counters within functions" 46 //usage: "\n -r Reset all the counters (root only)" 47 //usage: "\n -n Disable byte order auto-detection" 34 48 35 49 #include "libbb.h" … … 150 164 if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3) 151 165 bb_error_msg_and_die("%s(%i): wrong map line", 152 166 mapFile, maplineno); 153 167 154 168 if (!strcmp(fn_name, "_stext")) /* only elf works like this */ { … … 185 199 if (indx >= len / sizeof(*buf)) 186 200 bb_error_msg_and_die("profile address out of range. " 187 201 "Wrong map file?"); 188 202 189 203 while (indx < (next_add-add0)/step) { … … 207 221 if (optVerbose) 208 222 printf("%016llx %-40s %6i %8.4f\n", fn_add, 209 223 fn_name, this, this/(double)fn_len); 210 224 else 211 225 printf("%6i %-40s %8.4f\n", 212 226 this, fn_name, this/(double)fn_len); 213 227 if (optSub) { 214 228 unsigned long long scan; … … 220 234 addr = (scan - 1)*step + add0; 221 235 printf("\t%#llx\t%s+%#llx\t%u\n", 222 223 236 addr, fn_name, addr - fn_add, 237 buf[scan]); 224 238 } 225 239 } … … 238 252 if (optVerbose) 239 253 printf("%016x %-40s %6i %8.4f\n", 240 254 0, "total", total, total/(double)(fn_add-add0)); 241 255 else 242 256 printf("%6i %-40s %8.4f\n", 243 257 total, "total", total/(double)(fn_add-add0)); 244 258 245 259 fclose(map); -
branches/3.2/mindi-busybox/util-linux/rev.c
r2725 r3232 7 7 */ 8 8 9 //applet:IF_REV(APPLET(rev, _BB_DIR_BIN, _BB_SUID_DROP))9 //applet:IF_REV(APPLET(rev, BB_DIR_BIN, BB_SUID_DROP)) 10 10 11 11 //kbuild:lib-$(CONFIG_REV) += rev.o -
branches/3.2/mindi-busybox/util-linux/rtcwake.c
r2725 r3232 23 23 * That flag should not be needed on systems with adjtime support. 24 24 */ 25 26 //usage:#define rtcwake_trivial_usage 27 //usage: "[-a | -l | -u] [-d DEV] [-m MODE] [-s SEC | -t TIME]" 28 //usage:#define rtcwake_full_usage "\n\n" 29 //usage: "Enter a system sleep state until specified wakeup time\n" 30 //usage: IF_LONG_OPTS( 31 //usage: "\n -a,--auto Read clock mode from adjtime" 32 //usage: "\n -l,--local Clock is set to local time" 33 //usage: "\n -u,--utc Clock is set to UTC time" 34 //usage: "\n -d,--device=DEV Specify the RTC device" 35 //usage: "\n -m,--mode=MODE Set the sleep state (default: standby)" 36 //usage: "\n -s,--seconds=SEC Set the timeout in SEC seconds from now" 37 //usage: "\n -t,--time=TIME Set the timeout to TIME seconds from epoch" 38 //usage: ) 39 //usage: IF_NOT_LONG_OPTS( 40 //usage: "\n -a Read clock mode from adjtime" 41 //usage: "\n -l Clock is set to local time" 42 //usage: "\n -u Clock is set to UTC time" 43 //usage: "\n -d DEV Specify the RTC device" 44 //usage: "\n -m MODE Set the sleep state (default: standby)" 45 //usage: "\n -s SEC Set the timeout in SEC seconds from now" 46 //usage: "\n -t TIME Set the timeout to TIME seconds from epoch" 47 //usage: ) 25 48 26 49 #include "libbb.h" -
branches/3.2/mindi-busybox/util-linux/script.c
r2725 r3232 11 11 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 12 12 */ 13 14 //usage:#define script_trivial_usage 15 //usage: "[-afq" IF_SCRIPTREPLAY("t") "] [-c PROG] [OUTFILE]" 16 //usage:#define script_full_usage "\n\n" 17 //usage: " -a Append output" 18 //usage: "\n -c PROG Run PROG, not shell" 19 //usage: "\n -f Flush output after each write" 20 //usage: "\n -q Quiet" 21 //usage: IF_SCRIPTREPLAY( 22 //usage: "\n -t Send timing to stderr" 23 //usage: ) 24 13 25 #include "libbb.h" 14 26 … … 66 78 printf("Script started, file is %s\n", fname); 67 79 } 68 shell = getenv("SHELL"); 69 if (shell == NULL) { 70 shell = DEFAULT_SHELL; 71 } 80 shell = get_shell_name(); 72 81 73 82 pty = xgetpty(pty_line); -
branches/3.2/mindi-busybox/util-linux/scriptreplay.c
r2725 r3232 8 8 * 9 9 */ 10 11 //usage:#define scriptreplay_trivial_usage 12 //usage: "timingfile [typescript [divisor]]" 13 //usage:#define scriptreplay_full_usage "\n\n" 14 //usage: "Play back typescripts, using timing information" 15 10 16 #include "libbb.h" 11 17 -
branches/3.2/mindi-busybox/util-linux/setarch.c
r2725 r3232 6 6 * 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 */ 8 */ 9 10 //usage:#define setarch_trivial_usage 11 //usage: "personality PROG ARGS" 12 //usage:#define setarch_full_usage "\n\n" 13 //usage: "Personality may be:\n" 14 //usage: " linux32 Set 32bit uname emulation\n" 15 //usage: " linux64 Set 64bit uname emulation" 16 //usage: 17 //usage:#define linux32_trivial_usage NOUSAGE_STR 18 //usage:#define linux32_full_usage "" 19 //usage: 20 //usage:#define linux64_trivial_usage NOUSAGE_STR 21 //usage:#define linux64_full_usage "" 9 22 10 23 #include <sys/personality.h> -
branches/3.2/mindi-busybox/util-linux/swaponoff.c
r2725 r3232 8 8 */ 9 9 10 //usage:#define swapon_trivial_usage 11 //usage: "[-a]" IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]" 12 //usage:#define swapon_full_usage "\n\n" 13 //usage: "Start swapping on DEVICE\n" 14 //usage: "\n -a Start swapping on all swap devices" 15 //usage: IF_FEATURE_SWAPON_PRI( 16 //usage: "\n -p PRI Set swap device priority" 17 //usage: ) 18 //usage: 19 //usage:#define swapoff_trivial_usage 20 //usage: "[-a] [DEVICE]" 21 //usage:#define swapoff_full_usage "\n\n" 22 //usage: "Stop swapping on DEVICE\n" 23 //usage: "\n -a Stop swapping on all swap devices" 24 10 25 #include "libbb.h" 11 26 #include <mntent.h> 12 #include <sys/swap.h> 27 #ifndef __BIONIC__ 28 # include <sys/swap.h> 29 #endif 13 30 14 31 #if ENABLE_FEATURE_MOUNT_LABEL … … 16 33 #else 17 34 # define resolve_mount_spec(fsname) ((void)0) 35 #endif 36 37 #ifndef MNTTYPE_SWAP 38 # define MNTTYPE_SWAP "swap" 18 39 #endif 19 40 … … 27 48 #define g_flags 0 28 49 #endif 50 #define INIT_G() do { } while (0) 29 51 30 52 static int swap_enable_disable(char *device) … … 90 112 int ret; 91 113 114 INIT_G(); 115 92 116 #if !ENABLE_FEATURE_SWAPON_PRI 93 117 ret = getopt32(argv, "a"); 94 118 #else 95 opt_complementary = "p+"; 119 if (applet_name[5] == 'n') 120 opt_complementary = "p+"; 96 121 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags); 97 122 -
branches/3.2/mindi-busybox/util-linux/switch_root.c
r2725 r3232 6 6 * Licensed under GPLv2, see file LICENSE in this source tree. 7 7 */ 8 9 //usage:#define switch_root_trivial_usage 10 //usage: "[-c /dev/console] NEW_ROOT NEW_INIT [ARGS]" 11 //usage:#define switch_root_full_usage "\n\n" 12 //usage: "Free initramfs and switch to another root fs:\n" 13 //usage: "chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,\n" 14 //usage: "execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.\n" 15 //usage: "\n -c DEV Reopen stdio to DEV after switch" 16 8 17 #include <sys/vfs.h> 9 18 #include <sys/mount.h> … … 106 115 xchroot("."); 107 116 // The chdir is needed to recalculate "." and ".." links 108 xchdir("/");117 /*xchdir("/"); - done in xchroot */ 109 118 110 119 // If a new console specified, redirect stdin/stdout/stderr to it -
branches/3.2/mindi-busybox/util-linux/umount.c
r2725 r3232 8 8 * Licensed under GPLv2, see file LICENSE in this source tree. 9 9 */ 10 11 //usage:#define umount_trivial_usage 12 //usage: "[OPTIONS] FILESYSTEM|DIRECTORY" 13 //usage:#define umount_full_usage "\n\n" 14 //usage: "Unmount file systems\n" 15 //usage: IF_FEATURE_UMOUNT_ALL( 16 //usage: "\n -a Unmount all file systems" IF_FEATURE_MTAB_SUPPORT(" in /etc/mtab") 17 //usage: ) 18 //usage: IF_FEATURE_MTAB_SUPPORT( 19 //usage: "\n -n Don't erase /etc/mtab entries" 20 //usage: ) 21 //usage: "\n -r Try to remount devices as read-only if mount is busy" 22 //usage: "\n -l Lazy umount (detach filesystem)" 23 //usage: "\n -f Force umount (i.e., unreachable NFS server)" 24 //usage: IF_FEATURE_MOUNT_LOOP( 25 //usage: "\n -D Don't free loop device even if it has been used" 26 //usage: ) 27 //usage: 28 //usage:#define umount_example_usage 29 //usage: "$ umount /dev/hdc1\n" 30 10 31 #include <mntent.h> 11 32 #include <sys/mount.h> … … 24 45 #endif 25 46 26 /* ignored: -v -d -t -i */ 27 #define OPTION_STRING "fldnra" "vdt:i" 47 /* Ignored: -v -t -i 48 * bbox always acts as if -d is present. 49 * -D can be used to suppress it (bbox extension). 50 * Rationale: 51 * (1) util-linux's umount does it if "loop=..." is seen in /etc/mtab: 52 * thus, on many systems, bare umount _does_ drop loop devices. 53 * (2) many users request this feature. 54 */ 55 #define OPTION_STRING "fldDnra" "vt:i" 28 56 #define OPT_FORCE (1 << 0) // Same as MNT_FORCE 29 57 #define OPT_LAZY (1 << 1) // Same as MNT_DETACH 30 #define OPT_FREELOOP (1 << 2) 31 #define OPT_NO_MTAB (1 << 3) 32 #define OPT_REMOUNT (1 << 4) 33 #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 5) : 0) 58 //#define OPT_FREE_LOOP (1 << 2) // -d is assumed always present 59 #define OPT_DONT_FREE_LOOP (1 << 3) 60 #define OPT_NO_MTAB (1 << 4) 61 #define OPT_REMOUNT (1 << 5) 62 #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 6) : 0) 34 63 35 64 int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 145 174 // De-allocate the loop device. This ioctl should be ignored on 146 175 // any non-loop block devices. 147 if (ENABLE_FEATURE_MOUNT_LOOP && (opt & OPT_FREELOOP) && m)176 if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONT_FREE_LOOP) && m) 148 177 del_loop(m->device); 149 178 if (ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m) -
branches/3.2/mindi-busybox/util-linux/volume_id/Kbuild.src
r2725 r3232 32 32 ### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o 33 33 ### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o 34 lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o 34 35 lib-$(CONFIG_FEATURE_VOLUMEID_NTFS) += ntfs.o 36 lib-$(CONFIG_FEATURE_VOLUMEID_EXFAT) += exfat.o 35 37 lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o 36 38 lib-$(CONFIG_FEATURE_VOLUMEID_UDF) += udf.o -
branches/3.2/mindi-busybox/util-linux/volume_id/btrfs.c
r2725 r3232 103 103 volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE); 104 104 volume_id_set_uuid(id, sb->fsid, UUID_DCE); 105 IF_FEATURE_BLKID_TYPE(id->type = "btrfs";) 105 106 106 107 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/cramfs.c
r2725 r3232 52 52 53 53 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 54 // id->type = "cramfs"; 54 IF_FEATURE_BLKID_TYPE(id->type = "cramfs";) 55 55 return 0; 56 56 } -
branches/3.2/mindi-busybox/util-linux/volume_id/ext.c
r2725 r3232 20 20 21 21 #include "volume_id_internal.h" 22 #include "bb_e2fs_defs.h" 22 23 23 struct ext2_super_block {24 uint32_t inodes_count;25 uint32_t blocks_count;26 uint32_t r_blocks_count;27 uint32_t free_blocks_count;28 uint32_t free_inodes_count;29 uint32_t first_data_block;30 uint32_t log_block_size;31 uint32_t dummy3[7];32 uint8_t magic[2];33 uint16_t state;34 uint32_t dummy5[8];35 uint32_t feature_compat;36 uint32_t feature_incompat;37 uint32_t feature_ro_compat;38 uint8_t uuid[16];39 uint8_t volume_name[16];40 } PACKED;41 42 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0000000443 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0000000844 24 #define EXT_SUPERBLOCK_OFFSET 0x400 45 25 … … 55 35 return -1; 56 36 57 if (es-> magic[0] != 0123 || es->magic[1] != 0357) {37 if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) { 58 38 dbg("ext: no magic found"); 59 39 return -1; … … 62 42 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 63 43 // volume_id_set_label_raw(id, es->volume_name, 16); 64 volume_id_set_label_string(id, es->volume_name, 16);65 volume_id_set_uuid(id, es-> uuid, UUID_DCE);44 volume_id_set_label_string(id, (void*)es->s_volume_name, 16); 45 volume_id_set_uuid(id, es->s_uuid, UUID_DCE); 66 46 dbg("ext: label '%s' uuid '%s'", id->label, id->uuid); 67 47 68 // if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) 69 // id->type = "ext3"; 70 // else 71 // id->type = "ext2"; 72 48 #if ENABLE_FEATURE_BLKID_TYPE 49 if ((es->s_feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) 50 || (es->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT)) 51 ) { 52 id->type = "ext4"; 53 } 54 else if (es->s_feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL)) 55 id->type = "ext3"; 56 else 57 id->type = "ext2"; 58 #endif 73 59 return 0; 74 60 } -
branches/3.2/mindi-busybox/util-linux/volume_id/fat.c
r2725 r3232 333 333 ret: 334 334 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 335 // id->type = "vfat"; 335 IF_FEATURE_BLKID_TYPE(id->type = "vfat";) 336 336 337 337 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/get_devname.c
r2725 r3232 20 20 char *label; 21 21 char *uc_uuid; /* prefix makes it easier to grep for */ 22 IF_FEATURE_BLKID_TYPE(const char *type;) 22 23 } *uuidCache; 24 25 #if !ENABLE_FEATURE_BLKID_TYPE 26 #define get_label_uuid(fd, label, uuid, type) \ 27 get_label_uuid(fd, label, uuid) 28 #define uuidcache_addentry(device, label, uuid, type) \ 29 uuidcache_addentry(device, label, uuid) 30 #endif 23 31 24 32 /* Returns !0 on error. … … 27 35 * NB: closes fd. */ 28 36 static int 29 get_label_uuid(int fd, char **label, char **uuid )37 get_label_uuid(int fd, char **label, char **uuid, const char **type) 30 38 { 31 39 int rv = 1; … … 42 50 goto ret; 43 51 44 if (vid->label[0] != '\0' || vid->uuid[0] != '\0') { 52 if (vid->label[0] != '\0' || vid->uuid[0] != '\0' 53 #if ENABLE_FEATURE_BLKID_TYPE 54 || vid->type != NULL 55 #endif 56 ) { 45 57 *label = xstrndup(vid->label, sizeof(vid->label)); 46 58 *uuid = xstrndup(vid->uuid, sizeof(vid->uuid)); 59 #if ENABLE_FEATURE_BLKID_TYPE 60 *type = vid->type; 61 dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type); 62 #else 47 63 dbg("found label '%s', uuid '%s'", *label, *uuid); 64 #endif 48 65 rv = 0; 49 66 } … … 55 72 /* NB: we take ownership of (malloc'ed) label and uuid */ 56 73 static void 57 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid )74 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type) 58 75 { 59 76 struct uuidCache_s *last; … … 73 90 last->label = label; 74 91 last->uc_uuid = uuid; 92 IF_FEATURE_BLKID_TYPE(last->type = type;) 75 93 } 76 94 … … 84 102 int depth UNUSED_PARAM) 85 103 { 86 char *uuid = uuid; /* for compiler */87 char *label = label;88 int fd;89 90 104 /* note: this check rejects links to devices, among other nodes */ 91 105 if (!S_ISBLK(statbuf->st_mode)) … … 100 114 return TRUE; 101 115 102 fd = open(device, O_RDONLY); 103 if (fd < 0) 104 return TRUE; 105 106 /* get_label_uuid() closes fd in all cases (success & failure) */ 107 if (get_label_uuid(fd, &label, &uuid) == 0) { 108 /* uuidcache_addentry() takes ownership of all three params */ 109 uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid); 110 } 116 add_to_uuid_cache(device); 117 111 118 return TRUE; 112 119 } 113 120 114 static void 115 uuidcache_init(void) 116 { 121 static struct uuidCache_s* 122 uuidcache_init(int scan_devices) 123 { 124 dbg("DBG: uuidCache=%x, uuidCache"); 117 125 if (uuidCache) 118 return ;126 return uuidCache; 119 127 120 128 /* We were scanning /proc/partitions … … 128 136 * (Maybe add scanning of /sys/block/XXX/dev for devices 129 137 * somehow not having their /dev/XXX entries created?) */ 130 131 recursive_action("/dev", ACTION_RECURSE, 132 uuidcache_check_device, /* file_action */ 133 NULL, /* dir_action */ 134 NULL, /* userData */ 135 0 /* depth */); 138 if (scan_devices) 139 recursive_action("/dev", ACTION_RECURSE, 140 uuidcache_check_device, /* file_action */ 141 NULL, /* dir_action */ 142 NULL, /* userData */ 143 0 /* depth */); 144 145 return uuidCache; 136 146 } 137 147 … … 145 155 struct uuidCache_s *uc; 146 156 147 uuidcache_init(); 148 uc = uuidCache; 149 157 uc = uuidcache_init(/*scan_devices:*/ 1); 150 158 while (uc) { 151 159 switch (n) { … … 212 220 213 221 /* Used by blkid */ 214 void display_uuid_cache(void) 215 { 216 struct uuidCache_s *u; 217 218 uuidcache_init(); 219 u = uuidCache; 220 while (u) { 221 printf("%s:", u->device); 222 if (u->label[0]) 223 printf(" LABEL=\"%s\"", u->label); 224 if (u->uc_uuid[0]) 225 printf(" UUID=\"%s\"", u->uc_uuid); 222 void display_uuid_cache(int scan_devices) 223 { 224 struct uuidCache_s *uc; 225 226 uc = uuidcache_init(scan_devices); 227 while (uc) { 228 printf("%s:", uc->device); 229 if (uc->label[0]) 230 printf(" LABEL=\"%s\"", uc->label); 231 if (uc->uc_uuid[0]) 232 printf(" UUID=\"%s\"", uc->uc_uuid); 233 #if ENABLE_FEATURE_BLKID_TYPE 234 if (uc->type) 235 printf(" TYPE=\"%s\"", uc->type); 236 #endif 226 237 bb_putchar('\n'); 227 u = u->next; 228 } 229 } 238 uc = uc->next; 239 } 240 } 241 242 int add_to_uuid_cache(const char *device) 243 { 244 char *uuid = uuid; /* for compiler */ 245 char *label = label; 246 #if ENABLE_FEATURE_BLKID_TYPE 247 const char *type = type; 248 #endif 249 int fd; 250 251 fd = open(device, O_RDONLY); 252 if (fd < 0) 253 return 0; 254 255 /* get_label_uuid() closes fd in all cases (success & failure) */ 256 if (get_label_uuid(fd, &label, &uuid, &type) == 0) { 257 /* uuidcache_addentry() takes ownership of all four params */ 258 uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type); 259 return 1; 260 } 261 return 0; 262 } 263 230 264 231 265 /* Used by mount and findfs */ … … 235 269 struct uuidCache_s *uc; 236 270 237 uuidcache_init(); 238 uc = uuidCache; 271 uc = uuidcache_init(/*scan_devices:*/ 1); 239 272 while (uc) { 240 273 if (uc->label[0] && strcmp(spec, uc->label) == 0) { … … 250 283 struct uuidCache_s *uc; 251 284 252 uuidcache_init(); 253 uc = uuidCache; 285 uc = uuidcache_init(/*scan_devices:*/ 1); 254 286 while (uc) { 255 287 /* case of hex numbers doesn't matter */ -
branches/3.2/mindi-busybox/util-linux/volume_id/hfs.c
r2725 r3232 132 132 #define HFSPLUS_POR_CNID 1 133 133 134 static void FAST_FUNC hfs_set_uuid(struct volume_id *id, const uint8_t *hfs_id) 135 { 136 #define hfs_id_len 8 137 md5_ctx_t md5c; 138 uint8_t uuid[16]; 139 unsigned i; 140 141 for (i = 0; i < hfs_id_len; i++) 142 if (hfs_id[i] != 0) 143 goto do_md5; 144 return; 145 do_md5: 146 md5_begin(&md5c); 147 md5_hash(&md5c, "\263\342\17\71\362\222\21\326\227\244\0\60\145\103\354\254", 16); 148 md5_hash(&md5c, hfs_id, hfs_id_len); 149 md5_end(&md5c, uuid); 150 uuid[6] = 0x30 | (uuid[6] & 0x0f); 151 uuid[8] = 0x80 | (uuid[8] & 0x3f); 152 volume_id_set_uuid(id, uuid, UUID_DCE); 153 } 154 134 155 int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/) 135 156 { … … 194 215 } 195 216 196 volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS);217 hfs_set_uuid(id, hfs->finder_info.id); 197 218 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 198 // id->type = "hfs"; 219 IF_FEATURE_BLKID_TYPE(id->type = "hfs";) 199 220 200 221 return 0; … … 208 229 209 230 hfsplus: 210 volume_id_set_uuid(id, hfsplus->finder_info.id, UUID_HFS);231 hfs_set_uuid(id, hfsplus->finder_info.id); 211 232 212 233 blocksize = be32_to_cpu(hfsplus->blocksize); … … 287 308 found: 288 309 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 289 // id->type = "hfsplus"; 310 IF_FEATURE_BLKID_TYPE(id->type = "hfsplus";) 290 311 291 312 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/iso9660.c
r2725 r3232 115 115 found: 116 116 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 117 // id->type = "iso9660"; 117 IF_FEATURE_BLKID_TYPE(id->type = "iso9660";) 118 118 119 119 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/jfs.c
r2725 r3232 55 55 56 56 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 57 // id->type = "jfs"; 57 IF_FEATURE_BLKID_TYPE(id->type = "jfs";) 58 58 59 59 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/linux_raid.c
r2725 r3232 70 70 71 71 // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u", 72 // 73 // 74 // 72 // le32_to_cpu(mdp->major_version), 73 // le32_to_cpu(mdp->minor_version), 74 // le32_to_cpu(mdp->patch_version)); 75 75 76 76 dbg("found raid signature"); 77 77 // volume_id_set_usage(id, VOLUME_ID_RAID); 78 // id->type = "linux_raid_member"; 78 IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";) 79 79 80 80 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/linux_swap.c
r2725 r3232 73 73 found: 74 74 // volume_id_set_usage(id, VOLUME_ID_OTHER); 75 // id->type = "swap"; 75 IF_FEATURE_BLKID_TYPE(id->type = "swap";) 76 76 77 77 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/luks.c
r2725 r3232 95 95 // volume_id_set_usage(id, VOLUME_ID_CRYPTO); 96 96 volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING); 97 // id->type = "crypto_LUKS"; 97 IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";) 98 98 99 99 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/ntfs.c
r2725 r3232 133 133 134 134 buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size), 135 135 mft_record_size); 136 136 if (buf == NULL) 137 137 goto found; … … 151 151 attr = (struct file_attribute*) &buf[attr_off]; 152 152 attr_type = le32_to_cpu(attr->type); 153 attr_len = le 16_to_cpu(attr->len);153 attr_len = le32_to_cpu(attr->len); 154 154 val_off = le16_to_cpu(attr->value_offset); 155 155 val_len = le32_to_cpu(attr->value_len); … … 166 166 167 167 dbg("found attribute type 0x%x, len %i, at offset %i", 168 168 attr_type, attr_len, attr_off); 169 169 170 170 // if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) { … … 189 189 found: 190 190 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 191 // id->type = "ntfs"; 191 IF_FEATURE_BLKID_TYPE(id->type = "ntfs";) 192 192 193 193 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/ocfs2.c
r2725 r3232 102 102 OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE); 103 103 volume_id_set_uuid(id, os->s_uuid, UUID_DCE); 104 // id->type = "ocfs2"; 104 IF_FEATURE_BLKID_TYPE(id->type = "ocfs2";) 105 105 return 0; 106 106 } -
branches/3.2/mindi-busybox/util-linux/volume_id/reiserfs.c
r2725 r3232 108 108 found: 109 109 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 110 // id->type = "reiserfs"; 110 IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";) 111 111 112 112 return 0; -
branches/3.2/mindi-busybox/util-linux/volume_id/romfs.c
r2725 r3232 48 48 49 49 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 50 // id->type = "romfs"; 50 IF_FEATURE_BLKID_TYPE(id->type = "romfs";) 51 51 return 0; 52 52 } -
branches/3.2/mindi-busybox/util-linux/volume_id/sysv.c
r2725 r3232 100 100 // volume_id_set_label_raw(id, vs->s_fname, 6); 101 101 volume_id_set_label_string(id, vs->s_fname, 6); 102 // id->type = "sysv";102 IF_FEATURE_BLKID_TYPE(id->type = "sysv"); 103 103 goto found; 104 104 } … … 113 113 // volume_id_set_label_raw(id, xs->s_fname, 6); 114 114 volume_id_set_label_string(id, xs->s_fname, 6); 115 // id->type = "xenix"; 115 IF_FEATURE_BLKID_TYPE(id->type = "xenix";) 116 116 goto found; 117 117 } -
branches/3.2/mindi-busybox/util-linux/volume_id/udf.c
r2725 r3232 110 110 111 111 dbg("vsd: %c%c%c%c%c", 112 112 vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); 113 113 114 114 if (vsd->id[0] == '\0') … … 168 168 found: 169 169 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 170 // id->type = "udf"; 171 170 IF_FEATURE_BLKID_TYPE(id->type = "udf";) 172 171 return 0; 173 172 } -
branches/3.2/mindi-busybox/util-linux/volume_id/unused_msdos.c
r2725 r3232 110 110 } else { 111 111 dbg("found 0x%x data partition at 0x%llx, len 0x%llx", 112 112 part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen); 113 113 114 114 // if (is_raid(part[i].sys_ind)) -
branches/3.2/mindi-busybox/util-linux/volume_id/unused_silicon_raid.c
r2725 r3232 63 63 // volume_id_set_usage(id, VOLUME_ID_RAID); 64 64 // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", 65 // 65 // le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); 66 66 // id->type = "silicon_medley_raid_member"; 67 67 -
branches/3.2/mindi-busybox/util-linux/volume_id/util.c
r2725 r3232 32 32 else 33 33 c = (buf[i] << 8) | buf[i+1]; 34 if (c == 0) { 35 str[j] = '\0'; 34 if (c == 0) 36 35 break; 37 } else if (c < 0x80) { 38 if (j+1 >= len) 39 break; 40 str[j++] = (uint8_t) c; 41 } else if (c < 0x800) { 36 if (j+1 >= len) 37 break; 38 if (c < 0x80) { 39 /* 0xxxxxxx */ 40 } else { 41 uint8_t topbits = 0xc0; 42 42 if (j+2 >= len) 43 43 break; 44 str[j++] = (uint8_t) (0xc0 | (c >> 6)); 45 str[j++] = (uint8_t) (0x80 | (c & 0x3f)); 46 } else { 47 if (j+3 >= len) 48 break; 49 str[j++] = (uint8_t) (0xe0 | (c >> 12)); 50 str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f)); 51 str[j++] = (uint8_t) (0x80 | (c & 0x3f)); 44 if (c < 0x800) { 45 /* 110yyyxx 10xxxxxx */ 46 } else { 47 if (j+3 >= len) 48 break; 49 /* 1110yyyy 10yyyyxx 10xxxxxx */ 50 str[j++] = (uint8_t) (0xe0 | (c >> 12)); 51 topbits = 0x80; 52 } 53 str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f)); 54 c = 0x80 | (c & 0x3f); 52 55 } 56 str[j++] = (uint8_t) c; 53 57 } 54 58 str[j] = '\0'; … … 126 130 void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count) 127 131 { 128 132 volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count); 129 133 } 130 134 … … 132 136 { 133 137 unsigned i; 134 unsigned count = 0; 135 136 switch (format) { 137 case UUID_DOS: 138 count = 4; 139 break; 140 case UUID_NTFS: 141 case UUID_HFS: 142 count = 8; 143 break; 144 case UUID_DCE: 145 count = 16; 146 break; 147 case UUID_DCE_STRING: 148 /* 36 is ok, id->uuid has one extra byte for NUL */ 149 count = VOLUME_ID_UUID_SIZE; 150 break; 151 } 138 unsigned count = (format == UUID_DCE_STRING ? VOLUME_ID_UUID_SIZE : 4 << format); 139 152 140 // memcpy(id->uuid_raw, buf, count); 153 141 // id->uuid_raw_len = count; … … 169 157 buf[7], buf[6], buf[5], buf[4], 170 158 buf[3], buf[2], buf[1], buf[0]); 171 break;172 case UUID_HFS:173 sprintf(id->uuid, "%02X%02X%02X%02X%02X%02X%02X%02X",174 buf[0], buf[1], buf[2], buf[3],175 buf[4], buf[5], buf[6], buf[7]);176 159 break; 177 160 case UUID_DCE: -
branches/3.2/mindi-busybox/util-linux/volume_id/volume_id.c
r2725 r3232 94 94 volume_id_probe_vfat, 95 95 #endif 96 #if ENABLE_FEATURE_VOLUMEID_EXFAT 97 volume_id_probe_exfat, 98 #endif 96 99 #if ENABLE_FEATURE_VOLUMEID_MAC 97 100 volume_id_probe_mac_partition_map, 101 #endif 102 #if ENABLE_FEATURE_VOLUMEID_SQUASHFS 103 volume_id_probe_squashfs, 98 104 #endif 99 105 #if ENABLE_FEATURE_VOLUMEID_XFS … … 130 136 #if ENABLE_FEATURE_VOLUMEID_UFS 131 137 volume_id_probe_ufs, 138 #endif 139 #if ENABLE_FEATURE_VOLUMEID_NILFS 140 volume_id_probe_nilfs, 132 141 #endif 133 142 #if ENABLE_FEATURE_VOLUMEID_NTFS -
branches/3.2/mindi-busybox/util-linux/volume_id/volume_id_internal.h
r2725 r3232 81 81 // smallint usage_id; 82 82 // const char *usage; 83 // const char *type; 83 #if ENABLE_FEATURE_BLKID_TYPE 84 const char *type; 85 #endif 84 86 }; 85 87 … … 135 137 #endif 136 138 139 /* volume_id_set_uuid(id,buf,fmt) assumes size of uuid buf 140 * by shifting: 4 << fmt, except for fmt == UUID_DCE_STRING. 141 * The constants below should match sizes. 142 */ 137 143 enum uuid_format { 138 UUID_DCE_STRING, 139 UUID_DCE, 140 UUID_DOS, 141 UUID_NTFS, 142 UUID_HFS, 144 UUID_DOS = 0, /* 4 bytes */ 145 UUID_NTFS = 1, /* 8 bytes */ 146 UUID_DCE = 2, /* 16 bytes */ 147 UUID_DCE_STRING = 3, /* 36 bytes (VOLUME_ID_UUID_SIZE) */ 143 148 }; 144 149 … … 211 216 //int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id /*,uint64_t off*/); 212 217 218 int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/); 219 213 220 int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/); 214 221 222 int FAST_FUNC volume_id_probe_exfat(struct volume_id *id /*,uint64_t off*/); 223 215 224 int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/); 216 225 … … 219 228 int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/); 220 229 230 int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/); 231 221 232 int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/); 222 233 -
branches/3.2/mindi-busybox/util-linux/volume_id/xfs.c
r2725 r3232 55 55 56 56 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); 57 // id->type = "xfs"; 57 IF_FEATURE_BLKID_TYPE(id->type = "xfs";) 58 58 59 59 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.