aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-04-17 04:32:50 +0000
committerMatt Kraai <kraai@debian.org>2001-04-17 04:32:50 +0000
commit1240082e37d5e89c618de0d28d8466e611c41f4a (patch)
treed5e2fa5b3336c4f98f10984fa2ea2fe5428e07f3
parent24ed3bee0c4ca631855a0f43f75e30ba0c134b9f (diff)
downloadbusybox-w32-1240082e37d5e89c618de0d28d8466e611c41f4a.tar.gz
busybox-w32-1240082e37d5e89c618de0d28d8466e611c41f4a.tar.bz2
busybox-w32-1240082e37d5e89c618de0d28d8466e611c41f4a.zip
Further cleanup of mount option handling.
-rw-r--r--mount.c123
-rw-r--r--util-linux/mount.c123
2 files changed, 122 insertions, 124 deletions
diff --git a/mount.c b/mount.c
index 311d518aa..6a4c8eb2f 100644
--- a/mount.c
+++ b/mount.c
@@ -273,6 +273,64 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
273 return (TRUE); 273 return (TRUE);
274} 274}
275 275
276void show_mounts()
277{
278#if defined BB_FEATURE_USE_DEVPS_PATCH
279 int fd, i, numfilesystems;
280 char device[] = "/dev/mtab";
281 struct k_mntent *mntentlist;
282
283 /* open device */
284 fd = open(device, O_RDONLY);
285 if (fd < 0)
286 perror_msg_and_die("open failed for `%s'", device);
287
288 /* How many mounted filesystems? We need to know to
289 * allocate enough space for later... */
290 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
291 if (numfilesystems<0)
292 perror_msg_and_die( "\nDEVMTAB_COUNT_MOUNTS");
293 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
294
295 /* Grab the list of mounted filesystems */
296 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
297 perror_msg_and_die( "\nDEVMTAB_GET_MOUNTS");
298
299 for( i = 0 ; i < numfilesystems ; i++) {
300 printf( "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
301 mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
302 mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
303 mntentlist[i].mnt_passno);
304 }
305#ifdef BB_FEATURE_CLEAN_UP
306 /* Don't bother to close files or free memory. Exit
307 * does that automagically, so we can save a few bytes */
308 free( mntentlist);
309 close(fd);
310#endif
311 exit(EXIT_SUCCESS);
312#else
313 FILE *mountTable = setmntent(mtab_file, "r");
314
315 if (mountTable) {
316 struct mntent *m;
317
318 while ((m = getmntent(mountTable)) != 0) {
319 char *blockDevice = m->mnt_fsname;
320 if (strcmp(blockDevice, "/dev/root") == 0) {
321 find_real_root_device_name( blockDevice);
322 }
323 printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
324 m->mnt_type, m->mnt_opts);
325 }
326 endmntent(mountTable);
327 } else {
328 perror_msg_and_die("%s", mtab_file);
329 }
330 exit(EXIT_SUCCESS);
331#endif
332}
333
276extern int mount_main(int argc, char **argv) 334extern int mount_main(int argc, char **argv)
277{ 335{
278 char string_flags_buf[1024] = ""; 336 char string_flags_buf[1024] = "";
@@ -289,65 +347,6 @@ extern int mount_main(int argc, char **argv)
289 int rc = EXIT_FAILURE; 347 int rc = EXIT_FAILURE;
290 int fstabmount = FALSE; 348 int fstabmount = FALSE;
291 349
292#if defined BB_FEATURE_USE_DEVPS_PATCH
293 if (argc == 1) {
294 int fd, i, numfilesystems;
295 char device[] = "/dev/mtab";
296 struct k_mntent *mntentlist;
297
298 /* open device */
299 fd = open(device, O_RDONLY);
300 if (fd < 0)
301 perror_msg_and_die("open failed for `%s'", device);
302
303 /* How many mounted filesystems? We need to know to
304 * allocate enough space for later... */
305 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
306 if (numfilesystems<0)
307 perror_msg_and_die( "\nDEVMTAB_COUNT_MOUNTS");
308 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
309
310 /* Grab the list of mounted filesystems */
311 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
312 perror_msg_and_die( "\nDEVMTAB_GET_MOUNTS");
313
314 for( i = 0 ; i < numfilesystems ; i++) {
315 printf( "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
316 mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
317 mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
318 mntentlist[i].mnt_passno);
319 }
320#ifdef BB_FEATURE_CLEAN_UP
321 /* Don't bother to close files or free memory. Exit
322 * does that automagically, so we can save a few bytes */
323 free( mntentlist);
324 close(fd);
325#endif
326 return EXIT_SUCCESS;
327 }
328#else
329 if (argc == 1) {
330 FILE *mountTable = setmntent(mtab_file, "r");
331
332 if (mountTable) {
333 struct mntent *m;
334
335 while ((m = getmntent(mountTable)) != 0) {
336 char *blockDevice = m->mnt_fsname;
337 if (strcmp(blockDevice, "/dev/root") == 0) {
338 find_real_root_device_name( blockDevice);
339 }
340 printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
341 m->mnt_type, m->mnt_opts);
342 }
343 endmntent(mountTable);
344 } else {
345 perror_msg_and_die("%s", mtab_file);
346 }
347 return EXIT_SUCCESS;
348 }
349#endif
350
351 /* Parse options */ 350 /* Parse options */
352 i = --argc; 351 i = --argc;
353 argv++; 352 argv++;
@@ -405,14 +404,14 @@ extern int mount_main(int argc, char **argv)
405 argv++; 404 argv++;
406 } 405 }
407 406
407 if (device == NULL && !all)
408 show_mounts();
409
408 if (all == TRUE || directory == NULL) { 410 if (all == TRUE || directory == NULL) {
409 struct mntent *m; 411 struct mntent *m;
410 FILE *f = setmntent("/etc/fstab", "r"); 412 FILE *f = setmntent("/etc/fstab", "r");
411 fstabmount = TRUE; 413 fstabmount = TRUE;
412 414
413 if (all == FALSE && device == NULL)
414 goto goodbye;
415
416 if (f == NULL) 415 if (f == NULL)
417 perror_msg_and_die( "\nCannot read /etc/fstab"); 416 perror_msg_and_die( "\nCannot read /etc/fstab");
418 417
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 311d518aa..6a4c8eb2f 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -273,6 +273,64 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
273 return (TRUE); 273 return (TRUE);
274} 274}
275 275
276void show_mounts()
277{
278#if defined BB_FEATURE_USE_DEVPS_PATCH
279 int fd, i, numfilesystems;
280 char device[] = "/dev/mtab";
281 struct k_mntent *mntentlist;
282
283 /* open device */
284 fd = open(device, O_RDONLY);
285 if (fd < 0)
286 perror_msg_and_die("open failed for `%s'", device);
287
288 /* How many mounted filesystems? We need to know to
289 * allocate enough space for later... */
290 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
291 if (numfilesystems<0)
292 perror_msg_and_die( "\nDEVMTAB_COUNT_MOUNTS");
293 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
294
295 /* Grab the list of mounted filesystems */
296 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
297 perror_msg_and_die( "\nDEVMTAB_GET_MOUNTS");
298
299 for( i = 0 ; i < numfilesystems ; i++) {
300 printf( "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
301 mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
302 mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
303 mntentlist[i].mnt_passno);
304 }
305#ifdef BB_FEATURE_CLEAN_UP
306 /* Don't bother to close files or free memory. Exit
307 * does that automagically, so we can save a few bytes */
308 free( mntentlist);
309 close(fd);
310#endif
311 exit(EXIT_SUCCESS);
312#else
313 FILE *mountTable = setmntent(mtab_file, "r");
314
315 if (mountTable) {
316 struct mntent *m;
317
318 while ((m = getmntent(mountTable)) != 0) {
319 char *blockDevice = m->mnt_fsname;
320 if (strcmp(blockDevice, "/dev/root") == 0) {
321 find_real_root_device_name( blockDevice);
322 }
323 printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
324 m->mnt_type, m->mnt_opts);
325 }
326 endmntent(mountTable);
327 } else {
328 perror_msg_and_die("%s", mtab_file);
329 }
330 exit(EXIT_SUCCESS);
331#endif
332}
333
276extern int mount_main(int argc, char **argv) 334extern int mount_main(int argc, char **argv)
277{ 335{
278 char string_flags_buf[1024] = ""; 336 char string_flags_buf[1024] = "";
@@ -289,65 +347,6 @@ extern int mount_main(int argc, char **argv)
289 int rc = EXIT_FAILURE; 347 int rc = EXIT_FAILURE;
290 int fstabmount = FALSE; 348 int fstabmount = FALSE;
291 349
292#if defined BB_FEATURE_USE_DEVPS_PATCH
293 if (argc == 1) {
294 int fd, i, numfilesystems;
295 char device[] = "/dev/mtab";
296 struct k_mntent *mntentlist;
297
298 /* open device */
299 fd = open(device, O_RDONLY);
300 if (fd < 0)
301 perror_msg_and_die("open failed for `%s'", device);
302
303 /* How many mounted filesystems? We need to know to
304 * allocate enough space for later... */
305 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
306 if (numfilesystems<0)
307 perror_msg_and_die( "\nDEVMTAB_COUNT_MOUNTS");
308 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
309
310 /* Grab the list of mounted filesystems */
311 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
312 perror_msg_and_die( "\nDEVMTAB_GET_MOUNTS");
313
314 for( i = 0 ; i < numfilesystems ; i++) {
315 printf( "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
316 mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
317 mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
318 mntentlist[i].mnt_passno);
319 }
320#ifdef BB_FEATURE_CLEAN_UP
321 /* Don't bother to close files or free memory. Exit
322 * does that automagically, so we can save a few bytes */
323 free( mntentlist);
324 close(fd);
325#endif
326 return EXIT_SUCCESS;
327 }
328#else
329 if (argc == 1) {
330 FILE *mountTable = setmntent(mtab_file, "r");
331
332 if (mountTable) {
333 struct mntent *m;
334
335 while ((m = getmntent(mountTable)) != 0) {
336 char *blockDevice = m->mnt_fsname;
337 if (strcmp(blockDevice, "/dev/root") == 0) {
338 find_real_root_device_name( blockDevice);
339 }
340 printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
341 m->mnt_type, m->mnt_opts);
342 }
343 endmntent(mountTable);
344 } else {
345 perror_msg_and_die("%s", mtab_file);
346 }
347 return EXIT_SUCCESS;
348 }
349#endif
350
351 /* Parse options */ 350 /* Parse options */
352 i = --argc; 351 i = --argc;
353 argv++; 352 argv++;
@@ -405,14 +404,14 @@ extern int mount_main(int argc, char **argv)
405 argv++; 404 argv++;
406 } 405 }
407 406
407 if (device == NULL && !all)
408 show_mounts();
409
408 if (all == TRUE || directory == NULL) { 410 if (all == TRUE || directory == NULL) {
409 struct mntent *m; 411 struct mntent *m;
410 FILE *f = setmntent("/etc/fstab", "r"); 412 FILE *f = setmntent("/etc/fstab", "r");
411 fstabmount = TRUE; 413 fstabmount = TRUE;
412 414
413 if (all == FALSE && device == NULL)
414 goto goodbye;
415
416 if (f == NULL) 415 if (f == NULL)
417 perror_msg_and_die( "\nCannot read /etc/fstab"); 416 perror_msg_and_die( "\nCannot read /etc/fstab");
418 417