diff options
| author | Ron Yorston <rmy@pobox.com> | 2016-04-04 16:22:54 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2016-04-04 16:22:54 +0100 |
| commit | 253dbd612b2d2f041f4263e15a3b94df70f41e36 (patch) | |
| tree | f6c6e12a0541233058a7f7ccb1251afeb457da06 /miscutils | |
| parent | 3cf56a021d7a62512b477640e930e1a78288075c (diff) | |
| parent | d7d4750e1e213e7448147186dddfe3bfbb47eea0 (diff) | |
| download | busybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.tar.gz busybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.tar.bz2 busybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/beep.c | 2 | ||||
| -rw-r--r-- | miscutils/devfsd.c | 2 | ||||
| -rw-r--r-- | miscutils/eject.c | 26 | ||||
| -rw-r--r-- | miscutils/flash_eraseall.c | 2 | ||||
| -rw-r--r-- | miscutils/inotifyd.c | 4 | ||||
| -rw-r--r-- | miscutils/taskset.c | 37 | ||||
| -rw-r--r-- | miscutils/ubi_tools.c | 29 | ||||
| -rw-r--r-- | miscutils/ubirename.c | 94 |
8 files changed, 152 insertions, 44 deletions
diff --git a/miscutils/beep.c b/miscutils/beep.c index 910e03e1b..18b160cc4 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c | |||
| @@ -88,7 +88,7 @@ int beep_main(int argc, char **argv) | |||
| 88 | bb_show_usage(); | 88 | bb_show_usage(); |
| 89 | } | 89 | } |
| 90 | while (rep) { | 90 | while (rep) { |
| 91 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); | 91 | //bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); |
| 92 | xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq); | 92 | xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq); |
| 93 | usleep(1000 * length); | 93 | usleep(1000 * length); |
| 94 | ioctl(speaker, KIOCSOUND, (void*)0); | 94 | ioctl(speaker, KIOCSOUND, (void*)0); |
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 9256567cc..6217918da 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
| @@ -284,7 +284,7 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found"; | |||
| 284 | 284 | ||
| 285 | /* Busybox stuff */ | 285 | /* Busybox stuff */ |
| 286 | #if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG | 286 | #if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG |
| 287 | #define info_logger(p, fmt, args...) bb_info_msg(fmt, ## args) | 287 | #define info_logger(p, fmt, args...) bb_error_msg(fmt, ## args) |
| 288 | #define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args) | 288 | #define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args) |
| 289 | #define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args) | 289 | #define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args) |
| 290 | #define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args) | 290 | #define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args) |
diff --git a/miscutils/eject.c b/miscutils/eject.c index a20e04b7f..e33d79127 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c | |||
| @@ -25,23 +25,19 @@ | |||
| 25 | 25 | ||
| 26 | #include <sys/mount.h> | 26 | #include <sys/mount.h> |
| 27 | #include "libbb.h" | 27 | #include "libbb.h" |
| 28 | #if ENABLE_FEATURE_EJECT_SCSI | ||
| 28 | /* Must be after libbb.h: they need size_t */ | 29 | /* Must be after libbb.h: they need size_t */ |
| 29 | #include "fix_u32.h" | 30 | # include "fix_u32.h" |
| 30 | #include <scsi/sg.h> | 31 | # include <scsi/sg.h> |
| 31 | #include <scsi/scsi.h> | 32 | # include <scsi/scsi.h> |
| 32 | 33 | #endif | |
| 33 | /* various defines swiped from linux/cdrom.h */ | ||
| 34 | #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ | ||
| 35 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ | ||
| 36 | #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ | ||
| 37 | /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ | ||
| 38 | #define CDS_TRAY_OPEN 2 | ||
| 39 | 34 | ||
| 40 | #define dev_fd 3 | 35 | #define dev_fd 3 |
| 41 | 36 | ||
| 42 | /* Code taken from the original eject (http://eject.sourceforge.net/), | 37 | /* Code taken from the original eject (http://eject.sourceforge.net/), |
| 43 | * refactored it a bit for busybox (ne-bb@nicoerfurth.de) */ | 38 | * refactored it a bit for busybox (ne-bb@nicoerfurth.de) */ |
| 44 | 39 | ||
| 40 | #if ENABLE_FEATURE_EJECT_SCSI | ||
| 45 | static void eject_scsi(const char *dev) | 41 | static void eject_scsi(const char *dev) |
| 46 | { | 42 | { |
| 47 | static const char sg_commands[3][6] = { | 43 | static const char sg_commands[3][6] = { |
| @@ -76,6 +72,16 @@ static void eject_scsi(const char *dev) | |||
| 76 | /* force kernel to reread partition table when new disc is inserted */ | 72 | /* force kernel to reread partition table when new disc is inserted */ |
| 77 | ioctl(dev_fd, BLKRRPART); | 73 | ioctl(dev_fd, BLKRRPART); |
| 78 | } | 74 | } |
| 75 | #else | ||
| 76 | # define eject_scsi(dev) ((void)0) | ||
| 77 | #endif | ||
| 78 | |||
| 79 | /* various defines swiped from linux/cdrom.h */ | ||
| 80 | #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ | ||
| 81 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ | ||
| 82 | #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ | ||
| 83 | /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ | ||
| 84 | #define CDS_TRAY_OPEN 2 | ||
| 79 | 85 | ||
| 80 | #define FLAG_CLOSE 1 | 86 | #define FLAG_CLOSE 1 |
| 81 | #define FLAG_SMART 2 | 87 | #define FLAG_SMART 2 |
diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c index bf9b739a1..d95d214d9 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c | |||
| @@ -147,7 +147,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv) | |||
| 147 | ret = ioctl(fd, MEMGETBADBLOCK, &offset); | 147 | ret = ioctl(fd, MEMGETBADBLOCK, &offset); |
| 148 | if (ret > 0) { | 148 | if (ret > 0) { |
| 149 | if (!(flags & OPTION_Q)) | 149 | if (!(flags & OPTION_Q)) |
| 150 | bb_info_msg("\nSkipping bad block at 0x%08x", erase.start); | 150 | printf("\nSkipping bad block at 0x%08x\n", erase.start); |
| 151 | continue; | 151 | continue; |
| 152 | } | 152 | } |
| 153 | if (ret < 0) { | 153 | if (ret < 0) { |
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c index 7a1a6a2e5..908d657fd 100644 --- a/miscutils/inotifyd.c +++ b/miscutils/inotifyd.c | |||
| @@ -47,8 +47,8 @@ | |||
| 47 | //usage: "\n o Event queue overflowed" | 47 | //usage: "\n o Event queue overflowed" |
| 48 | //usage: "\n x File can't be watched anymore" | 48 | //usage: "\n x File can't be watched anymore" |
| 49 | //usage: "\nIf watching a directory:" | 49 | //usage: "\nIf watching a directory:" |
| 50 | //usage: "\n m Subfile is moved into dir" | 50 | //usage: "\n y Subfile is moved into dir" |
| 51 | //usage: "\n y Subfile is moved out of dir" | 51 | //usage: "\n m Subfile is moved out of dir" |
| 52 | //usage: "\n n Subfile is created" | 52 | //usage: "\n n Subfile is created" |
| 53 | //usage: "\n d Subfile is deleted" | 53 | //usage: "\n d Subfile is deleted" |
| 54 | //usage: "\n" | 54 | //usage: "\n" |
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 100b1d926..fb352ab8d 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
| @@ -75,27 +75,26 @@ static char *from_cpuset(cpu_set_t *mask) | |||
| 75 | #define TASKSET_PRINTF_MASK "%llx" | 75 | #define TASKSET_PRINTF_MASK "%llx" |
| 76 | static unsigned long long from_cpuset(cpu_set_t *mask) | 76 | static unsigned long long from_cpuset(cpu_set_t *mask) |
| 77 | { | 77 | { |
| 78 | char *p = (void*)mask; | 78 | BUILD_BUG_ON(CPU_SETSIZE < 8*sizeof(int)); |
| 79 | 79 | ||
| 80 | BUILD_BUG_ON(CPU_SETSIZE < sizeof(int)); | 80 | /* Take the least significant bits. Assume cpu_set_t is |
| 81 | 81 | * implemented as an array of unsigned long or unsigned | |
| 82 | /* Take the least significant bits. Careful! | 82 | * int. |
| 83 | * Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases | ||
| 84 | */ | 83 | */ |
| 85 | #if BB_BIG_ENDIAN | 84 | if (CPU_SETSIZE < 8*sizeof(long)) |
| 86 | /* For big endian, it means LAST bits */ | 85 | return *(unsigned*)mask; |
| 87 | if (CPU_SETSIZE < sizeof(long)) | 86 | if (CPU_SETSIZE < 8*sizeof(long long)) |
| 88 | p += CPU_SETSIZE - sizeof(int); | 87 | return *(unsigned long*)mask; |
| 89 | else if (CPU_SETSIZE < sizeof(long long)) | 88 | # if BB_BIG_ENDIAN |
| 90 | p += CPU_SETSIZE - sizeof(long); | 89 | if (sizeof(long long) > sizeof(long)) { |
| 91 | else | 90 | /* We can put two long in the long long, but they have to |
| 92 | p += CPU_SETSIZE - sizeof(long long); | 91 | * be swapped: the least significant word comes first in the |
| 93 | #endif | 92 | * array */ |
| 94 | if (CPU_SETSIZE < sizeof(long)) | 93 | unsigned long *p = (void*)mask; |
| 95 | return *(unsigned*)p; | 94 | return p[0] + ((unsigned long long)p[1] << (8*sizeof(long))); |
| 96 | if (CPU_SETSIZE < sizeof(long long)) | 95 | } |
| 97 | return *(unsigned long*)p; | 96 | # endif |
| 98 | return *(unsigned long long*)p; | 97 | return *(unsigned long long*)mask; |
| 99 | } | 98 | } |
| 100 | #endif | 99 | #endif |
| 101 | 100 | ||
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index dd1bda300..4364bc807 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c | |||
| @@ -195,7 +195,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 195 | } else | 195 | } else |
| 196 | 196 | ||
| 197 | //usage:#define ubimkvol_trivial_usage | 197 | //usage:#define ubimkvol_trivial_usage |
| 198 | //usage: "UBI_DEVICE -N NAME [-s SIZE | -m]" | 198 | //usage: "-N NAME [-s SIZE | -m] UBI_DEVICE" |
| 199 | //usage:#define ubimkvol_full_usage "\n\n" | 199 | //usage:#define ubimkvol_full_usage "\n\n" |
| 200 | //usage: "Create UBI volume\n" | 200 | //usage: "Create UBI volume\n" |
| 201 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" | 201 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" |
| @@ -212,9 +212,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 212 | unsigned num; | 212 | unsigned num; |
| 213 | char *p; | 213 | char *p; |
| 214 | 214 | ||
| 215 | if (sscanf(ubi_ctrl, "/dev/ubi%u", &num) != 1) | 215 | num = ubi_devnum_from_devname(ubi_ctrl); |
| 216 | bb_error_msg_and_die("wrong format of UBI device name"); | ||
| 217 | |||
| 218 | p = path_sys_class_ubi_ubi + sprintf(path_sys_class_ubi_ubi, "%u/", num); | 216 | p = path_sys_class_ubi_ubi + sprintf(path_sys_class_ubi_ubi, "%u/", num); |
| 219 | 217 | ||
| 220 | strcpy(p, "avail_eraseblocks"); | 218 | strcpy(p, "avail_eraseblocks"); |
| @@ -248,20 +246,31 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 248 | } else | 246 | } else |
| 249 | 247 | ||
| 250 | //usage:#define ubirmvol_trivial_usage | 248 | //usage:#define ubirmvol_trivial_usage |
| 251 | //usage: "UBI_DEVICE -n VOLID" | 249 | //usage: "-n VOLID / -N VOLNAME UBI_DEVICE" |
| 252 | //usage:#define ubirmvol_full_usage "\n\n" | 250 | //usage:#define ubirmvol_full_usage "\n\n" |
| 253 | //usage: "Remove UBI volume\n" | 251 | //usage: "Remove UBI volume\n" |
| 254 | //usage: "\n -n VOLID Volume ID" | 252 | //usage: "\n -n VOLID Volume ID" |
| 253 | //usage: "\n -N VOLNAME Volume name" | ||
| 255 | if (do_rmvol) { | 254 | if (do_rmvol) { |
| 256 | if (!(opts & OPTION_n)) | 255 | if (!(opts & (OPTION_n|OPTION_N))) |
| 257 | bb_error_msg_and_die("volume id not specified"); | 256 | bb_error_msg_and_die("volume id not specified"); |
| 258 | 257 | ||
| 259 | /* FIXME? kernel expects int32_t* here: */ | 258 | if (opts & OPTION_N) { |
| 260 | xioctl(fd, UBI_IOCRMVOL, &vol_id); | 259 | unsigned num = ubi_devnum_from_devname(ubi_ctrl); |
| 260 | vol_id = ubi_get_volid_by_name(num, vol_name); | ||
| 261 | } | ||
| 262 | |||
| 263 | if (sizeof(vol_id) != 4) { | ||
| 264 | /* kernel expects int32_t* in this ioctl */ | ||
| 265 | int32_t t = vol_id; | ||
| 266 | xioctl(fd, UBI_IOCRMVOL, &t); | ||
| 267 | } else { | ||
| 268 | xioctl(fd, UBI_IOCRMVOL, &vol_id); | ||
| 269 | } | ||
| 261 | } else | 270 | } else |
| 262 | 271 | ||
| 263 | //usage:#define ubirsvol_trivial_usage | 272 | //usage:#define ubirsvol_trivial_usage |
| 264 | //usage: "UBI_DEVICE -n VOLID -s SIZE" | 273 | //usage: "-n VOLID -s SIZE UBI_DEVICE" |
| 265 | //usage:#define ubirsvol_full_usage "\n\n" | 274 | //usage:#define ubirsvol_full_usage "\n\n" |
| 266 | //usage: "Resize UBI volume\n" | 275 | //usage: "Resize UBI volume\n" |
| 267 | //usage: "\n -n VOLID Volume ID" | 276 | //usage: "\n -n VOLID Volume ID" |
| @@ -279,7 +288,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 279 | } else | 288 | } else |
| 280 | 289 | ||
| 281 | //usage:#define ubiupdatevol_trivial_usage | 290 | //usage:#define ubiupdatevol_trivial_usage |
| 282 | //usage: "UBI_DEVICE [-t | [-s SIZE] IMG_FILE]" | 291 | //usage: "[-t | [-s SIZE] IMG_FILE] UBI_DEVICE" |
| 283 | //usage:#define ubiupdatevol_full_usage "\n\n" | 292 | //usage:#define ubiupdatevol_full_usage "\n\n" |
| 284 | //usage: "Update UBI volume\n" | 293 | //usage: "Update UBI volume\n" |
| 285 | //usage: "\n -t Truncate to zero size" | 294 | //usage: "\n -t Truncate to zero size" |
diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c new file mode 100644 index 000000000..8b1c3785a --- /dev/null +++ b/miscutils/ubirename.c | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | /* ubirename - port of the ubirename from the mtd-utils package | ||
| 2 | * | ||
| 3 | * A utility to rename one UBI volume. | ||
| 4 | * | ||
| 5 | * 2016-03-01 Sven Eisenberg <sven.eisenberg@novero.com> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
| 8 | */ | ||
| 9 | //config:config UBIRENAME | ||
| 10 | //config: bool "ubirename" | ||
| 11 | //config: default y | ||
| 12 | //config: select PLATFORM_LINUX | ||
| 13 | //config: help | ||
| 14 | //config: Utility to rename UBI volumes | ||
| 15 | |||
| 16 | //applet:IF_UBIRENAME(APPLET(ubirename, BB_DIR_USR_SBIN, BB_SUID_DROP)) | ||
| 17 | |||
| 18 | //kbuild:lib-$(CONFIG_UBIRENAME) += ubirename.o | ||
| 19 | |||
| 20 | //usage:#define ubirename_trivial_usage | ||
| 21 | //usage: "UBI_DEVICE OLD_VOLNAME NEW_VOLNAME [OLD2 NEW2]..." | ||
| 22 | //usage:#define ubirename_full_usage "\n\n" | ||
| 23 | //usage: "Rename UBI volumes on UBI_DEVICE" | ||
| 24 | |||
| 25 | #include "libbb.h" | ||
| 26 | #include <mtd/mtd-user.h> | ||
| 27 | |||
| 28 | #ifndef __packed | ||
| 29 | # define __packed __attribute__((packed)) | ||
| 30 | #endif | ||
| 31 | |||
| 32 | // from ubi-media.h | ||
| 33 | #define UBI_MAX_VOLUME_NAME 127 | ||
| 34 | #define UBI_MAX_VOLUMES 128 | ||
| 35 | // end ubi-media.h | ||
| 36 | |||
| 37 | // from ubi-user.h | ||
| 38 | /* ioctl commands of UBI character devices */ | ||
| 39 | #define UBI_IOC_MAGIC 'o' | ||
| 40 | |||
| 41 | /* Re-name volumes */ | ||
| 42 | #define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req) | ||
| 43 | |||
| 44 | /* Maximum amount of UBI volumes that can be re-named at one go */ | ||
| 45 | #define UBI_MAX_RNVOL 32 | ||
| 46 | |||
| 47 | struct ubi_rnvol_req { | ||
| 48 | int32_t count; | ||
| 49 | int8_t padding1[12]; | ||
| 50 | struct { | ||
| 51 | int32_t vol_id; | ||
| 52 | int16_t name_len; | ||
| 53 | int8_t padding2[2]; | ||
| 54 | char name[UBI_MAX_VOLUME_NAME + 1]; | ||
| 55 | } ents[UBI_MAX_RNVOL]; | ||
| 56 | } __packed; | ||
| 57 | // end ubi-user.h | ||
| 58 | |||
| 59 | int ubirename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
| 60 | int ubirename_main(int argc, char **argv) | ||
| 61 | { | ||
| 62 | struct ubi_rnvol_req *rnvol; | ||
| 63 | const char *ubi_devname; | ||
| 64 | unsigned ubi_devnum; | ||
| 65 | unsigned n; | ||
| 66 | |||
| 67 | /* argc can be 4, 6, 8, ... */ | ||
| 68 | if ((argc & 1) || (argc >>= 1) < 2) | ||
| 69 | bb_show_usage(); | ||
| 70 | |||
| 71 | rnvol = xzalloc(sizeof(*rnvol)); | ||
| 72 | rnvol->count = --argc; | ||
| 73 | if (argc > ARRAY_SIZE(rnvol->ents)) | ||
| 74 | bb_error_msg_and_die("too many renames requested"); | ||
| 75 | |||
| 76 | ubi_devname = argv[1]; | ||
| 77 | ubi_devnum = ubi_devnum_from_devname(ubi_devname); | ||
| 78 | |||
| 79 | n = 0; | ||
| 80 | argv += 2; | ||
| 81 | while (argv[0]) { | ||
| 82 | rnvol->ents[n].vol_id = ubi_get_volid_by_name(ubi_devnum, argv[0]); | ||
| 83 | rnvol->ents[n].name_len = strlen(argv[1]); | ||
| 84 | if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) | ||
| 85 | bb_error_msg_and_die("new name '%s' is too long", argv[1]); | ||
| 86 | strcpy(rnvol->ents[n].name, argv[1]); | ||
| 87 | n++; | ||
| 88 | argv += 2; | ||
| 89 | } | ||
| 90 | |||
| 91 | xioctl(xopen(ubi_devname, O_RDONLY), UBI_IOCRNVOL, rnvol); | ||
| 92 | |||
| 93 | return 0; | ||
| 94 | } | ||
