X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffstools.git;a=blobdiff_plain;f=jffs2reset.c;h=13edf1e2a8ec83c5cf4885310a6ef00839c54b8b;hp=0673982f7d85bd06c6653c960c9ac576346958cb;hb=17fec3a09b65e09311042cff037bf97ce28ef693;hpb=9303a84fb4bcf84ebcf58f2afdd7cac7dde0161f diff --git a/jffs2reset.c b/jffs2reset.c index 0673982..13edf1e 100644 --- a/jffs2reset.c +++ b/jffs2reset.c @@ -28,25 +28,25 @@ static int handle_rmdir(const char *dir) { - struct stat s; - struct dirent **namelist; - int n; - - n = scandir(dir, &namelist, NULL, NULL); + struct dirent *dt; + struct stat st; + DIR *d; + int fd; - if (n < 1) + d = opendir(dir); + if (!d) return -1; - while (n--) { - char file[256]; + fd = dirfd(d); + + while ((dt = readdir(d)) != NULL) { + if (fstatat(fd, dt->d_name, &st, AT_SYMLINK_NOFOLLOW) || S_ISDIR(st.st_mode)) + continue; - snprintf(file, sizeof(file), "%s%s", dir, namelist[n]->d_name); - if (!lstat(file, &s) && !S_ISDIR(s.st_mode)) - unlink(file); - free(namelist[n]); + unlinkat(fd, dt->d_name, 0); } - free(namelist); + closedir(d); rmdir(dir); return 0; @@ -84,7 +84,7 @@ jffs2_reset(int argc, char **argv) return -1; } - mp = find_mount_point(v->blk, "jffs2"); + mp = find_mount_point(v->blk, 1); if (mp) { fprintf(stderr, "%s is mounted as %s, only erasing files\n", v->blk, mp); foreachdir(mp, handle_rmdir); @@ -124,7 +124,7 @@ jffs2_mark(int argc, char **argv) sz = write(fd, &deadc0de, sizeof(deadc0de)); close(fd); - if (sz != 1) { + if (sz != 4) { fprintf(stderr, "writing %s failed: %s\n", v->blk, strerror(errno)); return -1; }