{
FILE *fp;
struct mntent *mnt;
+ const char *p;
fp = setmntent("/etc/fstab", "r");
if (fp) {
while (mnt = getmntent(fp)) {
+ p = mnt_device_path(mnt);
if (strcmp(mnt->mnt_dir, mount) == 0) {
endmntent(fp);
- return mnt->mnt_fsname;
+ return p;
}
}
endmntent(fp);
return f;
}
-static int is_mounted(struct mntent *ent)
+static int is_mounted(const char *path)
{
FILE *f = setmntent("/etc/mtab", "r");
struct mntent mnt;
static char buf[_MAX_MNTLEN];
while(getmntent_r(f, &mnt, buf, _MAX_MNTLEN)) {
- if (strcmp(mnt.mnt_fsname, ent->mnt_fsname) == 0) {
+ if (strcmp(mnt.mnt_fsname, path) == 0) {
endmntent(f);
return 1;
}
static void do_mount(struct mntent *mnt)
{
+ const char *p;
if (strcmp(mnt->mnt_type, "swap") == 0)
return;
- if (mount(mnt->mnt_fsname, mnt->mnt_dir, flagsof(mnt)) == -1) {
+ p = mnt_device_path(mnt);
+ if (mount(p, mnt->mnt_dir, flagsof(mnt)) == -1) {
err = errno;
- perror(mnt->mnt_fsname);
+ perror(p);
return;
}
add2mtab(mnt);
static void automount(char *match)
{
FILE *f = setmntent("/etc/fstab", "r");
+ const char *p;
struct mntent *mnt;
while (mnt = getmntent(f)) {
+ p = mnt_device_path(mnt);
/* Warning - mnt contents go invalid if we do work on mtab so
be careful here and use getmntent_r in is_mounted */
- if (is_mounted(mnt))
+ if (is_mounted(p))
continue;
- if (match == NULL || strcmp(mnt->mnt_fsname, match) == 0 ||
+ if (match == NULL || strcmp(p, match) == 0 ||
strcmp(mnt->mnt_dir, match) == 0)
do_mount(mnt);
if (err)
return optbuf;
}
-#define DEV_PATH "/dev/"
-
-static char *root_device(void)
-{
- static DIR dp;
- struct dirent *entry;
- struct stat filestat, rootstat;
- static char namebuf[sizeof(DEV_PATH) + MAXNAMLEN + 1];
-
- if (stat("/", &rootstat) == 0
- && opendir_r(&dp,DEV_PATH) != (DIR *) NULL) {
- while ((entry = readdir(&dp)) != (struct dirent *) NULL) {
- strcpy(namebuf, DEV_PATH);
- strlcat(namebuf, entry->d_name, sizeof(namebuf));
- if (stat(namebuf, &filestat) != 0)
- continue;
- if (!S_ISBLK(filestat.st_mode))
- continue;
- if (filestat.st_rdev != rootstat.st_dev)
- continue;
- return namebuf;
- }
- }
- return NULL;
-}
-
-
static char *getdev(char *arg, char *p)
{
FILE *f;
struct mntent *mnt;
+ const char *path;
f = setmntent(p, "r");
if (f) {
while (mnt = getmntent(f)) {
- if ((strcmp(mnt->mnt_fsname, arg) == 0) || (strcmp(mnt->mnt_dir, arg) == 0)) {
+ path = mnt_device_path(mnt);
+ if ((strcmp(path, arg) == 0) || (strcmp(mnt->mnt_dir, arg) == 0)) {
endmntent(f);
- return strdup(mnt->mnt_fsname);
+ return strdup(path);
}
}
endmntent(f);
we want it to do the right thing anyway so you can clean up nicely */
if (strcmp(arg, "/"))
return NULL;
- return root_device();
+ return root_device_name();
}
static void rewrite_mtab(char *name, int flags)