am 64a053b6: am 705ab8db: Fix sim build - remove unncesessary header.

Merge commit '64a053b67371595d2b541cd4f945fcec1fb8e9d2'

* commit '64a053b67371595d2b541cd4f945fcec1fb8e9d2':
  Fix sim build - remove unncesessary header.
diff --git a/Android.mk b/Android.mk
index fa2f6f8..a307719 100644
--- a/Android.mk
+++ b/Android.mk
@@ -25,6 +25,7 @@
 	      liblog \
 	      libnetutils \
 	      libpixelflinger \
+	      libusbhost \
 	      libzipfile \
 	   ))
 endif
diff --git a/adb/commandline.c b/adb/commandline.c
index dcba83b..3600e5a 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -838,12 +838,24 @@
         return adb_send_emulator_command(argc, argv);
     }
 
-    if(!strcmp(argv[0], "shell")) {
+    if(!strcmp(argv[0], "shell") || !strcmp(argv[0], "hell")) {
         int r;
         int fd;
 
+        char h = (argv[0][0] == 'h');
+
+        if (h) {
+            printf("\x1b[41;33m");
+            fflush(stdout);
+        }
+
         if(argc < 2) {
-            return interactive_shell();
+            r = interactive_shell();
+            if (h) {
+                printf("\x1b[0m");
+                fflush(stdout);
+            }
+            return r;
         }
 
         snprintf(buf, sizeof buf, "shell:%s", argv[1]);
@@ -877,6 +889,10 @@
                 adb_sleep_ms(1000);
                 do_cmd(ttype, serial, "wait-for-device", 0);
             } else {
+                if (h) {
+                    printf("\x1b[0m");
+                    fflush(stdout);
+                }
                 return r;
             }
         }
diff --git a/fastboot/engine.c b/fastboot/engine.c
index 48073ee..28a0ad9 100644
--- a/fastboot/engine.c
+++ b/fastboot/engine.c
@@ -277,11 +277,11 @@
     a->data = (void*) notice;
 }
 
-void fb_execute_queue(usb_handle *usb)
+int fb_execute_queue(usb_handle *usb)
 {
     Action *a;
     char resp[FB_RESPONSE_SZ+1];
-    int status;
+    int status = 0;
 
     a = action_list;
     resp[FB_RESPONSE_SZ] = 0;
@@ -314,5 +314,5 @@
     }
 
     fprintf(stderr,"finished. total time: %.3fs\n", (now() - start));
+    return status;
 }
-
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index f3bfbeba..63208bc 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -552,11 +552,12 @@
     void *data;
     unsigned sz;
     unsigned page_size = 2048;
+    int status;
 
     skip(1);
     if (argc == 0) {
         usage();
-        return 0;
+        return 1;
     }
 
     if (!strcmp(*argv, "devices")) {
@@ -688,6 +689,7 @@
             argc = do_oem_command(argc, argv);
         } else {
             usage();
+	    return 1;
         }
     }
 
@@ -703,6 +705,6 @@
 
     usb = open_device();
 
-    fb_execute_queue(usb);
-    return 0;
+    status = fb_execute_queue(usb);
+    return (status) ? 1 : 0;
 }
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index a36c569..a4b27a0 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -49,7 +49,7 @@
 void fb_queue_command(const char *cmd, const char *msg);
 void fb_queue_download(const char *name, void *data, unsigned size);
 void fb_queue_notice(const char *notice);
-void fb_execute_queue(usb_handle *usb);
+int fb_execute_queue(usb_handle *usb);
 
 /* util stuff */
 void die(const char *fmt, ...);
diff --git a/fastboot/usb_osx.c b/fastboot/usb_osx.c
index 9488687..570a456 100644
--- a/fastboot/usb_osx.c
+++ b/fastboot/usb_osx.c
@@ -231,8 +231,7 @@
                 kr = (*interface)->ClearPipeStallBothEnds(interface,
                         handle->bulkIn);
                 if (kr != 0) {
-                    ERR("could not clear input pipe; result %d", kr);
-                    return -1;
+                    ERR("could not clear input pipe; result %x, ignoring...\n", kr);
                 }
             }
 
@@ -240,8 +239,7 @@
                 kr = (*interface)->ClearPipeStallBothEnds(interface,
                         handle->bulkOut);
                 if (kr != 0) {
-                    ERR("could not clear output pipe; result %d", kr);
-                    return -1;
+                    ERR("could not clear output pipe; result %x, ignoring....\n", kr);
                 }
             }
             
diff --git a/include/arch/linux-arm/AndroidConfig.h b/include/arch/linux-arm/AndroidConfig.h
index 32b7026..5e1e031 100644
--- a/include/arch/linux-arm/AndroidConfig.h
+++ b/include/arch/linux-arm/AndroidConfig.h
@@ -206,7 +206,9 @@
 /*
  * Add any extra platform-specific defines here.
  */
+#ifndef __linux__
 #define __linux__
