Merge "NetlinkEvents: adding support for iptables' quota2 NFLOG messages."
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
index 28ba80d..2effb12 100644
--- a/adb/usb_vendors.c
+++ b/adb/usb_vendors.c
@@ -97,6 +97,8 @@
 #define VENDOR_ID_COMPAL        0x1219
 // T & A Mobile Phones' USB Vendor ID
 #define VENDOR_ID_T_AND_A       0x1BBB
+// Lenovo's USB Vendor ID
+#define VENDOR_ID_LENOVO        0x2006
 
 
 /** built-in vendor list */
@@ -132,6 +134,7 @@
     VENDOR_ID_IRIVER,
     VENDOR_ID_COMPAL,
     VENDOR_ID_T_AND_A,
+    VENDOR_ID_LENOVO,
 };
 
 #define BUILT_IN_VENDOR_COUNT    (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
diff --git a/include/system/window.h b/include/system/window.h
index edb3002..4d519c5 100644
--- a/include/system/window.h
+++ b/include/system/window.h
@@ -153,6 +153,64 @@
      * likely be removed in the near future.
      */
     NATIVE_WINDOW_CONCRETE_TYPE = 5,
+
+
+    /*
+     * Default width and height of the ANativeWindow, these are the dimensions
+     * of the window irrespective of the NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
+     * call.
+     */
+    NATIVE_WINDOW_DEFAULT_WIDTH = 6,
+    NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
+
+    /*
+     * transformation that will most-likely be applied to buffers. This is only
+     * a hint, the actual transformation applied might be different.
+     *
+     * INTENDED USE:
+     *
+     * The transform hint can be used by a producer, for instance the GLES
+     * driver, to pre-rotate the rendering such that the final transformation
+     * in the composer is identity. This can be very useful when used in
+     * conjunction with the h/w composer HAL, in situations where it
+     * cannot handle arbitrary rotations.
+     *
+     * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
+     *    queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
+     *
+     * 2. The GL driver overrides the width and height of the ANW to
+     *    account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
+     *    NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
+     *    according to NATIVE_WINDOW_TRANSFORM_HINT and calling
+     *    native_window_set_buffers_dimensions().
+     *
+     * 3. The GL driver dequeues a buffer of the new pre-rotated size.
+     *
+     * 4. The GL driver renders to the buffer such that the image is
+     *    already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
+     *    to the rendering.
+     *
+     * 5. The GL driver calls native_window_set_transform to apply
+     *    inverse transformation to the buffer it just rendered.
+     *    In order to do this, the GL driver needs
+     *    to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
+     *    done easily:
+     *
+     *        int hintTransform, inverseTransform;
+     *        query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
+     *        inverseTransform = hintTransform;
+     *        if (hintTransform & HAL_TRANSFORM_ROT_90)
+     *            inverseTransform ^= HAL_TRANSFORM_ROT_180;
+     *
+     *
+     * 6. The GL driver queues the pre-transformed buffer.
+     *
+     * 7. The composer combines the buffer transform with the display
+     *    transform.  If the buffer transform happens to cancel out the
+     *    display transform then no rotation is needed.
+     *
+     */
+    NATIVE_WINDOW_TRANSFORM_HINT = 8,
 };
 
 /* valid operations for the (*perform)() hook */
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 8dd858f..0d476d4 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -159,6 +159,11 @@
     # create dalvik-cache, so as to enforce our permissions
     mkdir /data/dalvik-cache 0771 system system
 
+    # create resource-cache and double-check the perms
+    mkdir /data/resource-cache 0771 system system
+    chown system system /data/resource-cache
+    chmod 0771 /data/resource-cache
+
     # create the lost+found directories, so as to enforce our permissions
     mkdir /data/lost+found 0770 root root
 
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index bd00311..689cd2a 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -756,7 +756,7 @@
         h->fd = open(path, req->flags);
         if (h->fd < 0) {
             ERROR("ERROR\n");
-            fuse_status(fuse, hdr->unique, errno);
+            fuse_status(fuse, hdr->unique, -errno);
             free(h);
             return;
         }
@@ -778,7 +778,7 @@
         }
         res = pread64(h->fd, buffer, req->size, req->offset);
         if (res < 0) {
-            fuse_status(fuse, hdr->unique, errno);
+            fuse_status(fuse, hdr->unique, -errno);
             return;
         }
         fuse_reply(fuse, hdr->unique, buffer, res);
