Annotation of /trunk/mkinitrd-magellan/busybox/libbb/find_mount_point.c
Parent Directory | Revision Log
Revision 984 -
(hide annotations)
(download)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 1605 byte(s)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 1605 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | #include <mntent.h> | ||
12 | |||
13 | /* | ||
14 | * Given a block device, find the mount table entry if that block device | ||
15 | * is mounted. | ||
16 | * | ||
17 | * Given any other file (or directory), find the mount table entry for its | ||
18 | * filesystem. | ||
19 | */ | ||
20 | niro | 984 | struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) |
21 | niro | 532 | { |
22 | struct stat s; | ||
23 | niro | 984 | FILE *mtab_fp; |
24 | niro | 532 | struct mntent *mountEntry; |
25 | niro | 984 | dev_t devno_of_name; |
26 | bool block_dev; | ||
27 | niro | 532 | |
28 | if (stat(name, &s) != 0) | ||
29 | niro | 984 | return NULL; |
30 | niro | 532 | |
31 | niro | 984 | 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 | } | ||
37 | niro | 532 | |
38 | niro | 984 | mtab_fp = setmntent(bb_path_mtab_file, "r"); |
39 | if (!mtab_fp) | ||
40 | return NULL; | ||
41 | niro | 532 | |
42 | niro | 984 | 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; | ||
48 | niro | 532 | |
49 | if (strcmp(name, mountEntry->mnt_dir) == 0 | ||
50 | || strcmp(name, mountEntry->mnt_fsname) == 0 | ||
51 | ) { /* String match. */ | ||
52 | break; | ||
53 | } | ||
54 | niro | 984 | |
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) | ||
60 | niro | 532 | break; |
61 | niro | 984 | /* Match the directory's mount point. */ |
62 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == devno_of_name) | ||
63 | niro | 532 | break; |
64 | } | ||
65 | niro | 984 | endmntent(mtab_fp); |
66 | |||
67 | niro | 532 | return mountEntry; |
68 | } |