diff options
Diffstat (limited to 'e2fsprogs/ext2fs/ismounted.c')
-rw-r--r-- | e2fsprogs/ext2fs/ismounted.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/e2fsprogs/ext2fs/ismounted.c b/e2fsprogs/ext2fs/ismounted.c index 3f2241d23..2395ccaed 100644 --- a/e2fsprogs/ext2fs/ismounted.c +++ b/e2fsprogs/ext2fs/ismounted.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * ismounted.c --- Check to see if the filesystem was mounted | 2 | * ismounted.c --- Check to see if the filesystem was mounted |
3 | * | 3 | * |
4 | * Copyright (C) 1995,1996,1997,1998,1999,2000 Theodore Ts'o. | 4 | * Copyright (C) 1995,1996,1997,1998,1999,2000 Theodore Ts'o. |
5 | * | 5 | * |
6 | * %Begin-Header% | 6 | * %Begin-Header% |
@@ -38,17 +38,17 @@ | |||
38 | /* | 38 | /* |
39 | * Helper function which checks a file in /etc/mtab format to see if a | 39 | * Helper function which checks a file in /etc/mtab format to see if a |
40 | * filesystem is mounted. Returns an error if the file doesn't exist | 40 | * filesystem is mounted. Returns an error if the file doesn't exist |
41 | * or can't be opened. | 41 | * or can't be opened. |
42 | */ | 42 | */ |
43 | static errcode_t check_mntent_file(const char *mtab_file, const char *file, | 43 | static errcode_t check_mntent_file(const char *mtab_file, const char *file, |
44 | int *mount_flags, char *mtpt, int mtlen) | 44 | int *mount_flags, char *mtpt, int mtlen) |
45 | { | 45 | { |
46 | struct mntent *mnt; | 46 | struct mntent *mnt; |
47 | struct stat st_buf; | 47 | struct stat st_buf; |
48 | errcode_t retval = 0; | 48 | errcode_t retval = 0; |
49 | dev_t file_dev=0, file_rdev=0; | 49 | dev_t file_dev=0, file_rdev=0; |
50 | ino_t file_ino=0; | 50 | ino_t file_ino=0; |
51 | FILE *f; | 51 | FILE *f; |
52 | int fd; | 52 | int fd; |
53 | 53 | ||
54 | *mount_flags = 0; | 54 | *mount_flags = 0; |
@@ -103,7 +103,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, | |||
103 | } | 103 | } |
104 | #ifndef __GNU__ /* The GNU hurd is deficient; what else is new? */ | 104 | #ifndef __GNU__ /* The GNU hurd is deficient; what else is new? */ |
105 | /* Validate the entry in case /etc/mtab is out of date */ | 105 | /* Validate the entry in case /etc/mtab is out of date */ |
106 | /* | 106 | /* |
107 | * We need to be paranoid, because some broken distributions | 107 | * We need to be paranoid, because some broken distributions |
108 | * (read: Slackware) don't initialize /etc/mtab before checking | 108 | * (read: Slackware) don't initialize /etc/mtab before checking |
109 | * all of the non-root filesystems on the disk. | 109 | * all of the non-root filesystems on the disk. |
@@ -128,7 +128,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, | |||
128 | } | 128 | } |
129 | #endif /* __GNU__ */ | 129 | #endif /* __GNU__ */ |
130 | *mount_flags = EXT2_MF_MOUNTED; | 130 | *mount_flags = EXT2_MF_MOUNTED; |
131 | 131 | ||
132 | #ifdef MNTOPT_RO | 132 | #ifdef MNTOPT_RO |
133 | /* Check to see if the ro option is set */ | 133 | /* Check to see if the ro option is set */ |
134 | if (hasmntopt(mnt, MNTOPT_RO)) | 134 | if (hasmntopt(mnt, MNTOPT_RO)) |
@@ -145,7 +145,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, | |||
145 | */ | 145 | */ |
146 | if (!strcmp(mnt->mnt_dir, "/")) { | 146 | if (!strcmp(mnt->mnt_dir, "/")) { |
147 | is_root: | 147 | is_root: |
148 | #define TEST_FILE "/.ismount-test-file" | 148 | #define TEST_FILE "/.ismount-test-file" |
149 | *mount_flags |= EXT2_MF_ISROOT; | 149 | *mount_flags |= EXT2_MF_ISROOT; |
150 | fd = open(TEST_FILE, O_RDWR|O_CREAT); | 150 | fd = open(TEST_FILE, O_RDWR|O_CREAT); |
151 | if (fd < 0) { | 151 | if (fd < 0) { |
@@ -184,7 +184,7 @@ static errcode_t check_mntent(const char *file, int *mount_flags, | |||
184 | #endif /* MOUNTED */ | 184 | #endif /* MOUNTED */ |
185 | retval = check_mntent_file(MOUNTED, file, mount_flags, mtpt, mtlen); | 185 | retval = check_mntent_file(MOUNTED, file, mount_flags, mtpt, mtlen); |
186 | return retval; | 186 | return retval; |
187 | #else | 187 | #else |
188 | *mount_flags = 0; | 188 | *mount_flags = 0; |
189 | return 0; | 189 | return 0; |
190 | #endif /* defined(MOUNTED) || defined(_PATH_MOUNTED) */ | 190 | #endif /* defined(MOUNTED) || defined(_PATH_MOUNTED) */ |
@@ -197,31 +197,31 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags, | |||
197 | char *mtpt, int mtlen) | 197 | char *mtpt, int mtlen) |
198 | { | 198 | { |
199 | struct statfs *mp; | 199 | struct statfs *mp; |
200 | int len, n; | 200 | int len, n; |
201 | const char *s1; | 201 | const char *s1; |
202 | char *s2; | 202 | char *s2; |
203 | 203 | ||
204 | n = getmntinfo(&mp, MNT_NOWAIT); | 204 | n = getmntinfo(&mp, MNT_NOWAIT); |
205 | if (n == 0) | 205 | if (n == 0) |
206 | return errno; | 206 | return errno; |
207 | 207 | ||
208 | len = sizeof(_PATH_DEV) - 1; | 208 | len = sizeof(_PATH_DEV) - 1; |
209 | s1 = file; | 209 | s1 = file; |
210 | if (strncmp(_PATH_DEV, s1, len) == 0) | 210 | if (strncmp(_PATH_DEV, s1, len) == 0) |
211 | s1 += len; | 211 | s1 += len; |
212 | 212 | ||
213 | *mount_flags = 0; | 213 | *mount_flags = 0; |
214 | while (--n >= 0) { | 214 | while (--n >= 0) { |
215 | s2 = mp->f_mntfromname; | 215 | s2 = mp->f_mntfromname; |
216 | if (strncmp(_PATH_DEV, s2, len) == 0) { | 216 | if (strncmp(_PATH_DEV, s2, len) == 0) { |
217 | s2 += len - 1; | 217 | s2 += len - 1; |
218 | *s2 = 'r'; | 218 | *s2 = 'r'; |
219 | } | 219 | } |
220 | if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0) { | 220 | if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0) { |
221 | *mount_flags = EXT2_MF_MOUNTED; | 221 | *mount_flags = EXT2_MF_MOUNTED; |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | ++mp; | 224 | ++mp; |
225 | } | 225 | } |
226 | if (mtpt) | 226 | if (mtpt) |
227 | strncpy(mtpt, mp->f_mntonname, mtlen); | 227 | strncpy(mtpt, mp->f_mntonname, mtlen); |
@@ -270,7 +270,7 @@ static int is_swap_device(const char *file) | |||
270 | ret++; | 270 | ret++; |
271 | break; | 271 | break; |
272 | } | 272 | } |
273 | #endif /* __GNU__ */ | 273 | #endif /* __GNU__ */ |
274 | } | 274 | } |
275 | fclose(f); | 275 | fclose(f); |
276 | return ret; | 276 | return ret; |
@@ -296,7 +296,7 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, | |||
296 | } | 296 | } |
297 | #ifdef HAVE_MNTENT_H | 297 | #ifdef HAVE_MNTENT_H |
298 | return check_mntent(device, mount_flags, mtpt, mtlen); | 298 | return check_mntent(device, mount_flags, mtpt, mtlen); |
299 | #else | 299 | #else |
300 | #ifdef HAVE_GETMNTINFO | 300 | #ifdef HAVE_GETMNTINFO |
301 | return check_getmntinfo(device, mount_flags, mtpt, mtlen); | 301 | return check_getmntinfo(device, mount_flags, mtpt, mtlen); |
302 | #else | 302 | #else |
@@ -312,7 +312,7 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, | |||
312 | /* | 312 | /* |
313 | * ext2fs_check_if_mounted() sets the mount_flags EXT2_MF_MOUNTED, | 313 | * ext2fs_check_if_mounted() sets the mount_flags EXT2_MF_MOUNTED, |
314 | * EXT2_MF_READONLY, and EXT2_MF_ROOT | 314 | * EXT2_MF_READONLY, and EXT2_MF_ROOT |
315 | * | 315 | * |
316 | */ | 316 | */ |
317 | errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags) | 317 | errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags) |
318 | { | 318 | { |
@@ -324,7 +324,7 @@ int main(int argc, char **argv) | |||
324 | { | 324 | { |
325 | int retval, mount_flags; | 325 | int retval, mount_flags; |
326 | char mntpt[80]; | 326 | char mntpt[80]; |
327 | 327 | ||
328 | if (argc < 2) { | 328 | if (argc < 2) { |
329 | fprintf(stderr, "Usage: %s device\n", argv[0]); | 329 | fprintf(stderr, "Usage: %s device\n", argv[0]); |
330 | exit(1); | 330 | exit(1); |
@@ -347,12 +347,12 @@ int main(int argc, char **argv) | |||
347 | 347 | ||
348 | if (mount_flags & EXT2_MF_READONLY) | 348 | if (mount_flags & EXT2_MF_READONLY) |
349 | printf("\t%s is read-only.\n", argv[1]); | 349 | printf("\t%s is read-only.\n", argv[1]); |
350 | 350 | ||
351 | if (mount_flags & EXT2_MF_ISROOT) | 351 | if (mount_flags & EXT2_MF_ISROOT) |
352 | printf("\t%s is the root filesystem.\n", argv[1]); | 352 | printf("\t%s is the root filesystem.\n", argv[1]); |
353 | if (mntpt[0]) | 353 | if (mntpt[0]) |
354 | printf("\t%s is mounted on %s.\n", argv[1], mntpt); | 354 | printf("\t%s is mounted on %s.\n", argv[1], mntpt); |
355 | 355 | ||
356 | exit(0); | 356 | exit(0); |
357 | } | 357 | } |
358 | #endif /* DEBUG */ | 358 | #endif /* DEBUG */ |