From: Alan Cox Date: Sun, 31 Dec 2017 22:24:33 +0000 (+0000) Subject: remount: use mntent files X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=e86bd04f8a772bc286ac559114b76d5836350037;p=FUZIX.git remount: use mntent files This isn't sufficient for a proper remount but is a straight port of the current usage model. --- diff --git a/Applications/util/remount.c b/Applications/util/remount.c index 0b846a91..bfaf4f88 100644 --- a/Applications/util/remount.c +++ b/Applications/util/remount.c @@ -2,36 +2,28 @@ #include #include #include +#include -/* Assumed length of a line in /etc/mtab */ -#define MTAB_LINE 160 - -char *getdev(char *arg) +static char *getdev(char *arg) { FILE *f; - char tmp[MTAB_LINE]; - char* dev; - char* mntpt; + struct mntent *mnt; - f = fopen("/etc/mtab", "r"); + f = setmntent("/etc/mtab", "r"); if (f) { - while (fgets(tmp, sizeof(tmp), f)) { - dev = strtok(tmp, " \t"); - if (*tmp == '#' || dev == NULL) - continue; - mntpt = strtok(NULL, " \t"); - if (mntpt == NULL) - continue; - if ((strcmp(dev, arg) == 0) || (strcmp(mntpt, arg) == 0)) { - fclose(f); - return strdup(dev); + while (mnt = getmntent(f)) { + if ((strcmp(mnt->mnt_fsname, arg) == 0) || (strcmp(mnt->mnt_dir, arg) == 0)) { + endmntent(f); + return strdup(mnt->mnt_fsname); } } - fclose(f); + endmntent(f); } return NULL; } +/* FIXME: needs to update mtab entry / support nosuid etc ? */ + int main(int argc, char *argv[]) { char *dev;