1 /* vi: set sw=4 ts=4: */
10 #include <sys/mount.h>
12 extern const char mtab_file[]; /* Defined in utility.c */
15 void erase_mtab(const char *name)
17 struct mntent entries[20];
19 FILE *mountTable = setmntent(mtab_file, "r");
22 /* Check if reading the mtab file failed */
24 #if ! defined BB_FEATURE_USE_PROCFS
27 /* Bummer. fall back on trying the /proc filesystem */
28 && (mountTable = setmntent("/proc/mounts", "r")) == 0) {
34 while ((m = getmntent(mountTable)) != 0) {
35 entries[count].mnt_fsname = strdup(m->mnt_fsname);
36 entries[count].mnt_dir = strdup(m->mnt_dir);
37 entries[count].mnt_type = strdup(m->mnt_type);
38 entries[count].mnt_opts = strdup(m->mnt_opts);
39 entries[count].mnt_freq = m->mnt_freq;
40 entries[count].mnt_passno = m->mnt_passno;
43 endmntent(mountTable);
44 if ((mountTable = setmntent(mtab_file, "w"))) {
47 for (i = 0; i < count; i++) {
48 int result = (strcmp(entries[i].mnt_fsname, name) == 0
49 || strcmp(entries[i].mnt_dir, name) == 0);
54 addmntent(mountTable, &entries[i]);
56 endmntent(mountTable);
57 } else if (errno != EROFS)
61 void write_mtab(char *blockDevice, char *directory,
62 char *filesystemType, long flags, char *string_flags)
64 FILE *mountTable = setmntent(mtab_file, "a+");
67 if (mountTable == 0) {
72 int length = strlen(directory);
74 if (length > 1 && directory[length - 1] == '/')
75 directory[length - 1] = '\0';
77 #ifdef BB_FEATURE_USE_PROCFS
78 if (filesystemType == 0) {
79 struct mntent *p = find_mount_point(blockDevice, "/proc/mounts");
82 filesystemType = p->mnt_type;
85 m.mnt_fsname = blockDevice;
86 m.mnt_dir = directory;
87 m.mnt_type = filesystemType ? filesystemType : "default";
90 m.mnt_opts = string_flags;
92 if ((flags | MS_RDONLY) == flags)
100 addmntent(mountTable, &m);
101 endmntent(mountTable);