+#endif
 
 /*
  * Define if we have <malloc.h> header
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index 903f99f..57d6761 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -161,6 +161,7 @@
     { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/main.conf" },
     { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/input.conf" },
     { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/audio.conf" },
+    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/network.conf" },
     { 00444, AID_NET_BT,    AID_NET_BT,    "system/etc/bluetooth/blacklist.conf" },
     { 00640, AID_SYSTEM,    AID_SYSTEM,    "system/etc/bluetooth/auto_pairing.conf" },
     { 00444, AID_RADIO,     AID_AUDIO,     "system/etc/AudioPara4.csv" },
diff --git a/include/usbhost/usbhost.h b/include/usbhost/usbhost.h
new file mode 100644
index 0000000..f7cc52e
--- /dev/null
+++ b/include/usbhost/usbhost.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __USB_HOST_H
+#define __USB_HOST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+struct usb_host_context;
+struct usb_endpoint_descriptor;
+
+struct usb_descriptor_iter {
+    unsigned char*  config;
+    unsigned char*  config_end;
+    unsigned char*  curr_desc;
+};
+
+/* Callback for notification when new USB devices are attached.
+ * Return true to exit from usb_host_run.
+ */
+typedef int (* usb_device_added_cb)(const char *dev_name, void *client_data);
+
+/* Callback for notification when USB devices are removed.
+ * Return true to exit from usb_host_run.
+ */
+typedef int (* usb_device_removed_cb)(const char *dev_name, void *client_data);
+
+/* Callback indicating that initial device discovery is done.
+ * Return true to exit from usb_host_run.
+ */
+typedef int (* usb_discovery_done_cb)(void *client_data);
+
+/* Call this to initialize the USB host library. */
+struct usb_host_context *usb_host_init(void);
+
+/* Call this to cleanup the USB host library. */
+void usb_host_cleanup(struct usb_host_context *context);
+
+/* Call this to monitor the USB bus for new and removed devices.
+ * This is intended to be called from a dedicated thread,
+ * as it will not return until one of the callbacks returns true.
+ * added_cb will be called immediately for each existing USB device,
+ * and subsequently each time a new device is added.
+ * removed_cb is called when USB devices are removed from the bus.
+ * discovery_done_cb is called after the initial discovery of already
+ * connected devices is complete.
+ */
+void usb_host_run(struct usb_host_context *context,
+                  usb_device_added_cb added_cb,
+                  usb_device_removed_cb removed_cb,
+                  usb_discovery_done_cb discovery_done_cb,
+                  void *client_data);
+
+/* Creates a usb_device object for a USB device */
+struct usb_device *usb_device_open(const char *dev_name);
+
+/* Releases all resources associated with the USB device */
+void usb_device_close(struct usb_device *device);
+
+/* Returns the name for the USB device, which is the same as
+ * the dev_name passed to usb_device_open()
+ */
+const char* usb_device_get_name(struct usb_device *device);
+
+/* Returns a unique ID for the device.  Currently this is generated from the
+ * dev_name path.
+ */
+int usb_device_get_unique_id(struct usb_device *device);
+
+int usb_device_get_unique_id_from_name(const char* name);
+
+/* Returns the USB vendor ID from the device descriptor for the USB device */
+uint16_t usb_device_get_vendor_id(struct usb_device *device);
+
+/* Returns the USB product ID from the device descriptor for the USB device */
+uint16_t usb_device_get_product_id(struct usb_device *device);
+
+/* Sends a control message to the specified device on endpoint zero */
+int usb_device_send_control(struct usb_device *device,
+                            int requestType,
+                            int request,
+                            int value,
+                            int index,
+                            int length,
+                            void* buffer);
+
+/* Returns a USB descriptor string for the given string ID.
+ * Used to implement usb_device_get_manufacturer_name,
+ * usb_device_get_product_name and usb_device_get_serial.
+ * Call free() to free the result when you are done with it.
+ */
+char* usb_device_get_string(struct usb_device *device, int id);
+
+/* Returns the manufacturer name for the USB device.
+ * Call free() to free the result when you are done with it.
+ */
+char* usb_device_get_manufacturer_name(struct usb_device *device);
+
+/* Returns the product name for the USB device.
+ * Call free() to free the result when you are done with it.
+ */
+char* usb_device_get_product_name(struct usb_device *device);
+
+/* Returns the USB serial number for the USB device.
+ * Call free() to free the result when you are done with it.
+ */
+char* usb_device_get_serial(struct usb_device *device);
+
+/* Returns true if we have write access to the USB device,
+ * and false if we only have access to the USB device configuration.
+ */
+int usb_device_is_writeable(struct usb_device *device);
+
+/* Initializes a usb_descriptor_iter, which can be used to iterate through all
+ * the USB descriptors for a USB device.
+ */
+void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter);
+
+/* Returns the next USB descriptor for a device, or NULL if we have reached the
+ * end of the list.
+ */
+struct usb_descriptor_header *usb_descriptor_iter_next(struct usb_descriptor_iter *iter);
+
+/* Claims the specified interface of a USB device */
+int usb_device_claim_interface(struct usb_device *device, unsigned int interface);
+
+/* Releases the specified interface of a USB device */
+int usb_device_release_interface(struct usb_device *device, unsigned int interface);
+
+
+/* Creates a new usb_endpoint for the specified endpoint of a USB device.
+ * This can be used to read or write data across the endpoint.
+ */
+struct usb_endpoint *usb_endpoint_open(struct usb_device *dev,
+                const struct usb_endpoint_descriptor *desc);
+
+/* Releases all resources associated with the endpoint */
+void usb_endpoint_close(struct usb_endpoint *ep);
+
+/* Begins a read or write operation on the specified endpoint */
+int usb_endpoint_queue(struct usb_endpoint *ep, void *data, int len);
+
+ /* Waits for the results of a previous usb_endpoint_queue operation on the
+  * specified endpoint.  Returns number of bytes transferred, or a negative
+  * value for error.
+  */
+int usb_endpoint_wait(struct usb_device *device, int *out_ep_num);
+
+/* Cancels a pending usb_endpoint_queue() operation on an endpoint. */
+int usb_endpoint_cancel(struct usb_endpoint *ep);
+
+/* Returns the usb_device for the given endpoint */
+struct usb_device *usb_endpoint_get_device(struct usb_endpoint *ep);
+
+/* Returns the endpoint address for the given endpoint */
+int usb_endpoint_number(struct usb_endpoint *ep);
+
+/* Returns the maximum packet size for the given endpoint.
+ * For bulk endpoints this should be 512 for highspeed or 64 for fullspeed.
+ */
+int usb_endpoint_max_packet(struct usb_endpoint *ep);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __USB_HOST_H */
diff --git a/init/builtins.c b/init/builtins.c
index e0ccf9f..4326ebc 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -258,7 +258,6 @@
     const char *name;
     unsigned flag;
 } mount_flags[] = {
-    { "move",       MS_MOVE },
     { "noatime",    MS_NOATIME },
     { "nosuid",     MS_NOSUID },
     { "nodev",      MS_NODEV },
diff --git a/init/devices.c b/init/devices.c
index 8e912de..21e1ee3 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -264,6 +264,57 @@
                     uevent->firmware, uevent->major, uevent->minor);
 }
 
