diff options
author | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-02-08 19:58:47 +0000 |
---|---|---|
committer | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-02-08 19:58:47 +0000 |
commit | a18125005d67c38a8ad7fb454571bb996664ad96 (patch) | |
tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /mtab.c | |
parent | 8ef3b44285a8ce5b83bed9cf32ce5f40b30ba72f (diff) | |
download | busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.gz busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.bz2 busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.zip |
Some formatting updates (ran the code through indent)
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@357 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'mtab.c')
-rw-r--r-- | mtab.c | 98 |
1 files changed, 49 insertions, 49 deletions
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | #include "internal.h" | 2 | #include "internal.h" |
2 | #include <stdlib.h> | 3 | #include <stdlib.h> |
3 | #include <unistd.h> | 4 | #include <unistd.h> |
@@ -8,29 +9,29 @@ | |||
8 | #include <fstab.h> | 9 | #include <fstab.h> |
9 | #include <sys/mount.h> | 10 | #include <sys/mount.h> |
10 | 11 | ||
11 | extern const char mtab_file[]; /* Defined in utility.c */ | 12 | extern const char mtab_file[]; /* Defined in utility.c */ |
12 | 13 | ||
13 | 14 | ||
14 | void erase_mtab(const char * name) | 15 | void erase_mtab(const char *name) |
15 | { | 16 | { |
16 | struct mntent entries[20]; | 17 | struct mntent entries[20]; |
17 | int count = 0; | 18 | int count = 0; |
18 | FILE *mountTable = setmntent(mtab_file, "r"); | 19 | FILE *mountTable = setmntent(mtab_file, "r"); |
19 | struct mntent * m; | 20 | struct mntent *m; |
20 | 21 | ||
21 | /* Check if reading the mtab file failed */ | 22 | /* Check if reading the mtab file failed */ |
22 | if ( mountTable == 0 | 23 | if (mountTable == 0 |
23 | #if ! defined BB_FEATURE_USE_PROCFS | 24 | #if ! defined BB_FEATURE_USE_PROCFS |
24 | ) { | 25 | ) { |
25 | #else | 26 | #else |
26 | /* Bummer. fall back on trying the /proc filesystem */ | 27 | /* Bummer. fall back on trying the /proc filesystem */ |
27 | && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) { | 28 | && (mountTable = setmntent("/proc/mounts", "r")) == 0) { |
28 | #endif | 29 | #endif |
29 | perror(mtab_file); | 30 | perror(mtab_file); |
30 | return; | 31 | return; |
31 | } | 32 | } |
32 | 33 | ||
33 | while ( (m = getmntent(mountTable)) != 0 ) { | 34 | while ((m = getmntent(mountTable)) != 0) { |
34 | entries[count].mnt_fsname = strdup(m->mnt_fsname); | 35 | entries[count].mnt_fsname = strdup(m->mnt_fsname); |
35 | entries[count].mnt_dir = strdup(m->mnt_dir); | 36 | entries[count].mnt_dir = strdup(m->mnt_dir); |
36 | entries[count].mnt_type = strdup(m->mnt_type); | 37 | entries[count].mnt_type = strdup(m->mnt_type); |
@@ -40,64 +41,63 @@ void erase_mtab(const char * name) | |||
40 | count++; | 41 | count++; |
41 | } | 42 | } |
42 | endmntent(mountTable); | 43 | endmntent(mountTable); |
43 | if ( (mountTable = setmntent(mtab_file, "w")) ) { | 44 | if ((mountTable = setmntent(mtab_file, "w"))) { |
44 | int i; | 45 | int i; |
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 ); | ||
48 | 46 | ||
49 | if ( result ) | 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); | ||
50 | |||
51 | if (result) | ||
50 | continue; | 52 | continue; |
51 | else | 53 | else |
52 | addmntent(mountTable, &entries[i]); | 54 | addmntent(mountTable, &entries[i]); |
53 | } | 55 | } |
54 | endmntent(mountTable); | 56 | endmntent(mountTable); |
55 | } | 57 | } else if (errno != EROFS) |
56 | else if ( errno != EROFS ) | ||
57 | perror(mtab_file); | 58 | perror(mtab_file); |
58 | } | 59 | } |
59 | 60 | ||
60 | void write_mtab(char* blockDevice, char* directory, | 61 | void write_mtab(char *blockDevice, char *directory, |
61 | char* filesystemType, long flags, char* string_flags) | 62 | char *filesystemType, long flags, char *string_flags) |
62 | { | 63 | { |
63 | FILE *mountTable = setmntent(mtab_file, "a+"); | 64 | FILE *mountTable = setmntent(mtab_file, "a+"); |
64 | struct mntent m; | 65 | struct mntent m; |
65 | 66 | ||
66 | if ( mountTable == 0 ) { | 67 | if (mountTable == 0) { |
67 | perror(mtab_file); | 68 | perror(mtab_file); |
68 | return; | 69 | return; |
69 | } | 70 | } |
70 | if (mountTable) { | 71 | if (mountTable) { |
71 | int length = strlen(directory); | 72 | int length = strlen(directory); |
72 | 73 | ||
73 | if ( length > 1 && directory[length - 1] == '/' ) | 74 | if (length > 1 && directory[length - 1] == '/') |
74 | directory[length - 1] = '\0'; | 75 | directory[length - 1] = '\0'; |
75 | 76 | ||
76 | #ifdef BB_FEATURE_USE_PROCFS | 77 | #ifdef BB_FEATURE_USE_PROCFS |
77 | if ( filesystemType == 0 ) { | 78 | if (filesystemType == 0) { |
78 | struct mntent *p = findMountPoint(blockDevice, "/proc/mounts"); | 79 | struct mntent *p = findMountPoint(blockDevice, "/proc/mounts"); |
79 | 80 | ||
80 | if ( p && p->mnt_type ) | 81 | if (p && p->mnt_type) |
81 | filesystemType = p->mnt_type; | 82 | filesystemType = p->mnt_type; |
82 | } | 83 | } |
83 | #endif | 84 | #endif |
84 | m.mnt_fsname = blockDevice; | 85 | m.mnt_fsname = blockDevice; |
85 | m.mnt_dir = directory; | 86 | m.mnt_dir = directory; |
86 | m.mnt_type = filesystemType ? filesystemType : "default"; | 87 | m.mnt_type = filesystemType ? filesystemType : "default"; |
87 | 88 | ||
88 | if (*string_flags) { | 89 | if (*string_flags) { |
89 | m.mnt_opts = string_flags; | 90 | m.mnt_opts = string_flags; |
90 | } else { | 91 | } else { |
91 | if ( (flags | MS_RDONLY) == flags ) | 92 | if ((flags | MS_RDONLY) == flags) |
92 | m.mnt_opts = "ro"; | 93 | m.mnt_opts = "ro"; |
93 | else | 94 | else |
94 | m.mnt_opts = "rw"; | 95 | m.mnt_opts = "rw"; |
95 | } | 96 | } |
96 | |||
97 | m.mnt_freq = 0; | ||
98 | m.mnt_passno = 0; | ||
99 | addmntent(mountTable, &m); | ||
100 | endmntent(mountTable); | ||
101 | } | ||
102 | } | ||
103 | 97 | ||
98 | m.mnt_freq = 0; | ||
99 | m.mnt_passno = 0; | ||
100 | addmntent(mountTable, &m); | ||
101 | endmntent(mountTable); | ||
102 | } | ||
103 | } | ||