1 /* vi: set sw=4 ts=4: */
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 /* Bummer. fall back on trying the /proc filesystem */
25 && (mountTable = setmntent("/proc/mounts", "r")) == 0) {
26 perror_msg("%s", mtab_file);
30 while ((m = getmntent(mountTable)) != 0) {
31 entries[count].mnt_fsname = strdup(m->mnt_fsname);
32 entries[count].mnt_dir = strdup(m->mnt_dir);
33 entries[count].mnt_type = strdup(m->mnt_type);
34 entries[count].mnt_opts = strdup(m->mnt_opts);
35 entries[count].mnt_freq = m->mnt_freq;
36 entries[count].mnt_passno = m->mnt_passno;
39 endmntent(mountTable);
40 if ((mountTable = setmntent(mtab_file, "w"))) {
43 for (i = 0; i < count; i++) {
44 int result = (strcmp(entries[i].mnt_fsname, name) == 0
45 || strcmp(entries[i].mnt_dir, name) == 0);
50 addmntent(mountTable, &entries[i]);
52 endmntent(mountTable);
53 } else if (errno != EROFS)
54 perror_msg("%s", mtab_file);
57 void write_mtab(char *blockDevice, char *directory,
58 char *filesystemType, long flags, char *string_flags)
60 FILE *mountTable = setmntent(mtab_file, "a+");
63 if (mountTable == 0) {
64 perror_msg("%s", mtab_file);
68 int length = strlen(directory);
70 if (length > 1 && directory[length - 1] == '/')
71 directory[length - 1] = '\0';
73 if (filesystemType == 0) {
74 struct mntent *p = find_mount_point(blockDevice, "/proc/mounts");
77 filesystemType = p->mnt_type;
79 m.mnt_fsname = blockDevice;
80 m.mnt_dir = directory;
81 m.mnt_type = filesystemType ? filesystemType : "default";
84 m.mnt_opts = string_flags;
86 if ((flags | MS_RDONLY) == flags)
94 addmntent(mountTable, &m);
95 endmntent(mountTable);