11 extern const char mtab_file[]; /* Defined in utility.c */
14 void erase_mtab(const char * name)
16 struct mntent entries[20];
18 FILE *mountTable = setmntent(mtab_file, "r");
21 /* Check if reading the mtab file failed */
23 #if ! defined BB_FEATURE_USE_PROCFS
26 /* Bummer. fall back on trying the /proc filesystem */
27 && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
33 while ( (m = getmntent(mountTable)) != 0 ) {
34 entries[count].mnt_fsname = strdup(m->mnt_fsname);
35 entries[count].mnt_dir = strdup(m->mnt_dir);
36 entries[count].mnt_type = strdup(m->mnt_type);
37 entries[count].mnt_opts = strdup(m->mnt_opts);
38 entries[count].mnt_freq = m->mnt_freq;
39 entries[count].mnt_passno = m->mnt_passno;
42 endmntent(mountTable);
43 if ( (mountTable = setmntent(mtab_file, "w")) ) {
45 for ( i = 0; i < count; i++ ) {
46 int result = ( strcmp(entries[i].mnt_fsname, name) == 0
47 || strcmp(entries[i].mnt_dir, name) == 0 );
52 addmntent(mountTable, &entries[i]);
54 endmntent(mountTable);
56 else if ( errno != EROFS )
60 void write_mtab(char* blockDevice, char* directory,
61 char* filesystemType, long flags, char* string_flags)
63 FILE *mountTable = setmntent(mtab_file, "a+");
66 if ( mountTable == 0 ) {
71 int length = strlen(directory);
73 if ( length > 1 && directory[length - 1] == '/' )
74 directory[length - 1] = '\0';
76 #ifdef BB_FEATURE_USE_PROCFS
77 if ( filesystemType == 0 ) {
78 struct mntent *p = findMountPoint(blockDevice, "/proc/mounts");
80 if ( p && p->mnt_type )
81 filesystemType = p->mnt_type;
84 m.mnt_fsname = blockDevice;
85 m.mnt_dir = directory;
86 m.mnt_type = filesystemType ? filesystemType : "default";
89 m.mnt_opts = string_flags;
91 if ( (flags | MS_RDONLY) == flags )
99 addmntent(mountTable, &m);
100 endmntent(mountTable);