libfstools: skip JFFS2 padding when BLOCKSIZE was given
[project/fstools.git] / libfstools / mtd.c
index c5dce500c20283f5610b198d2b63a90e1a641893..fe381450940e522833028cb26cfb0f720bd04365 100644 (file)
@@ -67,7 +67,7 @@ static void mtd_volume_close(struct mtd_volume *p)
                return;
 
        close(p->fd);
-       p->fd = 0;
+       p->fd = -1;
 }
 
 static int mtd_volume_load(struct mtd_volume *p)
@@ -76,17 +76,14 @@ static int mtd_volume_load(struct mtd_volume *p)
        struct mtd_info_user mtdInfo;
        struct erase_info_user mtdLockInfo;
 
-       if (p->fd) {
-               lseek(p->fd, 0, SEEK_SET);
-               return 0;
-       }
+       if (p->fd >= 0)
+               return (lseek(p->fd, 0, SEEK_SET) == -1);
 
        if (!p->chr)
                return -1;
 
        p->fd = mtd_open(p->chr, 0);
        if (p->fd < 0) {
-               p->fd = 0;
                ULOG_ERR("Could not open mtd device: %s\n", p->chr);
                return -1;
        }
@@ -167,6 +164,7 @@ static struct volume *mtd_volume_find(char *name)
        v->name = strdup(name);
        v->drv = &mtd_driver;
        p->idx = atoi(idx);
+       p->fd = -1;
 
        snprintf(buffer, sizeof(buffer), "/dev/mtdblock%s", idx);
        v->blk = strdup(buffer);
@@ -338,6 +336,7 @@ static int mtd_volume_write(struct volume *v, void *buf, int offset, int length)
 
 static struct driver mtd_driver = {
        .name = "mtd",
+       .priority = 10,
        .find = mtd_volume_find,
        .init = mtd_volume_init,
        .erase = mtd_volume_erase,