subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Michal Simek <monstr@monstr.eu>, 2009-08-03 - ramfs |
| 3 | * Kumar Gala <galak@kernel.crashing.org>, 2007-11-14 - nfs |
| 4 | * Ricky Ng-Adam <rngadam@yahoo.com>, 2005-01-01 - tmpfs |
| 5 | * |
| 6 | * DESCRIPTION |
| 7 | * Check if current directory is on a tmpfs/nfs/ramfs filesystem |
| 8 | * If current directory is tmpfs/nfs/ramfs, return 1 |
| 9 | * If current directory is NOT tmpfs/nfs/ramfs, return 0 |
| 10 | */ |
| 11 | |
| 12 | #include <sys/vfs.h> |
| 13 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 14 | #define TMPFS_MAGIC 0x01021994 /* man 2 statfs */ |
subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 15 | int tst_is_cwd_tmpfs(void) |
| 16 | { |
| 17 | struct statfs sf; |
| 18 | statfs(".", &sf); |
| 19 | |
| 20 | /* Verify that the file is not on a tmpfs (in-memory) filesystem */ |
Cyril Hrubis | ce10184 | 2011-02-24 20:07:33 +0100 | [diff] [blame] | 21 | return (sf.f_type == TMPFS_MAGIC); |
subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 24 | #define NFS_MAGIC 0x6969 /* man 2 statfs */ |
subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 25 | int tst_is_cwd_nfs(void) |
| 26 | { |
| 27 | struct statfs sf; |
| 28 | statfs(".", &sf); |
| 29 | |
| 30 | /* Verify that the file is not on a nfs filesystem */ |
Cyril Hrubis | ce10184 | 2011-02-24 20:07:33 +0100 | [diff] [blame] | 31 | return (sf.f_type == NFS_MAGIC); |
subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 34 | #define V9FS_MAGIC 0x01021997 /* kernel-source/include/linux/magic.h */ |
Cyril Hrubis | bc5da68 | 2011-02-24 20:04:44 +0100 | [diff] [blame] | 35 | int tst_is_cwd_v9fs(void) |
| 36 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 37 | struct statfs sf; |
| 38 | statfs(".", &sf); |
Cyril Hrubis | bc5da68 | 2011-02-24 20:04:44 +0100 | [diff] [blame] | 39 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 40 | /* Verify that the file is not on a nfs filesystem */ |
| 41 | return (sf.f_type == V9FS_MAGIC); |
Cyril Hrubis | bc5da68 | 2011-02-24 20:04:44 +0100 | [diff] [blame] | 42 | } |
| 43 | |
subrata_modak | 431c9dd | 2009-08-04 11:30:16 +0000 | [diff] [blame] | 44 | #define RAMFS_MAGIC 0x858458f6 |
| 45 | int tst_is_cwd_ramfs(void) |
| 46 | { |
| 47 | struct statfs sf; |
| 48 | statfs(".", &sf); |
| 49 | |
| 50 | /* Verify that the file is not on a ramfs (in-memory) filesystem */ |
Cyril Hrubis | ce10184 | 2011-02-24 20:07:33 +0100 | [diff] [blame] | 51 | return (sf.f_type == RAMFS_MAGIC); |
| 52 | } |