From f1cb0d5b3516152540479d4f970b28b272a4336c Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 1 Jan 2011 20:03:30 -0800 Subject: [PATCH] fix ums mounting Change-Id: I97316668fe3e4447a04cd9f189b0d3d89cd97d9f --- extendedcommands.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/extendedcommands.c b/extendedcommands.c index 2bba90b..f2f1d6c 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -342,10 +342,19 @@ void show_nandroid_restore_menu() void show_mount_usb_storage_menu() { - char command[PATH_MAX]; + int fd; Volume *vol = volume_for_path("/sdcard"); - sprintf(command, "echo %s > /sys/devices/platform/usb_mass_storage/lun0/file", vol->device); - __system(command); + if ((fd = open("/sys/devices/platform/usb_mass_storage/lun0/file", + O_WRONLY)) < 0) { + LOGE("Unable to open ums lunfile (%s)", strerror(errno)); + return -1; + } + + if (write(fd, vol->device, strlen(vol->device)) < 0) { + LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); + close(fd); + return -1; + } static char* headers[] = { "USB Mass Storage device", "Leaving this menu unmount", "your SD card from your PC.", @@ -362,8 +371,17 @@ void show_mount_usb_storage_menu() break; } - __system("echo '' > /sys/devices/platform/usb_mass_storage/lun0/file"); - __system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable"); + if ((fd = open("/sys/devices/platform/usb_mass_storage/lun0/file", O_WRONLY)) < 0) { + LOGE("Unable to open ums lunfile (%s)", strerror(errno)); + return -1; + } + + char ch = 0; + if (write(fd, &ch, 1) < 0) { + LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); + close(fd); + return -1; + } } int confirm_selection(const char* title, const char* confirm)