From 393c395ca50d0b95003d5adfc6d1ca95763cc732 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 14 Dec 2012 17:14:11 +0100 Subject: du: document incompatibility with standard tool Signed-off-by: Denys Vlasenko --- coreutils/du.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/coreutils/du.c b/coreutils/du.c index 19a0319f1..9c6ff8800 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -89,6 +89,10 @@ struct globals { #define INIT_G() do { } while (0) +/* FIXME? coreutils' du rounds sizes up: + * for example, 1025k file is shown as "2" by du -m. + * We round to nearest. + */ static void print(unsigned long long size, const char *filename) { /* TODO - May not want to defer error checking here. */ -- cgit v1.2.3-55-g6feb From 12677acf0a0bda4a863279ece65eccda6c36d6b1 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Mon, 10 Dec 2012 14:49:39 -0500 Subject: CONFIG_PID_FILE_PATH: new configuration option for pidfile paths We set a default path for the directory where pidfiles are create when FEATURE_PIDFILE is selected. The default has no effect on applets which must specify a pidfile path on the command line to run, and it can be overridden by applets which optionally allow the user to specify the pidfile path. We also add pidfile write/remove support for klogd, ntpd and watchdog. For syslogd, we add a missing remove_pidfile() for better cleanup on daemon exit. Signed-off-by: Anthony G. Basile Signed-off-by: Mike Frysinger --- Config.in | 13 ++++++++++++- miscutils/crond.c | 2 +- miscutils/watchdog.c | 3 +++ networking/ifplugd.c | 2 +- networking/inetd.c | 6 ++---- networking/ntpd.c | 3 +++ sysklogd/klogd.c | 3 +++ sysklogd/syslogd.c | 5 ++++- util-linux/acpid.c | 2 +- 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Config.in b/Config.in index 17bdc895a..b3fd65bd9 100644 --- a/Config.in +++ b/Config.in @@ -310,7 +310,18 @@ config FEATURE_PIDFILE default y help This option makes some applets (e.g. crond, syslogd, inetd) write - a pidfile in /var/run. Some applications rely on them. + a pidfile at the configured PID_FILE_PATH. It has no effect + on applets which require pidfiles to run. + +config PID_FILE_PATH + string "Path to directory for pidfile" + default "/var/run" + depends on FEATURE_PIDFILE + help + This is the default path where pidfiles are created. Applets which + allow you to set the pidfile path on the command line will override + this value. The option has no effect on applets that require you to + specify a pidfile path. config FEATURE_SUID bool "Support for SUID/SGID handling" diff --git a/miscutils/crond.c b/miscutils/crond.c index a0b73c774..582dc991a 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -885,7 +885,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv) xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */ crondlog(LVL8 "crond (busybox "BB_VER") started, log level %d", G.log_level); rescan_crontab_dir(); - write_pidfile("/var/run/crond.pid"); + write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid"); /* Main loop */ t2 = time(NULL); diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index ee28dc30d..d3a76edf0 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -31,6 +31,7 @@ static void watchdog_shutdown(int sig UNUSED_PARAM) { static const char V = 'V'; + remove_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */ if (ENABLE_FEATURE_CLEAN_UP) close(3); @@ -95,6 +96,8 @@ int watchdog_main(int argc, char **argv) stimer_duration, htimer_duration * 1000); #endif + write_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); + while (1) { /* * Make sure we clear the counter before sleeping, diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 88bf448fa..86586f0fe 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -551,7 +551,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) applet_name = xasprintf("ifplugd(%s)", G.iface); #if ENABLE_FEATURE_PIDFILE - pidfile_name = xasprintf(_PATH_VARRUN"ifplugd.%s.pid", G.iface); + pidfile_name = xasprintf(CONFIG_PID_FILE_PATH "/ifplugd.%s.pid", G.iface); pid_from_pidfile = read_pid(pidfile_name); if (opts & FLAG_KILL) { diff --git a/networking/inetd.c b/networking/inetd.c index 00baf6971..584c5e5e4 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -186,8 +186,6 @@ #define ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN 0 #endif -#define _PATH_INETDPID "/var/run/inetd.pid" - #define CNT_INTERVAL 60 /* servers in CNT_INTERVAL sec. */ #define RETRYTIME 60 /* retry after bind or server fail */ @@ -1132,7 +1130,7 @@ static void clean_up_and_exit(int sig UNUSED_PARAM) if (ENABLE_FEATURE_CLEAN_UP) close(sep->se_fd); } - remove_pidfile(_PATH_INETDPID); + remove_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); exit(EXIT_SUCCESS); } @@ -1181,7 +1179,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) setgroups(1, &gid); } - write_pidfile(_PATH_INETDPID); + write_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); /* never fails under Linux (except if you pass it bad arguments) */ getrlimit(RLIMIT_NOFILE, &rlim_ofile); diff --git a/networking/ntpd.c b/networking/ntpd.c index 5b92db6f6..7facf9484 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -2080,6 +2080,8 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) */ cnt = G.peer_cnt * (INITIAL_SAMPLES + 1); + write_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); + while (!bb_got_signal) { llist_t *item; unsigned i, j; @@ -2195,6 +2197,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) } } /* while (!bb_got_signal) */ + remove_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); kill_myself_with_sig(bb_got_signal); } diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index efa0e537a..f59a155b4 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -195,6 +195,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) syslog(LOG_NOTICE, "klogd started: %s", bb_banner); + write_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); + used = 0; while (!bb_got_signal) { int n; @@ -258,6 +260,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) klogd_close(); syslog(LOG_NOTICE, "klogd: exiting"); + remove_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); if (bb_got_signal) kill_myself_with_sig(bb_got_signal); return EXIT_FAILURE; diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index fc380d9f9..5854bcd0f 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -916,6 +916,7 @@ static void do_syslogd(void) timestamp_and_log_internal("syslogd exiting"); puts("syslogd exiting"); + remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); if (ENABLE_FEATURE_IPC_SYSLOG) ipcsyslog_cleanup(); kill_myself_with_sig(bb_got_signal); @@ -979,8 +980,10 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) if (!(opts & OPT_nofork)) { bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); } + //umask(0); - why?? - write_pidfile("/var/run/syslogd.pid"); + write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); + do_syslogd(); /* return EXIT_SUCCESS; */ } diff --git a/util-linux/acpid.c b/util-linux/acpid.c index 5d2792948..38421c2d7 100644 --- a/util-linux/acpid.c +++ b/util-linux/acpid.c @@ -235,7 +235,7 @@ int acpid_main(int argc UNUSED_PARAM, char **argv) const char *opt_action = "/etc/acpid.conf"; const char *opt_map = "/etc/acpi.map"; #if ENABLE_FEATURE_PIDFILE - const char *opt_pidfile = "/var/run/acpid.pid"; + const char *opt_pidfile = CONFIG_PID_FILE_PATH "/acpid.pid"; #endif INIT_G(); -- cgit v1.2.3-55-g6feb From a38f9faa9fa230eb3753381c4f626acf029379fb Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 26 Dec 2012 17:12:26 -0500 Subject: ifenslave: fix missing close paren Reported-by: David J Cozatt Signed-off-by: Mike Frysinger --- networking/ifenslave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ifenslave.c b/networking/ifenslave.c index ae7719f52..f7f87bc55 100644 --- a/networking/ifenslave.c +++ b/networking/ifenslave.c @@ -546,7 +546,7 @@ int ifenslave_main(int argc UNUSED_PARAM, char **argv) #ifdef WHY_BOTHER /* Neither -c[hange] nor -d[etach] -> it's "enslave" then; * and -f[orce] is not there too. Check that it's ethernet. */ - if (!(opt & (OPT_d|OPT_c|OPT_f)) { + if (!(opt & (OPT_d|OPT_c|OPT_f))) { /* The family '1' is ARPHRD_ETHER for ethernet. */ if (master.hwaddr.ifr_hwaddr.sa_family != 1) { bb_error_msg_and_die( -- cgit v1.2.3-55-g6feb From fb499c57525377ca579e310d2d29c867535dd2f6 Mon Sep 17 00:00:00 2001 From: Lauri Hintsala Date: Fri, 4 Jan 2013 10:51:57 +0200 Subject: powertop: fix error message Application tries to use timer_stats module instead of cpufreq_stats. Error message is printed if opening of the file /proc/timer_stats fails. Signed-off-by: Lauri Hintsala Signed-off-by: Mike Frysinger --- procps/powertop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/procps/powertop.c b/procps/powertop.c index b4c45edbc..a69ee12b0 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -650,7 +650,7 @@ static void show_timerstats(void) } else { bb_putchar('\n'); bb_error_msg("no stats available; run as root or" - " enable the cpufreq_stats module"); + " enable the timer_stats module"); } } -- cgit v1.2.3-55-g6feb From 3917fa32dce8c887d0a87d0d2f4490f1b89b51d0 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sun, 6 Jan 2013 00:07:17 +0100 Subject: dmesg: handle multi-char log levels Since Linux 3.5 (7ff9554bb5: printk: convert byte-buffer to variable-length record buffer), klog buffer can now contain log lines with multi-char loglevel indicators (<[0-9]+>) - So we can no longer just skip 3 bytes. Instead skip past the terminating '>' like util-linux does. function old new delta dmesg_main 266 280 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0) Total: 13 bytes Signed-off-by: Peter Korsgaard Signed-off-by: Mike Frysinger --- util-linux/dmesg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 6505da54b..81ba1c9d1 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c @@ -59,16 +59,15 @@ int dmesg_main(int argc UNUSED_PARAM, char **argv) int last = '\n'; int in = 0; - /* Skip <#> at the start of lines */ + /* Skip <[0-9]+> at the start of lines */ while (1) { if (last == '\n' && buf[in] == '<') { - in += 3; - if (in >= len) - break; + while (buf[in++] != '>' && in < len) + ; + } else { + last = buf[in++]; + putchar(last); } - last = buf[in]; - putchar(last); - in++; if (in >= len) break; } -- cgit v1.2.3-55-g6feb From d189b598b449f3a258354133180e7b770c04526c Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sun, 6 Jan 2013 00:07:18 +0100 Subject: klogd: handle multi-char log levels Since Linux 3.5 (7ff9554bb5: printk: convert byte-buffer to variable-length record buffer), klog buffer can now contain log lines with multi-char loglevel indicators (<[0-9]+>) - So use strtoul to parse it. function old new delta klogd_main 490 525 +35 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 35/0) Total: 35 bytes Signed-off-by: Peter Korsgaard Signed-off-by: Mike Frysinger --- sysklogd/klogd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index f59a155b4..432ded153 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -240,11 +240,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) priority = LOG_INFO; if (*start == '<') { start++; - if (*start) { - /* kernel never generates multi-digit prios */ - priority = (*start - '0'); - start++; - } + if (*start) + priority = strtoul(start, &start, 10); if (*start == '>') start++; } -- cgit v1.2.3-55-g6feb From cd776cf96735760311560495f3f0078ae72e98a0 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sun, 6 Jan 2013 00:07:19 +0100 Subject: syslogd: add option to log to Linux kernel printk buffer Why invent our own shared memory circular buffer when the kernel has a perfectly fine one already? This can be used as a smaller/simpler alternative to the syslogd IPC support (as IPC shmem/klogd/logread aren't needed), while also allowing centralised logging of everything (kernel messages, userspace bootup and syslog) when used together with ttyprintk. Notice that kernel 3.5+ is needed to store syslog facility in printk buffer, otherwise only the priority is stored. bloat-o-meter compared to IPC+klogd+logread: function old new delta get_linux_version_code - 84 +84 lbb_prepare 25 90 +65 applet_nameofs 6 - -6 static.stdout@@GLIBC_2 8 - -8 applet_names 23 9 -14 bb_msg_standard_output 16 - -16 init_sem 18 - -18 xatoull_range 19 - -19 overlapping_strcpy 21 - -21 init_data 56 32 -24 applet_main 24 - -24 main 124 99 -25 full_write2_str 26 - -26 error_exit 26 - -26 bb_basename 30 - -30 sem_up 32 - -32 interrupted 35 - -35 fflush_stdout_and_exit 38 - -38 bb_banner 46 - -46 find_applet_by_name 59 - -59 bb_signals_recursive_norestart 90 - -90 run_applet_no_and_exit 104 - -104 timestamp_and_log 651 523 -128 syslogd_main 798 581 -217 xstrtoull_range_sfx 267 - -267 run_applet_and_exit 432 - -432 klogd_main 490 - -490 logread_main 508 - -508 .rodata 1870 937 -933 bb_common_bufsiz1 8193 - -8193 ------------------------------------------------------------------------------ (add/remove: 2/26 grow/shrink: 1/6 up/down: 149/-11829) Total: -11680 bytes Signed-off-by: Peter Korsgaard Signed-off-by: Mike Frysinger --- sysklogd/Config.src | 16 ++++++++++++++ sysklogd/syslogd.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/sysklogd/Config.src b/sysklogd/Config.src index b7a494eff..fcf993054 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -113,6 +113,19 @@ config FEATURE_LOGREAD_REDUCED_LOCKING from circular buffer, minimizing semaphore contention at some minor memory expense. +config FEATURE_KMSG_SYSLOG + bool "Linux kernel printk buffer support" + default y + depends on SYSLOGD + select PLATFORM_LINUX + help + When you enable this feature, the syslogd utility will + write system log message to the Linux kernel's printk buffer. + This can be used as a smaller alternative to the syslogd IPC + support, as klogd and logread aren't needed. + + NOTICE: Syslog facilities in log entries needs kernel 3.5+. + config KLOGD bool "klogd" default y @@ -123,6 +136,9 @@ config KLOGD you wish to record the messages produced by the kernel, you should enable this option. +comment "klogd should not be used together with syslog to kernel printk buffer" + depends on KLOGD && FEATURE_KMSG_SYSLOG + config FEATURE_KLOGD_KLOGCTL bool "Use the klogctl() interface" default y diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 5854bcd0f..ad54e22dd 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -43,6 +43,9 @@ //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" //usage: ) /* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ +//usage: IF_FEATURE_KMSG_SYSLOG( +//usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" +//usage: ) //usage: //usage:#define syslogd_example_usage //usage: "$ syslogd -R masterlog:514\n" @@ -140,6 +143,10 @@ IF_FEATURE_IPC_SYSLOG( \ ) \ IF_FEATURE_SYSLOGD_CFG( \ logRule_t *log_rules; \ +) \ +IF_FEATURE_KMSG_SYSLOG( \ + int kmsgfd; \ + int primask; \ ) struct init_globals { @@ -212,6 +219,7 @@ enum { IF_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C IF_FEATURE_SYSLOGD_DUP( OPTBIT_dup ,) // -D IF_FEATURE_SYSLOGD_CFG( OPTBIT_cfg ,) // -f + IF_FEATURE_KMSG_SYSLOG( OPTBIT_kmsg ,) // -K OPT_mark = 1 << OPTBIT_mark , OPT_nofork = 1 << OPTBIT_nofork , @@ -225,6 +233,8 @@ enum { OPT_circularlog = IF_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0, OPT_dup = IF_FEATURE_SYSLOGD_DUP( (1 << OPTBIT_dup )) + 0, OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, + OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, + }; #define OPTION_STR "m:nO:l:S" \ IF_FEATURE_ROTATE_LOGFILE("s:" ) \ @@ -233,7 +243,8 @@ enum { IF_FEATURE_REMOTE_LOG( "L" ) \ IF_FEATURE_IPC_SYSLOG( "C::") \ IF_FEATURE_SYSLOGD_DUP( "D" ) \ - IF_FEATURE_SYSLOGD_CFG( "f:" ) + IF_FEATURE_SYSLOGD_CFG( "f:" ) \ + IF_FEATURE_KMSG_SYSLOG( "K" ) #define OPTION_DECL *opt_m, *opt_l \ IF_FEATURE_ROTATE_LOGFILE(,*opt_s) \ IF_FEATURE_ROTATE_LOGFILE(,*opt_b) \ @@ -523,6 +534,44 @@ void ipcsyslog_init(void); void log_to_shmem(const char *msg); #endif /* FEATURE_IPC_SYSLOG */ +#if ENABLE_FEATURE_KMSG_SYSLOG +static void kmsg_init(void) +{ + G.kmsgfd = xopen("/dev/kmsg", O_WRONLY); + + /* + * kernel < 3.5 expects single char printk KERN_* priority prefix, + * from 3.5 onwards the full syslog facility/priority format is supported + */ + if (get_linux_version_code() < KERNEL_VERSION(3,5,0)) + G.primask = LOG_PRIMASK; + else + G.primask = -1; +} + +static void kmsg_cleanup(void) +{ + if (ENABLE_FEATURE_CLEAN_UP) + close(G.kmsgfd); +} + +/* Write message to /dev/kmsg */ +static void log_to_kmsg(int pri, const char *msg) +{ + /* + * kernel < 3.5 expects single char printk KERN_* priority prefix, + * from 3.5 onwards the full syslog facility/priority format is supported + */ + pri &= G.primask; + + write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); +} +#else +void kmsg_init(void); +void kmsg_cleanup(void); +void log_to_kmsg(int pri, const char *msg); +#endif /* FEATURE_KMSG_SYSLOG */ + /* Print a message to the log file. */ static void log_locally(time_t now, char *msg, logFile_t *log_file) { @@ -657,6 +706,11 @@ static void timestamp_and_log(int pri, char *msg, int len) } timestamp[15] = '\0'; + if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) { + log_to_kmsg(pri, msg); + return; + } + if (option_mask32 & OPT_small) sprintf(G.printbuf, "%s %s\n", timestamp, msg); else { @@ -831,6 +885,9 @@ static void do_syslogd(void) ipcsyslog_init(); } + if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) + kmsg_init(); + timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); while (!bb_got_signal) { @@ -919,6 +976,8 @@ static void do_syslogd(void) remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); if (ENABLE_FEATURE_IPC_SYSLOG) ipcsyslog_cleanup(); + if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) + kmsg_cleanup(); kill_myself_with_sig(bb_got_signal); #undef recvbuf } -- cgit v1.2.3-55-g6feb From a58f7b7d2f73b84638a8e8c14a142d4a03678eeb Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh Date: Mon, 14 Jan 2013 00:35:31 +0100 Subject: blkid: add type display for hfsplus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sven-Göran Bergh Signed-off-by: Denys Vlasenko --- util-linux/volume_id/hfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-linux/volume_id/hfs.c b/util-linux/volume_id/hfs.c index f3f19dba7..dd5ec2415 100644 --- a/util-linux/volume_id/hfs.c +++ b/util-linux/volume_id/hfs.c @@ -286,7 +286,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/ found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); -// id->type = "hfsplus"; + IF_FEATURE_BLKID_TYPE(id->type = "hfsplus";) return 0; } -- cgit v1.2.3-55-g6feb From 07b419dbcb34958d0f6050231783bd78f7d0344f Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh Date: Mon, 14 Jan 2013 00:37:00 +0100 Subject: volume_id: display hfs[+] 128-bit UUID properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sven-Göran Bergh Signed-off-by: Denys Vlasenko --- util-linux/volume_id/hfs.c | 25 +++++++++++++++++++++++-- util-linux/volume_id/util.c | 6 ------ util-linux/volume_id/volume_id_internal.h | 1 - 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/util-linux/volume_id/hfs.c b/util-linux/volume_id/hfs.c index dd5ec2415..3d9704d12 100644 --- a/util-linux/volume_id/hfs.c +++ b/util-linux/volume_id/hfs.c @@ -131,6 +131,27 @@ struct hfsplus_vol_header { #define HFS_NODE_LEAF 0xff #define HFSPLUS_POR_CNID 1 +static void FAST_FUNC hfs_set_uuid(struct volume_id *id, const uint8_t *hfs_id) +{ +#define hfs_id_len 8 + md5_ctx_t md5c; + uint8_t uuid[16]; + unsigned i; + + for (i = 0; i < hfs_id_len; i++) + if (hfs_id[i] != 0) + goto do_md5; + return; + do_md5: + md5_begin(&md5c); + md5_hash(&md5c, "\263\342\17\71\362\222\21\326\227\244\0\60\145\103\354\254", 16); + md5_hash(&md5c, hfs_id, hfs_id_len); + md5_end(&md5c, uuid); + uuid[6] = 0x30 | (uuid[6] & 0x0f); + uuid[8] = 0x80 | (uuid[8] & 0x3f); + volume_id_set_uuid(id, uuid, UUID_DCE); +} + int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/) { uint64_t off = 0; @@ -193,7 +214,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/ volume_id_set_label_string(id, hfs->label, hfs->label_len) ; } - volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS); + hfs_set_uuid(id, hfs->finder_info.id); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); IF_FEATURE_BLKID_TYPE(id->type = "hfs";) @@ -207,7 +228,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/ return -1; hfsplus: - volume_id_set_uuid(id, hfsplus->finder_info.id, UUID_HFS); + hfs_set_uuid(id, hfsplus->finder_info.id); blocksize = be32_to_cpu(hfsplus->blocksize); dbg("blocksize %u", blocksize); diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index 69e43dda8..11ee0d52e 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c @@ -142,7 +142,6 @@ void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_form count = 4; break; case UUID_NTFS: - case UUID_HFS: count = 8; break; case UUID_DCE: @@ -173,11 +172,6 @@ set: buf[7], buf[6], buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); break; - case UUID_HFS: - sprintf(id->uuid, "%02X%02X%02X%02X%02X%02X%02X%02X", - buf[0], buf[1], buf[2], buf[3], - buf[4], buf[5], buf[6], buf[7]); - break; case UUID_DCE: sprintf(id->uuid, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index 03dc46f27..dd62df399 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -141,7 +141,6 @@ enum uuid_format { UUID_DCE, UUID_DOS, UUID_NTFS, - UUID_HFS, }; enum endian { -- cgit v1.2.3-55-g6feb From 52185155088d0910d29c7f4fdf5cb3eecaac8965 Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh Date: Mon, 14 Jan 2013 00:50:49 +0100 Subject: volume_id: uuid_format small code shrink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit function old new delta volume_id_set_uuid 318 300 -18 Signed-off-by: Sven-Göran Bergh Signed-off-by: Denys Vlasenko --- util-linux/volume_id/util.c | 17 +---------------- util-linux/volume_id/volume_id_internal.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index 11ee0d52e..0e2d24be0 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c @@ -135,23 +135,8 @@ void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enu void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format) { unsigned i; - unsigned count = 0; + unsigned count = (format == UUID_DCE_STRING ? VOLUME_ID_UUID_SIZE : 4 << format); - switch (format) { - case UUID_DOS: - count = 4; - break; - case UUID_NTFS: - count = 8; - break; - case UUID_DCE: - count = 16; - break; - case UUID_DCE_STRING: - /* 36 is ok, id->uuid has one extra byte for NUL */ - count = VOLUME_ID_UUID_SIZE; - break; - } // memcpy(id->uuid_raw, buf, count); // id->uuid_raw_len = count; diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index dd62df399..e26ebaab6 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -136,11 +136,15 @@ void FAST_FUNC free_volume_id(struct volume_id *id); #define cpu_to_be32(x) (x) #endif +/* volume_id_set_uuid(id,buf,fmt) assumes size of uuid buf + * by shifting: 4 << fmt, except for fmt == UUID_DCE_STRING. + * The constants below should match sizes. + */ enum uuid_format { - UUID_DCE_STRING, - UUID_DCE, - UUID_DOS, - UUID_NTFS, + UUID_DOS = 0, /* 4 bytes */ + UUID_NTFS = 1, /* 8 bytes */ + UUID_DCE = 2, /* 16 bytes */ + UUID_DCE_STRING = 3, /* 36 bytes (VOLUME_ID_UUID_SIZE) */ }; enum endian { -- cgit v1.2.3-55-g6feb From 6967578728a3eef43b7b2be4080dafc1b87f528d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Jan 2013 01:34:48 +0100 Subject: whitespace fixes. no code changes Signed-off-by: Denys Vlasenko --- archival/dpkg.c | 6 +- archival/gzip.c | 16 +-- archival/lzop.c | 2 +- archival/tar.c | 14 +-- console-tools/setlogcons.c | 7 +- coreutils/cal.c | 4 +- coreutils/cut.c | 2 +- coreutils/df.c | 4 +- coreutils/id.c | 2 +- coreutils/ls.c | 4 +- coreutils/md5_sha1_sum.c | 2 +- e2fsprogs/fsck.c | 4 +- findutils/find.c | 4 +- miscutils/fbsplash.c | 2 +- miscutils/last.c | 4 +- modutils/depmod.c | 6 +- networking/arp.c | 14 +-- networking/ether-wake.c | 6 +- networking/httpd.c | 6 +- networking/httpd_ssi.c | 2 +- networking/ifconfig.c | 2 +- networking/interface.c | 29 +++-- networking/nc.c | 2 +- networking/ntpd.c | 11 +- networking/ntpd_simple.c | 2 +- networking/ping.c | 2 +- networking/route.c | 14 +-- procps/powertop.c | 2 +- procps/sysctl.c | 2 +- sysklogd/syslogd.c | 2 +- util-linux/fdformat.c | 2 +- util-linux/fdisk.c | 2 +- util-linux/flock.c | 2 +- util-linux/ipcrm.c | 6 +- util-linux/ipcs.c | 254 +++++++++++++++++++------------------- util-linux/lspci.c | 6 +- util-linux/mount.c | 48 +++---- util-linux/readprofile.c | 16 +-- util-linux/volume_id/linux_raid.c | 6 +- util-linux/volume_id/util.c | 2 +- 40 files changed, 261 insertions(+), 262 deletions(-) diff --git a/archival/dpkg.c b/archival/dpkg.c index dae8a9747..ed86f3355 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -1026,8 +1026,8 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count if (package_edge->type == EDGE_CONFLICTS) { const unsigned package_num = search_package_hashtable(package_edge->name, - package_edge->version, - package_edge->operator); + package_edge->version, + package_edge->operator); int result = 0; if (package_hashtable[package_num] != NULL) { status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); @@ -1114,7 +1114,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count */ if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1) bb_error_msg_and_die("fatal error, package dependencies corrupt: %d != %d - 1", - package_edge->type, root_of_alternatives->type); + package_edge->type, root_of_alternatives->type); if (package_hashtable[package_num] != NULL) result = !package_satisfies_dependency(package_num, package_edge->type); diff --git a/archival/gzip.c b/archival/gzip.c index 80db4f969..31ccab3cd 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -1179,7 +1179,7 @@ static void gen_codes(ct_data * tree, int max_code) * must be all ones. */ Assert(code + G2.bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); + "inconsistent bit counts"); Tracev((stderr, "\ngen_codes: max_code %d ", max_code)); for (n = 0; n <= max_code; n++) { @@ -1527,9 +1527,9 @@ static int ct_tally(int dist, int lc) } out_length >>= 3; Trace((stderr, - "\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ", - G2.last_lit, G2.last_dist, in_length, out_length, - 100L - out_length * 100L / in_length)); + "\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ", + G2.last_lit, G2.last_dist, in_length, out_length, + 100L - out_length * 100L / in_length)); if (G2.last_dist < G2.last_lit / 2 && out_length < in_length / 2) return 1; } @@ -1621,9 +1621,9 @@ static ulg flush_block(char *buf, ulg stored_len, int eof) static_lenb = (G2.static_len + 3 + 7) >> 3; Trace((stderr, - "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ", - opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len, - G2.last_lit, G2.last_dist)); + "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ", + opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len, + G2.last_lit, G2.last_dist)); if (static_lenb <= opt_lenb) opt_lenb = static_lenb; @@ -1661,7 +1661,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof) } else { send_bits((DYN_TREES << 1) + eof, 3); send_all_trees(G2.l_desc.max_code + 1, G2.d_desc.max_code + 1, - max_blindex + 1); + max_blindex + 1); compress_block((ct_data *) G2.dyn_ltree, (ct_data *) G2.dyn_dtree); G2.compressed_len += 3 + G2.opt_len; } diff --git a/archival/lzop.c b/archival/lzop.c index fbe08417d..ec4e784ed 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -350,7 +350,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len, // LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : - (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); } /**********************************************************************/ diff --git a/archival/tar.c b/archival/tar.c index a3565d6ae..f46f7bb7a 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -333,13 +333,13 @@ static int writeTarHeader(struct TarBallInfo *tbInfo, && (filesize <= 0x3fffffffffffffffffffffffLL) #endif ) { - /* GNU tar uses "base-256 encoding" for very large numbers. - * Encoding is binary, with highest bit always set as a marker - * and sign in next-highest bit: - * 80 00 .. 00 - zero - * bf ff .. ff - largest positive number - * ff ff .. ff - minus 1 - * c0 00 .. 00 - smallest negative number + /* GNU tar uses "base-256 encoding" for very large numbers. + * Encoding is binary, with highest bit always set as a marker + * and sign in next-highest bit: + * 80 00 .. 00 - zero + * bf ff .. ff - largest positive number + * ff ff .. ff - minus 1 + * c0 00 .. 00 - smallest negative number */ char *p8 = header.size + sizeof(header.size); do { diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c index 83a895407..c76a5a42b 100644 --- a/console-tools/setlogcons.c +++ b/console-tools/setlogcons.c @@ -22,9 +22,10 @@ int setlogcons_main(int argc UNUSED_PARAM, char **argv) struct { char fn; char subarg; - } arg = { 11, /* redirect kernel messages */ - 0 /* to specified console (current as default) */ - }; + } arg = { + 11, /* redirect kernel messages */ + 0 /* to specified console (current as default) */ + }; if (argv[1]) arg.subarg = xatou_range(argv[1], 0, 63); diff --git a/coreutils/cal.c b/coreutils/cal.c index b470ad968..158b23fbc 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -167,8 +167,8 @@ int cal_main(int argc UNUSED_PARAM, char **argv) day_array(month, year, dp); len = sprintf(lineout, "%s %d", month_names[month - 1], year); printf("%*s%s\n%s\n", - ((7*julian + WEEK_LEN) - len) / 2, "", - lineout, day_headings); + ((7*julian + WEEK_LEN) - len) / 2, "", + lineout, day_headings); for (row = 0; row < 6; row++) { build_row(lineout, dp)[0] = '\0'; dp += 7; diff --git a/coreutils/cut.c b/coreutils/cut.c index 2c27b704f..84449c775 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -212,7 +212,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) if (opt & CUT_OPT_SUPPRESS_FLGS) { bb_error_msg_and_die ("suppressing non-delimited lines makes sense%s", - _op_on_field); + _op_on_field); } if (delim != '\t') { bb_error_msg_and_die diff --git a/coreutils/df.c b/coreutils/df.c index 63dbd61bd..2c72e82a4 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -112,7 +112,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) /* From the manpage of df from coreutils-6.10: Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. - */ + */ if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ df_disp_hr = 512; @@ -221,7 +221,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) } #else if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) - printf("\n%-20s", ""); + printf("\n%-20s", ""); #endif #if ENABLE_FEATURE_HUMAN_READABLE diff --git a/coreutils/id.c b/coreutils/id.c index 399d25e34..1f20b755e 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -174,7 +174,7 @@ int id_main(int argc UNUSED_PARAM, char **argv) /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ /* Don't allow more than one username */ opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" - IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); + IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); } diff --git a/coreutils/ls.c b/coreutils/ls.c index d5b25ee70..166473d4d 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -260,7 +260,7 @@ enum { /* TODO: simple toggles may be stored as OPT_xxx bits instead */ static const uint32_t opt_flags[] = { - STYLE_COLUMNAR, /* C */ + STYLE_COLUMNAR, /* C */ DISP_HIDDEN | DISP_DOT, /* a */ DISP_NOLIST, /* d */ LIST_INO, /* i */ @@ -720,7 +720,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f if ((option_mask32 & OPT_L) || force_follow) { #if ENABLE_SELINUX if (is_selinux_enabled()) { - getfilecon(fullname, &cur->sid); + getfilecon(fullname, &cur->sid); } #endif if (stat(fullname, &statbuf)) { diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 2cb6dd43c..59b520fce 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -223,7 +223,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) } if (count_failed && !(flags & FLAG_SILENT)) { bb_error_msg("WARNING: %d of %d computed checksums did NOT match", - count_failed, count_total); + count_failed, count_total); } fclose_if_not_stdin(pre_computed_stream); } else { diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 4b2f774f5..d32f396e9 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -478,7 +478,7 @@ static int wait_one(int flags) instance_list = inst->next; if (verbose > 1) printf("Finished with %s (exit status %d)\n", - inst->device, status); + inst->device, status); num_running--; free_instance(inst); @@ -844,7 +844,7 @@ static int check_all(void) if (verbose > 1) printf("--waiting-- (pass %d)\n", passno); status |= wait_many(pass_done ? FLAG_WAIT_ALL : - FLAG_WAIT_ATLEAST_ONE); + FLAG_WAIT_ATLEAST_ONE); if (pass_done) { if (verbose > 1) puts("----------------------------------"); diff --git a/findutils/find.c b/findutils/find.c index b521e5b08..2235b5049 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -878,8 +878,8 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_EXEC( "-exec\0" ) IF_FEATURE_FIND_PAREN( "(\0" ) /* All options/actions starting from here require argument */ - "-name\0" - "-iname\0" + "-name\0" + "-iname\0" IF_FEATURE_FIND_PATH( "-path\0" ) #if ENABLE_DESKTOP IF_FEATURE_FIND_PATH( "-wholename\0") diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 05a77da23..12a77b70f 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -150,7 +150,7 @@ static void fb_open(const char *strfb_device) // map the device in memory G.addr = mmap(NULL, - G.scr_var.yres * G.scr_fix.line_length, + G.scr_var.yres * G.scr_fix.line_length, PROT_WRITE, MAP_SHARED, fbfd, 0); if (G.addr == MAP_FAILED) bb_perror_msg_and_die("mmap"); diff --git a/miscutils/last.c b/miscutils/last.c index d52780374..24f6e1c78 100644 --- a/miscutils/last.c +++ b/miscutils/last.c @@ -71,7 +71,7 @@ int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) file = xopen(bb_path_wtmp_file, O_RDONLY); printf("%-10s %-14s %-18s %-12.12s %s\n", - "USER", "TTY", "HOST", "LOGIN", "TIME"); + "USER", "TTY", "HOST", "LOGIN", "TIME"); /* yikes. We reverse over the file and that is a not too elegant way */ pos = xlseek(file, 0, SEEK_END); pos = lseek(file, pos - sizeof(ut), SEEK_SET); @@ -131,7 +131,7 @@ int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) * but some systems have it wrong */ t_tmp = (time_t)ut.ut_tv.tv_sec; printf("%-10s %-14s %-18s %-12.12s\n", - ut.ut_user, ut.ut_line, ut.ut_host, ctime(&t_tmp) + 4); + ut.ut_user, ut.ut_line, ut.ut_host, ctime(&t_tmp) + 4); next: pos -= sizeof(ut); if (pos <= 0) diff --git a/modutils/depmod.c b/modutils/depmod.c index 775236126..aa228ec85 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c @@ -31,7 +31,7 @@ typedef struct module_info { } module_info; static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, - void *data, int depth UNUSED_PARAM) + void *data, int depth UNUSED_PARAM) { char modname[MODULE_NAME_LEN]; module_info **first = (module_info **) data; @@ -95,7 +95,7 @@ static module_info *find_module(module_info *modules, const char *modname) } static void order_dep_list(module_info *modules, module_info *start, - llist_t *add) + llist_t *add) { module_info *m; llist_t *n; @@ -216,7 +216,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) } while (*++argv); } else { recursive_action(".", ACTION_RECURSE, - parse_module, NULL, &modules, 0); + parse_module, NULL, &modules, 0); } /* Generate dependency and alias files */ diff --git a/networking/arp.c b/networking/arp.c index 696c402e0..1c99987ae 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -214,7 +214,7 @@ static int arp_del(char **args) /* Get the hardware address to a specified interface name */ static void arp_getdevhw(char *ifname, struct sockaddr *sa, - const struct hwtype *hwt) + const struct hwtype *hwt) { struct ifreq ifr; const struct hwtype *xhw; @@ -233,8 +233,8 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa, xhw = get_hwntype(-1); } bb_error_msg("device '%s' has HW address %s '%s'", - ifname, xhw->name, - xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); + ifname, xhw->name, + xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); } } @@ -345,7 +345,7 @@ static int arp_set(char **args) /* Print the contents of an ARP request block. */ static void arp_disp(const char *name, char *ip, int type, int arp_flags, - char *hwa, char *mask, char *dev) + char *hwa, char *mask, char *dev) { static const int arp_masks[] = { ATF_PERM, ATF_PUBL, @@ -428,7 +428,7 @@ static int arp_show(char *name) /* All these strings can't overflow * because fgets above reads limited amount of data */ num = sscanf(line, "%s 0x%x 0x%x %s %s %s\n", - ip, &type, &flags, hwa, mask, dev); + ip, &type, &flags, hwa, mask, dev); if (num < 4) break; @@ -461,7 +461,7 @@ static int arp_show(char *name) } if (option_mask32 & ARP_OPT_v) printf("Entries: %d\tSkipped: %d\tFound: %d\n", - entries, entries - shown, shown); + entries, entries - shown, shown); if (!shown) { if (hw_set || host || device[0]) @@ -517,7 +517,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv) if (hw->alen <= 0) { bb_error_msg_and_die("%s: %s without ARP support", - hw->name, "hardware type"); + hw->name, "hardware type"); } /* Now see what we have to do here... */ diff --git a/networking/ether-wake.c b/networking/ether-wake.c index 6a88279f4..a73b0baea 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -238,9 +238,9 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv) { unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data; printf("The hardware address (SIOCGIFHWADDR) of %s is type %d " - "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n\n", ifname, - if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1], - hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); + "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n\n", ifname, + if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1], + hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); } # endif } diff --git a/networking/httpd.c b/networking/httpd.c index a942794f5..1934bb27e 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -796,9 +796,9 @@ static void parse_conf(const char *path, int flag) /* the line is not recognized */ config_error: bb_error_msg("config error '%s' in '%s'", buf, filename); - } /* while (fgets) */ + } /* while (fgets) */ - fclose(f); + fclose(f); } #if ENABLE_FEATURE_HTTPD_ENCODE_URL_STR @@ -1708,7 +1708,7 @@ static int pam_talker(int num_msg, case PAM_PROMPT_ECHO_OFF: s = userinfo->pw; break; - case PAM_ERROR_MSG: + case PAM_ERROR_MSG: case PAM_TEXT_INFO: s = ""; break; diff --git a/networking/httpd_ssi.c b/networking/httpd_ssi.c index cfe64eb46..4bd9a6d97 100644 --- a/networking/httpd_ssi.c +++ b/networking/httpd_ssi.c @@ -133,7 +133,7 @@ static void process_includes(const char *filename) process_includes(include_directive); /* Print everything after directive */ - if (end) { + if (end) { fputs(end, stdout); free(end); } diff --git a/networking/ifconfig.c b/networking/ifconfig.c index b6604f5d1..320df3010 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c @@ -449,7 +449,7 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) } #endif memcpy( (((char *)&ifr) + a1op->ifr_offset), - p, sizeof(struct sockaddr)); + p, sizeof(struct sockaddr)); } else { /* FIXME: error check?? */ unsigned long i = strtoul(*argv, NULL, 0); diff --git a/networking/interface.c b/networking/interface.c index 79c322ec0..4b9b9485d 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -950,8 +950,8 @@ static void ife_print6(struct interface *ptr) (struct sockaddr *) &sap.sin6_addr); sap.sin6_family = AF_INET6; printf(" inet6 addr: %s/%d", - INET6_sprint((struct sockaddr *) &sap, 1), - plen); + INET6_sprint((struct sockaddr *) &sap, 1), + plen); printf(" Scope:"); switch (scope & IPV6_ADDR_SCOPE_MASK) { case 0: @@ -1019,7 +1019,7 @@ static void ife_print(struct interface *ptr) if (ptr->has_ip) { printf(" %s addr:%s ", ap->name, - ap->sprint(&ptr->addr, 1)); + ap->sprint(&ptr->addr, 1)); if (ptr->flags & IFF_POINTOPOINT) { printf(" P-t-P:%s ", ap->sprint(&ptr->dstaddr, 1)); } @@ -1102,17 +1102,17 @@ static void ife_print(struct interface *ptr) printf(" "); printf("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n", - ptr->stats.rx_packets, ptr->stats.rx_errors, - ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, - ptr->stats.rx_frame_errors); + ptr->stats.rx_packets, ptr->stats.rx_errors, + ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, + ptr->stats.rx_frame_errors); if (can_compress) printf(" compressed:%lu\n", - ptr->stats.rx_compressed); + ptr->stats.rx_compressed); printf(" "); printf("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n", - ptr->stats.tx_packets, ptr->stats.tx_errors, - ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, - ptr->stats.tx_carrier_errors); + ptr->stats.tx_packets, ptr->stats.tx_errors, + ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, + ptr->stats.tx_carrier_errors); printf(" collisions:%lu ", ptr->stats.collisions); if (can_compress) printf("compressed:%lu ", ptr->stats.tx_compressed); @@ -1129,13 +1129,12 @@ static void ife_print(struct interface *ptr) printf(" "); if (ptr->map.irq) printf("Interrupt:%d ", ptr->map.irq); - if (ptr->map.base_addr >= 0x100) /* Only print devices using it for - I/O maps */ + if (ptr->map.base_addr >= 0x100) /* Only print devices using it for I/O maps */ printf("Base address:0x%lx ", - (unsigned long) ptr->map.base_addr); + (unsigned long) ptr->map.base_addr); if (ptr->map.mem_start) { printf("Memory:%lx-%lx ", ptr->map.mem_start, - ptr->map.mem_end); + ptr->map.mem_end); } if (ptr->map.dma) printf("DMA chan:%x ", ptr->map.dma); @@ -1168,7 +1167,7 @@ static struct interface *lookup_interface(char *name) #ifdef UNUSED static int for_all_interfaces(int (*doit) (struct interface *, void *), - void *cookie) + void *cookie) { struct interface *ife; diff --git a/networking/nc.c b/networking/nc.c index 1b32e3aa3..0c843a686 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -120,7 +120,7 @@ int nc_main(int argc, char **argv) /* getopt32 is _almost_ usable: ** it cannot handle "... -e PROG -prog-opt" */ while ((opt = getopt(argc, argv, - "" IF_NC_SERVER("lp:") IF_NC_EXTRA("w:i:f:e:") )) > 0 + "" IF_NC_SERVER("lp:") IF_NC_EXTRA("w:i:f:e:") )) > 0 ) { if (ENABLE_NC_SERVER && opt == 'l') IF_NC_SERVER(do_listen++); diff --git a/networking/ntpd.c b/networking/ntpd.c index 7facf9484..45485c080 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1854,7 +1854,7 @@ recv_and_process_client_pkt(void /*int fd*/) msg.m_status = G.stratum < MAXSTRAT ? G.ntp_status : LI_ALARM; msg.m_status |= (query_status & VERSION_MASK); msg.m_status |= ((query_status & MODE_MASK) == MODE_CLIENT) ? - MODE_SERVER : MODE_SYM_PAS; + MODE_SERVER : MODE_SYM_PAS; msg.m_stratum = G.stratum; msg.m_ppoll = G.poll_exp; msg.m_precision_exp = G_precision_exp; @@ -2328,14 +2328,13 @@ set_freq(double freq) /* frequency update */ if (pps_enable) { if (!(pll_status & STA_PPSTIME)) report_event(EVNT_KERN, - NULL, "PPS enabled"); + NULL, "PPS enabled"); ntv.status |= STA_PPSTIME | STA_PPSFREQ; } else { if (pll_status & STA_PPSTIME) report_event(EVNT_KERN, - NULL, "PPS disabled"); - ntv.status &= ~(STA_PPSTIME | - STA_PPSFREQ); + NULL, "PPS disabled"); + ntv.status &= ~(STA_PPSTIME | STA_PPSFREQ); } if (sys_leap == LEAP_ADDSECOND) ntv.status |= STA_INS; @@ -2351,7 +2350,7 @@ set_freq(double freq) /* frequency update */ if (ntp_adjtime(&ntv) == TIME_ERROR) { if (!(ntv.status & STA_PPSSIGNAL)) report_event(EVNT_KERN, NULL, - "PPS no signal"); + "PPS no signal"); } pll_status = ntv.status; #ifdef STA_NANO diff --git a/networking/ntpd_simple.c b/networking/ntpd_simple.c index 1b7c66b84..55bded8ff 100644 --- a/networking/ntpd_simple.c +++ b/networking/ntpd_simple.c @@ -710,7 +710,7 @@ recv_and_process_client_pkt(void /*int fd*/) msg.m_status = G.synced ? G.leap : LI_ALARM; msg.m_status |= (query_status & VERSION_MASK); msg.m_status |= ((query_status & MODE_MASK) == MODE_CLIENT) ? - MODE_SERVER : MODE_SYM_PAS; + MODE_SERVER : MODE_SYM_PAS; msg.m_stratum = G.stratum; msg.m_ppoll = query_ppoll; msg.m_precision_exp = G_precision_exp; diff --git a/networking/ping.c b/networking/ping.c index b8a438ba8..3df67f5c3 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -724,7 +724,7 @@ static void ping6(len_and_sockaddr *lsa) ICMP6_FILTER_SETPASSALL(&filt); } if (setsockopt(pingsock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, - sizeof(filt)) < 0) + sizeof(filt)) < 0) bb_error_msg_and_die("setsockopt(ICMP6_FILTER)"); } #endif /*ICMP6_FILTER*/ diff --git a/networking/route.c b/networking/route.c index b7b5a02e6..45f2be542 100644 --- a/networking/route.c +++ b/networking/route.c @@ -409,7 +409,7 @@ static NOINLINE void INET6_setroute(int action, char **args) bb_error_msg_and_die("resolving %s", args_m1); } memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, - sizeof(struct in6_addr)); + sizeof(struct in6_addr)); rt.rtmsg_flags |= RTF_GATEWAY; continue; } @@ -498,11 +498,11 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) FILE *fp = xfopen_for_read("/proc/net/route"); printf("Kernel IP routing table\n" - "Destination Gateway Genmask Flags %s Iface\n", + "Destination Gateway Genmask Flags %s Iface\n", netstatfmt ? " MSS Window irtt" : "Metric Ref Use"); if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */ - goto ERROR; /* Empty or missing line, or read error. */ + goto ERROR; /* Empty or missing line, or read error. */ } while (1) { int r; @@ -567,8 +567,8 @@ static void INET6_displayroutes(void) FILE *fp = xfopen_for_read("/proc/net/ipv6_route"); printf("Kernel IPv6 routing table\n%-44s%-40s" - "Flags Metric Ref Use Iface\n", - "Destination", "Next Hop"); + "Flags Metric Ref Use Iface\n", + "Destination", "Next Hop"); while (1) { int r; @@ -618,8 +618,8 @@ static void INET6_displayroutes(void) (struct sockaddr *) &snaddr6.sin6_addr); snaddr6.sin6_family = AF_INET6; naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6, - 0x0fff /* Apparently, upstream never resolves. */ - ); + 0x0fff /* Apparently, upstream never resolves. */ + ); if (!r) { /* 1st pass */ snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); diff --git a/procps/powertop.c b/procps/powertop.c index a69ee12b0..71988a295 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -493,7 +493,7 @@ static NOINLINE int process_timer_stats(void) * Get information about CPU using CPUID opcode. */ static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, - unsigned int *edx) + unsigned int *edx) { /* EAX value specifies what information to return */ __asm__( diff --git a/procps/sysctl.c b/procps/sysctl.c index 878656862..c6a1de21d 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c @@ -205,7 +205,7 @@ static int sysctl_act_recursive(const char *path) continue; /* d_name is "." or ".." */ /* if path was ".", drop "./" prefix: */ retval |= sysctl_act_recursive((next[0] == '.' && next[1] == '/') ? - next + 2 : next); + next + 2 : next); free(next); } closedir(dirp); diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index ad54e22dd..2053cb146 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -253,7 +253,7 @@ enum { #define OPTION_PARAM &opt_m, &(G.logFile.path), &opt_l \ IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \ IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \ - IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ + IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ IF_FEATURE_IPC_SYSLOG( ,&opt_C) \ IF_FEATURE_SYSLOGD_CFG( ,&opt_f) diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c index 2f0854a30..b3e918fb0 100644 --- a/util-linux/fdformat.c +++ b/util-linux/fdformat.c @@ -116,7 +116,7 @@ int fdformat_main(int argc UNUSED_PARAM, char **argv) /* Check backwards so we don't need a counter */ while (--read_bytes >= 0) { if (data[read_bytes] != FD_FILL_BYTE) { - printf("bad data in cyl %d\nContinuing... ", cyl); + printf("bad data in cyl %d\nContinuing... ", cyl); } } } diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index c0be15a3a..39eb27b47 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -3023,7 +3023,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) printf("\nThe current boot file is: %s\n", sgi_get_bootfile()); if (read_maybe_empty("Please enter the name of the " - "new boot file: ") == '\n') + "new boot file: ") == '\n') printf("Boot file unchanged\n"); else sgi_set_bootfile(line_ptr); diff --git a/util-linux/flock.c b/util-linux/flock.c index e9be4eee9..05a747f72 100644 --- a/util-linux/flock.c +++ b/util-linux/flock.c @@ -45,7 +45,7 @@ int flock_main(int argc UNUSED_PARAM, char **argv) if (argv[1]) { fd = open(argv[0], O_RDONLY|O_NOCTTY|O_CREAT, 0666); if (fd < 0 && errno == EISDIR) - fd = open(argv[0], O_RDONLY|O_NOCTTY); + fd = open(argv[0], O_RDONLY|O_NOCTTY); if (fd < 0) bb_perror_msg_and_die("can't open '%s'", argv[0]); //TODO? close_on_exec_on(fd); diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c index 274050cdf..888f70ef8 100644 --- a/util-linux/ipcrm.c +++ b/util-linux/ipcrm.c @@ -160,7 +160,7 @@ int ipcrm_main(int argc, char **argv) /* convert key to id */ id = ((c == 'q') ? msgget(key, 0) : - (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0)); + (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0)); if (id < 0) { const char *errmsg; @@ -189,8 +189,8 @@ int ipcrm_main(int argc, char **argv) } result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : - (c == 'm') ? shmctl(id, IPC_RMID, NULL) : - semctl(id, 0, IPC_RMID, arg)); + (c == 'm') ? shmctl(id, IPC_RMID, NULL) : + semctl(id, 0, IPC_RMID, arg)); if (result) { const char *errmsg; diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index ee7df5e33..8fdaf0b85 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c @@ -154,52 +154,52 @@ static NOINLINE void do_shm(void) /* glibc 2.1.3 and all earlier libc's have ints as fields of struct shminfo; glibc 2.1.91 has unsigned long; ach */ printf("max number of segments = %lu\n" - "max seg size (kbytes) = %lu\n" - "max total shared memory (pages) = %lu\n" - "min seg size (bytes) = %lu\n", - (unsigned long) shminfo.shmmni, - (unsigned long) (shminfo.shmmax >> 10), - (unsigned long) shminfo.shmall, - (unsigned long) shminfo.shmmin); + "max seg size (kbytes) = %lu\n" + "max total shared memory (pages) = %lu\n" + "min seg size (bytes) = %lu\n", + (unsigned long) shminfo.shmmni, + (unsigned long) (shminfo.shmmax >> 10), + (unsigned long) shminfo.shmall, + (unsigned long) shminfo.shmmin); return; case STATUS: printf("------ Shared Memory %s --------\n", "Status"); - printf( "segments allocated %d\n" - "pages allocated %ld\n" - "pages resident %ld\n" - "pages swapped %ld\n" - "Swap performance: %ld attempts\t%ld successes\n", - shm_info.used_ids, - shm_info.shm_tot, - shm_info.shm_rss, - shm_info.shm_swp, - shm_info.swap_attempts, shm_info.swap_successes); + printf("segments allocated %d\n" + "pages allocated %ld\n" + "pages resident %ld\n" + "pages swapped %ld\n" + "Swap performance: %ld attempts\t%ld successes\n", + shm_info.used_ids, + shm_info.shm_tot, + shm_info.shm_rss, + shm_info.shm_swp, + shm_info.swap_attempts, shm_info.swap_successes); return; case CREATOR: printf("------ Shared Memory %s --------\n", "Segment Creators/Owners"); - printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", - "shmid", "perms", "cuid", "cgid", "uid", "gid"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", + "shmid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times"); - printf( "%-10s %-10s %-20s %-20s %-20s\n", - "shmid", "owner", "attached", "detached", "changed"); + printf("%-10s %-10s %-20s %-20s %-20s\n", + "shmid", "owner", "attached", "detached", "changed"); break; case PID: printf("------ Shared Memory %s --------\n", "Creator/Last-op"); - printf( "%-10s %-10s %-10s %-10s\n", - "shmid", "owner", "cpid", "lpid"); + printf("%-10s %-10s %-10s %-10s\n", + "shmid", "owner", "cpid", "lpid"); break; default: printf("------ Shared Memory %s --------\n", "Segments"); - printf( "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", - "key", "shmid", "owner", "perms", "bytes", "nattch", - "status"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", + "key", "shmid", "owner", "perms", "bytes", "nattch", + "status"); break; } @@ -220,11 +220,11 @@ static NOINLINE void do_shm(void) printf("%-10d %-10d", shmid, ipcp->uid); /* ctime uses static buffer: use separate calls */ printf(" %-20.16s", shmseg.shm_atime - ? ctime(&shmseg.shm_atime) + 4 : "Not set"); + ? ctime(&shmseg.shm_atime) + 4 : "Not set"); printf(" %-20.16s", shmseg.shm_dtime - ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); + ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); printf(" %-20.16s\n", shmseg.shm_ctime - ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); + ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); break; case PID: if (pw) @@ -241,17 +241,17 @@ static NOINLINE void do_shm(void) else printf("%-10d %-10d", shmid, ipcp->uid); printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, - /* - * earlier: int, Austin has size_t - */ - (unsigned long) shmseg.shm_segsz, - /* - * glibc-2.1.3 and earlier has unsigned short; - * Austin has shmatt_t - */ - (long) shmseg.shm_nattch, - ipcp->mode & SHM_DEST ? "dest" : " ", - ipcp->mode & SHM_LOCKED ? "locked" : " "); + /* + * earlier: int, Austin has size_t + */ + (unsigned long) shmseg.shm_segsz, + /* + * glibc-2.1.3 and earlier has unsigned short; + * Austin has shmatt_t + */ + (long) shmseg.shm_nattch, + ipcp->mode & SHM_DEST ? "dest" : " ", + ipcp->mode & SHM_LOCKED ? "locked" : " "); break; } } @@ -281,32 +281,32 @@ static NOINLINE void do_sem(void) if ((semctl(0, 0, IPC_INFO, arg)) < 0) return; printf("max number of arrays = %d\n" - "max semaphores per array = %d\n" - "max semaphores system wide = %d\n" - "max ops per semop call = %d\n" - "semaphore max value = %d\n", - seminfo.semmni, - seminfo.semmsl, - seminfo.semmns, seminfo.semopm, seminfo.semvmx); + "max semaphores per array = %d\n" + "max semaphores system wide = %d\n" + "max ops per semop call = %d\n" + "semaphore max value = %d\n", + seminfo.semmni, + seminfo.semmsl, + seminfo.semmns, seminfo.semopm, seminfo.semvmx); return; case STATUS: printf("------ Semaphore %s --------\n", "Status"); - printf( "used arrays = %d\n" - "allocated semaphores = %d\n", - seminfo.semusz, seminfo.semaem); + printf("used arrays = %d\n" + "allocated semaphores = %d\n", + seminfo.semusz, seminfo.semaem); return; case CREATOR: printf("------ Semaphore %s --------\n", "Arrays Creators/Owners"); - printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", - "semid", "perms", "cuid", "cgid", "uid", "gid"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", + "semid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Shared Memory %s --------\n", "Operation/Change Times"); - printf( "%-8s %-10s %-26.24s %-26.24s\n", - "shmid", "owner", "last-op", "last-changed"); + printf("%-8s %-10s %-26.24s %-26.24s\n", + "shmid", "owner", "last-op", "last-changed"); break; case PID: @@ -314,8 +314,8 @@ static NOINLINE void do_sem(void) default: printf("------ Semaphore %s --------\n", "Arrays"); - printf( "%-10s %-10s %-10s %-10s %-10s\n", - "key", "semid", "owner", "perms", "nsems"); + printf("%-10s %-10s %-10s %-10s %-10s\n", + "key", "semid", "owner", "perms", "nsems"); break; } @@ -337,9 +337,9 @@ static NOINLINE void do_sem(void) printf("%-8d %-10d", semid, ipcp->uid); /* ctime uses static buffer: use separate calls */ printf(" %-26.24s", semary.sem_otime - ? ctime(&semary.sem_otime) : "Not set"); + ? ctime(&semary.sem_otime) : "Not set"); printf(" %-26.24s\n", semary.sem_ctime - ? ctime(&semary.sem_ctime) : "Not set"); + ? ctime(&semary.sem_ctime) : "Not set"); break; case PID: break; @@ -351,13 +351,13 @@ static NOINLINE void do_sem(void) else printf("%-10d %-9d", semid, ipcp->uid); printf(" %-10o %-10ld\n", ipcp->mode & 0777, - /* - * glibc-2.1.3 and earlier has unsigned short; - * glibc-2.1.91 has variation between - * unsigned short and unsigned long - * Austin prescribes unsigned short. - */ - (long) semary.sem_nsems); + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short and unsigned long + * Austin prescribes unsigned short. + */ + (long) semary.sem_nsems); break; } } @@ -383,42 +383,42 @@ static NOINLINE void do_msg(void) if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0) return; printf("------ Message%s --------\n", "s: Limits"); - printf( "max queues system wide = %d\n" - "max size of message (bytes) = %d\n" - "default max size of queue (bytes) = %d\n", - msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); + printf("max queues system wide = %d\n" + "max size of message (bytes) = %d\n" + "default max size of queue (bytes) = %d\n", + msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); return; case STATUS: printf("------ Message%s --------\n", "s: Status"); - printf( "allocated queues = %d\n" - "used headers = %d\n" - "used space = %d bytes\n", - msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); + printf("allocated queues = %d\n" + "used headers = %d\n" + "used space = %d bytes\n", + msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); return; case CREATOR: printf("------ Message%s --------\n", " Queues: Creators/Owners"); - printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", - "msqid", "perms", "cuid", "cgid", "uid", "gid"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", + "msqid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Message%s --------\n", " Queues Send/Recv/Change Times"); - printf( "%-8s %-10s %-20s %-20s %-20s\n", - "msqid", "owner", "send", "recv", "change"); + printf("%-8s %-10s %-20s %-20s %-20s\n", + "msqid", "owner", "send", "recv", "change"); break; case PID: printf("------ Message%s --------\n", " Queues PIDs"); - printf( "%-10s %-10s %-10s %-10s\n", - "msqid", "owner", "lspid", "lrpid"); + printf("%-10s %-10s %-10s %-10s\n", + "msqid", "owner", "lspid", "lrpid"); break; default: printf("------ Message%s --------\n", " Queues"); - printf( "%-10s %-10s %-10s %-10s %-12s %-12s\n", - "key", "msqid", "owner", "perms", "used-bytes", "messages"); + printf("%-10s %-10s %-10s %-10s %-12s %-12s\n", + "key", "msqid", "owner", "perms", "used-bytes", "messages"); break; } @@ -438,11 +438,11 @@ static NOINLINE void do_msg(void) else printf("%-8d %-10d", msqid, ipcp->uid); printf(" %-20.16s", msgque.msg_stime - ? ctime(&msgque.msg_stime) + 4 : "Not set"); + ? ctime(&msgque.msg_stime) + 4 : "Not set"); printf(" %-20.16s", msgque.msg_rtime - ? ctime(&msgque.msg_rtime) + 4 : "Not set"); + ? ctime(&msgque.msg_rtime) + 4 : "Not set"); printf(" %-20.16s\n", msgque.msg_ctime - ? ctime(&msgque.msg_ctime) + 4 : "Not set"); + ? ctime(&msgque.msg_ctime) + 4 : "Not set"); break; case PID: if (pw) @@ -459,13 +459,13 @@ static NOINLINE void do_msg(void) else printf("%-10d %-10d", msqid, ipcp->uid); printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, - /* - * glibc-2.1.3 and earlier has unsigned short; - * glibc-2.1.91 has variation between - * unsigned short, unsigned long - * Austin has msgqnum_t - */ - (long) msgque.msg_cbytes, (long) msgque.msg_qnum); + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short, unsigned long + * Austin has msgqnum_t + */ + (long) msgque.msg_cbytes, (long) msgque.msg_qnum); break; } } @@ -483,18 +483,18 @@ static void print_shm(int shmid) } printf("\nShared memory Segment shmid=%d\n" - "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" - "mode=%#o\taccess_perms=%#o\n" - "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", - shmid, - ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, - ipcp->mode, ipcp->mode & 0777, - (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, - (long) shmds.shm_nattch); + "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" + "mode=%#o\taccess_perms=%#o\n" + "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", + shmid, + ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, + ipcp->mode, ipcp->mode & 0777, + (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, + (long) shmds.shm_nattch); printf("att_time=%-26.24s\n", - shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set"); + shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set"); printf("det_time=%-26.24s\n", - shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set"); + shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set"); printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime)); } @@ -510,24 +510,24 @@ static void print_msg(int msqid) } printf("\nMessage Queue msqid=%d\n" - "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" - "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", - msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, - /* - * glibc-2.1.3 and earlier has unsigned short; - * glibc-2.1.91 has variation between - * unsigned short, unsigned long - * Austin has msgqnum_t (for msg_qbytes) - */ - (long) buf.msg_cbytes, (long) buf.msg_qbytes, - (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); + "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" + "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", + msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short, unsigned long + * Austin has msgqnum_t (for msg_qbytes) + */ + (long) buf.msg_cbytes, (long) buf.msg_qbytes, + (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); printf("send_time=%-26.24s\n", - buf.msg_stime ? ctime(&buf.msg_stime) : "Not set"); + buf.msg_stime ? ctime(&buf.msg_stime) : "Not set"); printf("rcv_time=%-26.24s\n", - buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set"); + buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set"); printf("change_time=%-26.24s\n\n", - buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set"); + buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set"); } static void print_sem(int semid) @@ -544,19 +544,19 @@ static void print_sem(int semid) } printf("\nSemaphore Array semid=%d\n" - "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" - "mode=%#o, access_perms=%#o\n" - "nsems = %ld\n" - "otime = %-26.24s\n", - semid, - ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, - ipcp->mode, ipcp->mode & 0777, - (long) semds.sem_nsems, - semds.sem_otime ? ctime(&semds.sem_otime) : "Not set"); + "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" + "mode=%#o, access_perms=%#o\n" + "nsems = %ld\n" + "otime = %-26.24s\n", + semid, + ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, + ipcp->mode, ipcp->mode & 0777, + (long) semds.sem_nsems, + semds.sem_otime ? ctime(&semds.sem_otime) : "Not set"); printf("ctime = %-26.24s\n" - "%-10s %-10s %-10s %-10s %-10s\n", - ctime(&semds.sem_ctime), - "semnum", "value", "ncount", "zcount", "pid"); + "%-10s %-10s %-10s %-10s %-10s\n", + ctime(&semds.sem_ctime), + "semnum", "value", "ncount", "zcount", "pid"); arg.val = 0; for (i = 0; i < semds.sem_nsems; i++) { diff --git a/util-linux/lspci.c b/util-linux/lspci.c index 5184858d1..514678afd 100644 --- a/util-linux/lspci.c +++ b/util-linux/lspci.c @@ -74,11 +74,11 @@ static int FAST_FUNC fileAction( if (option_mask32 & OPT_m) { printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"", - pci_slot_name, pci_class, pci_vid, pci_did, - pci_subsys_vid, pci_subsys_did); + pci_slot_name, pci_class, pci_vid, pci_did, + pci_subsys_vid, pci_subsys_did); } else { printf("%s Class %04x: %04x:%04x", - pci_slot_name, pci_class, pci_vid, pci_did); + pci_slot_name, pci_class, pci_vid, pci_did); } if ((option_mask32 & OPT_k) && driver) { diff --git a/util-linux/mount.c b/util-linux/mount.c index 525fdcce9..bcb298c07 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -927,7 +927,7 @@ static bool_t xdr_fhandle(XDR *xdrs, fhandle objp) static bool_t xdr_fhstatus(XDR *xdrs, fhstatus *objp) { if (!xdr_u_int(xdrs, &objp->fhs_status)) - return FALSE; + return FALSE; if (objp->fhs_status == 0) return xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle); return TRUE; @@ -941,8 +941,8 @@ static bool_t xdr_dirpath(XDR *xdrs, dirpath *objp) static bool_t xdr_fhandle3(XDR *xdrs, fhandle3 *objp) { return xdr_bytes(xdrs, (char **)&objp->fhandle3_val, - (unsigned int *) &objp->fhandle3_len, - FHSIZE3); + (unsigned int *) &objp->fhandle3_len, + FHSIZE3); } static bool_t xdr_mountres3_ok(XDR *xdrs, mountres3_ok *objp) @@ -950,10 +950,10 @@ static bool_t xdr_mountres3_ok(XDR *xdrs, mountres3_ok *objp) if (!xdr_fhandle3(xdrs, &objp->fhandle)) return FALSE; return xdr_array(xdrs, &(objp->auth_flavours.auth_flavours_val), - &(objp->auth_flavours.auth_flavours_len), - ~0, - sizeof(int), - (xdrproc_t) xdr_int); + &(objp->auth_flavours.auth_flavours_len), + ~0, + sizeof(int), + (xdrproc_t) xdr_int); } static bool_t xdr_mountstat3(XDR *xdrs, mountstat3 *objp) @@ -1522,19 +1522,19 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi switch (pm_mnt.pm_prot) { case IPPROTO_UDP: mclient = clntudp_create(&mount_server_addr, - pm_mnt.pm_prog, - pm_mnt.pm_vers, - retry_timeout, - &msock); + pm_mnt.pm_prog, + pm_mnt.pm_vers, + retry_timeout, + &msock); if (mclient) break; mount_server_addr.sin_port = htons(pm_mnt.pm_port); msock = RPC_ANYSOCK; case IPPROTO_TCP: mclient = clnttcp_create(&mount_server_addr, - pm_mnt.pm_prog, - pm_mnt.pm_vers, - &msock, 0, 0); + pm_mnt.pm_prog, + pm_mnt.pm_vers, + &msock, 0, 0); break; default: mclient = NULL; @@ -1555,18 +1555,18 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi if (pm_mnt.pm_vers == 3) clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT, - (xdrproc_t) xdr_dirpath, - (caddr_t) &pathname, - (xdrproc_t) xdr_mountres3, - (caddr_t) &status, - total_timeout); + (xdrproc_t) xdr_dirpath, + (caddr_t) &pathname, + (xdrproc_t) xdr_mountres3, + (caddr_t) &status, + total_timeout); else clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, - (xdrproc_t) xdr_dirpath, - (caddr_t) &pathname, - (xdrproc_t) xdr_fhstatus, - (caddr_t) &status, - total_timeout); + (xdrproc_t) xdr_dirpath, + (caddr_t) &pathname, + (xdrproc_t) xdr_fhstatus, + (caddr_t) &status, + total_timeout); if (clnt_stat == RPC_SUCCESS) goto prepare_kernel_data; /* we're done */ diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index 4ed801137..974fe89c4 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -163,7 +163,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) while (fgets(mapline, S_LEN, map)) { if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3) bb_error_msg_and_die("%s(%i): wrong map line", - mapFile, maplineno); + mapFile, maplineno); if (!strcmp(fn_name, "_stext")) /* only elf works like this */ { add0 = fn_add; @@ -198,7 +198,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) if (indx >= len / sizeof(*buf)) bb_error_msg_and_die("profile address out of range. " - "Wrong map file?"); + "Wrong map file?"); while (indx < (next_add-add0)/step) { if (optBins && (buf[indx] || optAll)) { @@ -220,10 +220,10 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) ) { if (optVerbose) printf("%016llx %-40s %6i %8.4f\n", fn_add, - fn_name, this, this/(double)fn_len); + fn_name, this, this/(double)fn_len); else printf("%6i %-40s %8.4f\n", - this, fn_name, this/(double)fn_len); + this, fn_name, this/(double)fn_len); if (optSub) { unsigned long long scan; @@ -233,8 +233,8 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) addr = (scan - 1)*step + add0; printf("\t%#llx\t%s+%#llx\t%u\n", - addr, fn_name, addr - fn_add, - buf[scan]); + addr, fn_name, addr - fn_add, + buf[scan]); } } } @@ -251,10 +251,10 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) /* trailer */ if (optVerbose) printf("%016x %-40s %6i %8.4f\n", - 0, "total", total, total/(double)(fn_add-add0)); + 0, "total", total, total/(double)(fn_add-add0)); else printf("%6i %-40s %8.4f\n", - total, "total", total/(double)(fn_add-add0)); + total, "total", total/(double)(fn_add-add0)); fclose(map); free(buf); diff --git a/util-linux/volume_id/linux_raid.c b/util-linux/volume_id/linux_raid.c index 761e54f9f..209eaabe9 100644 --- a/util-linux/volume_id/linux_raid.c +++ b/util-linux/volume_id/linux_raid.c @@ -69,9 +69,9 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, volume_id_set_uuid(id, uuid, UUID_DCE); // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u", -// le32_to_cpu(mdp->major_version), -// le32_to_cpu(mdp->minor_version), -// le32_to_cpu(mdp->patch_version)); +// le32_to_cpu(mdp->major_version), +// le32_to_cpu(mdp->minor_version), +// le32_to_cpu(mdp->patch_version)); dbg("found raid signature"); // volume_id_set_usage(id, VOLUME_ID_RAID); diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index 0e2d24be0..061545fde 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c @@ -129,7 +129,7 @@ void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count) { - volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count); + volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count); } void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format) -- cgit v1.2.3-55-g6feb From 6928d9f0495d814a08195d0e9805fd91cbb3d384 Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh Date: Mon, 14 Jan 2013 02:21:41 +0100 Subject: volume_id: add squashfs detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit function old new delta volume_id_probe_squashfs - 74 +74 fs1 12 16 +4 Signed-off-by: Sven-Göran Bergh Signed-off-by: Denys Vlasenko --- util-linux/Config.src | 10 ++++++ util-linux/volume_id/squashfs.c | 59 +++++++++++++++++++++++++++++++ util-linux/volume_id/volume_id.c | 3 ++ util-linux/volume_id/volume_id_internal.h | 2 ++ 4 files changed, 74 insertions(+) create mode 100644 util-linux/volume_id/squashfs.c diff --git a/util-linux/Config.src b/util-linux/Config.src index e4516ddb7..6c1b928da 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -841,6 +841,16 @@ config FEATURE_VOLUMEID_ROMFS help TODO +config FEATURE_VOLUMEID_SQUASHFS + bool "SquashFS filesystem" + default y + depends on VOLUMEID && FEATURE_BLKID_TYPE + help + Squashfs is a compressed read-only filesystem for Linux. Squashfs is + intended for general read-only filesystem use and in constrained block + device/memory systems (e.g. embedded systems) where low overhead is + needed. + config FEATURE_VOLUMEID_SYSV bool "sysv filesystem" default y diff --git a/util-linux/volume_id/squashfs.c b/util-linux/volume_id/squashfs.c new file mode 100644 index 000000000..331ac20fd --- /dev/null +++ b/util-linux/volume_id/squashfs.c @@ -0,0 +1,59 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2012 S-G Bergh + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//config:config FEATURE_VOLUMEID_SQUASHFS +//config: bool "SquashFS filesystem" +//config: default y +//config: depends on VOLUMEID && FEATURE_BLKID_TYPE +//config: help +//config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is +//config: intended for general read-only filesystem use and in constrained block +//config: device/memory systems (e.g. embedded systems) where low overhead is +//config: needed. + +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o + +#include "volume_id_internal.h" + +struct squashfs_superblock { + uint32_t magic; +/* + uint32_t dummy[6]; + uint16_t major; + uint16_t minor; +*/ +} PACKED; + +int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/) +{ +#define off ((uint64_t)0) + struct squashfs_superblock *sb; + + dbg("SquashFS: probing at offset 0x%llx", (unsigned long long) off); + sb = volume_id_get_buffer(id, off, 0x200); + if (!sb) + return -1; + + // Old SquashFS (pre 4.0) can be both big and little endian, so test for both. + // Likewise, it is commonly used in firwmare with some non-standard signatures. +#define pack(a,b,c,d) ( (uint32_t)((a * 256 + b) * 256 + c) * 256 + d ) +#define SIG1 pack('s','q','s','h') +#define SIG2 pack('h','s','q','s') +#define SIG3 pack('s','h','s','q') +#define SIG4 pack('q','s','h','s') + if (sb->magic == SIG1 + || sb->magic == SIG2 + || sb->magic == SIG3 + || sb->magic == SIG4 + ) { + IF_FEATURE_BLKID_TYPE(id->type = "squashfs";) + return 0; + } + + return -1; +} diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index 3c3c69818..f0fc84c05 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c @@ -99,6 +99,9 @@ static const probe_fptr fs1[] = { #if ENABLE_FEATURE_VOLUMEID_MAC volume_id_probe_mac_partition_map, #endif +#if ENABLE_FEATURE_VOLUMEID_SQUASHFS + volume_id_probe_squashfs, +#endif #if ENABLE_FEATURE_VOLUMEID_XFS volume_id_probe_xfs, #endif diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index e26ebaab6..3f02bd50d 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -227,6 +227,8 @@ int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/); +int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/); + int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_udf(struct volume_id *id /*,uint64_t off*/); -- cgit v1.2.3-55-g6feb From 90801dadfa06e2277d136132f71a75569593eda4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Jan 2013 02:24:27 +0100 Subject: Remove redundant 'config FEATURE_VOLUMEID_SQUASHFS' Signed-off-by: Denys Vlasenko --- util-linux/volume_id/squashfs.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/util-linux/volume_id/squashfs.c b/util-linux/volume_id/squashfs.c index 331ac20fd..c5b4f9ced 100644 --- a/util-linux/volume_id/squashfs.c +++ b/util-linux/volume_id/squashfs.c @@ -6,16 +6,6 @@ * Licensed under GPLv2, see file LICENSE in this source tree. */ -//config:config FEATURE_VOLUMEID_SQUASHFS -//config: bool "SquashFS filesystem" -//config: default y -//config: depends on VOLUMEID && FEATURE_BLKID_TYPE -//config: help -//config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is -//config: intended for general read-only filesystem use and in constrained block -//config: device/memory systems (e.g. embedded systems) where low overhead is -//config: needed. - //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o #include "volume_id_internal.h" -- cgit v1.2.3-55-g6feb From b7841cf7b919b16d1bd4619154bf7cb4c22b4ccd Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Mon, 14 Jan 2013 02:39:10 +0100 Subject: ntpd: fix incorrect m_status field in outgoing packets. Closes 5120 When using busybox ntpd with an NTPv3 client and NTPv4 server (or vice versa), the version numbers can be incorrectly ORed together, yielding the bogus value of "NTPv7". This makes ntpd unusable with clients such as Chrony and Windows "Internet Time". This patch avoids the version mangling, by copying only the Leap Indicator bits from the server's status field. Signed-off-by: Paul Marks Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 45485c080..79b7c3793 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1851,7 +1851,7 @@ recv_and_process_client_pkt(void /*int fd*/) /* Build a reply packet */ memset(&msg, 0, sizeof(msg)); - msg.m_status = G.stratum < MAXSTRAT ? G.ntp_status : LI_ALARM; + msg.m_status = G.stratum < MAXSTRAT ? (G.ntp_status & LI_MASK) : LI_ALARM; msg.m_status |= (query_status & VERSION_MASK); msg.m_status |= ((query_status & MODE_MASK) == MODE_CLIENT) ? MODE_SERVER : MODE_SYM_PAS; -- cgit v1.2.3-55-g6feb From b8173b603f57dcf918a67f1ec00763ab5f4e1cf8 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 14 Jan 2013 05:20:50 +0100 Subject: sha3sum: new applet function old new delta KeccakF - 496 +496 KeccakF_RoundConstants - 192 +192 sha3_hash - 171 +171 sha3_end - 40 +40 hash_file 274 299 +25 KeccakF_RotationConstants - 25 +25 KeccakF_PiLane - 25 +25 packed_usage 29213 29232 +19 sha3_begin - 18 +18 KeccakF_Mod5 - 10 +10 applet_names 2445 2453 +8 applet_main 1420 1424 +4 applet_nameofs 710 712 +2 ------------------------------------------------------------------------------ (add/remove: 8/0 grow/shrink: 9/7 up/down: 1049/-54) Total: ~995 bytes Signed-off-by: Lauri Kasanen Signed-off-by: Denys Vlasenko --- coreutils/Config.src | 12 ++- coreutils/Kbuild.src | 1 + coreutils/md5_sha1_sum.c | 17 +++++ include/applets.src.h | 1 + include/libbb.h | 7 ++ include/platform.h | 5 +- libbb/hash_md5_sha.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++ testsuite/sha3sum.tests | 3 + 8 files changed, 236 insertions(+), 4 deletions(-) create mode 100755 testsuite/sha3sum.tests diff --git a/coreutils/Config.src b/coreutils/Config.src index a28449b11..0c44c4b51 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -514,6 +514,12 @@ config SHA512SUM help Compute and check SHA512 message digest +config SHA3SUM + bool "sha3sum" + default y + help + Compute and check SHA3 (512-bit) message digest + config SLEEP bool "sleep" default y @@ -766,13 +772,13 @@ config FEATURE_HUMAN_READABLE help Allow df, du, and ls to have human readable output. -comment "Common options for md5sum, sha1sum, sha256sum, sha512sum" - depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM +comment "Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum" + depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM config FEATURE_MD5_SHA1_SUM_CHECK bool "Enable -c, -s and -w options" default y - depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM + depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM help Enabling the -c options allows files to be checked against pre-calculated hash values. diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src index d6453f014..b715b9c47 100644 --- a/coreutils/Kbuild.src +++ b/coreutils/Kbuild.src @@ -62,6 +62,7 @@ lib-$(CONFIG_SEQ) += seq.o lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o +lib-$(CONFIG_SHA3SUM) += md5_sha1_sum.o lib-$(CONFIG_SLEEP) += sleep.o lib-$(CONFIG_SPLIT) += split.o lib-$(CONFIG_SORT) += sort.o diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 59b520fce..92a4d4462 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -55,6 +55,16 @@ //usage: "\n -s Don't output anything, status code shows success" //usage: "\n -w Warn about improperly formatted checksum lines" //usage: ) +//usage: +//usage:#define sha3sum_trivial_usage +//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..." +//usage:#define sha3sum_full_usage "\n\n" +//usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA3-512 checksums" +//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" +//usage: "\n -c Check sums against list in FILEs" +//usage: "\n -s Don't output anything, status code shows success" +//usage: "\n -w Warn about improperly formatted checksum lines" +//usage: ) #include "libbb.h" @@ -65,6 +75,7 @@ enum { HASH_MD5 = 's', /* "md5>s typedef int bb__aliased_int FIX_ALIASING; +typedef long bb__aliased_long FIX_ALIASING; typedef uint16_t bb__aliased_uint16_t FIX_ALIASING; typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; @@ -212,7 +213,8 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; * a lvalue. This makes it more likely to not swap them by mistake */ #if defined(i386) || defined(__x86_64__) || defined(__powerpc__) -# define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp)) +# define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp)) +# define move_from_unaligned_long(v, longp) ((v) = *(bb__aliased_long*)(longp)) # define move_from_unaligned16(v, u16p) ((v) = *(bb__aliased_uint16_t*)(u16p)) # define move_from_unaligned32(v, u32p) ((v) = *(bb__aliased_uint32_t*)(u32p)) # define move_to_unaligned16(u16p, v) (*(bb__aliased_uint16_t*)(u16p) = (v)) @@ -221,6 +223,7 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; #else /* performs reasonably well (gcc usually inlines memcpy here) */ # define move_from_unaligned_int(v, intp) (memcpy(&(v), (intp), sizeof(int))) +# define move_from_unaligned_long(v, longp) (memcpy(&(v), (longp), sizeof(long))) # define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2)) # define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4)) # define move_to_unaligned16(u16p, v) do { \ diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index a313c2a65..06a2400b5 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -31,6 +31,11 @@ static ALWAYS_INLINE uint64_t rotr64(uint64_t x, unsigned n) return (x >> n) | (x << (64 - n)); } +/* rotl64 only used for sha3 currently */ +static ALWAYS_INLINE uint64_t rotl64(uint64_t x, unsigned n) +{ + return (x << n) | (x >> (64 - n)); +} /* Feed data through a temporary buffer. * The internal buffer remembers previous data until it has 64 @@ -896,3 +901,192 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) } memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); } + + +/* + * The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, + * Michael Peeters and Gilles Van Assche. For more information, feedback or + * questions, please refer to our website: http://keccak.noekeon.org/ + * + * Implementation by Ronny Van Keer, + * hereby denoted as "the implementer". + * + * To the extent possible under law, the implementer has waived all copyright + * and related or neighboring rights to the source code in this file. + * http://creativecommons.org/publicdomain/zero/1.0/ + * + * Busybox modifications (C) Lauri Kasanen, under the GPLv2. + */ + +enum { + cKeccakR_SizeInBytes = 576 / 8, + cKeccakNumberOfRounds = 24, +}; + +static const uint64_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { + 0x0000000000000001ULL, + 0x0000000000008082ULL, + 0x800000000000808aULL, + 0x8000000080008000ULL, + 0x000000000000808bULL, + 0x0000000080000001ULL, + 0x8000000080008081ULL, + 0x8000000000008009ULL, + 0x000000000000008aULL, + 0x0000000000000088ULL, + 0x0000000080008009ULL, + 0x000000008000000aULL, + 0x000000008000808bULL, + 0x800000000000008bULL, + 0x8000000000008089ULL, + 0x8000000000008003ULL, + 0x8000000000008002ULL, + 0x8000000000000080ULL, + 0x000000000000800aULL, + 0x800000008000000aULL, + 0x8000000080008081ULL, + 0x8000000000008080ULL, + 0x0000000080000001ULL, + 0x8000000080008008ULL +}; + +static const uint8_t KeccakF_RotationConstants[25] = { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, + 18, 39, 61, 20, 44 +}; + +static const uint8_t KeccakF_PiLane[25] = { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, + 14, 22, 9, 6, 1 +}; + +static const uint8_t KeccakF_Mod5[10] = { + 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 +}; + +static void KeccakF(uint64_t *state) +{ + uint8_t x, y; + uint64_t temp; + uint64_t BC[5]; + int round; + + if (BB_BIG_ENDIAN) { + for (x = 0; x < 25; x++) { + state[x] = SWAP_LE64(state[x]); + } + } + + for (round = 0; round < cKeccakNumberOfRounds; ++round) { + /* Theta */ + for (x = 0; x < 5; ++x) { + BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ + state[15 + x] ^ state[20 + x]; + } + for (x = 0; x < 5; ++x) { + temp = BC[KeccakF_Mod5[x + 4]] ^ + rotl64(BC[KeccakF_Mod5[x + 1]], 1); + + for (y = 0; y <= 20; y += 5) { + state[y + x] ^= temp; + } + } + + /* Rho Pi */ + temp = state[1]; + for (x = 0; x < 24; ++x) { + BC[0] = state[KeccakF_PiLane[x]]; + state[KeccakF_PiLane[x]] = + rotl64(temp, KeccakF_RotationConstants[x]); + temp = BC[0]; + } + + /* Chi */ + for (y = 0; y < 25; y += 5) { + BC[0] = state[y + 0]; + BC[1] = state[y + 1]; + BC[2] = state[y + 2]; + BC[3] = state[y + 3]; + BC[4] = state[y + 4]; + for (x = 0; x < 5; ++x) { + state[y + x] = + BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & + BC[KeccakF_Mod5[x + 2]]); + } + } + + /* Iota */ + state[0] ^= KeccakF_RoundConstants[round]; + } + + if (BB_BIG_ENDIAN) { + for (x = 0; x < 25; x++) { + state[x] = SWAP_LE64(state[x]); + } + } +} + +void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) +{ + memset(ctx, 0, sizeof(*ctx)); +} + +void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) +{ + const uint8_t *data = buf; + + /* If already data in queue, continue queuing first */ + while (bytes != 0 && ctx->bytes_queued != 0) { + uint8_t *buffer = (uint8_t*)ctx->state; + buffer[ctx->bytes_queued] ^= *data++; + bytes--; + ctx->bytes_queued++; + if (ctx->bytes_queued == cKeccakR_SizeInBytes) { + KeccakF(ctx->state); + ctx->bytes_queued = 0; + } + } + + /* Absorb complete blocks */ + while (bytes >= cKeccakR_SizeInBytes) { + /* XOR data onto beginning of state[]. + * We try to be efficient - operate on word at a time, not byte. + * Yet safe wrt unaligned access: can't just use "*(long*)data"... + */ + unsigned count = cKeccakR_SizeInBytes / sizeof(long); + long *buffer = (long*)ctx->state; + do { + long v; + move_from_unaligned_long(v, (long*)data); + *buffer++ ^= v; + data += sizeof(long); + } while (--count); + + KeccakF(ctx->state); + bytes -= cKeccakR_SizeInBytes; + } + + /* Queue remaining data bytes */ + while (bytes != 0) { + uint8_t *buffer = (uint8_t*)ctx->state; + buffer[ctx->bytes_queued] ^= *data++; + ctx->bytes_queued++; + bytes--; + } +} + +void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) +{ + /* Padding */ + uint8_t *buffer = (uint8_t*)ctx->state; + /* 0 is the number of bits in last, incomplete byte + * (that is, zero: we never have incomplete bytes): + */ + buffer[ctx->bytes_queued] ^= 1 << 0; + buffer[cKeccakR_SizeInBytes - 1] ^= 0x80; + + KeccakF(ctx->state); + + /* Output */ + memcpy(hashval, ctx->state, 64); +} diff --git a/testsuite/sha3sum.tests b/testsuite/sha3sum.tests new file mode 100755 index 000000000..82fada633 --- /dev/null +++ b/testsuite/sha3sum.tests @@ -0,0 +1,3 @@ +#!/bin/sh + +. ./md5sum.tests sha3sum c29d77bc548fa2b20a04c861400a5360879c52156e2a54a3415b99a9a3123e1d5f36714a24eca8c1f05a8e2d8ba859c930d41141f64a255c6794436fc99c486a -- cgit v1.2.3-55-g6feb From 60cb48ca50fcff24aa6c3927f51e4a508fa118f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Jan 2013 15:57:44 +0100 Subject: whitespace cleanup. no code changes Signed-off-by: Denys Vlasenko --- archival/cpio.c | 30 ++++++------- archival/libarchive/decompress_gunzip.c | 4 +- archival/libarchive/decompress_uncompress.c | 4 +- archival/libarchive/lzo1x_9x.c | 12 +++--- archival/libarchive/lzo1x_c.c | 2 +- archival/libarchive/lzo1x_d.c | 2 +- archival/lzop.c | 8 ++-- coreutils/cal.c | 7 +-- coreutils/mknod.c | 2 +- coreutils/od_bloaty.c | 4 +- coreutils/stat.c | 58 ++++++++++++++----------- coreutils/stty.c | 2 +- coreutils/test.c | 2 +- editors/awk.c | 2 +- editors/diff.c | 2 +- editors/vi.c | 2 +- findutils/grep.c | 2 +- init/init.c | 2 +- libbb/inet_common.c | 4 +- libbb/loop.c | 6 +-- libbb/procps.c | 2 +- libbb/selinux_common.c | 2 +- libpwdgrp/pwd_grp.c | 14 +++--- miscutils/devfsd.c | 26 +++++------ miscutils/hdparm.c | 4 +- miscutils/last_fancy.c | 16 +++---- modutils/rmmod.c | 2 +- networking/brctl.c | 8 ++-- networking/ether-wake.c | 8 ++-- networking/ifenslave.c | 2 +- networking/interface.c | 2 +- networking/libiproute/ipaddress.c | 10 +++-- networking/libiproute/iprule.c | 14 +++--- networking/libiproute/iptunnel.c | 2 +- networking/netstat.c | 2 +- networking/route.c | 4 +- networking/tc.c | 5 ++- networking/traceroute.c | 7 +-- networking/udhcp/dhcpc.c | 2 +- procps/nmeter.c | 2 +- procps/top.c | 2 +- runit/runsv.c | 2 +- runit/svlogd.c | 4 +- selinux/chcon.c | 20 ++++----- selinux/runcon.c | 10 ++--- selinux/sestatus.c | 2 +- selinux/setfiles.c | 19 ++++---- shell/ash.c | 8 ++-- shell/hush.c | 4 +- shell/math.c | 2 +- util-linux/fdisk_osf.c | 5 +-- util-linux/fsck_minix.c | 67 ++++++++++++++--------------- util-linux/getopt.c | 2 +- util-linux/ipcs.c | 2 +- util-linux/volume_id/nilfs.c | 2 +- util-linux/volume_id/ntfs.c | 4 +- util-linux/volume_id/udf.c | 2 +- util-linux/volume_id/unused_msdos.c | 2 +- util-linux/volume_id/unused_silicon_raid.c | 2 +- 59 files changed, 233 insertions(+), 219 deletions(-) diff --git a/archival/cpio.c b/archival/cpio.c index 98cc18fa0..699c6dbb7 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -253,24 +253,24 @@ static NOINLINE int cpio_o(void) } bytes += printf("070701" - "%08X%08X%08X%08X%08X%08X%08X" - "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */ + "%08X%08X%08X%08X%08X%08X%08X" + "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */ /* strlen+1: */ "%08X" /* chksum: */ "00000000" /* (only for "070702" files) */ /* name,NUL: */ "%s%c", - (unsigned)(uint32_t) st.st_ino, - (unsigned)(uint32_t) st.st_mode, - (unsigned)(uint32_t) st.st_uid, - (unsigned)(uint32_t) st.st_gid, - (unsigned)(uint32_t) st.st_nlink, - (unsigned)(uint32_t) st.st_mtime, - (unsigned)(uint32_t) st.st_size, - (unsigned)(uint32_t) major(st.st_dev), - (unsigned)(uint32_t) minor(st.st_dev), - (unsigned)(uint32_t) major(st.st_rdev), - (unsigned)(uint32_t) minor(st.st_rdev), - (unsigned)(strlen(name) + 1), - name, '\0'); + (unsigned)(uint32_t) st.st_ino, + (unsigned)(uint32_t) st.st_mode, + (unsigned)(uint32_t) st.st_uid, + (unsigned)(uint32_t) st.st_gid, + (unsigned)(uint32_t) st.st_nlink, + (unsigned)(uint32_t) st.st_mtime, + (unsigned)(uint32_t) st.st_size, + (unsigned)(uint32_t) major(st.st_dev), + (unsigned)(uint32_t) minor(st.st_dev), + (unsigned)(uint32_t) major(st.st_rdev), + (unsigned)(uint32_t) minor(st.st_rdev), + (unsigned)(strlen(name) + 1), + name, '\0'); bytes = cpio_pad4(bytes); if (st.st_size) { diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 2d5ab3eb3..4e6b138c3 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c @@ -293,8 +293,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current * m: maximum lookup bits, returns actual */ static int huft_build(const unsigned *b, const unsigned n, - const unsigned s, const unsigned short *d, - const unsigned char *e, huft_t **t, unsigned *m) + const unsigned s, const unsigned short *d, + const unsigned char *e, huft_t **t, unsigned *m) { unsigned a; /* counter for codes of length k */ unsigned c[BMAX + 1]; /* bit length count table */ diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index 3826a65ea..53c27080f 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -235,8 +235,8 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) p = &inbuf[posbits >> 3]; bb_error_msg ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)", - insize, posbits, p[-1], p[0], p[1], p[2], p[3], - (posbits & 07)); + insize, posbits, p[-1], p[0], p[1], p[2], p[3], + (posbits & 07)); */ bb_error_msg("corrupted data"); goto err; diff --git a/archival/libarchive/lzo1x_9x.c b/archival/libarchive/lzo1x_9x.c index 483205155..897132987 100644 --- a/archival/libarchive/lzo1x_9x.c +++ b/archival/libarchive/lzo1x_9x.c @@ -644,7 +644,7 @@ static int len_of_coded_match(unsigned m_len, unsigned m_off, unsigned lit) static int min_gain(unsigned ahead, unsigned lit1, - unsigned lit2, int l1, int l2, int l3) + unsigned lit2, int l1, int l2, int l3) { int lazy_match_min_gain = 0; @@ -673,7 +673,7 @@ static int min_gain(unsigned ahead, unsigned lit1, #if defined(SWD_BEST_OFF) static void better_match(const lzo_swd_p swd, - unsigned *m_len, unsigned *m_off) + unsigned *m_len, unsigned *m_off) { if (*m_len <= M2_MIN_LEN) return; @@ -914,8 +914,8 @@ int lzo1x_999_compress_level(const uint8_t *in, unsigned in_len, compression_level -= 7; return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem, - c[compression_level].good_length, - c[compression_level].max_lazy, - c[compression_level].max_chain, - c[compression_level].use_best_off); + c[compression_level].good_length, + c[compression_level].max_lazy, + c[compression_level].max_chain, + c[compression_level].use_best_off); } diff --git a/archival/libarchive/lzo1x_c.c b/archival/libarchive/lzo1x_c.c index cc86f74b1..8c77072ab 100644 --- a/archival/libarchive/lzo1x_c.c +++ b/archival/libarchive/lzo1x_c.c @@ -15,7 +15,7 @@ The LZO library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License diff --git a/archival/libarchive/lzo1x_d.c b/archival/libarchive/lzo1x_d.c index 348a85510..9bc1270da 100644 --- a/archival/libarchive/lzo1x_d.c +++ b/archival/libarchive/lzo1x_d.c @@ -15,7 +15,7 @@ The LZO library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License diff --git a/archival/lzop.c b/archival/lzop.c index ec4e784ed..56003d421 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -14,7 +14,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License @@ -116,7 +116,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len, unsigned nl; unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0; -// LZO_UNUSED(wrkmem); +// LZO_UNUSED(wrkmem); *out_len = 0; @@ -346,8 +346,8 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len, return LZO_E_EOF_NOT_FOUND; eof_found: -// LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2); -// LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); +// LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2); +// LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); diff --git a/coreutils/cal.c b/coreutils/cal.c index 158b23fbc..0b2307349 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -181,10 +181,11 @@ int cal_main(int argc UNUSED_PARAM, char **argv) sprintf(lineout, "%u", year); center(lineout, - (WEEK_LEN * 3 + HEAD_SEP * 2) - + julian * (J_WEEK_LEN * 2 + HEAD_SEP + (WEEK_LEN * 3 + HEAD_SEP * 2) + + julian * (J_WEEK_LEN * 2 + HEAD_SEP - (WEEK_LEN * 3 + HEAD_SEP * 2)), - 0); + 0 + ); puts("\n"); /* two \n's */ for (i = 0; i < 12; i++) { day_array(i + 1, year, days[i]); diff --git a/coreutils/mknod.c b/coreutils/mknod.c index 32d3659ac..aa0450481 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c @@ -59,7 +59,7 @@ int mknod_main(int argc, char **argv) /* Autodetect what the system supports; these macros should * optimize out to two constants. */ dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)), - xatoul_range(argv[3], 0, minor(UINT_MAX))); + xatoul_range(argv[3], 0, minor(UINT_MAX))); } } diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 2f6650153..b408a8477 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -1021,12 +1021,12 @@ dump(off_t current_offset, off_t end_offset) l_c_m = get_lcm(); /* Make bytes_to_write the smallest multiple of l_c_m that - is at least as large as n_bytes_read. */ + is at least as large as n_bytes_read. */ bytes_to_write = l_c_m * ((n_bytes_read + l_c_m - 1) / l_c_m); memset(block[idx] + n_bytes_read, 0, bytes_to_write - n_bytes_read); write_block(current_offset, bytes_to_write, - block[idx ^ 1], block[idx]); + block[idx ^ 1], block[idx]); current_offset += n_bytes_read; } diff --git a/coreutils/stat.c b/coreutils/stat.c index e38c8f6b0..c8677ebaa 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -591,37 +591,43 @@ static bool do_stat(const char *filename, const char *format) # else if (option_mask32 & OPT_TERSE) { format = (option_mask32 & OPT_SELINUX ? - "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n": - "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"); + "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n" + : + "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n" + ); } else { if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { format = (option_mask32 & OPT_SELINUX ? - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %-5h" - " Device type: %t,%T\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - " S_Context: %C\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n": - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %-5h" - " Device type: %t,%T\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n"); + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %-5h" + " Device type: %t,%T\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + " S_Context: %C\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + : + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %-5h" + " Device type: %t,%T\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + ); } else { format = (option_mask32 & OPT_SELINUX ? - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %h\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "S_Context: %C\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n": - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %h\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n"); + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %h\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "S_Context: %C\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + : + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %h\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + ); } } # endif diff --git a/coreutils/stty.c b/coreutils/stty.c index 0668cf7be..96754dd84 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -1056,7 +1056,7 @@ static void do_display(const struct termios *mode, int all) } #endif wrapf("%s = %s;", nth_string(control_name, i), - visible(mode->c_cc[control_info[i].offset])); + visible(mode->c_cc[control_info[i].offset])); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) diff --git a/coreutils/test.c b/coreutils/test.c index 0bc008e7c..4df505a05 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -610,7 +610,7 @@ static int test_eaccess(char *path, int mode) return 0; /* Root can execute any file that has any one of the execute - bits set. */ + * bits set. */ if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return 0; } diff --git a/editors/awk.c b/editors/awk.c index 42f6ef866..3224788c0 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -155,7 +155,7 @@ typedef struct tsplitter_s { /* simple token classes */ /* Order and hex values are very important!!! See next_token() */ -#define TC_SEQSTART 1 /* ( */ +#define TC_SEQSTART 1 /* ( */ #define TC_SEQTERM (1 << 1) /* ) */ #define TC_REGEXP (1 << 2) /* /.../ */ #define TC_OUTRDR (1 << 3) /* | > >> */ diff --git a/editors/diff.c b/editors/diff.c index 3a3334640..b08ded3a1 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -843,7 +843,7 @@ static void diffdir(char *p[2], const char *s_start) * add_to_dirlist will remove it. */ list[i].len = strlen(p[i]); recursive_action(p[i], ACTION_RECURSE | ACTION_FOLLOWLINKS, - add_to_dirlist, skip_dir, &list[i], 0); + add_to_dirlist, skip_dir, &list[i], 0); /* Sort dl alphabetically. * GNU diff does this ignoring any number of trailing dots. * We don't, so for us dotted files almost always are diff --git a/editors/vi.c b/editors/vi.c index e09e0d9c7..b1776c668 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -14,7 +14,7 @@ * add :help command * :map macros * if mark[] values were line numbers rather than pointers - * it would be easier to change the mark when add/delete lines + * it would be easier to change the mark when add/delete lines * More intelligence in refresh() * ":r !cmd" and "!cmd" to filter text through an external command * A true "undo" facility diff --git a/findutils/grep.c b/findutils/grep.c index f14d6e6c1..de4fcf5ad 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -638,7 +638,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_C) { /* -C unsets prev -A and -B, but following -A or -B - may override it */ + * may override it */ if (!(opts & OPT_A)) /* not overridden */ lines_after = Copt; if (!(opts & OPT_B)) /* not overridden */ diff --git a/init/init.c b/init/init.c index 724894698..b84bdccbc 100644 --- a/init/init.c +++ b/init/init.c @@ -520,7 +520,7 @@ static pid_t run(const struct init_action *a) /* Log the process name and args */ message(L_LOG, "starting pid %d, tty '%s': '%s'", - getpid(), a->terminal, a->command); + getpid(), a->terminal, a->command); /* Now run it. The new program will take over this PID, * so nothing further in init.c should be run. */ diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 7208db9ea..0f4fca1a2 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -97,7 +97,7 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne if (s_in->sin_family != AF_INET) { #ifdef DEBUG bb_error_msg("rresolve: unsupported address family %d!", - s_in->sin_family); + s_in->sin_family); #endif errno = EAFNOSUPPORT; return NULL; @@ -195,7 +195,7 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) if (sin6->sin6_family != AF_INET6) { #ifdef DEBUG bb_error_msg("rresolve: unsupported address family %d!", - sin6->sin6_family); + sin6->sin6_family); #endif errno = EAFNOSUPPORT; return NULL; diff --git a/libbb/loop.c b/libbb/loop.c index b3a520848..823fba079 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -150,9 +150,9 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse } /* If this block device already set up right, re-use it. - (Yes this is racy, but associating two loop devices with the same - file isn't pretty either. In general, mounting the same file twice - without using losetup manually is problematic.) + * (Yes this is racy, but associating two loop devices with the same + * file isn't pretty either. In general, mounting the same file twice + * without using losetup manually is problematic.) */ } else if (strcmp(file, (char *)loopinfo.lo_file_name) != 0 diff --git a/libbb/procps.c b/libbb/procps.c index b4557e797..5b68d3431 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -180,7 +180,7 @@ static char *skip_fields(char *str, int count) #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, - void (*cb)(struct smaprec *, void *), void *data) + void (*cb)(struct smaprec *, void *), void *data) { FILE *file; struct smaprec currec; diff --git a/libbb/selinux_common.c b/libbb/selinux_common.c index 62910e285..c2585557f 100644 --- a/libbb/selinux_common.c +++ b/libbb/selinux_common.c @@ -10,7 +10,7 @@ #include context_t FAST_FUNC set_security_context_component(security_context_t cur_context, - char *user, char *role, char *type, char *range) + char *user, char *role, char *type, char *range) { context_t con = context_new(cur_context); if (!con) diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index edf53f350..2060d7811 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c @@ -300,8 +300,8 @@ struct group *getgrgid(gid_t gid) * to have been created as a reentrant version of the non-standard * functions getspuid. Why getspuid was added, I do not know. */ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct spwd **__restrict result) + char *__restrict buffer, size_t buflen, + struct spwd **__restrict result) { int rv; struct passwd *pp; @@ -403,8 +403,8 @@ void endpwent(void) int getpwent_r(struct passwd *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct passwd **__restrict result) + char *__restrict buffer, size_t buflen, + struct passwd **__restrict result) { int rv; @@ -451,8 +451,8 @@ void endgrent(void) } int getgrent_r(struct group *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct group **__restrict result) + char *__restrict buffer, size_t buflen, + struct group **__restrict result) { int rv; @@ -501,7 +501,7 @@ void endspent(void) } int getspent_r(struct spwd *resultbuf, char *buffer, - size_t buflen, struct spwd **result) + size_t buflen, struct spwd **result) { int rv; diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 6493fe4f1..2e87261cf 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -219,7 +219,7 @@ static void action_execute(const struct devfsd_notify_struct *, const struct con const regmatch_t *, unsigned); static void action_modload(const struct devfsd_notify_struct *info, const struct config_entry_struct *entry); static void action_copy(const struct devfsd_notify_struct *, const struct config_entry_struct *, - const regmatch_t *, unsigned); + const regmatch_t *, unsigned); static void action_compat(const struct devfsd_notify_struct *, unsigned); static void free_config(void); static void restore(char *spath, struct stat source_stat, int rootlen); @@ -229,12 +229,12 @@ static void signal_handler(int); static const char *get_variable(const char *, void *); static int make_dir_tree(const char *); static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *, - const char *, const regmatch_t *, unsigned); + const char *, const regmatch_t *, unsigned); static void expand_regexp(char *, size_t, const char *, const char *, const regmatch_t *, unsigned); static const char *expand_variable( char *, unsigned, unsigned *, const char *, const char *(*)(const char *, void *), void *); static const char *get_variable_v2(const char *, const char *(*)(const char *, void *), void *); -static char get_old_ide_name(unsigned , unsigned); +static char get_old_ide_name(unsigned, unsigned); static char *write_old_sd_name(char *, unsigned, unsigned, const char *); /* busybox functions */ @@ -580,9 +580,9 @@ static void process_config_line(const char *line, unsigned long *event_mask) /*This action will pass "/dev/$devname"(i.e. "/dev/" prefixed to the device name) to the module loading facility. In addition, the /etc/modules.devfs configuration file is used.*/ - if (ENABLE_DEVFSD_MODLOAD) + if (ENABLE_DEVFSD_MODLOAD) new->action.what = AC_MODLOAD; - break; + break; case 6: /* EXECUTE */ new->action.what = AC_EXECUTE; num_args -= 3; @@ -750,7 +750,7 @@ static void action_permissions(const struct devfsd_notify_struct *info, } /* End Function action_permissions */ static void action_modload(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry UNUSED_PARAM) + const struct config_entry_struct *entry UNUSED_PARAM) /* [SUMMARY] Load a module. The devfs change. The config file entry. @@ -771,8 +771,8 @@ static void action_modload(const struct devfsd_notify_struct *info, } /* End Function action_modload */ static void action_execute(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry, - const regmatch_t *regexpr, unsigned int numexpr) + const struct config_entry_struct *entry, + const regmatch_t *regexpr, unsigned int numexpr) /* [SUMMARY] Execute a programme. The devfs change. The config file entry. @@ -1641,10 +1641,10 @@ st_expr_expand_out: /* Private functions follow */ static const char *expand_variable(char *buffer, unsigned int length, - unsigned int *out_pos, const char *input, - const char *(*func)(const char *variable, + unsigned int *out_pos, const char *input, + const char *(*func)(const char *variable, void *info), - void *info) + void *info) /* [SUMMARY] Expand a variable. The buffer to write to. The length of the output buffer. @@ -1786,8 +1786,8 @@ expand_variable_out: static const char *get_variable_v2(const char *variable, - const char *(*func)(const char *variable, void *info), - void *info) + const char *(*func)(const char *variable, void *info), + void *info) /* [SUMMARY] Get a variable from the environment or . The variable name. A function which will be used to get the variable. If this returns diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index a97f3e7b5..9c6dbf468 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1022,8 +1022,8 @@ static void identify(uint16_t *val) } if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) { /* We print out elsewhere whether the APM feature is enabled or - not. If it's not enabled, let's not repeat the info; just print - nothing here. */ + * not. If it's not enabled, let's not repeat the info; just print + * nothing here. */ printf("\tAdvancedPM level: "); if ((val[ADV_PWR] & 0xFF00) == 0x4000) { uint8_t apm_level = val[ADV_PWR] & 0x00FF; diff --git a/miscutils/last_fancy.c b/miscutils/last_fancy.c index dc09b65fb..f687d7e16 100644 --- a/miscutils/last_fancy.c +++ b/miscutils/last_fancy.c @@ -93,14 +93,14 @@ static void show_entry(struct utmp *ut, int state, time_t dur_secs) } printf(HEADER_FORMAT, - ut->ut_user, - ut->ut_line, - show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, - show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, - ut->ut_host, - login_time, - logout_str, - duration_str); + ut->ut_user, + ut->ut_line, + show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, + show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, + ut->ut_host, + login_time, + logout_str, + duration_str); } static int get_ut_type(struct utmp *ut) diff --git a/modutils/rmmod.c b/modutils/rmmod.c index 4a4a91982..f13ff9eb6 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -60,7 +60,7 @@ int rmmod_main(int argc UNUSED_PARAM, char **argv) filename2modname(bname, modname); if (bb_delete_module(modname, flags)) bb_error_msg_and_die("can't unload '%s': %s", - modname, moderror(errno)); + modname, moderror(errno)); } return EXIT_SUCCESS; diff --git a/networking/brctl.c b/networking/brctl.c index b4f5809df..207b069aa 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -133,9 +133,9 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif IF_FEATURE_BRCTL_FANCY(, - ARG_stp, - ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, - ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio + ARG_stp, + ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, + ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio ) IF_FEATURE_BRCTL_SHOW(, ARG_show) }; @@ -285,7 +285,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port"); memset(ifidx, 0, sizeof ifidx); arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx, - MAX_PORTS); + MAX_PORTS); xioctl(fd, SIOCDEVPRIVATE, &ifr); for (i = 0; i < MAX_PORTS; i++) { if (ifidx[i] == port) { diff --git a/networking/ether-wake.c b/networking/ether-wake.c index a73b0baea..bf09cd529 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -49,9 +49,9 @@ * Copyright 1999-2003 Donald Becker and Scyld Computing Corporation. * * The author may be reached as becker@scyld, or C/O - * Scyld Computing Corporation - * 914 Bay Ridge Road, Suite 220 - * Annapolis MD 21403 + * Scyld Computing Corporation + * 914 Bay Ridge Road, Suite 220 + * Annapolis MD 21403 * * Notes: * On some systems dropping root capability allows the process to be @@ -113,7 +113,7 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize) * Host name * IP address string * MAC address string -*/ + */ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) { struct ether_addr *eap; diff --git a/networking/ifenslave.c b/networking/ifenslave.c index f7f87bc55..c3be8180b 100644 --- a/networking/ifenslave.c +++ b/networking/ifenslave.c @@ -270,7 +270,7 @@ static int set_if_addr(char *master_ifname, char *slave_ifname) if (res < 0) { ifr.ifr_addr.sa_family = AF_INET; memset(ifr.ifr_addr.sa_data, 0, - sizeof(ifr.ifr_addr.sa_data)); + sizeof(ifr.ifr_addr.sa_data)); } res = set_ifrname_and_do_ioctl(ifra[i].s_ioctl, &ifr, slave_ifname); diff --git a/networking/interface.c b/networking/interface.c index 4b9b9485d..9ae8b3f03 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -27,7 +27,7 @@ * {1.34} - 19980630 - Arnaldo Carvalho de Melo * - gettext instead of catgets for i18n * 10/1998 - Andi Kleen. Use interface list primitives. - * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu + * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu * (default AF was wrong) */ diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index b3748e8c5..3fd3f4478 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -314,14 +314,16 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, if (rta_tb[IFA_BROADCAST]) { printf("brd %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_BROADCAST]), - abuf, sizeof(abuf))); + RTA_DATA(rta_tb[IFA_BROADCAST]), + abuf, sizeof(abuf)) + ); } if (rta_tb[IFA_ANYCAST]) { printf("any %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ANYCAST]), - abuf, sizeof(abuf))); + RTA_DATA(rta_tb[IFA_ANYCAST]), + abuf, sizeof(abuf)) + ); } printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1)); if (ifa->ifa_flags & IFA_F_SECONDARY) { diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index dd3265c7c..241a6bf9d 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -73,15 +73,17 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, if (tb[RTA_SRC]) { if (r->rtm_src_len != host_len) { printf("%s/%u", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), + RTA_DATA(tb[RTA_SRC]), + abuf, sizeof(abuf)), r->rtm_src_len - ); + ); } else { fputs(format_host(r->rtm_family, - RTA_PAYLOAD(tb[RTA_SRC]), - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), stdout); + RTA_PAYLOAD(tb[RTA_SRC]), + RTA_DATA(tb[RTA_SRC]), + abuf, sizeof(abuf)), + stdout + ); } } else if (r->rtm_src_len) { printf("0/%d", r->rtm_src_len); diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 5942feafc..2b651b926 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -438,7 +438,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) printf(" inherit"); if (p->iph.tos & ~1) printf("%c%s ", p->iph.tos & 1 ? '/' : ' ', - rtnl_dsfield_n2a(p->iph.tos & ~1, b1)); + rtnl_dsfield_n2a(p->iph.tos & ~1, b1)); } if (!(p->iph.frag_off & htons(IP_DF))) printf(" nopmtudisc"); diff --git a/networking/netstat.c b/networking/netstat.c index 9c239579f..c0c6ba501 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -187,7 +187,7 @@ static void prg_cache_add(long inode, char *name) for (pnp = prg_hash + hi; (pn = *pnp) != NULL; pnp = &pn->next) { if (pn->inode == inode) { /* Some warning should be appropriate here - as we got multiple processes for one i-node */ + * as we got multiple processes for one i-node */ return; } } diff --git a/networking/route.c b/networking/route.c index 45f2be542..f662031e9 100644 --- a/networking/route.c +++ b/networking/route.c @@ -507,8 +507,8 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) while (1) { int r; r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n", - devname, &d, &g, &flgs, &ref, &use, &metric, &m, - &mtu, &win, &ir); + devname, &d, &g, &flgs, &ref, &use, &metric, &m, + &mtu, &win, &ir); if (r != 11) { if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */ break; diff --git a/networking/tc.c b/networking/tc.c index 1574353a5..f968707a9 100644 --- a/networking/tc.c +++ b/networking/tc.c @@ -391,7 +391,7 @@ static int print_class(const struct sockaddr_nl *who UNUSED_PARAM, printf("root "); else if (msg->tcm_parent) { classid = print_tc_classid(filter_qdisc ? - TC_H_MIN(msg->tcm_parent) : msg->tcm_parent); + TC_H_MIN(msg->tcm_parent) : msg->tcm_parent); printf("parent %s ", classid); if (ENABLE_FEATURE_CLEAN_UP) free(classid); @@ -526,7 +526,8 @@ int tc_main(int argc UNUSED_PARAM, char **argv) duparg(*argv, "handle"); /* reject LONG_MIN || LONG_MAX */ /* TODO: for fw - if ((slash = strchr(handle, '/')) != NULL) + slash = strchr(handle, '/'); + if (slash != NULL) *slash = '\0'; */ msg.tcm_handle = get_u32(*argv, "handle"); diff --git a/networking/traceroute.c b/networking/traceroute.c index d197e5410..6b7b2ebdd 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -290,9 +290,10 @@ #endif -#define OPT_STRING "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ - IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \ - "4" IF_TRACEROUTE6("6") +#define OPT_STRING \ + "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ + IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \ + "4" IF_TRACEROUTE6("6") enum { OPT_DONT_FRAGMNT = (1 << 0), /* F */ OPT_USE_ICMP = (1 << 1) * ENABLE_FEATURE_TRACEROUTE_USE_ICMP, /* I */ diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index f72217c84..086228871 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1723,7 +1723,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) #endif /* enter bound state */ timeout = lease_seconds / 2; - temp_addr.s_addr = packet.yiaddr; + temp_addr.s_addr = packet.yiaddr; bb_info_msg("Lease of %s obtained, lease time %u", inet_ntoa(temp_addr), (unsigned)lease_seconds); requested_ip = packet.yiaddr; diff --git a/procps/nmeter.c b/procps/nmeter.c index ed5479024..6a3b32743 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -271,7 +271,7 @@ static int rdval_loadavg(const char* p, ullong *vec, ...) } // Parses /proc/diskstats -// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 +// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 // 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933 // 3 1 hda1 0 0 0 0 <- ignore if only 4 fields // Linux 3.0 (maybe earlier) started printing full stats for hda1 too. diff --git a/procps/top.c b/procps/top.c index b08444a76..2908bd3e7 100644 --- a/procps/top.c +++ b/procps/top.c @@ -995,7 +995,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval) } # if ENABLE_FEATURE_SHOW_THREADS if (c == 'h' - IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) + IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) ) { scan_mask ^= PSSCAN_TASKS; continue; diff --git a/runit/runsv.c b/runit/runsv.c index ad8d84f74..3e1a3c8e5 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -172,7 +172,7 @@ static void update_status(struct svdir *s) } close(fd); if (rename_or_warn("supervise/pid.new", - s->islog ? "log/supervise/pid" : "log/supervise/pid"+4)) + s->islog ? "log/supervise/pid" : "log/supervise/pid"+4)) return; pidchanged = 0; } diff --git a/runit/svlogd.c b/runit/svlogd.c index b0ba21bb6..b7a0a6e71 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -601,12 +601,12 @@ static int buffer_pwrite(int n, char *s, unsigned len) while (fchdir(ld->fddir) == -1) pause2cannot("change directory, want remove old logfile", - ld->name); + ld->name); oldest[0] = 'A'; oldest[1] = oldest[27] = '\0'; while (!(d = opendir("."))) pause2cannot("open directory, want remove old logfile", - ld->name); + ld->name); errno = 0; while ((f = readdir(d))) if ((f->d_name[0] == '@') && (strlen(f->d_name) == 27)) { diff --git a/selinux/chcon.c b/selinux/chcon.c index 88d0cfec6..f947c2c12 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c @@ -92,7 +92,7 @@ static int FAST_FUNC change_filedir_context( if (specified_context == NULL) { context = set_security_context_component(file_context, - user, role, type, range); + user, role, type, range); if (!context) { bb_error_msg("can't compute security context from %s", file_context); goto skip; @@ -121,15 +121,15 @@ static int FAST_FUNC change_filedir_context( } if ((option_mask32 & OPT_VERBOSE) || ((option_mask32 & OPT_CHANHES) && !fail)) { printf(!fail - ? "context of %s changed to %s\n" - : "can't change context of %s to %s\n", - fname, context_string); + ? "context of %s changed to %s\n" + : "can't change context of %s to %s\n", + fname, context_string); } if (!fail) { rc = TRUE; } else if ((option_mask32 & OPT_QUIET) == 0) { bb_error_msg("can't change context of %s to %s", - fname, context_string); + fname, context_string); } } else if (option_mask32 & OPT_VERBOSE) { printf("context of %s retained as %s\n", fname, context_string); @@ -181,7 +181,7 @@ int chcon_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_CHCON_LONG_OPTIONS if (option_mask32 & OPT_REFERENCE) { /* FIXME: lgetfilecon() should be used when '-h' is specified. - But current implementation follows the original one. */ + * But current implementation follows the original one. */ if (getfilecon(reference_file, &specified_context) < 0) bb_perror_msg_and_die("getfilecon('%s') failed", reference_file); } else @@ -201,10 +201,10 @@ int chcon_main(int argc UNUSED_PARAM, char **argv) fname[fname_len] = '\0'; if (recursive_action(fname, - 1<num_cmds == 0 - IF_HAS_KEYWORDS( && pi->res_word == RES_NONE) + IF_HAS_KEYWORDS(&& pi->res_word == RES_NONE) ) { free_pipe_list(pi); pi = NULL; @@ -4372,7 +4372,7 @@ static struct pipe *parse_stream(char **pstring, debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); /* Do we sit outside of any if's, loops or case's? */ if (!HAS_KEYWORDS - IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) + IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) ) { o_free(&dest); #if !BB_MMU diff --git a/shell/math.c b/shell/math.c index 760645d0f..15c003965 100644 --- a/shell/math.c +++ b/shell/math.c @@ -410,7 +410,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_ return "exponent less than 0"; c = 1; while (--right_side_val >= 0) - c *= rez; + c *= rez; rez = c; } else if (right_side_val == 0) diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 65e6bd7c4..ff16389bd 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c @@ -898,8 +898,7 @@ xbsd_initlabel(struct partition *p) pp->p_fstype = BSD_FS_UNUSED; #else d->d_npartitions = 3; - pp = &d->d_partitions[2]; /* Partition C should be - the whole disk */ + pp = &d->d_partitions[2]; /* Partition C should be the whole disk */ pp->p_offset = 0; pp->p_size = d->d_secperunit; pp->p_fstype = BSD_FS_UNUSED; @@ -935,7 +934,7 @@ xbsd_readlabel(struct partition *p) fdisk_fatal(unable_to_read); memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - sizeof(struct xbsd_disklabel)); + sizeof(struct xbsd_disklabel)); if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) return 0; diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 1508ecb03..c1d1b2cc3 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c @@ -13,7 +13,7 @@ * 10.11.91 - updated, does checking, no repairs yet. * Sent out to the mailing-list for testing. * - * 14.11.91 - Testing seems to have gone well. Added some + * 14.11.91 - Testing seems to have gone well. Added some * correction-code, and changed some functions. * * 15.11.91 - More correction code. Hopefully it notices most @@ -22,11 +22,10 @@ * 16.11.91 - More corrections (thanks to Mika Jalava). Most * things seem to work now. Yeah, sure. * - * - * 19.04.92 - Had to start over again from this old version, as a + * 19.04.92 - Had to start over again from this old version, as a * kernel bug ate my enhanced fsck in february. * - * 28.02.93 - added support for different directory entry sizes.. + * 28.02.93 - added support for different directory entry sizes.. * * Sat Mar 6 18:59:42 1993, faith@cs.unc.edu: Output namelen with * superblock information @@ -35,31 +34,31 @@ * to that required by fsutil * * Mon Jan 3 11:06:52 1994 - Dr. Wettstein (greg%wind.uucp@plains.nodak.edu) - * Added support for file system valid flag. Also - * added program_version variable and output of - * program name and version number when program - * is executed. + * Added support for file system valid flag. Also + * added program_version variable and output of + * program name and version number when program + * is executed. * - * 30.10.94 - added support for v2 filesystem - * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) + * 30.10.94 - added support for v2 filesystem + * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) * - * 10.12.94 - added test to prevent checking of mounted fs adapted - * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck - * program. (Daniel Quinlan, quinlan@yggdrasil.com) + * 10.12.94 - added test to prevent checking of mounted fs adapted + * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck + * program. (Daniel Quinlan, quinlan@yggdrasil.com) * * 01.07.96 - Fixed the v2 fs stuff to use the right #defines and such - * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) + * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) * * 02.07.96 - Added C bit fiddling routines from rmk@ecs.soton.ac.uk * (Russell King). He made them for ARM. It would seem - * that the ARM is powerful enough to do this in C whereas + * that the ARM is powerful enough to do this in C whereas * i386 and m64k must use assembly to get it fast >:-) - * This should make minix fsck system-independent. - * (janl@math.uio.no, Nicolai Langfeldt) + * This should make minix fsck system-independent. + * (janl@math.uio.no, Nicolai Langfeldt) * * 04.11.96 - Added minor fixes from Andreas Schwab to avoid compiler * warnings. Added mc68k bitops from - * Joerg Dorchain . + * Joerg Dorchain . * * 06.11.96 - Added v2 code submitted by Joerg Dorchain, but written by * Andreas Schwab. @@ -1131,7 +1130,7 @@ static void check_counts(void) continue; } printf("Zone %d: %sin use, counted=%d\n", - i, zone_in_use(i) ? "" : "not ", zone_count[i]); + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } @@ -1183,7 +1182,7 @@ static void check_counts2(void) continue; } printf("Zone %d: %sin use, counted=%d\n", - i, zone_in_use(i) ? "" : "not ", zone_count[i]); + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } #endif @@ -1253,7 +1252,7 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv) printf("Forcing filesystem check on %s\n", device_name); else if (OPT_repair) printf("Filesystem on %s is dirty, needs checking\n", - device_name); + device_name); read_tables(); @@ -1280,23 +1279,23 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv) if (!inode_in_use(i)) free_cnt++; printf("\n%6u inodes used (%u%%)\n", (INODES - free_cnt), - 100 * (INODES - free_cnt) / INODES); + 100 * (INODES - free_cnt) / INODES); for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++) if (!zone_in_use(i)) free_cnt++; printf("%6u zones used (%u%%)\n\n" - "%6u regular files\n" - "%6u directories\n" - "%6u character device files\n" - "%6u block device files\n" - "%6u links\n" - "%6u symbolic links\n" - "------\n" - "%6u files\n", - (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES, - regular, directory, chardev, blockdev, - links - 2 * directory + 1, symlinks, - total - 2 * directory + 1); + "%6u regular files\n" + "%6u directories\n" + "%6u character device files\n" + "%6u block device files\n" + "%6u links\n" + "%6u symbolic links\n" + "------\n" + "%6u files\n", + (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES, + regular, directory, chardev, blockdev, + links - 2 * directory + 1, symlinks, + total - 2 * directory + 1); } if (changed) { write_tables(); diff --git a/util-linux/getopt.c b/util-linux/getopt.c index d662c813a..1ae0c59db 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c @@ -372,7 +372,7 @@ int getopt_main(int argc, char **argv) if (!argv[1]) { if (compatible) { /* For some reason, the original getopt gave no error - when there were no arguments. */ + * when there were no arguments. */ printf(" --\n"); return 0; } diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index 8fdaf0b85..2668cafd4 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c @@ -152,7 +152,7 @@ static NOINLINE void do_shm(void) if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0) return; /* glibc 2.1.3 and all earlier libc's have ints as fields - of struct shminfo; glibc 2.1.91 has unsigned long; ach */ + * of struct shminfo; glibc 2.1.91 has unsigned long; ach */ printf("max number of segments = %lu\n" "max seg size (kbytes) = %lu\n" "max total shared memory (pages) = %lu\n" diff --git a/util-linux/volume_id/nilfs.c b/util-linux/volume_id/nilfs.c index ffa86d43c..b88a9e435 100644 --- a/util-linux/volume_id/nilfs.c +++ b/util-linux/volume_id/nilfs.c @@ -86,7 +86,7 @@ int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET). volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ? - NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); + NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); if (sb->s_rev_level == 2) diff --git a/util-linux/volume_id/ntfs.c b/util-linux/volume_id/ntfs.c index 547f141c9..7b2612f01 100644 --- a/util-linux/volume_id/ntfs.c +++ b/util-linux/volume_id/ntfs.c @@ -132,7 +132,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) dbg("mft record size %i", mft_record_size); buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size), - mft_record_size); + mft_record_size); if (buf == NULL) goto found; @@ -165,7 +165,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) break; dbg("found attribute type 0x%x, len %i, at offset %i", - attr_type, attr_len, attr_off); + attr_type, attr_len, attr_off); // if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) { // struct volume_info *info; diff --git a/util-linux/volume_id/udf.c b/util-linux/volume_id/udf.c index cd63c8d8a..d3747fb8e 100644 --- a/util-linux/volume_id/udf.c +++ b/util-linux/volume_id/udf.c @@ -109,7 +109,7 @@ nsr: return -1; dbg("vsd: %c%c%c%c%c", - vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); + vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); if (vsd->id[0] == '\0') return -1; diff --git a/util-linux/volume_id/unused_msdos.c b/util-linux/volume_id/unused_msdos.c index 65fb88501..2e8cb196a 100644 --- a/util-linux/volume_id/unused_msdos.c +++ b/util-linux/volume_id/unused_msdos.c @@ -109,7 +109,7 @@ int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id, uint64_t of extended = off + poff; } else { dbg("found 0x%x data partition at 0x%llx, len 0x%llx", - part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen); + part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen); // if (is_raid(part[i].sys_ind)) // volume_id_set_usage_part(p, VOLUME_ID_RAID); diff --git a/util-linux/volume_id/unused_silicon_raid.c b/util-linux/volume_id/unused_silicon_raid.c index d1c439ecf..878b88197 100644 --- a/util-linux/volume_id/unused_silicon_raid.c +++ b/util-linux/volume_id/unused_silicon_raid.c @@ -62,7 +62,7 @@ int FAST_FUNC volume_id_probe_silicon_medley_raid(struct volume_id *id, uint64_t // volume_id_set_usage(id, VOLUME_ID_RAID); // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", -// le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); +// le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); // id->type = "silicon_medley_raid_member"; return 0; -- cgit v1.2.3-55-g6feb From 30a8652fbf16884490cee4a624f039a9ab587269 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 01:12:26 +0100 Subject: sha3: make size/speed optimization decision configurable Signed-off-by: Denys Vlasenko --- libbb/Config.src | 10 +++++++ libbb/hash_md5_sha.c | 77 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/libbb/Config.src b/libbb/Config.src index ee1b66a45..19021fed1 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -28,6 +28,16 @@ config MD5_SMALL 2 3.0 5088 3 (smallest) 5.1 4912 +config SHA3_SMALL + int "SHA3: Trade bytes for speed (0:fast, 1:slow)" + default 1 + range 0 1 + help + Trade binary size versus speed for the sha3sum algorithm. + SHA3_SMALL=0 compared to SHA3_SMALL=1 (approximate): + 64-bit x86: +270 bytes of code, 45% faster + 32-bit x86: +450 bytes of code, 75% faster + config FEATURE_FAST_TOP bool "Faster /proc scanning code (+100 bytes)" default y diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 06a2400b5..643cf205f 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -918,6 +918,16 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) * Busybox modifications (C) Lauri Kasanen, under the GPLv2. */ +#if CONFIG_SHA3_SMALL < 0 +# define SHA3_SMALL 0 +#elif CONFIG_SHA3_SMALL > 1 +# define SHA3_SMALL 1 +#else +# define SHA3_SMALL CONFIG_SHA3_SMALL +#endif + +#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) + enum { cKeccakR_SizeInBytes = 576 / 8, cKeccakNumberOfRounds = 24, @@ -967,8 +977,6 @@ static const uint8_t KeccakF_Mod5[10] = { static void KeccakF(uint64_t *state) { uint8_t x, y; - uint64_t temp; - uint64_t BC[5]; int round; if (BB_BIG_ENDIAN) { @@ -979,30 +987,61 @@ static void KeccakF(uint64_t *state) for (round = 0; round < cKeccakNumberOfRounds; ++round) { /* Theta */ - for (x = 0; x < 5; ++x) { - BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ - state[15 + x] ^ state[20 + x]; - } - for (x = 0; x < 5; ++x) { - temp = BC[KeccakF_Mod5[x + 4]] ^ - rotl64(BC[KeccakF_Mod5[x + 1]], 1); - - for (y = 0; y <= 20; y += 5) { - state[y + x] ^= temp; + { + uint64_t BC[5]; + for (x = 0; x < 5; ++x) { + BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ + state[15 + x] ^ state[20 + x]; + } + for (x = 0; x < 5; ++x) { + uint64_t temp = BC[KeccakF_Mod5[x + 4]] ^ + rotl64(BC[KeccakF_Mod5[x + 1]], 1); + if (SHA3_SMALL && !ARCH_IS_64BIT) { + for (y = 0; y <= 20; y += 5) + state[y + x] ^= temp; + } else { + /* on 64-bit arch, this is actually smaller too */ + state[0 + x] ^= temp; + state[5 + x] ^= temp; + state[10 + x] ^= temp; + state[15 + x] ^= temp; + state[20 + x] ^= temp; + } } } /* Rho Pi */ - temp = state[1]; - for (x = 0; x < 24; ++x) { - BC[0] = state[KeccakF_PiLane[x]]; - state[KeccakF_PiLane[x]] = - rotl64(temp, KeccakF_RotationConstants[x]); - temp = BC[0]; + if (SHA3_SMALL) { + uint64_t t1 = state[1]; + for (x = 0; x < 24; ++x) { + uint64_t t0 = state[KeccakF_PiLane[x]]; + state[KeccakF_PiLane[x]] = rotl64(t1, KeccakF_RotationConstants[x]); + t1 = t0; + } + } else { + /* Especially large benefit for 32-bit arch: + * 64-bit rotations by non-constant usually are SLOW on those. + * We resort to unrolling here. + * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], + * but generates 300-500 more bytes of code. + */ + uint64_t t0; + uint64_t t1 = state[1]; +#define RhoPi_twice(x) \ + t0 = state[KeccakF_PiLane[x ]]; state[KeccakF_PiLane[x ]] = rotl64(t1, KeccakF_RotationConstants[x ]); \ + t1 = state[KeccakF_PiLane[x+1]]; state[KeccakF_PiLane[x+1]] = rotl64(t0, KeccakF_RotationConstants[x+1]); + RhoPi_twice(0); RhoPi_twice(2); + RhoPi_twice(4); RhoPi_twice(6); + RhoPi_twice(8); RhoPi_twice(10); + RhoPi_twice(12); RhoPi_twice(14); + RhoPi_twice(16); RhoPi_twice(18); + RhoPi_twice(20); RhoPi_twice(22); +#undef RhoPi_twice } /* Chi */ - for (y = 0; y < 25; y += 5) { + for (y = 0; y <= 20; y += 5) { + uint64_t BC[5]; BC[0] = state[y + 0]; BC[1] = state[y + 1]; BC[2] = state[y + 2]; -- cgit v1.2.3-55-g6feb From 6830ade6aa91dad5afe6abf9d1e4f696f5641bf1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 13:58:01 +0100 Subject: whitespace fixes. no code changes Signed-off-by: Denys Vlasenko --- console-tools/loadfont.c | 2 +- coreutils/cal.c | 4 ++-- coreutils/chown.c | 4 ++-- coreutils/df.c | 4 ++-- coreutils/sort.c | 2 +- coreutils/sum.c | 4 ++-- editors/sed.c | 2 +- editors/vi.c | 10 +++++----- include/bb_archive.h | 6 +++--- include/grp_.h | 24 ++++++++++++------------ include/libbb.h | 2 +- include/pwd_.h | 24 ++++++++++++------------ include/shadow_.h | 14 +++++++------- libbb/xatonum_template.c | 2 +- miscutils/devfsd.c | 30 +++++++++++++++--------------- miscutils/hdparm.c | 2 +- miscutils/less.c | 6 +++--- miscutils/rx.c | 4 ++-- miscutils/time.c | 2 +- shell/hush.c | 2 +- 20 files changed, 75 insertions(+), 75 deletions(-) diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c index 9e887f256..032506d6d 100644 --- a/console-tools/loadfont.c +++ b/console-tools/loadfont.c @@ -229,7 +229,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize, } /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP - this printf did not work on many kernels */ + * this printf did not work on many kernels */ advice.advised_hashsize = 0; advice.advised_hashstep = 0; diff --git a/coreutils/cal.c b/coreutils/cal.c index 0b2307349..0d388aa1c 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -43,7 +43,7 @@ static const unsigned char days_in_month[] ALIGN1 = { }; static const unsigned char sep1752[] ALIGN1 = { - 1, 2, 14, 15, 16, + 1, 2, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }; @@ -183,7 +183,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv) center(lineout, (WEEK_LEN * 3 + HEAD_SEP * 2) + julian * (J_WEEK_LEN * 2 + HEAD_SEP - - (WEEK_LEN * 3 + HEAD_SEP * 2)), + - (WEEK_LEN * 3 + HEAD_SEP * 2)), 0 ); puts("\n"); /* two \n's */ diff --git a/coreutils/chown.c b/coreutils/chown.c index bb166d8fe..1a9127622 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -126,8 +126,8 @@ int chown_main(int argc UNUSED_PARAM, char **argv) /* This matches coreutils behavior (almost - see below) */ param.chown_func = chown; if (OPT_NODEREF - /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ - IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) + /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ + IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) ) { param.chown_func = lchown; } diff --git a/coreutils/df.c b/coreutils/df.c index 2c72e82a4..5e9a8670f 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -110,8 +110,8 @@ int df_main(int argc UNUSED_PARAM, char **argv) df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */ /* From the manpage of df from coreutils-6.10: - Disk space is shown in 1K blocks by default, unless the environment - variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. + * Disk space is shown in 1K blocks by default, unless the environment + * variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. */ if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ df_disp_hr = 512; diff --git a/coreutils/sort.c b/coreutils/sort.c index 1df07285c..a1625fc9c 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -219,7 +219,7 @@ static int compare_keys(const void *xarg, const void *yarg) y = get_key(*(char **)yarg, key, flags); #else /* This curly bracket serves no purpose but to match the nesting - level of the for () loop we're not using */ + * level of the for () loop we're not using */ { x = *(char **)xarg; y = *(char **)yarg; diff --git a/coreutils/sum.c b/coreutils/sum.c index 95110a6da..75f6ef60a 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c @@ -94,8 +94,8 @@ int sum_main(int argc UNUSED_PARAM, char **argv) n = sum_file("-", type); } else { /* Need to print the name if either - - more than one file given - - doing sysv */ + * - more than one file given + * - doing sysv */ type += (argv[1] || type == SUM_SYSV); n = 1; do { diff --git a/editors/sed.c b/editors/sed.c index 070af611a..f8ca5d351 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -1077,7 +1077,7 @@ static void process_files(void) /* or does this line matches our last address regex */ || (sed_cmd->end_match && old_matched && (regexec(sed_cmd->end_match, - pattern_space, 0, NULL, 0) == 0) + pattern_space, 0, NULL, 0) == 0) ) ); } diff --git a/editors/vi.c b/editors/vi.c index b1776c668..5b5e2b0bf 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1929,11 +1929,11 @@ static int find_range(char **start, char **stop, char c) dot_end(); // find NL q = dot; } else { - // nothing -- this causes any other values of c to - // represent the one-character range under the - // cursor. this is correct for ' ' and 'l', but - // perhaps no others. - // + // nothing -- this causes any other values of c to + // represent the one-character range under the + // cursor. this is correct for ' ' and 'l', but + // perhaps no others. + // } if (q < p) { t = q; diff --git a/include/bb_archive.h b/include/bb_archive.h index 7bb5615da..a7a2a1135 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -220,9 +220,9 @@ IF_DESKTOP(long long) int unpack_xz_stream(transformer_aux_data_t *aux, int src_ char* append_ext(char *filename, const char *expected_ext) FAST_FUNC; int bbunpack(char **argv, - IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux), - char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), - const char *expected_ext + IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux), + char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), + const char *expected_ext ) FAST_FUNC; void check_errors_in_children(int signo); diff --git a/include/grp_.h b/include/grp_.h index 82ad90492..e5075e5a0 100644 --- a/include/grp_.h +++ b/include/grp_.h @@ -64,7 +64,7 @@ extern struct group *fgetgrent(FILE *__stream); /* Write the given entry onto the given stream. */ extern int putgrent(const struct group *__restrict __p, - FILE *__restrict __f); + FILE *__restrict __f); #endif /* Search for an entry with a matching group ID. */ @@ -82,32 +82,32 @@ extern struct group *getgrnam(const char *__name); POSIX people would choose. */ extern int getgrent_r(struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Search for an entry with a matching group ID. */ extern int getgrgid_r(gid_t __gid, struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Search for an entry with a matching group name. */ extern int getgrnam_r(const char *__restrict __name, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + struct group *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Read a group entry from STREAM. This function is not standardized an probably never will. */ extern int fgetgrent_r(FILE *__restrict __stream, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + struct group *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Store at most *NGROUPS members of the group set for USER into *GROUPS. Also include GROUP. The actual number of groups found is returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */ extern int getgrouplist(const char *__user, gid_t __group, - gid_t *__groups, int *__ngroups); + gid_t *__groups, int *__ngroups); /* Initialize the group set for the current user by reading the group database and using all groups diff --git a/include/libbb.h b/include/libbb.h index 6ac7d2cab..606db7d0d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1516,7 +1516,7 @@ struct smaprec { procps_read_smaps(pid, total) #endif int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, - void (*cb)(struct smaprec *, void *), void *data); + void (*cb)(struct smaprec *, void *), void *data); typedef struct procps_status_t { DIR *dir; diff --git a/include/pwd_.h b/include/pwd_.h index ea158da45..625b6f5a2 100644 --- a/include/pwd_.h +++ b/include/pwd_.h @@ -63,7 +63,7 @@ extern struct passwd *fgetpwent(FILE *__stream); /* Write the given entry onto the given stream. */ extern int putpwent(const struct passwd *__restrict __p, - FILE *__restrict __f); + FILE *__restrict __f); #endif /* Search for an entry with a matching user ID. */ @@ -81,25 +81,25 @@ extern struct passwd *getpwnam(const char *__name); POSIX people would choose. */ extern int getpwent_r(struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); extern int getpwuid_r(uid_t __uid, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); extern int getpwnam_r(const char *__restrict __name, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); /* Read an entry from STREAM. This function is not standardized and probably never will. */ extern int fgetpwent_r(FILE *__restrict __stream, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); POP_SAVED_FUNCTION_VISIBILITY diff --git a/include/shadow_.h b/include/shadow_.h index 648a62ab3..7babe4f30 100644 --- a/include/shadow_.h +++ b/include/shadow_.h @@ -79,21 +79,21 @@ extern int putspent(const struct spwd *__p, FILE *__stream); /* Reentrant versions of some of the functions above */ extern int getspent_r(struct spwd *__result_buf, char *__buffer, - size_t __buflen, struct spwd **__result); + size_t __buflen, struct spwd **__result); #endif extern int getspnam_r(const char *__name, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); #ifdef UNUSED_FOR_NOW extern int sgetspent_r(const char *__string, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); extern int fgetspent_r(FILE *__stream, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); /* Protect password file against multi writers */ extern int lckpwdf(void); diff --git a/libbb/xatonum_template.c b/libbb/xatonum_template.c index 029f66202..e0471983c 100644 --- a/libbb/xatonum_template.c +++ b/libbb/xatonum_template.c @@ -59,7 +59,7 @@ unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base, } /* Note: trailing space is an error. - It would be easy enough to allow though if desired. */ + * It would be easy enough to allow though if desired. */ if (*e) goto inval; chk_range: diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 2e87261cf..24c953bac 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -803,8 +803,8 @@ static void action_execute(const struct devfsd_notify_struct *info, static void action_copy(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry, - const regmatch_t *regexpr, unsigned int numexpr) + const struct config_entry_struct *entry, + const regmatch_t *regexpr, unsigned int numexpr) /* [SUMMARY] Copy permissions. The devfs change. The config file entry. @@ -1259,11 +1259,11 @@ static int make_dir_tree(const char *path) } /* End Function make_dir_tree */ static int expand_expression(char *output, unsigned int outsize, - const char *input, - const char *(*get_variable_func)(const char *variable, void *info), - void *info, - const char *devname, - const regmatch_t *ex, unsigned int numexp) + const char *input, + const char *(*get_variable_func)(const char *variable, void *info), + void *info, + const char *devname, + const regmatch_t *ex, unsigned int numexp) /* [SUMMARY] Expand environment variables and regular subexpressions in string. The output expanded expression is written here. The size of the output buffer. @@ -1288,8 +1288,8 @@ static int expand_expression(char *output, unsigned int outsize, } /* End Function expand_expression */ static void expand_regexp(char *output, size_t outsize, const char *input, - const char *devname, - const regmatch_t *ex, unsigned int numex) + const char *devname, + const regmatch_t *ex, unsigned int numex) /* [SUMMARY] Expand all occurrences of the regular subexpressions \0 to \9. The output expanded expression is written here. The size of the output buffer. @@ -1385,7 +1385,7 @@ static struct translate_struct translate_table[] = }; const char *get_old_name(const char *devname, unsigned int namelen, - char *buffer, unsigned int major, unsigned int minor) + char *buffer, unsigned int major, unsigned int minor) /* [SUMMARY] Translate a kernel-supplied name into an old name. The device name provided by the kernel. The length of the name. @@ -1423,7 +1423,7 @@ const char *get_old_name(const char *devname, unsigned int namelen, }; for (trans = translate_table; trans->match != NULL; ++trans) { - len = strlen(trans->match); + len = strlen(trans->match); if (strncmp(devname, trans->match, len) == 0) { if (trans->format == NULL) @@ -1549,9 +1549,9 @@ static char *write_old_sd_name(char *buffer, /*EXPERIMENTAL_FUNCTION*/ int st_expr_expand(char *output, unsigned int length, const char *input, - const char *(*get_variable_func)(const char *variable, - void *info), - void *info) + const char *(*get_variable_func)(const char *variable, + void *info), + void *info) /* [SUMMARY] Expand an expression using Borne Shell-like unquoted rules. The output expanded expression is written here. The size of the output buffer. @@ -1643,7 +1643,7 @@ st_expr_expand_out: static const char *expand_variable(char *buffer, unsigned int length, unsigned int *out_pos, const char *input, const char *(*func)(const char *variable, - void *info), + void *info), void *info) /* [SUMMARY] Expand a variable. The buffer to write to. diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 9c6dbf468..69726ae72 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1038,7 +1038,7 @@ static void identify(uint16_t *val) val[ACOUSTIC] & 0x00ff); } } else { - /* ATAPI */ + /* ATAPI */ if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ)) printf("\tATA sw reset required\n"); diff --git a/miscutils/less.c b/miscutils/less.c index f0187bf8a..5ce0a1203 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -709,9 +709,9 @@ static void print_found(const char *line) /* buf[] holds quarantined version of str */ /* Each part of the line that matches has the HIGHLIGHT - and NORMAL escape sequences placed around it. - NB: we regex against line, but insert text - from quarantined copy (buf[]) */ + * and NORMAL escape sequences placed around it. + * NB: we regex against line, but insert text + * from quarantined copy (buf[]) */ str = buf; growline = NULL; eflags = 0; diff --git a/miscutils/rx.c b/miscutils/rx.c index af597320c..1dffb593a 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c @@ -193,8 +193,8 @@ static int receive(/*int read_fd, */int file_fd) } if (cksum_or_crc != expected) { bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" - : "checksum error, expected 0x%02x, got 0x%02x", - expected, cksum_or_crc); + : "checksum error, expected 0x%02x, got 0x%02x", + expected, cksum_or_crc); goto error; } diff --git a/miscutils/time.c b/miscutils/time.c index ffed38632..19b0b44c9 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -70,7 +70,7 @@ static void resuse_end(pid_t pid, resource_t *resp) pid_t caught; /* Ignore signals, but don't ignore the children. When wait3 - returns the child process, set the time the command finished. */ + * returns the child process, set the time the command finished. */ while ((caught = wait3(&resp->waitstatus, 0, &resp->ru)) != pid) { if (caught == -1 && errno != EINTR) { bb_perror_msg("wait"); diff --git a/shell/hush.c b/shell/hush.c index 87807052c..e2dc1e2d0 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8281,7 +8281,7 @@ static int FAST_FUNC builtin_exit(char **argv) * (if there are _stopped_ jobs, running ones don't count) * # exit * exit - # EEE (then bash exits) + * EEE (then bash exits) * * TODO: we can use G.exiting = -1 as indicator "last cmd was exit" */ -- cgit v1.2.3-55-g6feb From 07a54e21dd08bcd752a23095fdedc904eb7127fb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 14:47:05 +0100 Subject: sha3: another speedup for SHA3_SMALL=0 case Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 643cf205f..3b1366762 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -1041,16 +1041,31 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - uint64_t BC[5]; - BC[0] = state[y + 0]; - BC[1] = state[y + 1]; - BC[2] = state[y + 2]; - BC[3] = state[y + 3]; - BC[4] = state[y + 4]; - for (x = 0; x < 5; ++x) { - state[y + x] = - BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & - BC[KeccakF_Mod5[x + 2]]); + if (SHA3_SMALL) { + uint64_t BC[5]; + BC[0] = state[y + 0]; + BC[1] = state[y + 1]; + BC[2] = state[y + 2]; + BC[3] = state[y + 3]; + BC[4] = state[y + 4]; + for (x = 0; x < 5; ++x) { + state[y + x] = + BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & + BC[KeccakF_Mod5[x + 2]]); + } + } else { + /* 32-bit x86: +50 bytes code, 10% faster */ + uint64_t BC0, BC1, BC2, BC3, BC4; + BC0 = state[y + 0]; + BC1 = state[y + 1]; + BC2 = state[y + 2]; + state[y + 0] = BC0 ^ ((~BC1) & BC2); + BC3 = state[y + 3]; + state[y + 1] = BC1 ^ ((~BC2) & BC3); + BC4 = state[y + 4]; + state[y + 2] = BC2 ^ ((~BC3) & BC4); + state[y + 3] = BC3 ^ ((~BC4) & BC0); + state[y + 4] = BC4 ^ ((~BC0) & BC1); } } -- cgit v1.2.3-55-g6feb From a55df2793660941f42589182537d02ce54eaed66 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 15:22:30 +0100 Subject: sha3: code shrink function old new delta KeccakF 1064 1053 -11 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 3b1366762..a0eec7789 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -988,24 +988,29 @@ static void KeccakF(uint64_t *state) for (round = 0; round < cKeccakNumberOfRounds; ++round) { /* Theta */ { - uint64_t BC[5]; + uint64_t BC[10]; for (x = 0; x < 5; ++x) { - BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ - state[15 + x] ^ state[20 + x]; + BC[x + 5] = BC[x] = state[x] + ^ state[x + 5] ^ state[x + 10] + ^ state[x + 15] ^ state[x + 20]; } + /* Using 2x5 vector above eliminates the need to use + * [Mod5[x+N]] index trick below to calculate (x+N) % 5, + * and the code is a bit _smaller_. + */ for (x = 0; x < 5; ++x) { - uint64_t temp = BC[KeccakF_Mod5[x + 4]] ^ - rotl64(BC[KeccakF_Mod5[x + 1]], 1); + uint64_t temp = BC[x + 4] ^ rotl64(BC[x + 1], 1); if (SHA3_SMALL && !ARCH_IS_64BIT) { for (y = 0; y <= 20; y += 5) - state[y + x] ^= temp; + state[x + y] ^= temp; } else { - /* on 64-bit arch, this is actually smaller too */ - state[0 + x] ^= temp; - state[5 + x] ^= temp; - state[10 + x] ^= temp; - state[15 + x] ^= temp; - state[20 + x] ^= temp; + /* On 64-bit, this is also smaller, + * not only faster, than loop */ + state[x] ^= temp; + state[x + 5] ^= temp; + state[x + 10] ^= temp; + state[x + 15] ^= temp; + state[x + 20] ^= temp; } } } @@ -1019,7 +1024,7 @@ static void KeccakF(uint64_t *state) t1 = t0; } } else { - /* Especially large benefit for 32-bit arch: + /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], -- cgit v1.2.3-55-g6feb From ac4100e103ca2b4e6e782c5814b1f43cef58c00b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 16:27:39 +0100 Subject: sha3: code shrink function old new delta KeccakF 1053 1078 +25 KeccakF_RoundConstants 192 48 -144 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 62 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index a0eec7789..4cd2244a1 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -933,32 +933,40 @@ enum { cKeccakNumberOfRounds = 24, }; -static const uint64_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL +/* Elements should be 64-bit, but top half is always zero or 0x80000000. + * It is encoded as a separate word below. + * Same is true for 31th bits. + */ +static const uint16_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { + 0x0001UL, + 0x8082UL, + 0x808aUL, + 0x8000UL, + 0x808bUL, + 0x0001UL, + 0x8081UL, + 0x8009UL, + 0x008aUL, + 0x0088UL, + 0x8009UL, + 0x000aUL, + 0x808bUL, + 0x008bUL, + 0x8089UL, + 0x8003UL, + 0x8002UL, + 0x0080UL, + 0x800aUL, + 0x000aUL, + 0x8081UL, + 0x8080UL, + 0x0001UL, + 0x8008UL }; +/* 0th first - 0011 0011 0000 0111 1101 1101: */ +#define KeccakF_RoundConstantBit63 ((uint32_t)(0x3307dd00)) +/* 0th first - 0001 0110 0011 1000 0001 1011: */ +#define KeccakF_RoundConstantBit31 ((uint32_t)(0x16381b00)) static const uint8_t KeccakF_RotationConstants[25] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, @@ -1075,7 +1083,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KeccakF_RoundConstants[round]; + state[0] ^= KeccakF_RoundConstants[round] + | (uint32_t)((KeccakF_RoundConstantBit31 << round) & 0x80000000) + | (uint64_t)((KeccakF_RoundConstantBit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { -- cgit v1.2.3-55-g6feb From 5b7f50f37210706c0f508788991de88244c7b29b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 19:52:30 +0100 Subject: sha3: cosmetic tweaks to various names, comments. No logic changes. Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 124 ++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 4cd2244a1..18e426079 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -926,66 +926,67 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) # define SHA3_SMALL CONFIG_SHA3_SMALL #endif -#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) - enum { - cKeccakR_SizeInBytes = 576 / 8, - cKeccakNumberOfRounds = 24, + KECCAK_IBLK_BYTES = 576 / 8, + KECCAK_NROUNDS = 24, }; /* Elements should be 64-bit, but top half is always zero or 0x80000000. - * It is encoded as a separate word below. - * Same is true for 31th bits. + * We encode 63rd bits in a separate word below. + * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. + * The speed penalty is lost in the noise. */ -static const uint16_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { - 0x0001UL, - 0x8082UL, - 0x808aUL, - 0x8000UL, - 0x808bUL, - 0x0001UL, - 0x8081UL, - 0x8009UL, - 0x008aUL, - 0x0088UL, - 0x8009UL, - 0x000aUL, - 0x808bUL, - 0x008bUL, - 0x8089UL, - 0x8003UL, - 0x8002UL, - 0x0080UL, - 0x800aUL, - 0x000aUL, - 0x8081UL, - 0x8080UL, - 0x0001UL, - 0x8008UL +static const uint16_t KECCAK_IOTA_CONST[KECCAK_NROUNDS] = { + 0x0001U, + 0x8082U, + 0x808aU, + 0x8000U, + 0x808bU, + 0x0001U, + 0x8081U, + 0x8009U, + 0x008aU, + 0x0088U, + 0x8009U, + 0x000aU, + 0x808bU, + 0x008bU, + 0x8089U, + 0x8003U, + 0x8002U, + 0x0080U, + 0x800aU, + 0x000aU, + 0x8081U, + 0x8080U, + 0x0001U, + 0x8008U, }; -/* 0th first - 0011 0011 0000 0111 1101 1101: */ -#define KeccakF_RoundConstantBit63 ((uint32_t)(0x3307dd00)) -/* 0th first - 0001 0110 0011 1000 0001 1011: */ -#define KeccakF_RoundConstantBit31 ((uint32_t)(0x16381b00)) +/* bit from CONST[0] is msb: 0011 0011 0000 0111 1101 1101 */ +#define KECCAK_IOTA_CONST_bit63 ((uint32_t)(0x3307dd00)) +/* bit from CONST[0] is msb: 0001 0110 0011 1000 0001 1011 */ +#define KECCAK_IOTA_CONST_bit31 ((uint32_t)(0x16381b00)) -static const uint8_t KeccakF_RotationConstants[25] = { +static const uint8_t KECCAK_ROT_CONST[25] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 }; -static const uint8_t KeccakF_PiLane[25] = { +static const uint8_t KECCAK_PI_LANE[25] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 }; -static const uint8_t KeccakF_Mod5[10] = { +static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; +#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) + static void KeccakF(uint64_t *state) { - uint8_t x, y; - int round; + unsigned x, y; + unsigned round; if (BB_BIG_ENDIAN) { for (x = 0; x < 25; x++) { @@ -993,7 +994,7 @@ static void KeccakF(uint64_t *state) } } - for (round = 0; round < cKeccakNumberOfRounds; ++round) { + for (round = 0; round < KECCAK_NROUNDS; ++round) { /* Theta */ { uint64_t BC[10]; @@ -1003,7 +1004,7 @@ static void KeccakF(uint64_t *state) ^ state[x + 15] ^ state[x + 20]; } /* Using 2x5 vector above eliminates the need to use - * [Mod5[x+N]] index trick below to calculate (x+N) % 5, + * BC[MOD5[x+N]] trick below to fetch BC[(x+N) % 5], * and the code is a bit _smaller_. */ for (x = 0; x < 5; ++x) { @@ -1027,22 +1028,24 @@ static void KeccakF(uint64_t *state) if (SHA3_SMALL) { uint64_t t1 = state[1]; for (x = 0; x < 24; ++x) { - uint64_t t0 = state[KeccakF_PiLane[x]]; - state[KeccakF_PiLane[x]] = rotl64(t1, KeccakF_RotationConstants[x]); + uint64_t t0 = state[KECCAK_PI_LANE[x]]; + state[KECCAK_PI_LANE[x]] = rotl64(t1, KECCAK_ROT_CONST[x]); t1 = t0; } } else { /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. - * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], + * This optimizes out KECCAK_PI_LANE[] and KECCAK_ROT_CONST[], * but generates 300-500 more bytes of code. */ uint64_t t0; uint64_t t1 = state[1]; #define RhoPi_twice(x) \ - t0 = state[KeccakF_PiLane[x ]]; state[KeccakF_PiLane[x ]] = rotl64(t1, KeccakF_RotationConstants[x ]); \ - t1 = state[KeccakF_PiLane[x+1]]; state[KeccakF_PiLane[x+1]] = rotl64(t0, KeccakF_RotationConstants[x+1]); + t0 = state[KECCAK_PI_LANE[x ]]; \ + state[KECCAK_PI_LANE[x ]] = rotl64(t1, KECCAK_ROT_CONST[x ]); \ + t1 = state[KECCAK_PI_LANE[x+1]]; \ + state[KECCAK_PI_LANE[x+1]] = rotl64(t0, KECCAK_ROT_CONST[x+1]); RhoPi_twice(0); RhoPi_twice(2); RhoPi_twice(4); RhoPi_twice(6); RhoPi_twice(8); RhoPi_twice(10); @@ -1063,8 +1066,8 @@ static void KeccakF(uint64_t *state) BC[4] = state[y + 4]; for (x = 0; x < 5; ++x) { state[y + x] = - BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & - BC[KeccakF_Mod5[x + 2]]); + BC[x] ^ ((~BC[MOD5[x + 1]]) & + BC[MOD5[x + 2]]); } } else { /* 32-bit x86: +50 bytes code, 10% faster */ @@ -1083,9 +1086,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KeccakF_RoundConstants[round] - | (uint32_t)((KeccakF_RoundConstantBit31 << round) & 0x80000000) - | (uint64_t)((KeccakF_RoundConstantBit63 << round) & 0x80000000) << 32; + state[0] ^= KECCAK_IOTA_CONST[round] + | (uint32_t)((KECCAK_IOTA_CONST_bit31 << round) & 0x80000000) + | (uint64_t)((KECCAK_IOTA_CONST_bit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { @@ -1095,6 +1098,8 @@ static void KeccakF(uint64_t *state) } } +#undef ARCH_IS_64BIT + void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) { memset(ctx, 0, sizeof(*ctx)); @@ -1110,19 +1115,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) buffer[ctx->bytes_queued] ^= *data++; bytes--; ctx->bytes_queued++; - if (ctx->bytes_queued == cKeccakR_SizeInBytes) { + if (ctx->bytes_queued == KECCAK_IBLK_BYTES) { KeccakF(ctx->state); ctx->bytes_queued = 0; } } /* Absorb complete blocks */ - while (bytes >= cKeccakR_SizeInBytes) { + while (bytes >= KECCAK_IBLK_BYTES) { /* XOR data onto beginning of state[]. * We try to be efficient - operate on word at a time, not byte. * Yet safe wrt unaligned access: can't just use "*(long*)data"... */ - unsigned count = cKeccakR_SizeInBytes / sizeof(long); + unsigned count = KECCAK_IBLK_BYTES / sizeof(long); long *buffer = (long*)ctx->state; do { long v; @@ -1132,7 +1137,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) } while (--count); KeccakF(ctx->state); - bytes -= cKeccakR_SizeInBytes; + bytes -= KECCAK_IBLK_BYTES; } /* Queue remaining data bytes */ @@ -1148,11 +1153,8 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) { /* Padding */ uint8_t *buffer = (uint8_t*)ctx->state; - /* 0 is the number of bits in last, incomplete byte - * (that is, zero: we never have incomplete bytes): - */ - buffer[ctx->bytes_queued] ^= 1 << 0; - buffer[cKeccakR_SizeInBytes - 1] ^= 0x80; + buffer[ctx->bytes_queued] ^= 1; + buffer[KECCAK_IBLK_BYTES - 1] ^= 0x80; KeccakF(ctx->state); -- cgit v1.2.3-55-g6feb From 8e7312e12fb088ba99f4f875903926f2ef9ed235 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 21:50:41 +0100 Subject: sha3: tweak choice of a fast code path for 64-bit Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 18e426079..7ae0b6385 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -1057,7 +1057,7 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - if (SHA3_SMALL) { + if (SHA3_SMALL && !ARCH_IS_64BIT) { uint64_t BC[5]; BC[0] = state[y + 0]; BC[1] = state[y + 1]; @@ -1071,6 +1071,7 @@ static void KeccakF(uint64_t *state) } } else { /* 32-bit x86: +50 bytes code, 10% faster */ + /* 64-bit x86: ~same code size, 30% faster */ uint64_t BC0, BC1, BC2, BC3, BC4; BC0 = state[y + 0]; BC1 = state[y + 1]; -- cgit v1.2.3-55-g6feb From 8fb3ab528e1a640342c04d996e54f7fa668fdce6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 22:07:48 +0100 Subject: sha3: remove two "small code" codepaths: I can't reproduce code size win on them anymore Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 61 ++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 7ae0b6385..60f44cc3d 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -977,14 +977,12 @@ static const uint8_t KECCAK_PI_LANE[25] = { 14, 22, 9, 6, 1 }; -static const uint8_t MOD5[10] = { - 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 -}; - #define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) static void KeccakF(uint64_t *state) { + /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ + unsigned x, y; unsigned round; @@ -1009,18 +1007,11 @@ static void KeccakF(uint64_t *state) */ for (x = 0; x < 5; ++x) { uint64_t temp = BC[x + 4] ^ rotl64(BC[x + 1], 1); - if (SHA3_SMALL && !ARCH_IS_64BIT) { - for (y = 0; y <= 20; y += 5) - state[x + y] ^= temp; - } else { - /* On 64-bit, this is also smaller, - * not only faster, than loop */ - state[x] ^= temp; - state[x + 5] ^= temp; - state[x + 10] ^= temp; - state[x + 15] ^= temp; - state[x + 20] ^= temp; - } + state[x] ^= temp; + state[x + 5] ^= temp; + state[x + 10] ^= temp; + state[x + 15] ^= temp; + state[x + 20] ^= temp; } } @@ -1057,33 +1048,17 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - if (SHA3_SMALL && !ARCH_IS_64BIT) { - uint64_t BC[5]; - BC[0] = state[y + 0]; - BC[1] = state[y + 1]; - BC[2] = state[y + 2]; - BC[3] = state[y + 3]; - BC[4] = state[y + 4]; - for (x = 0; x < 5; ++x) { - state[y + x] = - BC[x] ^ ((~BC[MOD5[x + 1]]) & - BC[MOD5[x + 2]]); - } - } else { - /* 32-bit x86: +50 bytes code, 10% faster */ - /* 64-bit x86: ~same code size, 30% faster */ - uint64_t BC0, BC1, BC2, BC3, BC4; - BC0 = state[y + 0]; - BC1 = state[y + 1]; - BC2 = state[y + 2]; - state[y + 0] = BC0 ^ ((~BC1) & BC2); - BC3 = state[y + 3]; - state[y + 1] = BC1 ^ ((~BC2) & BC3); - BC4 = state[y + 4]; - state[y + 2] = BC2 ^ ((~BC3) & BC4); - state[y + 3] = BC3 ^ ((~BC4) & BC0); - state[y + 4] = BC4 ^ ((~BC0) & BC1); - } + uint64_t BC0, BC1, BC2, BC3, BC4; + BC0 = state[y + 0]; + BC1 = state[y + 1]; + BC2 = state[y + 2]; + state[y + 0] = BC0 ^ ((~BC1) & BC2); + BC3 = state[y + 3]; + state[y + 1] = BC1 ^ ((~BC2) & BC3); + BC4 = state[y + 4]; + state[y + 2] = BC2 ^ ((~BC3) & BC4); + state[y + 3] = BC3 ^ ((~BC4) & BC0); + state[y + 4] = BC4 ^ ((~BC0) & BC1); } /* Iota */ -- cgit v1.2.3-55-g6feb From 970aa6b5bd95e435e537d123ec8be99c3077af1b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 22:19:24 +0100 Subject: sha3: cache ctx->bytes_queued function old new delta sha3_hash 171 155 -16 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 60f44cc3d..d143fc651 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -977,8 +977,6 @@ static const uint8_t KECCAK_PI_LANE[25] = { 14, 22, 9, 6, 1 }; -#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) - static void KeccakF(uint64_t *state) { /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ @@ -1074,8 +1072,6 @@ static void KeccakF(uint64_t *state) } } -#undef ARCH_IS_64BIT - void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) { memset(ctx, 0, sizeof(*ctx)); @@ -1084,16 +1080,17 @@ void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) { const uint8_t *data = buf; + unsigned bytes_queued = ctx->bytes_queued; /* If already data in queue, continue queuing first */ - while (bytes != 0 && ctx->bytes_queued != 0) { + while (bytes != 0 && bytes_queued != 0) { uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= *data++; + buffer[bytes_queued] ^= *data++; bytes--; - ctx->bytes_queued++; - if (ctx->bytes_queued == KECCAK_IBLK_BYTES) { + bytes_queued++; + if (bytes_queued == KECCAK_IBLK_BYTES) { KeccakF(ctx->state); - ctx->bytes_queued = 0; + bytes_queued = 0; } } @@ -1113,16 +1110,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) } while (--count); KeccakF(ctx->state); + bytes -= KECCAK_IBLK_BYTES; } /* Queue remaining data bytes */ while (bytes != 0) { uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= *data++; - ctx->bytes_queued++; + buffer[bytes_queued] ^= *data++; + bytes_queued++; bytes--; } + + ctx->bytes_queued = bytes_queued; } void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) -- cgit v1.2.3-55-g6feb From 406ea15e2c108c949f8b1a3547eecf4dd9509724 Mon Sep 17 00:00:00 2001 From: Martin Santesson Date: Wed, 16 Jan 2013 00:47:19 +0100 Subject: mount: add unc option to CIFS mount (needed for Linux 3.4+) unc option for CIFS mount is mandatory after CIFS option parsing was rewritten in Linux 3.4 Signed-off-by: Martin Santesson Signed-off-by: Denys Vlasenko --- util-linux/mount.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index bcb298c07..d473fd0a1 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -1822,10 +1822,24 @@ static int singlemount(struct mntent *mp, int ignore_busy) hostname = mp->mnt_fsname + 2; len = strcspn(hostname, "/\\"); - if (len == 0 || hostname[len] == '\0') + if (len == 0 // 1st char is a [back]slash (IOW: empty hostname) + || hostname[len] == '\0' // no [back]slash after hostname + || hostname[len+1] == '\0' // empty share name + ) { goto report_error; + } c = hostname[len]; hostname[len] = '\0'; + + // "unc=\\hostname\share" option is mandatory + // after CIFS option parsing was rewritten in Linux 3.4. + // Must pass it to the kernel. Must use backslashes. + { + char *unc = xasprintf("unc=\\\\%s\\%s", hostname, hostname + len + 1); + parse_mount_options(unc, &filteropts); + if (ENABLE_FEATURE_CLEAN_UP) free(unc); + } + lsa = host2sockaddr(hostname, 0); hostname[len] = c; if (!lsa) -- cgit v1.2.3-55-g6feb From 5368fe541c023130843cea361d779addb936b95c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Jan 2013 02:20:31 +0100 Subject: sha3: rename KeccakF->sha3_process_block76. This brings the naming more in line with other hashes. Pulled most statics and constants into it. Also noticed that two byte arrays are 1 element too big. Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 160 ++++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 79 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index d143fc651..15588dcfe 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -190,10 +190,9 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) int i; uint32_t temp; -# if BB_BIG_ENDIAN - for (i = 0; i < 16; i++) - words[i] = SWAP_LE32(words[i]); -# endif + if (BB_BIG_ENDIAN) + for (i = 0; i < 16; i++) + words[i] = SWAP_LE32(words[i]); # if MD5_SMALL == 3 pc = C_array; @@ -467,12 +466,13 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) common64_end(ctx, /*swap_needed:*/ BB_BIG_ENDIAN); /* The MD5 result is in little endian byte order */ -#if BB_BIG_ENDIAN - ctx->hash[0] = SWAP_LE32(ctx->hash[0]); - ctx->hash[1] = SWAP_LE32(ctx->hash[1]); - ctx->hash[2] = SWAP_LE32(ctx->hash[2]); - ctx->hash[3] = SWAP_LE32(ctx->hash[3]); -#endif + if (BB_BIG_ENDIAN) { + ctx->hash[0] = SWAP_LE32(ctx->hash[0]); + ctx->hash[1] = SWAP_LE32(ctx->hash[1]); + ctx->hash[2] = SWAP_LE32(ctx->hash[2]); + ctx->hash[3] = SWAP_LE32(ctx->hash[3]); + } + memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * 4); } @@ -927,59 +927,61 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) #endif enum { - KECCAK_IBLK_BYTES = 576 / 8, - KECCAK_NROUNDS = 24, + SHA3_IBLK_BYTES = 72, /* 576 bits / 8 */ }; -/* Elements should be 64-bit, but top half is always zero or 0x80000000. - * We encode 63rd bits in a separate word below. - * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. - * The speed penalty is lost in the noise. +/* + * In the crypto literature this function is usually called Keccak-f(). */ -static const uint16_t KECCAK_IOTA_CONST[KECCAK_NROUNDS] = { - 0x0001U, - 0x8082U, - 0x808aU, - 0x8000U, - 0x808bU, - 0x0001U, - 0x8081U, - 0x8009U, - 0x008aU, - 0x0088U, - 0x8009U, - 0x000aU, - 0x808bU, - 0x008bU, - 0x8089U, - 0x8003U, - 0x8002U, - 0x0080U, - 0x800aU, - 0x000aU, - 0x8081U, - 0x8080U, - 0x0001U, - 0x8008U, -}; -/* bit from CONST[0] is msb: 0011 0011 0000 0111 1101 1101 */ -#define KECCAK_IOTA_CONST_bit63 ((uint32_t)(0x3307dd00)) -/* bit from CONST[0] is msb: 0001 0110 0011 1000 0001 1011 */ -#define KECCAK_IOTA_CONST_bit31 ((uint32_t)(0x16381b00)) - -static const uint8_t KECCAK_ROT_CONST[25] = { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, - 18, 39, 61, 20, 44 -}; - -static const uint8_t KECCAK_PI_LANE[25] = { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, - 14, 22, 9, 6, 1 -}; - -static void KeccakF(uint64_t *state) +static void sha3_process_block76(uint64_t *state) { - /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ + enum { NROUNDS = 24 }; + + /* Elements should be 64-bit, but top half is always zero or 0x80000000. + * We encode 63rd bits in a separate word below. + * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. + * The speed penalty is lost in the noise. + */ + static const uint16_t IOTA_CONST[NROUNDS] = { + 0x0001, + 0x8082, + 0x808a, + 0x8000, + 0x808b, + 0x0001, + 0x8081, + 0x8009, + 0x008a, + 0x0088, + 0x8009, + 0x000a, + 0x808b, + 0x008b, + 0x8089, + 0x8003, + 0x8002, + 0x0080, + 0x800a, + 0x000a, + 0x8081, + 0x8080, + 0x0001, + 0x8008, + }; + /* bit for CONST[0] is in msb: 0011 0011 0000 0111 1101 1101 */ + const uint32_t IOTA_CONST_bit63 = (uint32_t)(0x3307dd00); + /* bit for CONST[0] is in msb: 0001 0110 0011 1000 0001 1011 */ + const uint32_t IOTA_CONST_bit31 = (uint32_t)(0x16381b00); + + static const uint8_t ROT_CONST[24] = { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44, + }; + static const uint8_t PI_LANE[24] = { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1, + }; + /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/ unsigned x, y; unsigned round; @@ -990,7 +992,7 @@ static void KeccakF(uint64_t *state) } } - for (round = 0; round < KECCAK_NROUNDS; ++round) { + for (round = 0; round < NROUNDS; ++round) { /* Theta */ { uint64_t BC[10]; @@ -1017,24 +1019,24 @@ static void KeccakF(uint64_t *state) if (SHA3_SMALL) { uint64_t t1 = state[1]; for (x = 0; x < 24; ++x) { - uint64_t t0 = state[KECCAK_PI_LANE[x]]; - state[KECCAK_PI_LANE[x]] = rotl64(t1, KECCAK_ROT_CONST[x]); + uint64_t t0 = state[PI_LANE[x]]; + state[PI_LANE[x]] = rotl64(t1, ROT_CONST[x]); t1 = t0; } } else { /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. - * This optimizes out KECCAK_PI_LANE[] and KECCAK_ROT_CONST[], + * This optimizes out PI_LANE[] and ROT_CONST[], * but generates 300-500 more bytes of code. */ uint64_t t0; uint64_t t1 = state[1]; #define RhoPi_twice(x) \ - t0 = state[KECCAK_PI_LANE[x ]]; \ - state[KECCAK_PI_LANE[x ]] = rotl64(t1, KECCAK_ROT_CONST[x ]); \ - t1 = state[KECCAK_PI_LANE[x+1]]; \ - state[KECCAK_PI_LANE[x+1]] = rotl64(t0, KECCAK_ROT_CONST[x+1]); + t0 = state[PI_LANE[x ]]; \ + state[PI_LANE[x ]] = rotl64(t1, ROT_CONST[x ]); \ + t1 = state[PI_LANE[x+1]]; \ + state[PI_LANE[x+1]] = rotl64(t0, ROT_CONST[x+1]); RhoPi_twice(0); RhoPi_twice(2); RhoPi_twice(4); RhoPi_twice(6); RhoPi_twice(8); RhoPi_twice(10); @@ -1060,9 +1062,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KECCAK_IOTA_CONST[round] - | (uint32_t)((KECCAK_IOTA_CONST_bit31 << round) & 0x80000000) - | (uint64_t)((KECCAK_IOTA_CONST_bit63 << round) & 0x80000000) << 32; + state[0] ^= IOTA_CONST[round] + | (uint32_t)((IOTA_CONST_bit31 << round) & 0x80000000) + | (uint64_t)((IOTA_CONST_bit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { @@ -1088,19 +1090,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) buffer[bytes_queued] ^= *data++; bytes--; bytes_queued++; - if (bytes_queued == KECCAK_IBLK_BYTES) { - KeccakF(ctx->state); + if (bytes_queued == SHA3_IBLK_BYTES) { + sha3_process_block76(ctx->state); bytes_queued = 0; } } /* Absorb complete blocks */ - while (bytes >= KECCAK_IBLK_BYTES) { + while (bytes >= SHA3_IBLK_BYTES) { /* XOR data onto beginning of state[]. * We try to be efficient - operate on word at a time, not byte. * Yet safe wrt unaligned access: can't just use "*(long*)data"... */ - unsigned count = KECCAK_IBLK_BYTES / sizeof(long); + unsigned count = SHA3_IBLK_BYTES / sizeof(long); long *buffer = (long*)ctx->state; do { long v; @@ -1109,9 +1111,9 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) data += sizeof(long); } while (--count); - KeccakF(ctx->state); + sha3_process_block76(ctx->state); - bytes -= KECCAK_IBLK_BYTES; + bytes -= SHA3_IBLK_BYTES; } /* Queue remaining data bytes */ @@ -1129,10 +1131,10 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) { /* Padding */ uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= 1; - buffer[KECCAK_IBLK_BYTES - 1] ^= 0x80; + buffer[ctx->bytes_queued] ^= 1; + buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; - KeccakF(ctx->state); + sha3_process_block76(ctx->state); /* Output */ memcpy(hashval, ctx->state, 64); -- cgit v1.2.3-55-g6feb From e4f0f26bade2560b96ee66e719e464753befa433 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Jan 2013 12:23:23 +0100 Subject: sha3: s/sha3_process_block76/sha3_process_block72/ Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 15588dcfe..d23d4f639 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -933,7 +933,7 @@ enum { /* * In the crypto literature this function is usually called Keccak-f(). */ -static void sha3_process_block76(uint64_t *state) +static void sha3_process_block72(uint64_t *state) { enum { NROUNDS = 24 }; @@ -1091,7 +1091,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) bytes--; bytes_queued++; if (bytes_queued == SHA3_IBLK_BYTES) { - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); bytes_queued = 0; } } @@ -1111,7 +1111,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) data += sizeof(long); } while (--count); - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); bytes -= SHA3_IBLK_BYTES; } @@ -1134,7 +1134,7 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) buffer[ctx->bytes_queued] ^= 1; buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); /* Output */ memcpy(hashval, ctx->state, 64); -- cgit v1.2.3-55-g6feb From 20c5e5a626296f92acc16bfc8417dd4f230bf56d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 17 Jan 2013 02:30:35 +0100 Subject: mount: fix -o user=foo mishandling, fix unc= generation, add prefixpath= function old new delta singlemount 1019 1049 +30 packed_usage 29252 29257 +5 parse_mount_options 230 232 +2 mount_option_str 337 338 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 38/0) Total: 38 bytes Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Denys Vlasenko --- util-linux/mount.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index d473fd0a1..deedd17da 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -36,6 +36,10 @@ //usage: IF_FEATURE_MTAB_SUPPORT( //usage: "\n -n Don't update /etc/mtab" //usage: ) +//usage: IF_FEATURE_MOUNT_VERBOSE( +//usage: "\n -v Verbose" +//usage: ) +////usage: "\n -s Sloppy (ignored)" //usage: "\n -r Read-only mount" //usage: "\n -w Read-write mount (default)" //usage: "\n -t FSTYPE[,...] Filesystem type(s)" @@ -224,7 +228,7 @@ static const int32_t mount_options[] = { IF_DESKTOP(/* "user" */ MOUNT_USERS,) IF_DESKTOP(/* "users" */ MOUNT_USERS,) /* "_netdev" */ 0, - IF_DESKTOP(/* "comment" */ 0,) /* systemd uses this in fstab */ + IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ ) IF_FEATURE_MOUNT_FLAGS( @@ -283,7 +287,7 @@ static const char mount_option_str[] = IF_DESKTOP("user\0") IF_DESKTOP("users\0") "_netdev\0" - IF_DESKTOP("comment\0") /* systemd uses this in fstab */ + IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ ) IF_FEATURE_MOUNT_FLAGS( // vfs flags @@ -475,10 +479,13 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) // FIXME: use hasmntopt() // Find this option in mount_options for (i = 0; i < ARRAY_SIZE(mount_options); i++) { - /* We support "option=" match for "comment=" thingy */ unsigned opt_len = strlen(option_str); + if (strncasecmp(option_str, options, opt_len) == 0 - && (options[opt_len] == '\0' || options[opt_len] == '=') + && (options[opt_len] == '\0' + /* or is it "comment=" thingy in fstab? */ + IF_FEATURE_MOUNT_FSTAB(IF_DESKTOP( || option_str[opt_len-1] == '=' )) + ) ) { unsigned long fl = mount_options[i]; if (fl & BB_MS_INVERTED_VALUE) @@ -1817,31 +1824,44 @@ static int singlemount(struct mntent *mp, int ignore_busy) ) { int len; char c; + char *hostname, *share; + char *dotted, *ip; len_and_sockaddr *lsa; - char *hostname, *dotted, *ip; + + // Parse mp->mnt_fsname of the form "//hostname/share[/dir1/dir2]" hostname = mp->mnt_fsname + 2; len = strcspn(hostname, "/\\"); - if (len == 0 // 1st char is a [back]slash (IOW: empty hostname) - || hostname[len] == '\0' // no [back]slash after hostname - || hostname[len+1] == '\0' // empty share name + share = hostname + len + 1; + if (len == 0 // 3rd char is a [back]slash (IOW: empty hostname) + || share[-1] == '\0' // no [back]slash after hostname + || share[0] == '\0' // empty share name ) { goto report_error; } - c = hostname[len]; - hostname[len] = '\0'; + c = share[-1]; + share[-1] = '\0'; + len = strcspn(share, "/\\"); // "unc=\\hostname\share" option is mandatory // after CIFS option parsing was rewritten in Linux 3.4. - // Must pass it to the kernel. Must use backslashes. + // Must use backslashes. + // If /dir1/dir2 is present, also add "prefixpath=dir1/dir2" { - char *unc = xasprintf("unc=\\\\%s\\%s", hostname, hostname + len + 1); - parse_mount_options(unc, &filteropts); - if (ENABLE_FEATURE_CLEAN_UP) free(unc); + char *unc = xasprintf( + share[len] != '\0' /* "/dir1/dir2" exists? */ + ? "unc=\\\\%s\\%.*s,prefixpath=%s" + : "unc=\\\\%s\\%.*s", + hostname, + len, share, + share + len + 1 /* "dir1/dir2" */ + ); + parse_mount_options(unc, &filteropts); + if (ENABLE_FEATURE_CLEAN_UP) free(unc); } lsa = host2sockaddr(hostname, 0); - hostname[len] = c; + share[-1] = c; if (!lsa) goto report_error; @@ -1853,8 +1873,6 @@ static int singlemount(struct mntent *mp, int ignore_busy) parse_mount_options(ip, &filteropts); if (ENABLE_FEATURE_CLEAN_UP) free(ip); - // "-o mand" is required [why?] - vfsflags |= MS_MANDLOCK; mp->mnt_type = (char*)"cifs"; rc = mount_it_now(mp, vfsflags, filteropts); -- cgit v1.2.3-55-g6feb From 5ca853e5dab665efef99f3b6690015977ff90572 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jan 2013 10:24:51 +0100 Subject: fix a typo in config help text. Closes 5714 Signed-off-by: Denys Vlasenko --- Config.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.in b/Config.in index b3fd65bd9..03c2d032f 100644 --- a/Config.in +++ b/Config.in @@ -332,7 +332,7 @@ config FEATURE_SUID root-level operations even when run by ordinary users (for example, mounting of user mounts in fstab needs this). - Busybox will automatically drop priviledges for applets + Busybox will automatically drop privileges for applets that don't need root access. If you are really paranoid and don't want to do this, build two -- cgit v1.2.3-55-g6feb From 5d78355d5afcda9a95cb18926317e86f8b14223e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jan 2013 11:02:21 +0100 Subject: code shrink function old new delta applet_name_compare 36 31 -5 find_applet_by_name 43 25 -18 Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index da13bf36c..67df44690 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -140,10 +140,9 @@ void FAST_FUNC bb_show_usage(void) } #if NUM_APPLETS > 8 -/* NB: any char pointer will work as well, not necessarily applet_names */ -static int applet_name_compare(const void *name, const void *v) +static int applet_name_compare(const void *name, const void *idx) { - int i = (const char *)v - applet_names; + int i = (int)(ptrdiff_t)idx - 1; return strcmp(name, APPLET_NAME(i)); } #endif @@ -152,10 +151,12 @@ int FAST_FUNC find_applet_by_name(const char *name) #if NUM_APPLETS > 8 /* Do a binary search to find the applet entry given the name. */ const char *p; - p = bsearch(name, applet_names, ARRAY_SIZE(applet_main), 1, applet_name_compare); - if (!p) - return -1; - return p - applet_names; + p = bsearch(name, (void*)(ptrdiff_t)1, ARRAY_SIZE(applet_main), 1, applet_name_compare); + /* + * if (!p) return -1; + * ^^^^^^^^^^^^^^^^^^ the code below will do this if p == NULL :) + */ + return (int)(ptrdiff_t)p - 1; #else /* A version which does not pull in bsearch */ int i = 0; @@ -747,8 +748,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". */ //TODO: just compare applet_no with APPLET_NO_test - if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) + if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) { + /* If you want "foo --help" to return 0: */ + /*xfunc_error_retval = 0;*/ bb_show_usage(); + } } if (ENABLE_FEATURE_SUID) check_suid(applet_no); -- cgit v1.2.3-55-g6feb From 7c4b13e0190a645f4083741c7803e51984cf71cb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jan 2013 13:02:27 +0100 Subject: ash: revert wrong "fix" for an apparent memory leak. Closes 5822 Signed-off-by: Denys Vlasenko --- shell/ash.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shell/ash.c b/shell/ash.c index eb1347447..31fbc550a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8677,8 +8677,17 @@ expredir(union node *n) #if ENABLE_ASH_BASH_COMPAT store_expfname: #endif +#if 0 +// By the design of stack allocator, the loop of this kind: +// while true; do while true; do break; done nfile.expfname) stunalloc(redir->nfile.expfname); +// It results in corrupted state of stacked allocations. +#endif redir->nfile.expfname = fn.list->text; break; case NFROMFD: -- cgit v1.2.3-55-g6feb From 9daf33fc5245abebdda145f95e1ad3a175241f18 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Jan 2013 13:30:13 +0100 Subject: dc: code shrink function old new delta stack_machine 103 101 -2 operators 176 168 -8 Signed-off-by: Denys Vlasenko --- miscutils/dc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/miscutils/dc.c b/miscutils/dc.c index 6903761e4..6bcfbe249 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -11,11 +11,11 @@ //usage: //usage:#define dc_full_usage "\n\n" //usage: "Tiny RPN calculator. Operations:\n" -//usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, eor,\n" +//usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n" //usage: "p - print top of the stack (without popping),\n" //usage: "f - print entire stack,\n" //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" -//usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 * 2 2 + / p' -> 16" +//usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" //usage: //usage:#define dc_example_usage //usage: "$ dc 2 2 + p\n" @@ -219,29 +219,29 @@ static const struct op operators[] = { {"p", print_no_pop}, {"f", print_stack_no_pop}, {"o", set_output_base}, - { "", NULL } }; static void stack_machine(const char *argument) { - char *endPointer; + char *end; double d; - const struct op *o = operators; + const struct op *o; - d = strtod(argument, &endPointer); - - if (endPointer != argument && *endPointer == '\0') { + d = strtod(argument, &end); + if (end != argument && *end == '\0') { push(d); return; } - while (o->function) { + o = operators; + do { if (strcmp(o->name, argument) == 0) { o->function(); return; } o++; - } + } while (o != operators + ARRAY_SIZE(operators)); + bb_error_msg_and_die("syntax error at '%s'", argument); } -- cgit v1.2.3-55-g6feb From 9980707efc3735574f89ca3fbc686374c6225e3e Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sun, 6 Jan 2013 13:11:04 +0100 Subject: syslogd: convert dummy functions to statics and get rid of IF_FEATURE_* checks As suggested by Mike. No bloat-o-meter difference, but a bit nicer to look at. We cannot convert the call to log_to_shmem() as it checks for G.shbuf outside the function, and G.shbuf is only available when IPC support is enabled. Signed-off-by: Peter Korsgaard Signed-off-by: Denys Vlasenko --- sysklogd/syslogd.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 2053cb146..f349f4711 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -529,8 +529,8 @@ static void log_to_shmem(const char *msg) printf("tail:%d\n", G.shbuf->tail); } #else -void ipcsyslog_cleanup(void); -void ipcsyslog_init(void); +static void ipcsyslog_cleanup(void) {} +static void ipcsyslog_init(void) {} void log_to_shmem(const char *msg); #endif /* FEATURE_IPC_SYSLOG */ @@ -567,9 +567,9 @@ static void log_to_kmsg(int pri, const char *msg) write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); } #else -void kmsg_init(void); -void kmsg_cleanup(void); -void log_to_kmsg(int pri, const char *msg); +static void kmsg_init(void) {} +static void kmsg_cleanup(void) {} +static void log_to_kmsg(int pri UNUSED_PARAM, const char *msg UNUSED_PARAM) {} #endif /* FEATURE_KMSG_SYSLOG */ /* Print a message to the log file. */ @@ -706,7 +706,7 @@ static void timestamp_and_log(int pri, char *msg, int len) } timestamp[15] = '\0'; - if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) { + if (option_mask32 & OPT_kmsg) { log_to_kmsg(pri, msg); return; } @@ -881,11 +881,10 @@ static void do_syslogd(void) #endif sock_fd = create_socket(); - if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { + if (option_mask32 & OPT_circularlog) ipcsyslog_init(); - } - if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) + if (option_mask32 & OPT_kmsg) kmsg_init(); timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); @@ -974,9 +973,8 @@ static void do_syslogd(void) timestamp_and_log_internal("syslogd exiting"); puts("syslogd exiting"); remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); - if (ENABLE_FEATURE_IPC_SYSLOG) - ipcsyslog_cleanup(); - if (ENABLE_FEATURE_KMSG_SYSLOG && (option_mask32 & OPT_kmsg)) + ipcsyslog_cleanup(); + if (option_mask32 & OPT_kmsg) kmsg_cleanup(); kill_myself_with_sig(bb_got_signal); #undef recvbuf -- cgit v1.2.3-55-g6feb From 2cfcc9e9d74447cb770255d1d8cb6f3722df22ba Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 20 Jan 2013 00:38:09 +0100 Subject: sha3: code shrink function old new delta sha3_hash 155 101 -54 Signed-off-by: Denys Vlasenko --- include/libbb.h | 4 +-- libbb/hash_md5_sha.c | 91 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 34 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 606db7d0d..e52006020 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1641,7 +1641,7 @@ typedef struct sha3_ctx_t { unsigned bytes_queued; } sha3_ctx_t; void md5_begin(md5_ctx_t *ctx) FAST_FUNC; -void md5_hash(md5_ctx_t *ctx, const void *data, size_t length) FAST_FUNC; +void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; #define sha1_hash md5_hash @@ -1654,7 +1654,7 @@ void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; -void sha3_end(sha3_ctx_t *ctx, uint8_t *resbuf) FAST_FUNC; +void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; extern uint32_t *global_crc32_table; uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index d23d4f639..b4d955e5a 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -56,7 +56,7 @@ static void FAST_FUNC common64_hash(md5_ctx_t *ctx, const void *buffer, size_t l len -= remaining; buffer = (const char *)buffer + remaining; bufpos += remaining; - /* clever way to do "if (bufpos != 64) break; ... ; bufpos = 0;" */ + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ bufpos -= 64; if (bufpos != 0) break; @@ -839,7 +839,7 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) len -= remaining; buffer = (const char *)buffer + remaining; bufpos += remaining; - /* clever way to do "if (bufpos != 128) break; ... ; bufpos = 0;" */ + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ bufpos -= 128; if (bufpos != 0) break; @@ -1079,63 +1079,90 @@ void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) memset(ctx, 0, sizeof(*ctx)); } -void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) +void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) { - const uint8_t *data = buf; - unsigned bytes_queued = ctx->bytes_queued; +#if SHA3_SMALL + const uint8_t *data = buffer; + unsigned bufpos = ctx->bytes_queued; + + while (1) { + unsigned remaining = SHA3_IBLK_BYTES - bufpos; + if (remaining > len) + remaining = len; + len -= remaining; + /* XOR data into buffer */ + while (remaining != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + bufpos++; + remaining--; + } + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ + bufpos -= SHA3_IBLK_BYTES; + if (bufpos != 0) + break; + /* Buffer is filled up, process it */ + sha3_process_block72(ctx->state); + /*bufpos = 0; - already is */ + } + ctx->bytes_queued = bufpos + SHA3_IBLK_BYTES; +#else + /* +50 bytes code size, but a bit faster because of long-sized XORs */ + const uint8_t *data = buffer; + unsigned bufpos = ctx->bytes_queued; /* If already data in queue, continue queuing first */ - while (bytes != 0 && bytes_queued != 0) { - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[bytes_queued] ^= *data++; - bytes--; - bytes_queued++; - if (bytes_queued == SHA3_IBLK_BYTES) { - sha3_process_block72(ctx->state); - bytes_queued = 0; + while (len != 0 && bufpos != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + len--; + bufpos++; + if (bufpos == SHA3_IBLK_BYTES) { + bufpos = 0; + goto do_block; } } /* Absorb complete blocks */ - while (bytes >= SHA3_IBLK_BYTES) { + while (len >= SHA3_IBLK_BYTES) { /* XOR data onto beginning of state[]. - * We try to be efficient - operate on word at a time, not byte. - * Yet safe wrt unaligned access: can't just use "*(long*)data"... + * We try to be efficient - operate one word at a time, not byte. + * Careful wrt unaligned access: can't just use "*(long*)data"! */ unsigned count = SHA3_IBLK_BYTES / sizeof(long); - long *buffer = (long*)ctx->state; + long *buf = (long*)ctx->state; do { long v; move_from_unaligned_long(v, (long*)data); - *buffer++ ^= v; + *buf++ ^= v; data += sizeof(long); } while (--count); - + len -= SHA3_IBLK_BYTES; + do_block: sha3_process_block72(ctx->state); - - bytes -= SHA3_IBLK_BYTES; } /* Queue remaining data bytes */ - while (bytes != 0) { - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[bytes_queued] ^= *data++; - bytes_queued++; - bytes--; + while (len != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + bufpos++; + len--; } - ctx->bytes_queued = bytes_queued; + ctx->bytes_queued = bufpos; +#endif } -void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) +void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf) { /* Padding */ - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= 1; - buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; + uint8_t *buf = (uint8_t*)ctx->state; + buf[ctx->bytes_queued] ^= 1; + buf[SHA3_IBLK_BYTES - 1] ^= 0x80; sha3_process_block72(ctx->state); /* Output */ - memcpy(hashval, ctx->state, 64); + memcpy(resbuf, ctx->state, 64); } -- cgit v1.2.3-55-g6feb From 81fa999540740b5269a349a9e991eb506592ea75 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 20 Jan 2013 16:05:41 +0100 Subject: syslogd: do not segfault on parse error when using default config. Closes 5762 Signed-off-by: Denys Vlasenko --- sysklogd/syslogd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index f349f4711..3fe3f5348 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -429,7 +429,9 @@ static void parse_syslogdcfg(const char *file) return; cfgerr: - bb_error_msg_and_die("error in '%s' at line %d", file, parser->lineno); + bb_error_msg_and_die("error in '%s' at line %d", + file ? file : "/etc/syslog.conf", + parser->lineno); } #endif -- cgit v1.2.3-55-g6feb From 2f5b5beb28a3ffe9d12a19b79c453c640cee2f29 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 20 Jan 2013 16:57:19 +0100 Subject: grep: fix grep -Fw not respecting the -w option. Closes 5792 Signed-off-by: Denys Vlasenko --- findutils/grep.c | 37 ++++++++++++++++++++++++++++++++----- testsuite/grep.tests | 12 ++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index de4fcf5ad..70f3516a5 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -344,10 +344,34 @@ static int grep_file(FILE *file) while (pattern_ptr) { gl = (grep_list_data_t *)pattern_ptr->data; if (FGREP_FLAG) { - found |= (((option_mask32 & OPT_i) - ? strcasestr(line, gl->pattern) - : strstr(line, gl->pattern) - ) != NULL); + char *match; + char *str = line; + opt_f_again: + match = ((option_mask32 & OPT_i) + ? strcasestr(str, gl->pattern) + : strstr(str, gl->pattern) + ); + if (match) { + if (option_mask32 & OPT_x) { + if (match != str) + goto opt_f_not_found; + if (str[strlen(gl->pattern)] != '\0') + goto opt_f_not_found; + } else + if (option_mask32 & OPT_w) { + char c = (match != str) ? match[-1] : ' '; + if (!isalnum(c) && c != '_') { + c = match[strlen(gl->pattern)]; + if (!c || (!isalnum(c) && c != '_')) + goto opt_f_found; + } + str = match + 1; + goto opt_f_again; + } + opt_f_found: + found = 1; + opt_f_not_found: ; + } } else { if (!(gl->flg_mem_alocated_compiled & COMPILED)) { gl->flg_mem_alocated_compiled |= COMPILED; @@ -376,7 +400,8 @@ static int grep_file(FILE *file) if (option_mask32 & OPT_x) { found = (gl->matched_range.rm_so == 0 && line[gl->matched_range.rm_eo] == '\0'); - } else if (!(option_mask32 & OPT_w)) { + } else + if (!(option_mask32 & OPT_w)) { found = 1; } else { char c = ' '; @@ -387,6 +412,8 @@ static int grep_file(FILE *file) if (!c || (!isalnum(c) && c != '_')) found = 1; } +//BUG: "echo foop foo | grep -w foo" should match, but doesn't: +//we bail out on first "mismatch" because it's not a word. } } } diff --git a/testsuite/grep.tests b/testsuite/grep.tests index 006a215e1..4781f2284 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests @@ -115,6 +115,18 @@ testing "grep -v -f EMPTY_FILE" \ "" \ "test\n" +testing "grep -Fw matches only words" \ + "grep -Fw foo input" \ + "" \ + "foop\n" \ + "" + +testing "grep -Fw doesn't stop on 1st mismatch" \ + "grep -Fw foo input" \ + "foop foo\n" \ + "foop foo\n" \ + "" + # testing "test name" "commands" "expected result" "file input" "stdin" # file input will be file called "input" # test can create a file "actual" instead of writing to stdout -- cgit v1.2.3-55-g6feb From 31dc8603eedc0140c798c9af3404a35ea190af2c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 20 Jan 2013 18:10:12 +0100 Subject: ifconfig: do not accept "ifconfig eth0 up 1.2.3.4/17" (ip with mask). Closes 5786 function old new delta ifconfig_main 1221 1237 +16 Signed-off-by: Denys Vlasenko --- networking/ifconfig.c | 167 ++++++++++++++++++++++++-------------------------- networking/route.c | 2 +- 2 files changed, 81 insertions(+), 88 deletions(-) diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 320df3010..782374b35 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c @@ -174,10 +174,6 @@ struct in6_ifreq { #define ARG_ADD_DEL (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER) -/* - * Set up the tables. Warning! They must have corresponding order! - */ - struct arg1opt { const char *name; unsigned short selector; @@ -198,6 +194,10 @@ struct options { #define ifreq_offsetof(x) offsetof(struct ifreq, x) +/* + * Set up the tables. Warning! They must have corresponding order! + */ + static const struct arg1opt Arg1Opt[] = { { "SIFMETRIC", SIOCSIFMETRIC, ifreq_offsetof(ifr_metric) }, { "SIFMTU", SIOCSIFMTU, ifreq_offsetof(ifr_mtu) }, @@ -220,11 +220,11 @@ static const struct arg1opt Arg1Opt[] = { { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr) }, { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq) }, #endif - /* Last entry if for unmatched (possibly hostname) arg. */ #if ENABLE_FEATURE_IPV6 { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */ { "DIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */ #endif + /* Last entry is for unmatched (assumed to be hostname/address) arg. */ { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, }; @@ -265,16 +265,49 @@ static const struct options OptArray[] = { { NULL, 0, ARG_HOSTNAME, (IFF_UP | IFF_RUNNING) } }; -/* - * A couple of prototypes. - */ #if ENABLE_FEATURE_IFCONFIG_HW -static int in_ether(const char *bufp, struct sockaddr *sap); +/* Input an Ethernet address and convert to binary. */ +static int in_ether(const char *bufp, struct sockaddr *sap) +{ + char *ptr; + int i, j; + unsigned char val; + unsigned char c; + + sap->sa_family = ARPHRD_ETHER; + ptr = (char *) sap->sa_data; + + i = 0; + do { + j = val = 0; + + /* We might get a semicolon here - not required. */ + if (i && (*bufp == ':')) { + bufp++; + } + + do { + c = *bufp; + if (((unsigned char)(c - '0')) <= 9) { + c -= '0'; + } else if ((unsigned char)((c|0x20) - 'a') <= 5) { + c = (unsigned char)((c|0x20) - 'a') + 10; + } else if (j && (c == ':' || c == 0)) { + break; + } else { + return -1; + } + ++bufp; + val <<= 4; + val += c; + } while (++j < 2); + *ptr++ = val; + } while (++i < ETH_ALEN); + + return *bufp; /* Error if we don't end at end of string. */ +} #endif -/* - * Our main function. - */ int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ifconfig_main(int argc UNUSED_PARAM, char **argv) { @@ -330,7 +363,7 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) strncpy_IFNAMSIZ(ifr.ifr_name, *argv); /* Process the remaining arguments. */ - while (*++argv != (char *) NULL) { + while (*++argv != NULL) { p = *argv; mask = N_MASK; if (*p == '-') { /* If the arg starts with '-'... */ @@ -356,9 +389,9 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) FOUND_ARG: if (mask & ARG_MASK) { mask = op->arg_flags; - a1op = Arg1Opt + (op - OptArray); if (mask & A_NETMASK & did_flags) bb_show_usage(); + a1op = Arg1Opt + (op - OptArray); if (*++argv == NULL) { if (mask & A_ARG_REQ) bb_show_usage(); @@ -371,19 +404,9 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_IFCONFIG_HW if (mask & A_CAST_RESOLVE) { #endif -#if ENABLE_FEATURE_IPV6 - char *prefix; - int prefix_len = 0; -#endif - /*safe_strncpy(host, *argv, (sizeof host));*/ host = *argv; -#if ENABLE_FEATURE_IPV6 - prefix = strchr(host, '/'); - if (prefix) { - prefix_len = xatou_range(prefix + 1, 0, 128); - *prefix = '\0'; - } -#endif + if (strcmp(host, "inet") == 0) + continue; /* compat stuff */ sai.sin_family = AF_INET; sai.sin_port = 0; if (strcmp(host, "default") == 0) { @@ -391,7 +414,8 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) sai.sin_addr.s_addr = INADDR_ANY; } #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS - else if ((host[0] == '+' && !host[1]) && (mask & A_BROADCAST) + else if ((host[0] == '+' && !host[1]) + && (mask & A_BROADCAST) && (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME) ) { /* + is special, meaning broadcast is derived. */ @@ -400,23 +424,36 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) #endif else { len_and_sockaddr *lsa; - if (strcmp(host, "inet") == 0) - continue; /* compat stuff */ +#if ENABLE_FEATURE_IPV6 + char *prefix; + int prefix_len = 0; + prefix = strchr(host, '/'); + if (prefix) { + prefix_len = xatou_range(prefix + 1, 0, 128); + *prefix = '\0'; + } + resolve: +#endif lsa = xhost2sockaddr(host, 0); #if ENABLE_FEATURE_IPV6 + if (lsa->u.sa.sa_family != AF_INET6 && prefix) { +/* TODO: we do not support "ifconfig eth0 up 1.2.3.4/17". + * For now, just make it fail instead of silently ignoring "/17" part: + */ + *prefix = '/'; + goto resolve; + } if (lsa->u.sa.sa_family == AF_INET6) { int sockfd6; struct in6_ifreq ifr6; - memcpy((char *) &ifr6.ifr6_addr, - (char *) &(lsa->u.sin6.sin6_addr), - sizeof(struct in6_addr)); - - /* Create a channel to the NET kernel. */ sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0); - xioctl(sockfd6, SIOGIFINDEX, &ifr); + xioctl(sockfd6, SIOCGIFINDEX, &ifr); ifr6.ifr6_ifindex = ifr.ifr_ifindex; ifr6.ifr6_prefixlen = prefix_len; + memcpy(&ifr6.ifr6_addr, + &lsa->u.sin6.sin6_addr, + sizeof(struct in6_addr)); ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "SIOC%s", a1op->name); if (ENABLE_FEATURE_CLEAN_UP) free(lsa); @@ -437,18 +474,17 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_IFCONFIG_HW } else { /* A_CAST_HOST_COPY_IN_ETHER */ /* This is the "hw" arg case. */ - smalluint hw_class= index_in_substrings("ether\0" + smalluint hw_class = index_in_substrings("ether\0" IF_FEATURE_HWIB("infiniband\0"), *argv) + 1; if (!hw_class || !*++argv) bb_show_usage(); - /*safe_strncpy(host, *argv, sizeof(host));*/ host = *argv; if (hw_class == 1 ? in_ether(host, &sa) : in_ib(host, &sa)) bb_error_msg_and_die("invalid hw-addr %s", host); p = (char *) &sa; } #endif - memcpy( (((char *)&ifr) + a1op->ifr_offset), + memcpy( ((char *)&ifr) + a1op->ifr_offset, p, sizeof(struct sockaddr)); } else { /* FIXME: error check?? */ @@ -458,17 +494,17 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) if (mask & A_MAP_TYPE) { xioctl(sockfd, SIOCGIFMAP, &ifr); if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR) - *((unsigned char *) p) = i; + *(unsigned char *) p = i; else if (mask & A_MAP_USHORT) - *((unsigned short *) p) = i; + *(unsigned short *) p = i; else - *((unsigned long *) p) = i; + *(unsigned long *) p = i; } else #endif if (mask & A_CAST_CHAR_PTR) - *((caddr_t *) p) = (caddr_t) i; + *(caddr_t *) p = (caddr_t) i; else /* A_CAST_INT */ - *((int *) p) = i; + *(int *) p = i; } ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "SIOC%s", a1op->name); @@ -494,7 +530,7 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) if (!(mask & A_SET_AFTER)) continue; mask = N_SET; - } + } /* if (mask & ARG_MASK) */ xioctl(sockfd, SIOCGIFFLAGS, &ifr); selector = op->selector; @@ -509,46 +545,3 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) close(sockfd); return 0; } - -#if ENABLE_FEATURE_IFCONFIG_HW -/* Input an Ethernet address and convert to binary. */ -static int in_ether(const char *bufp, struct sockaddr *sap) -{ - char *ptr; - int i, j; - unsigned char val; - unsigned char c; - - sap->sa_family = ARPHRD_ETHER; - ptr = (char *) sap->sa_data; - - i = 0; - do { - j = val = 0; - - /* We might get a semicolon here - not required. */ - if (i && (*bufp == ':')) { - bufp++; - } - - do { - c = *bufp; - if (((unsigned char)(c - '0')) <= 9) { - c -= '0'; - } else if (((unsigned char)((c|0x20) - 'a')) <= 5) { - c = (c|0x20) - ('a'-10); - } else if (j && (c == ':' || c == 0)) { - break; - } else { - return -1; - } - ++bufp; - val <<= 4; - val += c; - } while (++j < 2); - *ptr++ = val; - } while (++i < ETH_ALEN); - - return *bufp; /* Error if we don't end at end of string. */ -} -#endif diff --git a/networking/route.c b/networking/route.c index f662031e9..4235ea72c 100644 --- a/networking/route.c +++ b/networking/route.c @@ -435,7 +435,7 @@ static NOINLINE void INET6_setroute(int action, char **args) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy_IFNAMSIZ(ifr.ifr_name, devname); - xioctl(skfd, SIOGIFINDEX, &ifr); + xioctl(skfd, SIOCGIFINDEX, &ifr); rt.rtmsg_ifindex = ifr.ifr_ifindex; } -- cgit v1.2.3-55-g6feb From 4609f477c7e043a4f6147dfe6e86b775da2ef784 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Jan 2013 01:22:12 +0100 Subject: mdev: fix mode of dir1 in =dir1/dir2/file rule Signed-off-by: Denys Vlasenko --- testsuite/mdev.tests | 22 +++++++++++++++++++++- util-linux/mdev.c | 16 ++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests index 7320e17dd..48d3dcc2c 100755 --- a/testsuite/mdev.tests +++ b/testsuite/mdev.tests @@ -11,7 +11,7 @@ FILTER_LS="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f # cut: remove size+date FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-" -# testing "test name" "options" "expected result" "file input" "stdin" +# testing "test name" "commands" "expected result" "file input" "stdin" rm -rf mdev.testdir mkdir mdev.testdir @@ -126,6 +126,26 @@ br--r--r-- 1 0 0 sda "" "" SKIP= +# continuing to use directory structure from prev test +rm -rf mdev.testdir/dev/* +echo "sda 0:0 444 =disk/sd/a" >mdev.testdir/etc/mdev.conf +optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME +testing "mdev move rule '=bar/baz/fname'" \ + "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; + ls -lnR mdev.testdir/dev | $FILTER_LS2" \ +"\ +mdev.testdir/dev: +drwxr-xr-x 3 0 0 disk + +mdev.testdir/dev/disk: +drwxr-xr-x 2 0 0 sd + +mdev.testdir/dev/disk/sd: +br--r--r-- 1 0 0 a +" \ + "" "" +SKIP= + # continuing to use directory structure from prev test rm -rf mdev.testdir/dev/* # here we complicate things by having non-matching group 1 and using %0 diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 79871d30e..75de14ff1 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -429,6 +429,18 @@ static const struct rule *next_rule(void) #endif +static void mkdir_recursive(char *name) +{ + /* if name has many levels ("dir1/dir2"), + * bb_make_directory() will create dir1 according to umask, + * not according to its "mode" parameter. + * Since we run with umask=0, need to temporarily switch it. + */ + umask(022); /* "dir1" (if any) will be 0755 too */ + bb_make_directory(name, 0755, FILEUTILS_RECUR); + umask(0); +} + /* Builds an alias path. * This function potentionally reallocates the alias parameter. * Only used for ENABLE_FEATURE_MDEV_RENAME @@ -442,7 +454,7 @@ static char *build_alias(char *alias, const char *device_name) dest = strrchr(alias, '/'); if (dest) { /* ">bar/[baz]" ? */ *dest = '\0'; /* mkdir bar */ - bb_make_directory(alias, 0755, FILEUTILS_RECUR); + mkdir_recursive(alias); *dest = '/'; if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */ dest = alias; @@ -641,7 +653,7 @@ static void make_device(char *device_name, char *path, int operation) char *slash = strrchr(node_name, '/'); if (slash) { *slash = '\0'; - bb_make_directory(node_name, 0755, FILEUTILS_RECUR); + mkdir_recursive(node_name); *slash = '/'; } if (G.verbose) -- cgit v1.2.3-55-g6feb From 0cfba07fcd6e909b1a6113e2904da3a5f2d8349e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Jan 2013 08:28:37 +0100 Subject: fix testsuite false positive Signed-off-by: Denys Vlasenko --- testsuite/mkfs.minix.tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/mkfs.minix.tests b/testsuite/mkfs.minix.tests index 7eecaf230..324eaafce 100755 --- a/testsuite/mkfs.minix.tests +++ b/testsuite/mkfs.minix.tests @@ -9,7 +9,7 @@ # testing "test name" "options" "expected result" "file input" "stdin" # '\n' produces 10 on little endian, but not on big endian -cr=`echo | od -i | sed 's/.* //g;2d'` +cr=`echo | od -i | sed 's/ *$//g;s/.* //g;2d'` if [ x"$cr" = x"10" ]; then hash=4f35f7afeba07d56055bed1f29ae20b7 else -- cgit v1.2.3-55-g6feb From 64406a92a054f884747553011d4529103e2900e4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Jan 2013 08:51:23 +0100 Subject: Bump version to 1.21.0 Signed-off-by: Denys Vlasenko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8995ff506..c31ca899b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 PATCHLEVEL = 21 SUBLEVEL = 0 -EXTRAVERSION = .git +EXTRAVERSION = NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb From f474dfa681a74c7b219842bd21521c2cb3084c7a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Jan 2013 08:56:21 +0100 Subject: Start 1.22.0 development cycle Signed-off-by: Denys Vlasenko --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c31ca899b..24942f994 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 -PATCHLEVEL = 21 +PATCHLEVEL = 22 SUBLEVEL = 0 -EXTRAVERSION = +EXTRAVERSION = .git NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb From 6aab061d2d6243505f7c21c7a92dcebc3922784c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Jan 2013 10:07:23 +0100 Subject: ps: fix sscanf format specifier (%l); make uptime unsigned Signed-off-by: Denys Vlasenko --- procps/ps.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/procps/ps.c b/procps/ps.c index efc087ee5..5f7372263 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -70,7 +70,7 @@ enum { MAX_WIDTH = 2*1024 }; #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG -static long get_uptime(void) +static unsigned long get_uptime(void) { #ifdef __linux__ struct sysinfo info; @@ -78,12 +78,15 @@ static long get_uptime(void) return 0; return info.uptime; #elif 1 - char buf[64]; - long uptime; + unsigned long uptime; + char buf[sizeof(uptime)*3 + 2]; + /* /proc/uptime is "UPTIME_SEC.NN IDLE_SEC.NN\n" + * (where IDLE is cumulative over all CPUs) + */ if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) - bb_perror_msg_and_die("can't read %s", "/proc/uptime"); + bb_perror_msg_and_die("can't read '%s'", "/proc/uptime"); buf[sizeof(buf)-1] = '\0'; - sscanf(buf, "%l", &uptime); + sscanf(buf, "%lu", &uptime); return uptime; #else struct timespec ts; @@ -138,7 +141,10 @@ struct globals { unsigned terminal_width; #if ENABLE_FEATURE_PS_TIME unsigned kernel_HZ; - unsigned long long seconds_since_boot; + /* used to be long long, but 64 bits is enough + * (long long may become 128 bits in the future): + */ + uint64_t seconds_since_boot; #endif } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) @@ -149,14 +155,13 @@ struct globals { #define buffer (G.buffer ) #define terminal_width (G.terminal_width ) #define kernel_HZ (G.kernel_HZ ) -#define seconds_since_boot (G.seconds_since_boot) #define INIT_G() do { } while (0) #if ENABLE_FEATURE_PS_TIME /* for ELF executables, notes are pushed before environment and args */ -static ptrdiff_t find_elf_note(ptrdiff_t findme) +static uintptr_t find_elf_note(uintptr_t findme) { - ptrdiff_t *ep = (ptrdiff_t *) environ; + uintptr_t *ep = (uintptr_t *) environ; while (*ep++) continue; @@ -222,7 +227,6 @@ static inline unsigned get_HZ_by_waiting(void) static unsigned get_kernel_HZ(void) { - if (kernel_HZ) return kernel_HZ; @@ -231,7 +235,7 @@ static unsigned get_kernel_HZ(void) if (kernel_HZ == (unsigned)-1) kernel_HZ = get_HZ_by_waiting(); - seconds_since_boot = get_uptime(); + G.seconds_since_boot = get_uptime(); return kernel_HZ; } @@ -350,7 +354,7 @@ static void func_etime(char *buf, int size, const procps_status_t *ps) mm = ps->start_time / get_kernel_HZ(); /* must be after get_kernel_HZ()! */ - mm = seconds_since_boot - mm; + mm = G.seconds_since_boot - mm; ss = mm % 60; mm /= 60; snprintf(buf, size+1, "%3lu:%02u", mm, ss); @@ -588,7 +592,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv) // -o col1,col2,col3=header // Select which columns to display /* We allow (and ignore) most of the above. FIXME. - * -T is picked for threads (POSIX hasn't it standardized). + * -T is picked for threads (POSIX hasn't standardized it). * procps v3.2.7 supports -T and shows tids as SPID column, * it also supports -L where it shows tids as LWP column. */ @@ -599,7 +603,9 @@ int ps_main(int argc UNUSED_PARAM, char **argv) parse_o(llist_pop(&opt_o)); } while (opt_o); } else { - /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */ + /* Below: parse_o() needs char*, NOT const char*, + * can't pass it constant string. Need to make a copy first. + */ #if ENABLE_SELINUX if (!(opt & OPT_Z) || !is_selinux_enabled()) { /* no -Z or no SELinux: do not show LABEL */ @@ -653,7 +659,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) }; #if ENABLE_FEATURE_PS_LONG time_t now = now; - long uptime; + unsigned long uptime; #endif /* If we support any options, parse argv */ #if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE || ENABLE_FEATURE_PS_LONG -- cgit v1.2.3-55-g6feb From 778794d1dd99f29d099eb80ae2750381bc5e0059 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Jan 2013 10:13:52 +0100 Subject: *: reuse more strings Signed-off-by: Denys Vlasenko --- archival/unzip.c | 4 ++-- editors/vi.c | 28 ++++++++++++++-------------- procps/top.c | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index 046027cc6..83bf8f6d6 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -626,7 +626,7 @@ int unzip_main(int argc, char **argv) printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); fflush_all(); if (!fgets(key_buf, sizeof(key_buf), stdin)) { - bb_perror_msg_and_die("can't read input"); + bb_perror_msg_and_die("can't read standard input"); } i = key_buf[0]; } @@ -669,7 +669,7 @@ int unzip_main(int argc, char **argv) /* Prompt for new name */ printf("new name: "); if (!fgets(key_buf, sizeof(key_buf), stdin)) { - bb_perror_msg_and_die("can't read input"); + bb_perror_msg_and_die("can't read standard input"); } free(dst_fn); dst_fn = xstrdup(key_buf); diff --git a/editors/vi.c b/editors/vi.c index 5b5e2b0bf..7173415c8 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1049,7 +1049,7 @@ static void colon(char *buf) #endif // how many lines in text[]? li = count_lines(text, end - 1); - status_line("\"%s\"%s" + status_line("'%s'%s" IF_FEATURE_VI_READONLY("%s") " %dL, %dC", current_filename, (file_size(fn) < 0 ? " [New file]" : ""), @@ -1165,7 +1165,7 @@ static void colon(char *buf) goto ret; // nothing was inserted // how many lines in text[]? li = count_lines(q, q + ch - 1); - status_line("\"%s\"" + status_line("'%s'" IF_FEATURE_VI_READONLY("%s") " %dL, %dC", fn, IF_FEATURE_VI_READONLY((readonly_mode ? " [Readonly]" : ""),) @@ -1298,7 +1298,7 @@ static void colon(char *buf) } #if ENABLE_FEATURE_VI_READONLY if (readonly_mode && !useforce) { - status_line_bold("\"%s\" File is read only", fn); + status_line_bold("'%s' is read only", fn); goto ret; } #endif @@ -1321,9 +1321,9 @@ static void colon(char *buf) } if (l < 0) { if (l == -1) - status_line_bold("\"%s\" %s", fn, strerror(errno)); + status_line_bold("'%s' %s", fn, strerror(errno)); } else { - status_line("\"%s\" %dL, %dC", fn, li, l); + status_line("'%s' %dL, %dC", fn, li, l); if (q == text && r == end - 1 && l == ch) { file_modified = 0; last_file_modified = -1; @@ -1735,7 +1735,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) q = (char *)re_compile_pattern(pat, strlen(pat), (struct re_pattern_buffer *)&preg); if (q != 0) { // The pattern was not compiled - status_line_bold("bad search pattern: \"%s\": %s", pat, q); + status_line_bold("bad search pattern: '%s': %s", pat, q); i = 0; // return p if pattern not compiled goto cs1; } @@ -2503,12 +2503,12 @@ static int file_insert(const char *fn, char *p, int update_ro_status) /* Validate file */ if (stat(fn, &statbuf) < 0) { - status_line_bold("\"%s\" %s", fn, strerror(errno)); + status_line_bold("'%s' %s", fn, strerror(errno)); goto fi0; } if (!S_ISREG(statbuf.st_mode)) { // This is not a regular file - status_line_bold("\"%s\" Not a regular file", fn); + status_line_bold("'%s' is not a regular file", fn); goto fi0; } if (p < text || p > end) { @@ -2519,19 +2519,19 @@ static int file_insert(const char *fn, char *p, int update_ro_status) // read file to buffer fd = open(fn, O_RDONLY); if (fd < 0) { - status_line_bold("\"%s\" %s", fn, strerror(errno)); + status_line_bold("'%s' %s", fn, strerror(errno)); goto fi0; } - size = statbuf.st_size; + size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX); p += text_hole_make(p, size); cnt = safe_read(fd, p, size); if (cnt < 0) { - status_line_bold("\"%s\" %s", fn, strerror(errno)); + status_line_bold("'%s' %s", fn, strerror(errno)); p = text_hole_delete(p, p + size - 1); // un-do buffer insert } else if (cnt < size) { // There was a partial read, shrink unused space text[] p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert - status_line_bold("can't read all of file \"%s\"", fn); + status_line_bold("can't read '%s'", fn); } if (cnt >= size) file_modified++; @@ -3469,7 +3469,7 @@ static void do_cmd(int c) } else { file_modified = 0; last_file_modified = -1; - status_line("\"%s\" %dL, %dC", current_filename, count_lines(text, end - 1), cnt); + status_line("'%s' %dL, %dC", current_filename, count_lines(text, end - 1), cnt); if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n' || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N' ) { @@ -3667,7 +3667,7 @@ static void do_cmd(int c) } if (file_modified) { if (ENABLE_FEATURE_VI_READONLY && readonly_mode) { - status_line_bold("\"%s\" File is read only", current_filename); + status_line_bold("'%s' is read only", current_filename); break; } cnt = file_write(current_filename, text, end - 1); diff --git a/procps/top.c b/procps/top.c index 2908bd3e7..abee69806 100644 --- a/procps/top.c +++ b/procps/top.c @@ -294,7 +294,7 @@ static void get_jiffy_counts(void) * they are used to calculate per process CPU% */ prev_jif = cur_jif; if (read_cpu_jiffy(fp, &cur_jif) < 4) - bb_error_msg_and_die("can't read /proc/stat"); + bb_error_msg_and_die("can't read '%s'", "/proc/stat"); #if !ENABLE_FEATURE_TOP_SMP_CPU fclose(fp); -- cgit v1.2.3-55-g6feb From 9b7ebfe6447349e6b614b53413c21fce7bce7da1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Jan 2013 11:00:45 +0100 Subject: mount: whitespace fix. no code changes Signed-off-by: Denys Vlasenko --- util-linux/mount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index deedd17da..62fd41fd7 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -1856,8 +1856,8 @@ static int singlemount(struct mntent *mp, int ignore_busy) len, share, share + len + 1 /* "dir1/dir2" */ ); - parse_mount_options(unc, &filteropts); - if (ENABLE_FEATURE_CLEAN_UP) free(unc); + parse_mount_options(unc, &filteropts); + if (ENABLE_FEATURE_CLEAN_UP) free(unc); } lsa = host2sockaddr(hostname, 0); -- cgit v1.2.3-55-g6feb From bf99807657eac6f0d4fc593b3a83d34338c62293 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Jan 2013 11:16:08 +0100 Subject: unzip: add missing fflush; code shrink function old new delta my_fgets80 - 41 +41 unzip_main 2291 2242 -49 Signed-off-by: Denys Vlasenko --- archival/unzip.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index 83bf8f6d6..e4c824850 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -267,6 +267,14 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd) } } +static void my_fgets80(char *buf80) +{ + fflush_all(); + if (!fgets(buf80, 80, stdin)) { + bb_perror_msg_and_die("can't read standard input"); + } +} + int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unzip_main(int argc, char **argv) { @@ -291,7 +299,7 @@ int unzip_main(int argc, char **argv) llist_t *zreject = NULL; char *base_dir = NULL; int i, opt; - char key_buf[80]; + char key_buf[80]; /* must match size used by my_fgets80 */ struct stat stat_buf; /* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: @@ -624,10 +632,7 @@ int unzip_main(int argc, char **argv) i = 'y'; } else { printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); - fflush_all(); - if (!fgets(key_buf, sizeof(key_buf), stdin)) { - bb_perror_msg_and_die("can't read standard input"); - } + my_fgets80(key_buf); i = key_buf[0]; } } else { /* File is not regular file */ @@ -668,9 +673,7 @@ int unzip_main(int argc, char **argv) case 'r': /* Prompt for new name */ printf("new name: "); - if (!fgets(key_buf, sizeof(key_buf), stdin)) { - bb_perror_msg_and_die("can't read standard input"); - } + my_fgets80(key_buf); free(dst_fn); dst_fn = xstrdup(key_buf); chomp(dst_fn); -- cgit v1.2.3-55-g6feb From 243e7330015e748b898c4c8692909fa18bd57463 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Jan 2013 11:41:22 +0100 Subject: flashcp: pad output to BUFSIZE. Hopefully closes 5882 Signed-off-by: Denys Vlasenko --- miscutils/flashcp.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/miscutils/flashcp.c b/miscutils/flashcp.c index 81cde9072..36b6efe1e 100644 --- a/miscutils/flashcp.c +++ b/miscutils/flashcp.c @@ -16,6 +16,7 @@ #include "libbb.h" #include +/* If 1, simulates "flashing" by writing to existing regular file */ #define MTD_DEBUG 0 #define OPT_v (1 << 0) @@ -32,7 +33,7 @@ static void progress(int mode, uoff_t count, uoff_t total) if (total) percent = (unsigned) (percent / total); printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ", - (mode == 0) ? "Erasing block" : ((mode == 1) ? "Writing kb" : "Verifying kb"), + (mode == -1) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"), count, total, (unsigned)percent); fflush_all(); } @@ -97,8 +98,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv) #endif e.start = 0; for (i = 1; i <= erase_count; i++) { - progress(0, i, erase_count); - errno = 0; + progress(-1, i, erase_count); #if !MTD_DEBUG if (ioctl(fd_d, MEMERASE, &e) < 0) { bb_perror_msg_and_die("erase error at 0x%llx on %s", @@ -113,7 +113,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv) /* doing this outer loop gives significantly smaller code * than doing two separate loops for writing and verifying */ - for (i = 1; i <= 2; i++) { + for (i = 0; i <= 1; i++) { uoff_t done; unsigned count; @@ -122,25 +122,29 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv) done = 0; count = BUFSIZE; while (1) { - uoff_t rem = statb.st_size - done; + uoff_t rem; + + progress(i, done / 1024, (uoff_t)statb.st_size / 1024); + rem = statb.st_size - done; if (rem == 0) break; if (rem < BUFSIZE) count = rem; - progress(i, done / 1024, (uoff_t)statb.st_size / 1024); xread(fd_f, buf, count); - if (i == 1) { + if (i == 0) { int ret; + if (count < BUFSIZE) + memset((char*)buf + count, 0, BUFSIZE - count); errno = 0; - ret = full_write(fd_d, buf, count); - if (ret != count) { + ret = full_write(fd_d, buf, BUFSIZE); + if (ret != BUFSIZE) { bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, " "write returned %d", done, devicename, ret); } - } else { /* i == 2 */ + } else { /* i == 1 */ xread(fd_d, buf2, count); - if (memcmp(buf, buf2, count)) { + if (memcmp(buf, buf2, count) != 0) { bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done); } } -- cgit v1.2.3-55-g6feb From ee3bc70cea2064d9243e7a39cd1c90dc66eb5e4a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Jan 2013 11:36:00 +0100 Subject: getopt: improve help text; code shrink function old new delta generate_output 356 351 -5 packed_usage 29271 29257 -14 Signed-off-by: Denys Vlasenko --- util-linux/getopt.c | 59 +++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/util-linux/getopt.c b/util-linux/getopt.c index 1ae0c59db..58df1c823 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c @@ -35,27 +35,32 @@ //usage: "[OPTIONS] [--] OPTSTRING PARAMS" //usage:#define getopt_full_usage "\n\n" //usage: IF_LONG_OPTS( -//usage: " -a,--alternative Allow long options starting with single -" -//usage: "\n -l,--longoptions=LOPT[,...] Long options to be recognized" -//usage: "\n -n,--name=PROGNAME The name under which errors are reported" -//usage: "\n -o,--options=OPTSTRING Short options to be recognized" -//usage: "\n -q,--quiet Disable error reporting by getopt(3)" +//usage: IF_FEATURE_GETOPT_LONG( +//usage: " -a,--alternative Allow long options starting with single -\n" +//usage: " -l,--longoptions=LOPT[,...] Long options to recognize\n" +//usage: ) +//usage: " -n,--name=PROGNAME The name under which errors are reported" +//usage: "\n -o,--options=OPTSTRING Short options to recognize" +//usage: "\n -q,--quiet No error messages on unrecognized options" //usage: "\n -Q,--quiet-output No normal output" //usage: "\n -s,--shell=SHELL Set shell quoting conventions" -//usage: "\n -T,--test Test for getopt(1) version" -//usage: "\n -u,--unquoted Don't quote the output" +//usage: "\n -T,--test Version test (exits with 4)" +//usage: "\n -u,--unquoted Don't quote output" //usage: ) //usage: IF_NOT_LONG_OPTS( -//usage: " -a Allow long options starting with single -" -//usage: "\n -l LOPT[,...] Long options to be recognized" -//usage: "\n -n PROGNAME The name under which errors are reported" -//usage: "\n -o OPTSTRING Short options to be recognized" -//usage: "\n -q Disable error reporting by getopt(3)" +//usage: IF_FEATURE_GETOPT_LONG( +//usage: " -a Allow long options starting with single -\n" +//usage: " -l LOPT[,...] Long options to recognize\n" +//usage: ) +//usage: " -n PROGNAME The name under which errors are reported" +//usage: "\n -o OPTSTRING Short options to recognize" +//usage: "\n -q No error messages on unrecognized options" //usage: "\n -Q No normal output" //usage: "\n -s SHELL Set shell quoting conventions" -//usage: "\n -T Test for getopt(1) version" -//usage: "\n -u Don't quote the output" +//usage: "\n -T Version test (exits with 4)" +//usage: "\n -u Don't quote output" //usage: ) +//usage: IF_FEATURE_GETOPT_LONG( /* example uses -l, needs FEATURE_GETOPT_LONG */ //usage: "\n" //usage: "\nExample:" //usage: "\n" @@ -73,6 +78,7 @@ //usage: "\n *) echo Error; exit 1;;" //usage: "\n esac" //usage: "\ndone" +//usage: ) //usage: //usage:#define getopt_example_usage //usage: "$ cat getopt.test\n" @@ -214,11 +220,6 @@ static const char *normalize(const char *arg) static int generate_output(char **argv, int argc, const char *optstr, const struct option *longopts) { int exit_code = 0; /* We assume everything will be OK */ - int opt; -#if ENABLE_FEATURE_GETOPT_LONG - int longindex; -#endif - const char *charptr; if (quiet_errors) /* No error reporting from getopt(3) */ opterr = 0; @@ -233,13 +234,14 @@ static int generate_output(char **argv, int argc, const char *optstr, const stru #endif while (1) { - opt = #if ENABLE_FEATURE_GETOPT_LONG - alternative ? - getopt_long_only(argc, argv, optstr, longopts, &longindex) : - getopt_long(argc, argv, optstr, longopts, &longindex); + int longindex; + int opt = alternative + ? getopt_long_only(argc, argv, optstr, longopts, &longindex) + : getopt_long(argc, argv, optstr, longopts, &longindex) + ; #else - getopt(argc, argv, optstr); + int opt = getopt(argc, argv, optstr); #endif if (opt == -1) break; @@ -257,9 +259,10 @@ static int generate_output(char **argv, int argc, const char *optstr, const stru if (opt == NON_OPT) printf(" %s", normalize(optarg)); else { + const char *charptr; printf(" -%c", opt); charptr = strchr(optstr, opt); - if (charptr != NULL && *++charptr == ':') + if (charptr && *++charptr == ':') printf(" %s", normalize(optarg ? optarg : "")); } @@ -267,9 +270,11 @@ static int generate_output(char **argv, int argc, const char *optstr, const stru } if (!quiet_output) { + unsigned idx; printf(" --"); - while (optind < argc) - printf(" %s", normalize(argv[optind++])); + idx = optind; + while (argv[idx]) + printf(" %s", normalize(argv[idx++])); bb_putchar('\n'); } return exit_code; -- cgit v1.2.3-55-g6feb From 17d4436424400517014da7bc46759985e0ea131b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 26 Jan 2013 14:21:15 +0100 Subject: ps: seconds_since_boot: uint64_t -> ulong Even if long is 32-bit, 4 billion second uptime isn't likely :) Signed-off-by: Denys Vlasenko --- procps/ps.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/procps/ps.c b/procps/ps.c index 5f7372263..89cadad00 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -141,10 +141,7 @@ struct globals { unsigned terminal_width; #if ENABLE_FEATURE_PS_TIME unsigned kernel_HZ; - /* used to be long long, but 64 bits is enough - * (long long may become 128 bits in the future): - */ - uint64_t seconds_since_boot; + unsigned long seconds_since_boot; #endif } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) -- cgit v1.2.3-55-g6feb From 6be6f3bfecf436b03fe9b84b2aedbe8c938a8996 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Jan 2013 12:26:29 +0100 Subject: flashcp: trivial code shrink Signed-off-by: Denys Vlasenko --- miscutils/flashcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miscutils/flashcp.c b/miscutils/flashcp.c index 36b6efe1e..b526566a4 100644 --- a/miscutils/flashcp.c +++ b/miscutils/flashcp.c @@ -33,7 +33,7 @@ static void progress(int mode, uoff_t count, uoff_t total) if (total) percent = (unsigned) (percent / total); printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ", - (mode == -1) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"), + (mode < 0) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"), count, total, (unsigned)percent); fflush_all(); } -- cgit v1.2.3-55-g6feb From 03b614739b923994ff0bef74622973ad18fefebd Mon Sep 17 00:00:00 2001 From: Kang Kai Date: Mon, 28 Jan 2013 14:02:51 +0100 Subject: testsuite/du/du-k-works: fix false positive Signed-off-by: Kang Kai Signed-off-by: Denys Vlasenko --- testsuite/du/du-k-works | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testsuite/du/du-k-works b/testsuite/du/du-k-works index 36dcaa85d..417b0daa5 100644 --- a/testsuite/du/du-k-works +++ b/testsuite/du/du-k-works @@ -2,6 +2,10 @@ mkdir du.testdir cd du.testdir dd if=/dev/zero of=file1 bs=1k count=64 2>/dev/null dd if=/dev/zero of=file2 bs=1k count=16 2>/dev/null +# ext4 on images <512M gives 81kb +# ext3 on images <512M gives 83kb test x"`busybox du -k .`" = x"80 ." \ + -o x"`busybox du -k .`" = x"81 ." \ + -o x"`busybox du -k .`" = x"83 ." \ -o x"`busybox du -k .`" = x"84 ." \ -o x"`busybox du -k .`" = x"88 ." -- cgit v1.2.3-55-g6feb From 04ac6e03c3ae8302be2420cf73d70cf466791fa6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Jan 2013 15:25:35 +0100 Subject: udhcpc6: fix port numbers used if !FEATURE_UDHCP_PORT Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_dhcpc.c | 28 ++++++++++++++-------------- networking/udhcp/dhcpc.h | 6 ++++-- networking/udhcp/dhcpd.h | 6 ++++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index c44220bf9..b0f0798e5 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -311,8 +311,8 @@ static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t return d6_send_raw_packet( packet, (end - (uint8_t*) packet), - /*src*/ NULL, CLIENT_PORT, - /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT, MAC_BCAST_ADDR, + /*src*/ NULL, CLIENT_PORT6, + /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR, client_config.ifindex ); } @@ -554,8 +554,8 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st if (server_ipv6) return d6_send_kernel_packet( &packet, (opt_ptr - (uint8_t*) &packet), - our_cur_ipv6, CLIENT_PORT, - server_ipv6, SERVER_PORT + our_cur_ipv6, CLIENT_PORT6, + server_ipv6, SERVER_PORT6 ); return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); } @@ -576,8 +576,8 @@ static int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cu bb_info_msg("Sending release..."); return d6_send_kernel_packet( &packet, (opt_ptr - (uint8_t*) &packet), - our_cur_ipv6, CLIENT_PORT, - server_ipv6, SERVER_PORT + our_cur_ipv6, CLIENT_PORT6, + server_ipv6, SERVER_PORT6 ); } @@ -614,7 +614,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6 /* make sure its the right packet for us, and that it passes sanity checks */ if (packet.ip6.ip6_nxt != IPPROTO_UDP || (packet.ip6.ip6_vfc >> 4) != 6 - || packet.udp.dest != htons(CLIENT_PORT) + || packet.udp.dest != htons(CLIENT_PORT6) /* || bytes > (int) sizeof(packet) - can't happen */ || packet.udp.len != packet.ip6.ip6_plen ) { @@ -708,7 +708,7 @@ static int d6_raw_socket(int ifindex) BPF_STMT(BPF_LDX|BPF_B|BPF_MSH, 0), /* load udp destination port from halfword[header_len + 2] */ BPF_STMT(BPF_LD|BPF_H|BPF_IND, 2), - /* jump to L3 if udp dport is CLIENT_PORT, else to L4 */ + /* jump to L3 if udp dport is CLIENT_PORT6, else to L4 */ BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 68, 0, 1), /* L3: accept packet */ BPF_STMT(BPF_RET|BPF_K, 0xffffffff), @@ -733,7 +733,7 @@ static int d6_raw_socket(int ifindex) xbind(fd, (struct sockaddr *) &sock, sizeof(sock)); #if 0 - if (CLIENT_PORT == 68) { + if (CLIENT_PORT6 == 546) { /* Use only if standard port is in use */ /* Ignoring error (kernel may lack support for this) */ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, @@ -761,7 +761,7 @@ static void change_listen_mode(int new_mode) sockfd = -1; } if (new_mode == LISTEN_KERNEL) - sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); + sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT6, client_config.interface); else if (new_mode != LISTEN_NONE) sockfd = d6_raw_socket(client_config.ifindex); /* else LISTEN_NONE: sockfd stays closed */ @@ -931,8 +931,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) fd_set rfds; /* Default options */ - IF_FEATURE_UDHCP_PORT(SERVER_PORT = 547;) - IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 546;) + IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) + IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) client_config.interface = "eth0"; client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; @@ -961,8 +961,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) } #if ENABLE_FEATURE_UDHCP_PORT if (opt & OPT_P) { - CLIENT_PORT = xatou16(str_P); - SERVER_PORT = CLIENT_PORT - 1; + CLIENT_PORT6 = xatou16(str_P); + SERVER_PORT6 = CLIENT_PORT6 + 1; } #endif while (list_O) { diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 2859a0772..9f423a5b2 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h @@ -29,9 +29,11 @@ struct client_config_t { #define client_config (*(struct client_config_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE / 2])) #if ENABLE_FEATURE_UDHCP_PORT -#define CLIENT_PORT (client_config.port) +#define CLIENT_PORT (client_config.port) +#define CLIENT_PORT6 (client_config.port) #else -#define CLIENT_PORT 68 +#define CLIENT_PORT 68 +#define CLIENT_PORT6 546 #endif POP_SAVED_FUNCTION_VISIBILITY diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 7c801bf6b..a77724f20 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h @@ -61,9 +61,11 @@ struct server_config_t { /* client_config sits in 2nd half of bb_common_bufsiz1 */ #if ENABLE_FEATURE_UDHCP_PORT -#define SERVER_PORT (server_config.port) +#define SERVER_PORT (server_config.port) +#define SERVER_PORT6 (server_config.port) #else -#define SERVER_PORT 67 +#define SERVER_PORT 67 +#define SERVER_PORT6 547 #endif -- cgit v1.2.3-55-g6feb From 6e29d07417c84e69ed0fb375205ae4e62fa236f7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Jan 2013 16:51:22 +0100 Subject: mdev: extend debug logging output Signed-off-by: Denys Vlasenko --- util-linux/mdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 75de14ff1..52122dd63 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -661,6 +661,8 @@ static void make_device(char *device_name, char *path, int operation) if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) bb_perror_msg("can't create '%s'", node_name); if (ENABLE_FEATURE_MDEV_CONF) { + if (G.verbose) + bb_error_msg("chmod: %o chown: %u:%u", rule->mode, rule->ugid.uid, rule->ugid.gid); chmod(node_name, rule->mode); chown(node_name, rule->ugid.uid, rule->ugid.gid); } @@ -923,7 +925,9 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) if (logfd >= 0) { xmove_fd(logfd, STDERR_FILENO); G.verbose = 1; - bb_error_msg("seq: %s action: %s", seq, action); + if (seq) + applet_name = xasprintf("%s[%s]", applet_name, seq); + bb_error_msg("action: %s", action); } } -- cgit v1.2.3-55-g6feb From a8816dafc4b274b17c58df88cabdbf9e2b47f528 Mon Sep 17 00:00:00 2001 From: Kuleshov Aleksey Date: Mon, 4 Feb 2013 15:14:20 +0100 Subject: arp: fix -H/-t handling. While at it, shrank code. function old new delta arp_main 1558 1487 -71 Signed-off-by: Kuleshov Aleksey Signed-off-by: Denys Vlasenko --- networking/arp.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/networking/arp.c b/networking/arp.c index 1c99987ae..201bb2aff 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -477,28 +477,33 @@ static int arp_show(char *name) int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int arp_main(int argc UNUSED_PARAM, char **argv) { - const char *hw_type = "ether"; + const char *hw_type; const char *protocol; unsigned opts; INIT_G(); xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); + ap = get_aftype(DFLT_AF); - if (!ap) - bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); + /* Defaults are always supported */ + //if (!ap) + // bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); + hw = get_hwtype(DFLT_HW); + //if (!hw) + // bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, &hw_type, &hw_type, &device); argv += optind; if (opts & (ARP_OPT_A | ARP_OPT_p)) { ap = get_aftype(protocol); - if (ap == NULL) + if (!ap) bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); } - if (opts & (ARP_OPT_A | ARP_OPT_p)) { + if (opts & (ARP_OPT_H | ARP_OPT_t)) { hw = get_hwtype(hw_type); - if (hw == NULL) + if (!hw) bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); hw_set = 1; } @@ -507,14 +512,6 @@ int arp_main(int argc UNUSED_PARAM, char **argv) if (ap->af != AF_INET) { bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); } - - /* If no hw type specified get default */ - if (!hw) { - hw = get_hwtype(DFLT_HW); - if (!hw) - bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); - } - if (hw->alen <= 0) { bb_error_msg_and_die("%s: %s without ARP support", hw->name, "hardware type"); @@ -528,6 +525,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv) return arp_set(argv); return arp_del(argv); } + //if (opts & ARP_OPT_a) - default return arp_show(argv[0]); } -- cgit v1.2.3-55-g6feb From 06af569f447664526a76e527ea14ae059f5c19a9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 4 Feb 2013 16:18:58 +0100 Subject: arp: code shrink function old new delta packed_usage 29257 29252 -5 arp_main 1487 1471 -16 Signed-off-by: Denys Vlasenko --- networking/arp.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/networking/arp.c b/networking/arp.c index 201bb2aff..40d244116 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -22,12 +22,12 @@ //usage:#define arp_full_usage "\n\n" //usage: "Manipulate ARP cache\n" //usage: "\n -a Display (all) hosts" -//usage: "\n -s Set new ARP entry" -//usage: "\n -d Delete a specified entry" +//usage: "\n -d Delete ARP entry" +//usage: "\n -s Set new entry" //usage: "\n -v Verbose" //usage: "\n -n Don't resolve names" //usage: "\n -i IF Network interface" -//usage: "\n -D Read from given device" +//usage: "\n -D Read HWADDR from IFACE" //usage: "\n -A,-p AF Protocol family" //usage: "\n -H HWTYPE Hardware address type" @@ -213,16 +213,15 @@ static int arp_del(char **args) } /* Get the hardware address to a specified interface name */ -static void arp_getdevhw(char *ifname, struct sockaddr *sa, - const struct hwtype *hwt) +static void arp_getdevhw(char *ifname, struct sockaddr *sa) { struct ifreq ifr; const struct hwtype *xhw; strcpy(ifr.ifr_name, ifname); ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, - "cant get HW-Address for '%s'", ifname); - if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) { + "can't get HW-Address for '%s'", ifname); + if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) { bb_error_msg_and_die("protocol type mismatch"); } memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); @@ -233,8 +232,8 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa, xhw = get_hwntype(-1); } bb_error_msg("device '%s' has HW address %s '%s'", - ifname, xhw->name, - xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); + ifname, xhw->name, + xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); } } @@ -261,7 +260,7 @@ static int arp_set(char **args) bb_error_msg_and_die("need hardware address"); } if (option_mask32 & ARP_OPT_D) { - arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL); + arp_getdevhw(*args++, &req.arp_ha); } else { if (hw->input(*args++, &req.arp_ha) < 0) { bb_error_msg_and_die("invalid hardware address"); -- cgit v1.2.3-55-g6feb From ba76b7a40b929878833731f76306b1c977cc8650 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 4 Feb 2013 23:35:27 +0100 Subject: mdev: chdir back to /dev after trying to read firmware Signed-off-by: Denys Vlasenko --- util-linux/mdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 52122dd63..c592ef687 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -815,6 +815,7 @@ static void load_firmware(const char *firmware, const char *sysfs_path) full_write(loading_fd, "-1", 2); out: + xchdir("/dev"); if (ENABLE_FEATURE_CLEAN_UP) { close(firmware_fd); close(loading_fd); @@ -921,7 +922,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) } { - int logfd = open("/dev/mdev.log", O_WRONLY | O_APPEND); + int logfd = open("mdev.log", O_WRONLY | O_APPEND); if (logfd >= 0) { xmove_fd(logfd, STDERR_FILENO); G.verbose = 1; -- cgit v1.2.3-55-g6feb