Merge "toolbox: nandread: Add options to extract raw images, partial images, and fix bad block check."
diff --git a/adb/Android.mk b/adb/Android.mk
index f3eaa6e..6325e53 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -25,6 +25,12 @@
LOCAL_LDLIBS += -lpthread -framework CoreFoundation -framework IOKit -framework Carbon
endif
+ifeq ($(HOST_OS),freebsd)
+ USB_SRCS := usb_libusb.c
+ EXTRA_SRCS := get_my_path_freebsd.c
+ LOCAL_LDLIBS += -lpthread -lusb
+endif
+
ifeq ($(HOST_OS),windows)
USB_SRCS := usb_windows.c
EXTRA_SRCS := get_my_path_windows.c
diff --git a/adb/adb.c b/adb/adb.c
index c1646b8..a34dd71 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -783,7 +783,7 @@
fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
return -1;
}
- get_my_path(path);
+ get_my_path(path, PATH_MAX);
pid_t pid = fork();
if(pid < 0) return -1;
@@ -895,9 +895,10 @@
** AID_GRAPHICS to access the frame buffer
** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
** AID_SDCARD_RW to allow writing to the SD card
+ ** AID_MOUNT to allow unmounting the SD card before rebooting
*/
gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
- AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_RW };
+ AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_RW, AID_MOUNT };
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
/* then switch user and group to "shell" */
diff --git a/adb/adb.h b/adb/adb.h
index b958682..a148019 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -236,7 +236,7 @@
void handle_packet(apacket *p, atransport *t);
void send_packet(apacket *p, atransport *t);
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
int launch_server();
int adb_main(int is_daemon);
diff --git a/adb/commandline.c b/adb/commandline.c
index 0edd1e1..857cee3 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -50,7 +50,7 @@
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
int find_sync_dirs(const char *srcarg,
char **android_srcdir_out, char **data_srcdir_out);
int install_app(transport_type transport, char* serial, int argc, char** argv);
@@ -105,12 +105,12 @@
" environment variable is used, which must\n"
" be an absolute path.\n"
" devices - list all connected devices\n"
- " connect <host>:<port> - connect to a device via TCP/IP"
- " disconnect <host>:<port> - disconnect from a TCP/IP device"
+ " connect <host>:<port> - connect to a device via TCP/IP\n"
+ " disconnect <host>:<port> - disconnect from a TCP/IP device\n"
"\n"
"device commands:\n"
" adb push <local> <remote> - copy file/dir to device\n"
- " adb pull <remote> <local> - copy file/dir from device\n"
+ " adb pull <remote> [<local>] - copy file/dir from device\n"
" adb sync [ <directory> ] - copy host->device only if changed\n"
" (see 'adb help all')\n"
" adb shell - run remote shell interactively\n"
@@ -126,9 +126,10 @@
" dev:<character device name>\n"
" jdwp:<process pid> (remote only)\n"
" adb jdwp - list PIDs of processes hosting a JDWP transport\n"
- " adb install [-l] [-r] <file> - push this package file to the device and install it\n"
+ " adb install [-l] [-r] [-s] <file> - push this package file to the device and install it\n"
" ('-l' means forward-lock the app)\n"
" ('-r' means reinstall the app, keeping its data)\n"
+ " ('-s' means install on SD card instead of internal storage)\n"
" adb uninstall [-k] <package> - remove this app package from the device\n"
" ('-k' means keep the data and cache directories)\n"
" adb bugreport - return all information from the device\n"
@@ -151,8 +152,9 @@
" adb status-window - continuously print device status for a specified device\n"
" adb remount - remounts the /system partition on the device read-write\n"
" adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program\n"
+ " adb reboot-bootloader - reboots the device into the bootloader\n"
" adb root - restarts the adbd daemon with root permissions\n"
- " adb usb - restarts the adbd daemon listening on USB"
+ " adb usb - restarts the adbd daemon listening on USB\n"
" adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port"
"\n"
"networking:\n"
@@ -219,8 +221,8 @@
if(errno == EINTR) continue;
break;
}
- /* we want to output to stdout, so no adb_write here !! */
- unix_write(1, buf, len);
+ fwrite(buf, 1, len, stdout);
+ fflush(stdout);
}
}
@@ -673,7 +675,7 @@
/* If the CWD isn't under a good-looking top, see if the
* executable is.
*/
- get_my_path(dir);
+ get_my_path(dir, PATH_MAX);
top = find_top_from(dir, path_buf);
}
return top;
@@ -929,10 +931,13 @@
}
if(!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot")
+ || !strcmp(argv[0], "reboot-bootloader")
|| !strcmp(argv[0], "tcpip") || !strcmp(argv[0], "usb")
|| !strcmp(argv[0], "root")) {
char command[100];
- if (argc > 1)
+ if (!strcmp(argv[0], "reboot-bootloader"))
+ snprintf(command, sizeof(command), "reboot:bootloader");
+ else if (argc > 1)
snprintf(command, sizeof(command), "%s:%s", argv[0], argv[1]);
else
snprintf(command, sizeof(command), "%s:", argv[0]);
@@ -947,10 +952,8 @@
}
if(!strcmp(argv[0], "bugreport")) {
- if (argc != 1) {
- return 1;
- }
- do_cmd(ttype, serial, "shell", "dumpstate", "-", 0);
+ if (argc != 1) return usage();
+ do_cmd(ttype, serial, "shell", "bugreport", 0);
return 0;
}
@@ -990,9 +993,13 @@
if(!strcmp(argv[0], "forward")) {
if(argc != 3) return usage();
if (serial) {
- snprintf(buf, sizeof buf, "host-serial:%s:forward:%s;%s",serial,argv[1],argv[2]);
+ snprintf(buf, sizeof buf, "host-serial:%s:forward:%s;%s",serial, argv[1], argv[2]);
+ } else if (ttype == kTransportUsb) {
+ snprintf(buf, sizeof buf, "host-usb:forward:%s;%s", argv[1], argv[2]);
+ } else if (ttype == kTransportLocal) {
+ snprintf(buf, sizeof buf, "host-local:forward:%s;%s", argv[1], argv[2]);
} else {
- snprintf(buf, sizeof buf, "host:forward:%s;%s",argv[1],argv[2]);
+ snprintf(buf, sizeof buf, "host:forward:%s;%s", argv[1], argv[2]);
}
if(adb_command(buf)) {
fprintf(stderr,"error: %s\n", adb_error());
@@ -1014,8 +1021,13 @@
}
if(!strcmp(argv[0], "pull")) {
- if(argc != 3) return usage();
- return do_sync_pull(argv[1], argv[2]);
+ if (argc == 2) {
+ return do_sync_pull(argv[1], ".");
+ } else if (argc == 3) {
+ return do_sync_pull(argv[1], argv[2]);
+ } else {
+ return usage();
+ }
}
if(!strcmp(argv[0], "install")) {
@@ -1244,17 +1256,25 @@
{
struct stat st;
int err;
- const char *const WHERE = "/data/local/tmp/%s";
+ const char *const DATA_DEST = "/data/local/tmp/%s";
+ const char *const SD_DEST = "/sdcard/tmp/%s";
+ const char* where = DATA_DEST;
char to[PATH_MAX];
char* filename = argv[argc - 1];
const char* p;
+ int i;
+
+ for (i = 0; i < argc; i++) {
+ if (!strcmp(argv[i], "-s"))
+ where = SD_DEST;
+ }
p = adb_dirstop(filename);
if (p) {
p++;
- snprintf(to, sizeof to, WHERE, p);
+ snprintf(to, sizeof to, where, p);
} else {
- snprintf(to, sizeof to, WHERE, filename);
+ snprintf(to, sizeof to, where, filename);
}
if (p[0] == '\0') {
}
diff --git a/adb/get_my_path_darwin.c b/adb/get_my_path_darwin.c
index 6125cb4..5b95d15 100644
--- a/adb/get_my_path_darwin.c
+++ b/adb/get_my_path_darwin.c
@@ -17,7 +17,7 @@
#import <Carbon/Carbon.h>
#include <unistd.h>
-void get_my_path(char s[PATH_MAX])
+void get_my_path(char *s, size_t maxLen)
{
ProcessSerialNumber psn;
GetCurrentProcess(&psn);
@@ -25,6 +25,6 @@
dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict,
CFSTR("CFBundleExecutable"));
- CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8);
+ CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8);
}
diff --git a/adb/get_my_path_freebsd.c b/adb/get_my_path_freebsd.c
new file mode 100644
index 0000000..b06ec66
--- /dev/null
+++ b/adb/get_my_path_freebsd.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009 bsdroid project
+ * Alexey Tarasov <tarasov@dodologics.com>
+ *
+ * Copyright (C) 2007 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.
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <limits.h>
+#include <stdio.h>
+
+void
+get_my_path(char *exe, size_t maxLen)
+{
+ char proc[64];
+
+ snprintf(proc, sizeof(proc), "/proc/%d/file", getpid());
+
+ int err = readlink(proc, exe, maxLen - 1);
+
+ exe[err > 0 ? err : 0] = '\0';
+}
+
diff --git a/adb/get_my_path_linux.c b/adb/get_my_path_linux.c
index f516e59..179c3dd 100644
--- a/adb/get_my_path_linux.c
+++ b/adb/get_my_path_linux.c
@@ -19,15 +19,15 @@
#include <limits.h>
#include <stdio.h>
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
{
char proc[64];
snprintf(proc, sizeof proc, "/proc/%d/exe", getpid());
- int err = readlink(proc, exe, PATH_MAX - 1);
+ int err = readlink(proc, exe, maxLen - 1);
if(err > 0) {
- exe[err] = 0;
+ exe[err] = '\0';
} else {
- exe[0] = 0;
+ exe[0] = '\0';
}
}
diff --git a/adb/get_my_path_windows.c b/adb/get_my_path_windows.c
index fc7143c..ddf2816 100644
--- a/adb/get_my_path_windows.c
+++ b/adb/get_my_path_windows.c
@@ -18,14 +18,17 @@
#include <assert.h>
#include <windows.h>
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
{
- char* r;
+ char *r;
- GetModuleFileName( NULL, exe, PATH_MAX-1 );
- exe[PATH_MAX-1] = 0;
- r = strrchr( exe, '\\' );
- if (r)
- *r = 0;
+ /* XXX: should be GetModuleFileNameA */
+ if (GetModuleFileName(NULL, exe, maxLen) > 0) {
+ r = strrchr(exe, '\\');
+ if (r != NULL)
+ *r = '\0';
+ } else {
+ exe[0] = '\0';
+ }
}
diff --git a/adb/services.c b/adb/services.c
index b5df554..487c7d3 100644
--- a/adb/services.c
+++ b/adb/services.c
@@ -176,9 +176,23 @@
void reboot_service(int fd, void *arg)
{
char buf[100];
- int ret;
+ int pid, ret;
sync();
+
+ /* Attempt to unmount the SD card first.
+ * No need to bother checking for errors.
+ */
+ pid = fork();
+ if (pid == 0) {
+ /* ask vdc to unmount it */
+ execl("/system/bin/vdc", "/system/bin/vdc", "volume", "unmount",
+ getenv("EXTERNAL_STORAGE"), "force", NULL);
+ } else if (pid > 0) {
+ /* wait until vdc succeeds or fails */
+ waitpid(pid, &ret, 0);
+ }
+
ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_RESTART2, (char *)arg);
if (ret < 0) {
diff --git a/adb/usb_libusb.c b/adb/usb_libusb.c
new file mode 100644
index 0000000..8c75266
--- /dev/null
+++ b/adb/usb_libusb.c
@@ -0,0 +1,657 @@
+/*
+ * Copyright (C) 2009 bsdroid project
+ * Alexey Tarasov <tarasov@dodologics.com>
+ *
+ * Copyright (C) 2007 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.
+ */
+
+#include <sys/endian.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#include <err.h>
+#include <errno.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+#include <libusb.h>
+#include "sysdeps.h"
+
+#define TRACE_TAG TRACE_USB
+#include "adb.h"
+
+static adb_mutex_t usb_lock = ADB_MUTEX_INITIALIZER;
+static libusb_context *ctx = NULL;
+
+struct usb_handle
+{
+ usb_handle *prev;
+ usb_handle *next;
+
+ libusb_device *dev;
+ libusb_device_handle *devh;
+ int interface;
+ uint8_t dev_bus;
+ uint8_t dev_addr;
+
+ int zero_mask;
+ unsigned char end_point_address[2];
+ char serial[128];
+
+ adb_cond_t notify;
+ adb_mutex_t lock;
+};
+
+static struct usb_handle handle_list = {
+ .prev = &handle_list,
+ .next = &handle_list,
+};
+
+void
+usb_cleanup()
+{
+ libusb_exit(ctx);
+}
+
+void
+report_bulk_libusb_error(int r)
+{
+ switch (r) {
+ case LIBUSB_ERROR_TIMEOUT:
+ D("Transfer timeout\n");
+ break;
+
+ case LIBUSB_ERROR_PIPE:
+ D("Control request is not supported\n");
+ break;
+
+ case LIBUSB_ERROR_OVERFLOW:
+ D("Device offered more data\n");
+ break;
+
+ case LIBUSB_ERROR_NO_DEVICE :
+ D("Device was disconnected\n");
+ break;
+
+ default:
+ D("Error %d during transfer\n", r);
+ break;
+ };
+}
+
+static int
+usb_bulk_write(usb_handle *uh, const void *data, int len)
+{
+ int r = 0;
+ int transferred = 0;
+
+ r = libusb_bulk_transfer(uh->devh, uh->end_point_address[1], (void *)data, len,
+ &transferred, 0);
+
+ if (r != 0) {
+ D("usb_bulk_write(): ");
+ report_bulk_libusb_error(r);
+ return r;
+ }
+
+ return (transferred);
+}
+
+static int
+usb_bulk_read(usb_handle *uh, void *data, int len)
+{
+ int r = 0;
+ int transferred = 0;
+
+ r = libusb_bulk_transfer(uh->devh, uh->end_point_address[0], data, len,
+ &transferred, 0);
+
+ if (r != 0) {
+ D("usb_bulk_read(): ");
+ report_bulk_libusb_error(r);
+ return r;
+ }
+
+ return (transferred);
+}
+
+int
+usb_write(struct usb_handle *uh, const void *_data, int len)
+{
+ unsigned char *data = (unsigned char*) _data;
+ int n;
+ int need_zero = 0;
+
+ if (uh->zero_mask == 1) {
+ if (!(len & uh->zero_mask)) {
+ need_zero = 1;
+ }
+ }
+
+ D("usb_write(): %p:%d -> transport %p\n", _data, len, uh);
+
+ while (len > 0) {
+ int xfer = (len > 4096) ? 4096 : len;
+
+ n = usb_bulk_write(uh, data, xfer);
+
+ if (n != xfer) {
+ D("usb_write(): failed for transport %p (%d bytes left)\n", uh, len);
+ return -1;
+ }
+
+ len -= xfer;
+ data += xfer;
+ }
+
+ if (need_zero){
+ n = usb_bulk_write(uh, _data, 0);
+
+ if (n < 0) {
+ D("usb_write(): failed to finish operation for transport %p\n", uh);
+ }
+ return n;
+ }
+
+ return 0;
+}
+
+int
+usb_read(struct usb_handle *uh, void *_data, int len)
+{
+ unsigned char *data = (unsigned char*) _data;
+ int n;
+
+ D("usb_read(): %p:%d <- transport %p\n", _data, len, uh);
+
+ while (len > 0) {
+ int xfer = (len > 4096) ? 4096 : len;
+
+ n = usb_bulk_read(uh, data, xfer);
+
+ if (n != xfer) {
+ if (n > 0) {
+ data += n;
+ len -= n;
+ continue;
+ }
+
+ D("usb_read(): failed for transport %p (%d bytes left)\n", uh, len);
+ return -1;
+ }
+
+ len -= xfer;
+ data += xfer;
+ }
+
+ return 0;
+ }
+
+int
+usb_close(struct usb_handle *h)
+{
+ D("usb_close(): closing transport %p\n", h);
+ adb_mutex_lock(&usb_lock);
+
+ h->next->prev = h->prev;
+ h->prev->next = h->next;
+ h->prev = NULL;
+ h->next = NULL;
+
+ libusb_release_interface(h->devh, h->interface);
+ libusb_close(h->devh);
+ libusb_unref_device(h->dev);
+
+ adb_mutex_unlock(&usb_lock);
+
+ free(h);
+
+ return (0);
+}
+
+void usb_kick(struct usb_handle *h)
+{
+ D("usb_cick(): kicking transport %p\n", h);
+
+ adb_mutex_lock(&h->lock);
+ unregister_usb_transport(h);
+ adb_mutex_unlock(&h->lock);
+
+ h->next->prev = h->prev;
+ h->prev->next = h->next;
+ h->prev = NULL;
+ h->next = NULL;
+
+ libusb_release_interface(h->devh, h->interface);
+ libusb_close(h->devh);
+ libusb_unref_device(h->dev);
+ free(h);
+}
+
+int
+check_usb_interface(libusb_interface *interface,
+ libusb_device_descriptor *desc,
+ struct usb_handle *uh)
+{
+ int e;
+
+ if (interface->num_altsetting == 0) {
+ D("check_usb_interface(): No interface settings\n");
+ return -1;
+ }
+
+ libusb_interface_descriptor *idesc = &interface->altsetting[0];
+
+ if (idesc->bNumEndpoints != 2) {
+ D("check_usb_interface(): Interface have not 2 endpoints, ignoring\n");
+ return -1;
+ }
+
+ for (e = 0; e < idesc->bNumEndpoints; e++) {
+ libusb_endpoint_descriptor *edesc = &idesc->endpoint[e];
+
+ if (edesc->bmAttributes != LIBUSB_TRANSFER_TYPE_BULK) {
+ D("check_usb_interface(): Endpoint (%u) is not bulk (%u), ignoring\n",
+ edesc->bmAttributes, LIBUSB_TRANSFER_TYPE_BULK);
+ return -1;
+ }
+
+ if (edesc->bEndpointAddress & LIBUSB_ENDPOINT_IN)
+ uh->end_point_address[0] = edesc->bEndpointAddress;
+ else
+ uh->end_point_address[1] = edesc->bEndpointAddress;
+
+ /* aproto 01 needs 0 termination */
+ if (idesc->bInterfaceProtocol == 0x01) {
+ uh->zero_mask = edesc->wMaxPacketSize - 1;
+ D("check_usb_interface(): Forced Android interface protocol v.1\n");
+ }
+ }
+
+ D("check_usb_interface(): Device: %04x:%04x "
+ "iclass: %x, isclass: %x, iproto: %x ep: %x/%x-> ",
+ desc->idVendor, desc->idProduct, idesc->bInterfaceClass,
+ idesc->bInterfaceSubClass, idesc->bInterfaceProtocol,
+ uh->end_point_address[0], uh->end_point_address[1]);
+
+ if (!is_adb_interface(desc->idVendor, desc->idProduct,
+ idesc->bInterfaceClass, idesc->bInterfaceSubClass,
+ idesc->bInterfaceProtocol))
+ {
+ D("not matches\n");
+ return -1;
+ }
+
+ D("matches\n");
+ return 1;
+}
+
+int
+check_usb_interfaces(libusb_config_descriptor *config,
+ libusb_device_descriptor *desc, struct usb_handle *uh)
+{
+ int i;
+
+ for (i = 0; i < config->bNumInterfaces; ++i) {
+ if (check_usb_interface(&config->interface[i], desc, uh) != -1) {
+ /* found some interface and saved information about it */
+ D("check_usb_interfaces(): Interface %d of %04x:%04x "
+ "matches Android device\n", i, desc->idVendor,
+ desc->idProduct);
+
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+int
+register_device(struct usb_handle *uh, const char *serial)
+{
+ D("register_device(): Registering %p [%s] as USB transport\n",
+ uh, serial);
+
+ struct usb_handle *usb= NULL;
+
+ usb = calloc(1, sizeof(struct usb_handle));
+ memcpy(usb, uh, sizeof(struct usb_handle));
+ strcpy(usb->serial, uh->serial);
+
+ adb_cond_init(&usb->notify, 0);
+ adb_mutex_init(&usb->lock, 0);
+
+ adb_mutex_lock(&usb_lock);
+
+ usb->next = &handle_list;
+ usb->prev = handle_list.prev;
+ usb->prev->next = usb;
+ usb->next->prev = usb;
+
+ adb_mutex_unlock(&usb_lock);
+
+ register_usb_transport(usb, serial, 1);
+
+ return (1);
+}
+
+int
+already_registered(usb_handle *uh)
+{
+ struct usb_handle *usb= NULL;
+ int exists = 0;
+
+ adb_mutex_lock(&usb_lock);
+
+ for (usb = handle_list.next; usb != &handle_list; usb = usb->next) {
+ if ((usb->dev_bus == uh->dev_bus) &&
+ (usb->dev_addr == uh->dev_addr))
+ {
+ exists = 1;
+ break;
+ }
+ }
+
+ adb_mutex_unlock(&usb_lock);
+
+ return exists;
+}
+
+void
+check_device(libusb_device *dev)
+{
+ struct usb_handle uh;
+ int i = 0;
+ int found = -1;
+ char serial[256] = {0};
+
+ libusb_device_descriptor desc;
+ libusb_config_descriptor *config = NULL;
+
+ int r = libusb_get_device_descriptor(dev, &desc);
+
+ if (r != LIBUSB_SUCCESS) {
+ D("check_device(): Failed to get device descriptor\n");
+ return;
+ }
+
+ if ((desc.idVendor == 0) && (desc.idProduct == 0))
+ return;
+
+ D("check_device(): Probing usb device %04x:%04x\n",
+ desc.idVendor, desc.idProduct);
+
+ if (!is_adb_interface (desc.idVendor, desc.idProduct,
+ ADB_CLASS, ADB_SUBCLASS, ADB_PROTOCOL))
+ {
+ D("check_device(): Ignored due unknown vendor id\n");
+ return;
+ }
+
+ uh.dev_bus = libusb_get_bus_number(dev);
+ uh.dev_addr = libusb_get_device_address(dev);
+
+ if (already_registered(&uh)) {
+ D("check_device(): Device (bus: %d, address: %d) "
+ "is already registered\n", uh.dev_bus, uh.dev_addr);
+ return;
+ }
+
+ D("check_device(): Device bus: %d, address: %d\n",
+ uh.dev_bus, uh.dev_addr);
+
+ r = libusb_get_active_config_descriptor(dev, &config);
+
+ if (r != 0) {
+ if (r == LIBUSB_ERROR_NOT_FOUND) {
+ D("check_device(): Device %4x:%4x is unconfigured\n",
+ desc.idVendor, desc.idProduct);
+ return;
+ }
+
+ D("check_device(): Failed to get configuration for %4x:%4x\n",
+ desc.idVendor, desc.idProduct);
+ return;
+ }
+
+ if (config == NULL) {
+ D("check_device(): Sanity check failed after "
+ "getting active config\n");
+ return;
+ }
+
+ if (config->interface != NULL) {
+ found = check_usb_interfaces(config, &desc, &uh);
+ }
+
+ /* not needed anymore */
+ libusb_free_config_descriptor(config);
+
+ r = libusb_open(dev, &uh.devh);
+ uh.dev = dev;
+
+ if (r != 0) {
+ switch (r) {
+ case LIBUSB_ERROR_NO_MEM:
+ D("check_device(): Memory allocation problem\n");
+ break;
+
+ case LIBUSB_ERROR_ACCESS:
+ D("check_device(): Permissions problem, "
+ "current user priveleges are messed up?\n");
+ break;
+
+ case LIBUSB_ERROR_NO_DEVICE:
+ D("check_device(): Device disconected, bad cable?\n");
+ break;
+
+ default:
+ D("check_device(): libusb triggered error %d\n", r);
+ }
+ // skip rest
+ found = -1;
+ }
+
+ if (found >= 0) {
+ D("check_device(): Device matches Android interface\n");
+ // read the device's serial number
+ memset(serial, 0, sizeof(serial));
+ uh.interface = found;
+
+ r = libusb_claim_interface(uh.devh, uh.interface);
+
+ if (r < 0) {
+ D("check_device(): Failed to claim interface %d\n",
+ uh.interface);
+
+ goto fail;
+ }
+
+ if (desc.iSerialNumber) {
+ // reading serial
+ uint16_t buffer[128] = {0};
+ uint16_t languages[128] = {0};
+ int languageCount = 0;
+
+ memset(languages, 0, sizeof(languages));
+ r = libusb_control_transfer(uh.devh,
+ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE,
+ LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_DT_STRING << 8,
+ 0, (uint8_t *)languages, sizeof(languages), 0);
+
+ if (r <= 0) {
+ D("check_device(): Failed to get languages count\n");
+ goto fail;
+ }
+
+ languageCount = (r - 2) / 2;
+
+ for (i = 1; i <= languageCount; ++i) {
+ memset(buffer, 0, sizeof(buffer));
+
+ r = libusb_control_transfer(uh.devh,
+ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE,
+ LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc.iSerialNumber,
+ languages[i], (uint8_t *)buffer, sizeof(buffer), 0);
+
+ if (r > 0) { /* converting serial */
+ int j = 0;
+ r /= 2;
+
+ for (j = 1; j < r; ++j)
+ serial[j - 1] = buffer[j];
+
+ serial[j - 1] = '\0';
+ break; /* languagesCount cycle */
+ }
+ }
+
+ if (register_device(&uh, serial) == 0) {
+ D("check_device(): Failed to register device\n");
+ goto fail_interface;
+ }
+
+ libusb_ref_device(dev);
+ }
+ }
+
+ return;
+
+fail_interface:
+ libusb_release_interface(uh.devh, uh.interface);
+
+fail:
+ libusb_close(uh.devh);
+ uh.devh = NULL;
+}
+
+int
+check_device_connected(struct usb_handle *uh)
+{
+ int r = libusb_kernel_driver_active(uh->devh, uh->interface);
+
+ if (r == LIBUSB_ERROR_NO_DEVICE)
+ return 0;
+
+ if (r < 0)
+ return -1;
+
+ return 1;
+}
+
+void
+kick_disconnected()
+{
+ struct usb_handle *usb= NULL;
+
+ adb_mutex_lock(&usb_lock);
+
+ for (usb = handle_list.next; usb != &handle_list; usb = usb->next) {
+
+ if (check_device_connected(usb) == 0) {
+ D("kick_disconnected(): Transport %p is not online anymore\n",
+ usb);
+
+ usb_kick(usb);
+ }
+ }
+
+ adb_mutex_unlock(&usb_lock);
+}
+
+void
+scan_usb_devices()
+{
+ D("scan_usb_devices(): started\n");
+
+ libusb_device **devs= NULL;
+ libusb_device *dev= NULL;
+ ssize_t cnt = libusb_get_device_list(ctx, &devs);
+
+ if (cnt < 0) {
+ D("scan_usb_devices(): Failed to get device list (error: %d)\n",
+ cnt);
+
+ return;
+ }
+
+ int i = 0;
+
+ while ((dev = devs[i++]) != NULL) {
+ check_device(dev);
+ }
+
+ libusb_free_device_list(devs, 1);
+}
+
+void *
+device_poll_thread(void* unused)
+{
+ D("device_poll_thread(): Created USB scan thread\n");
+
+ for (;;) {
+ sleep(5);
+ kick_disconnected();
+ scan_usb_devices();
+ }
+
+ /* never reaching this point */
+ return (NULL);
+}
+
+static void
+sigalrm_handler(int signo)
+{
+ /* nothing */
+}
+
+void
+usb_init()
+{
+ D("usb_init(): started\n");
+ adb_thread_t tid;
+ struct sigaction actions;
+
+ int r = libusb_init(&ctx);
+
+ if (r != LIBUSB_SUCCESS) {
+ err(EX_IOERR, "Failed to init libusb\n");
+ }
+
+ memset(&actions, 0, sizeof(actions));
+
+ sigemptyset(&actions.sa_mask);
+
+ actions.sa_flags = 0;
+ actions.sa_handler = sigalrm_handler;
+
+ sigaction(SIGALRM, &actions, NULL);
+
+ /* initial device scan */
+ scan_usb_devices();
+
+ /* starting USB event polling thread */
+ if (adb_thread_create(&tid, device_poll_thread, NULL)) {
+ err(EX_IOERR, "cannot create USB scan thread\n");
+ }
+
+ D("usb_init(): finished\n");
+}
+
diff --git a/adb/usb_linux.c b/adb/usb_linux.c
index 863af1d..66ee317 100644
--- a/adb/usb_linux.c
+++ b/adb/usb_linux.c
@@ -150,13 +150,13 @@
while((de = readdir(devdir))) {
unsigned char devdesc[256];
unsigned char* bufptr = devdesc;
+ unsigned char* bufend;
struct usb_device_descriptor* device;
struct usb_config_descriptor* config;
struct usb_interface_descriptor* interface;
struct usb_endpoint_descriptor *ep1, *ep2;
unsigned zero_mask = 0;
unsigned vid, pid;
- int i, interfaces;
size_t desclength;
if(badname(de->d_name)) continue;
@@ -173,6 +173,7 @@
}
desclength = adb_read(fd, devdesc, sizeof(devdesc));
+ bufend = bufptr + desclength;
// should have device and configuration descriptors, and atleast two endpoints
if (desclength < USB_DT_DEVICE_SIZE + USB_DT_CONFIG_SIZE) {
@@ -203,75 +204,73 @@
continue;
}
- // loop through all the interfaces and look for the ADB interface
- interfaces = config->bNumInterfaces;
- for (i = 0; i < interfaces; i++) {
- if (bufptr + USB_DT_ENDPOINT_SIZE > devdesc + desclength)
- break;
+ // loop through all the descriptors and look for the ADB interface
+ while (bufptr < bufend) {
+ unsigned char length = bufptr[0];
+ unsigned char type = bufptr[1];
- interface = (struct usb_interface_descriptor *)bufptr;
- bufptr += USB_DT_INTERFACE_SIZE;
- if (interface->bLength != USB_DT_INTERFACE_SIZE ||
- interface->bDescriptorType != USB_DT_INTERFACE) {
- D("usb_interface_descriptor not found\n");
- break;
- }
+ if (type == USB_DT_INTERFACE) {
+ interface = (struct usb_interface_descriptor *)bufptr;
+ bufptr += length;
- DBGX("bInterfaceClass: %d, bInterfaceSubClass: %d,"
- "bInterfaceProtocol: %d, bNumEndpoints: %d\n",
- interface->bInterfaceClass, interface->bInterfaceSubClass,
- interface->bInterfaceProtocol, interface->bNumEndpoints);
-
- if (interface->bNumEndpoints == 2 &&
- is_adb_interface(vid, pid, interface->bInterfaceClass,
- interface->bInterfaceSubClass, interface->bInterfaceProtocol)) {
-
- DBGX("looking for bulk endpoints\n");
- // looks like ADB...
- ep1 = (struct usb_endpoint_descriptor *)bufptr;
- bufptr += USB_DT_ENDPOINT_SIZE;
- ep2 = (struct usb_endpoint_descriptor *)bufptr;
- bufptr += USB_DT_ENDPOINT_SIZE;
-
- if (bufptr > devdesc + desclength ||
- ep1->bLength != USB_DT_ENDPOINT_SIZE ||
- ep1->bDescriptorType != USB_DT_ENDPOINT ||
- ep2->bLength != USB_DT_ENDPOINT_SIZE ||
- ep2->bDescriptorType != USB_DT_ENDPOINT) {
- D("endpoints not found\n");
+ if (length != USB_DT_INTERFACE_SIZE) {
+ D("interface descriptor has wrong size\n");
break;
}
- // both endpoints should be bulk
- if (ep1->bmAttributes != USB_ENDPOINT_XFER_BULK ||
- ep2->bmAttributes != USB_ENDPOINT_XFER_BULK) {
- D("bulk endpoints not found\n");
- continue;
+ DBGX("bInterfaceClass: %d, bInterfaceSubClass: %d,"
+ "bInterfaceProtocol: %d, bNumEndpoints: %d\n",
+ interface->bInterfaceClass, interface->bInterfaceSubClass,
+ interface->bInterfaceProtocol, interface->bNumEndpoints);
+
+ if (interface->bNumEndpoints == 2 &&
+ is_adb_interface(vid, pid, interface->bInterfaceClass,
+ interface->bInterfaceSubClass, interface->bInterfaceProtocol)) {
+
+ DBGX("looking for bulk endpoints\n");
+ // looks like ADB...
+ ep1 = (struct usb_endpoint_descriptor *)bufptr;
+ bufptr += USB_DT_ENDPOINT_SIZE;
+ ep2 = (struct usb_endpoint_descriptor *)bufptr;
+ bufptr += USB_DT_ENDPOINT_SIZE;
+
+ if (bufptr > devdesc + desclength ||
+ ep1->bLength != USB_DT_ENDPOINT_SIZE ||
+ ep1->bDescriptorType != USB_DT_ENDPOINT ||
+ ep2->bLength != USB_DT_ENDPOINT_SIZE ||
+ ep2->bDescriptorType != USB_DT_ENDPOINT) {
+ D("endpoints not found\n");
+ break;
+ }
+
+ // both endpoints should be bulk
+ if (ep1->bmAttributes != USB_ENDPOINT_XFER_BULK ||
+ ep2->bmAttributes != USB_ENDPOINT_XFER_BULK) {
+ D("bulk endpoints not found\n");
+ continue;
+ }
+ /* aproto 01 needs 0 termination */
+ if(interface->bInterfaceProtocol == 0x01) {
+ zero_mask = ep1->wMaxPacketSize - 1;
+ }
+
+ // we have a match. now we just need to figure out which is in and which is out.
+ if (ep1->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
+ local_ep_in = ep1->bEndpointAddress;
+ local_ep_out = ep2->bEndpointAddress;
+ } else {
+ local_ep_in = ep2->bEndpointAddress;
+ local_ep_out = ep1->bEndpointAddress;
+ }
+
+ register_device_callback(devname, local_ep_in, local_ep_out,
+ interface->bInterfaceNumber, device->iSerialNumber, zero_mask);
+ break;
}
-
- /* aproto 01 needs 0 termination */
- if(interface->bInterfaceProtocol == 0x01) {
- zero_mask = ep1->wMaxPacketSize - 1;
- }
-
- // we have a match. now we just need to figure out which is in and which is out.
- if (ep1->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
- local_ep_in = ep1->bEndpointAddress;
- local_ep_out = ep2->bEndpointAddress;
- } else {
- local_ep_in = ep2->bEndpointAddress;
- local_ep_out = ep1->bEndpointAddress;
- }
-
- register_device_callback(devname, local_ep_in, local_ep_out,
- interface->bInterfaceNumber, device->iSerialNumber, zero_mask);
-
- break;
} else {
- // seek next interface descriptor
- bufptr += (USB_DT_ENDPOINT_SIZE * interface->bNumEndpoints);
- }
- } // end of for
+ bufptr += length;
+ }
+ } // end of while
adb_close(fd);
} // end of devdir while
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
index 064abc0..fd34052 100644
--- a/adb/usb_vendors.c
+++ b/adb/usb_vendors.c
@@ -51,6 +51,18 @@
#define VENDOR_ID_ACER 0x0502
// Sony Ericsson's USB Vendor ID
#define VENDOR_ID_SONY_ERICSSON 0x0FCE
+// Foxconn's USB Vendor ID
+#define VENDOR_ID_FOXCONN 0x0489
+// Dell's USB Vendor ID
+#define VENDOR_ID_DELL 0x413c
+// Nvidia's USB Vendor ID
+#define VENDOR_ID_NVIDIA 0x0955
+// Garmin-Asus's USB Vendor ID
+#define VENDOR_ID_GARMIN_ASUS 0x091E
+// Sharp's USB Vendor ID
+#define VENDOR_ID_SHARP 0x04dd
+// ZTE's USB Vendor ID
+#define VENDOR_ID_ZTE 0x19D2
/** built-in vendor list */
int builtInVendorIds[] = {
@@ -62,6 +74,12 @@
VENDOR_ID_HUAWEI,
VENDOR_ID_ACER,
VENDOR_ID_SONY_ERICSSON,
+ VENDOR_ID_FOXCONN,
+ VENDOR_ID_DELL,
+ VENDOR_ID_NVIDIA,
+ VENDOR_ID_GARMIN_ASUS,
+ VENDOR_ID_SHARP,
+ VENDOR_ID_ZTE,
};
#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
diff --git a/debuggerd/Android.mk b/debuggerd/Android.mk
index b22e1a8..b86f2a5 100644
--- a/debuggerd/Android.mk
+++ b/debuggerd/Android.mk
@@ -14,13 +14,23 @@
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := crasher.c
+LOCAL_SRC_FILES := crasher.c
LOCAL_SRC_FILES += crashglue.S
-LOCAL_MODULE := crasher
+LOCAL_MODULE := crasher
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := eng
#LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_SHARED_LIBRARIES := libcutils libc
include $(BUILD_EXECUTABLE)
+ifeq ($(TARGET_ARCH_VARIANT),armv7-a)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := vfp-crasher.c vfp.S
+LOCAL_MODULE := vfp-crasher
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_SHARED_LIBRARIES := libcutils libc
+include $(BUILD_EXECUTABLE)
+endif # TARGET_ARCH_VARIANT == armv7-a
+
endif # TARGET_ARCH == arm
diff --git a/debuggerd/crashglue.S b/debuggerd/crashglue.S
index 888951b..0c1fd9b 100644
--- a/debuggerd/crashglue.S
+++ b/debuggerd/crashglue.S
@@ -1,5 +1,7 @@
.globl crash1
+.type crash1, %function
.globl crashnostack
+.type crashnostack, %function
crash1:
ldr r0, =0xa5a50000
@@ -25,4 +27,4 @@
mov sp, #0
mov r0, #0
ldr r0, [r0]
- b .
\ No newline at end of file
+ b .
diff --git a/debuggerd/debuggerd.c b/debuggerd/debuggerd.c
index 996e6c2..7b987cf 100644
--- a/debuggerd/debuggerd.c
+++ b/debuggerd/debuggerd.c
@@ -120,7 +120,7 @@
void dump_stack_and_code(int tfd, int pid, mapinfo *map,
int unwind_depth, unsigned int sp_list[],
- int frame0_pc_sane, bool at_fault)
+ bool at_fault)
{
unsigned int sp, pc, p, end, data;
struct pt_regs r;
@@ -132,19 +132,11 @@
sp = r.ARM_sp;
pc = r.ARM_pc;
- /* Died because calling the weeds - dump
- * the code around the PC in the next frame instead.
- */
- if (frame0_pc_sane == 0) {
- pc = r.ARM_lr;
- }
-
- _LOG(tfd, only_in_tombstone,
- "\ncode around %s:\n", frame0_pc_sane ? "pc" : "lr");
+ _LOG(tfd, only_in_tombstone, "\ncode around pc:\n");
end = p = pc & ~3;
- p -= 16;
- end += 16;
+ p -= 32;
+ end += 32;
/* Dump the code around PC as:
* addr contents
@@ -163,12 +155,12 @@
_LOG(tfd, only_in_tombstone, "%s\n", code_buffer);
}
- if (frame0_pc_sane) {
+ if ((unsigned) r.ARM_lr != pc) {
_LOG(tfd, only_in_tombstone, "\ncode around lr:\n");
end = p = r.ARM_lr & ~3;
- p -= 16;
- end += 16;
+ p -= 32;
+ end += 32;
/* Dump the code around LR as:
* addr contents
@@ -285,6 +277,24 @@
_LOG(tfd, only_in_tombstone,
" ip %08x sp %08x lr %08x pc %08x cpsr %08x\n",
r.ARM_ip, r.ARM_sp, r.ARM_lr, r.ARM_pc, r.ARM_cpsr);
+
+#if __ARM_NEON__
+ struct user_vfp vfp_regs;
+ int i;
+
+ if(ptrace(PTRACE_GETVFPREGS, pid, 0, &vfp_regs)) {
+ _LOG(tfd, only_in_tombstone,
+ "cannot get registers: %s\n", strerror(errno));
+ return;
+ }
+
+ for (i = 0; i < 32; i += 2) {
+ _LOG(tfd, only_in_tombstone,
+ " d%-2d %016llx d%-2d %016llx\n",
+ i, vfp_regs.fpregs[i], i+1, vfp_regs.fpregs[i+1]);
+ }
+ _LOG(tfd, only_in_tombstone, " scr %08lx\n\n", vfp_regs.fpscr);
+#endif
}
const char *get_signame(int sig)
@@ -417,8 +427,7 @@
dump_pc_and_lr(tfd, tid, milist, stack_depth, at_fault);
}
- dump_stack_and_code(tfd, tid, milist, stack_depth, sp_list, frame0_pc_sane,
- at_fault);
+ dump_stack_and_code(tfd, tid, milist, stack_depth, sp_list, at_fault);
while(milist) {
mapinfo *next = milist->next;
@@ -606,15 +615,16 @@
(void)tid;
/* First log a helpful message */
LOG( "********************************************************\n"
- "* process %d crashed. debuggerd waiting for gdbserver \n"
- "* \n"
- "* adb shell gdbserver :port --attach %d & \n"
- "* \n"
- "* and press the HOME key. \n"
+ "* Process %d has been suspended while crashing. To\n"
+ "* attach gdbserver for a gdb connection on port 5039:\n"
+ "*\n"
+ "* adb shell gdbserver :5039 --attach %d &\n"
+ "*\n"
+ "* Press HOME key to let the process continue crashing.\n"
"********************************************************\n",
cr->pid, cr->pid);
- /* wait for HOME key */
+ /* wait for HOME key (TODO: something useful for devices w/o HOME key) */
if (init_getevent() == 0) {
int ms = 1200 / 10;
int dit = 1;
@@ -698,7 +708,7 @@
sprintf(buf,"/proc/%d/task/%d", cr.pid, tid);
if(stat(buf, &s)) {
- LOG("tid %d does not exist in pid %d. ignorning debug request\n",
+ LOG("tid %d does not exist in pid %d. ignoring debug request\n",
tid, cr.pid);
close(fd);
return;
diff --git a/debuggerd/vfp-crasher.c b/debuggerd/vfp-crasher.c
new file mode 100644
index 0000000..7a19cdd
--- /dev/null
+++ b/debuggerd/vfp-crasher.c
@@ -0,0 +1,7 @@
+int main()
+{
+ extern void crash(void);
+
+ crash();
+ return 0;
+}
diff --git a/debuggerd/vfp.S b/debuggerd/vfp.S
new file mode 100644
index 0000000..2192415
--- /dev/null
+++ b/debuggerd/vfp.S
@@ -0,0 +1,41 @@
+ .text
+ .align 2
+ .global crash
+ .type crash, %function
+crash:
+ fconstd d0, #0
+ fconstd d1, #1
+ fconstd d2, #2
+ fconstd d3, #3
+ fconstd d4, #4
+ fconstd d5, #5
+ fconstd d6, #6
+ fconstd d7, #7
+ fconstd d8, #8
+ fconstd d9, #9
+ fconstd d10, #10
+ fconstd d11, #11
+ fconstd d12, #12
+ fconstd d13, #13
+ fconstd d14, #14
+ fconstd d15, #15
+ fconstd d16, #16
+ fconstd d17, #17
+ fconstd d18, #18
+ fconstd d19, #19
+ fconstd d20, #20
+ fconstd d21, #21
+ fconstd d22, #22
+ fconstd d23, #23
+ fconstd d24, #24
+ fconstd d25, #25
+ fconstd d26, #26
+ fconstd d27, #27
+ fconstd d28, #28
+ fconstd d29, #29
+ fconstd d30, #30
+ fconstd d31, #31
+ mov r0, #0
+ str r0, [r0]
+ bx lr
+
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index 911c3f6..bed30b2 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -149,7 +149,10 @@
if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
(info->dev_vendor != 0x18d1) && // Google
(info->dev_vendor != 0x0451) &&
+ (info->dev_vendor != 0x0502) &&
(info->dev_vendor != 0x22b8) && // Motorola
+ (info->dev_vendor != 0x0955) && // Nvidia
+ (info->dev_vendor != 0x413c) && // DELL
(info->dev_vendor != 0x0bb4)) // HTC
return -1;
if(info->ifc_class != 0xff) return -1;
@@ -228,11 +231,12 @@
" -c <cmdline> override kernel commandline\n"
" -i <vendor id> specify a custom USB vendor id\n"
" -b <base_addr> specify a custom kernel base address\n"
+ " -n <page size> specify the nand page size. default: 2048\n"
);
exit(1);
}
-void *load_bootable_image(const char *kernel, const char *ramdisk,
+void *load_bootable_image(unsigned page_size, const char *kernel, const char *ramdisk,
unsigned *sz, const char *cmdline)
{
void *kdata = 0, *rdata = 0;
@@ -273,7 +277,7 @@
}
fprintf(stderr,"creating boot image...\n");
- bdata = mkbootimg(kdata, ksize, rdata, rsize, 0, 0, 2048, base_addr, &bsize);
+ bdata = mkbootimg(kdata, ksize, rdata, rsize, 0, 0, page_size, base_addr, &bsize);
if(bdata == 0) {
fprintf(stderr,"failed to create boot.img\n");
return 0;
@@ -545,6 +549,7 @@
int wants_reboot_bootloader = 0;
void *data;
unsigned sz;
+ unsigned page_size = 2048;
skip(1);
if (argc == 0) {
@@ -567,6 +572,11 @@
require(2);
base_addr = strtoul(argv[1], 0, 16);
skip(2);
+ } else if(!strcmp(*argv, "-n")) {
+ require(2);
+ page_size = (unsigned)strtoul(argv[1], NULL, 0);
+ if (!page_size) die("invalid page size");
+ skip(2);
} else if(!strcmp(*argv, "-s")) {
require(2);
serial = argv[1];
@@ -626,7 +636,7 @@
rname = argv[0];
skip(1);
}
- data = load_bootable_image(kname, rname, &sz, cmdline);
+ data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
if (data == 0) return 1;
fb_queue_download("boot.img", data, sz);
fb_queue_command("boot", "booting");
@@ -656,7 +666,7 @@
} else {
skip(3);
}
- data = load_bootable_image(kname, rname, &sz, cmdline);
+ data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
if (data == 0) die("cannot load bootable image");
fb_queue_flash(pname, data, sz);
} else if(!strcmp(*argv, "flashall")) {
diff --git a/include/arch/darwin-x86/AndroidConfig.h b/include/arch/darwin-x86/AndroidConfig.h
index 20e0000..3aa0cd1 100644
--- a/include/arch/darwin-x86/AndroidConfig.h
+++ b/include/arch/darwin-x86/AndroidConfig.h
@@ -146,7 +146,7 @@
*/
#if (defined(__ppc__) || defined(__ppc64__))
# define HAVE_BIG_ENDIAN
-#elif defined(__i386__)
+#elif (defined(__i386__) || defined(__x86_64__))
# define HAVE_LITTLE_ENDIAN
#endif
@@ -219,7 +219,7 @@
*/
#if (defined(__ppc__) || defined(__ppc64__))
# define ARCH_PPC
-#elif defined(__i386__)
+#elif (defined(__i386__) || defined(__x86_64__))
# define ARCH_X86
#endif
@@ -256,6 +256,16 @@
#define HAVE_STRLCPY 1
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+#define HAVE_FUNOPEN 1
+
+/*
* Define if writev() exists
*/
#define HAVE_WRITEV 1
diff --git a/include/arch/freebsd-x86/AndroidConfig.h b/include/arch/freebsd-x86/AndroidConfig.h
index b01a854..57d5024 100644
--- a/include/arch/freebsd-x86/AndroidConfig.h
+++ b/include/arch/freebsd-x86/AndroidConfig.h
@@ -295,6 +295,16 @@
#define HAVE_STRLCPY 1
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+#define HAVE_FUNOPEN 1
+
+/*
* Define if prctl() exists
*/
/* #define HAVE_PRCTL 1 */
diff --git a/include/arch/linux-arm/AndroidConfig.h b/include/arch/linux-arm/AndroidConfig.h
index 26547a2..f51ddb1 100644
--- a/include/arch/linux-arm/AndroidConfig.h
+++ b/include/arch/linux-arm/AndroidConfig.h
@@ -298,6 +298,16 @@
#define HAVE_STRLCPY 1
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+#define HAVE_FUNOPEN 1
+
+/*
* Define if prctl() exists
*/
#define HAVE_PRCTL 1
diff --git a/include/arch/linux-sh/AndroidConfig.h b/include/arch/linux-sh/AndroidConfig.h
index 67ac277..5e93990 100644
--- a/include/arch/linux-sh/AndroidConfig.h
+++ b/include/arch/linux-sh/AndroidConfig.h
@@ -303,6 +303,16 @@
#define HAVE_STRLCPY 1
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+#define HAVE_FUNOPEN 1
+
+/*
* Define if prctl() exists
*/
#define HAVE_PRCTL 1
diff --git a/include/arch/linux-x86/AndroidConfig.h b/include/arch/linux-x86/AndroidConfig.h
index 31bdb5f..b0fe90a 100644
--- a/include/arch/linux-x86/AndroidConfig.h
+++ b/include/arch/linux-x86/AndroidConfig.h
@@ -279,6 +279,16 @@
/* #define HAVE_STRLCPY 1 */
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+#define HAVE_OPEN_MEMSTREAM 1
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+/* #define HAVE_FUNOPEN 1 */
+
+/*
* Define if prctl() exists
*/
#define HAVE_PRCTL 1
diff --git a/include/arch/target_linux-x86/AndroidConfig.h b/include/arch/target_linux-x86/AndroidConfig.h
index d89d054..4db3e72 100644
--- a/include/arch/target_linux-x86/AndroidConfig.h
+++ b/include/arch/target_linux-x86/AndroidConfig.h
@@ -289,6 +289,16 @@
#define HAVE_STRLCPY 1
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+#define HAVE_FUNOPEN 1
+
+/*
* Define if prctl() exists
*/
#define HAVE_PRCTL 1
diff --git a/include/arch/windows/AndroidConfig.h b/include/arch/windows/AndroidConfig.h
index 0fc4955..1b6ece1 100644
--- a/include/arch/windows/AndroidConfig.h
+++ b/include/arch/windows/AndroidConfig.h
@@ -272,6 +272,16 @@
/* #define HAVE_STRLCPY 1 */
/*
+ * Define if the open_memstream() function exists on the system.
+ */
+/* #define HAVE_OPEN_MEMSTREAM 1 */
+
+/*
+ * Define if the BSD funopen() function exists on the system.
+ */
+/* #define HAVE_FUNOPEN 1 */
+
+/*
* Define if <winsock2.h> exists.
* Only MinGW has it.
*/
diff --git a/include/cutils/iosched_policy.h b/include/cutils/iosched_policy.h
new file mode 100644
index 0000000..07c5d1f
--- /dev/null
+++ b/include/cutils/iosched_policy.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007 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 __CUTILS_IOSCHED_POLICY_H
+#define __CUTILS_IOSCHED_POLICY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ IoSchedClass_NONE,
+ IoSchedClass_RT,
+ IoSchedClass_BE,
+ IoSchedClass_IDLE,
+} IoSchedClass;
+
+extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio);
+extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CUTILS_IOSCHED_POLICY_H */
diff --git a/include/cutils/log.h b/include/cutils/log.h
index ec3cac8..dd47c35 100644
--- a/include/cutils/log.h
+++ b/include/cutils/log.h
@@ -196,6 +196,91 @@
#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG)
#endif
+
+// ---------------------------------------------------------------------
+
+/*
+ * Simplified macro to send a verbose system log message using the current LOG_TAG.
+ */
+#ifndef SLOGV
+#if LOG_NDEBUG
+#define SLOGV(...) ((void)0)
+#else
+#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#endif
+#endif
+
+#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
+
+#ifndef SLOGV_IF
+#if LOG_NDEBUG
+#define SLOGV_IF(cond, ...) ((void)0)
+#else
+#define SLOGV_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug system log message using the current LOG_TAG.
+ */
+#ifndef SLOGD
+#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGD_IF
+#define SLOGD_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info system log message using the current LOG_TAG.
+ */
+#ifndef SLOGI
+#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGI_IF
+#define SLOGI_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning system log message using the current LOG_TAG.
+ */
+#ifndef SLOGW
+#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGW_IF
+#define SLOGW_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error system log message using the current LOG_TAG.
+ */
+#ifndef SLOGE
+#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGE_IF
+#define SLOGE_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+
+
// ---------------------------------------------------------------------
/*
@@ -338,6 +423,21 @@
#define android_logToFile(tag, file) (0)
#define android_logToFd(tag, fd) (0)
+typedef enum {
+ LOG_ID_MAIN = 0,
+ LOG_ID_RADIO = 1,
+ LOG_ID_EVENTS = 2,
+ LOG_ID_SYSTEM = 3,
+
+ LOG_ID_MAX
+} log_id_t;
+
+/*
+ * Send a simple string to the log.
+ */
+int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
+int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
+
#ifdef __cplusplus
}
diff --git a/include/cutils/logger.h b/include/cutils/logger.h
index 3a08019..b60f7ad 100644
--- a/include/cutils/logger.h
+++ b/include/cutils/logger.h
@@ -25,6 +25,7 @@
#define LOGGER_LOG_MAIN "log/main"
#define LOGGER_LOG_RADIO "log/radio"
#define LOGGER_LOG_EVENTS "log/events"
+#define LOGGER_LOG_SYSTEM "log/system"
#define LOGGER_ENTRY_MAX_LEN (4*1024)
#define LOGGER_ENTRY_MAX_PAYLOAD \
diff --git a/include/cutils/logprint.h b/include/cutils/logprint.h
index d6ec480..769c8a7 100644
--- a/include/cutils/logprint.h
+++ b/include/cutils/logprint.h
@@ -142,7 +142,7 @@
* Assumes single threaded execution
*
*/
-int android_log_filterAndPrintLogLine(
+int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry);
diff --git a/include/cutils/mspace.h b/include/cutils/mspace.h
index 33410c1..e6e4047 100644
--- a/include/cutils/mspace.h
+++ b/include/cutils/mspace.h
@@ -80,6 +80,12 @@
mspace create_contiguous_mspace_with_name(size_t starting_capacity,
size_t max_capacity, int locked, const char *name);
+/*
+ Identical to create_contiguous_mspace, but uses previously mapped memory.
+*/
+mspace create_contiguous_mspace_with_base(size_t starting_capacity,
+ size_t max_capacity, int locked, void *base);
+
size_t destroy_contiguous_mspace(mspace msp);
#endif
diff --git a/vold/uevent.h b/include/cutils/open_memstream.h
similarity index 61%
rename from vold/uevent.h
rename to include/cutils/open_memstream.h
index 0e9e671..b7998be 100644
--- a/vold/uevent.h
+++ b/include/cutils/open_memstream.h
@@ -1,6 +1,5 @@
-
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * 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.
@@ -15,7 +14,23 @@
* limitations under the License.
*/
-#ifndef _UEVENT_MSG_H
-#define _UEVENT_MSG_H
+#ifndef __CUTILS_OPEN_MEMSTREAM_H__
+#define __CUTILS_OPEN_MEMSTREAM_H__
+#include <stdio.h>
+
+#ifndef HAVE_OPEN_MEMSTREAM
+
+#ifdef __cplusplus
+extern "C" {
#endif
+
+FILE* open_memstream(char** bufp, size_t* sizep);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*!HAVE_OPEN_MEMSTREAM*/
+
+#endif /*__CUTILS_OPEN_MEMSTREAM_H__*/
diff --git a/include/pixelflinger/format.h b/include/pixelflinger/format.h
index 6b2050c..82eeca4 100644
--- a/include/pixelflinger/format.h
+++ b/include/pixelflinger/format.h
@@ -39,19 +39,25 @@
GGL_PIXEL_FORMAT_LA_88 = 0xA, // 16-bit LA
GGL_PIXEL_FORMAT_RGB_332 = 0xB, // 8-bit RGB (non paletted)
- // YCbCr formats (SP=semi-planar, P=planar)
- GGL_PIXEL_FORMAT_YCbCr_422_SP= 0x10,
- GGL_PIXEL_FORMAT_YCbCr_420_SP= 0x11,
- GGL_PIXEL_FORMAT_YCbCr_422_P = 0x12,
- GGL_PIXEL_FORMAT_YCbCr_420_P = 0x13,
- GGL_PIXEL_FORMAT_YCbCr_422_I = 0x14,
- GGL_PIXEL_FORMAT_YCbCr_420_I = 0x15,
+ // reserved range. don't use.
+ GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
+ GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
+ GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
+ GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
+ GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
+ GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
+ GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
+ GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
// reserved/special formats
GGL_PIXEL_FORMAT_Z_16 = 0x18,
GGL_PIXEL_FORMAT_S_8 = 0x19,
GGL_PIXEL_FORMAT_SZ_24 = 0x1A,
GGL_PIXEL_FORMAT_SZ_8 = 0x1B,
+
+ // reserved range. don't use.
+ GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
+ GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
};
enum GGLFormatComponents {
@@ -62,10 +68,6 @@
GGL_RGBA = 0x1908,
GGL_LUMINANCE = 0x1909,
GGL_LUMINANCE_ALPHA = 0x190A,
- GGL_Y_CB_CR_SP = 0x8000,
- GGL_Y_CB_CR = GGL_Y_CB_CR_SP,
- GGL_Y_CB_CR_P = 0x8001,
- GGL_Y_CB_CR_I = 0x8002,
};
enum GGLFormatComponentIndex {
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index 24b7c81..49fa912 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -156,9 +156,10 @@
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" },
{ 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" },
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
- { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/main.conf" },
- { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/input.conf" },
- { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/audio.conf" },
+ { 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" },
+ { 00640, AID_SYSTEM, AID_SYSTEM, "system/etc/bluetooth/auto_pairing.conf" },
{ 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" },
{ 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" },
@@ -167,7 +168,7 @@
/* the following two files are INTENTIONALLY set-gid and not set-uid.
* Do not change. */
{ 02755, AID_ROOT, AID_NET_RAW, "system/bin/ping" },
- { 02755, AID_ROOT, AID_INET, "system/bin/netcfg" },
+ { 02750, AID_ROOT, AID_INET, "system/bin/netcfg" },
/* the following four files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/su" },
diff --git a/include/private/pixelflinger/ggl_context.h b/include/private/pixelflinger/ggl_context.h
index 8a36fa9..2d7fdcf 100644
--- a/include/private/pixelflinger/ggl_context.h
+++ b/include/private/pixelflinger/ggl_context.h
@@ -285,8 +285,7 @@
};
struct fog_state_t {
- uint8_t color[3];
- uint8_t reserved;
+ uint8_t color[4];
};
struct logic_op_state_t {
diff --git a/include/sysutils/NetlinkEvent.h b/include/sysutils/NetlinkEvent.h
index 95e83a3..b329b09 100644
--- a/include/sysutils/NetlinkEvent.h
+++ b/include/sysutils/NetlinkEvent.h
@@ -39,6 +39,8 @@
const char *getSubsystem() { return mSubsystem; }
int getAction() { return mAction; }
+
+ void dump();
};
#endif
diff --git a/init/devices.c b/init/devices.c
index 55c5ee4..bde906b 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -138,6 +138,7 @@
{ "/dev/msm_snd", 0660, AID_SYSTEM, AID_AUDIO, 1 },
{ "/dev/msm_mp3", 0660, AID_SYSTEM, AID_AUDIO, 1 },
{ "/dev/audience_a1026", 0660, AID_SYSTEM, AID_AUDIO, 1 },
+ { "/dev/tpa2018d1", 0660, AID_SYSTEM, AID_AUDIO, 1 },
{ "/dev/msm_audpre", 0660, AID_SYSTEM, AID_AUDIO, 0 },
{ "/dev/msm_audio_ctl", 0660, AID_SYSTEM, AID_AUDIO, 0 },
{ "/dev/htc-acoustic", 0660, AID_SYSTEM, AID_AUDIO, 0 },
@@ -306,8 +307,15 @@
mode = get_device_perm(path, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
dev = (major << 8) | minor;
+ /* Temporarily change egid to avoid race condition setting the gid of the
+ * device node. Unforunately changing the euid would prevent creation of
+ * some device nodes, so the uid has to be set with chown() and is still
+ * racy. Fixing the gid race at least fixed the issue with system_server
+ * opening dynamic input devices under the AID_INPUT gid. */
+ setegid(gid);
mknod(path, mode, dev);
- chown(path, uid, gid);
+ chown(path, uid, -1);
+ setegid(AID_ROOT);
}
#if LOG_UEVENTS
diff --git a/init/init.c b/init/init.c
index f76eb36..4d98cc2 100755
--- a/init/init.c
+++ b/init/init.c
@@ -35,6 +35,7 @@
#include <sys/reboot.h>
#include <cutils/sockets.h>
+#include <cutils/iosched_policy.h>
#include <termios.h>
#include <linux/kd.h>
#include <linux/keychord.h>
@@ -224,6 +225,13 @@
}
}
+ if (svc->ioprio_class != IoSchedClass_NONE) {
+ if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) {
+ ERROR("Failed to set pid %d ioprio = %d,%d: %s\n",
+ getpid(), svc->ioprio_class, svc->ioprio_pri, strerror(errno));
+ }
+ }
+
if (needs_console) {
setsid();
open_console();
@@ -767,21 +775,31 @@
void handle_keychord(int fd)
{
struct service *svc;
+ char* debuggable;
+ char* adb_enabled;
int ret;
__u16 id;
- ret = read(fd, &id, sizeof(id));
- if (ret != sizeof(id)) {
- ERROR("could not read keychord id\n");
- return;
- }
+ // only handle keychords if ro.debuggable is set or adb is enabled.
+ // the logic here is that bugreports should be enabled in userdebug or eng builds
+ // and on user builds for users that are developers.
+ debuggable = property_get("ro.debuggable");
+ adb_enabled = property_get("init.svc.adbd");
+ if ((debuggable && !strcmp(debuggable, "1")) ||
+ (adb_enabled && !strcmp(adb_enabled, "running"))) {
+ ret = read(fd, &id, sizeof(id));
+ if (ret != sizeof(id)) {
+ ERROR("could not read keychord id\n");
+ return;
+ }
- svc = service_find_by_keychord(id);
- if (svc) {
- INFO("starting service %s from keychord\n", svc->name);
- service_start(svc, NULL);
- } else {
- ERROR("service for keychord %d not found\n", id);
+ svc = service_find_by_keychord(id);
+ if (svc) {
+ INFO("starting service %s from keychord\n", svc->name);
+ service_start(svc, NULL);
+ } else {
+ ERROR("service for keychord %d not found\n", id);
+ }
}
}
@@ -853,10 +871,7 @@
property_init();
// only listen for keychords if ro.debuggable is true
- debuggable = property_get("ro.debuggable");
- if (debuggable && !strcmp(debuggable, "1")) {
- keychord_fd = open_keychord();
- }
+ keychord_fd = open_keychord();
if (console[0]) {
snprintf(tmp, sizeof(tmp), "/dev/%s", console);
diff --git a/init/init.h b/init/init.h
index 60c3055..8c0571c 100644
--- a/init/init.h
+++ b/init/init.h
@@ -146,6 +146,9 @@
int nkeycodes;
int keychord_id;
+ int ioprio_class;
+ int ioprio_pri;
+
int nargs;
/* "MUST BE AT THE END OF THE STRUCT" */
char *args[1];
diff --git a/init/keywords.h b/init/keywords.h
index 308118e..254c785 100644
--- a/init/keywords.h
+++ b/init/keywords.h
@@ -75,6 +75,7 @@
KEYWORD(chmod, COMMAND, 2, do_chmod)
KEYWORD(loglevel, COMMAND, 1, do_loglevel)
KEYWORD(device, COMMAND, 4, do_device)
+ KEYWORD(ioprio, OPTION, 0, 0)
#ifdef __MAKE_KEYWORD_ENUM__
KEYWORD_COUNT,
};
diff --git a/init/parser.c b/init/parser.c
index 54622cc..7da0d19 100644
--- a/init/parser.c
+++ b/init/parser.c
@@ -10,6 +10,8 @@
#include "init.h"
#include "property_service.h"
+#include <cutils/iosched_policy.h>
+
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
@@ -155,6 +157,7 @@
if (!strcmp(s, "ostname")) return K_hostname;
break;
case 'i':
+ if (!strcmp(s, "oprio")) return K_ioprio;
if (!strcmp(s, "fup")) return K_ifup;
if (!strcmp(s, "nsmod")) return K_insmod;
if (!strcmp(s, "mport")) return K_import;
@@ -619,6 +622,8 @@
return;
}
+ svc->ioprio_class = IoSchedClass_NONE;
+
kw = lookup_keyword(args[0]);
switch (kw) {
case K_capability:
@@ -636,6 +641,28 @@
case K_disabled:
svc->flags |= SVC_DISABLED;
break;
+ case K_ioprio:
+ if (nargs != 3) {
+ parse_error(state, "ioprio optin usage: ioprio <rt|be|idle> <ioprio 0-7>\n");
+ } else {
+ svc->ioprio_pri = strtoul(args[2], 0, 8);
+
+ if (svc->ioprio_pri < 0 || svc->ioprio_pri > 7) {
+ parse_error(state, "priority value must be range 0 - 7\n");
+ break;
+ }
+
+ if (!strcmp(args[1], "rt")) {
+ svc->ioprio_class = IoSchedClass_RT;
+ } else if (!strcmp(args[1], "be")) {
+ svc->ioprio_class = IoSchedClass_BE;
+ } else if (!strcmp(args[1], "idle")) {
+ svc->ioprio_class = IoSchedClass_IDLE;
+ } else {
+ parse_error(state, "ioprio option usage: ioprio <rt|be|idle> <0-7>\n");
+ }
+ }
+ break;
case K_group:
if (nargs < 2) {
parse_error(state, "group option requires a group id\n");
diff --git a/init/property_service.c b/init/property_service.c
index 7db7c2c..d2505dd 100644
--- a/init/property_service.c
+++ b/init/property_service.c
@@ -77,6 +77,7 @@
{ "service.adb.root", AID_SHELL, 0 },
{ "persist.sys.", AID_SYSTEM, 0 },
{ "persist.service.", AID_SYSTEM, 0 },
+ { "persist.security.", AID_SYSTEM, 0 },
{ NULL, 0, 0 }
};
diff --git a/libacc/Android.mk b/libacc/Android.mk
index 2b4998e..5101e16 100644
--- a/libacc/Android.mk
+++ b/libacc/Android.mk
@@ -11,7 +11,7 @@
include $(BUILD_SHARED_LIBRARY)
-# Shared library for host
+# Static library for host
# ========================================================
include $(CLEAR_VARS)
@@ -23,7 +23,7 @@
LOCAL_STATIC_LIBRARIES := libcutils
LOCAL_LDLIBS := -ldl
-include $(BUILD_HOST_SHARED_LIBRARY)
+include $(BUILD_HOST_STATIC_LIBRARY)
# Build children
# ========================================================
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 0c32f25..8f33b0b 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -82,9 +82,7 @@
~Vector() {
if (mpBase) {
- for(size_t i = 0; i < mUsed; i++) {
- mpBase[mUsed].~E();
- }
+ clear();
free(mpBase);
}
}
@@ -110,10 +108,20 @@
* ensure(1) = item;
}
- size_t size() {
+ inline size_t size() {
return mUsed;
}
+ void clear() {
+ if (mpBase) {
+ size_t used = mUsed;
+ for(size_t i = 0; i < used; i++) {
+ mpBase[i].~E();
+ }
+ }
+ mUsed = 0;
+ }
+
private:
E* ensure(int n) {
size_t newUsed = mUsed + n;
@@ -1677,6 +1685,7 @@
pDestType->tag);
break;
}
+ setR0Type(pDestType);
}
virtual void loadR0FromR0() {
@@ -2847,6 +2856,7 @@
pTargetType->tag);
break;
}
+ setR0Type(pTargetType);
}
virtual void loadR0FromR0() {
diff --git a/libacc/tests/Android.mk b/libacc/tests/Android.mk
index b3af6f1..6ddfa74 100644
--- a/libacc/tests/Android.mk
+++ b/libacc/tests/Android.mk
@@ -8,9 +8,13 @@
LOCAL_SRC_FILES:= \
main.cpp
-LOCAL_SHARED_LIBRARIES := \
- libacc
+LOCAL_STATIC_LIBRARIES := \
+ libacc \
+ libcutils
+LOCAL_LDLIBS := -ldl
+
+
LOCAL_MODULE_TAGS := tests
include $(BUILD_HOST_EXECUTABLE)
@@ -42,8 +46,11 @@
LOCAL_SRC_FILES:= \
runtimeTest.cpp
-LOCAL_SHARED_LIBRARIES := \
- libacc
+LOCAL_STATIC_LIBRARIES := \
+ libacc \
+ libcutils
+
+LOCAL_LDLIBS := -ldl
LOCAL_MODULE_TAGS := tests
diff --git a/libacc/tests/data/assignment.c b/libacc/tests/data/assignment.c
new file mode 100644
index 0000000..4fc7801
--- /dev/null
+++ b/libacc/tests/data/assignment.c
@@ -0,0 +1,9 @@
+int main() {
+ int a = 0;
+ int b = 1;
+ a = b = 2; // Test that "b = 2" generates an rvalue.
+ if (a = 7) { // Test that a = 7 generates an rvalue.
+ b = 3;
+ }
+ return a;
+}
diff --git a/libacc/tests/test.py b/libacc/tests/test.py
index d93af46..1b444c7 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -10,6 +10,7 @@
gUseArm = True
gUseX86 = True
gRunOTCCOutput = True
+gCompileOTCCANSI = True
def parseArgv():
@@ -59,7 +60,12 @@
def checkEnvironment():
global gRunOTCCOutput
- gRunOTCCOutput = uname() == "Linux" and unameM() != "x86_64" and outputCanRun()
+ global gCompileOTCCANSI
+ osName = uname()
+ gRunOTCCOutput = osName == "Linux" and unameM() != "x86_64" and outputCanRun()
+ # OSX doesn't have stdin/stdout/stderr accessible through dll load symbols, so
+ # we can't compile the ANSI version of the OTCC compiler on OS X.
+ gCompileOTCCANSI = osName == "Linux"
def adb(args):
return runCmd(["adb"] + args)
@@ -180,8 +186,10 @@
def testCompileReturnVal(self):
self.compileCheck(["data/returnval-ansi.c"], "")
- def testCompileOTCCANSII(self):
- self.compileCheck(["data/otcc-ansi.c"], "", "", ['x86'])
+ def testCompileOTCCANSI(self):
+ global gCompileOTCCANSI
+ if gCompileOTCCANSI:
+ self.compileCheck(["data/otcc-ansi.c"], "", "", ['x86'])
def testRunReturnVal(self):
self.compileCheck(["-R", "data/returnval-ansi.c"],
@@ -442,6 +450,11 @@
result: -2
""","""""")
+ def testAssignment(self):
+ self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
+result: 7
+""","""""")
+
def testArray(self):
self.compileCheck(["-R", "data/array.c"], """Executing compiled code:
localInt: 3
diff --git a/libcutils/Android.mk b/libcutils/Android.mk
index b219473..4c45cc9 100644
--- a/libcutils/Android.mk
+++ b/libcutils/Android.mk
@@ -31,13 +31,15 @@
config_utils.c \
cpu_info.c \
load_file.c \
+ open_memstream.c \
strdup16to8.c \
strdup8to16.c \
record_stream.c \
process_name.c \
properties.c \
threads.c \
- sched_policy.c
+ sched_policy.c \
+ iosched_policy.c
commonHostSources := \
ashmem-host.c
diff --git a/libcutils/atomic-android-arm.S b/libcutils/atomic-android-arm.S
index da5c26b..1dd2363 100644
--- a/libcutils/atomic-android-arm.S
+++ b/libcutils/atomic-android-arm.S
@@ -24,17 +24,25 @@
.align
.global android_atomic_write
+ .type android_atomic_write, %function
.global android_atomic_inc
+ .type android_atomic_inc, %function
.global android_atomic_dec
+ .type android_atomic_dec, %function
.global android_atomic_add
+ .type android_atomic_add, %function
.global android_atomic_and
+ .type android_atomic_and, %function
.global android_atomic_or
+ .type android_atomic_or, %function
.global android_atomic_swap
+ .type android_atomic_swap, %function
.global android_atomic_cmpxchg
+ .type android_atomic_cmpxchg, %function
/*
* ----------------------------------------------------------------------------
diff --git a/libcutils/atomic-android-armv6.S b/libcutils/atomic-android-armv6.S
index a713089..1574c9c 100644
--- a/libcutils/atomic-android-armv6.S
+++ b/libcutils/atomic-android-armv6.S
@@ -19,17 +19,25 @@
.align
.global android_atomic_write
+ .type android_atomic_write, %function
.global android_atomic_inc
+ .type android_atomic_inc, %function
.global android_atomic_dec
+ .type android_atomic_dec, %function
.global android_atomic_add
+ .type android_atomic_add, %function
.global android_atomic_and
+ .type android_atomic_and, %function
.global android_atomic_or
+ .type android_atomic_or, %function
.global android_atomic_swap
+ .type android_atomic_swap, %function
.global android_atomic_cmpxchg
+ .type android_atomic_cmpxchg, %function
diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c
new file mode 100644
index 0000000..f350f58
--- /dev/null
+++ b/libcutils/iosched_policy.c
@@ -0,0 +1,67 @@
+
+/* libs/cutils/iosched_policy.c
+**
+** Copyright 2007, 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.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#ifdef HAVE_SCHED_H
+
+#include <cutils/iosched_policy.h>
+
+extern int ioprio_set(int which, int who, int ioprio);
+
+enum {
+ WHO_PROCESS = 1,
+ WHO_PGRP,
+ WHO_USER,
+};
+
+#define CLASS_SHIFT 13
+#define IOPRIO_NORM 4
+
+int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) {
+#ifdef HAVE_ANDROID_OS
+ if (ioprio_set(WHO_PROCESS, pid, ioprio | (clazz << CLASS_SHIFT))) {
+ return -1;
+ }
+#endif
+ return 0;
+}
+
+int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio) {
+#ifdef HAVE_ANDROID_OS
+ int rc;
+
+ if ((rc = ioprio_get(WHO_PROCESS, pid)) < 0) {
+ return -1;
+ }
+
+ *clazz = (rc >> CLASS_SHIFT);
+ *ioprio = (rc & 0xff);
+#else
+ *clazz = IoSchedClass_NONE;
+ *ioprio = 0;
+#endif
+ return 0;
+}
+
+#endif /* HAVE_SCHED_H */
diff --git a/libcutils/mspace.c b/libcutils/mspace.c
index 8fd5de7..63b199d 100644
--- a/libcutils/mspace.c
+++ b/libcutils/mspace.c
@@ -134,10 +134,73 @@
return oldbrk;
}
-mspace create_contiguous_mspace_with_name(size_t starting_capacity,
- size_t max_capacity, int locked, char const * name) {
- int fd, ret;
+mspace create_contiguous_mspace_with_base(size_t starting_capacity,
+ size_t max_capacity, int locked, void *base) {
struct mspace_contig_state *cs;
+ unsigned int pagesize;
+ mstate m;
+
+ init_mparams();
+ pagesize = PAGESIZE;
+ assert(starting_capacity <= max_capacity);
+ assert(((uintptr_t)base & (pagesize-1)) == 0);
+ assert(((uintptr_t)max_capacity & (pagesize-1)) == 0);
+ starting_capacity = (size_t)ALIGN_UP(starting_capacity, pagesize);
+
+ /* Make the first page read/write. dlmalloc needs to use that page.
+ */
+ if (mprotect(base, starting_capacity, PROT_READ | PROT_WRITE) < 0) {
+ goto error;
+ }
+
+ /* Create the mspace, pointing to the memory given.
+ */
+ m = create_mspace_with_base((char *)base + sizeof(*cs), starting_capacity,
+ locked);
+ if (m == (mspace)0) {
+ goto error;
+ }
+ /* Make sure that m is in the same page as base.
+ */
+ assert(((uintptr_t)m & (uintptr_t)~(pagesize-1)) == (uintptr_t)base);
+ /* Use some space for the information that our MORECORE needs.
+ */
+ cs = (struct mspace_contig_state *)base;
+
+ /* Find out exactly how much of the memory the mspace
+ * is using.
+ */
+ cs->brk = m->seg.base + m->seg.size;
+ cs->top = (char *)base + max_capacity;
+
+ assert((char *)base <= cs->brk);
+ assert(cs->brk <= cs->top);
+ /* Prevent access to the memory we haven't handed out yet.
+ */
+ if (cs->brk != cs->top) {
+ /* mprotect() requires page-aligned arguments, but it's possible
+ * for cs->brk not to be page-aligned at this point.
+ */
+ char *prot_brk = (char *)ALIGN_UP(cs->brk, pagesize);
+ if ((mprotect(base, prot_brk - (char *)base, PROT_READ | PROT_WRITE) < 0) ||
+ (mprotect(prot_brk, cs->top - prot_brk, PROT_NONE) < 0)) {
+ goto error;
+ }
+ }
+
+ cs->m = m;
+ cs->magic = CONTIG_STATE_MAGIC;
+
+ return (mspace)m;
+
+error:
+ return (mspace)0;
+}
+
+
+mspace create_contiguous_mspace_with_name(size_t starting_capacity,
+ size_t max_capacity, int locked, char const *name) {
+ int fd, ret;
char buf[ASHMEM_NAME_LEN] = "mspace";
void *base;
unsigned int pagesize;
@@ -173,47 +236,12 @@
*/
assert(((uintptr_t)base & (pagesize-1)) == 0);
- /* Reserve some space for the information that our MORECORE needs.
- */
- cs = base;
-
- /* Create the mspace, pointing to the memory we just reserved.
- */
- m = create_mspace_with_base(base + sizeof(*cs), starting_capacity, locked);
- if (m == (mspace)0)
- goto error;
-
- /* Make sure that m is in the same page as cs.
- */
- assert(((uintptr_t)m & (uintptr_t)~(pagesize-1)) == (uintptr_t)base);
-
- /* Find out exactly how much of the memory the mspace
- * is using.
- */
- cs->brk = m->seg.base + m->seg.size;
- cs->top = (char *)base + max_capacity;
- assert((char *)base <= cs->brk);
- assert(cs->brk <= cs->top);
-
- /* Prevent access to the memory we haven't handed out yet.
- */
- if (cs->brk != cs->top) {
- /* mprotect() requires page-aligned arguments, but it's possible
- * for cs->brk not to be page-aligned at this point.
- */
- char *prot_brk = (char *)ALIGN_UP(cs->brk, pagesize);
- if (mprotect(prot_brk, cs->top - prot_brk, PROT_NONE) < 0)
- goto error;
+ m = create_contiguous_mspace_with_base(starting_capacity, max_capacity,
+ locked, base);
+ if (m == 0) {
+ munmap(base, max_capacity);
}
-
- cs->m = m;
- cs->magic = CONTIG_STATE_MAGIC;
-
- return (mspace)m;
-
-error:
- munmap(base, max_capacity);
- return (mspace)0;
+ return m;
}
mspace create_contiguous_mspace(size_t starting_capacity,
diff --git a/libcutils/open_memstream.c b/libcutils/open_memstream.c
new file mode 100644
index 0000000..5b4388a
--- /dev/null
+++ b/libcutils/open_memstream.c
@@ -0,0 +1,381 @@
+/*
+ * 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 HAVE_OPEN_MEMSTREAM
+
+/*
+ * Implementation of the POSIX open_memstream() function, which Linux has
+ * but BSD lacks.
+ *
+ * Summary:
+ * - Works like a file-backed FILE* opened with fopen(name, "w"), but the
+ * backing is a chunk of memory rather than a file.
+ * - The buffer expands as you write more data. Seeking past the end
+ * of the file and then writing to it zero-fills the gap.
+ * - The values at "*bufp" and "*sizep" should be considered read-only,
+ * and are only valid immediately after an fflush() or fclose().
+ * - A '\0' is maintained just past the end of the file. This is not included
+ * in "*sizep". (The behavior w.r.t. fseek() is not clearly defined.
+ * The spec says the null byte is written when a write() advances EOF,
+ * but it looks like glibc ensures the null byte is always found at EOF,
+ * even if you just seeked backwards. The example on the opengroup.org
+ * page suggests that this is the expected behavior. The null must be
+ * present after a no-op fflush(), which we can't see, so we have to save
+ * and restore it. Annoying, but allows file truncation.)
+ * - After fclose(), the caller must eventually free(*bufp).
+ *
+ * This is built out of funopen(), which BSD has but Linux lacks. There is
+ * no flush() operator, so we need to keep the user pointers up to date
+ * after each operation.
+ *
+ * I don't think Windows has any of the above, but we don't need to use
+ * them there, so we just supply a stub.
+ */
+#include <cutils/open_memstream.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#if 0
+# define DBUG(x) printf x
+#else
+# define DBUG(x) ((void)0)
+#endif
+
+#ifdef HAVE_FUNOPEN
+
+/*
+ * Definition of a seekable, write-only memory stream.
+ */
+typedef struct {
+ char** bufp; /* pointer to buffer pointer */
+ size_t* sizep; /* pointer to eof */
+
+ size_t allocSize; /* size of buffer */
+ size_t eof; /* furthest point we've written to */
+ size_t offset; /* current write offset */
+ char saved; /* required by NUL handling */
+} MemStream;
+
+#define kInitialSize 1024
+
+/*
+ * Ensure that we have enough storage to write "size" bytes at the
+ * current offset. We also have to take into account the extra '\0'
+ * that we maintain just past EOF.
+ *
+ * Returns 0 on success.
+ */
+static int ensureCapacity(MemStream* stream, int writeSize)
+{
+ DBUG(("+++ ensureCap off=%d size=%d\n", stream->offset, writeSize));
+
+ size_t neededSize = stream->offset + writeSize + 1;
+ if (neededSize <= stream->allocSize)
+ return 0;
+
+ size_t newSize;
+
+ if (stream->allocSize == 0) {
+ newSize = kInitialSize;
+ } else {
+ newSize = stream->allocSize;
+ newSize += newSize / 2; /* expand by 3/2 */
+ }
+
+ if (newSize < neededSize)
+ newSize = neededSize;
+ DBUG(("+++ realloc %p->%p to size=%d\n",
+ stream->bufp, *stream->bufp, newSize));
+ char* newBuf = (char*) realloc(*stream->bufp, newSize);
+ if (newBuf == NULL)
+ return -1;
+
+ *stream->bufp = newBuf;
+ stream->allocSize = newSize;
+ return 0;
+}
+
+/*
+ * Write data to a memstream, expanding the buffer if necessary.
+ *
+ * If we previously seeked beyond EOF, zero-fill the gap.
+ *
+ * Returns the number of bytes written.
+ */
+static int write_memstream(void* cookie, const char* buf, int size)
+{
+ MemStream* stream = (MemStream*) cookie;
+
+ if (ensureCapacity(stream, size) < 0)
+ return -1;
+
+ /* seeked past EOF earlier? */
+ if (stream->eof < stream->offset) {
+ DBUG(("+++ zero-fill gap from %d to %d\n",
+ stream->eof, stream->offset-1));
+ memset(*stream->bufp + stream->eof, '\0',
+ stream->offset - stream->eof);
+ }
+
+ /* copy data, advance write pointer */
+ memcpy(*stream->bufp + stream->offset, buf, size);
+ stream->offset += size;
+
+ if (stream->offset > stream->eof) {
+ /* EOF has advanced, update it and append null byte */
+ DBUG(("+++ EOF advanced to %d, appending nul\n", stream->offset));
+ assert(stream->offset < stream->allocSize);
+ stream->eof = stream->offset;
+ } else {
+ /* within previously-written area; save char we're about to stomp */
+ DBUG(("+++ within written area, saving '%c' at %d\n",
+ *(*stream->bufp + stream->offset), stream->offset));
+ stream->saved = *(*stream->bufp + stream->offset);
+ }
+ *(*stream->bufp + stream->offset) = '\0';
+ *stream->sizep = stream->offset;
+
+ return size;
+}
+
+/*
+ * Seek within a memstream.
+ *
+ * Returns the new offset, or -1 on failure.
+ */
+static fpos_t seek_memstream(void* cookie, fpos_t offset, int whence)
+{
+ MemStream* stream = (MemStream*) cookie;
+ off_t newPosn = (off_t) offset;
+
+ if (whence == SEEK_CUR) {
+ newPosn += stream->offset;
+ } else if (whence == SEEK_END) {
+ newPosn += stream->eof;
+ }
+
+ if (newPosn < 0 || ((fpos_t)((size_t) newPosn)) != newPosn) {
+ /* bad offset - negative or huge */
+ DBUG(("+++ bogus seek offset %ld\n", (long) newPosn));
+ errno = EINVAL;
+ return (fpos_t) -1;
+ }
+
+ if (stream->offset < stream->eof) {
+ /*
+ * We were pointing to an area we'd already written to, which means
+ * we stomped on a character and must now restore it.
+ */
+ DBUG(("+++ restoring char '%c' at %d\n",
+ stream->saved, stream->offset));
+ *(*stream->bufp + stream->offset) = stream->saved;
+ }
+
+ stream->offset = (size_t) newPosn;
+
+ if (stream->offset < stream->eof) {
+ /*
+ * We're seeked backward into the stream. Preserve the character
+ * at EOF and stomp it with a NUL.
+ */
+ stream->saved = *(*stream->bufp + stream->offset);
+ *(*stream->bufp + stream->offset) = '\0';
+ *stream->sizep = stream->offset;
+ } else {
+ /*
+ * We're positioned at, or possibly beyond, the EOF. We want to
+ * publish the current EOF, not the current position.
+ */
+ *stream->sizep = stream->eof;
+ }
+
+ return newPosn;
+}
+
+/*
+ * Close the memstream. We free everything but the data buffer.
+ */
+static int close_memstream(void* cookie)
+{
+ free(cookie);
+ return 0;
+}
+
+/*
+ * Prepare a memstream.
+ */
+FILE* open_memstream(char** bufp, size_t* sizep)
+{
+ FILE* fp;
+ MemStream* stream;
+
+ if (bufp == NULL || sizep == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ stream = (MemStream*) calloc(1, sizeof(MemStream));
+ if (stream == NULL)
+ return NULL;
+
+ fp = funopen(stream,
+ NULL, write_memstream, seek_memstream, close_memstream);
+ if (fp == NULL) {
+ free(stream);
+ return NULL;
+ }
+
+ *sizep = 0;
+ *bufp = NULL;
+ stream->bufp = bufp;
+ stream->sizep = sizep;
+
+ return fp;
+}
+
+#else /*not HAVE_FUNOPEN*/
+FILE* open_memstream(char** bufp, size_t* sizep)
+{
+ abort();
+}
+#endif /*HAVE_FUNOPEN*/
+
+
+
+#if 0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Simple regression test.
+ *
+ * To test on desktop Linux with valgrind, it's possible to make a simple
+ * change to open_memstream() to use fopencookie instead:
+ *
+ * cookie_io_functions_t iofuncs =
+ * { NULL, write_memstream, seek_memstream, close_memstream };
+ * fp = fopencookie(stream, "w", iofuncs);
+ *
+ * (Some tweaks to seek_memstream are also required, as that takes a
+ * pointer to an offset rather than an offset, and returns 0 or -1.)
+ */
+int testMemStream(void)
+{
+ FILE *stream;
+ char *buf;
+ size_t len;
+ off_t eob;
+
+ printf("Test1\n");
+
+ /* std example */
+ stream = open_memstream(&buf, &len);
+ fprintf(stream, "hello my world");
+ fflush(stream);
+ printf("buf=%s, len=%zu\n", buf, len);
+ eob = ftello(stream);
+ fseeko(stream, 0, SEEK_SET);
+ fprintf(stream, "good-bye");
+ fseeko(stream, eob, SEEK_SET);
+ fclose(stream);
+ printf("buf=%s, len=%zu\n", buf, len);
+ free(buf);
+
+ printf("Test2\n");
+
+ /* std example without final seek-to-end */
+ stream = open_memstream(&buf, &len);
+ fprintf(stream, "hello my world");
+ fflush(stream);
+ printf("buf=%s, len=%zu\n", buf, len);
+ eob = ftello(stream);
+ fseeko(stream, 0, SEEK_SET);
+ fprintf(stream, "good-bye");
+ //fseeko(stream, eob, SEEK_SET);
+ fclose(stream);
+ printf("buf=%s, len=%zu\n", buf, len);
+ free(buf);
+
+ printf("Test3\n");
+
+ /* fancy example; should expand buffer with writes */
+ static const int kCmpLen = 1024 + 128;
+ char* cmp = malloc(kCmpLen);
+ memset(cmp, 0, 1024);
+ memset(cmp+1024, 0xff, kCmpLen-1024);
+ sprintf(cmp, "This-is-a-tes1234");
+ sprintf(cmp + 1022, "abcdef");
+
+ stream = open_memstream (&buf, &len);
+ setvbuf(stream, NULL, _IONBF, 0); /* note: crashes in glibc with this */
+ fprintf(stream, "This-is-a-test");
+ fseek(stream, -1, SEEK_CUR); /* broken in glibc; can use {13,SEEK_SET} */
+ fprintf(stream, "1234");
+ fseek(stream, 1022, SEEK_SET);
+ fputc('a', stream);
+ fputc('b', stream);
+ fputc('c', stream);
+ fputc('d', stream);
+ fputc('e', stream);
+ fputc('f', stream);
+ fflush(stream);
+
+ if (memcmp(buf, cmp, len+1) != 0) {
+ printf("mismatch\n");
+ } else {
+ printf("match\n");
+ }
+
+ printf("Test4\n");
+ stream = open_memstream (&buf, &len);
+ fseek(stream, 5000, SEEK_SET);
+ fseek(stream, 4096, SEEK_SET);
+ fseek(stream, -1, SEEK_SET); /* should have no effect */
+ fputc('x', stream);
+ if (ftell(stream) == 4097)
+ printf("good\n");
+ else
+ printf("BAD: offset is %ld\n", ftell(stream));
+
+ printf("DONE\n");
+
+ return 0;
+}
+
+/* expected output:
+Test1
+buf=hello my world, len=14
+buf=good-bye world, len=14
+Test2
+buf=hello my world, len=14
+buf=good-bye, len=8
+Test3
+match
+Test4
+good
+DONE
+*/
+
+#endif
+
+#endif /*!HAVE_OPEN_MEMSTREAM*/
diff --git a/libcutils/process_name.c b/libcutils/process_name.c
index 17f52e2..b235429 100644
--- a/libcutils/process_name.c
+++ b/libcutils/process_name.c
@@ -22,6 +22,10 @@
#include <sys/stat.h>
#include <fcntl.h>
+#if defined(HAVE_PRCTL)
+#include <sys/prctl.h>
+#endif
+
#define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name"
static const char* process_name = "unknown";
@@ -35,10 +39,19 @@
}
// We never free the old name. Someone else could be using it.
- char* copy = (char*) malloc(strlen(new_name) + 1);
+ int len = strlen(new_name);
+ char* copy = (char*) malloc(len + 1);
strcpy(copy, new_name);
process_name = (const char*) copy;
+#if defined(HAVE_PRCTL)
+ if (len < 16) {
+ prctl(PR_SET_NAME, (unsigned long) new_name, 0, 0, 0);
+ } else {
+ prctl(PR_SET_NAME, (unsigned long) new_name + len - 15, 0, 0, 0);
+ }
+#endif
+
// If we know we are not running in the emulator, then return.
if (running_in_emulator == 0) {
return;
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 64d9bb7..2333762 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -53,13 +53,22 @@
sprintf(path, "/dev/cpuctl/%s/tasks", grp_name);
if ((fd = open(path, O_WRONLY)) < 0) {
- LOGE("add_tid_to_cgroup failed to open '%s' (%s)\n", path, strerror(errno));
+ LOGE("add_tid_to_cgroup failed to open '%s' (%s)\n", path,
+ strerror(errno));
return -1;
}
sprintf(text, "%d", tid);
if (write(fd, text, strlen(text)) < 0) {
close(fd);
+ /*
+ * If the thread is in the process of exiting,
+ * don't flag an error
+ */
+ if (errno == ESRCH)
+ return 0;
+ LOGW("add_tid_to_cgroup failed to write '%s' (%s)\n", path,
+ strerror(errno));
return -1;
}
@@ -81,8 +90,9 @@
/*
* Try to get the scheduler group.
*
- * The data from /proc/<pid>/cgroup looks like:
+ * The data from /proc/<pid>/cgroup looks (something) like:
* 2:cpu:/bg_non_interactive
+ * 1:cpuacct:/
*
* We return the part after the "/", which will be an empty string for
* the default cgroup. If the string is longer than "bufLen", the string
@@ -92,34 +102,57 @@
{
#ifdef HAVE_ANDROID_OS
char pathBuf[32];
- char readBuf[256];
- ssize_t count;
- int fd;
+ char lineBuf[256];
+ FILE *fp;
snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/cgroup", tid);
- if ((fd = open(pathBuf, O_RDONLY)) < 0) {
+ if (!(fp = fopen(pathBuf, "r"))) {
return -1;
}
- count = read(fd, readBuf, sizeof(readBuf));
- if (count <= 0) {
- close(fd);
- errno = ENODATA;
- return -1;
- }
- close(fd);
+ while(fgets(lineBuf, sizeof(lineBuf) -1, fp)) {
+ char *next = lineBuf;
+ char *subsys;
+ char *grp;
+ size_t len;
- readBuf[--count] = '\0'; /* remove the '\n', now count==strlen */
+ /* Junk the first field */
+ if (!strsep(&next, ":")) {
+ goto out_bad_data;
+ }
- char* cp = strchr(readBuf, '/');
- if (cp == NULL) {
- readBuf[sizeof(readBuf)-1] = '\0';
- errno = ENODATA;
- return -1;
+ if (!(subsys = strsep(&next, ":"))) {
+ goto out_bad_data;
+ }
+
+ if (strcmp(subsys, "cpu")) {
+ /* Not the subsys we're looking for */
+ continue;
+ }
+
+ if (!(grp = strsep(&next, ":"))) {
+ goto out_bad_data;
+ }
+ grp++; /* Drop the leading '/' */
+ len = strlen(grp);
+ grp[len-1] = '\0'; /* Drop the trailing '\n' */
+
+ if (bufLen <= len) {
+ len = bufLen - 1;
+ }
+ strncpy(buf, grp, len);
+ buf[len] = '\0';
+ fclose(fp);
+ return 0;
}
- memcpy(buf, cp+1, count); /* count-1 for cp+1, count+1 for NUL */
- return 0;
+ LOGE("Failed to find cpu subsys");
+ fclose(fp);
+ return -1;
+ out_bad_data:
+ LOGE("Bad cgroup data {%s}", lineBuf);
+ fclose(fp);
+ return -1;
#else
errno = ENOSYS;
return -1;
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 241dbf0..9923bba 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -27,6 +27,7 @@
#include <cutils/logger.h>
#include <cutils/logd.h>
+#include <cutils/log.h>
#define LOG_BUF_SIZE 1024
@@ -41,21 +42,13 @@
#define log_close(filedes) close(filedes)
#endif
-typedef enum {
- LOG_ID_MAIN = 0,
- LOG_ID_RADIO,
- LOG_ID_EVENTS,
- LOG_ID_MAX
-} log_id_t;
-
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
-static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) =
- __write_to_log_init;
+static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
#ifdef HAVE_PTHREADS
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
-static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1 };
+static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 };
/*
* This is used by the C++ code to decide if it should write logs through
@@ -110,6 +103,7 @@
log_fds[LOG_ID_MAIN] = log_open("/dev/"LOGGER_LOG_MAIN, O_WRONLY);
log_fds[LOG_ID_RADIO] = log_open("/dev/"LOGGER_LOG_RADIO, O_WRONLY);
log_fds[LOG_ID_EVENTS] = log_open("/dev/"LOGGER_LOG_EVENTS, O_WRONLY);
+ log_fds[LOG_ID_SYSTEM] = log_open("/dev/"LOGGER_LOG_SYSTEM, O_WRONLY);
write_to_log = __write_to_log_kernel;
@@ -123,6 +117,10 @@
log_fds[LOG_ID_EVENTS] = -1;
write_to_log = __write_to_log_null;
}
+
+ if (log_fds[LOG_ID_SYSTEM] < 0) {
+ log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
+ }
}
#ifdef HAVE_PTHREADS
@@ -161,6 +159,34 @@
return write_to_log(log_id, vec, 3);
}
+int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
+{
+ struct iovec vec[3];
+
+ if (!tag)
+ tag = "";
+
+ /* XXX: This needs to go! */
+ if (!strcmp(tag, "HTC_RIL") ||
+ !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
+ !strcmp(tag, "AT") ||
+ !strcmp(tag, "GSM") ||
+ !strcmp(tag, "STK") ||
+ !strcmp(tag, "CDMA") ||
+ !strcmp(tag, "PHONE") ||
+ !strcmp(tag, "SMS"))
+ bufID = LOG_ID_RADIO;
+
+ vec[0].iov_base = (unsigned char *) &prio;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = (void *) tag;
+ vec[1].iov_len = strlen(tag) + 1;
+ vec[2].iov_base = (void *) msg;
+ vec[2].iov_len = strlen(msg) + 1;
+
+ return write_to_log(bufID, vec, 3);
+}
+
int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
{
char buf[LOG_BUF_SIZE];
@@ -173,7 +199,7 @@
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
{
va_list ap;
- char buf[LOG_BUF_SIZE];
+ char buf[LOG_BUF_SIZE];
va_start(ap, fmt);
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
@@ -182,6 +208,18 @@
return __android_log_write(prio, tag, buf);
}
+int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[LOG_BUF_SIZE];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+ va_end(ap);
+
+ return __android_log_buf_write(bufID, prio, tag, buf);
+}
+
void __android_log_assert(const char *cond, const char *tag,
const char *fmt, ...)
{
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 080f9e3..5ddda36 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -840,7 +840,7 @@
* Returns count bytes written
*/
-int android_log_filterAndPrintLogLine(
+int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry)
@@ -850,11 +850,6 @@
char *outBuffer = NULL;
size_t totalLen;
- if (0 == android_log_shouldPrintLine(p_format, entry->tag,
- entry->priority)) {
- return 0;
- }
-
outBuffer = android_log_formatLogLine(p_format, defaultBuffer,
sizeof(defaultBuffer), entry, &totalLen);
diff --git a/libmincrypt/tools/DumpPublicKey.java b/libmincrypt/tools/DumpPublicKey.java
index c9e7e4d..d2935e0 100644
--- a/libmincrypt/tools/DumpPublicKey.java
+++ b/libmincrypt/tools/DumpPublicKey.java
@@ -77,7 +77,7 @@
// Write out modulus as little endian array of integers.
result.append(",{");
for (int i = 0; i < nwords; ++i) {
- int n = N.mod(B).intValue();
+ long n = N.mod(B).longValue();
result.append(n);
if (i != nwords - 1) {
@@ -91,7 +91,7 @@
// Write R^2 as little endian array of integers.
result.append(",{");
for (int i = 0; i < nwords; ++i) {
- int rr = RR.mod(B).intValue();
+ long rr = RR.mod(B).longValue();
result.append(rr);
if (i != nwords - 1) {
diff --git a/libnetutils/dhcp_utils.c b/libnetutils/dhcp_utils.c
index bad2e2f..0f8a6c4 100644
--- a/libnetutils/dhcp_utils.c
+++ b/libnetutils/dhcp_utils.c
@@ -24,8 +24,9 @@
#include <cutils/properties.h>
-static const char DAEMON_NAME[] = "dhcpcd";
-static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
+static const char DAEMON_NAME[] = "dhcpcd";
+static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
+static const char HOSTNAME_PROP_NAME[] = "net.hostname";
static const char DHCP_PROP_NAME_PREFIX[] = "dhcp";
static const int NAP_TIME = 1; /* wait for 1 second at a time */
/* when polling for property values */
@@ -129,6 +130,7 @@
{
char result_prop_name[PROPERTY_KEY_MAX];
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
+ char daemon_cmd[PROPERTY_VALUE_MAX * 2];
const char *ctrl_prop = "ctl.start";
const char *desired_status = "running";
@@ -139,7 +141,13 @@
property_set(result_prop_name, "");
/* Start the daemon and wait until it's ready */
- property_set(ctrl_prop, DAEMON_NAME);
+ if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0'))
+ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:-h %s %s", DAEMON_NAME,
+ prop_value, interface);
+ else
+ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:%s", DAEMON_NAME, interface);
+ memset(prop_value, '\0', PROPERTY_VALUE_MAX);
+ property_set(ctrl_prop, daemon_cmd);
if (wait_for_property(DAEMON_PROP_NAME, desired_status, 10) < 0) {
snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start");
return -1;
diff --git a/libpixelflinger/format.cpp b/libpixelflinger/format.cpp
index 161e6d6..6546e8c 100644
--- a/libpixelflinger/format.cpp
+++ b/libpixelflinger/format.cpp
@@ -40,12 +40,12 @@
{ 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
{ 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
- { 1, 16, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_SP },// PIXEL_FORMAT_YCbCr_422_SP
- { 1, 12, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_SP },// PIXEL_FORMAT_YCbCr_420_SP
- { 1, 16, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_P }, // PIXEL_FORMAT_YCbCr_422_P
- { 1, 12, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_P }, // PIXEL_FORMAT_YCbCr_420_P
- { 1, 16, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_I }, // PIXEL_FORMAT_YCbCr_422_I
- { 1, 12, {{ 0, 8, 0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_I }, // PIXEL_FORMAT_YCbCr_420_I
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
{ 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
{ 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
@@ -53,6 +53,15 @@
{ 1, 8, {{ 8, 0, 0, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX },
{ 4, 24, {{ 0, 0, 24, 0, 0, 0, 0, 0 }}, GGL_DEPTH_COMPONENT},
{ 4, 8, {{ 32,24, 0, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX },
+
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+ { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE
+
};
}; // namespace android
diff --git a/libpixelflinger/pixelflinger.cpp b/libpixelflinger/pixelflinger.cpp
index b54da0c..84e584e 100644
--- a/libpixelflinger/pixelflinger.cpp
+++ b/libpixelflinger/pixelflinger.cpp
@@ -281,6 +281,7 @@
const int32_t r = gglClampx(color[0]);
const int32_t g = gglClampx(color[1]);
const int32_t b = gglClampx(color[2]);
+ c->state.fog.color[GGLFormat::ALPHA]= 0xFF; // unused
c->state.fog.color[GGLFormat::RED] = (r - (r>>8))>>8;
c->state.fog.color[GGLFormat::GREEN]= (g - (g>>8))>>8;
c->state.fog.color[GGLFormat::BLUE] = (b - (b>>8))>>8;
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index 5f959a7..1550d83 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -46,6 +46,16 @@
}
}
+void NetlinkEvent::dump() {
+ int i;
+
+ for (i = 0; i < NL_PARAMS_MAX; i++) {
+ if (!mParams[i])
+ break;
+ LOGD("NL param '%s'\n", mParams[i]);
+ }
+}
+
bool NetlinkEvent::decode(char *buffer, int size) {
char *s = buffer;
char *end;
diff --git a/logcat/Android.mk b/logcat/Android.mk
index 5a9f12d..7b8eb01 100644
--- a/logcat/Android.mk
+++ b/logcat/Android.mk
@@ -3,24 +3,10 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= logcat.cpp
+LOCAL_SRC_FILES:= logcat.cpp event.logtags
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE:= logcat
include $(BUILD_EXECUTABLE)
-
-########################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := event-log-tags
-
-# This will install the file in /system/etc
-#
-LOCAL_MODULE_CLASS := ETC
-
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_PREBUILT_STRIP_COMMENTS := 1
-
-include $(BUILD_PREBUILT)
diff --git a/logcat/event-log-tags b/logcat/event-log-tags
deleted file mode 100644
index 2140b37..0000000
--- a/logcat/event-log-tags
+++ /dev/null
@@ -1,399 +0,0 @@
-# The entries in this file map a sparse set of log tag numbers to tag names.
-# This is installed on the device, in /system/etc, and parsed by logcat.
-#
-# Tag numbers are decimal integers, from 0 to 2^31. (Let's leave the
-# negative values alone for now.)
-#
-# Tag names are one or more ASCII letters and numbers or underscores, i.e.
-# "[A-Z][a-z][0-9]_". Do not include spaces or punctuation (the former
-# impacts log readability, the latter makes regex searches more annoying).
-#
-# Tag numbers and names are separated by whitespace. Blank lines and lines
-# starting with '#' are ignored.
-#
-# Optionally, after the tag names can be put a description for the value(s)
-# of the tag. Description are in the format
-# (<name>|data type[|data unit])
-# Multiple values are separated by commas.
-#
-# The data type is a number from the following values:
-# 1: int
-# 2: long
-# 3: string
-# 4: list
-#
-# The data unit is a number taken from the following list:
-# 1: Number of objects
-# 2: Number of bytes
-# 3: Number of milliseconds
-# 4: Number of allocations
-# 5: Id
-# 6: Percent
-# Default value for data of type int/long is 2 (bytes).
-#
-# TODO: generate ".java" and ".h" files with integer constants from this file.
-
-# These are used for testing, do not modify without updating
-# tests/framework-tests/src/android/util/EventLogFunctionalTest.java.
-42 answer (to life the universe etc|3)
-314 pi
-2718 e
-
-2719 configuration_changed (config mask|1|5)
-# "account" is the java hash of the account name
-2720 sync (id|3),(event|1|5),(source|1|5),(account|1|5)
-2721 cpu (total|1|6),(user|1|6),(system|1|6),(iowait|1|6),(irq|1|6),(softirq|1|6)
-2722 battery_level (level|1|6),(voltage|1|1),(temperature|1|1)
-2723 battery_status (status|1|5),(health|1|5),(present|1|5),(plugged|1|5),(technology|3)
-# This is logged when the device is being forced to sleep (typically by
-# the user pressing the power button).
-2724 power_sleep_requested (wakeLocksCleared|1|1)
-# This is logged when the screen on broadcast has completed
-2725 power_screen_broadcast_send (wakelockCount|1|1)
-# This is logged when the screen broadcast has completed
-2726 power_screen_broadcast_done (on|1|5),(broadcastDuration|2|3),(wakelockCount|1|1)
-# This is logged when the screen on broadcast has completed
-2727 power_screen_broadcast_stop (which|1|5),(wakelockCount|1|1)
-# This is logged when the screen is turned on or off.
-2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1)
-# This is logged when the partial wake lock (keeping the device awake
-# regardless of whether the screen is off) is acquired or released.
-2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3)
-# This is logged when battery goes from discharging to charging.
-# It lets us count the total amount of time between charges and the discharge level
-2730 battery_discharge (duration|2|3),(minLevel|1|6),(maxLevel|1|6)
-#
-# Leave IDs through 2739 for more power logs
-#
-
-# This event is logged when the location service uploads location data.
-2740 location_controller
-# This event is logged when someone is deciding to force a garbage collection
-2741 force_gc (reason|3)
-# This event is logged on each tickle
-2742 tickle (authority|3)
-# What happens in a sync operation (bytes sent and received, and
-# operation details)
-2743 sync_details (authority|3),(send|1|2),(recv|1|2),(details|3)
-
-# The disk space free on the /data partition, in bytes
-2744 free_storage_changed (data|2|2)
-# Device low memory notification and disk space free on the /data partition, in bytes at that time
-2745 low_storage (data|2|2)
-# disk space free on the /data, /system, and /cache partitions in bytes
-2746 free_storage_left (data|2|2),(system|2|2),(cache|2|2)
-
-# contacts aggregation: time and number of contacts.
-# count is negative for query phase, positive for merge phase
-2747 contacts_aggregation (aggregation time|2|3), (count|1|1)
-
-# when a NotificationManager.notify is called
-2750 notification_enqueue (pkg|3),(id|1|5),(notification|3)
-# when someone tries to cancel a notification, the notification manager sometimes
-# calls this with flags too
-2751 notification_cancel (pkg|3),(id|1|5),(required_flags|1)
-# when someone tries to cancel all of the notifications for a particular package
-2752 notification_cancel_all (pkg|3),(required_flags|1)
-
-# This event is logged when GTalkService encounters important events
-2800 gtalkservice (eventType|1)
-# This event is logged for GTalk connection state changes. The status field is an int, but
-# it really contains 4 separate values, each taking up a byte
-# (eventType << 24) + (connection state << 16) + (connection error << 8) + network state
-2801 gtalk_connection (status|1)
-
-2802 watchdog (Service|3)
-2803 watchdog_proc_pss (Process|3),(Pid|1|5),(Pss|1|2)
-2804 watchdog_soft_reset (Process|3),(Pid|1|5),(MaxPss|1|2),(Pss|1|2),(Skip|3)
-2805 watchdog_hard_reset (Process|3),(Pid|1|5),(MaxPss|1|2),(Pss|1|2)
-2806 watchdog_pss_stats (EmptyPss|1|2),(EmptyCount|1|1),(BackgroundPss|1|2),(BackgroundCount|1|1),(ServicePss|1|2),(ServiceCount|1|1),(VisiblePss|1|2),(VisibleCount|1|1),(ForegroundPss|1|2),(ForegroundCount|1|1),(NoPssCount|1|1)
-2807 watchdog_proc_stats (DeathsInOne|1|1),(DeathsInTwo|1|1),(DeathsInThree|1|1),(DeathsInFour|1|1),(DeathsInFive|1|1)
-2808 watchdog_scheduled_reboot (Now|2|1),(Interval|1|3),(StartTime|1|3),(Window|1|3),(Skip|3)
-2809 watchdog_meminfo (MemFree|1|2),(Buffers|1|2),(Cached|1|2),(Active|1|2),(Inactive|1|2),(AnonPages|1|2),(Mapped|1|2),(Slab|1|2),(SReclaimable|1|2),(SUnreclaim|1|2),(PageTables|1|2)
-2810 watchdog_vmstat (runtime|2|3),(pgfree|1|1),(pgactivate|1|1),(pgdeactivate|1|1),(pgfault|1|1),(pgmajfault|1|1)
-2811 watchdog_requested_reboot (NoWait|1|1),(ScheduleInterval|1|3),(RecheckInterval|1|3),(StartTime|1|3),(Window|1|3),(MinScreenOff|1|3),(MinNextAlarm|1|3)
-
-2820 backup_data_changed (Package|3)
-2821 backup_start (Transport|3)
-2822 backup_transport_failure (Package|3)
-2823 backup_agent_failure (Package|3),(Message|3)
-2824 backup_package (Package|3),(Size|1|2)
-2825 backup_success (Packages|1|1),(Time|1|3)
-2826 backup_reset (Transport|3)
-2827 backup_initialize
-
-2830 restore_start (Transport|3),(Source|2|5)
-2831 restore_transport_failure
-2832 restore_agent_failure (Package|3),(Message|3)
-2833 restore_package (Package|3),(Size|1|2)
-2834 restore_success (Packages|1|1),(Time|1|3)
-
-# Device boot timings. We include monotonic clock values because the
-# intrinsic event log times are wall-clock.
-#
-# Runtime starts:
-3000 boot_progress_start (time|2|3)
-# SystemServer.run() starts:
-3010 boot_progress_system_run (time|2|3)
-# ZygoteInit class preloading starts:
-3020 boot_progress_preload_start (time|2|3)
-# ZygoteInit class preloading ends:
-3030 boot_progress_preload_end (time|2|3)
-# ActivityManagerService.systemReady() starts:
-3040 boot_progress_ams_ready (time|2|3)
-# ActivityManagerService calls enableScreenAfterBoot():
-3050 boot_progress_enable_screen (time|2|3)
-# Package Manager starts:
-3060 boot_progress_pms_start (time|2|3)
-# Package Manager .apk scan starts:
-3070 boot_progress_pms_system_scan_start (time|2|3)
-# Package Manager .apk scan starts:
-3080 boot_progress_pms_data_scan_start (time|2|3)
-# Package Manager .apk scan ends:
-3090 boot_progress_pms_scan_end (time|2|3)
-# Package Manager ready:
-3100 boot_progress_pms_ready (time|2|3)
-# + check activity_launch_time for Home app
-
-# This event is logged when GTalk connection is closed.
-# The status field is an int, but contains 2 different values, it's represented as
-#
-# (networkType << 8) + connection error
-#
-# the possible error values are
-#
-# no_error=0, no_network=1, connection_failed=2, unknown_host=3, auth_failed=4,
-# auth_expired=5, heart_beat_timeout=6, server_error=7, server_reject_rate_limiting=8, unknown=10
-#
-# duration is the connection duration.
-4000 gtalk_conn_close (status|1),(duration|1)
-
-# This event is logged for GTalk heartbeat resets
-# interval_and_nt contains both the heartbeat interval and the network type, It's represented as
-# (networkType << 16) + interval
-# interval is in seconds; network type can be 0 (mobile) or 1 (wifi); ip is the host ip addr.
-4001 gtalk_heartbeat_reset (interval_and_nt|1),(ip|3)
-
-# dvm_gc_info: LIST (LONG, LONG, LONG)
-#
-# First LONG:
-#
-# [63] 1
-# [62-24] ASCII process identifier
-# [23-12] GC time in ms
-# [11- 0] Bytes freed
-#
-# Second LONG (aggregated heap info):
-#
-# [63-62] 10
-# [61-60] Reserved; must be zero
-# [59-48] Objects freed
-# [47-36] Actual size (current footprint)
-# [35-24] Allowed size (current hard max)
-# [23-12] Objects allocated
-# [11- 0] Bytes allocated
-#
-# Third LONG (zygote heap info):
-#
-# [63-62] 11
-# [61-60] Reserved; must be zero
-# [59-48] Soft limit
-# [47-36] Actual size (current footprint)
-# [35-24] Allowed size (current hard max)
-# [23-12] Objects allocated
-# [11- 0] Bytes allocated
-#
-# Fourth LONG:
-#
-# [63-48] Reserved; must be zero
-# [47-36] dlmallocFootprint
-# [35-24] mallinfo: total allocated space
-# [23-12] External byte limit
-# [11- 0] External bytes allocated
-#
-# See HeapDebug.c
-#
-20001 dvm_gc_info (custom|2),(custom|2),(custom|2),(custom|2)
-20002 dvm_gc_madvise_info (total|1|2),(zygote|1|2)
-
-# Do not change these names without updating the checkin_events setting in
-# google3/googledata/wireless/android/provisioning/gservices.config !!
-#
-# An activity is being finished:
-30001 am_finish_activity (Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)
-# A task is being brought to the front of the screen:
-30002 am_task_to_front (Task|1|5)
-# An existing activity is being given a new intent:
-30003 am_new_intent (Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)
-# A new task is being created:
-30004 am_create_task (Task ID|1|5)
-# A new activity is being created in an existing task:
-30005 am_create_activity (Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)
-# An activity has been resumed into the foreground but was not already running:
-30006 am_restart_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
-# An activity has been resumed and is now in the foreground:
-30007 am_resume_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
-# Application Not Responding
-30008 anr (pid|1|5),(Package Name|3),(reason|3)
-# Activity launch time
-30009 activity_launch_time (Token|1|5),(Component Name|3),(time|2|3)
-# Application process bound to work
-30010 am_proc_bound (PID|1|5),(Process Name|3)
-# Application process died
-30011 am_proc_died (PID|1|5),(Process Name|3)
-# The Activity Manager failed to pause the given activity.
-30012 am_failed_to_pause (Token|1|5),(Wanting to pause|3),(Currently pausing|3)
-# Attempting to pause the current activity
-30013 am_pause_activity (Token|1|5),(Component Name|3)
-# Application process has been started
-30014 am_proc_start (PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)
-# An application process has been marked as bad
-30015 am_proc_bad (UID|1|5),(Process Name|3)
-# An application process that was bad is now marked as good
-30016 am_proc_good (UID|1|5),(Process Name|3)
-# Reporting to applications that memory is low
-30017 am_low_memory (Num Processes|1|1)
-# An activity is being destroyed:
-30018 am_destroy_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
-# An activity has been relaunched, resumed, and is now in the foreground:
-30019 am_relaunch_resume_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
-# An activity has been relaunched:
-30020 am_relaunch_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
-# The activity's onPause has been called.
-30021 am_on_paused_called (Component Name|3)
-# The activity's onResume has been called.
-30022 am_on_resume_called (Component Name|3)
-# Kill a process to reclaim memory.
-30023 am_kill_for_memory (PID|1|5),(Process Name|3),(OomAdj|1|5)
-# Discard an undelivered serialized broadcast (timeout/ANR/crash)
-30024 am_broadcast_discard_filter (Broadcast|1|5),(Action|3),(Receiver Number|1|1),(BroadcastFilter|1|5)
-30025 am_broadcast_discard_app (Broadcast|1|5),(Action|3),(Receiver Number|1|1),(App|3)
-# A service is being created
-30030 am_create_service (Service Record|1|5),(Name|3),(Intent|3),(PID|1|5)
-# A service is being destroyed
-30031 am_destroy_service (Service Record|1|5),(Name|3),(PID|1|5)
-# A process has crashed too many times, it is being cleared
-30032 am_process_crashed_too_much (Name|3),(PID|1|5)
-# An unknown process is trying to attach to the activity manager
-30033 am_drop_process (PID|1|5)
-# A service has crashed too many times, it is being stopped
-30034 am_service_crashed_too_much (Crash Count|1|1),(Component Name|3),(PID|1|5)
-# A service is going to be restarted after its process went away
-30035 am_schedule_service_restart (Component Name|3),(Time|2|3)
-# A client was waiting for a content provider, but its process was lost
-30036 am_provider_lost_process (Package Name|3),(UID|1|5),(Name|3)
-
-# Out of memory for surfaces.
-31000 wm_no_surface_memory (Window|3),(PID|1|5),(Operation|3)
-
-# Re-connecting to input method service because we haven't received its interface
-32000 imf_force_reconnect_ime (IME|4),(Time Since Connect|2|3),(Showing|1|1)
-
-75000 sqlite_mem_alarm_current (current|1|2)
-75001 sqlite_mem_alarm_max (max|1|2)
-75002 sqlite_mem_alarm_alloc_attempt (attempts|1|4)
-75003 sqlite_mem_released (Memory released|1|2)
-75004 sqlite_db_corrupt (Database file corrupt|3)
-
-40000 checkin (Check in time|2|3)
-
-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)
-# Connectivity state changed:
-# [31-13] Reserved for future use
-# [12- 9] Network subtype (for mobile network, as defined by TelephonyManager)
-# [ 8- 3] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
-# [ 2- 0] Network type (as defined by ConnectivityManager)
-50020 connectivity_state_changed (custom|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)
-
-# PDP Context has a bad DNS address
-50100 pdp_bad_dns_address (dns_address|3)
-
-# For data connection on PDP context, reached the data-out-without-data-in
-# packet count that triggers a countdown to radio restart
-50101 pdp_radio_reset_countdown_triggered (out_packet_count|1|1)
-
-# Radio restart - timed out with no incoming packets.
-50102 pdp_radio_reset (out_packet_count|1|1)
-
-# PDP context reset - timed out with no incoming packets.
-50103 pdp_context_reset (out_packet_count|1|1)
-
-# Reregister to data network - timed out with no incoming packets.
-50104 pdp_reregister_network (out_packet_count|1|1)
-
-# PDP Setup failures
-50105 pdp_setup_fail (cause|1|5), (cid|1|5), (network_type|1|5)
-
-# Call drops
-50106 call_drop (cause|1|5), (cid|1|5), (network_type|1|5)
-
-# Data network registration failed after successful voice registration
-50107 data_network_registration_fail (op_numeric|1|5), (cid|1|5)
-
-# Suspicious status of data connection while radio poweroff
-50108 data_network_status_on_radio_off (dc_state|3), (enable|1|5)
-
-# PDP drop caused by network
-50109 pdp_network_drop (cid|1|5), (network_type|1|5)
-
-# CDMA data network setup failure
-50110 cdma_data_setup_failed (cause|1|5), (cid|1|5), (network_type|1|5)
-
-# CDMA data network drop
-50111 cdma_data_drop (cid|1|5), (network_type|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
-51000 socket_stats (send|1|2),(recv|1|2),(ip|1|5),(port|1|5),(close|1|5)
-
-# db stats. 0 is query, 1 is write (may become more fine grained in the
-# future)
-52000 db_operation (name|3),(op_type|1|5),(time|2|3)
-
-# http request/response stats
-52001 http_stats (useragent|3),(response|2|3),(processing|2|3),(tx|1|2),(rx|1|2)
-60000 viewroot_draw (Draw time|1|3)
-60001 viewroot_layout (Layout time|1|3)
-60002 view_build_drawing_cache (View created drawing cache|1|5)
-60003 view_use_drawing_cache (View drawn using bitmap cache|1|5)
-
-# 0 for screen off, 1 for screen on, 2 for key-guard done
-70000 screen_toggled (screen_state|1|5)
-
-# browser stats for diary study
-70101 browser_zoom_level_change (start level|1|5),(end level|1|5),(time|2|3)
-70102 browser_double_tap_duration (duration|1|3),(time|2|3)
-
-# aggregation service
-70200 aggregation (aggregation time|2|3)
-70201 aggregation_test (field1|1|2),(field2|1|2),(field3|1|2),(field4|1|2),(field5|1|2)
-
-# NOTE - the range 1000000-2000000 is reserved for partners and others who
-# want to define their own log tags without conflicting with the core platform.
diff --git a/logcat/event.logtags b/logcat/event.logtags
new file mode 100644
index 0000000..1b38f4c
--- /dev/null
+++ b/logcat/event.logtags
@@ -0,0 +1,172 @@
+# The entries in this file map a sparse set of log tag numbers to tag names.
+# This is installed on the device, in /system/etc, and parsed by logcat.
+#
+# Tag numbers are decimal integers, from 0 to 2^31. (Let's leave the
+# negative values alone for now.)
+#
+# Tag names are one or more ASCII letters and numbers or underscores, i.e.
+# "[A-Z][a-z][0-9]_". Do not include spaces or punctuation (the former
+# impacts log readability, the latter makes regex searches more annoying).
+#
+# Tag numbers and names are separated by whitespace. Blank lines and lines
+# starting with '#' are ignored.
+#
+# Optionally, after the tag names can be put a description for the value(s)
+# of the tag. Description are in the format
+# (<name>|data type[|data unit])
+# Multiple values are separated by commas.
+#
+# The data type is a number from the following values:
+# 1: int
+# 2: long
+# 3: string
+# 4: list
+#
+# The data unit is a number taken from the following list:
+# 1: Number of objects
+# 2: Number of bytes
+# 3: Number of milliseconds
+# 4: Number of allocations
+# 5: Id
+# 6: Percent
+# Default value for data of type int/long is 2 (bytes).
+#
+# TODO: generate ".java" and ".h" files with integer constants from this file.
+
+# These are used for testing, do not modify without updating
+# tests/framework-tests/src/android/util/EventLogFunctionalTest.java.
+42 answer (to life the universe etc|3)
+314 pi
+2718 e
+
+# "account" is the java hash of the account name
+2720 sync (id|3),(event|1|5),(source|1|5),(account|1|5)
+
+# This event is logged when the location service uploads location data.
+2740 location_controller
+# This event is logged when someone is deciding to force a garbage collection
+2741 force_gc (reason|3)
+# This event is logged on each tickle
+2742 tickle (authority|3)
+
+# contacts aggregation: time and number of contacts.
+# count is negative for query phase, positive for merge phase
+2747 contacts_aggregation (aggregation time|2|3), (count|1|1)
+
+# Device boot timings. We include monotonic clock values because the
+# intrinsic event log times are wall-clock.
+#
+# Runtime starts:
+3000 boot_progress_start (time|2|3)
+# ZygoteInit class preloading starts:
+3020 boot_progress_preload_start (time|2|3)
+# ZygoteInit class preloading ends:
+3030 boot_progress_preload_end (time|2|3)
+
+# dvm_gc_info: LIST (LONG, LONG, LONG)
+#
+# First LONG:
+#
+# [63] 1
+# [62-24] ASCII process identifier
+# [23-12] GC time in ms
+# [11- 0] Bytes freed
+#
+# Second LONG (aggregated heap info):
+#
+# [63-62] 10
+# [61-60] Reserved; must be zero
+# [59-48] Objects freed
+# [47-36] Actual size (current footprint)
+# [35-24] Allowed size (current hard max)
+# [23-12] Objects allocated
+# [11- 0] Bytes allocated
+#
+# Third LONG (zygote heap info):
+#
+# [63-62] 11
+# [61-60] Reserved; must be zero
+# [59-48] Soft limit
+# [47-36] Actual size (current footprint)
+# [35-24] Allowed size (current hard max)
+# [23-12] Objects allocated
+# [11- 0] Bytes allocated
+#
+# Fourth LONG:
+#
+# [63-48] Reserved; must be zero
+# [47-36] dlmallocFootprint
+# [35-24] mallinfo: total allocated space
+# [23-12] External byte limit
+# [11- 0] External bytes allocated
+#
+# See HeapDebug.c
+#
+20001 dvm_gc_info (custom|2),(custom|2),(custom|2),(custom|2)
+20002 dvm_gc_madvise_info (total|1|2),(zygote|1|2)
+
+75000 sqlite_mem_alarm_current (current|1|2)
+75001 sqlite_mem_alarm_max (max|1|2)
+75002 sqlite_mem_alarm_alloc_attempt (attempts|1|4)
+75003 sqlite_mem_released (Memory released|1|2)
+75004 sqlite_db_corrupt (Database file corrupt|3)
+
+40000 checkin (Check in time|2|3)
+
+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)
+
+# Do not change these names without updating tag in:
+#//device/dalvik/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.c
+51000 socket_stats (send|1|2),(recv|1|2),(ip|1|5),(port|1|5),(close|1|5)
+
+# Database operation samples.
+# db: the filename of the database
+# sql: the executed query (without query args)
+# time: cpu time millis (not wall time), including lock acquisition
+# blocking_package: if this is on a main thread, the package name, otherwise ""
+# sample_percent: the percent likelihood this query was logged
+52000 db_operation (db|3),(sql|3),(time|1|3),(blocking_package|3),(sample_percent|1|6)
+
+# http request/response stats
+52001 http_stats (useragent|3),(response|2|3),(processing|2|3),(tx|1|2),(rx|1|2)
+60000 viewroot_draw (Draw time|1|3)
+60001 viewroot_layout (Layout time|1|3)
+60002 view_build_drawing_cache (View created drawing cache|1|5)
+60003 view_use_drawing_cache (View drawn using bitmap cache|1|5)
+
+# 0 for screen off, 1 for screen on, 2 for key-guard done
+70000 screen_toggled (screen_state|1|5)
+
+# aggregation service
+70200 aggregation (aggregation time|2|3)
+70201 aggregation_test (field1|1|2),(field2|1|2),(field3|1|2),(field4|1|2),(field5|1|2)
+
+# NOTE - the range 1000000-2000000 is reserved for partners and others who
+# want to define their own log tags without conflicting with the core platform.
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 3130a1c..670408c 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -24,12 +24,64 @@
#define DEFAULT_MAX_ROTATED_LOGS 4
static AndroidLogFormat * g_logformat;
+static bool g_nonblock = false;
/* logd prefixes records with a length field */
#define RECORD_LENGTH_FIELD_SIZE_BYTES sizeof(uint32_t)
#define LOG_FILE_DIR "/dev/log/"
+struct queued_entry_t {
+ union {
+ unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1] __attribute__((aligned(4)));
+ struct logger_entry entry __attribute__((aligned(4)));
+ };
+ queued_entry_t* next;
+
+ queued_entry_t() {
+ next = NULL;
+ }
+};
+
+static int cmp(queued_entry_t* a, queued_entry_t* b) {
+ int n = a->entry.sec - b->entry.sec;
+ if (n != 0) {
+ return n;
+ }
+ return a->entry.nsec - b->entry.nsec;
+}
+
+struct log_device_t {
+ char* device;
+ bool binary;
+ int fd;
+ bool printed;
+ char label;
+
+ queued_entry_t* queue;
+ log_device_t* next;
+
+ log_device_t(char* d, bool b, char l) {
+ device = d;
+ binary = b;
+ label = l;
+ next = NULL;
+ printed = false;
+ }
+
+ void enqueue(queued_entry_t* entry) {
+ if (this->queue == NULL) {
+ this->queue = entry;
+ } else {
+ queued_entry_t** e = &this->queue;
+ while (*e && cmp(entry, *e) >= 0) {
+ e = &((*e)->next);
+ }
+ entry->next = *e;
+ *e = entry;
+ }
+ }
+};
namespace android {
@@ -40,8 +92,8 @@
static int g_maxRotatedLogs = DEFAULT_MAX_ROTATED_LOGS; // 0 means "unbounded"
static int g_outFD = -1;
static off_t g_outByteCount = 0;
-static int g_isBinary = 0;
static int g_printBinary = 0;
+static int g_devCount = 0;
static EventTagMap* g_eventTagMap = NULL;
@@ -103,14 +155,27 @@
} while (ret < 0 && errno == EINTR);
}
-static void processBuffer(struct logger_entry *buf)
+static void processBuffer(log_device_t* dev, struct logger_entry *buf)
{
int bytesWritten;
int err;
AndroidLogEntry entry;
char binaryMsgBuf[1024];
- if (g_isBinary) {
+ if (!dev->printed) {
+ dev->printed = true;
+ if (g_devCount > 1) {
+ snprintf(binaryMsgBuf, sizeof(binaryMsgBuf), "--------- beginning of %s\n",
+ dev->device);
+ bytesWritten = write(g_outFD, binaryMsgBuf, strlen(binaryMsgBuf));
+ if (bytesWritten < 0) {
+ perror("output error");
+ exit(-1);
+ }
+ }
+ }
+
+ if (dev->binary) {
err = android_log_processBinaryLogBuffer(buf, &entry, g_eventTagMap,
binaryMsgBuf, sizeof(binaryMsgBuf));
//printf(">>> pri=%d len=%d msg='%s'\n",
@@ -118,15 +183,27 @@
} else {
err = android_log_processLogBuffer(buf, &entry);
}
- if (err < 0)
+ if (err < 0) {
goto error;
+ }
- bytesWritten = android_log_filterAndPrintLogLine(
- g_logformat, g_outFD, &entry);
+ if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
+ if (false && g_devCount > 1) {
+ binaryMsgBuf[0] = dev->label;
+ binaryMsgBuf[1] = ' ';
+ bytesWritten = write(g_outFD, binaryMsgBuf, 2);
+ if (bytesWritten < 0) {
+ perror("output error");
+ exit(-1);
+ }
+ }
- if (bytesWritten < 0) {
- perror("output error");
- exit(-1);
+ bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);
+
+ if (bytesWritten < 0) {
+ perror("output error");
+ exit(-1);
+ }
}
g_outByteCount += bytesWritten;
@@ -142,36 +219,129 @@
return;
}
-static void readLogLines(int logfd)
+static void chooseFirst(log_device_t* dev, log_device_t** firstdev, queued_entry_t** firstentry) {
+ *firstdev = NULL;
+ *firstentry = NULL;
+ int i=0;
+ for (; dev; dev=dev->next) {
+ i++;
+ if (dev->queue) {
+ if ((*firstentry) == NULL || cmp(dev->queue, *firstentry) < 0) {
+ (*firstentry) = dev->queue;
+ *firstdev = dev;
+ }
+ }
+ }
+}
+
+static void printEntry(log_device_t* dev, queued_entry_t* entry) {
+ if (g_printBinary) {
+ printBinary(&entry->entry);
+ } else {
+ processBuffer(dev, &entry->entry);
+ }
+}
+
+static void eatEntry(log_device_t* dev, queued_entry_t* entry) {
+ if (dev->queue != entry) {
+ perror("assertion failed: entry isn't first in queue");
+ exit(1);
+ }
+ printEntry(dev, entry);
+ dev->queue = entry->next;
+ delete entry;
+}
+
+static void readLogLines(log_device_t* devices)
{
+ log_device_t* dev;
+ int max = 0;
+ queued_entry_t* entry;
+ queued_entry_t* old;
+ int ret;
+ bool somethingForEveryone;
+ bool sleep = true;
+
+ int result;
+ fd_set readset;
+
+ for (dev=devices; dev; dev = dev->next) {
+ if (dev->fd > max) {
+ max = dev->fd;
+ }
+ }
+
while (1) {
- unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1] __attribute__((aligned(4)));
- struct logger_entry *entry = (struct logger_entry *) buf;
- int ret;
+ do {
+ timeval timeout = { 0, 5000 /* 5ms */ }; // If we oversleep it's ok, i.e. ignore EINTR.
+ FD_ZERO(&readset);
+ for (dev=devices; dev; dev = dev->next) {
+ FD_SET(dev->fd, &readset);
+ }
+ result = select(max + 1, &readset, NULL, NULL, sleep ? NULL : &timeout);
+ } while (result == -1 && errno == EINTR);
- ret = read(logfd, entry, LOGGER_ENTRY_MAX_LEN);
- if (ret < 0) {
- if (errno == EINTR)
- continue;
- if (errno == EAGAIN)
- break;
- perror("logcat read");
- exit(EXIT_FAILURE);
+ if (result >= 0) {
+ for (dev=devices; dev; dev = dev->next) {
+ if (FD_ISSET(dev->fd, &readset)) {
+ entry = new queued_entry_t;
+ /* NOTE: driver guarantees we read exactly one full entry */
+ ret = read(dev->fd, entry->buf, LOGGER_ENTRY_MAX_LEN);
+ if (ret < 0) {
+ if (errno == EINTR) {
+ delete entry;
+ goto next;
+ }
+ if (errno == EAGAIN) {
+ delete entry;
+ break;
+ }
+ perror("logcat read");
+ exit(EXIT_FAILURE);
+ }
+ else if (!ret) {
+ fprintf(stderr, "read: Unexpected EOF!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ entry->entry.msg[entry->entry.len] = '\0';
+
+ dev->enqueue(entry);
+ }
+ }
+
+ if (result == 0) {
+ // we did our short timeout trick and there's nothing new
+ // print all that aren't the last in their list
+ sleep = true;
+ while (true) {
+ chooseFirst(devices, &dev, &entry);
+ if (!entry) {
+ break;
+ }
+ eatEntry(dev, entry);
+ }
+ // They requested to just dump the log
+ if (g_nonblock) {
+ exit(0);
+ }
+ } else {
+ // print all that aren't the last in their list
+ while (true) {
+ chooseFirst(devices, &dev, &entry);
+ if (!entry) {
+ sleep = false;
+ break;
+ } else if (entry->next == NULL) {
+ sleep = false;
+ break;
+ }
+ eatEntry(dev, entry);
+ }
+ }
}
- else if (!ret) {
- fprintf(stderr, "read: Unexpected EOF!\n");
- exit(EXIT_FAILURE);
- }
-
- /* NOTE: driver guarantees we read exactly one full entry */
-
- entry->msg[entry->len] = '\0';
-
- if (g_printBinary) {
- printBinary(entry);
- } else {
- (void) processBuffer(entry);
- }
+next:
+ ;
}
}
@@ -275,16 +445,17 @@
extern "C" void logprint_run_tests(void);
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
- int logfd;
int err;
int hasSetLogFormat = 0;
int clearLog = 0;
int getLogSize = 0;
int mode = O_RDONLY;
- char *log_device = strdup("/dev/"LOGGER_LOG_MAIN);
const char *forceFilters = NULL;
+ log_device_t* devices = NULL;
+ log_device_t* dev;
+ bool needBinary = false;
g_logformat = android_log_format_new();
@@ -319,21 +490,34 @@
break;
case 'd':
- mode |= O_NONBLOCK;
+ g_nonblock = true;
break;
case 'g':
getLogSize = 1;
break;
- case 'b':
- free(log_device);
- log_device =
- (char*) malloc(strlen(LOG_FILE_DIR) + strlen(optarg) + 1);
- strcpy(log_device, LOG_FILE_DIR);
- strcat(log_device, optarg);
+ case 'b': {
+ char* buf = (char*) malloc(strlen(LOG_FILE_DIR) + strlen(optarg) + 1);
+ strcpy(buf, LOG_FILE_DIR);
+ strcat(buf, optarg);
- android::g_isBinary = (strcmp(optarg, "events") == 0);
+ bool binary = strcmp(optarg, "events") == 0;
+ if (binary) {
+ needBinary = true;
+ }
+
+ if (devices) {
+ dev = devices;
+ while (dev->next) {
+ dev = dev->next;
+ }
+ dev->next = new log_device_t(buf, binary, optarg[0]);
+ } else {
+ devices = new log_device_t(buf, binary, optarg[0]);
+ }
+ android::g_devCount++;
+ }
break;
case 'B':
@@ -460,6 +644,19 @@
}
}
+ if (!devices) {
+ devices = new log_device_t(strdup("/dev/"LOGGER_LOG_MAIN), false, 'm');
+ android::g_devCount = 1;
+ int accessmode =
+ (mode & O_RDONLY) ? R_OK : 0
+ | (mode & O_WRONLY) ? W_OK : 0;
+ // only add this if it's available
+ if (0 == access("/dev/"LOGGER_LOG_SYSTEM, accessmode)) {
+ devices->next = new log_device_t(strdup("/dev/"LOGGER_LOG_SYSTEM), false, 's');
+ android::g_devCount++;
+ }
+ }
+
if (android::g_logRotateSizeKBytes != 0
&& android::g_outputFileName == NULL
) {
@@ -516,42 +713,52 @@
}
}
- logfd = open(log_device, mode);
- if (logfd < 0) {
- fprintf(stderr, "Unable to open log device '%s': %s\n",
- log_device, strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- if (clearLog) {
- int ret;
- ret = android::clearLog(logfd);
- if (ret) {
- perror("ioctl");
+ dev = devices;
+ while (dev) {
+ dev->fd = open(dev->device, mode);
+ if (dev->fd < 0) {
+ fprintf(stderr, "Unable to open log device '%s': %s\n",
+ dev->device, strerror(errno));
exit(EXIT_FAILURE);
}
- return 0;
+
+ if (clearLog) {
+ int ret;
+ ret = android::clearLog(dev->fd);
+ if (ret) {
+ perror("ioctl");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (getLogSize) {
+ int size, readable;
+
+ size = android::getLogSize(dev->fd);
+ if (size < 0) {
+ perror("ioctl");
+ exit(EXIT_FAILURE);
+ }
+
+ readable = android::getLogReadableSize(dev->fd);
+ if (readable < 0) {
+ perror("ioctl");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("%s: ring buffer is %dKb (%dKb consumed), "
+ "max entry is %db, max payload is %db\n", dev->device,
+ size / 1024, readable / 1024,
+ (int) LOGGER_ENTRY_MAX_LEN, (int) LOGGER_ENTRY_MAX_PAYLOAD);
+ }
+
+ dev = dev->next;
}
if (getLogSize) {
- int size, readable;
-
- size = android::getLogSize(logfd);
- if (size < 0) {
- perror("ioctl");
- exit(EXIT_FAILURE);
- }
-
- readable = android::getLogReadableSize(logfd);
- if (readable < 0) {
- perror("ioctl");
- exit(EXIT_FAILURE);
- }
-
- printf("ring buffer is %dKb (%dKb consumed), "
- "max entry is %db, max payload is %db\n",
- size / 1024, readable / 1024,
- (int) LOGGER_ENTRY_MAX_LEN, (int) LOGGER_ENTRY_MAX_PAYLOAD);
+ return 0;
+ }
+ if (clearLog) {
return 0;
}
@@ -559,10 +766,10 @@
//LOG_EVENT_LONG(11, 0x1122334455667788LL);
//LOG_EVENT_STRING(0, "whassup, doc?");
- if (android::g_isBinary)
+ if (needBinary)
android::g_eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
- android::readLogLines(logfd);
+ android::readLogLines(devices);
return 0;
}
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index 3bb2262..7ac991c 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -8,7 +8,7 @@
etc/hosts
ifeq ($(TARGET_PRODUCT),generic)
-copy_from += etc/vold.conf
+copy_from += etc/vold.fstab
endif
# the /system/etc/init.goldfish.sh is needed to enable emulator support
diff --git a/rootdir/etc/vold.conf b/rootdir/etc/vold.conf
deleted file mode 100644
index 4e04509..0000000
--- a/rootdir/etc/vold.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-## vold configuration file for the 'generic' target
-
-volume_sdcard {
- ## This is the direct uevent device path to the SD slot on the device
- media_path /devices/platform/goldfish_mmc.0/mmc_host/mmc0
-
- media_type mmc
- mount_point /sdcard
- ums_path /devices/platform/usb_mass_storage/lun0
-}
diff --git a/rootdir/etc/vold.fstab b/rootdir/etc/vold.fstab
new file mode 100644
index 0000000..4aad8dc
--- /dev/null
+++ b/rootdir/etc/vold.fstab
@@ -0,0 +1,24 @@
+## Vold 2.0 Generic fstab
+## - San Mehat (san@android.com)
+##
+
+#######################
+## Regular device mount
+##
+## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
+## label - Label for the volume
+## mount_point - Where the volume will be mounted
+## part - Partition # (1 based), or 'auto' for first usable partition.
+## <sysfs_path> - List of sysfs paths to source devices
+######################
+
+## Example of a standard sdcard mount for the emulator / Dream
+# Mounts the first usable partition of the specified device
+dev_mount sdcard /mnt/sdcard auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
+
+## Example of a dual card setup
+# dev_mount left_sdcard /sdcard1 auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
+# dev_mount right_sdcard /sdcard2 auto /devices/platform/goldfish_mmc.1 /devices/platform/msm_sdcc.3/mmc_host/mmc1
+
+## Example of specifying a specific partition for mounts
+# dev_mount sdcard /sdcard 2 /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
diff --git a/rootdir/init.rc b/rootdir/init.rc
index f62d1d8..4a67011 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -12,21 +12,44 @@
export ANDROID_ROOT /system
export ANDROID_ASSETS /system/app
export ANDROID_DATA /data
- export EXTERNAL_STORAGE /sdcard
+ export EXTERNAL_STORAGE /mnt/sdcard
+ export ASEC_MOUNTPOINT /mnt/asec
export BOOTCLASSPATH /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
# Backward compatibility
symlink /system/etc /etc
symlink /sys/kernel/debug /d
-# create mountpoints and mount tmpfs on sqlite_stmt_journals
- mkdir /sdcard 0000 system system
+# 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
mkdir /config 0500 root root
- mkdir /sqlite_stmt_journals 01777 root root
- mount tmpfs tmpfs /sqlite_stmt_journals size=4m
+
+ # Directory for putting things only root should see.
+ mkdir /mnt/secure 0700 root root
+
+ # Directory for staging bindmounts
+ mkdir /mnt/secure/staging 0700 root root
+
+ # Directory-target for where the secure container
+ # imagefile directory will be bind-mounted
+ mkdir /mnt/secure/asec 0700 root root
+
+ # Secure container public mount points.
+ mkdir /mnt/asec 0700 root system
+ mount tmpfs tmpfs /mnt/asec mode=0755,gid=1000
mount rootfs rootfs / ro remount
@@ -41,7 +64,7 @@
# Create cgroup mount points for process groups
mkdir /dev/cpuctl
mount cgroup none /dev/cpuctl cpu
- chown sytem system /dev/cpuctl
+ chown system system /dev/cpuctl
chown system system /dev/cpuctl/tasks
chmod 0777 /dev/cpuctl/tasks
write /dev/cpuctl/cpu.shares 1024
@@ -86,18 +109,13 @@
write /proc/apanic_console 1
- # Collect ramconsole data
- copy /proc/last_kmsg /data/dontpanic/last_kmsg
- chown root log /data/dontpanic/last_kmsg
- chmod 0640 /data/dontpanic/last_kmsg
-
# Same reason as /data above
mount yaffs2 mtd@cache /cache nosuid nodev
chown system cache /cache
chmod 0770 /cache
# This may have been created by the recovery system with odd permissions
- chown system system /cache/recovery
+ chown system cache /cache/recovery
chmod 0770 /cache/recovery
#change permissions on vmallocinfo so we can grab it from bugreports
@@ -107,8 +125,10 @@
# create basic filesystem structure
mkdir /data/misc 01771 system misc
mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
+ mkdir /data/misc/bluetooth 0770 system system
mkdir /data/misc/keystore 0700 keystore keystore
mkdir /data/misc/vpn 0770 system system
+ mkdir /data/misc/systemkeys 0700 system system
mkdir /data/misc/vpn/profiles 0770 system system
# give system access to wpa_supplicant.conf for backup and restore
mkdir /data/misc/wifi 0770 wifi wifi
@@ -121,6 +141,12 @@
mkdir /data/app 0771 system system
mkdir /data/property 0700 root root
+ # STOPSHIP: Temporary Encrypted File Systems workaround
+ mkdir /data/secure 0771 system system
+ mkdir /data/secure/data 0771 system system
+ mkdir /data/secure/misc 01771 system misc
+ mkdir /data/securemisc/vpn 0770 system system
+ mkdir /data/secure/misc/vpn/profiles 0770 system system
# create dalvik-cache and double-check the perms
mkdir /data/dalvik-cache 0771 system system
@@ -260,13 +286,10 @@
service vold /system/bin/vold
socket vold stream 0660 root mount
+ ioprio be 2
-service nexus /system/bin/nexus
- socket nexus stream 0660 root system
- disabled
-
-#service mountd /system/bin/mountd
-# socket mountd stream 0660 root mount
+service netd /system/bin/netd
+ socket netd stream 0660 root system
service debuggerd /system/bin/debuggerd
@@ -285,11 +308,7 @@
service media /system/bin/mediaserver
user media
group system audio camera graphics inet net_bt net_bt_admin
-
-service bootsound /system/bin/playmp3
- user media
- group audio
- oneshot
+ ioprio rt 4
service bootanim /system/bin/bootanimation
user graphics
diff --git a/sh/miscbltin.c b/sh/miscbltin.c
index 1a8e252..d89029a 100644
--- a/sh/miscbltin.c
+++ b/sh/miscbltin.c
@@ -277,8 +277,6 @@
return 0;
}
-typedef unsigned long rlim_t;
-
#if 1
/*
* ulimit builtin
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 122a544..a6114ac 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -51,7 +51,8 @@
iftop \
id \
vmstat \
- nandread
+ nandread \
+ ionice
LOCAL_SRC_FILES:= \
toolbox.c \
diff --git a/toolbox/chown.c b/toolbox/chown.c
index 13617db..e9d108b 100644
--- a/toolbox/chown.c
+++ b/toolbox/chown.c
@@ -35,19 +35,29 @@
gid_t gid = -1; // passing -1 to chown preserves current group
pw = getpwnam(user);
- if (pw == NULL) {
- fprintf(stderr, "No such user '%s'\n", user);
- return 10;
+ if (pw != NULL) {
+ uid = pw->pw_uid;
+ } else {
+ char* endptr;
+ uid = (int) strtoul(user, &endptr, 0);
+ if (endptr == user) { // no conversion
+ fprintf(stderr, "No such user '%s'\n", user);
+ return 10;
+ }
}
- uid = pw->pw_uid;
if (group != NULL) {
grp = getgrnam(group);
- if (grp == NULL) {
- fprintf(stderr, "No such group '%s'\n", group);
- return 10;
+ if (grp != NULL) {
+ gid = grp->gr_gid;
+ } else {
+ char* endptr;
+ gid = (int) strtoul(group, &endptr, 0);
+ if (endptr == group) { // no conversion
+ fprintf(stderr, "No such group '%s'\n", group);
+ return 10;
+ }
}
- gid = grp->gr_gid;
}
for (i = 2; i < argc; i++) {
@@ -59,4 +69,3 @@
return 0;
}
-
diff --git a/toolbox/ionice.c b/toolbox/ionice.c
new file mode 100644
index 0000000..4a182f2
--- /dev/null
+++ b/toolbox/ionice.c
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <cutils/iosched_policy.h>
+
+static char *classes[] = {"none", "rt", "be", "idle", NULL};
+
+int ionice_main(int argc, char *argv[])
+{
+ IoSchedClass clazz = IoSchedClass_NONE;
+ int ioprio = 0;
+ int pid;
+
+ if(argc != 2 && argc != 4) {
+ fprintf(stderr, "usage: ionice <pid> [none|rt|be|idle] [prio]\n");
+ return 1;
+ }
+
+ if (!(pid = atoi(argv[1]))) {
+ fprintf(stderr, "Invalid pid specified\n");
+ return 1;
+ }
+
+ if (argc == 2) {
+ if (android_get_ioprio(pid, &clazz, &ioprio)) {
+ fprintf(stderr, "Failed to read priority (%s)\n", strerror(errno));
+ return 1;
+ }
+ fprintf(stdout, "Pid %d, class %s (%d), prio %d\n", pid, classes[clazz], clazz, ioprio);
+ return 0;
+ }
+
+ if (!strcmp(argv[2], "none")) {
+ clazz = IoSchedClass_NONE;
+ } else if (!strcmp(argv[2], "rt")) {
+ clazz = IoSchedClass_RT;
+ } else if (!strcmp(argv[2], "be")) {
+ clazz = IoSchedClass_BE;
+ } else if (!strcmp(argv[2], "idle")) {
+ clazz = IoSchedClass_IDLE;
+ } else {
+ fprintf(stderr, "Unsupported class '%s'\n", argv[2]);
+ return 1;
+ }
+
+ ioprio = atoi(argv[3]);
+
+ printf("Setting pid %d i/o class to %d, prio %d\n", pid, clazz, ioprio);
+ if (android_set_ioprio(pid, clazz, ioprio)) {
+ fprintf(stderr, "Failed to set priority (%s)\n", strerror(errno));
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c
index 4483cc0..ff9e844 100644
--- a/toolbox/newfs_msdos.c
+++ b/toolbox/newfs_msdos.c
@@ -235,35 +235,6 @@
static void usage(void);
#ifdef ANDROID
-static void err(int val, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- char *fmt2;
- asprintf(&fmt2, "%s\n", fmt);
- vfprintf(stderr, fmt2, ap);
- free(fmt2);
- va_end(ap);
-}
-
-static void errx(int val, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- char *fmt2;
- asprintf(&fmt2, "%s\n", fmt);
- vfprintf(stderr, fmt2, ap);
- free(fmt2);
- va_end(ap);
-}
-
-static void warnx(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- char *fmt2;
- asprintf(&fmt2, "%s\n", fmt);
- vfprintf(stderr, fmt2, ap);
- free(fmt2);
- va_end(ap);
-}
#define powerof2(x) ((((x) - 1) & (x)) == 0)
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
@@ -443,11 +414,14 @@
if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) {
off_t delta;
getdiskinfo(fd, fname, dtype, oflag, &bpb);
+ if (opt_s) {
+ bpb.bsec = opt_s;
+ }
bpb.bsec -= (opt_ofs / bpb.bps);
delta = bpb.bsec % bpb.spt;
if (delta != 0) {
- warnx("trim %d sectors to adjust to a multiple of %d",
- (int)delta, bpb.spt);
+ warnx("trim %d sectors from %d to adjust to a multiple of %d",
+ (int)delta, bpb.bsec, bpb.spt);
bpb.bsec -= delta;
}
if (bpb.spc == 0) { /* set defaults */
@@ -745,8 +719,10 @@
}
if ((n = write(fd, img, bpb.bps)) == -1)
err(1, "%s", fname);
- if ((unsigned)n != bpb.bps)
+ if ((unsigned)n != bpb.bps) {
errx(1, "%s: can't write sector %u", fname, lsn);
+ exit(1);
+ }
}
}
return 0;
@@ -811,20 +787,31 @@
struct hd_geometry geom;
if (ioctl(fd, BLKSSZGET, &bpb->bps)) {
- fprintf(stderr, "Error getting bytes / sector (%s)", strerror(errno));
+ fprintf(stderr, "Error getting bytes / sector (%s)\n", strerror(errno));
exit(1);
}
ckgeom(fname, bpb->bps, "bytes/sector");
if (ioctl(fd, BLKGETSIZE, &bpb->bsec)) {
- fprintf(stderr, "Error getting blocksize (%s)", strerror(errno));
+ fprintf(stderr, "Error getting blocksize (%s)\n", strerror(errno));
exit(1);
}
if (ioctl(fd, HDIO_GETGEO, &geom)) {
- fprintf(stderr, "Error getting gemoetry (%s)", strerror(errno));
- exit(1);
+ fprintf(stderr, "Error getting gemoetry (%s) - trying sane values\n", strerror(errno));
+ geom.heads = 64;
+ geom.sectors = 63;
+ }
+
+ if (!geom.heads) {
+ printf("Bogus heads from kernel - setting sane value\n");
+ geom.heads = 64;
+ }
+
+ if (!geom.sectors) {
+ printf("Bogus sectors from kernel - setting sane value\n");
+ geom.sectors = 63;
}
bpb->spt = geom.sectors;
diff --git a/vold/Android.mk b/vold/Android.mk
deleted file mode 100644
index 3dd9f87..0000000
--- a/vold/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- vold.c \
- cmd_dispatch.c \
- uevent.c \
- mmc.c \
- misc.c \
- blkdev.c \
- ums.c \
- geom_mbr_enc.c \
- volmgr.c \
- media.c \
- volmgr_vfat.c \
- volmgr_ext3.c \
- logwrapper.c \
- ProcessKiller.c\
- switch.c \
- format.c \
- devmapper.c
-
-LOCAL_MODULE:= vold
-
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
-
-LOCAL_CFLAGS :=
-
-LOCAL_SHARED_LIBRARIES := libcutils
-
-include $(BUILD_EXECUTABLE)
diff --git a/vold/ProcessKiller.c b/vold/ProcessKiller.c
deleted file mode 100644
index fc3eb37..0000000
--- a/vold/ProcessKiller.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/*
-** mountd process killer
-*/
-
-#include "vold.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <poll.h>
-#include <sys/stat.h>
-
-
-static boolean ReadSymLink(const char* path, char* link)
-{
- struct stat s;
- int length;
-
- if (lstat(path, &s) < 0)
- return false;
- if ((s.st_mode & S_IFMT) != S_IFLNK)
- return false;
-
- // we have a symlink
- length = readlink(path, link, PATH_MAX - 1);
- if (length <= 0)
- return false;
- link[length] = 0;
- return true;
-}
-
-static boolean PathMatchesMountPoint(const char* path, const char* mountPoint)
-{
- int length = strlen(mountPoint);
- if (length > 1 && strncmp(path, mountPoint, length) == 0)
- {
- // we need to do extra checking if mountPoint does not end in a '/'
- if (mountPoint[length - 1] == '/')
- return true;
- // if mountPoint does not have a trailing slash, we need to make sure
- // there is one in the path to avoid partial matches.
- return (path[length] == 0 || path[length] == '/');
- }
-
- return false;
-}
-
-static void GetProcessName(int pid, char buffer[PATH_MAX])
-{
- int fd;
- sprintf(buffer, "/proc/%d/cmdline", pid);
- fd = open(buffer, O_RDONLY);
- if (fd < 0) {
- strcpy(buffer, "???");
- } else {
- int length = read(fd, buffer, PATH_MAX - 1);
- buffer[length] = 0;
- close(fd);
- }
-}
-
-static boolean CheckFileDescriptorSymLinks(int pid, const char* mountPoint)
-{
- DIR* dir;
- struct dirent* de;
- boolean fileOpen = false;
- char path[PATH_MAX];
- char link[PATH_MAX];
- int parent_length;
-
- // compute path to process's directory of open files
- sprintf(path, "/proc/%d/fd", pid);
- dir = opendir(path);
- if (!dir)
- return false;
-
- // remember length of the path
- parent_length = strlen(path);
- // append a trailing '/'
- path[parent_length++] = '/';
-
- while ((de = readdir(dir)) != 0 && !fileOpen) {
- if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
- continue;
-
- // append the file name, after truncating to parent directory
- path[parent_length] = 0;
- strcat(path, de->d_name);
-
- if (ReadSymLink(path, link) && PathMatchesMountPoint(link, mountPoint))
- {
- char name[PATH_MAX];
- GetProcessName(pid, name);
- LOG_ERROR("process %s (%d) has open file %s", name, pid, link);
- fileOpen = true;
- }
- }
-
- closedir(dir);
- return fileOpen;
-}
-
-static boolean CheckFileMaps(int pid, const char* mountPoint)
-{
- FILE* file;
- char buffer[PATH_MAX + 100];
- boolean mapOpen = false;
-
- sprintf(buffer, "/proc/%d/maps", pid);
- file = fopen(buffer, "r");
- if (!file)
- return false;
-
- while (!mapOpen && fgets(buffer, sizeof(buffer), file))
- {
- // skip to the path
- const char* path = strchr(buffer, '/');
- if (path && PathMatchesMountPoint(path, mountPoint))
- {
- char name[PATH_MAX];
- GetProcessName(pid, name);
- LOG_ERROR("process %s (%d) has open file map for %s", name, pid, path);
- mapOpen = true;
- }
- }
-
- fclose(file);
- return mapOpen;
-}
-
-static boolean CheckSymLink(int pid, const char* mountPoint, const char* name, const char* message)
-{
- char path[PATH_MAX];
- char link[PATH_MAX];
-
- sprintf(path, "/proc/%d/%s", pid, name);
- if (ReadSymLink(path, link) && PathMatchesMountPoint(link, mountPoint))
- {
- char name[PATH_MAX];
- GetProcessName(pid, name);
- LOG_ERROR("process %s (%d) has %s in %s", name, pid, message, mountPoint);
- return true;
- }
- else
- return false;
-}
-
-static int get_pid(const char* s)
-{
- int result = 0;
- while (*s) {
- if (!isdigit(*s)) return -1;
- result = 10 * result + (*s++ - '0');
- }
- return result;
-}
-
-// hunt down and kill processes that have files open on the given mount point
-void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded)
-{
- DIR* dir;
- struct dirent* de;
-
- LOG_ERROR("KillProcessesWithOpenFiles %s", mountPoint);
- dir = opendir("/proc");
- if (!dir) return;
-
- while ((de = readdir(dir)) != 0)
- {
- boolean killed = false;
- // does the name look like a process ID?
- int pid = get_pid(de->d_name);
- if (pid == -1) continue;
-
- if (CheckFileDescriptorSymLinks(pid, mountPoint) // check for open files
- || CheckFileMaps(pid, mountPoint) // check for mmap()
- || CheckSymLink(pid, mountPoint, "cwd", "working directory") // check working directory
- || CheckSymLink(pid, mountPoint, "root", "chroot") // check for chroot()
- || CheckSymLink(pid, mountPoint, "exe", "executable path") // check executable path
- )
- {
- int i;
- boolean hit = false;
-
- for (i = 0; i < num_excluded; i++) {
- if (pid == excluded[i]) {
- LOG_ERROR("I just need a little more TIME captain!");
- hit = true;
- break;
- }
- }
-
- if (!hit) {
- LOG_ERROR("Killing process %d", pid);
- kill(pid, (sigkill ? SIGKILL : SIGTERM));
- }
- }
- }
-
- closedir(dir);
-}
diff --git a/vold/blkdev.c b/vold/blkdev.c
deleted file mode 100644
index 33fed1b..0000000
--- a/vold/blkdev.c
+++ /dev/null
@@ -1,329 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include <linux/fs.h>
-#include <linux/msdos_fs.h>
-
-#include "vold.h"
-#include "blkdev.h"
-#include "diskmbr.h"
-#include "media.h"
-
-#define DEBUG_BLKDEV 0
-
-static blkdev_list_t *list_root = NULL;
-
-static blkdev_t *_blkdev_create(blkdev_t *disk, char *devpath, int major,
- int minor, char *type, struct media *media);
-
-static int fat_valid_media(unsigned char media)
-{
- return 0xf8 <= media || media == 0xf0;
-}
-
-char *blkdev_get_devpath(blkdev_t *blk)
-{
- char *dp = malloc(256);
- sprintf(dp, "%s/vold/%d:%d", DEVPATH, blk->major, blk->minor);
- return dp;
-}
-
-int blkdev_refresh(blkdev_t *blk)
-{
- int fd = 0;
- char *devpath = NULL;
- unsigned char *block = NULL;
- int i, rc;
-
- if (!(block = malloc(512)))
- goto out;
-
- /*
- * Get the device size
- */
- devpath = blkdev_get_devpath(blk);
-
- if ((fd = open(devpath, O_RDONLY)) < 0) {
- LOGE("Unable to open device '%s' (%s)", devpath, strerror(errno));
- return -errno;
- }
-
- if (ioctl(fd, BLKGETSIZE, &blk->nr_sec)) {
- LOGE("Unable to get device size (%s)", strerror(errno));
- return -errno;
- }
- close(fd);
- free(devpath);
-
- /*
- * Open the disk partition table
- */
- devpath = blkdev_get_devpath(blk->disk);
- if ((fd = open(devpath, O_RDONLY)) < 0) {
- LOGE("Unable to open device '%s' (%s)", devpath,
- strerror(errno));
- free(devpath);
- return -errno;
- }
-
- free(devpath);
-
- if ((rc = read(fd, block, 512)) != 512) {
- LOGE("Unable to read device partition table (%d, %s)",
- rc, strerror(errno));
- goto out;
- }
-
- /*
- * If we're a disk, then process the partition table. Otherwise we're
- * a partition so get the partition type
- */
-
- if (blk->type == blkdev_disk) {
- blk->nr_parts = 0;
-
- if ((block[0x1fe] != 0x55) || (block[0x1ff] != 0xAA)) {
- LOGI("Disk %d:%d does not contain a partition table",
- blk->major, blk->minor);
- goto out;
- }
-
- for (i = 0; i < NDOSPART; i++) {
- struct dos_partition part;
-
- dos_partition_dec(block + DOSPARTOFF + i * sizeof(struct dos_partition), &part);
- if (part.dp_flag != 0 && part.dp_flag != 0x80) {
- struct fat_boot_sector *fb = (struct fat_boot_sector *) &block[0];
-
- if (!i && fb->reserved && fb->fats && fat_valid_media(fb->media)) {
- LOGI("Detected FAT filesystem in partition table");
- break;
- } else {
- LOGI("Partition table looks corrupt");
- break;
- }
- }
- if (part.dp_size != 0 && part.dp_typ != 0)
- blk->nr_parts++;
- }
- } else if (blk->type == blkdev_partition) {
- struct dos_partition part;
- int part_no;
-
- if (blk->media->media_type == media_mmc)
- part_no = blk->minor % MMC_PARTS_PER_CARD -1;
- else
- part_no = blk->minor -1;
-
- if (part_no < NDOSPART) {
- dos_partition_dec(block + DOSPARTOFF + part_no * sizeof(struct dos_partition), &part);
- blk->part_type = part.dp_typ;
- } else {
- LOGW("Skipping partition %d", part_no);
- }
- }
-
- out:
-
- if (block)
- free(block);
-
- char tmp[255];
- char tmp2[32];
- sprintf(tmp, "%s (blkdev %d:%d), %u secs (%u MB)",
- (blk->type == blkdev_disk ? "Disk" : "Partition"),
- blk->major, blk->minor,
- blk->nr_sec,
- (uint32_t) (((uint64_t) blk->nr_sec * 512) / 1024) / 1024);
-
- if (blk->type == blkdev_disk)
- sprintf(tmp2, " %d partitions", blk->nr_parts);
- else
- sprintf(tmp2, " type 0x%x", blk->part_type);
-
- strcat(tmp, tmp2);
- LOGI(tmp);
-
- close(fd);
-
- return 0;
-}
-
-blkdev_t *blkdev_create(blkdev_t *disk, char *devpath, int major, int minor, struct media *media, char *type)
-{
- return _blkdev_create(disk, devpath, major, minor, type, media);
-}
-
-static blkdev_t *_blkdev_create(blkdev_t *disk, char *devpath, int major,
- int minor, char *type, struct media *media)
-{
- blkdev_t *new;
- struct blkdev_list *list_entry;
-
- if (disk && disk->type != blkdev_disk) {
- LOGE("Non disk parent specified for blkdev!");
- return NULL;
- }
-
- if (!(new = malloc(sizeof(blkdev_t))))
- return NULL;
-
- memset(new, 0, sizeof(blkdev_t));
-
- if (!(list_entry = malloc(sizeof(struct blkdev_list)))) {
- free (new);
- return NULL;
- }
- list_entry->dev = new;
- list_entry->next = NULL;
-
- if (!list_root)
- list_root = list_entry;
- else {
- struct blkdev_list *list_scan = list_root;
- while (list_scan->next)
- list_scan = list_scan->next;
- list_scan->next = list_entry;
- }
-
- if (devpath)
- new->devpath = strdup(devpath);
- new->major = major;
- new->minor = minor;
- new->media = media;
- new->nr_sec = 0xffffffff;
-
- if (disk)
- new->disk = disk;
- else
- new->disk = new; // Note the self disk pointer
-
- /* Create device nodes */
- char nodepath[255];
- mode_t mode = 0660 | S_IFBLK;
- dev_t dev = (major << 8) | minor;
-
- sprintf(nodepath, "%s/vold/%d:%d", DEVPATH, major, minor);
- if (mknod(nodepath, mode, dev) < 0) {
- LOGE("Error making device nodes for '%s' (%s)",
- nodepath, strerror(errno));
- }
-
- if (!strcmp(type, "disk"))
- new->type = blkdev_disk;
- else if (!strcmp(type, "partition"))
- new->type = blkdev_partition;
- else {
- LOGE("Unknown block device type '%s'", type);
- new->type = blkdev_unknown;
- }
-
- return new;
-}
-
-void blkdev_destroy(blkdev_t *blkdev)
-{
- struct blkdev_list *list_next;
-
- if (list_root->dev == blkdev) {
- list_next = list_root->next;
- free (list_root);
- list_root = list_next;
- } else {
- struct blkdev_list *list_scan = list_root;
- while (list_scan->next->dev != blkdev)
- list_scan = list_scan -> next;
- list_next = list_scan->next->next;
- free(list_scan->next);
- list_scan->next = list_next;
- }
-
- if (blkdev->devpath)
- free(blkdev->devpath);
-
- char nodepath[255];
- sprintf(nodepath, "%s/vold/%d:%d", DEVPATH, blkdev->major, blkdev->minor);
- unlink(nodepath);
-
- free(blkdev);
-}
-
-blkdev_t *blkdev_lookup_by_path(char *devpath)
-{
- struct blkdev_list *list_scan = list_root;
-
- while (list_scan) {
- if (!strcmp(list_scan->dev->devpath, devpath))
- return list_scan->dev;
- list_scan = list_scan->next;
- }
- return NULL;
-}
-
-blkdev_t *blkdev_lookup_by_devno(int maj, int min)
-{
- struct blkdev_list *list_scan = list_root;
-
- while (list_scan) {
- if ((list_scan->dev->major == maj) &&
- (list_scan->dev->minor == min))
- return list_scan->dev;
- list_scan = list_scan->next;
- }
- return NULL;
-}
-
-/*
- * Given a disk device, return the number of partitions which
- * have yet to be processed.
- */
-int blkdev_get_num_pending_partitions(blkdev_t *blk)
-{
- struct blkdev_list *list_scan = list_root;
- int num = blk->nr_parts;
-
- if (blk->type != blkdev_disk)
- return -EINVAL;
-
- while (list_scan) {
- if (list_scan->dev->type != blkdev_partition)
- goto next;
-
- if (list_scan->dev->major != blk->major)
- goto next;
-
- if (list_scan->dev->nr_sec != 0xffffffff &&
- list_scan->dev->devpath) {
- num--;
- }
- next:
- list_scan = list_scan->next;
- }
- return num;
-}
-
diff --git a/vold/blkdev.h b/vold/blkdev.h
deleted file mode 100644
index e789739..0000000
--- a/vold/blkdev.h
+++ /dev/null
@@ -1,64 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _BLKDEV_H
-#define _BLKDEV_H
-
-#include <sys/types.h>
-
-struct media;
-
-enum blk_type { blkdev_unknown, blkdev_disk, blkdev_partition };
-
-struct blkdev {
- char *devpath;
- enum blk_type type;
- struct media *media;
-
- // If type == blkdev_disk then nr_parts = number of partitions
- int nr_parts;
-
- // If type == blkdev_partition then part_type = partition type
- uint8_t part_type;
- // If type == blkdev_partition
- struct blkdev *disk;
-
- unsigned int nr_sec;
-
- int major;
- int minor;
-};
-
-struct blkdev_list {
- struct blkdev *dev;
- struct blkdev_list *next;
-};
-
-typedef struct blkdev blkdev_t;
-typedef struct blkdev_list blkdev_list_t;
-
-blkdev_t *blkdev_create(blkdev_t *disk, char *devpath, int major, int minor, struct media *media, char *type);
-blkdev_t *blkdev_create_pending_partition(blkdev_t *disk, char *dev_fspath, int major, int minor, struct media *media);
-blkdev_t *blkdev_lookup_by_path(char *devpath);
-blkdev_t *blkdev_lookup_by_devno(int maj, int min);
-char *blkdev_get_devpath(blkdev_t *blk);
-
-void blkdev_destroy(blkdev_t *blk);
-
-int blkdev_get_num_pending_partitions(blkdev_t *blk);
-int blkdev_refresh(blkdev_t *blk);
-#endif
diff --git a/vold/cmd_dispatch.c b/vold/cmd_dispatch.c
deleted file mode 100644
index ab65fd9..0000000
--- a/vold/cmd_dispatch.c
+++ /dev/null
@@ -1,115 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <unistd.h>
-#include <errno.h>
-
-#include "vold.h"
-#include "cmd_dispatch.h"
-#include "ums.h"
-#include "volmgr.h"
-
-struct cmd_dispatch {
- char *cmd;
- int (* dispatch) (char *);
-};
-
-static void dispatch_cmd(char *cmd);
-static int do_send_ums_status(char *cmd);
-static int do_set_ums_enable(char *cmd);
-static int do_mount_volume(char *cmd);
-static int do_eject_media(char *cmd);
-static int do_format_media(char *cmd);
-
-static struct cmd_dispatch dispatch_table[] = {
- { VOLD_CMD_ENABLE_UMS, do_set_ums_enable },
- { VOLD_CMD_DISABLE_UMS, do_set_ums_enable },
- { VOLD_CMD_SEND_UMS_STATUS, do_send_ums_status },
- { VOLD_CMD_MOUNT_VOLUME, do_mount_volume },
- { VOLD_CMD_EJECT_MEDIA, do_eject_media },
- { VOLD_CMD_FORMAT_MEDIA, do_format_media },
- { NULL, NULL }
-};
-
-int process_framework_command(int socket)
-{
- int rc;
- char buffer[101];
-
- if ((rc = read(socket, buffer, sizeof(buffer) -1)) < 0) {
- LOGE("Unable to read framework command (%s)", strerror(errno));
- return -errno;
- } else if (!rc)
- return -ECONNRESET;
-
- int start = 0;
- int i;
-
- buffer[rc] = 0;
-
- for (i = 0; i < rc; i++) {
- if (buffer[i] == 0) {
- dispatch_cmd(buffer + start);
- start = i + 1;
- }
- }
- return 0;
-}
-
-static void dispatch_cmd(char *cmd)
-{
- struct cmd_dispatch *c;
-
- LOG_VOL("dispatch_cmd(%s):", cmd);
-
- for (c = dispatch_table; c->cmd != NULL; c++) {
- if (!strncmp(c->cmd, cmd, strlen(c->cmd))) {
- c->dispatch(cmd);
- return;
- }
- }
-
- LOGE("No cmd handlers defined for '%s'", cmd);
-}
-
-static int do_send_ums_status(char *cmd)
-{
- return ums_send_status();
-}
-
-static int do_set_ums_enable(char *cmd)
-{
- if (!strcmp(cmd, VOLD_CMD_ENABLE_UMS))
- return volmgr_enable_ums(true);
-
- return volmgr_enable_ums(false);
-}
-
-static int do_mount_volume(char *cmd)
-{
- return volmgr_start_volume_by_mountpoint(&cmd[strlen("mount_volume:")]);
-}
-
-static int do_format_media(char *cmd)
-{
- return volmgr_format_volume(&cmd[strlen("format_media:")]);
-}
-
-static int do_eject_media(char *cmd)
-{
- return volmgr_stop_volume_by_mountpoint(&cmd[strlen("eject_media:")]);
-}
diff --git a/vold/cmd_dispatch.h b/vold/cmd_dispatch.h
deleted file mode 100644
index f8ba6b3..0000000
--- a/vold/cmd_dispatch.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _CMD_DISPATCH_H
-#define _CMD_DISPATCH_H
-
-// These must match the strings in java/android/android/os/UsbListener.java
-#define VOLD_CMD_ENABLE_UMS "enable_ums"
-#define VOLD_CMD_DISABLE_UMS "disable_ums"
-#define VOLD_CMD_SEND_UMS_STATUS "send_ums_status"
-
-// these commands should contain a volume mount point after the colon
-#define VOLD_CMD_MOUNT_VOLUME "mount_volume:"
-#define VOLD_CMD_EJECT_MEDIA "eject_media:"
-#define VOLD_CMD_FORMAT_MEDIA "format_media:"
-
-#endif
diff --git a/vold/devmapper.c b/vold/devmapper.c
deleted file mode 100644
index ef44c90..0000000
--- a/vold/devmapper.c
+++ /dev/null
@@ -1,463 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sched.h>
-#include <fcntl.h>
-
-#include <sys/mount.h>
-
-#include <linux/loop.h>
-#include <linux/dm-ioctl.h>
-
-#include <cutils/config_utils.h>
-#include <cutils/properties.h>
-
-#include "vold.h"
-#include "devmapper.h"
-
-#define DEBUG_DEVMAPPER 1
-
-static void *_align(void *ptr, unsigned int a)
-{
- register unsigned long agn = --a;
-
- return (void *) (((unsigned long) ptr + agn) & ~agn);
-}
-
-static struct dm_ioctl *_dm_ioctl_setup(struct devmapping *dm, int flags)
-{
- void *buffer;
- void *p;
- const size_t min_size = 16 * 1024;
- size_t len = sizeof(struct dm_ioctl);
- struct dm_ioctl *io;
- struct dm_target_spec *tgt;
- int i;
- char params[1024];
- char key[80];
-
- key[0] = '\0';
- for (i = 0; i < (int) sizeof(dm->key); i++) {
- char tmp[8];
-
- sprintf(tmp, "%02x", dm->key[i]);
- strcat(key, tmp);
- }
-
- char srcdev[128];
-
- // XXX: Handle non crypt targets and non twofish (use param)
- if (dm->src_type == dmsrc_loopback)
- strcpy(srcdev, dm->type_data.loop.loop_dev);
- else if (dm->src_type == dmsrc_partition)
- strcpy(srcdev, dm->type_data.part.part_dev);
-
- sprintf(params, "twofish %s 0 %s 0", key, srcdev);
-
-LOG_VOL("Params = '%s'", params);
-
- if (len < min_size)
- len = min_size;
-
- if (!(buffer = malloc(len))) {
- LOGE("out of memory");
- return NULL;
- }
-
- memset(buffer, 0, len);
- io = buffer;
- tgt = (struct dm_target_spec *) &buffer[sizeof(struct dm_ioctl)];
-
- io->version[0] = 4;
- io->version[1] = 0;
- io->version[2] = 0;
-
- io->data_size = len;
- io->data_start = sizeof(struct dm_ioctl);
-
- io->flags = flags;
- io->dev = 0;
-
- io->target_count = 1;
- io->event_nr = 1;
- strncpy(io->name, dm->target, sizeof(io->name));
-
- tgt->status = 0;
- tgt->sector_start = 0;
- tgt->length = (dm->size_mb * (1024 * 1024)) / 512;
- strncpy(tgt->target_type, "crypt", sizeof(tgt->target_type));
-
- p = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec);
- strcpy((char *) p, params);
- p+= strlen(params) + 1;
-
- p = _align(p, 8);
- tgt->next = p - buffer;
-
- return io;
-}
-
-static int get_next_available_dm()
-{
- int i;
-
- for (i = 0; i < 8; i++) {
- char path[255];
- sprintf(path, "/dev/block/dm-%d", i);
- if ((access(path, F_OK) < 0) && (errno == ENOENT))
- return i;
- }
-
- LOGE("Out of device mapper numbers");
- return -1;
-}
-
-static int create_devmapping(struct devmapping *dm)
-{
- struct dm_ioctl *io;
- int rc, fd;
-
-#if DEBUG_DEVMAPPER
- LOG_VOL("create_devmapping():");
-#endif
-
- if (dm->dm_no < 0) {
- LOGE("Invalid dm_no set");
- return -EINVAL;
- }
-
- if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
- LOGE("Error opening device mapper (%d)", errno);
- return -errno;
- }
-
- if (!(io = _dm_ioctl_setup(dm, 0))) {
- LOGE("Unable to setup ioctl (out of memory)");
- close(fd);
- return -ENOMEM;
- }
-
- if ((rc = ioctl(fd, DM_DEV_CREATE, io)) < 0) {
- LOGE("device-mapper create ioctl failed (%d)", errno);
- rc = -errno;
- goto out_free;
- }
-
- free(io);
-
- if (!(io = _dm_ioctl_setup(dm, DM_STATUS_TABLE_FLAG))) {
- LOGE("Unable to setup ioctl (out of memory)");
- rc = -ENOMEM;
- goto out_nofree;
- }
-
- if ((rc = ioctl(fd, DM_TABLE_LOAD, io)) < 0) {
- LOGE("device-mapper load ioctl failed (%d)", errno);
- rc = -errno;
- goto out_free;
- }
-
- free(io);
-
- if (!(io = _dm_ioctl_setup(dm, 0))) {
- LOGE("Unable to setup ioctl (out of memory)");
- rc = -ENOMEM;
- goto out_nofree;
- }
-
- if ((rc = ioctl(fd, DM_DEV_SUSPEND, io)) < 0) {
- LOGE("device-mapper resume ioctl failed (%d)", errno);
- rc = -errno;
- goto out_free;
- }
-
-out_free:
- free (io);
-out_nofree:
- close (fd);
- return rc;
-}
-
-static int loopback_start(struct devmapping *dm)
-{
- int i;
- int fd;
- char filename[255];
- int rc;
-
-#if DEBUG_DEVMAPPER
- LOG_VOL("loopback_start(%s):", dm->type_data.loop.loop_src);
-#endif
-
- for (i = 0; i < MAX_LOOP; i++) {
- struct loop_info info;
-
- sprintf(filename, "/dev/block/loop%d", i);
-
- if ((fd = open(filename, O_RDWR)) < 0) {
- LOGE("Unable to open %s (%s)", filename, strerror(errno));
- return -errno;
- }
-
- rc = ioctl(fd, LOOP_GET_STATUS, &info);
- if (rc < 0 && errno == ENXIO)
- break;
-
- close(fd);
-
- if (rc < 0) {
- LOGE("Unable to get loop status for %s (%s)", filename,
- strerror(errno));
- return -errno;
- }
- }
-
- if (i == MAX_LOOP) {
- LOGE("Out of loop devices");
- return -ENOSPC;
- }
-
- int file_fd;
-
- if ((file_fd = open(dm->type_data.loop.loop_src, O_RDWR)) < 0) {
- LOGE("Unable to open %s (%s)", dm->type_data.loop.loop_src,
- strerror(errno));
- return -errno;
- }
-
- if (ioctl(fd, LOOP_SET_FD, file_fd) < 0) {
- LOGE("Error setting up loopback interface (%s)", strerror(errno));
- return -errno;
- }
-
- dm->type_data.loop.loop_dev = strdup(filename);
- dm->type_data.loop.loop_no = i;
-
- close(fd);
- close(file_fd);
-
-#if DEBUG_DEVMAPPER
- LOG_VOL("Loop setup on %s for %s", dm->type_data.loop.loop_dev,
- dm->type_data.loop.loop_src);
-#endif
-
- return 0;
-}
-
-int devmapper_start(struct devmapping *dm)
-{
- int rc;
- char src_blkdev_path[255];
-
-#if DEBUG_DEVMAPPER
- LOG_VOL("devmapper_start()");
-#endif
-
- if (dm->src_type == dmsrc_loopback) {
- if ((rc = loopback_start(dm)) < 0)
- return rc;
- } else if (dm->src_type == dmsrc_partition) {
- LOGE("partition maps not yet supported");
- return -ENOSYS;
- } else {
- LOGE("devmapper_start(): Unsupported source type '%d'", dm->src_type);
- return -ENOENT;
- }
-
- /*
- * Configure the device mapper
- */
- if ((rc = create_devmapping(dm)) < 0) {
- LOGE("Failed to create devmapping (%d)", rc);
- // XXX: if loopback then tear down
- return rc;
- }
-
- return 0;
-}
-
-struct devmapping *devmapper_init(char *src, char *src_type, uint32_t size_mb,
- char *target, char *params, char *tgt_fs, char *mediapath)
-{
- struct devmapping *dm;
-
- if (!(dm = malloc(sizeof(struct devmapping)))) {
- LOGE("devmapper_init(): out of memory");
- return NULL;
- }
-
- memset(dm, 0, sizeof(struct devmapping));
-
- if (!strcmp(src_type, "loopback_file")) {
- dm->src_type = dmsrc_loopback;
- dm->type_data.loop.loop_src = strdup(src);
- } else if (!strncmp(src_type, "partition ", strlen("partition "))) {
- dm->src_type = dmsrc_partition;
- char *p = strtok(src_type, " ");
- if (!p) {
- LOGE("Invalid partition specifier");
- goto out_free;
- }
- dm->type_data.part.part_type = strtoul(p, NULL, 0);
- } else {
- LOGE("Invalid src_type defined (%s)", src_type);
- goto out_free;
- }
-
- // XXX: Validate these
- dm->size_mb = size_mb;
- dm->target = strdup(target);
- dm->params = strdup(params);
- dm->tgt_fs = strdup(tgt_fs);
-
- if ((dm->dm_no = get_next_available_dm()) < 0)
- goto out_free;
-
- sprintf(mediapath, "/devices/virtual/block/dm-%d", dm->dm_no);
-
- if (!(dm->media = media_create(mediapath,
- "unknown",
- "unknown",
- media_devmapper))) {
- LOGE("Unable to create media");
- goto out_free;
- }
-
- return dm;
- out_free:
- if (dm->target)
- free(dm->target);
- if (dm->params)
- free(dm->params);
- if (dm->tgt_fs)
- free(dm->tgt_fs);
-
- free(dm);
- return NULL;
-}
-
-int devmapper_genesis(struct devmapping *dm)
-{
-
- if (dm->src_type == dmsrc_loopback) {
- int fd;
-
- LOG_VOL("devmapper_genesis(): Working on %s",
- dm->type_data.loop.loop_src);
-
- unlink(dm->type_data.loop.loop_src);
-
- LOG_VOL("devmapper_genesis(): Creating imagefile (%u MB)",
- dm->size_mb);
-
- if ((fd = creat(dm->type_data.loop.loop_src, 0600)) < 0) {
- LOGE("Error creating imagefile (%s)", strerror(errno));
- return -errno;
- }
-
- if (ftruncate(fd, (dm->size_mb * (1024 * 1024))) < 0) {
- LOGE("Error truncating imagefile (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
- close(fd);
- } else if (dm->src_type == dmsrc_partition) {
- LOGE("partition maps not yet supported");
- return -ENOSYS;
- }
-
- return devmapper_start(dm);
-}
-
-static int destroy_devmapping(struct devmapping *dm)
-{
- struct dm_ioctl *io;
- int dmFd;
- int rc = 0;
-
- LOG_VOL("destroy_devmapping():");
-
- if ((dmFd = open("/dev/device-mapper", O_RDWR)) < 0) {
- LOGE("Error opening device mapper (%d)", errno);
- return -errno;
- }
-
- if (!(io = _dm_ioctl_setup(dm, DM_PERSISTENT_DEV_FLAG))) {
- LOGE("Unable to setup ioctl (out of memory)");
- rc = -ENOMEM;
- goto out_nofree;
- }
-
- if ((rc = ioctl(dmFd, DM_DEV_REMOVE, io)) < 0) {
- LOGE("device-mapper remove ioctl failed (%d)", errno);
- rc = -errno;
- goto out_free;
- }
-
-out_free:
- free (io);
-out_nofree:
- close (dmFd);
- return rc;
-}
-
-static int loopback_stop(struct devmapping *dm)
-{
- char devname[255];
- int device_fd;
- int rc = 0;
-
- LOG_VOL("loopback_stop():");
-
- device_fd = open(dm->type_data.loop.loop_dev, O_RDONLY);
- if (device_fd < 0) {
- LOG_ERROR("Failed to open loop (%d)", errno);
- return -errno;
- }
-
- if (ioctl(device_fd, LOOP_CLR_FD, 0) < 0) {
- LOG_ERROR("Failed to destroy loop (%d)", errno);
- rc = -errno;
- }
-
- close(device_fd);
- return rc;
-}
-
-int devmapper_stop(struct devmapping *dm)
-{
- int rc;
-
- LOG_VOL("devmapper_stop():");
-
- if ((rc = destroy_devmapping(dm)))
- return rc;
-
- if (dm->src_type == dmsrc_loopback) {
- if ((rc = loopback_stop(dm)))
- return rc;
- } else if (dm->src_type == dmsrc_partition) {
- LOGE("partition maps not yet supported");
- return -ENOSYS;
- }
- return 0;
-}
diff --git a/vold/devmapper.h b/vold/devmapper.h
deleted file mode 100644
index 3d8cab3..0000000
--- a/vold/devmapper.h
+++ /dev/null
@@ -1,70 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _DEVMAPPER_H
-#define _DEVMAPPER_H
-
-#include <pthread.h>
-
-#include "vold.h"
-#include "blkdev.h"
-#include "media.h"
-
-#define MAX_LOOP 8
-
-enum dm_src_type {
- dmsrc_unknown,
- dmsrc_loopback,
- dmsrc_partition,
-};
-
-struct loop_data {
- char *loop_src;
-
- char *loop_dev;
- int loop_no;
-};
-
-struct part_data {
- char part_type;
-
- char *part_dev;
-};
-
-struct devmapping {
- enum dm_src_type src_type;
- union {
- struct loop_data loop;
- struct part_data part;
- } type_data;
-
- uint32_t size_mb;
- char *target;
- char *params;
- char *tgt_fs;
-
- unsigned char key[16];
- int dm_no;
-
- media_t *media;
-};
-
-struct devmapping *devmapper_init(char *, char *, unsigned int, char *, char *, char *, char *);
-int devmapper_start(struct devmapping *);
-int devmapper_stop(struct devmapping *);
-int devmapper_genesis(struct devmapping *);
-#endif
diff --git a/vold/diskmbr.h b/vold/diskmbr.h
deleted file mode 100644
index 417e7ca..0000000
--- a/vold/diskmbr.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1987, 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
- * $FreeBSD: src/sys/sys/diskmbr.h,v 1.99.2.1 2005/01/31 23:26:56 imp Exp $
- */
-
-#ifndef _SYS_DISKMBR_H_
-#define _SYS_DISKMBR_H_
-
-#define DOSBBSECTOR 0 /* DOS boot block relative sector number */
-#define DOSPARTOFF 446
-#define DOSPARTSIZE 16
-#define NDOSPART 4
-#define NEXTDOSPART 32
-#define DOSMAGICOFFSET 510
-#define DOSMAGIC 0xAA55
-
-#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */
-#define DOSPTYP_LINSWP 0x82 /* Linux swap partition */
-#define DOSPTYP_LINUX 0x83 /* Linux partition */
-#define DOSPTYP_PMBR 0xee /* GPT Protective MBR */
-#define DOSPTYP_EXT 5 /* DOS extended partition */
-#define DOSPTYP_EXTLBA 15 /* DOS extended partition */
-
-struct dos_partition {
- unsigned char dp_flag; /* bootstrap flags */
- unsigned char dp_shd; /* starting head */
- unsigned char dp_ssect; /* starting sector */
- unsigned char dp_scyl; /* starting cylinder */
- unsigned char dp_typ; /* partition type */
- unsigned char dp_ehd; /* end head */
- unsigned char dp_esect; /* end sector */
- unsigned char dp_ecyl; /* end cylinder */
- u_int32_t dp_start; /* absolute starting sector number */
- u_int32_t dp_size; /* partition size in sectors */
-};
-#ifdef CTASSERT
-CTASSERT(sizeof (struct dos_partition) == DOSPARTSIZE);
-#endif
-
-void dos_partition_dec(void const *pp, struct dos_partition *d);
-void dos_partition_enc(void *pp, struct dos_partition *d);
-
-#define DPSECT(s) ((s) & 0x3f) /* isolate relevant bits of sector */
-#define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */
-
-#define DIOCSMBR _IOW('M', 129, u_char[512])
-
-#endif /* !_SYS_DISKMBR_H_ */
diff --git a/vold/format.c b/vold/format.c
deleted file mode 100755
index c67b358..0000000
--- a/vold/format.c
+++ /dev/null
@@ -1,117 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-
-#include <linux/fs.h>
-
-#include "vold.h"
-#include "blkdev.h"
-#include "format.h"
-#include "diskmbr.h"
-#include "logwrapper.h"
-
-static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
-static char MKE2FS_PATH[] = "/system/bin/mke2fs";
-
-int format_partition(blkdev_t *part, char *type)
-{
- char *devpath;
- int rc = -EINVAL;
-
- devpath = blkdev_get_devpath(part);
-
- if (!strcmp(type, FORMAT_TYPE_FAT32)) {
- char *args[7];
- args[0] = MKDOSFS_PATH;
- args[1] = "-F";
- if ((part->nr_sec * 512) <= (unsigned int) (1024*1024*1024*2))
- args[2] = "16";
- else
- args[2] = "32";
-
- args[3] = "-O";
- args[4] = "android";
- args[5] = devpath;
- args[6] = NULL;
- rc = logwrap(7, args, 1);
- } else {
- char *args[7];
- args[0] = MKE2FS_PATH;
- args[1] = "-b 4096";
- args[2] = "-m 1";
- args[3] = "-L android";
- args[4] = "-v";
- args[5] = devpath;
- args[6] = NULL;
- rc = logwrap(6, args, 1);
- }
-
- free(devpath);
-
- if (rc == 0) {
- LOG_VOL("Filesystem formatted OK");
- return 0;
- } else {
- LOGE("Format failed (unknokwn exit code %d)", rc);
- return -EIO;
- }
- return 0;
-}
-
-int initialize_mbr(blkdev_t *disk)
-{
- int fd, rc;
- unsigned char block[512];
- struct dos_partition part;
- char *devpath;
-
- devpath = blkdev_get_devpath(disk);
-
- memset(&part, 0, sizeof(part));
- part.dp_flag = 0x80;
- part.dp_typ = 0xc;
- part.dp_start = ((1024 * 64) / 512) + 1;
- part.dp_size = disk->nr_sec - part.dp_start;
-
- memset(block, 0, sizeof(block));
- block[0x1fe] = 0x55;
- block[0x1ff] = 0xaa;
-
- dos_partition_enc(block + DOSPARTOFF, &part);
-
- if ((fd = open(devpath, O_RDWR)) < 0) {
- LOGE("Error opening disk file (%s)", strerror(errno));
- return -errno;
- }
- free(devpath);
-
- if (write(fd, block, sizeof(block)) < 0) {
- LOGE("Error writing MBR (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
-
- if (ioctl(fd, BLKRRPART, NULL) < 0) {
- LOGE("Error re-reading partition table (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
- close(fd);
- return 0;
-}
diff --git a/vold/format.h b/vold/format.h
deleted file mode 100644
index 73cc012..0000000
--- a/vold/format.h
+++ /dev/null
@@ -1,26 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _FORMAT_H
-#define _FORMAT_H
-
-#define FORMAT_TYPE_EXT2 "ext2"
-#define FORMAT_TYPE_FAT32 "fat32"
-
-int format_partition(blkdev_t *part, char *type);
-int initialize_mbr(blkdev_t *disk);
-#endif
diff --git a/vold/geom_mbr_enc.c b/vold/geom_mbr_enc.c
deleted file mode 100644
index f1f8339..0000000
--- a/vold/geom_mbr_enc.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * Copyright (c) 2003 Poul-Henning Kamp
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Functions to encode or decode struct dos_partition into a bytestream
- * of correct endianess and packing. These functions do no validation
- * or sanity checking, they only pack/unpack the fields correctly.
- *
- * NB! This file must be usable both in kernel and userland.
- */
-
-#include <sys/types.h>
-#include <sys/endian.h>
-
-#include "diskmbr.h"
-
-static __inline uint32_t __unused
-le32dec(const void *buf)
-{
- const uint8_t *p = (const uint8_t *)buf;
-
- return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
-}
-
-static __inline void
-le32enc(void *pp, uint32_t u)
-{
- unsigned char *p = (unsigned char *)pp;
-
- p[0] = u & 0xff;
- p[1] = (u >> 8) & 0xff;
- p[2] = (u >> 16) & 0xff;
- p[3] = (u >> 24) & 0xff;
-}
-
-void
-dos_partition_dec(void const *pp, struct dos_partition *d)
-{
- unsigned char const *p = pp;
-
- d->dp_flag = p[0];
- d->dp_shd = p[1];
- d->dp_ssect = p[2];
- d->dp_scyl = p[3];
- d->dp_typ = p[4];
- d->dp_ehd = p[5];
- d->dp_esect = p[6];
- d->dp_ecyl = p[7];
- d->dp_start = le32dec(p + 8);
- d->dp_size = le32dec(p + 12);
-}
-
-void
-dos_partition_enc(void *pp, struct dos_partition *d)
-{
- unsigned char *p = pp;
-
- p[0] = d->dp_flag;
- p[1] = d->dp_shd;
- p[2] = d->dp_ssect;
- p[3] = d->dp_scyl;
- p[4] = d->dp_typ;
- p[5] = d->dp_ehd;
- p[6] = d->dp_esect;
- p[7] = d->dp_ecyl;
- le32enc(p + 8, d->dp_start);
- le32enc(p + 12, d->dp_size);
-}
diff --git a/vold/logwrapper.c b/vold/logwrapper.c
deleted file mode 100644
index 8da4892..0000000
--- a/vold/logwrapper.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include "private/android_filesystem_config.h"
-#include "cutils/log.h"
-
-int parent(const char *tag, int parent_read) {
- int status;
- char buffer[4096];
-
- int a = 0; // start index of unprocessed data
- int b = 0; // end index of unprocessed data
- int sz;
- while ((sz = read(parent_read, &buffer[b], sizeof(buffer) - 1 - b)) > 0) {
-
- sz += b;
- // Log one line at a time
- for (b = 0; b < sz; b++) {
- if (buffer[b] == '\r') {
- buffer[b] = '\0';
- } else if (buffer[b] == '\n') {
- buffer[b] = '\0';
-
- LOG(LOG_INFO, tag, "%s", &buffer[a]);
- a = b + 1;
- }
- }
-
- if (a == 0 && b == sizeof(buffer) - 1) {
- // buffer is full, flush
- buffer[b] = '\0';
- LOG(LOG_INFO, tag, &buffer[a]);
- b = 0;
- } else if (a != b) {
- // Keep left-overs
- b -= a;
- memmove(buffer, &buffer[a], b);
- a = 0;
- } else {
- a = 0;
- b = 0;
- }
-
- }
- // Flush remaining data
- if (a != b) {
- buffer[b] = '\0';
- LOG(LOG_INFO, tag, &buffer[a]);
- }
- status = 0xAAAA;
- if (wait(&status) != -1) { // Wait for child
- if (WIFEXITED(status)) {
- LOG(LOG_INFO, "logwrapper", "%s terminated by exit(%d)", tag,
- WEXITSTATUS(status));
- return WEXITSTATUS(status);
- } else if (WIFSIGNALED(status))
- LOG(LOG_INFO, "logwrapper", "%s terminated by signal %d", tag,
- WTERMSIG(status));
- else if (WIFSTOPPED(status))
- LOG(LOG_INFO, "logwrapper", "%s stopped by signal %d", tag,
- WSTOPSIG(status));
- } else
- LOG(LOG_INFO, "logwrapper", "%s wait() failed: %s (%d)", tag,
- strerror(errno), errno);
- return -EAGAIN;
-}
-
-void child(int argc, char* argv[]) {
- // create null terminated argv_child array
- char* argv_child[argc + 1];
- memcpy(argv_child, argv, argc * sizeof(char *));
- argv_child[argc] = NULL;
-
- // XXX: PROTECT FROM VIKING KILLER
- if (execv(argv_child[0], argv_child)) {
- LOG(LOG_ERROR, "logwrapper",
- "executing %s failed: %s", argv_child[0], strerror(errno));
- exit(-1);
- }
-}
-
-int logwrap(int argc, char* argv[], pid_t *childPid, int background)
-{
- pid_t pid;
-
- int parent_ptty;
- int child_ptty;
- char *child_devname = NULL;
-
- /* Use ptty instead of socketpair so that STDOUT is not buffered */
- parent_ptty = open("/dev/ptmx", O_RDWR);
- if (parent_ptty < 0) {
- LOG(LOG_ERROR, "logwrapper", "Cannot create parent ptty");
- return -errno;
- }
-
- if (grantpt(parent_ptty) || unlockpt(parent_ptty) ||
- ((child_devname = (char*)ptsname(parent_ptty)) == 0)) {
- LOG(LOG_ERROR, "logwrapper", "Problem with /dev/ptmx");
- return -1;
- }
-
- pid = fork();
- if (pid < 0) {
- LOG(LOG_ERROR, "logwrapper", "Failed to fork");
- return -errno;
- } else if (pid == 0) {
- child_ptty = open(child_devname, O_RDWR);
- if (child_ptty < 0) {
- LOG(LOG_ERROR, "logwrapper", "Problem with child ptty");
- return -errno;
- }
-
- // redirect stdout and stderr
- close(parent_ptty);
- dup2(child_ptty, 1);
- dup2(child_ptty, 2);
- close(child_ptty);
-
- if (background) {
- int fd = open("/dev/cpuctl/bg_non_interactive/tasks", O_WRONLY);
-
- if (fd >=0 ) {
- char text[64];
-
- sprintf(text, "%d", getpid());
- if (write(fd, text, strlen(text)) < 0) {
- LOG(LOG_WARN, "logwrapper",
- "Unable to background process (%s)", strerror(errno));
- close(fd);
- }
- close(fd);
- } else {
- LOG(LOG_WARN, "logwrapper",
- "Unable to background process (%s)", strerror(errno));
- }
- }
-
- child(argc, argv);
- } else {
- return parent(argv[0], parent_ptty);
- }
-
- return 0;
-}
diff --git a/vold/logwrapper.h b/vold/logwrapper.h
deleted file mode 100644
index bf28aae..0000000
--- a/vold/logwrapper.h
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _LOGWRAPPER_H
-#define _LOGWRAPPER_H
-
-#include <stdlib.h>
-int logwrap(int argc, char* argv[], int background);
-#endif
diff --git a/vold/media.c b/vold/media.c
deleted file mode 100644
index db42a3e..0000000
--- a/vold/media.c
+++ /dev/null
@@ -1,163 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-
-#include <sys/types.h>
-
-#include "vold.h"
-#include "media.h"
-
-static media_list_t *list_root = NULL;
-
-media_t *media_create(char *devpath, char *name, char *serial, media_type_t type)
-{
- media_list_t *list_entry;
- media_t *new;
-
- if (!(new = malloc(sizeof(media_t))))
- return NULL;
-
- memset(new, 0, sizeof(media_t));
-
- if (!(list_entry = malloc(sizeof(media_list_t)))) {
- free(new);
- return NULL;
- }
- list_entry->media = new;
- list_entry->next = NULL;
-
- if (!list_root)
- list_root = list_entry;
- else {
- media_list_t *list_scan = list_root;
- while(list_scan->next)
- list_scan = list_scan->next;
- list_scan->next = list_entry;
- }
-
- new->devpath = strdup(devpath);
- new->name = strdup(name);
- if (!serial)
- new->serial = 0;
- else
- new->serial = strtoul(serial, NULL, 0);
-
- new->media_type = type;
-
- return new;
-}
-
-void media_destroy(media_t *media)
-{
- media_list_t *list_next;
-
- if (list_root->media == media) {
- list_next = list_root->next;
- free(list_root);
- list_root = list_next;
- } else {
- media_list_t *list_scan = list_root;
- while (list_scan->next->media != media)
- list_scan = list_scan -> next;
- list_next = list_scan->next->next;
- free(list_scan->next);
- list_scan->next = list_next;
- }
-
- free(media->devpath);
- free(media->name);
-
- while(media->devs)
- media_remove_blkdev(media, media->devs->dev);
- free(media);
-}
-
-media_t *media_lookup_by_path(char *devpath, boolean fuzzy_match)
-{
- media_list_t *list_scan = list_root;
-
- while (list_scan) {
- if (fuzzy_match) {
- if (!strncmp(list_scan->media->devpath, devpath, strlen(devpath)))
- return list_scan->media;
- } else {
- if (!strcmp(list_scan->media->devpath, devpath))
- return list_scan->media;
- }
- list_scan = list_scan->next;
- }
-#if DEBUG_MEDIA
- LOG_VOL("media_lookup_by_path(): No media found @ %s", devpath);
-#endif
- return NULL;
-}
-
-int media_add_blkdev(media_t *card, blkdev_t *dev)
-{
- blkdev_list_t *list_entry;
-
- if (!(list_entry = malloc(sizeof(blkdev_list_t))))
- return -ENOMEM;
-
- list_entry->next = NULL;
- list_entry->dev = dev;
- if (!card->devs)
- card->devs = list_entry;
- else {
- blkdev_list_t *scan = card->devs;
-
- while(scan->next)
- scan = scan->next;
-
- scan->next = list_entry;
- }
- return 0;
-}
-
-void media_remove_blkdev(media_t *card, blkdev_t *dev)
-{
- if (card->devs->dev == dev)
- card->devs = card->devs->next;
- else {
- blkdev_list_t *scan = card->devs;
- while (scan->next->dev != dev)
- scan = scan -> next;
- blkdev_list_t *next = scan->next->next;
- free(scan->next);
- scan->next = next;
- }
-}
-
-media_t *media_lookup_by_dev(blkdev_t *dev)
-{
- media_list_t *media_scan = list_root;
-
- while (media_scan) {
- blkdev_list_t *blk_scan = media_scan->media->devs;
- while (blk_scan) {
- if (blk_scan->dev == dev)
- return media_scan->media;
- blk_scan = blk_scan->next;
- }
- media_scan = media_scan->next;
- }
- return NULL;
-}
diff --git a/vold/media.h b/vold/media.h
deleted file mode 100644
index 6fd8b84..0000000
--- a/vold/media.h
+++ /dev/null
@@ -1,57 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _MEDIA_H
-#define _MEDIA_H
-
-#include <sys/types.h>
-
-#include "blkdev.h"
-
-typedef enum media_type {
- media_unknown,
- media_mmc,
- media_devmapper,
-} media_type_t;
-
-/*
- * max 8 partitions per card
- */
-#define MMC_PARTS_PER_CARD (1<<3)
-#define ALIGN_MMC_MINOR(min) (min / MMC_PARTS_PER_CARD * MMC_PARTS_PER_CARD)
-
-typedef struct media {
- char *devpath;
- char *name;
- uint32_t serial;
- media_type_t media_type;
-
- blkdev_list_t *devs;
-} media_t;
-
-typedef struct media_list {
- media_t *media;
- struct media_list *next;
-} media_list_t;
-
-media_t *media_create(char *devpath, char *name, char *serial, enum media_type);
-media_t *media_lookup_by_path(char *devpath, boolean fuzzy_match);
-media_t *media_lookup_by_dev(blkdev_t *dev);
-void media_destroy(media_t *media);
-int media_add_blkdev(media_t *media, blkdev_t *dev);
-void media_remove_blkdev(media_t *media, blkdev_t *dev);
-#endif
diff --git a/vold/misc.c b/vold/misc.c
deleted file mode 100644
index 0f8f61e..0000000
--- a/vold/misc.c
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-void *read_file(char *filename, ssize_t *_size)
-{
- int ret, fd;
- struct stat sb;
- ssize_t size;
- void *buffer = NULL;
-
- /* open the file */
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- /* find out how big it is */
- if (fstat(fd, &sb) < 0)
- goto bail;
- size = sb.st_size;
-
- /* allocate memory for it to be read into */
- buffer = malloc(size);
- if (!buffer)
- goto bail;
-
- /* slurp it into our buffer */
- ret = read(fd, buffer, size);
- if (ret != size)
- goto bail;
-
- /* let the caller know how big it is */
- *_size = size;
-
-bail:
- close(fd);
- return buffer;
-}
-char *truncate_sysfs_path(char *path, int num_elements_to_remove, char *buffer, int buffer_size)
-{
- int i;
-
- strncpy(buffer, path, buffer_size);
-
- for (i = 0; i < num_elements_to_remove; i++) {
- char *p = &buffer[strlen(buffer)-1];
-
- for (p = &buffer[strlen(buffer) -1]; *p != '/'; p--);
- *p = '\0';
- }
-
- return buffer;
-}
-
-char *read_sysfs_var(char *buffer, size_t maxlen, char *devpath, char *var)
-{
- char filename[255];
- char *p;
- ssize_t sz;
-
- snprintf(filename, sizeof(filename), "/sys%s/%s", devpath, var);
- p = read_file(filename, &sz);
- p[(strlen(p) - 1)] = '\0';
- strncpy(buffer, p, maxlen);
- free(p);
- return buffer;
-}
-
diff --git a/vold/mmc.c b/vold/mmc.c
deleted file mode 100644
index d90845d..0000000
--- a/vold/mmc.c
+++ /dev/null
@@ -1,301 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-
-#include <sys/types.h>
-
-#include "vold.h"
-#include "mmc.h"
-#include "media.h"
-#include "diskmbr.h" /* for NDOSPART */
-
-#define DEBUG_BOOTSTRAP 0
-
-static int mmc_bootstrap_controller(char *sysfs_path);
-static int mmc_bootstrap_card(char *sysfs_path);
-static int mmc_bootstrap_block(char *devpath);
-static int mmc_bootstrap_mmcblk(char *devpath);
-static int mmc_bootstrap_mmcblk_partition(char *devpath);
-
-/*
- * Bootstrap our mmc information.
- */
-int mmc_bootstrap()
-{
- DIR *d;
- struct dirent *de;
-
- if (!(d = opendir(SYSFS_CLASS_MMC_PATH))) {
- LOG_ERROR("Unable to open '%s' (%s)", SYSFS_CLASS_MMC_PATH,
- strerror(errno));
- return -errno;
- }
-
- while ((de = readdir(d))) {
- char tmp[255];
-
- if (de->d_name[0] == '.')
- continue;
-
- sprintf(tmp, "%s/%s", SYSFS_CLASS_MMC_PATH, de->d_name);
- if (mmc_bootstrap_controller(tmp)) {
- LOG_ERROR("Error bootstrapping controller '%s' (%s)", tmp,
- strerror(errno));
- }
- }
-
- closedir(d);
-
- return 0;
-}
-
-static int mmc_bootstrap_controller(char *sysfs_path)
-{
- DIR *d;
- struct dirent *de;
-
-#if DEBUG_BOOTSTRAP
- LOG_VOL("bootstrap_controller(%s):", sysfs_path);
-#endif
- if (!(d = opendir(sysfs_path))) {
- LOG_ERROR("Unable to open '%s' (%s)", sysfs_path, strerror(errno));
- return -errno;
- }
-
- while ((de = readdir(d))) {
- char tmp[255];
-
- if (de->d_name[0] == '.')
- continue;
-
- if ((!strcmp(de->d_name, "uevent")) ||
- (!strcmp(de->d_name, "subsystem")) ||
- (!strcmp(de->d_name, "device")) ||
- (!strcmp(de->d_name, "power"))) {
- continue;
- }
-
- sprintf(tmp, "%s/%s", sysfs_path, de->d_name);
-
- if (mmc_bootstrap_card(tmp) < 0)
- LOG_ERROR("Error bootstrapping card '%s' (%s)", tmp, strerror(errno));
- } // while
-
- closedir(d);
- return 0;
-}
-
-static int mmc_bootstrap_card(char *sysfs_path)
-{
- char saved_cwd[255];
- char new_cwd[255];
- char *devpath;
- char *uevent_params[4];
- char *p;
- char filename[255];
- char tmp[255];
- ssize_t sz;
-
-#if DEBUG_BOOTSTRAP
- LOG_VOL("bootstrap_card(%s):", sysfs_path);
-#endif
-
- /*
- * sysfs_path is based on /sys/class, but we want the actual device class
- */
- if (!getcwd(saved_cwd, sizeof(saved_cwd))) {
- LOGE("Error getting working dir path");
- return -errno;
- }
-
- if (chdir(sysfs_path) < 0) {
- LOGE("Unable to chdir to %s (%s)", sysfs_path, strerror(errno));
- return -errno;
- }
-
- if (!getcwd(new_cwd, sizeof(new_cwd))) {
- LOGE("Buffer too small for device path");
- return -errno;
- }
-
- if (chdir(saved_cwd) < 0) {
- LOGE("Unable to restore working dir");
- return -errno;
- }
-
- devpath = &new_cwd[4]; // Skip over '/sys'
-
- /*
- * Collect parameters so we can simulate a UEVENT
- */
- sprintf(tmp, "DEVPATH=%s", devpath);
- uevent_params[0] = (char *) strdup(tmp);
-
- sprintf(filename, "/sys%s/type", devpath);
- p = read_file(filename, &sz);
- p[strlen(p) - 1] = '\0';
- sprintf(tmp, "MMC_TYPE=%s", p);
- free(p);
- uevent_params[1] = (char *) strdup(tmp);
-
- sprintf(filename, "/sys%s/name", devpath);
- p = read_file(filename, &sz);
- if (!p) {
- LOGE("Unable to read MMC name: %s", filename);
- return -errno;
- }
- p[strlen(p) - 1] = '\0';
- sprintf(tmp, "MMC_NAME=%s", p);
- free(p);
- uevent_params[2] = (char *) strdup(tmp);
-
- uevent_params[3] = (char *) NULL;
-
- if (simulate_uevent("mmc", devpath, "add", uevent_params) < 0) {
- LOGE("Error simulating uevent (%s)", strerror(errno));
- return -errno;
- }
-
- /*
- * Check for block drivers
- */
- char block_devpath[255];
- sprintf(tmp, "%s/block", devpath);
- sprintf(filename, "/sys%s/block", devpath);
- if (!access(filename, F_OK)) {
- if (mmc_bootstrap_block(tmp)) {
- LOGE("Error bootstrapping block @ %s", tmp);
- }
- }
-
- return 0;
-}
-
-static int mmc_bootstrap_block(char *devpath)
-{
- char blockdir_path[255];
- DIR *d;
- struct dirent *de;
-
-#if DEBUG_BOOTSTRAP
- LOG_VOL("mmc_bootstrap_block(%s):", devpath);
-#endif
-
- sprintf(blockdir_path, "/sys%s", devpath);
-
- if (!(d = opendir(blockdir_path))) {
- LOGE("Failed to opendir %s", devpath);
- return -errno;
- }
-
- while ((de = readdir(d))) {
- char tmp[255];
-
- if (de->d_name[0] == '.')
- continue;
- sprintf(tmp, "%s/%s", devpath, de->d_name);
- if (mmc_bootstrap_mmcblk(tmp))
- LOGE("Error bootstraping mmcblk @ %s", tmp);
- }
- closedir(d);
- return 0;
-}
-
-static int mmc_bootstrap_mmcblk(char *devpath)
-{
- char *mmcblk_devname;
- int part_no;
- int rc;
-
-#if DEBUG_BOOTSTRAP
- LOG_VOL("mmc_bootstrap_mmcblk(%s):", devpath);
-#endif
-
- if ((rc = mmc_bootstrap_mmcblk_partition(devpath))) {
- LOGE("Error bootstrapping mmcblk partition '%s'", devpath);
- return rc;
- }
-
- for (mmcblk_devname = &devpath[strlen(devpath)];
- *mmcblk_devname != '/'; mmcblk_devname--);
- mmcblk_devname++;
-
- for (part_no = 1; part_no <= NDOSPART; part_no++) {
- char part_file[255];
- sprintf(part_file, "/sys%s/%sp%d", devpath, mmcblk_devname, part_no);
- if (!access(part_file, F_OK)) {
- char part_devpath[255];
-
- sprintf(part_devpath, "%s/%sp%d", devpath, mmcblk_devname, part_no);
- if (mmc_bootstrap_mmcblk_partition(part_devpath))
- LOGE("Error bootstrapping mmcblk partition '%s'", part_devpath);
- }
- }
-
- return 0;
-}
-
-static int mmc_bootstrap_mmcblk_partition(char *devpath)
-{
- char filename[255];
- char *uevent_buffer;
- ssize_t sz;
- char *uevent_params[5];
- char tmp[255];
- FILE *fp;
- char line[255];
-
-#if DEBUG_BOOTSTRAP
- LOG_VOL("mmc_bootstrap_mmcblk_partition(%s):", devpath);
-#endif
-
- sprintf(tmp, "DEVPATH=%s", devpath);
- uevent_params[0] = strdup(tmp);
-
- sprintf(filename, "/sys%s/uevent", devpath);
- if (!(fp = fopen(filename, "r"))) {
- LOGE("Unable to open '%s' (%s)", filename, strerror(errno));
- return -errno;
- }
-
- while (fgets(line, sizeof(line), fp)) {
- line[strlen(line)-1] = 0;
- if (!strncmp(line, "DEVTYPE=", 8))
- uevent_params[1] = strdup(line);
- else if (!strncmp(line, "MAJOR=",6))
- uevent_params[2] = strdup(line);
- else if (!strncmp(line, "MINOR=",6))
- uevent_params[3] = strdup(line);
- }
- fclose(fp);
-
- if (!uevent_params[1] || !uevent_params[2] || !uevent_params[3]) {
- LOGE("mmcblk uevent missing required params");
- return -1;
- }
- uevent_params[4] = '\0';
-
- if (simulate_uevent("block", devpath, "add", uevent_params) < 0) {
- LOGE("Error simulating uevent (%s)", strerror(errno));
- return -errno;
- }
- return 0;
-}
diff --git a/vold/mmc.h b/vold/mmc.h
deleted file mode 100644
index 5a5d184..0000000
--- a/vold/mmc.h
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _MMC_H
-#define _MMC_H
-
-#define SYSFS_CLASS_MMC_PATH "/sys/class/mmc_host"
-
-#endif
diff --git a/vold/switch.c b/vold/switch.c
deleted file mode 100644
index d8dab43..0000000
--- a/vold/switch.c
+++ /dev/null
@@ -1,124 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-
-#include <sys/types.h>
-
-#include "vold.h"
-#include "switch.h"
-
-#define DEBUG_BOOTSTRAP 0
-
-static int mmc_bootstrap_switch(char *sysfs_path);
-
-int switch_bootstrap()
-{
- DIR *d;
- struct dirent *de;
-
- if (!(d = opendir(SYSFS_CLASS_SWITCH_PATH))) {
- LOG_ERROR("Unable to open '%s' (%s)", SYSFS_CLASS_SWITCH_PATH,
- strerror(errno));
- return -errno;
- }
-
- while ((de = readdir(d))) {
- char tmp[255];
-
- if (de->d_name[0] == '.')
- continue;
-
- sprintf(tmp, "%s/%s", SYSFS_CLASS_SWITCH_PATH, de->d_name);
- if (mmc_bootstrap_switch(tmp)) {
- LOG_ERROR("Error bootstrapping switch '%s' (%s)", tmp,
- strerror(errno));
- }
- }
-
- closedir(d);
-
- return 0;
-}
-
-static int mmc_bootstrap_switch(char *sysfs_path)
-{
-#if DEBUG_BOOTSTRAP
- LOG_VOL("bootstrap_switch(%s):", sysfs_path);
-#endif
-
- char filename[255];
- char name[255];
- char state[255];
- char tmp[255];
- char *uevent_params[3];
- char devpath[255];
- FILE *fp;
-
- /*
- * Read switch name
- */
- sprintf(filename, "%s/name", sysfs_path);
- if (!(fp = fopen(filename, "r"))) {
- LOGE("Error opening switch name path '%s' (%s)",
- sysfs_path, strerror(errno));
- return -errno;
- }
- if (!fgets(name, sizeof(name), fp)) {
- LOGE("Unable to read switch name");
- fclose(fp);
- return -EIO;
- }
- fclose(fp);
-
- name[strlen(name) -1] = '\0';
- sprintf(devpath, "/devices/virtual/switch/%s", name);
- sprintf(tmp, "SWITCH_NAME=%s", name);
- uevent_params[0] = (char *) strdup(tmp);
-
- /*
- * Read switch state
- */
- sprintf(filename, "%s/state", sysfs_path);
- if (!(fp = fopen(filename, "r"))) {
- LOGE("Error opening switch state path '%s' (%s)",
- sysfs_path, strerror(errno));
- return -errno;
- }
- if (!fgets(state, sizeof(state), fp)) {
- LOGE("Unable to read switch state");
- fclose(fp);
- return -EIO;
- }
- fclose(fp);
-
- state[strlen(state) -1] = '\0';
- sprintf(tmp, "SWITCH_STATE=%s", state);
- uevent_params[1] = (char *) strdup(tmp);
-
- uevent_params[2] = (char *) NULL;
-
- if (simulate_uevent("switch", devpath, "add", uevent_params) < 0) {
- LOGE("Error simulating uevent (%s)", strerror(errno));
- return -errno;
- }
-
- return 0;
-}
diff --git a/vold/switch.h b/vold/switch.h
deleted file mode 100644
index 6729f2d..0000000
--- a/vold/switch.h
+++ /dev/null
@@ -1,25 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _SWITCH_H
-#define _SWITCH_H
-
-#include "vold.h"
-
-#define SYSFS_CLASS_SWITCH_PATH "/sys/class/switch"
-
-#endif
diff --git a/vold/uevent.c b/vold/uevent.c
deleted file mode 100644
index dc15d80..0000000
--- a/vold/uevent.c
+++ /dev/null
@@ -1,447 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "vold.h"
-#include "uevent.h"
-#include "mmc.h"
-#include "blkdev.h"
-#include "volmgr.h"
-#include "media.h"
-
-#define DEBUG_UEVENT 0
-
-#define UEVENT_PARAMS_MAX 32
-
-enum uevent_action { action_add, action_remove, action_change };
-
-struct uevent {
- char *path;
- enum uevent_action action;
- char *subsystem;
- char *param[UEVENT_PARAMS_MAX];
- unsigned int seqnum;
-};
-
-struct uevent_dispatch {
- char *subsystem;
- int (* dispatch) (struct uevent *);
-};
-
-static void dump_uevent(struct uevent *);
-static int dispatch_uevent(struct uevent *event);
-static void free_uevent(struct uevent *event);
-static char *get_uevent_param(struct uevent *event, char *param_name);
-
-static int handle_powersupply_event(struct uevent *event);
-static int handle_switch_event(struct uevent *);
-static int handle_battery_event(struct uevent *);
-static int handle_mmc_event(struct uevent *);
-static int handle_block_event(struct uevent *);
-static int handle_bdi_event(struct uevent *);
-static void _cb_blkdev_ok_to_destroy(blkdev_t *dev);
-
-static struct uevent_dispatch dispatch_table[] = {
- { "switch", handle_switch_event },
- { "battery", handle_battery_event },
- { "mmc", handle_mmc_event },
- { "block", handle_block_event },
- { "bdi", handle_bdi_event },
- { "power_supply", handle_powersupply_event },
- { NULL, NULL }
-};
-
-static boolean low_batt = false;
-static boolean door_open = true;
-
-int process_uevent_message(int socket)
-{
- char buffer[64 * 1024]; // Thank god we're not in the kernel :)
- int count;
- char *s = buffer;
- char *end;
- struct uevent *event;
- int param_idx = 0;
- int i;
- int first = 1;
- int rc = 0;
-
- if ((count = recv(socket, buffer, sizeof(buffer), 0)) < 0) {
- LOGE("Error receiving uevent (%s)", strerror(errno));
- return -errno;
- }
-
- if (!(event = malloc(sizeof(struct uevent)))) {
- LOGE("Error allocating memory (%s)", strerror(errno));
- return -errno;
- }
-
- memset(event, 0, sizeof(struct uevent));
-
- end = s + count;
- while (s < end) {
- if (first) {
- char *p;
- for (p = s; *p != '@'; p++);
- p++;
- event->path = strdup(p);
- first = 0;
- } else {
- if (!strncmp(s, "ACTION=", strlen("ACTION="))) {
- char *a = s + strlen("ACTION=");
-
- if (!strcmp(a, "add"))
- event->action = action_add;
- else if (!strcmp(a, "change"))
- event->action = action_change;
- else if (!strcmp(a, "remove"))
- event->action = action_remove;
- } else if (!strncmp(s, "SEQNUM=", strlen("SEQNUM=")))
- event->seqnum = atoi(s + strlen("SEQNUM="));
- else if (!strncmp(s, "SUBSYSTEM=", strlen("SUBSYSTEM=")))
- event->subsystem = strdup(s + strlen("SUBSYSTEM="));
- else
- event->param[param_idx++] = strdup(s);
- }
- s+= strlen(s) + 1;
- }
-
- rc = dispatch_uevent(event);
-
- free_uevent(event);
- return rc;
-}
-
-int simulate_uevent(char *subsys, char *path, char *action, char **params)
-{
- struct uevent *event;
- char tmp[255];
- int i, rc;
-
- if (!(event = malloc(sizeof(struct uevent)))) {
- LOGE("Error allocating memory (%s)", strerror(errno));
- return -errno;
- }
-
- memset(event, 0, sizeof(struct uevent));
-
- event->subsystem = strdup(subsys);
-
- if (!strcmp(action, "add"))
- event->action = action_add;
- else if (!strcmp(action, "change"))
- event->action = action_change;
- else if (!strcmp(action, "remove"))
- event->action = action_remove;
- else {
- LOGE("Invalid action '%s'", action);
- return -1;
- }
-
- event->path = strdup(path);
-
- for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
- if (!params[i])
- break;
- event->param[i] = strdup(params[i]);
- }
-
- rc = dispatch_uevent(event);
- free_uevent(event);
- return rc;
-}
-
-static int dispatch_uevent(struct uevent *event)
-{
- int i;
-
-#if DEBUG_UEVENT
- dump_uevent(event);
-#endif
- for (i = 0; dispatch_table[i].subsystem != NULL; i++) {
- if (!strcmp(dispatch_table[i].subsystem, event->subsystem))
- return dispatch_table[i].dispatch(event);
- }
-
-#if DEBUG_UEVENT
- LOG_VOL("No uevent handlers registered for '%s' subsystem", event->subsystem);
-#endif
- return 0;
-}
-
-static void dump_uevent(struct uevent *event)
-{
- int i;
-
- LOG_VOL("[UEVENT] Sq: %u S: %s A: %d P: %s",
- event->seqnum, event->subsystem, event->action, event->path);
- for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
- if (!event->param[i])
- break;
- LOG_VOL("%s", event->param[i]);
- }
-}
-
-static void free_uevent(struct uevent *event)
-{
- int i;
- free(event->path);
- free(event->subsystem);
- for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
- if (!event->param[i])
- break;
- free(event->param[i]);
- }
- free(event);
-}
-
-static char *get_uevent_param(struct uevent *event, char *param_name)
-{
- int i;
-
- for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
- if (!event->param[i])
- break;
- if (!strncmp(event->param[i], param_name, strlen(param_name)))
- return &event->param[i][strlen(param_name) + 1];
- }
-
- LOGE("get_uevent_param(): No parameter '%s' found", param_name);
- return NULL;
-}
-
-/*
- * ---------------
- * Uevent Handlers
- * ---------------
- */
-
-static int handle_powersupply_event(struct uevent *event)
-{
- char *ps_type = get_uevent_param(event, "POWER_SUPPLY_TYPE");
-
- if (!strcasecmp(ps_type, "battery")) {
- char *ps_cap = get_uevent_param(event, "POWER_SUPPLY_CAPACITY");
- int capacity = atoi(ps_cap);
-
- if (capacity < 5)
- low_batt = true;
- else
- low_batt = false;
- volmgr_safe_mode(low_batt || door_open);
- }
- return 0;
-}
-
-static int handle_switch_event(struct uevent *event)
-{
- char *name = get_uevent_param(event, "SWITCH_NAME");
- char *state = get_uevent_param(event, "SWITCH_STATE");
-
-
- if (!strcmp(name, "usb_mass_storage")) {
- if (!strcmp(state, "online")) {
- ums_hostconnected_set(true);
- } else {
- ums_hostconnected_set(false);
- volmgr_enable_ums(false);
- }
- } else if (!strcmp(name, "sd-door")) {
- if (!strcmp(state, "open"))
- door_open = true;
- else
- door_open = false;
- volmgr_safe_mode(low_batt || door_open);
- }
-
- return 0;
-}
-
-static int handle_battery_event(struct uevent *event)
-{
- return 0;
-}
-
-static int handle_block_event(struct uevent *event)
-{
- char mediapath[255];
- media_t *media;
- int n;
- int maj, min;
- blkdev_t *blkdev;
-
- /*
- * Look for backing media for this block device
- */
- if (!strncmp(get_uevent_param(event, "DEVPATH"),
- "/devices/virtual/",
- strlen("/devices/virtual/"))) {
- n = 0;
- } else if (!strcmp(get_uevent_param(event, "DEVTYPE"), "disk"))
- n = 2;
- else if (!strcmp(get_uevent_param(event, "DEVTYPE"), "partition"))
- n = 3;
- else {
- LOGE("Bad blockdev type '%s'", get_uevent_param(event, "DEVTYPE"));
- return -EINVAL;
- }
-
- truncate_sysfs_path(event->path, n, mediapath, sizeof(mediapath));
-
- if (!(media = media_lookup_by_path(mediapath, false))) {
-#if DEBUG_UEVENT
- LOG_VOL("No backend media found @ device path '%s'", mediapath);
-#endif
- return 0;
- }
-
- maj = atoi(get_uevent_param(event, "MAJOR"));
- min = atoi(get_uevent_param(event, "MINOR"));
-
- if (event->action == action_add) {
- blkdev_t *disk;
-
- /*
- * If there isn't a disk already its because *we*
- * are the disk
- */
- if (media->media_type == media_mmc)
- disk = blkdev_lookup_by_devno(maj, ALIGN_MMC_MINOR(min));
- else
- disk = blkdev_lookup_by_devno(maj, 0);
-
- if (!(blkdev = blkdev_create(disk,
- event->path,
- maj,
- min,
- media,
- get_uevent_param(event, "DEVTYPE")))) {
- LOGE("Unable to allocate new blkdev (%s)", strerror(errno));
- return -1;
- }
-
- blkdev_refresh(blkdev);
-
- /*
- * Add the blkdev to media
- */
- int rc;
- if ((rc = media_add_blkdev(media, blkdev)) < 0) {
- LOGE("Unable to add blkdev to card (%d)", rc);
- return rc;
- }
-
- LOGI("New blkdev %d.%d on media %s, media path %s, Dpp %d",
- blkdev->major, blkdev->minor, media->name, mediapath,
- blkdev_get_num_pending_partitions(blkdev->disk));
-
- if (blkdev_get_num_pending_partitions(blkdev->disk) == 0) {
- if ((rc = volmgr_consider_disk(blkdev->disk)) < 0) {
- if (rc == -EBUSY) {
- LOGI("Volmgr not ready to handle device");
- } else {
- LOGE("Volmgr failed to handle device (%d)", rc);
- return rc;
- }
- }
- }
- } else if (event->action == action_remove) {
- if (!(blkdev = blkdev_lookup_by_devno(maj, min)))
- return 0;
-
- LOGI("Destroying blkdev %d.%d @ %s on media %s", blkdev->major,
- blkdev->minor, blkdev->devpath, media->name);
- volmgr_notify_eject(blkdev, _cb_blkdev_ok_to_destroy);
-
- } else if (event->action == action_change) {
- if (!(blkdev = blkdev_lookup_by_devno(maj, min)))
- return 0;
-
- LOGI("Modified blkdev %d.%d @ %s on media %s", blkdev->major,
- blkdev->minor, blkdev->devpath, media->name);
-
- blkdev_refresh(blkdev);
- } else {
-#if DEBUG_UEVENT
- LOG_VOL("No handler implemented for action %d", event->action);
-#endif
- }
- return 0;
-}
-
-static void _cb_blkdev_ok_to_destroy(blkdev_t *dev)
-{
- media_t *media = media_lookup_by_dev(dev);
- if (media)
- media_remove_blkdev(media, dev);
- blkdev_destroy(dev);
-}
-
-static int handle_bdi_event(struct uevent *event)
-{
- return 0;
-}
-
-static int handle_mmc_event(struct uevent *event)
-{
- if (event->action == action_add) {
- media_t *media;
- char serial[80];
- char *type;
-
- /*
- * Pull card information from sysfs
- */
- type = get_uevent_param(event, "MMC_TYPE");
- if (strcmp(type, "SD") && strcmp(type, "MMC"))
- return 0;
-
- read_sysfs_var(serial, sizeof(serial), event->path, "serial");
- if (!(media = media_create(event->path,
- get_uevent_param(event, "MMC_NAME"),
- serial,
- media_mmc))) {
- LOGE("Unable to allocate new media (%s)", strerror(errno));
- return -1;
- }
- LOGI("New MMC card '%s' (serial %u) added @ %s", media->name,
- media->serial, media->devpath);
- } else if (event->action == action_remove) {
- media_t *media;
-
- if (!(media = media_lookup_by_path(event->path, false))) {
- LOGE("Unable to lookup media '%s'", event->path);
- return -1;
- }
-
- LOGI("MMC card '%s' (serial %u) @ %s removed", media->name,
- media->serial, media->devpath);
- media_destroy(media);
- } else {
-#if DEBUG_UEVENT
- LOG_VOL("No handler implemented for action %d", event->action);
-#endif
- }
-
- return 0;
-}
diff --git a/vold/ums.c b/vold/ums.c
deleted file mode 100644
index 4d0fc25..0000000
--- a/vold/ums.c
+++ /dev/null
@@ -1,129 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-
-#include "vold.h"
-#include "ums.h"
-
-#define DEBUG_UMS 0
-
-static boolean host_connected = false;
-static boolean ums_enabled = false;
-
-int ums_bootstrap(void)
-{
- return 0;
-}
-
-void ums_enabled_set(boolean enabled)
-{
- ums_enabled = enabled;
- send_msg(enabled ? VOLD_EVT_UMS_ENABLED : VOLD_EVT_UMS_DISABLED);
-}
-
-boolean ums_enabled_get()
-{
- return ums_enabled;
-}
-
-void ums_hostconnected_set(boolean connected)
-{
-#if DEBUG_UMS
- LOG_VOL("ums_hostconnected_set(%d):", connected);
-#endif
- host_connected = connected;
-
- if (!connected)
- ums_enabled_set(false);
- send_msg(connected ? VOLD_EVT_UMS_CONNECTED : VOLD_EVT_UMS_DISCONNECTED);
-}
-
-int ums_enable(char *dev_fspath, char *lun_syspath)
-{
- LOG_VOL("ums_enable(%s, %s):", dev_fspath, lun_syspath);
-
- int fd;
- char filename[255];
-
- sprintf(filename, "/sys/%s/file", lun_syspath);
- if ((fd = open(filename, O_WRONLY)) < 0) {
- LOGE("Unable to open '%s' (%s)", filename, strerror(errno));
- return -errno;
- }
-
- if (write(fd, dev_fspath, strlen(dev_fspath)) < 0) {
- LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
-
- close(fd);
- return 0;
-}
-
-int ums_disable(char *lun_syspath)
-{
-#if DEBUG_UMS
- LOG_VOL("ums_disable(%s):", lun_syspath);
-#endif
-
- int fd;
- char filename[255];
-
- sprintf(filename, "/sys/%s/file", lun_syspath);
- if ((fd = open(filename, O_WRONLY)) < 0) {
- LOGE("Unable to open '%s' (%s)", filename, strerror(errno));
- return -errno;
- }
-
- char ch = 0;
-
- if (write(fd, &ch, 1) < 0) {
- LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
-
- close(fd);
- return 0;
-}
-
-boolean ums_hostconnected_get(void)
-{
- return host_connected;
-}
-
-int ums_send_status(void)
-{
- int rc;
-
-#if DEBUG_UMS
- LOG_VOL("ums_send_status():");
-#endif
-
- rc = send_msg(ums_enabled_get() ? VOLD_EVT_UMS_ENABLED :
- VOLD_EVT_UMS_DISABLED);
- if (rc < 0)
- return rc;
-
- rc = send_msg(ums_hostconnected_get() ? VOLD_EVT_UMS_CONNECTED :
- VOLD_EVT_UMS_DISCONNECTED);
-
- return rc;
-}
diff --git a/vold/ums.h b/vold/ums.h
deleted file mode 100644
index 02cdec3..0000000
--- a/vold/ums.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _UMS_H
-#define _UMS_H
-
-// these must match the corresponding strings in java/android/android/os/UsbListener.java
-#define VOLD_EVT_UMS_ENABLED "ums_enabled"
-#define VOLD_EVT_UMS_DISABLED "ums_disabled"
-#define VOLD_EVT_UMS_CONNECTED "ums_connected"
-#define VOLD_EVT_UMS_DISCONNECTED "ums_disconnected"
-
-
-int ums_send_status(void);
-int ums_enable(char *device_file, char *lun_syspath);
-int ums_disable(char *lun_syspath);
-#endif
diff --git a/vold/vold.c b/vold/vold.c
deleted file mode 100644
index 11b99a9..0000000
--- a/vold/vold.c
+++ /dev/null
@@ -1,238 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <pthread.h>
-
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <cutils/config_utils.h>
-#include <cutils/cpu_info.h>
-#include <cutils/properties.h>
-#include <cutils/sockets.h>
-
-#include <linux/netlink.h>
-
-#include <private/android_filesystem_config.h>
-
-#include "vold.h"
-#include "volmgr.h"
-
-
-#define VOLD_SOCKET "vold"
-
-/*
- * Globals
- */
-
-static int ver_major = 2;
-static int ver_minor = 0;
-static pthread_mutex_t write_mutex = PTHREAD_MUTEX_INITIALIZER;
-static int fw_sock = -1;
-
-int bootstrap = 0;
-
-int main(int argc, char **argv)
-{
- int door_sock = -1;
- int uevent_sock = -1;
- struct sockaddr_nl nladdr;
- int uevent_sz = 64 * 1024;
-
- LOGI("Android Volume Daemon version %d.%d", ver_major, ver_minor);
-
- /*
- * Create all the various sockets we'll need
- */
-
- // Socket to listen on for incomming framework connections
- if ((door_sock = android_get_control_socket(VOLD_SOCKET)) < 0) {
- LOGE("Obtaining file descriptor socket '%s' failed: %s",
- VOLD_SOCKET, strerror(errno));
- exit(1);
- }
-
- if (listen(door_sock, 4) < 0) {
- LOGE("Unable to listen on fd '%d' for socket '%s': %s",
- door_sock, VOLD_SOCKET, strerror(errno));
- exit(1);
- }
-
- mkdir("/dev/block/vold", 0755);
-
- // Socket to listen on for uevent changes
- memset(&nladdr, 0, sizeof(nladdr));
- nladdr.nl_family = AF_NETLINK;
- nladdr.nl_pid = getpid();
- nladdr.nl_groups = 0xffffffff;
-
- if ((uevent_sock = socket(PF_NETLINK,
- SOCK_DGRAM,NETLINK_KOBJECT_UEVENT)) < 0) {
- LOGE("Unable to create uevent socket: %s", strerror(errno));
- exit(1);
- }
-
- if (setsockopt(uevent_sock, SOL_SOCKET, SO_RCVBUFFORCE, &uevent_sz,
- sizeof(uevent_sz)) < 0) {
- LOGE("Unable to set uevent socket options: %s", strerror(errno));
- exit(1);
- }
-
- if (bind(uevent_sock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) {
- LOGE("Unable to bind uevent socket: %s", strerror(errno));
- exit(1);
- }
-
- /*
- * Bootstrap
- */
-
- bootstrap = 1;
- // Volume Manager
- volmgr_bootstrap();
-
- // SD Card system
- mmc_bootstrap();
-
- // USB Mass Storage
- ums_bootstrap();
-
- // Switch
- switch_bootstrap();
-
- bootstrap = 0;
- /*
- * Main loop
- */
- LOG_VOL("Bootstrapping complete");
- while(1) {
- fd_set read_fds;
- struct timeval to;
- int max = 0;
- int rc = 0;
-
- to.tv_sec = (60 * 60);
- to.tv_usec = 0;
-
- FD_ZERO(&read_fds);
- FD_SET(door_sock, &read_fds);
- if (door_sock > max)
- max = door_sock;
- FD_SET(uevent_sock, &read_fds);
- if (uevent_sock > max)
- max = uevent_sock;
-
- if (fw_sock != -1) {
- FD_SET(fw_sock, &read_fds);
- if (fw_sock > max)
- max = fw_sock;
- }
-
- if ((rc = select(max + 1, &read_fds, NULL, NULL, &to)) < 0) {
- LOGE("select() failed (%s)", strerror(errno));
- sleep(1);
- continue;
- }
-
- if (!rc) {
- continue;
- }
-
- if (FD_ISSET(door_sock, &read_fds)) {
- struct sockaddr addr;
- socklen_t alen;
-
- alen = sizeof(addr);
-
- if (fw_sock != -1) {
- LOGE("Dropping duplicate framework connection");
- int tmp = accept(door_sock, &addr, &alen);
- close(tmp);
- continue;
- }
-
- if ((fw_sock = accept(door_sock, &addr, &alen)) < 0) {
- LOGE("Unable to accept framework connection (%s)",
- strerror(errno));
- }
- LOG_VOL("Accepted connection from framework");
- if ((rc = volmgr_send_states()) < 0) {
- LOGE("Unable to send volmgr status to framework (%d)", rc);
- }
- }
-
- if (FD_ISSET(fw_sock, &read_fds)) {
- if ((rc = process_framework_command(fw_sock)) < 0) {
- if (rc == -ECONNRESET) {
- LOGE("Framework disconnected");
- close(fw_sock);
- fw_sock = -1;
- } else {
- LOGE("Error processing framework command (%s)",
- strerror(errno));
- }
- }
- }
-
- if (FD_ISSET(uevent_sock, &read_fds)) {
- if ((rc = process_uevent_message(uevent_sock)) < 0) {
- LOGE("Error processing uevent msg (%s)", strerror(errno));
- }
- }
- } // while
-
-}
-
-int send_msg(char* message)
-{
- int result = -1;
-
- pthread_mutex_lock(&write_mutex);
-
-// LOG_VOL("send_msg(%s):", message);
-
- if (fw_sock >= 0)
- result = write(fw_sock, message, strlen(message) + 1);
-
- pthread_mutex_unlock(&write_mutex);
-
- return result;
-}
-
-int send_msg_with_data(char *message, char *data)
-{
- int result = -1;
-
- char* buffer = (char *)alloca(strlen(message) + strlen(data) + 1);
- if (!buffer) {
- LOGE("alloca failed in send_msg_with_data");
- return -1;
- }
-
- strcpy(buffer, message);
- strcat(buffer, data);
- return send_msg(buffer);
-}
diff --git a/vold/vold.h b/vold/vold.h
deleted file mode 100644
index abc27a1..0000000
--- a/vold/vold.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2008 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 VOLD_H__
-#define VOLD_H__
-
-#define LOG_TAG "vold"
-#include "cutils/log.h"
-
-typedef int boolean;
-enum {
- false = 0,
- true = 1
-};
-
-#define DEVPATH "/dev/block/"
-#define DEVPATHLENGTH 11
-
-#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
-
-// Set this for logging error messages
-#define ENABLE_LOG_ERROR
-
-// set this to log vold events
-#define ENABLE_LOG_VOL
-
-#ifdef ENABLE_LOG_ERROR
-#define LOG_ERROR(fmt, args...) \
- { LOGE(fmt , ## args); }
-#else
-#define LOG_ERROR(fmt, args...) \
- do { } while (0)
-#endif /* ENABLE_LOG_ERROR */
-
-#ifdef ENABLE_LOG_VOL
-#define LOG_VOL(fmt, args...) \
- { LOGD(fmt , ## args); }
-#else
-#define LOG_VOL(fmt, args...) \
- do { } while (0)
-#endif /* ENABLE_LOG_VOL */
-
-#ifdef ENABLE_LOG_SERVER
-#define LOG_SERVER(fmt, args...) \
- { LOGD(fmt , ## args); }
-#else
-#define LOG_SERVER(fmt, args...) \
- do { } while (0)
-#endif /* ENABLE_LOG_SERVER */
-
-#ifdef ENABLE_LOG_ASEC
-#define LOG_ASEC(fmt, args...) \
- { LOGD(fmt , ## args); }
-#else
-#define LOG_ASEC(fmt, args...) \
- do { } while (0)
-#endif /* ENABLE_LOG_ASEC */
-
-/*
- * Prototypes
- */
-
-int process_framework_command(int socket);
-
-int process_inotify_event(int fd);
-int inotify_bootstrap(void);
-
-int process_uevent_message(int socket);
-int simulate_uevent(char *subsystem, char *path, char *action, char **params);
-
-int mmc_bootstrap(void);
-int ums_bootstrap(void);
-
-int volmgr_bootstrap(void);
-
-int switch_bootstrap(void);
-
-void *read_file(char *filename, ssize_t *_size);
-char *truncate_sysfs_path(char *path, int num_elements_to_remove, char *buffer, int buffer_size);
-char *read_sysfs_var(char *buffer, size_t maxlen, char *devpath, char *var);
-
-void ums_hostconnected_set(boolean connected);
-boolean ums_hostconnected_get(void);
-
-int send_msg(char *msg);
-int send_msg_with_data(char *msg, char *data);
-extern int bootstrap;
-#endif
diff --git a/vold/volmgr.c b/vold/volmgr.c
deleted file mode 100644
index deb680e..0000000
--- a/vold/volmgr.c
+++ /dev/null
@@ -1,1247 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sched.h>
-
-#include <sys/mount.h>
-
-#include <cutils/config_utils.h>
-#include <cutils/properties.h>
-
-#include "vold.h"
-#include "volmgr.h"
-#include "blkdev.h"
-#include "ums.h"
-#include "format.h"
-#include "devmapper.h"
-
-#include "volmgr_ext3.h"
-#include "volmgr_vfat.h"
-
-#define DEBUG_VOLMGR 0
-
-static volume_t *vol_root = NULL;
-static boolean safe_mode = true;
-
-static struct volmgr_fstable_entry fs_table[] = {
-// { "ext3", ext_identify, ext_check, ext_mount , true },
- { "vfat", vfat_identify, vfat_check, vfat_mount , false },
- { NULL, NULL, NULL, NULL , false}
-};
-
-struct _volume_state_event_map {
- volume_state_t state;
- char *event;
- char *property_val;
-};
-
-static struct _volume_state_event_map volume_state_strings[] = {
- { volstate_unknown, "volstate_unknown:", "unknown" },
- { volstate_nomedia, VOLD_EVT_NOMEDIA, VOLD_ES_PVAL_NOMEDIA },
- { volstate_unmounted, VOLD_EVT_UNMOUNTED, VOLD_ES_PVAL_UNMOUNTED },
- { volstate_checking, VOLD_EVT_CHECKING, VOLD_ES_PVAL_CHECKING },
- { volstate_mounted, VOLD_EVT_MOUNTED, VOLD_ES_PVAL_MOUNTED },
- { volstate_mounted_ro, VOLD_EVT_MOUNTED_RO, VOLD_ES_PVAL_MOUNTED_RO },
- { volstate_badremoval, VOLD_EVT_BADREMOVAL, VOLD_ES_PVAL_BADREMOVAL },
- { volstate_damaged, VOLD_EVT_DAMAGED, VOLD_ES_PVAL_DAMAGED },
- { volstate_nofs, VOLD_EVT_NOFS, VOLD_ES_PVAL_NOFS },
- { volstate_ums, VOLD_EVT_UMS, VOLD_ES_PVAL_UMS },
- { 0, NULL, NULL }
-};
-
-
-static int volmgr_readconfig(char *cfg_path);
-static int volmgr_config_volume(cnode *node);
-static volume_t *volmgr_lookup_volume_by_mediapath(char *media_path, boolean fuzzy);
-static volume_t *volmgr_lookup_volume_by_dev(blkdev_t *dev);
-static int _volmgr_start(volume_t *vol, blkdev_t *dev);
-static int volmgr_start_fs(struct volmgr_fstable_entry *fs, volume_t *vol, blkdev_t *dev);
-static void *volmgr_start_fs_thread(void *arg);
-static void volmgr_start_fs_thread_sighandler(int signo);
-static void volume_setstate(volume_t *vol, volume_state_t state);
-static char *conv_volstate_to_eventstr(volume_state_t state);
-static char *conv_volstate_to_propstr(volume_state_t state);
-static int volume_send_state(volume_t *vol);
-static void _cb_volstopped_for_ums_enable(volume_t *v, void *arg);
-static int _volmgr_enable_ums(volume_t *);
-static int volmgr_shutdown_volume(volume_t *v, void (* cb) (volume_t *, void *arg), boolean emit_statechange);
-static int volmgr_stop_volume(volume_t *v, void (*cb) (volume_t *, void *), void *arg, boolean emit_statechange);
-static void _cb_volume_stopped_for_eject(volume_t *v, void *arg);
-static void _cb_volume_stopped_for_shutdown(volume_t *v, void *arg);
-static int _volmgr_consider_disk_and_vol(volume_t *vol, blkdev_t *dev);
-static void volmgr_uncage_reaper(volume_t *vol, void (* cb) (volume_t *, void *arg), void *arg);
-static void volmgr_reaper_thread_sighandler(int signo);
-static void volmgr_add_mediapath_to_volume(volume_t *v, char *media_path);
-static int volmgr_send_eject_request(volume_t *v);
-static volume_t *volmgr_lookup_volume_by_mountpoint(char *mount_point, boolean leave_locked);
-
-static boolean _mountpoint_mounted(char *mp)
-{
- char device[256];
- char mount_path[256];
- char rest[256];
- FILE *fp;
- char line[1024];
-
- if (!(fp = fopen("/proc/mounts", "r"))) {
- LOGE("Error opening /proc/mounts (%s)", strerror(errno));
- return false;
- }
-
- while(fgets(line, sizeof(line), fp)) {
- line[strlen(line)-1] = '\0';
- sscanf(line, "%255s %255s %255s\n", device, mount_path, rest);
- if (!strcmp(mount_path, mp)) {
- fclose(fp);
- return true;
- }
-
- }
-
- fclose(fp);
- return false;
-}
-
-/*
- * Public functions
- */
-
-int volmgr_set_volume_key(char *mount_point, unsigned char *key)
-{
- volume_t *v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
-
- if (!v)
- return -ENOENT;
-
- if (v->media_type != media_devmapper) {
- LOGE("Cannot set key on a non devmapper volume");
- pthread_mutex_unlock(&v->lock);
- return -EINVAL;
- }
-
- memcpy(v->dm->key, key, sizeof(v->dm->key));
- pthread_mutex_unlock(&v->lock);
- return 0;
-}
-
-int volmgr_format_volume(char *mount_point)
-{
- int rc;
- volume_t *v;
-
- LOG_VOL("volmgr_format_volume(%s):", mount_point);
-
- v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
-
- if (!v)
- return -ENOENT;
-
- if (v->state == volstate_mounted ||
- v->state == volstate_mounted_ro ||
- v->state == volstate_ums ||
- v->state == volstate_checking) {
- LOGE("Can't format '%s', currently in state %d", mount_point, v->state);
- pthread_mutex_unlock(&v->lock);
- return -EBUSY;
- } else if (v->state == volstate_nomedia &&
- v->media_type != media_devmapper) {
- LOGE("Can't format '%s', (no media)", mount_point);
- pthread_mutex_unlock(&v->lock);
- return -ENOMEDIUM;
- }
-
- // XXX:Reject if the underlying source media is not present
-
- if (v->media_type == media_devmapper) {
- if ((rc = devmapper_genesis(v->dm)) < 0) {
- LOGE("devmapper genesis failed for %s (%d)", mount_point, rc);
- pthread_mutex_unlock(&v->lock);
- return rc;
- }
- } else {
- if ((rc = initialize_mbr(v->dev->disk)) < 0) {
- LOGE("MBR init failed for %s (%d)", mount_point, rc);
- pthread_mutex_unlock(&v->lock);
- return rc;
- }
- }
-
- volume_setstate(v, volstate_formatting);
- pthread_mutex_unlock(&v->lock);
- return rc;
-}
-
-int volmgr_bootstrap(void)
-{
- int rc;
-
- if ((rc = volmgr_readconfig("/system/etc/vold.conf")) < 0) {
- LOGE("Unable to process config");
- return rc;
- }
-
- /*
- * Check to see if any of our volumes is mounted
- */
- volume_t *v = vol_root;
- while (v) {
- if (_mountpoint_mounted(v->mount_point)) {
- LOGW("Volume '%s' already mounted at startup", v->mount_point);
- v->state = volstate_mounted;
- }
- v = v->next;
- }
-
- return 0;
-}
-
-int volmgr_safe_mode(boolean enable)
-{
- if (enable == safe_mode)
- return 0;
-
- safe_mode = enable;
-
- volume_t *v = vol_root;
- int rc;
-
- while (v) {
- pthread_mutex_lock(&v->lock);
- if (v->state == volstate_mounted && v->fs) {
- rc = v->fs->mount_fn(v->dev, v, safe_mode);
- if (!rc) {
- LOGI("Safe mode %s on %s", (enable ? "enabled" : "disabled"), v->mount_point);
- } else {
- LOGE("Failed to %s safe-mode on %s (%s)",
- (enable ? "enable" : "disable" ), v->mount_point, strerror(-rc));
- }
- }
-
- pthread_mutex_unlock(&v->lock);
- v = v->next;
- }
-
- return 0;
-}
-
-int volmgr_send_states(void)
-{
- volume_t *vol_scan = vol_root;
- int rc;
-
- while (vol_scan) {
- pthread_mutex_lock(&vol_scan->lock);
- if ((rc = volume_send_state(vol_scan)) < 0) {
- LOGE("Error sending state to framework (%d)", rc);
- }
- pthread_mutex_unlock(&vol_scan->lock);
- vol_scan = vol_scan->next;
- break; // XXX:
- }
-
- return 0;
-}
-
-/*
- * Called when a block device is ready to be
- * evaluated by the volume manager.
- */
-int volmgr_consider_disk(blkdev_t *dev)
-{
- volume_t *vol;
-
- if (!(vol = volmgr_lookup_volume_by_mediapath(dev->media->devpath, true)))
- return 0;
-
- pthread_mutex_lock(&vol->lock);
-
- if (vol->state == volstate_mounted) {
- LOGE("Volume %s already mounted (did we just crash?)", vol->mount_point);
- pthread_mutex_unlock(&vol->lock);
- return 0;
- }
-
- int rc = _volmgr_consider_disk_and_vol(vol, dev);
- pthread_mutex_unlock(&vol->lock);
- return rc;
-}
-
-int volmgr_start_volume_by_mountpoint(char *mount_point)
-{
- volume_t *v;
-
- v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
- if (!v)
- return -ENOENT;
-
- if (v->media_type == media_devmapper) {
- if (devmapper_start(v->dm) < 0) {
- LOGE("volmgr failed to start devmapper volume '%s'",
- v->mount_point);
- }
- } else if (v->media_type == media_mmc) {
- if (!v->dev) {
- LOGE("Cannot start volume '%s' (volume is not bound)", mount_point);
- pthread_mutex_unlock(&v->lock);
- return -ENOENT;
- }
-
- if (_volmgr_consider_disk_and_vol(v, v->dev->disk) < 0) {
- LOGE("volmgr failed to start volume '%s'", v->mount_point);
- }
- }
-
- pthread_mutex_unlock(&v->lock);
- return 0;
-}
-
-static void _cb_volstopped_for_devmapper_teardown(volume_t *v, void *arg)
-{
- devmapper_stop(v->dm);
- volume_setstate(v, volstate_nomedia);
- pthread_mutex_unlock(&v->lock);
-}
-
-int volmgr_stop_volume_by_mountpoint(char *mount_point)
-{
- int rc;
- volume_t *v;
-
- v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
- if (!v)
- return -ENOENT;
-
- if (v->state == volstate_mounted)
- volmgr_send_eject_request(v);
-
- if (v->media_type == media_devmapper)
- rc = volmgr_shutdown_volume(v, _cb_volstopped_for_devmapper_teardown, false);
- else
- rc = volmgr_shutdown_volume(v, NULL, true);
-
- /*
- * If shutdown returns -EINPROGRESS,
- * do *not* release the lock as
- * it is now owned by the reaper thread
- */
- if (rc != -EINPROGRESS) {
- if (rc)
- LOGE("unable to shutdown volume '%s'", v->mount_point);
- pthread_mutex_unlock(&v->lock);
- }
- return 0;
-}
-
-int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *))
-{
- LOG_VOL("Volmgr notified of %d:%d eject", dev->major, dev->minor);
-
- volume_t *v;
- int rc;
-
- // XXX: Partitioning support is going to need us to stop *all*
- // devices in this volume
- if (!(v = volmgr_lookup_volume_by_dev(dev))) {
- if (cb)
- cb(dev);
- return 0;
- }
-
- pthread_mutex_lock(&v->lock);
-
- volume_state_t old_state = v->state;
-
- if (v->state == volstate_mounted ||
- v->state == volstate_ums ||
- v->state == volstate_checking) {
-
- volume_setstate(v, volstate_badremoval);
-
- /*
- * Stop any devmapper volumes which
- * are using us as a source
- * XXX: We may need to enforce stricter
- * order here
- */
- volume_t *dmvol = vol_root;
- while (dmvol) {
- if ((dmvol->media_type == media_devmapper) &&
- (dmvol->dm->src_type == dmsrc_loopback) &&
- (!strncmp(dmvol->dm->type_data.loop.loop_src,
- v->mount_point, strlen(v->mount_point)))) {
-
- pthread_mutex_lock(&dmvol->lock);
- if (dmvol->state != volstate_nomedia) {
- rc = volmgr_shutdown_volume(dmvol, _cb_volstopped_for_devmapper_teardown, false);
- if (rc != -EINPROGRESS) {
- if (rc)
- LOGE("unable to shutdown volume '%s'", v->mount_point);
- pthread_mutex_unlock(&dmvol->lock);
- }
- } else
- pthread_mutex_unlock(&dmvol->lock);
- }
- dmvol = dmvol->next;
- }
-
- } else if (v->state == volstate_formatting) {
- /*
- * The device is being ejected due to
- * kernel disk revalidation.
- */
- LOG_VOL("Volmgr ignoring eject of %d:%d (volume formatting)",
- dev->major, dev->minor);
- if (cb)
- cb(dev);
- pthread_mutex_unlock(&v->lock);
- return 0;
- } else
- volume_setstate(v, volstate_nomedia);
-
- if (old_state == volstate_ums) {
- ums_disable(v->ums_path);
- pthread_mutex_unlock(&v->lock);
- } else {
- int rc = volmgr_stop_volume(v, _cb_volume_stopped_for_eject, cb, false);
- if (rc != -EINPROGRESS) {
- if (rc)
- LOGE("unable to shutdown volume '%s'", v->mount_point);
- pthread_mutex_unlock(&v->lock);
- }
- }
- return 0;
-}
-
-static void _cb_volume_stopped_for_eject(volume_t *v, void *arg)
-{
- void (* eject_cb) (blkdev_t *) = arg;
-
-#if DEBUG_VOLMGR
- LOG_VOL("Volume %s has been stopped for eject", v->mount_point);
-#endif
-
- if (eject_cb)
- eject_cb(v->dev);
- v->dev = NULL; // Clear dev because its being ejected
-}
-
-/*
- * Instructs the volume manager to enable or disable USB mass storage
- * on any volumes configured to use it.
- */
-int volmgr_enable_ums(boolean enable)
-{
- volume_t *v = vol_root;
-
- while(v) {
- if (v->ums_path) {
- int rc;
-
- if (enable) {
- pthread_mutex_lock(&v->lock);
- if (v->state == volstate_mounted)
- volmgr_send_eject_request(v);
- else if (v->state == volstate_ums || v->state == volstate_nomedia) {
- pthread_mutex_unlock(&v->lock);
- goto next_vol;
- }
-
- // Stop the volume, and enable UMS in the callback
- rc = volmgr_shutdown_volume(v, _cb_volstopped_for_ums_enable, false);
- if (rc != -EINPROGRESS) {
- if (rc)
- LOGE("unable to shutdown volume '%s'", v->mount_point);
- pthread_mutex_unlock(&v->lock);
- }
- } else {
- // Disable UMS
- pthread_mutex_lock(&v->lock);
- if (v->state != volstate_ums) {
- pthread_mutex_unlock(&v->lock);
- goto next_vol;
- }
-
- if ((rc = ums_disable(v->ums_path)) < 0) {
- LOGE("unable to disable ums on '%s'", v->mount_point);
- pthread_mutex_unlock(&v->lock);
- continue;
- }
-
- LOG_VOL("Kick-starting volume %d:%d after UMS disable",
- v->dev->disk->major, v->dev->disk->minor);
- // Start volume
- if ((rc = _volmgr_consider_disk_and_vol(v, v->dev->disk)) < 0) {
- LOGE("volmgr failed to consider disk %d:%d",
- v->dev->disk->major, v->dev->disk->minor);
- }
- pthread_mutex_unlock(&v->lock);
- }
- }
- next_vol:
- v = v->next;
- }
- return 0;
-}
-
-/*
- * Static functions
- */
-
-static int volmgr_send_eject_request(volume_t *v)
-{
- return send_msg_with_data(VOLD_EVT_EJECTING, v->mount_point);
-}
-
-// vol->lock must be held!
-static int _volmgr_consider_disk_and_vol(volume_t *vol, blkdev_t *dev)
-{
- int rc = 0;
-
-#if DEBUG_VOLMGR
- LOG_VOL("volmgr_consider_disk_and_vol(%s, %d:%d):", vol->mount_point,
- dev->major, dev->minor);
-#endif
-
- if (vol->state == volstate_unknown ||
- vol->state == volstate_mounted ||
- vol->state == volstate_mounted_ro) {
- LOGE("Cannot consider volume '%s' because it is in state '%d",
- vol->mount_point, vol->state);
- return -EADDRINUSE;
- }
-
- if (vol->state == volstate_formatting) {
- LOG_VOL("Evaluating dev '%s' for formattable filesystems for '%s'",
- dev->devpath, vol->mount_point);
- /*
- * Since we only support creating 1 partition (right now),
- * we can just lookup the target by devno
- */
- blkdev_t *part;
- if (vol->media_type == media_mmc)
- part = blkdev_lookup_by_devno(dev->major, ALIGN_MMC_MINOR(dev->minor) + 1);
- else
- part = blkdev_lookup_by_devno(dev->major, 1);
- if (!part) {
- if (vol->media_type == media_mmc)
- part = blkdev_lookup_by_devno(dev->major, ALIGN_MMC_MINOR(dev->minor));
- else
- part = blkdev_lookup_by_devno(dev->major, 0);
- if (!part) {
- LOGE("Unable to find device to format");
- return -ENODEV;
- }
- }
-
- if ((rc = format_partition(part,
- vol->media_type == media_devmapper ?
- FORMAT_TYPE_EXT2 : FORMAT_TYPE_FAT32)) < 0) {
- LOGE("format failed (%d)", rc);
- return rc;
- }
-
- }
-
- LOGI("Evaluating dev '%s' for mountable filesystems for '%s'",
- dev->devpath, vol->mount_point);
-
- if (dev->nr_parts == 0) {
- rc = _volmgr_start(vol, dev);
-#if DEBUG_VOLMGR
- LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d", vol->mount_point,
- dev->major, dev->minor, rc);
-#endif
- } else {
- /*
- * Device has multiple partitions
- * This is where interesting partition policies could be implemented.
- * For now just try them in sequence until one succeeds
- */
-
- rc = -ENODEV;
- int i;
- for (i = 0; i < dev->nr_parts; i++) {
- blkdev_t *part;
- if (vol->media_type == media_mmc)
- part = blkdev_lookup_by_devno(dev->major, ALIGN_MMC_MINOR(dev->minor) + (i+1));
- else
- part = blkdev_lookup_by_devno(dev->major, (i+1));
- if (!part) {
- LOGE("Error - unable to lookup partition for blkdev %d:%d",
- dev->major, dev->minor);
- continue;
- }
- rc = _volmgr_start(vol, part);
-#if DEBUG_VOLMGR
- LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d",
- vol->mount_point, part->major, part->minor, rc);
-#endif
- if (!rc || rc == -EBUSY)
- break;
- }
-
- if (rc == -ENODEV) {
- // Assert to make sure each partition had a backing blkdev
- LOGE("Internal consistency error");
- return 0;
- }
- }
-
- if (rc == -ENODATA) {
- LOGE("Device %d:%d contains no usable filesystems",
- dev->major, dev->minor);
- rc = 0;
- }
-
- return rc;
-}
-
-static void volmgr_reaper_thread_sighandler(int signo)
-{
- LOGE("Volume reaper thread got signal %d", signo);
-}
-
-static void __reaper_cleanup(void *arg)
-{
- volume_t *vol = (volume_t *) arg;
-
- if (vol->worker_args.reaper_args.cb)
- vol->worker_args.reaper_args.cb(vol, vol->worker_args.reaper_args.cb_arg);
-
- vol->worker_running = false;
-
- // Wake up anyone that was waiting on this thread
- pthread_mutex_unlock(&vol->worker_sem);
-
- // Unlock the volume
- pthread_mutex_unlock(&vol->lock);
-}
-
-static void *volmgr_reaper_thread(void *arg)
-{
- volume_t *vol = (volume_t *) arg;
-
- pthread_cleanup_push(__reaper_cleanup, arg);
-
- vol->worker_running = true;
- vol->worker_pid = getpid();
-
- struct sigaction actions;
-
- memset(&actions, 0, sizeof(actions));
- sigemptyset(&actions.sa_mask);
- actions.sa_flags = 0;
- actions.sa_handler = volmgr_reaper_thread_sighandler;
- sigaction(SIGUSR1, &actions, NULL);
-
- LOGW("Reaper here - working on %s", vol->mount_point);
-
- boolean send_sig_kill = false;
- int i, rc;
-
- for (i = 0; i < 10; i++) {
- errno = 0;
- rc = umount(vol->mount_point);
- LOGW("volmngr reaper umount(%s) attempt %d (%s)",
- vol->mount_point, i + 1, strerror(errno));
- if (!rc)
- break;
- if (rc && (errno == EINVAL || errno == ENOENT)) {
- rc = 0;
- break;
- }
- sleep(1);
- if (i >= 4) {
- KillProcessesWithOpenFiles(vol->mount_point, send_sig_kill, NULL, 0);
- if (!send_sig_kill)
- send_sig_kill = true;
- }
- }
-
- if (!rc) {
- LOGI("Reaper sucessfully unmounted %s", vol->mount_point);
- vol->fs = NULL;
- volume_setstate(vol, volstate_unmounted);
- } else {
- LOGE("Unable to unmount!! (%d)", rc);
- }
-
- out:
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
- return NULL;
-}
-
-// vol->lock must be held!
-static void volmgr_uncage_reaper(volume_t *vol, void (* cb) (volume_t *, void *arg), void *arg)
-{
-
- if (vol->worker_running) {
- LOGE("Worker thread is currently running.. waiting..");
- pthread_mutex_lock(&vol->worker_sem);
- LOGI("Worker thread now available");
- }
-
- vol->worker_args.reaper_args.cb = cb;
- vol->worker_args.reaper_args.cb_arg = arg;
-
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- pthread_create(&vol->worker_thread, &attr, volmgr_reaper_thread, vol);
-}
-
-static int volmgr_stop_volume(volume_t *v, void (*cb) (volume_t *, void *), void *arg, boolean emit_statechange)
-{
- int i, rc;
-
- if (v->state == volstate_mounted || v->state == volstate_badremoval) {
- // Try to unmount right away (5 retries)
- for (i = 0; i < 5; i++) {
- rc = umount(v->mount_point);
- if (!rc)
- break;
-
- if (rc && (errno == EINVAL || errno == ENOENT)) {
- rc = 0;
- break;
- }
-
- LOGI("volmngr quick stop umount(%s) attempt %d (%s)",
- v->mount_point, i + 1, strerror(errno));
-
- if (i == 0)
- usleep(1000 * 250); // First failure, sleep for 250 ms
- else
- sched_yield();
- }
-
- if (!rc) {
- LOGI("volmgr_stop_volume(%s): Volume unmounted sucessfully",
- v->mount_point);
- if (emit_statechange)
- volume_setstate(v, volstate_unmounted);
- v->fs = NULL;
- goto out_cb_immed;
- }
-
- /*
- * Since the volume is still in use, dispatch the stopping to
- * a thread
- */
- LOGW("Volume %s is busy (%d) - uncaging the reaper", v->mount_point, rc);
- volmgr_uncage_reaper(v, cb, arg);
- return -EINPROGRESS;
- } else if (v->state == volstate_checking) {
- volume_setstate(v, volstate_unmounted);
- if (v->worker_running) {
- LOG_VOL("Cancelling worker thread");
- pthread_kill(v->worker_thread, SIGUSR1);
- } else
- LOGE("Strange... we were in checking state but worker thread wasn't running..");
- goto out_cb_immed;
- }
-
- out_cb_immed:
- if (cb)
- cb(v, arg);
- return 0;
-}
-
-
-/*
- * Gracefully stop a volume
- * v->lock must be held!
- * if we return -EINPROGRESS, do NOT release the lock as the reaper
- * is using the volume
- */
-static int volmgr_shutdown_volume(volume_t *v, void (* cb) (volume_t *, void *), boolean emit_statechange)
-{
- return volmgr_stop_volume(v, cb, NULL, emit_statechange);
-}
-
-static void _cb_volume_stopped_for_shutdown(volume_t *v, void *arg)
-{
- void (* shutdown_cb) (volume_t *) = arg;
-
-#if DEBUG_VOLMGR
- LOG_VOL("Volume %s has been stopped for shutdown", v->mount_point);
-#endif
- shutdown_cb(v);
-}
-
-
-/*
- * Called when a volume is sucessfully unmounted for UMS enable
- */
-static void _cb_volstopped_for_ums_enable(volume_t *v, void *arg)
-{
- int rc;
- char *devdir_path;
-
-#if DEBUG_VOLMGR
- LOG_VOL("_cb_volstopped_for_ums_enable(%s):", v->mount_point);
-#endif
- devdir_path = blkdev_get_devpath(v->dev->disk);
-
- if ((rc = ums_enable(devdir_path, v->ums_path)) < 0) {
- free(devdir_path);
- LOGE("Error enabling ums (%d)", rc);
- return;
- }
- free(devdir_path);
- volume_setstate(v, volstate_ums);
- pthread_mutex_unlock(&v->lock);
-}
-
-static int volmgr_readconfig(char *cfg_path)
-{
- cnode *root = config_node("", "");
- cnode *node;
-
- config_load_file(root, cfg_path);
- node = root->first_child;
-
- while (node) {
- if (!strncmp(node->name, "volume_", 7))
- volmgr_config_volume(node);
- else
- LOGE("Skipping unknown configuration node '%s'", node->name);
- node = node->next;
- }
- return 0;
-}
-
-static void volmgr_add_mediapath_to_volume(volume_t *v, char *media_path)
-{
- int i;
-
-#if DEBUG_VOLMGR
- LOG_VOL("volmgr_add_mediapath_to_volume(%p, %s):", v, media_path);
-#endif
- for (i = 0; i < VOLMGR_MAX_MEDIAPATHS_PER_VOLUME; i++) {
- if (!v->media_paths[i]) {
- v->media_paths[i] = strdup(media_path);
- return;
- }
- }
- LOGE("Unable to add media path '%s' to volume (out of media slots)", media_path);
-}
-
-static int volmgr_config_volume(cnode *node)
-{
- volume_t *new;
- int rc = 0, i;
-
- char *dm_src, *dm_src_type, *dm_tgt, *dm_param, *dm_tgtfs;
- uint32_t dm_size_mb = 0;
-
- dm_src = dm_src_type = dm_tgt = dm_param = dm_tgtfs = NULL;
-#if DEBUG_VOLMGR
- LOG_VOL("volmgr_configure_volume(%s):", node->name);
-#endif
- if (!(new = malloc(sizeof(volume_t))))
- return -ENOMEM;
- memset(new, 0, sizeof(volume_t));
-
- new->state = volstate_nomedia;
- pthread_mutex_init(&new->lock, NULL);
- pthread_mutex_init(&new->worker_sem, NULL);
-
- cnode *child = node->first_child;
-
- while (child) {
- if (!strcmp(child->name, "media_path"))
- volmgr_add_mediapath_to_volume(new, child->value);
- else if (!strcmp(child->name, "emu_media_path"))
- volmgr_add_mediapath_to_volume(new, child->value);
- else if (!strcmp(child->name, "media_type")) {
- if (!strcmp(child->value, "mmc"))
- new->media_type = media_mmc;
- else if (!strcmp(child->value, "devmapper"))
- new->media_type = media_devmapper;
- else {
- LOGE("Invalid media type '%s'", child->value);
- rc = -EINVAL;
- goto out_free;
- }
- } else if (!strcmp(child->name, "mount_point"))
- new->mount_point = strdup(child->value);
- else if (!strcmp(child->name, "ums_path"))
- new->ums_path = strdup(child->value);
- else if (!strcmp(child->name, "dm_src"))
- dm_src = strdup(child->value);
- else if (!strcmp(child->name, "dm_src_type"))
- dm_src_type = strdup(child->value);
- else if (!strcmp(child->name, "dm_src_size_mb"))
- dm_size_mb = atoi(child->value);
- else if (!strcmp(child->name, "dm_target"))
- dm_tgt = strdup(child->value);
- else if (!strcmp(child->name, "dm_target_params"))
- dm_param = strdup(child->value);
- else if (!strcmp(child->name, "dm_target_fs"))
- dm_tgtfs = strdup(child->value);
- else
- LOGE("Ignoring unknown config entry '%s'", child->name);
- child = child->next;
- }
-
- if (new->media_type == media_mmc) {
- if (!new->media_paths[0] || !new->mount_point || new->media_type == media_unknown) {
- LOGE("Required configuration parameter missing for mmc volume");
- rc = -EINVAL;
- goto out_free;
- }
- } else if (new->media_type == media_devmapper) {
- if (!dm_src || !dm_src_type || !dm_tgt ||
- !dm_param || !dm_tgtfs || !dm_size_mb) {
- LOGE("Required configuration parameter missing for devmapper volume");
- rc = -EINVAL;
- goto out_free;
- }
-
- char dm_mediapath[255];
- if (!(new->dm = devmapper_init(dm_src, dm_src_type, dm_size_mb,
- dm_tgt, dm_param, dm_tgtfs, dm_mediapath))) {
- LOGE("Unable to initialize devmapping");
- goto out_free;
- }
- LOG_VOL("media path for devmapper volume = '%s'", dm_mediapath);
- volmgr_add_mediapath_to_volume(new, dm_mediapath);
- }
-
- if (!vol_root)
- vol_root = new;
- else {
- volume_t *scan = vol_root;
- while (scan->next)
- scan = scan->next;
- scan->next = new;
- }
-
- if (dm_src)
- free(dm_src);
- if (dm_src_type)
- free(dm_src_type);
- if (dm_tgt)
- free(dm_tgt);
- if (dm_param)
- free(dm_param);
- if (dm_tgtfs)
- free(dm_tgtfs);
-
- return rc;
-
- out_free:
-
- if (dm_src)
- free(dm_src);
- if (dm_src_type)
- free(dm_src_type);
- if (dm_tgt)
- free(dm_tgt);
- if (dm_param)
- free(dm_param);
- if (dm_tgtfs)
- free(dm_tgtfs);
-
-
- for (i = 0; i < VOLMGR_MAX_MEDIAPATHS_PER_VOLUME; i++) {
- if (new->media_paths[i])
- free(new->media_paths[i]);
- }
- if (new->mount_point)
- free(new->mount_point);
- if (new->ums_path)
- free(new->ums_path);
- return rc;
-}
-
-static volume_t *volmgr_lookup_volume_by_dev(blkdev_t *dev)
-{
- volume_t *scan = vol_root;
- while(scan) {
- if (scan->dev == dev)
- return scan;
- scan = scan->next;
- }
- return NULL;
-}
-
-static volume_t *volmgr_lookup_volume_by_mountpoint(char *mount_point, boolean leave_locked)
-{
- volume_t *v = vol_root;
-
- while(v) {
- pthread_mutex_lock(&v->lock);
- if (!strcmp(v->mount_point, mount_point)) {
- if (!leave_locked)
- pthread_mutex_unlock(&v->lock);
- return v;
- }
- pthread_mutex_unlock(&v->lock);
- v = v->next;
- }
- return NULL;
-}
-
-static volume_t *volmgr_lookup_volume_by_mediapath(char *media_path, boolean fuzzy)
-{
- volume_t *scan = vol_root;
- int i;
-
- while (scan) {
-
- for (i = 0; i < VOLMGR_MAX_MEDIAPATHS_PER_VOLUME; i++) {
- if (!scan->media_paths[i])
- continue;
-
- if (fuzzy && !strncmp(media_path, scan->media_paths[i], strlen(scan->media_paths[i])))
- return scan;
- else if (!fuzzy && !strcmp(media_path, scan->media_paths[i]))
- return scan;
- }
-
- scan = scan->next;
- }
- return NULL;
-}
-
-/*
- * Attempt to bring a volume online
- * Returns: 0 on success, errno on failure, with the following exceptions:
- * - ENODATA - Unsupported filesystem type / blank
- * vol->lock MUST be held!
- */
-static int _volmgr_start(volume_t *vol, blkdev_t *dev)
-{
- struct volmgr_fstable_entry *fs;
- int rc = ENODATA;
-
-#if DEBUG_VOLMGR
- LOG_VOL("_volmgr_start(%s, %d:%d):", vol->mount_point,
- dev->major, dev->minor);
-#endif
-
- if (vol->state == volstate_mounted) {
- LOGE("Unable to start volume '%s' (already mounted)", vol->mount_point);
- return -EBUSY;
- }
-
- for (fs = fs_table; fs->name; fs++) {
- if (!fs->identify_fn(dev))
- break;
- }
-
- if (!fs) {
- LOGE("No supported filesystems on %d:%d", dev->major, dev->minor);
- volume_setstate(vol, volstate_nofs);
- return -ENODATA;
- }
-
- return volmgr_start_fs(fs, vol, dev);
-}
-
-// vol->lock MUST be held!
-static int volmgr_start_fs(struct volmgr_fstable_entry *fs, volume_t *vol, blkdev_t *dev)
-{
- /*
- * Spawn a thread to do the actual checking / mounting in
- */
-
- if (vol->worker_running) {
- LOGE("Worker thread is currently running.. waiting..");
- pthread_mutex_lock(&vol->worker_sem);
- LOGI("Worker thread now available");
- }
-
- vol->dev = dev;
-
- if (bootstrap) {
- LOGI("Aborting start of %s (bootstrap = %d)\n", vol->mount_point,
- bootstrap);
- vol->state = volstate_unmounted;
- return -EBUSY;
- }
-
- vol->worker_args.start_args.fs = fs;
- vol->worker_args.start_args.dev = dev;
-
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- pthread_create(&vol->worker_thread, &attr, volmgr_start_fs_thread, vol);
-
- return 0;
-}
-
-static void __start_fs_thread_lock_cleanup(void *arg)
-{
- volume_t *vol = (volume_t *) arg;
-
-#if DEBUG_VOLMGR
- LOG_VOL("__start_fs_thread_lock_cleanup(%s):", vol->mount_point);
-#endif
-
- vol->worker_running = false;
-
- // Wake up anyone that was waiting on this thread
- pthread_mutex_unlock(&vol->worker_sem);
-
- // Unlock the volume
- pthread_mutex_unlock(&vol->lock);
-}
-
-static void *volmgr_start_fs_thread(void *arg)
-{
- volume_t *vol = (volume_t *) arg;
-
- pthread_cleanup_push(__start_fs_thread_lock_cleanup, arg);
- pthread_mutex_lock(&vol->lock);
-
- vol->worker_running = true;
- vol->worker_pid = getpid();
-
- struct sigaction actions;
-
- memset(&actions, 0, sizeof(actions));
- sigemptyset(&actions.sa_mask);
- actions.sa_flags = 0;
- actions.sa_handler = volmgr_start_fs_thread_sighandler;
- sigaction(SIGUSR1, &actions, NULL);
-
- struct volmgr_fstable_entry *fs = vol->worker_args.start_args.fs;
- blkdev_t *dev = vol->worker_args.start_args.dev;
- int rc;
-
-#if DEBUG_VOLMGR
- LOG_VOL("Worker thread pid %d starting %s fs %d:%d on %s", getpid(),
- fs->name, dev->major, dev->minor, vol->mount_point);
-#endif
-
- if (fs->check_fn) {
-#if DEBUG_VOLMGR
- LOG_VOL("Starting %s filesystem check on %d:%d", fs->name,
- dev->major, dev->minor);
-#endif
- volume_setstate(vol, volstate_checking);
- pthread_mutex_unlock(&vol->lock);
- rc = fs->check_fn(dev);
- pthread_mutex_lock(&vol->lock);
- if (vol->state != volstate_checking) {
- LOGE("filesystem check aborted");
- goto out;
- }
-
- if (rc < 0) {
- LOGE("%s filesystem check failed on %d:%d (%s)", fs->name,
- dev->major, dev->minor, strerror(-rc));
- if (rc == -ENODATA) {
- volume_setstate(vol, volstate_nofs);
- goto out;
- }
- goto out_unmountable;
- }
-#if DEBUG_VOLMGR
- LOGI("%s filesystem check of %d:%d OK", fs->name,
- dev->major, dev->minor);
-#endif
- }
-
- rc = fs->mount_fn(dev, vol, safe_mode);
- if (!rc) {
- LOGI("Sucessfully mounted %s filesystem %d:%d on %s (safe-mode %s)",
- fs->name, dev->major, dev->minor, vol->mount_point,
- (safe_mode ? "on" : "off"));
- vol->fs = fs;
- volume_setstate(vol, volstate_mounted);
- goto out;
- }
-
- LOGE("%s filesystem mount of %d:%d failed (%d)", fs->name, dev->major,
- dev->minor, rc);
-
- out_unmountable:
- volume_setstate(vol, volstate_damaged);
- out:
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
- return NULL;
-}
-
-static void volmgr_start_fs_thread_sighandler(int signo)
-{
- LOGE("Volume startup thread got signal %d", signo);
-}
-
-static void volume_setstate(volume_t *vol, volume_state_t state)
-{
- if (state == vol->state)
- return;
-
-#if DEBUG_VOLMGR
- LOG_VOL("Volume %s state change from %d -> %d", vol->mount_point, vol->state, state);
-#endif
-
- vol->state = state;
-
- char *prop_val = conv_volstate_to_propstr(vol->state);
-
- if (prop_val) {
- property_set(PROP_EXTERNAL_STORAGE_STATE, prop_val);
- volume_send_state(vol);
- }
-}
-
-static int volume_send_state(volume_t *vol)
-{
- char *event = conv_volstate_to_eventstr(vol->state);
-
- return send_msg_with_data(event, vol->mount_point);
-}
-
-static char *conv_volstate_to_eventstr(volume_state_t state)
-{
- int i;
-
- for (i = 0; volume_state_strings[i].event != NULL; i++) {
- if (volume_state_strings[i].state == state)
- break;
- }
-
- return volume_state_strings[i].event;
-}
-
-static char *conv_volstate_to_propstr(volume_state_t state)
-{
- int i;
-
- for (i = 0; volume_state_strings[i].event != NULL; i++) {
- if (volume_state_strings[i].state == state)
- break;
- }
-
- return volume_state_strings[i].property_val;
-}
-
diff --git a/vold/volmgr.h b/vold/volmgr.h
deleted file mode 100644
index 2c7ec50..0000000
--- a/vold/volmgr.h
+++ /dev/null
@@ -1,135 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _VOLMGR_H
-#define _VOLMGR_H
-
-#include <pthread.h>
-
-#include "vold.h"
-#include "blkdev.h"
-#include "media.h"
-#include "devmapper.h"
-
-#define PROP_EXTERNAL_STORAGE_STATE "EXTERNAL_STORAGE_STATE"
-
-// these must match the corresponding states in the MediaState enum.
-// A path to the volume mount point follows the colon
-typedef enum volume_state {
- volstate_unknown,
-
- volstate_nomedia,
-#define VOLD_EVT_NOMEDIA "volume_nomedia:"
-#define VOLD_ES_PVAL_NOMEDIA "removed"
-
- volstate_unmounted,
-#define VOLD_EVT_UNMOUNTED "volume_unmounted:"
-#define VOLD_ES_PVAL_UNMOUNTED "unmounted"
-
- volstate_checking,
-#define VOLD_EVT_CHECKING "volume_checking:"
-#define VOLD_ES_PVAL_CHECKING "checking"
-
- volstate_mounted,
-#define VOLD_EVT_MOUNTED "volume_mounted:"
-#define VOLD_ES_PVAL_MOUNTED "mounted"
-
- volstate_mounted_ro,
-#define VOLD_EVT_MOUNTED_RO "volume_mounted_ro:"
-#define VOLD_ES_PVAL_MOUNTED_RO "mounted_ro"
-
- volstate_badremoval,
-#define VOLD_EVT_BADREMOVAL "volume_badremoval:"
-#define VOLD_ES_PVAL_BADREMOVAL "bad_removal"
-
- volstate_damaged,
-#define VOLD_EVT_DAMAGED "volume_damaged:"
-#define VOLD_ES_PVAL_DAMAGED "unmountable"
-
- volstate_nofs,
-#define VOLD_EVT_NOFS "volume_nofs:"
-#define VOLD_ES_PVAL_NOFS "nofs"
-
- volstate_ums,
-#define VOLD_EVT_UMS "volume_ums:"
-#define VOLD_ES_PVAL_UMS "shared"
-
- volstate_ejecting,
-#define VOLD_EVT_EJECTING "volume_ejecting:"
-#define VOLD_ES_PVAL_EJECTING "ejecting"
-
- volstate_formatting,
-} volume_state_t;
-
-struct volume;
-
-struct volmgr_fstable_entry {
- char *name;
- int (*identify_fn) (blkdev_t *dev);
- int (*check_fn) (blkdev_t *dev);
- int (*mount_fn) (blkdev_t *dev, struct volume *vol, boolean safe_mode);
- boolean case_sensitive_paths;
-};
-
-struct volmgr_start_args {
- struct volmgr_fstable_entry *fs;
- blkdev_t *dev;
-};
-
-struct volmgr_reaper_args {
- void (*cb) (struct volume *, void *);
- void *cb_arg;
-};
-
-#define VOLMGR_MAX_MEDIAPATHS_PER_VOLUME 8
-
-typedef struct volume {
- char *media_paths[VOLMGR_MAX_MEDIAPATHS_PER_VOLUME];
-
- media_type_t media_type;
- char *mount_point;
- char *ums_path;
- struct devmapping *dm;
-
- pthread_mutex_t lock;
- volume_state_t state;
- blkdev_t *dev;
- pid_t worker_pid;
- pthread_t worker_thread;
- union {
- struct volmgr_start_args start_args;
- struct volmgr_reaper_args reaper_args;
- } worker_args;
- boolean worker_running;
- pthread_mutex_t worker_sem;
-
- struct volmgr_fstable_entry *fs;
-
- struct volume *next;
-} volume_t;
-
-int volmgr_consider_disk(blkdev_t *dev);
-int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *));
-int volmgr_send_states(void);
-int volmgr_enable_ums(boolean enable);
-int volmgr_stop_volume_by_mountpoint(char *mount_point);
-int volmgr_start_volume_by_mountpoint(char *mount_point);
-int volmgr_safe_mode(boolean enable);
-int volmgr_format_volume(char *mount_point);
-int volmgr_set_volume_key(char *mount_point, unsigned char *key);
-void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded);
-#endif
diff --git a/vold/volmgr_ext3.c b/vold/volmgr_ext3.c
deleted file mode 100644
index fe3b2bb..0000000
--- a/vold/volmgr_ext3.c
+++ /dev/null
@@ -1,184 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-
-#include <linux/ext2_fs.h>
-#include <linux/ext3_fs.h>
-
-#include "vold.h"
-#include "volmgr.h"
-#include "volmgr_ext3.h"
-#include "logwrapper.h"
-
-
-#define EXT_DEBUG 0
-
-static char E2FSCK_PATH[] = "/system/bin/e2fsck";
-
-int ext_identify(blkdev_t *dev)
-{
- int rc = -1;
- int fd;
- struct ext3_super_block sb;
- char *devpath;
-
-#if EXT_DEBUG
- LOG_VOL("ext_identify(%d:%d):", dev-major, dev->minor);
-#endif
-
- devpath = blkdev_get_devpath(dev);
-
- if ((fd = open(devpath, O_RDWR)) < 0) {
- LOGE("Unable to open device '%s' (%s)", devpath,
- strerror(errno));
- free(devpath);
- return -errno;
- }
-
- if (lseek(fd, 1024, SEEK_SET) < 0) {
- LOGE("Unable to lseek to get superblock (%s)", strerror(errno));
- rc = -errno;
- goto out;
- }
-
- if (read(fd, &sb, sizeof(sb)) != sizeof(sb)) {
- LOGE("Unable to read superblock (%s)", strerror(errno));
- rc = -errno;
- goto out;
- }
-
- if (sb.s_magic == EXT2_SUPER_MAGIC ||
- sb.s_magic == EXT3_SUPER_MAGIC)
- rc = 0;
- else
- rc = -ENODATA;
-
- out:
-#if EXT_DEBUG
- LOG_VOL("ext_identify(%s): rc = %d", devpath, rc);
-#endif
- free(devpath);
- close(fd);
- return rc;
-}
-
-int ext_check(blkdev_t *dev)
-{
- char *devpath;
-
-#if EXT_DEBUG
- LOG_VOL("ext_check(%s):", dev->dev_fspath);
-#endif
-
- devpath = blkdev_get_devpath(dev);
-
- if (access(E2FSCK_PATH, X_OK)) {
- LOGE("ext_check(%s): %s not found (skipping checks)",
- devpath, E2FSCK_PATH);
- free(devpath);
- return 0;
- }
-
- char *args[5];
-
- args[0] = E2FSCK_PATH;
- args[1] = "-v";
- args[2] = "-p";
- args[3] = devpath;
- args[4] = NULL;
-
- int rc = logwrap(4, args, 1);
-
- if (rc == 0) {
- LOG_VOL("filesystem '%s' had no errors", devpath);
- } else if (rc == 1) {
- LOG_VOL("filesystem '%s' had corrected errors", devpath);
- rc = 0;
- } else if (rc == 2) {
- LOGE("VOL volume '%s' had corrected errors (system should be rebooted)", devpath);
- rc = -EIO;
- } else if (rc == 4) {
- LOGE("VOL volume '%s' had uncorrectable errors", devpath);
- rc = -EIO;
- } else if (rc == 8) {
- LOGE("Operational error while checking volume '%s'", devpath);
- rc = -EIO;
- } else {
- LOGE("Unknown e2fsck exit code (%d)", rc);
- rc = -EIO;
- }
- free(devpath);
- return rc;
-}
-
-int ext_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode)
-{
-#if EXT_DEBUG
- LOG_VOL("ext_mount(%s, %s, %d):", dev->dev_fspath, vol->mount_point, safe_mode);
-#endif
-
- char *fs[] = { "ext3", "ext2", NULL };
- char *devpath;
-
- devpath = blkdev_get_devpath(dev);
-
- int flags, rc = 0;
-
- flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_NOATIME | MS_NODIRATIME;
-
- if (safe_mode)
- flags |= MS_SYNCHRONOUS;
-
- if (vol->state == volstate_mounted) {
- LOG_VOL("Remounting %s on %s, safe mode %d", devpath,
- vol->mount_point, safe_mode);
- flags |= MS_REMOUNT;
- }
-
- char **f;
- for (f = fs; *f != NULL; f++) {
- rc = mount(devpath, vol->mount_point, *f, flags, NULL);
- if (rc && errno == EROFS) {
- LOGE("ext_mount(%s, %s): Read only filesystem - retrying mount RO",
- devpath, vol->mount_point);
- flags |= MS_RDONLY;
- rc = mount(devpath, vol->mount_point, *f, flags, NULL);
- }
-#if EXT_DEBUG
- LOG_VOL("ext_mount(%s, %s): %s mount rc = %d", devpath, *f,
- vol->mount_point, rc);
-#endif
- if (!rc)
- break;
- }
- free(devpath);
-
- // Chmod the mount point so that its a free-for-all.
- // (required for consistency with VFAT.. sigh)
- if (chmod(vol->mount_point, 0777) < 0) {
- LOGE("Failed to chmod %s (%s)", vol->mount_point, strerror(errno));
- return -errno;
- }
-
- return rc;
-}
diff --git a/vold/volmgr_ext3.h b/vold/volmgr_ext3.h
deleted file mode 100644
index bfe882a..0000000
--- a/vold/volmgr_ext3.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _VOLMGR_EXT3_H
-#define _VOLMGR_EXT3_H
-
-#include "volmgr.h"
-#include "blkdev.h"
-
-int ext_identify(blkdev_t *blkdev);
-int ext_check(blkdev_t *blkdev);
-int ext_mount(blkdev_t *blkdev, volume_t *vol, boolean safe_mode);
-#endif
diff --git a/vold/volmgr_vfat.c b/vold/volmgr_vfat.c
deleted file mode 100644
index 4c695e4..0000000
--- a/vold/volmgr_vfat.c
+++ /dev/null
@@ -1,165 +0,0 @@
-
-/*
- * Copyright (C) 2008 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.
- */
-
-#include <errno.h>
-
-#include <sys/mount.h>
-#include <cutils/properties.h>
-
-#include "vold.h"
-#include "volmgr.h"
-#include "volmgr_vfat.h"
-#include "logwrapper.h"
-
-#define VFAT_DEBUG 0
-
-static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
-
-int vfat_identify(blkdev_t *dev)
-{
-#if VFAT_DEBUG
- LOG_VOL("vfat_identify(%d:%d):", dev->major, dev->minor);
-#endif
- return 0; // XXX: Implement
-}
-
-int vfat_check(blkdev_t *dev)
-{
- int rc;
- boolean rw = true;
-
-#if VFAT_DEBUG
- LOG_VOL("vfat_check(%d:%d):", dev->major, dev->minor);
-#endif
-
- if (access(FSCK_MSDOS_PATH, X_OK)) {
- LOGE("vfat_check(%d:%d): %s not found (skipping checks)",
- dev->major, dev->minor, FSCK_MSDOS_PATH);
- return 0;
- }
-
- int pass = 1;
- do {
- char *args[5];
- args[0] = FSCK_MSDOS_PATH;
- args[1] = "-p";
- args[2] = "-f";
- args[3] = blkdev_get_devpath(dev);
- args[4] = NULL;
- rc = logwrap(4, args, 1);
- free(args[3]);
-
- if (rc == 0) {
- LOG_VOL("Filesystem check completed OK");
- return 0;
- } else if (rc == 2) {
- LOG_VOL("Filesystem check failed (not a FAT filesystem)");
- return -ENODATA;
- } else if (rc == 4) {
- if (pass++ <= 3) {
- LOG_VOL("Filesystem modified - rechecking (pass %d)",
- pass);
- continue;
- } else {
- LOG_VOL("Failing check after too many rechecks");
- return -EIO;
- }
- } else if (rc == -11) {
- LOG_VOL("Filesystem check crashed");
- return -EIO;
- } else {
- LOG_VOL("Filesystem check failed (unknown exit code %d)", rc);
- return -EIO;
- }
- } while (0);
- return 0;
-}
-
-int vfat_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode)
-{
- int flags, rc;
- char *devpath;
-
- devpath = blkdev_get_devpath(dev);
-
-#if VFAT_DEBUG
- LOG_VOL("vfat_mount(%d:%d, %s, %d):", dev->major, dev->minor, vol->mount_point, safe_mode);
-#endif
-
- flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
-
- if (vol->state == volstate_mounted) {
- LOG_VOL("Remounting %d:%d on %s, safe mode %d", dev->major,
- dev->minor, vol->mount_point, safe_mode);
- flags |= MS_REMOUNT;
- }
-
- /*
- * Note: This is a temporary hack. If the sampling profiler is enabled,
- * we make the SD card world-writable so any process can write snapshots.
- *
- * TODO: Remove this code once we have a drop box in system_server.
- */
- char value[PROPERTY_VALUE_MAX];
- property_get("persist.sampling_profiler", value, "");
- if (value[0] == '1') {
- LOGW("The SD card is world-writable because the"
- " 'persist.sampling_profiler' system property is set to '1'.");
- rc = mount(devpath, vol->mount_point, "vfat", flags,
- "utf8,uid=1000,gid=1015,fmask=000,dmask=000,shortname=mixed");
- } else {
- /*
- * The mount masks restrict access so that:
- * 1. The 'system' user cannot access the SD card at all -
- * (protects system_server from grabbing file references)
- * 2. Group users can RWX
- * 3. Others can only RX
- */
- rc = mount(devpath, vol->mount_point, "vfat", flags,
- "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
- }
-
- if (rc && errno == EROFS) {
- LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO",
- dev->major, dev->minor, vol->mount_point);
- flags |= MS_RDONLY;
- rc = mount(devpath, vol->mount_point, "vfat", flags,
- "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
- }
-
- if (rc == 0) {
- char *lost_path;
- asprintf(&lost_path, "%s/LOST.DIR", vol->mount_point);
- if (access(lost_path, F_OK)) {
- /*
- * Create a LOST.DIR in the root so we have somewhere to put
- * lost cluster chains (fsck_msdos doesn't currently do this)
- */
- if (mkdir(lost_path, 0755)) {
- LOGE("Unable to create LOST.DIR (%s)", strerror(errno));
- }
- }
- free(lost_path);
- }
-
-#if VFAT_DEBUG
- LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor,
- vol->mount_point, rc);
-#endif
- free (devpath);
- return rc;
-}
diff --git a/vold/volmgr_vfat.h b/vold/volmgr_vfat.h
deleted file mode 100644
index d9cf04d..0000000
--- a/vold/volmgr_vfat.h
+++ /dev/null
@@ -1,29 +0,0 @@
-
-/*
- * Copyright (C) 2008 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 _VOLMGR_VFAT_H
-#define _VOLMGR_VFAT_H
-
-#include "volmgr.h"
-#include "blkdev.h"
-
-
-
-int vfat_identify(blkdev_t *blkdev);
-int vfat_check(blkdev_t *blkdev);
-int vfat_mount(blkdev_t *blkdev, volume_t *vol, boolean safe_mode);
-#endif