10 extern const char mtab_file[]; /* Defined in utility.c */
13 stralloc(const char * string)
15 int length = strlen(string) + 1;
16 char * n = malloc(length);
17 memcpy(n, string, length);
22 erase_mtab(const char * name)
24 struct mntent entries[20];
26 FILE *mountTable = setmntent(mtab_file, "r");
29 /* Check if reading the mtab file failed */
31 #if ! defined BB_FEATURE_USE_PROCFS
34 /* Bummer. fall back on trying the /proc filesystem */
35 && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
41 while ( (m = getmntent(mountTable)) != 0 ) {
42 entries[count].mnt_fsname = stralloc(m->mnt_fsname);
43 entries[count].mnt_dir = stralloc(m->mnt_dir);
44 entries[count].mnt_type = stralloc(m->mnt_type);
45 entries[count].mnt_opts = stralloc(m->mnt_opts);
46 entries[count].mnt_freq = m->mnt_freq;
47 entries[count].mnt_passno = m->mnt_passno;
50 endmntent(mountTable);
51 if ( (mountTable = setmntent(mtab_file, "w")) ) {
53 for ( i = 0; i < count; i++ ) {
54 int result = ( strcmp(entries[i].mnt_fsname, name) == 0
55 || strcmp(entries[i].mnt_dir, name) == 0 );
60 addmntent(mountTable, &entries[i]);
62 endmntent(mountTable);
64 else if ( errno != EROFS )
69 write_mtab(char* blockDevice, char* directory,
70 char* filesystemType, long flags, char* string_flags)
72 FILE *mountTable = setmntent(mtab_file, "a+");
75 if ( mountTable == 0 ) {
80 int length = strlen(directory);
82 if ( length > 1 && directory[length - 1] == '/' )
83 directory[length - 1] = '\0';
85 #ifdef BB_FEATURE_USE_PROCFS
86 if ( filesystemType == 0 ) {
87 struct mntent *p = findMountPoint(blockDevice, "/proc/mounts");
89 if ( p && p->mnt_type )
90 filesystemType = p->mnt_type;
93 m.mnt_fsname = blockDevice;
94 m.mnt_dir = directory;
95 m.mnt_type = filesystemType ? filesystemType : "default";
98 m.mnt_opts = string_flags;
100 if ( (flags | MS_RDONLY) == flags )
108 addmntent(mountTable, &m);
109 endmntent(mountTable);