diff options
| -rw-r--r-- | adb/adb.c | 4 | ||||
| -rw-r--r-- | adb/usb_vendors.c | 3 | ||||
| -rw-r--r-- | debuggerd/crasher.c | 65 | ||||
| -rw-r--r-- | debuggerd/debuggerd.c | 14 | ||||
| -rw-r--r-- | debuggerd/tombstone.c | 48 | ||||
| -rw-r--r-- | debuggerd/tombstone.h | 2 | ||||
| -rw-r--r-- | include/cutils/debugger.h | 2 | ||||
| -rwxr-xr-x | init/init.c | 18 | ||||
| -rwxr-xr-x | init/property_service.c | 6 | ||||
| -rw-r--r-- | libsparse/output_file.c | 3 | ||||
| -rw-r--r-- | rootdir/etc/init.goldfish.rc | 1 | ||||
| -rw-r--r-- | rootdir/init.rc | 2 | ||||
| -rw-r--r-- | toolbox/dd.c | 8 | ||||
| -rw-r--r-- | toolbox/dmesg.c | 27 | ||||
| -rw-r--r-- | toolbox/ls.c | 80 | ||||
| -rw-r--r-- | toolbox/mount.c | 7 |
16 files changed, 191 insertions, 99 deletions
@@ -401,6 +401,10 @@ static char *connection_state_name(atransport *t) return "bootloader"; case CS_DEVICE: return "device"; + case CS_RECOVERY: + return "recovery"; + case CS_SIDELOAD: + return "sideload"; case CS_OFFLINE: return "offline"; default: diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c index 604c461..698f8a9 100644 --- a/adb/usb_vendors.c +++ b/adb/usb_vendors.c @@ -141,6 +141,8 @@ #define VENDOR_ID_XIAOMI 0x2717 // BYD's USB Vendor ID #define VENDOR_ID_BYD 0x19D1 +// OUYA's USB Vendor ID +#define VENDOR_ID_OUYA 0x2836 /** built-in vendor list */ @@ -198,6 +200,7 @@ int builtInVendorIds[] = { VENDOR_ID_OPPO, VENDOR_ID_XIAOMI, VENDOR_ID_BYD, + VENDOR_ID_OUYA, }; #define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c index 630d980..d88ef88 100644 --- a/debuggerd/crasher.c +++ b/debuggerd/crasher.c @@ -17,6 +17,8 @@ #include <cutils/sockets.h> +extern const char* __progname; + void crash1(void); void crashnostack(void); void maybeabort(void); @@ -47,20 +49,16 @@ int smash_stack(int i) { return *(int*)(&buf[0]); } -void test_call1() -{ - *((int*) 32) = 1; +__attribute__((noinline)) void overflow_stack(void* p) { + fprintf(stderr, "p = %p\n", p); + void* buf[1]; + buf[0] = p; + overflow_stack(&buf); } -void *test_thread(void *x) +void test_call1() { - printf("crasher: thread pid=%d tid=%d\n", getpid(), gettid()); - - sleep(1); - test_call1(); - printf("goodbye\n"); - - return 0; + *((int*) 32) = 1; } void *noisy(void *x) @@ -118,35 +116,48 @@ __attribute__((noinline)) int crash(int a) { int do_action(const char* arg) { - if(!strncmp(arg, "thread-", strlen("thread-"))) { + fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); + + if (!strncmp(arg, "thread-", strlen("thread-"))) { return do_action_on_thread(arg + strlen("thread-")); + } else if (!strcmp(arg,"smash-stack")) { + return smash_stack(42); + } else if (!strcmp(arg,"stack-overflow")) { + overflow_stack(NULL); + } else if (!strcmp(arg,"nostack")) { + crashnostack(); + } else if (!strcmp(arg,"ctest")) { + return ctest(); + } else if (!strcmp(arg,"exit")) { + exit(1); + } else if (!strcmp(arg,"crash")) { + return crash(42); + } else if (!strcmp(arg,"abort")) { + maybeabort(); } - if(!strcmp(arg,"smash-stack")) return smash_stack(42); - if(!strcmp(arg,"nostack")) crashnostack(); - if(!strcmp(arg,"ctest")) return ctest(); - if(!strcmp(arg,"exit")) exit(1); - if(!strcmp(arg,"crash")) return crash(42); - if(!strcmp(arg,"abort")) maybeabort(); - - pthread_t thr; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&thr, &attr, test_thread, 0); - while(1) sleep(1); + fprintf(stderr, "%s OP\n", __progname); + fprintf(stderr, "where OP is:\n"); + fprintf(stderr, " smash-stack overwrite a stack-guard canary\n"); + fprintf(stderr, " stack-overflow recurse until the stack overflows\n"); + fprintf(stderr, " nostack crash with a NULL stack pointer\n"); + fprintf(stderr, " ctest (obsoleted by thread-crash?)\n"); + fprintf(stderr, " exit call exit(1)\n"); + fprintf(stderr, " crash cause a SIGSEGV\n"); + fprintf(stderr, " abort call abort()\n"); + fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); + fprintf(stderr, "on the process' main thread.\n"); + return EXIT_SUCCESS; } int main(int argc, char **argv) { fprintf(stderr,"crasher: built at " __TIME__ "!@\n"); - fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); if(argc > 1) { return do_action(argv[1]); } else { crash1(); -// *((int*) 0) = 42; } return 0; diff --git a/debuggerd/debuggerd.c b/debuggerd/debuggerd.c index 55222c5..99e6f13 100644 --- a/debuggerd/debuggerd.c +++ b/debuggerd/debuggerd.c @@ -52,6 +52,7 @@ typedef struct { debugger_action_t action; pid_t pid, tid; uid_t uid, gid; + uintptr_t abort_msg_address; } debugger_request_t; static int @@ -207,12 +208,15 @@ static int read_request(int fd, debugger_request_t* out_request) { } debugger_msg_t msg; + memset(&msg, 0, sizeof(msg)); status = TEMP_FAILURE_RETRY(read(fd, &msg, sizeof(msg))); if (status < 0) { LOG("read failure? %s\n", strerror(errno)); return -1; } - if (status != sizeof(msg)) { + if (status == sizeof(debugger_msg_t)) { + XLOG("crash request of size %d abort_msg_address=%#08x\n", status, msg.abort_msg_address); + } else { LOG("invalid crash request of size %d\n", status); return -1; } @@ -222,6 +226,7 @@ static int read_request(int fd, debugger_request_t* out_request) { out_request->pid = cr.pid; out_request->uid = cr.uid; out_request->gid = cr.gid; + out_request->abort_msg_address = msg.abort_msg_address; if (msg.action == DEBUGGER_ACTION_CRASH) { /* Ensure that the tid reported by the crashing process is valid. */ @@ -265,6 +270,7 @@ static void handle_request(int fd) { XLOG("handle_request(%d)\n", fd); debugger_request_t request; + memset(&request, 0, sizeof(request)); int status = read_request(fd, &request); if (!status) { XLOG("BOOM: pid=%d uid=%d gid=%d tid=%d\n", @@ -308,7 +314,7 @@ static void handle_request(int fd) { if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { XLOG("stopped -- dumping to tombstone\n"); tombstone_path = engrave_tombstone(request.pid, request.tid, - signal, true, true, &detach_failed, + signal, request.abort_msg_address, true, true, &detach_failed, &total_sleep_time_usec); } else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) { XLOG("stopped -- dumping to fd\n"); @@ -345,8 +351,8 @@ static void handle_request(int fd) { /* don't dump sibling threads when attaching to GDB because it * makes the process less reliable, apparently... */ tombstone_path = engrave_tombstone(request.pid, request.tid, - signal, !attach_gdb, false, &detach_failed, - &total_sleep_time_usec); + signal, request.abort_msg_address, !attach_gdb, false, + &detach_failed, &total_sleep_time_usec); break; } diff --git a/debuggerd/tombstone.c b/debuggerd/tombstone.c index e8b3e24..da5f03c 100644 --- a/debuggerd/tombstone.c +++ b/debuggerd/tombstone.c @@ -174,7 +174,7 @@ static void dump_fault_addr(log_t* log, pid_t tid, int sig) siginfo_t si; memset(&si, 0, sizeof(si)); - if(ptrace(PTRACE_GETSIGINFO, tid, 0, &si)){ + if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si)){ _LOG(log, false, "cannot get siginfo: %s\n", strerror(errno)); } else if (signal_has_address(sig)) { _LOG(log, false, "signal %d (%s), code %d (%s), fault addr %08x\n", @@ -616,11 +616,46 @@ static void dump_logs(log_t* log, pid_t pid, bool tailOnly) dump_log_file(log, pid, "/dev/log/main", tailOnly); } +static void dump_abort_message(log_t* log, pid_t tid, uintptr_t address) { + if (address == 0) { + return; + } + + address += sizeof(size_t); // Skip the buffer length. + + char msg[512]; + memset(msg, 0, sizeof(msg)); + char* p = &msg[0]; + while (p < &msg[sizeof(msg)]) { + uint32_t data; + if (!try_get_word_ptrace(tid, address, &data)) { + break; + } + address += sizeof(uint32_t); + + if ((*p++ = (data >> 0) & 0xff) == 0) { + break; + } + if ((*p++ = (data >> 8) & 0xff) == 0) { + break; + } + if ((*p++ = (data >> 16) & 0xff) == 0) { + break; + } + if ((*p++ = (data >> 24) & 0xff) == 0) { + break; + } + } + msg[sizeof(msg) - 1] = '\0'; + + _LOG(log, false, "Abort message: '%s'\n", msg); +} + /* * Dumps all information about the specified pid to the tombstone. */ -static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, - bool dump_sibling_threads, int* total_sleep_time_usec) +static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, + bool dump_sibling_threads, int* total_sleep_time_usec) { /* don't copy log messages to tombstone unless this is a dev device */ char value[PROPERTY_VALUE_MAX]; @@ -632,9 +667,10 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, dump_build_info(log); dump_revision_info(log); dump_thread_info(log, pid, tid, true); - if(signal) { + if (signal) { dump_fault_addr(log, tid, signal); } + dump_abort_message(log, tid, abort_msg_address); ptrace_context_t* context = load_ptrace_context(tid); dump_thread(context, log, tid, true, total_sleep_time_usec); @@ -712,7 +748,7 @@ static char* find_and_open_tombstone(int* fd) return strdup(path); } -char* engrave_tombstone(pid_t pid, pid_t tid, int signal, +char* engrave_tombstone(pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec) { mkdir(TOMBSTONE_DIR, 0755); @@ -733,7 +769,7 @@ char* engrave_tombstone(pid_t pid, pid_t tid, int signal, log_t log; log.tfd = fd; log.quiet = quiet; - *detach_failed = dump_crash(&log, pid, tid, signal, dump_sibling_threads, + *detach_failed = dump_crash(&log, pid, tid, signal, abort_msg_address, dump_sibling_threads, total_sleep_time_usec); close(fd); diff --git a/debuggerd/tombstone.h b/debuggerd/tombstone.h index edcd7b1..d4a1a96 100644 --- a/debuggerd/tombstone.h +++ b/debuggerd/tombstone.h @@ -25,7 +25,7 @@ /* Creates a tombstone file and writes the crash dump to it. * Returns the path of the tombstone, which must be freed using free(). */ -char* engrave_tombstone(pid_t pid, pid_t tid, int signal, +char* engrave_tombstone(pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec); #endif // _DEBUGGERD_TOMBSTONE_H diff --git a/include/cutils/debugger.h b/include/cutils/debugger.h index 5a8e796..4eda523 100644 --- a/include/cutils/debugger.h +++ b/include/cutils/debugger.h @@ -34,10 +34,10 @@ typedef enum { DEBUGGER_ACTION_DUMP_BACKTRACE, } debugger_action_t; -/* message sent over the socket */ typedef struct { debugger_action_t action; pid_t tid; + uintptr_t abort_msg_address; } debugger_msg_t; /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). diff --git a/init/init.c b/init/init.c index b28b0ab..39df0ff 100755 --- a/init/init.c +++ b/init/init.c @@ -90,7 +90,7 @@ void notify_service_state(const char *name, const char *state) } static int have_console; -static char *console_name = "/dev/console"; +static char console_name[PROP_VALUE_MAX] = "/dev/console"; static time_t process_needs_restart; static const char *ENV[32]; @@ -430,7 +430,7 @@ static void restart_processes() static void msg_start(const char *name) { - struct service *svc; + struct service *svc = NULL; char *tmp = NULL; char *args = NULL; @@ -438,11 +438,13 @@ static void msg_start(const char *name) svc = service_find_by_name(name); else { tmp = strdup(name); - args = strchr(tmp, ':'); - *args = '\0'; - args++; + if (tmp) { + args = strchr(tmp, ':'); + *args = '\0'; + args++; - svc = service_find_by_name(tmp); + svc = service_find_by_name(tmp); + } } if (svc) { @@ -547,11 +549,9 @@ static int keychord_init_action(int nargs, char **args) static int console_init_action(int nargs, char **args) { int fd; - char tmp[PROP_VALUE_MAX]; if (console[0]) { - snprintf(tmp, sizeof(tmp), "/dev/%s", console); - console_name = strdup(tmp); + snprintf(console_name, sizeof(console_name), "/dev/%s", console); } fd = open(console_name, O_RDWR); diff --git a/init/property_service.c b/init/property_service.c index 61dd86f..48488be 100755 --- a/init/property_service.c +++ b/init/property_service.c @@ -353,7 +353,11 @@ int property_set(const char *name, const char *value) __futex_wake(&pa->serial, INT32_MAX); } else { pa = __system_property_area__; - if(pa->count == PA_COUNT_MAX) return -1; + if(pa->count == PA_COUNT_MAX) { + ERROR("Failed to set '%s'='%s', property pool is exhausted at %d entries", + name, value, PA_COUNT_MAX); + return -1; + } pi = pa_info_array + pa->count; pi->serial = (valuelen << 24); diff --git a/libsparse/output_file.c b/libsparse/output_file.c index b5ae419..5014e4a 100644 --- a/libsparse/output_file.c +++ b/libsparse/output_file.c @@ -675,6 +675,9 @@ struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t } else { out = output_file_new_normal(); } + if (!out) { + return NULL; + } out->ops->open(out, fd); diff --git a/rootdir/etc/init.goldfish.rc b/rootdir/etc/init.goldfish.rc index a0c1c4f..1373be8 100644 --- a/rootdir/etc/init.goldfish.rc +++ b/rootdir/etc/init.goldfish.rc @@ -3,6 +3,7 @@ on early-init mkdir /mnt/sdcard 0000 system system # for backwards compatibility symlink /mnt/sdcard /sdcard + mount debugfs debugfs /sys/kernel/debug on boot setsebool in_qemu 1 diff --git a/rootdir/init.rc b/rootdir/init.rc index 0784c63..4d72d61 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -37,7 +37,7 @@ loglevel 3 export ANDROID_STORAGE /storage export ASEC_MOUNTPOINT /mnt/asec export LOOP_MOUNTPOINT /mnt/obb - export BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar + export BOOTCLASSPATH /system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar # Backward compatibility symlink /system/etc /etc diff --git a/toolbox/dd.c b/toolbox/dd.c index 350f1d2..a8c12d2 100644 --- a/toolbox/dd.c +++ b/toolbox/dd.c @@ -590,8 +590,8 @@ pos_in(void) /* If not a pipe or tape device, try to seek on it. */ if (!(in.flags & (ISPIPE|ISTAPE))) { - if (lseek(in.fd, - (off_t)in.offset * (off_t)in.dbsz, SEEK_CUR) == -1) { + if (lseek64(in.fd, + (off64_t)in.offset * (off64_t)in.dbsz, SEEK_CUR) == -1) { fprintf(stderr, "%s: seek error: %s", in.name, strerror(errno)); exit(1); @@ -661,8 +661,8 @@ pos_out(void) * have specified the seek operand. */ if (!(out.flags & ISTAPE)) { - if (lseek(out.fd, - (off_t)out.offset * (off_t)out.dbsz, SEEK_SET) == -1) { + if (lseek64(out.fd, + (off64_t)out.offset * (off64_t)out.dbsz, SEEK_SET) == -1) { fprintf(stderr, "%s: seek error: %s\n", out.name, strerror(errno)); exit(1); diff --git a/toolbox/dmesg.c b/toolbox/dmesg.c index e57f607..9c73b00 100644 --- a/toolbox/dmesg.c +++ b/toolbox/dmesg.c @@ -5,15 +5,30 @@ #include <sys/klog.h> #include <string.h> -#define KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */ -#define KLOG_BUF_LEN (1 << KLOG_BUF_SHIFT) +#define FALLBACK_KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */ +#define FALLBACK_KLOG_BUF_LEN (1 << FALLBACK_KLOG_BUF_SHIFT) int dmesg_main(int argc, char **argv) { - char buffer[KLOG_BUF_LEN + 1]; - char *p = buffer; + char *buffer; + char *p; ssize_t ret; - int n, op; + int n, op, klog_buf_len; + + klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0); + + if (klog_buf_len <= 0) { + klog_buf_len = FALLBACK_KLOG_BUF_LEN; + } + + buffer = (char *)malloc(klog_buf_len + 1); + + if (!buffer) { + perror("malloc"); + return EXIT_FAILURE; + } + + p = buffer; if((argc == 2) && (!strcmp(argv[1],"-c"))) { op = KLOG_READ_CLEAR; @@ -21,7 +36,7 @@ int dmesg_main(int argc, char **argv) op = KLOG_READ_ALL; } - n = klogctl(op, buffer, KLOG_BUF_LEN); + n = klogctl(op, buffer, klog_buf_len); if (n < 0) { perror("klogctl"); return EXIT_FAILURE; diff --git a/toolbox/ls.c b/toolbox/ls.c index e530521..5324511 100644 --- a/toolbox/ls.c +++ b/toolbox/ls.c @@ -28,6 +28,7 @@ #define LIST_LONG_NUMERIC (1 << 5) #define LIST_CLASSIFY (1 << 6) #define LIST_MACLABEL (1 << 7) +#define LIST_INODE (1 << 8) // fwd static int listpath(const char *name, int flags); @@ -127,22 +128,20 @@ static int show_total_size(const char *dirname, DIR *d, int flags) return 0; } -static int listfile_size(const char *path, const char *filename, int flags) +static int listfile_size(const char *path, const char *filename, struct stat *s, + int flags) { - struct stat s; - - if (lstat(path, &s) < 0) { - fprintf(stderr, "lstat '%s' failed: %s\n", path, strerror(errno)); + if(!s || !path) { return -1; } /* blocks are 512 bytes, we want output to be KB */ if ((flags & LIST_SIZE) != 0) { - printf("%lld ", s.st_blocks / 2); + printf("%lld ", s->st_blocks / 2); } if ((flags & LIST_CLASSIFY) != 0) { - char filetype = mode2kind(s.st_mode); + char filetype = mode2kind(s->st_mode); if (filetype != 'l') { printf("%c ", filetype); } else { @@ -161,15 +160,18 @@ static int listfile_size(const char *path, const char *filename, int flags) return 0; } -static int listfile_long(const char *path, int flags) +static int listfile_long(const char *path, struct stat *s, int flags) { - struct stat s; char date[32]; char mode[16]; char user[16]; char group[16]; const char *name; + if(!s || !path) { + return -1; + } + /* name is anything after the final '/', or the whole path if none*/ name = strrchr(path, '/'); if(name == 0) { @@ -178,36 +180,32 @@ static int listfile_long(const char *path, int flags) name++; } - if(lstat(path, &s) < 0) { - return -1; - } - - mode2str(s.st_mode, mode); + mode2str(s->st_mode, mode); if (flags & LIST_LONG_NUMERIC) { - sprintf(user, "%ld", s.st_uid); - sprintf(group, "%ld", s.st_gid); + sprintf(user, "%ld", s->st_uid); + sprintf(group, "%ld", s->st_gid); } else { - user2str(s.st_uid, user); - group2str(s.st_gid, group); + user2str(s->st_uid, user); + group2str(s->st_gid, group); } - strftime(date, 32, "%Y-%m-%d %H:%M", localtime((const time_t*)&s.st_mtime)); + strftime(date, 32, "%Y-%m-%d %H:%M", localtime((const time_t*)&s->st_mtime)); date[31] = 0; // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 // MMMMMMMM UUUUUUUU GGGGGGGGG XXXXXXXX YYYY-MM-DD HH:MM NAME (->LINK) - switch(s.st_mode & S_IFMT) { + switch(s->st_mode & S_IFMT) { case S_IFBLK: case S_IFCHR: printf("%s %-8s %-8s %3d, %3d %s %s\n", mode, user, group, - (int) MAJOR(s.st_rdev), (int) MINOR(s.st_rdev), + (int) MAJOR(s->st_rdev), (int) MINOR(s->st_rdev), date, name); break; case S_IFREG: printf("%s %-8s %-8s %8lld %s %s\n", - mode, user, group, s.st_size, date, name); + mode, user, group, s->st_size, date, name); break; case S_IFLNK: { char linkto[256]; @@ -237,15 +235,18 @@ static int listfile_long(const char *path, int flags) return 0; } -static int listfile_maclabel(const char *path, int flags) +static int listfile_maclabel(const char *path, struct stat *s, int flags) { - struct stat s; char mode[16]; char user[16]; char group[16]; char *maclabel = NULL; const char *name; + if(!s || !path) { + return -1; + } + /* name is anything after the final '/', or the whole path if none*/ name = strrchr(path, '/'); if(name == 0) { @@ -254,20 +255,16 @@ static int listfile_maclabel(const char *path, int flags) name++; } - if(lstat(path, &s) < 0) { - return -1; - } - lgetfilecon(path, &maclabel); if (!maclabel) { return -1; } - mode2str(s.st_mode, mode); - user2str(s.st_uid, user); - group2str(s.st_gid, group); + mode2str(s->st_mode, mode); + user2str(s->st_uid, user); + group2str(s->st_gid, group); - switch(s.st_mode & S_IFMT) { + switch(s->st_mode & S_IFMT) { case S_IFLNK: { char linkto[256]; ssize_t len; @@ -301,7 +298,9 @@ static int listfile_maclabel(const char *path, int flags) static int listfile(const char *dirname, const char *filename, int flags) { - if ((flags & (LIST_LONG | LIST_SIZE | LIST_CLASSIFY | LIST_MACLABEL)) == 0) { + struct stat s; + + if ((flags & (LIST_LONG | LIST_SIZE | LIST_CLASSIFY | LIST_MACLABEL | LIST_INODE)) == 0) { printf("%s\n", filename); return 0; } @@ -316,12 +315,20 @@ static int listfile(const char *dirname, const char *filename, int flags) pathname = filename; } + if(lstat(pathname, &s) < 0) { + return -1; + } + + if(flags & LIST_INODE) { + printf("%8llu ", s.st_ino); + } + if ((flags & LIST_MACLABEL) != 0) { - return listfile_maclabel(pathname, flags); + return listfile_maclabel(pathname, &s, flags); } else if ((flags & LIST_LONG) != 0) { - return listfile_long(pathname, flags); + return listfile_long(pathname, &s, flags); } else /*((flags & LIST_SIZE) != 0)*/ { - return listfile_size(pathname, filename, flags); + return listfile_size(pathname, filename, &s, flags); } } @@ -456,6 +463,7 @@ int ls_main(int argc, char **argv) case 'Z': flags |= LIST_MACLABEL; break; case 'a': flags |= LIST_ALL; break; case 'F': flags |= LIST_CLASSIFY; break; + case 'i': flags |= LIST_INODE; break; default: fprintf(stderr, "%s: Unknown option '-%c'. Aborting.\n", "ls", arg[0]); exit(1); diff --git a/toolbox/mount.c b/toolbox/mount.c index b7adce2..bcda2a2 100644 --- a/toolbox/mount.c +++ b/toolbox/mount.c @@ -19,7 +19,7 @@ #define LOOPDEV_MAXLEN 64 struct mount_opts { - const char str[8]; + const char str[16]; unsigned long rwmask; unsigned long rwset; unsigned long rwnoset; @@ -65,10 +65,11 @@ static const struct mount_opts options[] = { static void add_extra_option(struct extra_opts *extra, char *s) { int len = strlen(s); - int newlen = extra->used_size + len; + int newlen; if (extra->str) len++; /* +1 for ',' */ + newlen = extra->used_size + len; if (newlen >= extra->alloc_size) { char *new; @@ -79,7 +80,7 @@ static void add_extra_option(struct extra_opts *extra, char *s) extra->str = new; extra->end = extra->str + extra->used_size; - extra->alloc_size = newlen; + extra->alloc_size = newlen + 1; } if (extra->used_size) { |
