1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static const int MS_RDONLY = 1; /* Mount read-only. */
32 void erase_mtab(const char *name)
34 struct mntent entries[20];
36 FILE *mountTable = setmntent(bb_path_mtab_file, "r");
39 /* Check if reading the mtab file failed */
41 /* Bummer. fall back on trying the /proc filesystem */
42 && (mountTable = setmntent("/proc/mounts", "r")) == 0) {
43 bb_perror_msg(bb_path_mtab_file);
47 while ((m = getmntent(mountTable)) != 0) {
48 entries[count].mnt_fsname = strdup(m->mnt_fsname);
49 entries[count].mnt_dir = strdup(m->mnt_dir);
50 entries[count].mnt_type = strdup(m->mnt_type);
51 entries[count].mnt_opts = strdup(m->mnt_opts);
52 entries[count].mnt_freq = m->mnt_freq;
53 entries[count].mnt_passno = m->mnt_passno;
56 endmntent(mountTable);
57 if ((mountTable = setmntent(bb_path_mtab_file, "w"))) {
60 for (i = 0; i < count; i++) {
61 int result = (strcmp(entries[i].mnt_fsname, name) == 0
62 || strcmp(entries[i].mnt_dir, name) == 0);
67 addmntent(mountTable, &entries[i]);
69 endmntent(mountTable);
70 } else if (errno != EROFS)
71 bb_perror_msg(bb_path_mtab_file);
74 void write_mtab(char *blockDevice, char *directory,
75 char *filesystemType, long flags, char *string_flags)
77 FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
80 if (mountTable == 0) {
81 bb_perror_msg(bb_path_mtab_file);
85 int length = strlen(directory);
87 if (length > 1 && directory[length - 1] == '/')
88 directory[length - 1] = '\0';
90 if (filesystemType == 0) {
91 struct mntent *p = find_mount_point(blockDevice, "/proc/mounts");
94 filesystemType = p->mnt_type;
96 m.mnt_fsname = blockDevice;
97 m.mnt_dir = directory;
98 m.mnt_type = filesystemType ? filesystemType : "default";
101 m.mnt_opts = string_flags;
103 if ((flags | MS_RDONLY) == flags)
111 addmntent(mountTable, &m);
112 endmntent(mountTable);