summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2009-05-25 04:15:37 +0200
committerDenys Vlasenko2009-05-25 04:15:37 +0200
commitbf2af9acb28ed6d8bbe351d669daaa140d0239f0 (patch)
tree3adba401caf5c25406f89ebe053a0d9dbb043b54
parent4f26c97b9a2fdf6d967eafa06c67d04e432840a1 (diff)
downloadbusybox-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.zip
busybox-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.tar.gz
flash_lock, flash_unlock: new applets
By Thierry Reding (thierry.reding AT avionic-design.de) Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h11
-rw-r--r--include/xatonum.h4
-rw-r--r--libbb/xatonum_template.c5
-rw-r--r--loginutils/addgroup.c2
-rw-r--r--miscutils/Config.in14
-rw-r--r--miscutils/Kbuild4
-rw-r--r--miscutils/flash_lock_unlock.c69
-rw-r--r--modutils/modprobe-small.c2
-rw-r--r--networking/tc.c4
10 files changed, 112 insertions, 6 deletions
diff --git a/include/applets.h b/include/applets.h
index 7838757..5fbb346 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -155,8 +155,9 @@ IF_FDISK(APPLET(fdisk, _BB_DIR_SBIN, _BB_SUID_NEVER))
IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER, fgrep))
IF_FIND(APPLET_NOEXEC(find, find, _BB_DIR_USR_BIN, _BB_SUID_NEVER, find))
IF_FINDFS(APPLET(findfs, _BB_DIR_SBIN, _BB_SUID_MAYBE))
-//IF_FLASH_ERASEALL(APPLET_ODDNAME(flash_eraseall, flash_eraseall, _BB_DIR_USR_SBIN, _BB_SUID_NEVER, flash_eraseall))
IF_FLASH_ERASEALL(APPLET(flash_eraseall, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
+IF_FLASH_LOCK(APPLET_ODDNAME(flash_lock, flash_lock_unlock, _BB_DIR_USR_SBIN, _BB_SUID_NEVER, flash_lock))
+IF_FLASH_UNLOCK(APPLET_ODDNAME(flash_unlock, flash_lock_unlock, _BB_DIR_USR_SBIN, _BB_SUID_NEVER, flash_unlock))
IF_FOLD(APPLET(fold, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
IF_FREE(APPLET(free, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
IF_FREERAMDISK(APPLET(freeramdisk, _BB_DIR_SBIN, _BB_SUID_NEVER))
diff --git a/include/usage.h b/include/usage.h
index 1e327fb..e606925 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1248,6 +1248,17 @@
"$ find / -name passwd\n" \
"/etc/passwd\n"
+#define flash_lock_trivial_usage \
+ "MTD_DEVICE OFFSET SECTORS"
+#define flash_lock_full_usage "\n\n" \
+ "Lock part or all of an MTD device. If SECTORS is -1, then all sectors\n" \
+ "will be locked, regardless of the value of OFFSET"
+
+#define flash_unlock_trivial_usage \
+ "MTD_DEVICE"
+#define flash_unlock_full_usage "\n\n" \
+ "Unlock an MTD device"
+
#define flash_eraseall_trivial_usage \
"[-jq] MTD_DEVICE"
#define flash_eraseall_full_usage "\n\n" \
diff --git a/include/xatonum.h b/include/xatonum.h
index ee816ef..864d2a3 100644
--- a/include/xatonum.h
+++ b/include/xatonum.h
@@ -22,6 +22,7 @@ unsigned type xato##UT##_sfx(const char *str, const struct suffix_mult *sfx) FAS
unsigned type xato##UT(const char *str) FAST_FUNC; \
type xstrto##T##_range_sfx(const char *str, int b, type l, type u, const struct suffix_mult *sfx) FAST_FUNC; \
type xstrto##T##_range(const char *str, int b, type l, type u) FAST_FUNC; \
+type xstrto##T(const char *str, int b) FAST_FUNC; \
type xato##T##_range_sfx(const char *str, type l, type u, const struct suffix_mult *sfx) FAST_FUNC; \
type xato##T##_range(const char *str, type l, type u) FAST_FUNC; \
type xato##T##_sfx(const char *str, const struct suffix_mult *sfx) FAST_FUNC; \
@@ -66,6 +67,9 @@ static ALWAYS_INLINE \
narrow xstrto##N##_range(const char *str, int b, narrow l, narrow u) \
{ return xstrto##W##_range(str, b, l, u); } \
static ALWAYS_INLINE \
+narrow xstrto##N(const char *str, int b) \
+{ return xstrto##W(str, b); } \
+static ALWAYS_INLINE \
narrow xato##N##_range_sfx(const char *str, narrow l, narrow u, const struct suffix_mult *sfx) \
{ return xato##W##_range_sfx(str, l, u, sfx); } \
static ALWAYS_INLINE \
diff --git a/libbb/xatonum_template.c b/libbb/xatonum_template.c
index 5e0bb59..339a7d3 100644
--- a/libbb/xatonum_template.c
+++ b/libbb/xatonum_template.c
@@ -157,6 +157,11 @@ type FAST_FUNC xstrto(_range)(const char *numstr, int base, type lower, type upp
return xstrto(_range_sfx)(numstr, base, lower, upper, NULL);
}
+type FAST_FUNC xstrto()(const char *numstr, int base)
+{
+ return xstrto(_range_sfx)(numstr, base, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
+}
+
type FAST_FUNC xato(_range_sfx)(const char *numstr,
type lower,
type upper,
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index dc60788..e49278e 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -30,7 +30,7 @@ static void xgroup_study(struct group *g)
}
/* if a specific gid is requested, the --system switch and */
- /* min and max values are overriden, and the range of valid */
+ /* min and max values are overridden, and the range of valid */
/* gid values is set to [0, INT_MAX] */
if (!(option_mask32 & OPT_GID)) {
if (option_mask32 & OPT_SYSTEM_ACCOUNT) {
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 7feaf4a..06ff51a 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -250,6 +250,20 @@ config FBSPLASH
"NN" (ASCII decimal number) - percentage to show on progress bar
"exit" - well you guessed it
+config FLASH_LOCK
+ bool "flash_lock"
+ default n
+ help
+ The flash_lock binary from mtd-utils as of git head 5ec0c10d0. This
+ utility locks part or all of the flash device.
+
+config FLASH_UNLOCK
+ bool "flash_unlock"
+ default n
+ help
+ The flash_unlock binary from mtd-utils as of git head 5ec0c10d0. This
+ utility unlocks part or all of the flash device.
+
config FLASH_ERASEALL
bool "flash_eraseall"
default n
diff --git a/miscutils/Kbuild b/miscutils/Kbuild
index 23d7d8d..8ae8a48 100644
--- a/miscutils/Kbuild
+++ b/miscutils/Kbuild
@@ -16,7 +16,9 @@ lib-$(CONFIG_DEVFSD) += devfsd.o
lib-$(CONFIG_DEVMEM) += devmem.o
lib-$(CONFIG_EJECT) += eject.o
lib-$(CONFIG_FBSPLASH) += fbsplash.o
-lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o
+lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o
+lib-$(CONFIG_FLASH_LOCK) += flash_lock_unlock.o
+lib-$(CONFIG_FLASH_UNLOCK) += flash_lock_unlock.o
lib-$(CONFIG_IONICE) += ionice.o
lib-$(CONFIG_HDPARM) += hdparm.o
lib-$(CONFIG_INOTIFYD) += inotifyd.o
diff --git a/miscutils/flash_lock_unlock.c b/miscutils/flash_lock_unlock.c
new file mode 100644
index 0000000..f4e2f73
--- /dev/null
+++ b/miscutils/flash_lock_unlock.c
@@ -0,0 +1,69 @@
+/* vi: set sw=4 ts=4: */
+/* Ported to busybox from mtd-utils.
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ */
+#include "libbb.h"
+#include <mtd/mtd-user.h>
+
+int flash_lock_unlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int flash_lock_unlock_main(int argc UNUSED_PARAM, char **argv)
+{
+ /* note: fields in these structs are 32-bits.
+ * apparently we can't win anything by using off_t
+ * or long long's for offset and/or sectors vars. */
+ struct mtd_info_user info;
+ struct erase_info_user lock;
+ unsigned long offset;
+ long sectors;
+ int fd;
+
+#define do_lock (ENABLE_FLASH_LOCK && (!ENABLE_FLASH_UNLOCK || (applet_name[6] == 'l')))
+
+ if (!argv[1])
+ bb_show_usage();
+
+ /* parse offset and number of sectors to lock */
+ offset = 0;
+ sectors = -1;
+ if (do_lock) {
+ if (!argv[2] || !argv[3])
+ bb_show_usage();
+ offset = xstrtoul(argv[2], 0);
+ sectors = xstrtol(argv[3], 0);
+ }
+
+ fd = xopen(argv[1], O_RDWR);
+
+ xioctl(fd, MEMGETINFO, &info);
+
+ lock.start = 0;
+ lock.length = info.size;
+ if (do_lock) {
+ unsigned long size = info.size - info.erasesize;
+ if (offset > size) {
+ bb_error_msg_and_die("%lx is beyond device size %lx\n",
+ offset, size);
+ }
+
+ if (sectors == -1) {
+ sectors = info.size / info.erasesize;
+ } else {
+// isn't this useless?
+ unsigned long num = info.size / info.erasesize;
+ if (sectors > num) {
+ bb_error_msg_and_die("%ld are too many "
+ "sectors, device only has "
+ "%ld\n", sectors, num);
+ }
+ }
+
+ lock.start = offset;
+ lock.length = sectors * info.erasesize;
+ xioctl(fd, MEMLOCK, &lock);
+ } else {
+ xioctl(fd, MEMUNLOCK, &lock);
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index 3fd7bf5..0d78033 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -656,7 +656,7 @@ depmod -[aA] [-n -e -v -q -V -r -u]
[-b basedirectory] [forced_version]
depmod [-n -e -v -q -r -u] [-F kernelsyms] module1.ko module2.ko ...
If no arguments (except options) are given, "depmod -a" is assumed.
-depmod will output a dependancy list suitable for the modprobe utility.
+depmod will output a dependency list suitable for the modprobe utility.
Options:
-a, --all Probe all modules
-A, --quick Only does the work if there's a new module
diff --git a/networking/tc.c b/networking/tc.c
index 79cdd7c..4e84faa 100644
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -322,7 +322,7 @@ static int print_qdisc(const struct sockaddr_nl *who UNUSED_PARAM,
int qqq = index_in_strings(_q_, name);
if (qqq == 0) { /* pfifo_fast aka prio */
prio_print_opt(tb[TCA_OPTIONS]);
- } else if (qqq == 1) { /* class based queueing */
+ } else if (qqq == 1) { /* class based queuing */
cbq_print_opt(tb[TCA_OPTIONS]);
} else
bb_error_msg("unknown %s", name);
@@ -388,7 +388,7 @@ static int print_class(const struct sockaddr_nl *who UNUSED_PARAM,
int qqq = index_in_strings(_q_, name);
if (qqq == 0) { /* pfifo_fast aka prio */
/* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/
- } else if (qqq == 1) { /* class based queueing */
+ } else if (qqq == 1) { /* class based queuing */
/* cbq_print_copt() is identical to cbq_print_opt(). */
cbq_print_opt(tb[TCA_OPTIONS]);
} else