+static char **get_character_device_symlinks(struct uevent *uevent)
+{
+    const char *parent;
+    char *slash;
+    char **links;
+    int link_num = 0;
+    int width;
+
+    if (strncmp(uevent->path, "/devices/platform/", 18))
+        return NULL;
+
+    links = malloc(sizeof(char *) * 2);
+    if (!links)
+        return NULL;
+    memset(links, 0, sizeof(char *) * 2);
+
+    /* skip "/devices/platform/<driver>" */
+    parent = strchr(uevent->path + 18, '/');
+    if (!*parent)
+        goto err;
+
+    if (!strncmp(parent, "/usb", 4)) {
+        /* skip root hub name and device. use device interface */
+        while (*++parent && *parent != '/');
+        if (*parent)
+            while (*++parent && *parent != '/');
+        if (!*parent)
+            goto err;
+        slash = strchr(++parent, '/');
+        if (!slash)
+            goto err;
+        width = slash - parent;
+        if (width <= 0)
+            goto err;
+
+        if (asprintf(&links[link_num], "/dev/usb/%s%.*s", uevent->subsystem, width, parent) > 0)
+            link_num++;
+        else
+            links[link_num] = NULL;
+        mkdir("/dev/usb", 0755);
+    }
+    else {
+        goto err;
+    }
+
+    return links;
+err:
+    free(links);
+    return NULL;
+}
+
 static char **parse_platform_block_device(struct uevent *uevent)
 {
     const char *driver;
@@ -407,6 +458,7 @@
             name += 4;
         } else
             base = "/dev/";
+        links = get_character_device_symlinks(uevent);
     }
 
     if (!devpath_ready)
diff --git a/init/init.c b/init/init.c
index 8f95da7..98539b8 100755
--- a/init/init.c
+++ b/init/init.c
@@ -673,7 +673,7 @@
     mkdir("/proc", 0755);
     mkdir("/sys", 0755);
 
-    mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755");
+    mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
     mkdir("/dev/pts", 0755);
     mkdir("/dev/socket", 0755);
     mount("devpts", "/dev/pts", "devpts", 0, NULL);
diff --git a/libacc/Android.mk b/libacc/Android.mk
index 5101e16..67661b4 100644
--- a/libacc/Android.mk
+++ b/libacc/Android.mk
@@ -4,7 +4,8 @@
 # Shared library for target
 # ========================================================
 
-LOCAL_MODULE:= libacc
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := libacc
 LOCAL_SRC_FILES := acc.cpp
 
 LOCAL_SHARED_LIBRARIES := libdl libcutils
