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");
30 && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
35 while ( (m = getmntent(mountTable)) != 0 ) {
36 entries[count].mnt_fsname = stralloc(m->mnt_fsname);
37 entries[count].mnt_dir = stralloc(m->mnt_dir);
38 entries[count].mnt_type = stralloc(m->mnt_type);
39 entries[count].mnt_opts = stralloc(m->mnt_opts);
40 entries[count].mnt_freq = m->mnt_freq;
41 entries[count].mnt_passno = m->mnt_passno;
44 endmntent(mountTable);
45 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);
58 else if ( errno != EROFS )
63 write_mtab(char* blockDevice, char* directory,
64 char* filesystemType, long flags, char* string_flags)
66 FILE *mountTable = setmntent(mtab_file, "a+");
69 if ( mountTable == 0 ) {
74 int length = strlen(directory);
76 if ( length > 1 && directory[length - 1] == '/' )
77 directory[length - 1] = '\0';
79 if ( filesystemType == 0 ) {
81 = findMountPoint(blockDevice, "/proc/mounts");
83 if ( p && p->mnt_type )
84 filesystemType = p->mnt_type;
86 m.mnt_fsname = blockDevice;
87 m.mnt_dir = directory;
88 m.mnt_type = filesystemType ? filesystemType : "default";
91 m.mnt_opts = string_flags;
93 if ( (flags | MS_RDONLY) == flags )
101 addmntent(mountTable, &m);
102 endmntent(mountTable);