Merge "Fix AndroidDevice.get_prop, add tests."
diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp
index cd3c7bc..6fa6c2e 100644
--- a/adb/adb_utils.cpp
+++ b/adb/adb_utils.cpp
@@ -72,16 +72,17 @@
   return result;
 }
 
-int mkdirs(const char *path)
-{
+int mkdirs(const std::string& path) {
+    // TODO: rewrite this function and merge it with the *other* mkdirs in adb.
+    std::unique_ptr<char> path_rw(strdup(path.c_str()));
     int ret;
-    char *x = (char *)path + 1;
+    char* x = path_rw.get() + 1;
 
     for(;;) {
-        x = adb_dirstart(x);
+        x = const_cast<char*>(adb_dirstart(x));
         if(x == 0) return 0;
         *x = 0;
-        ret = adb_mkdir(path, 0775);
+        ret = adb_mkdir(path_rw.get(), 0775);
         *x = OS_PATH_SEPARATOR;
         if((ret < 0) && (errno != EEXIST)) {
             return ret;
diff --git a/adb/adb_utils.h b/adb/adb_utils.h
index d1a3f5f..673aaac 100644
--- a/adb/adb_utils.h
+++ b/adb/adb_utils.h
@@ -22,7 +22,7 @@
 bool getcwd(std::string* cwd);
 bool directory_exists(const std::string& path);
 
-int mkdirs(const char *path);
+int mkdirs(const std::string& path);
 
 std::string escape_arg(const std::string& s);
 
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index f190336..d54faec 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -487,8 +487,8 @@
     const uint8_t* ptr = reinterpret_cast<const uint8_t*>(data);
 
     if (show_progress) {
-        char *x = strrchr(service, ':');
-        if(x) service = x + 1;
+        const char* x = strrchr(service, ':');
+        if (x) service = x + 1;
     }
 
     while (sz > 0) {
@@ -1496,7 +1496,7 @@
     int last_apk = -1;
     for (i = argc - 1; i >= 0; i--) {
         const char* file = argv[i];
-        char* dot = strrchr(file, '.');
+        const char* dot = strrchr(file, '.');
         if (dot && !strcasecmp(dot, ".apk")) {
             if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
                 fprintf(stderr, "Invalid APK file: %s\n", file);
@@ -1542,7 +1542,7 @@
     int first_apk = -1;
     for (i = argc - 1; i >= 0; i--) {
         const char* file = argv[i];
-        char* dot = strrchr(file, '.');
+        const char* dot = strrchr(file, '.');
         if (dot && !strcasecmp(dot, ".apk")) {
             if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
                 fprintf(stderr, "Invalid APK file: %s\n", file);
diff --git a/adb/file_sync_service.cpp b/adb/file_sync_service.cpp
index e8e9a0f..2067836 100644
--- a/adb/file_sync_service.cpp
+++ b/adb/file_sync_service.cpp
@@ -53,7 +53,7 @@
     if(name[0] != '/') return -1;
 
     for(;;) {
-        x = adb_dirstart(x);
+        x = const_cast<char*>(adb_dirstart(x));
         if(x == 0) return 0;
         *x = 0;
         if (should_use_fs_config(name)) {
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 6160923..729bbcb 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -247,10 +247,10 @@
     return p;
 }
 
-static __inline__  char*  adb_dirstop( const char*  path )
+static __inline__  const char*  adb_dirstop( const char*  path )
 {
-    char*  p  = strrchr(path, '/');
-    char*  p2 = strrchr(path, '\\');
+    const char*  p  = strrchr(path, '/');
+    const char*  p2 = strrchr(path, '\\');
 
     if ( !p )
         p = p2;
@@ -521,12 +521,12 @@
 {
 }
 
-static __inline__ char*  adb_dirstart(const char*  path)
+static __inline__ const char*  adb_dirstart(const char*  path)
 {
     return strchr(path, '/');
 }
 
-static __inline__ char*  adb_dirstop(const char*  path)
+static __inline__ const char*  adb_dirstop(const char*  path)
 {
     return strrchr(path, '/');
 }
diff --git a/adb/usb_linux.cpp b/adb/usb_linux.cpp
index e570ef5..dd22712 100644
--- a/adb/usb_linux.cpp
+++ b/adb/usb_linux.cpp
@@ -264,14 +264,12 @@
 
                             // Determine the device path
                         if (!fstat(fd, &st) && S_ISCHR(st.st_mode)) {
-                            char *slash;
-                            ssize_t link_len;
                             snprintf(pathbuf, sizeof(pathbuf), "/sys/dev/char/%d:%d",
                                      major(st.st_rdev), minor(st.st_rdev));
-                            link_len = readlink(pathbuf, link, sizeof(link) - 1);
+                            ssize_t link_len = readlink(pathbuf, link, sizeof(link) - 1);
                             if (link_len > 0) {
                                 link[link_len] = '\0';
-                                slash = strrchr(link, '/');
+                                const char* slash = strrchr(link, '/');
                                 if (slash) {
                                     snprintf(pathbuf, sizeof(pathbuf),
                                              "usb:%s", slash + 1);
diff --git a/fastboot/usb_linux.cpp b/fastboot/usb_linux.cpp
index 9078c8f..7b87907 100644
--- a/fastboot/usb_linux.cpp
+++ b/fastboot/usb_linux.cpp
@@ -26,29 +26,22 @@
  * SUCH DAMAGE.
  */
 
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <pthread.h>
-#include <ctype.h>
+#include <unistd.h>
 
 #include <linux/usbdevice_fs.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 "fastboot.h"
 #include "usb.h"
@@ -69,9 +62,19 @@
 #define DBG1(x...)
 #endif
 
-/* The max bulk size for linux is 16384 which is defined
- * in drivers/usb/core/devio.c.
- */
+// Kernels before 3.3 have a 16KiB transfer limit. That limit was replaced
+// with a 16MiB global limit in 3.3, but each URB submitted required a
+// contiguous kernel allocation, so you would get ENOMEM if you tried to
+// send something larger than the biggest available contiguous kernel
+// memory region. 256KiB contiguous allocations are generally not reliable
+// on a device kernel that has been running for a while fragmenting its
+// memory, but that shouldn't be a problem for fastboot on the host.
+// In 3.6, the contiguous buffer limit was removed by allocating multiple
+// 16KiB chunks and having the USB driver stitch them back together while
+// transmitting using a scatter-gather list, so 256KiB bulk transfers should
+// be reliable.
+// 256KiB seems to work, but 1MiB bulk transfers lock up my z620 with a 3.13
+// kernel.
 #define MAX_USBFS_BULK_SIZE (16 * 1024)
 
 struct usb_handle
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c
index 1316339..5f6f8f9 100644
--- a/libcutils/fs_config.c
+++ b/libcutils/fs_config.c
@@ -118,6 +118,7 @@
     { 00550, AID_DHCP,      AID_SHELL,     0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
     { 00555, AID_ROOT,      AID_ROOT,      0, "system/etc/ppp/*" },
     { 00555, AID_ROOT,      AID_ROOT,      0, "system/etc/rc.*" },
+    { 00440, AID_ROOT,      AID_ROOT,      0, "system/etc/recovery.img" },
     { 00444, AID_ROOT,      AID_ROOT,      0, conf_dir + 1 },
     { 00444, AID_ROOT,      AID_ROOT,      0, conf_file + 1 },
     { 00644, AID_SYSTEM,    AID_SYSTEM,    0, "data/app/*" },
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 893c0dc..5b657bb 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -264,7 +264,7 @@
      * buffer at the same time.  This allows us to share the underlying storage. */
     union {
         __u8 request_buffer[MAX_REQUEST_SIZE];
-        __u8 read_buffer[MAX_READ + PAGESIZE];
+        __u8 read_buffer[MAX_READ + PAGE_SIZE];
     };
 };
 
@@ -1282,7 +1282,7 @@
     __u32 size = req->size;
     __u64 offset = req->offset;
     int res;
-    __u8 *read_buffer = (__u8 *) ((uintptr_t)(handler->read_buffer + PAGESIZE) & ~((uintptr_t)PAGESIZE-1));
+    __u8 *read_buffer = (__u8 *) ((uintptr_t)(handler->read_buffer + PAGE_SIZE) & ~((uintptr_t)PAGE_SIZE-1));
 
     /* Don't access any other fields of hdr or req beyond this point, the read buffer
      * overlaps the request buffer and will clobber data in the request.  This
@@ -1308,7 +1308,7 @@
     struct fuse_write_out out;
     struct handle *h = id_to_ptr(req->fh);
     int res;
-    __u8 aligned_buffer[req->size] __attribute__((__aligned__(PAGESIZE)));
+    __u8 aligned_buffer[req->size] __attribute__((__aligned__(PAGE_SIZE)));
 
     if (req->flags & O_DIRECT) {
         memcpy(aligned_buffer, buffer, req->size);