Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/find_mount_point.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/find_mount_point.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 18 18 * filesystem. 19 19 */ 20 struct mntent *find_mount_point(const char *name, const char *table)20 struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) 21 21 { 22 22 struct stat s; 23 dev_t mountDevice; 24 FILE *mountTable; 23 FILE *mtab_fp; 25 24 struct mntent *mountEntry; 25 dev_t devno_of_name; 26 bool block_dev; 26 27 27 28 if (stat(name, &s) != 0) 28 return 0;29 return NULL; 29 30 30 if ((s.st_mode & S_IFMT) == S_IFBLK) 31 mountDevice = s.st_rdev; 32 else 33 mountDevice = s.st_dev; 31 devno_of_name = s.st_dev; 32 block_dev = 0; 33 if (S_ISBLK(s.st_mode)) { 34 devno_of_name = s.st_rdev; 35 block_dev = 1; 36 } 34 37 38 mtab_fp = setmntent(bb_path_mtab_file, "r"); 39 if (!mtab_fp) 40 return NULL; 35 41 36 mountTable = setmntent(table ? table : bb_path_mtab_file, "r"); 37 if (!mountTable) 38 return 0; 42 while ((mountEntry = getmntent(mtab_fp)) != NULL) { 43 /* rootfs mount in Linux 2.6 exists always, 44 * and it makes sense to always ignore it. 45 * Otherwise people can't reference their "real" root! */ 46 if (strcmp(mountEntry->mnt_fsname, "rootfs") == 0) 47 continue; 39 48 40 while ((mountEntry = getmntent(mountTable)) != 0) {41 49 if (strcmp(name, mountEntry->mnt_dir) == 0 42 50 || strcmp(name, mountEntry->mnt_fsname) == 0 … … 44 52 break; 45 53 } 46 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ 54 55 if (!(subdir_too || block_dev)) 56 continue; 57 58 /* Is device's dev_t == name's dev_t? */ 59 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == devno_of_name) 47 60 break; 48 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ 61 /* Match the directory's mount point. */ 62 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == devno_of_name) 49 63 break; 50 64 } 51 endmntent(mountTable); 65 endmntent(mtab_fp); 66 52 67 return mountEntry; 53 68 }
Note:
See TracChangeset
for help on using the changeset viewer.