summaryrefslogtreecommitdiff
path: root/util-linux/mount.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-17 15:00:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-17 15:00:58 +0000
commit8d474b50094b421c484abc528438357c0d70def7 (patch)
tree11d2c47911059360b1e055beee3137886badd8d4 /util-linux/mount.c
parent66fabdb6313caae9ad30cb66a3820402c3f90d97 (diff)
downloadbusybox-w32-8d474b50094b421c484abc528438357c0d70def7.tar.gz
busybox-w32-8d474b50094b421c484abc528438357c0d70def7.tar.bz2
busybox-w32-8d474b50094b421c484abc528438357c0d70def7.zip
mount: style fixes
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r--util-linux/mount.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 5219842ef..bc9759e81 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -101,7 +101,7 @@ struct {
101/* Append mount options to string */ 101/* Append mount options to string */
102static void append_mount_options(char **oldopts, char *newopts) 102static void append_mount_options(char **oldopts, char *newopts)
103{ 103{
104 if(*oldopts && **oldopts) { 104 if (*oldopts && **oldopts) {
105 char *temp = xasprintf("%s,%s",*oldopts,newopts); 105 char *temp = xasprintf("%s,%s",*oldopts,newopts);
106 free(*oldopts); 106 free(*oldopts);
107 *oldopts = temp; 107 *oldopts = temp;
@@ -128,7 +128,7 @@ static int parse_mount_options(char *options, char **unrecognized)
128 for (i = 0; i < (sizeof(mount_options) / sizeof(*mount_options)); i++) { 128 for (i = 0; i < (sizeof(mount_options) / sizeof(*mount_options)); i++) {
129 if (!strcasecmp(mount_options[i].name, options)) { 129 if (!strcasecmp(mount_options[i].name, options)) {
130 long fl = mount_options[i].flags; 130 long fl = mount_options[i].flags;
131 if(fl < 0) flags &= fl; 131 if (fl < 0) flags &= fl;
132 else flags |= fl; 132 else flags |= fl;
133 break; 133 break;
134 } 134 }
@@ -147,7 +147,7 @@ static int parse_mount_options(char *options, char **unrecognized)
147 } 147 }
148 148
149 // Advance to next option, or finish 149 // Advance to next option, or finish
150 if(comma) { 150 if (comma) {
151 *comma = ','; 151 *comma = ',';
152 options = ++comma; 152 options = ++comma;
153 } else break; 153 } else break;
@@ -166,17 +166,18 @@ static llist_t *get_block_backed_filesystems(void)
166 int i; 166 int i;
167 FILE *f; 167 FILE *f;
168 168
169 for(i = 0; filesystems[i]; i++) { 169 for (i = 0; filesystems[i]; i++) {
170 if(!(f = fopen(filesystems[i], "r"))) continue; 170 f = fopen(filesystems[i], "r");
171 if (!f) continue;
171 172
172 for(fs = buf = 0; (fs = buf = bb_get_chomped_line_from_file(f)); 173 for (fs = buf = 0; (fs = buf = bb_get_chomped_line_from_file(f));
173 free(buf)) 174 free(buf))
174 { 175 {
175 if(!strncmp(buf,"nodev",5) && isspace(buf[5])) continue; 176 if (!strncmp(buf,"nodev",5) && isspace(buf[5])) continue;
176 177
177 while(isspace(*fs)) fs++; 178 while (isspace(*fs)) fs++;
178 if(*fs=='#' || *fs=='*') continue; 179 if (*fs=='#' || *fs=='*') continue;
179 if(!*fs) continue; 180 if (!*fs) continue;
180 181
181 llist_add_to_end(&list,xstrdup(fs)); 182 llist_add_to_end(&list,xstrdup(fs));
182 } 183 }
@@ -206,18 +207,19 @@ static int fakeIt;
206#endif 207#endif
207 208
208// Perform actual mount of specific filesystem at specific location. 209// Perform actual mount of specific filesystem at specific location.
210// NB: mp->xxx fields may be trashed on exit
209static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) 211static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
210{ 212{
211 int rc; 213 int rc;
212 214
213 if (fakeIt) { return 0; } 215 if (fakeIt) return 0;
214 216
215 // Mount, with fallback to read-only if necessary. 217 // Mount, with fallback to read-only if necessary.
216 218
217 for(;;) { 219 for (;;) {
218 rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, 220 rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
219 vfsflags, filteropts); 221 vfsflags, filteropts);
220 if(!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS)) 222 if (!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS))
221 break; 223 break;
222 bb_error_msg("%s is write-protected, mounting read-only", 224 bb_error_msg("%s is write-protected, mounting read-only",
223 mp->mnt_fsname); 225 mp->mnt_fsname);
@@ -440,7 +442,6 @@ enum {
440#endif 442#endif
441}; 443};
442 444
443
444/* 445/*
445 * We want to be able to compile mount on old kernels in such a way 446 * We want to be able to compile mount on old kernels in such a way
446 * that the binary will work well on more recent kernels. 447 * that the binary will work well on more recent kernels.
@@ -1283,7 +1284,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
1283 1284
1284 // Might this be an CIFS filesystem? 1285 // Might this be an CIFS filesystem?
1285 1286
1286 if(ENABLE_FEATURE_MOUNT_CIFS && 1287 if (ENABLE_FEATURE_MOUNT_CIFS &&
1287 (!mp->mnt_type || !strcmp(mp->mnt_type,"cifs")) && 1288 (!mp->mnt_type || !strcmp(mp->mnt_type,"cifs")) &&
1288 (mp->mnt_fsname[0]==mp->mnt_fsname[1] && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\'))) 1289 (mp->mnt_fsname[0]==mp->mnt_fsname[1] && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\')))
1289 { 1290 {
@@ -1345,7 +1346,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
1345 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { 1346 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
1346 loopFile = bb_simplify_path(mp->mnt_fsname); 1347 loopFile = bb_simplify_path(mp->mnt_fsname);
1347 mp->mnt_fsname = 0; 1348 mp->mnt_fsname = 0;
1348 switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) { 1349 switch (set_loop(&(mp->mnt_fsname), loopFile, 0)) {
1349 case 0: 1350 case 0:
1350 case 1: 1351 case 1:
1351 break; 1352 break;
@@ -1385,7 +1386,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
1385 for (fl = fslist; fl; fl = fl->link) { 1386 for (fl = fslist; fl; fl = fl->link) {
1386 mp->mnt_type = fl->data; 1387 mp->mnt_type = fl->data;
1387 1388
1388 if (!(rc = mount_it_now(mp,vfsflags, filteropts))) break; 1389 rc = mount_it_now(mp,vfsflags, filteropts);
1390 if (!rc) break;
1389 1391
1390 mp->mnt_type = 0; 1392 mp->mnt_type = 0;
1391 } 1393 }
@@ -1474,7 +1476,7 @@ int mount_main(int argc, char **argv)
1474 if (!all) { 1476 if (!all) {
1475 FILE *mountTable = setmntent(bb_path_mtab_file, "r"); 1477 FILE *mountTable = setmntent(bb_path_mtab_file, "r");
1476 1478
1477 if(!mountTable) bb_error_msg_and_die("no %s",bb_path_mtab_file); 1479 if (!mountTable) bb_error_msg_and_die("no %s",bb_path_mtab_file);
1478 1480
1479 while (getmntent_r(mountTable,mtpair,bb_common_bufsiz1, 1481 while (getmntent_r(mountTable,mtpair,bb_common_bufsiz1,
1480 sizeof(bb_common_bufsiz1))) 1482 sizeof(bb_common_bufsiz1)))
@@ -1521,14 +1523,15 @@ int mount_main(int argc, char **argv)
1521 fstabname = bb_path_mtab_file; 1523 fstabname = bb_path_mtab_file;
1522 else fstabname="/etc/fstab"; 1524 else fstabname="/etc/fstab";
1523 1525
1524 if (!(fstab=setmntent(fstabname,"r"))) 1526 fstab = setmntent(fstabname,"r");
1527 if (!fstab)
1525 bb_perror_msg_and_die("cannot read %s",fstabname); 1528 bb_perror_msg_and_die("cannot read %s",fstabname);
1526 1529
1527 // Loop through entries until we find what we're looking for. 1530 // Loop through entries until we find what we're looking for.
1528 1531
1529 memset(mtpair,0,sizeof(mtpair)); 1532 memset(mtpair,0,sizeof(mtpair));
1530 for (;;) { 1533 for (;;) {
1531 struct mntent *mtnext = mtpair + (mtcur==mtpair ? 1 : 0); 1534 struct mntent *mtnext = (mtcur==mtpair ? mtpair+1 : mtpair);
1532 1535
1533 // Get next fstab entry 1536 // Get next fstab entry
1534 1537
@@ -1565,7 +1568,7 @@ int mount_main(int argc, char **argv)
1565 1568
1566 // Is this what we're looking for? 1569 // Is this what we're looking for?
1567 1570
1568 if(strcmp(argv[optind],mtcur->mnt_fsname) && 1571 if (strcmp(argv[optind],mtcur->mnt_fsname) &&
1569 strcmp(storage_path,mtcur->mnt_fsname) && 1572 strcmp(storage_path,mtcur->mnt_fsname) &&
1570 strcmp(argv[optind],mtcur->mnt_dir) && 1573 strcmp(argv[optind],mtcur->mnt_dir) &&
1571 strcmp(storage_path,mtcur->mnt_dir)) continue; 1574 strcmp(storage_path,mtcur->mnt_dir)) continue;