diff --git a/libusbhost/Android.mk b/libusbhost/Android.mk
new file mode 100644
index 0000000..97c1edc
--- /dev/null
+++ b/libusbhost/Android.mk
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(my-dir)
+
+# Static library for Linux host
+# ========================================================
+
+ifeq ($(HOST_OS),linux)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libusbhost
+LOCAL_SRC_FILES := usbhost.c
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+endif
+
+# Static library for target
+# ========================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libusbhost
+LOCAL_SRC_FILES := usbhost.c
+
+LOCAL_CFLAGS := -g -DUSE_LIBLOG
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
new file mode 100644
index 0000000..98ccf7c
--- /dev/null
+++ b/libusbhost/usbhost.c
@@ -0,0 +1,503 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// #define DEBUG 1
+#if DEBUG
+
+#ifdef USE_LIBLOG
+#define LOG_TAG "usbhost"
+#include "utils/Log.h"
+#define D LOGD
+#else
+#define D printf
+#endif
+
+#else
+#define D(...)
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/inotify.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+#include <pthread.h>
+
+#include <linux/usbdevice_fs.h>
+#include <linux/version.h>
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
+#include <linux/usb/ch9.h>
+#else
+#include <linux/usb_ch9.h>
+#endif
+#include <asm/byteorder.h>
+
+#include "usbhost/usbhost.h"
+
+#define USB_FS_DIR "/dev/bus/usb"
+#define USB_FS_ID_SCANNER   "/dev/bus/usb/%d/%d"
+
+
+struct usb_host_context {
+    int fd;
+};
+
+struct usb_device {
+    char dev_name[64];
+    unsigned char desc[256];
+    int desc_length;
+    int fd;
+    int writeable;
+};
+
+struct usb_endpoint
+{
+    struct usb_device *dev;
+    struct usb_endpoint_descriptor  desc;
+    struct usbdevfs_urb urb;
+};
+
+static inline int badname(const char *name)
+{
+    while(*name) {
+        if(!isdigit(*name++)) return 1;
+    }
+    return 0;
+}
+
+/* returns true if one of the callbacks indicates we are done */
+static int find_existing_devices(usb_device_added_cb added_cb,
+                                  usb_device_removed_cb removed_cb,
+                                  void *client_data)
+{
+    char busname[32], devname[32];
+    DIR *busdir , *devdir ;
+    struct dirent *de;
+    int done = 0;
+
+    busdir = opendir(USB_FS_DIR);
+    if(busdir == 0) return 1;
+
+    while ((de = readdir(busdir)) != 0 && !done) {
+        if(badname(de->d_name)) continue;
+
+        snprintf(busname, sizeof busname, "%s/%s", USB_FS_DIR, de->d_name);
+        devdir = opendir(busname);
+        if(devdir == 0) continue;
+
+        while ((de = readdir(devdir)) && !done) {
+            if(badname(de->d_name)) continue;
+
+            snprintf(devname, sizeof devname, "%s/%s", busname, de->d_name);
+            done = added_cb(devname, client_data);
+        } // end of devdir while
+        closedir(devdir);
+    } //end of busdir while
+    closedir(busdir);
+
+    return done;
+}
+
+struct usb_host_context *usb_host_init()
+{
+    struct usb_host_context *context = calloc(1, sizeof(struct usb_host_context));
+    if (!context) {
+        fprintf(stderr, "out of memory in usb_host_context\n");
+        return NULL;
+    }
+    context->fd = inotify_init();
+    if (context->fd < 0) {
+        fprintf(stderr, "inotify_init failed\n");
+        free(context);
+        return NULL;
+    }
+    return context;
+}
+
+void usb_host_cleanup(struct usb_host_context *context)
+{
+    close(context->fd);
+    free(context);
+}
+
+void usb_host_run(struct usb_host_context *context,
+                  usb_device_added_cb added_cb,
+                  usb_device_removed_cb removed_cb,
+                  usb_discovery_done_cb discovery_done_cb,
+                  void *client_data)
+{
+    struct inotify_event* event;
+    char event_buf[512];
+    char path[100];
+    int i, ret, done = 0;
+    int wd, wds[10];
+    int wd_count = sizeof(wds) / sizeof(wds[0]);
+
+    D("Created device discovery thread\n");
+
+    /* watch for files added and deleted within USB_FS_DIR */
+    memset(wds, 0, sizeof(wds));
+    /* watch the root for new subdirectories */
+    wds[0] = inotify_add_watch(context->fd, USB_FS_DIR, IN_CREATE | IN_DELETE);
+    if (wds[0] < 0) {
+        fprintf(stderr, "inotify_add_watch failed\n");
+        if (discovery_done_cb)
+            discovery_done_cb(client_data);
+        return;
+    }
+
+    /* watch existing subdirectories of USB_FS_DIR */
+    for (i = 1; i < wd_count; i++) {
+        snprintf(path, sizeof(path), "%s/%03d", USB_FS_DIR, i);
+        ret = inotify_add_watch(context->fd, path, IN_CREATE | IN_DELETE);
+        if (ret > 0)
+            wds[i] = ret;
+    }
+
+    /* check for existing devices first, after we have inotify set up */
+    done = find_existing_devices(added_cb, removed_cb, client_data);
+    if (discovery_done_cb)
+        done |= discovery_done_cb(client_data);
+
+    while (!done) {
+        ret = read(context->fd, event_buf, sizeof(event_buf));
+        if (ret >= (int)sizeof(struct inotify_event)) {
+            event = (struct inotify_event *)event_buf;
+            wd = event->wd;
+            if (wd == wds[0]) {
+                i = atoi(event->name);
+                snprintf(path, sizeof(path), "%s/%s", USB_FS_DIR, event->name);
+                D("new subdirectory %s: index: %d\n", path, i);
+                if (i > 0 && i < wd_count) {
+                ret = inotify_add_watch(context->fd, path, IN_CREATE | IN_DELETE);
+                if (ret > 0)
+                    wds[i] = ret;
+                }
+            } else {
+                for (i = 1; i < wd_count && !done; i++) {
+                    if (wd == wds[i]) {
+                        snprintf(path, sizeof(path), "%s/%03d/%s", USB_FS_DIR, i, event->name);
+                        if (event->mask == IN_CREATE) {
+                            D("new device %s\n", path);
+                            done = added_cb(path, client_data);
+                        } else if (event->mask == IN_DELETE) {
+                            D("gone device %s\n", path);
+                            done = removed_cb(path, client_data);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+struct usb_device *usb_device_open(const char *dev_name)
+{
+    struct usb_device *device = calloc(1, sizeof(struct usb_device));
+    int fd, length, did_retry = 0;
+
+    strcpy(device->dev_name, dev_name);
+    device->writeable = 1;
+
+retry:
+    fd = open(dev_name, O_RDWR);
+    if (fd < 0) {
+        /* if we fail, see if have read-only access */
+        fd = open(dev_name, O_RDONLY);
+        D("usb_device_open open returned %d errno %d\n", fd, errno);
+        if (fd < 0 && (errno == EACCES || errno == ENOENT) && !did_retry) {
+            /* work around race condition between inotify and permissions management */
+            sleep(1);
+            did_retry = 1;
+            goto retry;
+        }
+
+        if (fd < 0) goto fail;
+        device->writeable = 0;
+        D("[ usb open read-only %s fd = %d]\n", dev_name, fd);
+    }
+
+    length = read(fd, device->desc, sizeof(device->desc));
+    D("usb_device_open read returned %d errno %d\n", fd, errno);
+    if (length < 0)
+        goto fail;
+
+    device->fd = fd;
+    device->desc_length = length;
+    return device;
+fail:
+    close(fd);
+    free(device);
+    return NULL;
+}
+
+void usb_device_close(struct usb_device *device)
+{
+    close(device->fd);
+    free(device);
+}
+
+const char* usb_device_get_name(struct usb_device *device)
+{
+    return device->dev_name;
+}
+
+int usb_device_get_unique_id(struct usb_device *device)
+{
+    int bus = 0, dev = 0;
+    sscanf(device->dev_name, USB_FS_ID_SCANNER, &bus, &dev);
+    return bus * 1000 + dev;
+}
+
+int usb_device_get_unique_id_from_name(const char* name)
+{
+    int bus = 0, dev = 0;
+    sscanf(name, USB_FS_ID_SCANNER, &bus, &dev);
+    return bus * 1000 + dev;
+}
+
+uint16_t usb_device_get_vendor_id(struct usb_device *device)
+{
+    struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
+    return __le16_to_cpu(desc->idVendor);
+}
+
+uint16_t usb_device_get_product_id(struct usb_device *device)
+{
+    struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
+    return __le16_to_cpu(desc->idProduct);
+}
+
+int usb_device_send_control(struct usb_device *device,
+                            int requestType,
+                            int request,
+                            int value,
+                            int index,
+                            int length,
+                            void* buffer)
+{
+    struct usbdevfs_ctrltransfer  ctrl;
+
+    // this usually requires read/write permission
+    if (!device->writeable) {
+        int fd = open(device->dev_name, O_RDWR);
+        if (fd > 0) {
+            close(device->fd);
+            device->fd = fd;
+            device->writeable = 1;
+        } else {
+            return -1;
+        }
+    }
+
+    memset(&ctrl, 0, sizeof(ctrl));
+    ctrl.bRequestType = requestType;
+    ctrl.bRequest = request;
+    ctrl.wValue = value;
+    ctrl.wIndex = index;
+    ctrl.wLength = length;
+    ctrl.data = buffer;
+    return ioctl(device->fd, USBDEVFS_CONTROL, &ctrl);
+}
+
+char* usb_device_get_string(struct usb_device *device, int id)
+{
+    char string[256];
+    __u16 buffer[128];
+    __u16 languages[128];
+    int i, result;
+    int languageCount = 0;
+
+    string[0] = 0;
+    memset(languages, 0, sizeof(languages));
+
+    // read list of supported languages
+    result = usb_device_send_control(device,
+            USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE, USB_REQ_GET_DESCRIPTOR,
+            (USB_DT_STRING << 8) | 0, 0, sizeof(languages), languages);
+    if (result > 0)
+        languageCount = (result - 2) / 2;
+
+    for (i = 1; i <= languageCount; i++) {
+        memset(buffer, 0, sizeof(buffer));
+
+        result = usb_device_send_control(device,
+                USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE, USB_REQ_GET_DESCRIPTOR,
+                (USB_DT_STRING << 8) | id, languages[i], sizeof(buffer), buffer);
+        if (result > 0) {
+            int i;
+            // skip first word, and copy the rest to the string, changing shorts to bytes.
+            result /= 2;
+            for (i = 1; i < result; i++)
+                string[i - 1] = buffer[i];
+            string[i - 1] = 0;
+            return strdup(string);
+        }
+    }
+
+    return NULL;
+}
+
+char* usb_device_get_manufacturer_name(struct usb_device *device)
+{
+    struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
+
+    if (desc->iManufacturer)
+        return usb_device_get_string(device, desc->iManufacturer);
+    else
+        return NULL;
+}
+
+char* usb_device_get_product_name(struct usb_device *device)
+{
+    struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
+
+    if (desc->iProduct)
+        return usb_device_get_string(device, desc->iProduct);
+    else
+        return NULL;
+}
+
+char* usb_device_get_serial(struct usb_device *device)
+{
+    struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
+
+    if (desc->iSerialNumber)
+        return usb_device_get_string(device, desc->iSerialNumber);
+    else
+        return NULL;
+}
+
+int usb_device_is_writeable(struct usb_device *device)
+{
+    return device->writeable;
+}
+
+void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter)
+{
+    iter->config = device->desc;
+    iter->config_end = device->desc + device->desc_length;
+    iter->curr_desc = device->desc;
+}
+
+struct usb_descriptor_header *usb_descriptor_iter_next(struct usb_descriptor_iter *iter)
+{
+    struct usb_descriptor_header* next;
+    if (iter->curr_desc >= iter->config_end)
+        return NULL;
+    next = (struct usb_descriptor_header*)iter->curr_desc;
+    iter->curr_desc += next->bLength;
+    return next;
+}
+
+int usb_device_claim_interface(struct usb_device *device, unsigned int interface)
+{
+    return ioctl(device->fd, USBDEVFS_CLAIMINTERFACE, &interface);
+}
+
+int usb_device_release_interface(struct usb_device *device, unsigned int interface)
+{
+    return ioctl(device->fd, USBDEVFS_RELEASEINTERFACE, &interface);
+}
+
+struct usb_endpoint *usb_endpoint_open(struct usb_device *dev,
+        const struct usb_endpoint_descriptor *desc)
+{
+    struct usb_endpoint *ep = calloc(1, sizeof(struct usb_endpoint));
+    memcpy(&ep->desc, desc, sizeof(ep->desc));
+    ep->dev = dev;
+    return ep;
+}
+
+void usb_endpoint_close(struct usb_endpoint *ep)
+{
+    // cancel IO here?
+    free(ep);
+}
+
+int usb_endpoint_queue(struct usb_endpoint *ep, void *data, int len)
+{
+    struct usbdevfs_urb *urb = &ep->urb;
+    int res;
+
+    D("usb_endpoint_queue\n");
+    memset(urb, 0, sizeof(*urb));
+    urb->type = USBDEVFS_URB_TYPE_BULK;
+    urb->endpoint = ep->desc.bEndpointAddress;
+    urb->status = -1;
+    urb->buffer = data;
+    urb->buffer_length = len;
+
+    do {
+        res = ioctl(ep->dev->fd, USBDEVFS_SUBMITURB, urb);
+    } while((res < 0) && (errno == EINTR));
+
+    return res;
+}
+
+int usb_endpoint_wait(struct usb_device *dev, int *out_ep_num)
+{
+    struct usbdevfs_urb *out = NULL;
+    int res;
+
+    while (1) {
+        res = ioctl(dev->fd, USBDEVFS_REAPURB, &out);
+        D("USBDEVFS_REAPURB returned %d\n", res);
+        if (res < 0) {
+            if(errno == EINTR) {
+                continue;
+            }
+            D("[ reap urb - error ]\n");
+            *out_ep_num = -1;
+        } else {
+            D("[ urb @%p status = %d, actual = %d ]\n",
+                out, out->status, out->actual_length);
+            res = out->actual_length;
+            *out_ep_num = out->endpoint;
+        }
+        break;
+    }
+    return res;
+}
+
+int usb_endpoint_cancel(struct usb_endpoint *ep)
+{
+    return ioctl(ep->dev->fd, USBDEVFS_DISCARDURB, &ep->urb);
+}
+
+struct usb_device *usb_endpoint_get_device(struct usb_endpoint *ep)
+{
+    return ep->dev;
+}
+
+int usb_endpoint_number(struct usb_endpoint *ep)
+{
+    return ep->desc.bEndpointAddress;
+}
+
+int usb_endpoint_max_packet(struct usb_endpoint *ep)
+{
+    return __le16_to_cpu(ep->desc.wMaxPacketSize);
+}
+
diff --git a/logcat/event.logtags b/logcat/event.logtags
index f146738..d41f36b 100644
--- a/logcat/event.logtags
+++ b/logcat/event.logtags
@@ -115,31 +115,20 @@
 50000 menu_item_selected (Menu type where 0 is options and 1 is context|1|5),(Menu item title|3)
 50001 menu_opened (Menu type where 0 is options and 1 is context|1|5)
 
-# Wi-Fi network state changed:
-# [31- 6] Reserved for future use
-# [ 5- 0] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
-50021 wifi_network_state_changed (network_state|1|5)
-
-# Wi-Fi supplicant state changed:
-# [31- 6] Reserved for future use
-# [ 5- 0] Supplicant state ordinal (as defined by SupplicantState)
-50022 wifi_supplicant_state_changed (supplicant_state|1|5)
-
-# Wi-Fi driver state changed:
-# [31- 1] Reserved for future use
-# [ 0- 0] Driver start (1) or stopped (0)
-50023 wifi_driver_state_changed (driver_state|1|5)
-
-# Wi-Fi interface configuration state changed:
-# [31- 1] Reserved for future use
-# [ 0- 0] Interface configuration succeeded (1) or failed (0)
-50024 wifi_interface_configuration_state_changed (IP_configuration|1|5)
-
-# Wi-Fi supplicant connection state changed:
-# [31- 2] Reserved for future use
-# [ 1- 0] Connected to supplicant (1) or disconnected from supplicant (0),
-#         or supplicant died (2)
-50025 wifi_supplicant_connection_state_changed (connected|1|5)
+# HSM wifi state change
+# Hierarchical state class name (as defined in WifiStateTracker.java)
+# Logged on every state change in the hierarchical state machine
+50021 wifi_state_changed (wifi_state|3)
+# HSM wifi event
+# [31-16] Reserved for future use
+# [15 - 0] HSM event (as defined in WifiStateTracker.java)
+# Logged when an event is handled in a hierarchical state
+50022 wifi_event_handled (wifi_event|1|5)
+# Supplicant state change
+# [31-13] Reserved for future use
+# [8 - 0] Supplicant state (as defined in SupplicantState.java)
+# Logged when the supplicant switches to a new state
+50023 wifi_supplicant_state_changed (supplicant_state|1|5)
 
 # Do not change these names without updating tag in:
 #//device/dalvik/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.c
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 5acdf77..96b68ef 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -402,8 +402,9 @@
                     "  -d              dump the log and then exit (don't block)\n"
                     "  -t <count>      print only the most recent <count> lines (implies -d)\n"
                     "  -g              get the size of the log's ring buffer and exit\n"
-                    "  -b <buffer>     request alternate ring buffer\n"
-                    "                  ('main' (default), 'radio', 'events')\n"
+                    "  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio'\n"
+                    "                  or 'events'. Multiple -b parameters are allowed and the\n"
+                    "                  results are interleaved. The default is -b main -b system.\n"
                     "  -B              output the log in binary");
 
 
diff --git a/rootdir/etc/init.goldfish.rc b/rootdir/etc/init.goldfish.rc
index 569555c..6f30843 100644
--- a/rootdir/etc/init.goldfish.rc
+++ b/rootdir/etc/init.goldfish.rc
@@ -1,3 +1,9 @@
+on early-init
+    export EXTERNAL_STORAGE /mnt/sdcard
+    mkdir /mnt/sdcard 0000 system system
+    # for backwards compatibility
+    symlink /mnt/sdcard /sdcard
+
 on boot
     setprop ARGH ARGH
     setprop net.eth0.dns1 10.0.2.3
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 1e3e2d2..fdc36c8 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -1,6 +1,9 @@
 on early-init
     start ueventd
 
+# create mountpoints
+    mkdir /mnt 0775 root system
+
 on init
 
 sysclktz 0
@@ -14,7 +17,6 @@
     export ANDROID_ROOT /system
     export ANDROID_ASSETS /system/app
     export ANDROID_DATA /data
-    export EXTERNAL_STORAGE /mnt/sdcard
     export ASEC_MOUNTPOINT /mnt/asec
     export LOOP_MOUNTPOINT /mnt/obb
     export BOOTCLASSPATH /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar
@@ -23,18 +25,12 @@
     symlink /system/etc /etc
     symlink /sys/kernel/debug /d
 
-# create mountpoints
-    mkdir /mnt 0775 root system
-    mkdir /mnt/sdcard 0000 system system
 
 # Create cgroup mount point for cpu accounting
     mkdir /acct
     mount cgroup none /acct cpuacct
     mkdir /acct/uid
 
-# Backwards Compat - XXX: Going away in G*
-    symlink /mnt/sdcard /sdcard
-
     mkdir /system
     mkdir /data 0771 system system
     mkdir /cache 0770 system cache
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index 7845eb9..05118bc 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -23,7 +23,6 @@
 /dev/android_adb          0660   adb        adb
 /dev/android_adb_enable   0660   adb        adb
 /dev/ttyMSM0              0600   bluetooth  bluetooth
-/dev/ttyHS0               0600   bluetooth  bluetooth
 /dev/uinput               0660   system     bluetooth
 /dev/alarm                0664   system     radio
 /dev/tty0                 0660   root       system
@@ -70,6 +69,7 @@
 /dev/qmi1                 0640   radio      radio
 /dev/qmi2                 0640   radio      radio
 /dev/bus/usb/*            0660   root       usb
+/dev/mtp_usb              0660   root       usb
 
 # CDMA radio interface MUX
 /dev/ts0710mux*           0640   radio      radio
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 82e6354..27cbde2 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -695,7 +695,7 @@
         out.major = FUSE_KERNEL_VERSION;
         out.minor = FUSE_KERNEL_MINOR_VERSION;
         out.max_readahead = req->max_readahead;
-        out.flags = 0;
+        out.flags = FUSE_ATOMIC_O_TRUNC;
         out.max_background = 32;
         out.congestion_threshold = 32;
         out.max_write = 256 * 1024;
diff --git a/toolbox/mount.c b/toolbox/mount.c
index 472c952..82ecc56 100644
--- a/toolbox/mount.c
+++ b/toolbox/mount.c
@@ -222,9 +222,50 @@
     return 0;
 }
 
+static int get_mounts_dev_dir(const char *arg, char **dev, char **dir)
+{
+	FILE *f;
+	char mount_dev[256];
+	char mount_dir[256];
+	char mount_type[256];
+	char mount_opts[256];
+	int mount_freq;
+	int mount_passno;
+	int match;
+
+	f = fopen("/proc/mounts", "r");
+	if (!f) {
+		fprintf(stdout, "could not open /proc/mounts\n");
+		return -1;
+	}
+
+	do {
+		match = fscanf(f, "%255s %255s %255s %255s %d %d\n",
+					   mount_dev, mount_dir, mount_type,
+					   mount_opts, &mount_freq, &mount_passno);
+		mount_dev[255] = 0;
+		mount_dir[255] = 0;
+		mount_type[255] = 0;
+		mount_opts[255] = 0;
+		if (match == 6 &&
+			(strcmp(arg, mount_dev) == 0 ||
+			 strcmp(arg, mount_dir) == 0)) {
+			*dev = strdup(mount_dev);
+			*dir = strdup(mount_dir);
+			fclose(f);
+			return 0;
+		}
+	} while (match != EOF);
+
+	fclose(f);
+	return -1;
+}
+
 int mount_main(int argc, char *argv[])
 {
 	char *type = NULL;
+	char *dev = NULL;
+	char *dir = NULL;
 	int c;
 	int loop = 0;
 
@@ -265,12 +306,19 @@
 	if (rwflag & MS_TYPE)
 		type = "none";
 
-	if (optind + 2 != argc || type == NULL) {
+	if (optind + 2 == argc) {
+		dev = argv[optind];
+		dir = argv[optind + 1];
+	} else if (optind + 1 == argc && rwflag & MS_REMOUNT) {
+		get_mounts_dev_dir(argv[optind], &dev, &dir);
+	}
+
+	if (dev == NULL || dir == NULL || type == NULL) {
 		fprintf(stderr, "Usage: %s [-r] [-w] [-o options] [-t type] "
 			"device directory\n", progname);
 		exit(1);
 	}
 
-	return do_mount(argv[optind], argv[optind + 1], type, rwflag,
-		        extra.str, loop);
+	return do_mount(dev, dir, type, rwflag, extra.str, loop);
+	/* We leak dev and dir in some cases, but we're about to exit */
 }
diff --git a/toolbox/ps.c b/toolbox/ps.c
index bc50cfa..2aa3efb 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -27,6 +27,7 @@
 #define SHOW_PRIO 1
 #define SHOW_TIME 2
 #define SHOW_POLICY 4
+#define SHOW_CPU  8
 
 static int display_flags = 0;
 
@@ -41,7 +42,7 @@
     int ppid, tty;
     unsigned wchan, rss, vss, eip;
     unsigned utime, stime;
-    int prio, nice, rtprio, sched;
+    int prio, nice, rtprio, sched, psr;
     struct passwd *pw;
     
     sprintf(statline, "/proc/%d", pid);
@@ -122,7 +123,7 @@
     nexttok(&ptr); // nswap
     nexttok(&ptr); // cnswap
     nexttok(&ptr); // exit signal
-    nexttok(&ptr); // processor
+    psr = atoi(nexttok(&ptr)); // processor
     rtprio = atoi(nexttok(&ptr)); // rt_priority
     sched = atoi(nexttok(&ptr)); // scheduling policy
     
@@ -142,7 +143,9 @@
     
     if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
         printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
-        if(display_flags&SHOW_PRIO)
+        if (display_flags & SHOW_CPU)
+            printf(" %-2d", psr);
+        if (display_flags & SHOW_PRIO)
             printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
         if (display_flags & SHOW_POLICY) {
             SchedPolicy p;
@@ -207,6 +210,8 @@
             display_flags |= SHOW_POLICY;
         } else if(!strcmp(argv[1],"-p")) {
             display_flags |= SHOW_PRIO;
+        } else if(!strcmp(argv[1],"-c")) {
+            display_flags |= SHOW_CPU;
         }  else if(isdigit(argv[1][0])){
             pidfilter = atoi(argv[1]);
         } else {
@@ -216,7 +221,8 @@
         argv++;
     }
 
-    printf("USER     PID   PPID  VSIZE  RSS   %s %s WCHAN    PC         NAME\n", 
+    printf("USER     PID   PPID  VSIZE  RSS   %s%s %s WCHAN    PC         NAME\n",
+           (display_flags&SHOW_CPU)?"CPU ":"",
            (display_flags&SHOW_PRIO)?"PRIO  NICE  RTPRI SCHED ":"",
            (display_flags&SHOW_POLICY)?"PCY " : "");
     while((de = readdir(d)) != 0){