libfstools: skip JFFS2 padding when BLOCKSIZE was given
[project/fstools.git] / libfstools / find.c
index 190fa81ad564d75c56ba39b48df33f2729283789..1d91c515b42070406dee79a00dcc5f0575f8a0fd 100644 (file)
@@ -23,6 +23,7 @@ int
 find_overlay_mount(char *overlay)
 {
        FILE *fp = fopen("/proc/mounts", "r");
+       size_t len = strlen(overlay);
        static char line[256];
        int ret = -1;
 
@@ -30,7 +31,7 @@ find_overlay_mount(char *overlay)
                return ret;
 
        while (ret && fgets(line, sizeof(line), fp))
-               if (!strncmp(line, overlay, strlen(overlay)))
+               if (len < sizeof(line) && !strncmp(line, overlay, len) && line[len] == ' ')
                        ret = 0;
 
        fclose(fp);
@@ -46,7 +47,6 @@ find_mount(char *mp)
 {
        FILE *fp = fopen("/proc/mounts", "r");
        static char line[256];
-       char *point = NULL;
 
        if(!fp)
                return NULL;
@@ -75,7 +75,7 @@ find_mount(char *mp)
 
        fclose(fp);
 
-       return point;
+       return NULL;
 }
 
 /*
@@ -104,12 +104,14 @@ find_mount_point(char *block, int root_only)
 {
        FILE *fp = fopen("/proc/self/mountinfo", "r");
        static char line[256];
-       int len = strlen(block);
        char *point = NULL, *pos, *tmp, *cpoint, *devname, *fstype;
        struct stat s;
        int rstat;
        unsigned int minor, major;
 
+       if (!block)
+               return NULL;
+
        if (!fp)
                return NULL;
 
@@ -184,7 +186,7 @@ find_mount_point(char *block, int root_only)
                devname = tmp;
 
                /* if device name matches */
-               if (!strncmp(block, devname, len)) {
+               if (!strcmp(block, devname)) {
                        if (root_only && fs_rootfs_only(fstype))
                                break;
 
@@ -224,7 +226,7 @@ find_filesystem(char *fs)
        int ret = -1;
 
        if (!fp) {
-               ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno));
+               ULOG_ERR("opening /proc/filesystems failed: %m\n");
                goto out;
        }