@@ -792,7 +792,7 @@
         TRACE("WRITE %p(%d) %u@%llu\n", h, h->fd, req->size, req->offset);
         res = pwrite64(h->fd, ((char*) data) + sizeof(*req), req->size, req->offset);
         if (res < 0) {
-            fuse_status(fuse, hdr->unique, errno);
+            fuse_status(fuse, hdr->unique, -errno);
             return;
         }
         out.size = res;
diff --git a/toolbox/ls.c b/toolbox/ls.c
index b08e378..bee365c 100644
--- a/toolbox/ls.c
+++ b/toolbox/ls.c
@@ -24,6 +24,7 @@
 #define LIST_DIRECTORIES    (1 << 3)
 #define LIST_SIZE           (1 << 4)
 #define LIST_LONG_NUMERIC   (1 << 5)
+#define LIST_CLASSIFY       (1 << 6)
 
 // fwd
 static int listpath(const char *name, int flags);
@@ -133,7 +134,27 @@
     }
 
     /* blocks are 512 bytes, we want output to be KB */
-    printf("%lld %s\n", s.st_blocks / 2, filename);
+    if ((flags & LIST_SIZE) != 0) {
+        printf("%lld ", s.st_blocks / 2);
+    }
+
+    if ((flags & LIST_CLASSIFY) != 0) {
+        char filetype = mode2kind(s.st_mode);
+        if (filetype != 'l') {
+            printf("%c ", filetype);
+        } else {
+            struct stat link_dest;
+            if (!stat(path, &link_dest)) {
+                printf("l%c ", mode2kind(link_dest.st_mode));
+            } else {
+                fprintf(stderr, "stat '%s' failed: %s\n", path, strerror(errno));
+                printf("l? ");
+            }
+        }
+    }
+
+    printf("%s\n", filename);
+
     return 0;
 }
 
@@ -215,7 +236,7 @@
 
 static int listfile(const char *dirname, const char *filename, int flags)
 {
-    if ((flags & (LIST_LONG | LIST_SIZE)) == 0) {
+    if ((flags & (LIST_LONG | LIST_SIZE | LIST_CLASSIFY)) == 0) {
         printf("%s\n", filename);
         return 0;
     }
@@ -366,6 +387,7 @@
                     case 'R': flags |= LIST_RECURSIVE; break;
                     case 'd': flags |= LIST_DIRECTORIES; break;
                     case 'a': flags |= LIST_ALL; break;
+                    case 'F': flags |= LIST_CLASSIFY; break;
                     default:
                         fprintf(stderr, "%s: Unknown option '-%c'. Aborting.\n", "ls", arg[0]);
                         exit(1);
diff --git a/toolbox/umount.c b/toolbox/umount.c
index 6eb8b92..890e870 100644
--- a/toolbox/umount.c
+++ b/toolbox/umount.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <linux/loop.h>
+#include <errno.h>
 
 #define LOOPDEV_MAXLEN 64
 #define LOOP_MAJOR 7
@@ -36,7 +37,7 @@
     
     f = fopen("/proc/mounts", "r");
     if (!f) {
-        fprintf(stdout, "could not open /proc/mounts\n");
+        fprintf(stdout, "could not open /proc/mounts: %s\n", strerror(errno));
         return -1;
     }
 
@@ -66,8 +67,8 @@
     }
 
     loop = is_loop_mount(argv[1], loopdev);
-    if(umount(argv[1])){
-        fprintf(stderr,"failed.\n");
+    if (umount(argv[1])) {
+        fprintf(stderr, "failed: %s\n", strerror(errno));
         return 1;
     }
 
@@ -75,11 +76,11 @@
         // free the loop device
         loop_fd = open(loopdev, O_RDONLY);
         if (loop_fd < 0) {
-            perror("open loop device failed");
+            fprintf(stderr, "open loop device failed: %s\n", strerror(errno));
             return 1;
         }
         if (ioctl(loop_fd, LOOP_CLR_FD, 0) < 0) {
-            perror("ioctl LOOP_CLR_FD failed");
+            fprintf(stderr, "ioctl LOOP_CLR_FD failed: %s\n", strerror(errno));
             return 1;
         }