aboutsummaryrefslogtreecommitdiffstats
path: root/mtdutils
diff options
context:
space:
mode:
Diffstat (limited to 'mtdutils')
-rw-r--r--mtdutils/Android.mk2
-rw-r--r--mtdutils/mounts.c15
-rw-r--r--mtdutils/mounts.h1
-rw-r--r--mtdutils/mtdutils.c16
4 files changed, 29 insertions, 5 deletions
diff --git a/mtdutils/Android.mk b/mtdutils/Android.mk
index f04355b..b7d35c2 100644
--- a/mtdutils/Android.mk
+++ b/mtdutils/Android.mk
@@ -6,10 +6,12 @@ LOCAL_SRC_FILES := \
mounts.c
LOCAL_MODULE := libmtdutils
+LOCAL_CLANG := true
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
+LOCAL_CLANG := true
LOCAL_SRC_FILES := flash_image.c
LOCAL_MODULE := flash_image
LOCAL_MODULE_TAGS := eng
diff --git a/mtdutils/mounts.c b/mtdutils/mounts.c
index 6a9b03d..41efa37 100644
--- a/mtdutils/mounts.c
+++ b/mtdutils/mounts.c
@@ -153,6 +153,21 @@ unmount_mounted_volume(const MountedVolume *volume)
}
int
+unmount_mounted_volume_detach(const MountedVolume *volume)
+{
+ /* Intentionally pass NULL to umount if the caller tries
+ * to unmount a volume they already unmounted using this
+ * function.
+ */
+ int ret = umount2(volume->mount_point, MNT_DETACH);
+ if (ret == 0) {
+ free_volume_internals(volume, 1);
+ return 0;
+ }
+ return ret;
+}
+
+int
remount_read_only(const MountedVolume* volume)
{
return mount(volume->device, volume->mount_point, volume->filesystem,
diff --git a/mtdutils/mounts.h b/mtdutils/mounts.h
index d721355..c8318c0 100644
--- a/mtdutils/mounts.h
+++ b/mtdutils/mounts.h
@@ -31,6 +31,7 @@ const MountedVolume *
find_mounted_volume_by_mount_point(const char *mount_point);
int unmount_mounted_volume(const MountedVolume *volume);
+int unmount_mounted_volume_detach(const MountedVolume *volume);
int remount_read_only(const MountedVolume* volume);
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index cc30334..ed74d0f 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -28,6 +28,9 @@
#include "mtdutils.h"
+static const char mtdprefix[] = "/dev/block/mtd/by-name/";
+#define MTD_BASENAME_OFFSET (sizeof(mtdprefix)-1+1)
+
struct MtdPartition {
int device_index;
unsigned int size;
@@ -144,7 +147,7 @@ mtd_scan_partitions()
p->device_index = mtdnum;
p->size = mtdsize;
p->erase_size = mtderasesize;
- p->name = strdup(mtdname);
+ asprintf(&p->name, "%s%s", mtdprefix, mtdname);
if (p->name == NULL) {
errno = ENOMEM;
goto bail;
@@ -183,6 +186,9 @@ mtd_find_partition_by_name(const char *name)
if (strcmp(p->name, name) == 0) {
return p;
}
+ if (strcmp(p->name+MTD_BASENAME_OFFSET, name) == 0) {
+ return p;
+ }
}
}
}
@@ -300,20 +306,20 @@ static int read_block(const MtdPartition *partition, int fd, char *data)
if (TEMP_FAILURE_RETRY(lseek64(fd, pos, SEEK_SET)) != pos ||
TEMP_FAILURE_RETRY(read(fd, data, size)) != size) {
printf("mtd: read error at 0x%08llx (%s)\n",
- pos, strerror(errno));
+ (long long)pos, strerror(errno));
} else if (ioctl(fd, ECCGETSTATS, &after)) {
printf("mtd: ECCGETSTATS error (%s)\n", strerror(errno));
return -1;
} else if (after.failed != before.failed) {
printf("mtd: ECC errors (%d soft, %d hard) at 0x%08llx\n",
- after.corrected - before.corrected,
- after.failed - before.failed, pos);
+ after.corrected - before.corrected,
+ after.failed - before.failed, (long long)pos);
// copy the comparison baseline for the next read.
memcpy(&before, &after, sizeof(struct mtd_ecc_stats));
} else if ((mgbb = ioctl(fd, MEMGETBADBLOCK, &pos))) {
fprintf(stderr,
"mtd: MEMGETBADBLOCK returned %d at 0x%08llx: %s\n",
- mgbb, pos, strerror(errno));
+ mgbb, (long long)pos, strerror(errno));
} else {
return 0; // Success!
}