Hi, On Thursday 12 August 2010 19:09:42 Jeff Squyres wrote: > On Aug 12, 2010, at 7:21 AM, Terry Dontje wrote: > > Is there not a way to determine whether the fs is tmpfs or not? > I don't know -- Rainer? Well, this is semi-portable ,-] But sure, it would work on Linux, where we'd want it:
./statfs /dev/shm --------------- statfs() output----------------- statfs() returned the following information about file system of path (/dev/shm): f_type : TMPFS (1021994) f_bsize : 4096 f_blocks : 723663 f_bfree : 723662 f_bavail : 723662 f_files : 723663 f_ffree : 723661 f_fsid : TMPFS (0x0) f_namelen : 255 (the program detects most Filesystems according to their known magic). Regards, Rainer -- ---------------------------------------------------------------- Dr.-Ing. Rainer Keller http://www.hlrs.de/people/keller HLRS Tel: ++49 (0)711-685 6 5858 Nobelstrasse 19 Fax: ++49 (0)711-685 6 5832 70550 Stuttgart email: kel...@hlrs.de Germany AIM/Skype:rusraink
/* * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. * * Author: Rainer Keller */ #define HAVE_LINUX_MAGIC_H #define HAVE_SYS_MOUNT_H #define HAVE_SYS_STATFS_H #define HAVE_SYS_STATVFS_H #define HAVE_SYS_TYPES_H #define HAVE_SYS_VFS_H #define HAVE_STRINGS_H #include <stdio.h> #include <inttypes.h> #ifdef HAVE_STRINGS_H #include <strings.h> #endif #ifdef HAVE_SYS_MOUNT_H #include <sys/mount.h> #endif #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_SYS_STATFS_H #include <sys/statfs.h> #endif #ifdef HAVE_SYS_STATVFS_H #include <sys/statvfs.h> #endif #ifdef HAVE_SYS_VFS_H #include <sys/vfs.h> #endif #ifdef HAVE_LINUX_MAGIC_H #include <linux/magic.h> #endif #ifndef ADFS_SUPER_MAGIC #define ADFS_SUPER_MAGIC 0xadf5 #endif #ifndef AFFS_SUPER_MAGIC #define AFFS_SUPER_MAGIC 0xadff #endif #ifndef AFS_SUPER_MAGIC #define AFS_SUPER_MAGIC 0x5346414F #endif #ifndef AUTOFS_SUPER_MAGIC #define AUTOFS_SUPER_MAGIC 0x0187 #endif #ifndef BEFS_SUPER_MAGIC #define BEFS_SUPER_MAGIC 0x42465331 #endif #ifndef BFS_MAGIC #define BFS_MAGIC 0x1BADFACE #endif #ifndef BINFMT_MISC_SUPER_MAGIC #define BINFMT_MISC_SUPER_MAGIC 0x42494e4d #endif #ifndef CGROUP_SUPER_MAGIC #define CGROUP_SUPER_MAGIC 0x27e0eb #endif #ifndef CIFS_MAGIC_NUMBER #define CIFS_MAGIC_NUMBER 0xFF534D42 #endif #ifndef CODA_SUPER_MAGIC #define CODA_SUPER_MAGIC 0x73757245 #endif #ifndef COH_SUPER_MAGIC #define COH_SUPER_MAGIC 0x012FF7B7 #endif #ifndef CRAMFS_MAGIC #define CRAMFS_MAGIC 0x28cd3d45 #endif #ifndef DEBUGFS_MAGIC #define DEBUGFS_MAGIC 0x64626720 #endif #ifndef DEVFS_SUPER_MAGIC #define DEVFS_SUPER_MAGIC 0x1373 #endif #ifndef DEVPTS_SUPER_MAGIC #define DEVPTS_SUPER_MAGIC 0x1cd1 #endif #ifndef ECRYPTFS_SUPER_MAGIC #define ECRYPTFS_SUPER_MAGIC 0xf15f #endif #ifndef EFS_SUPER_MAGIC #define EFS_SUPER_MAGIC 0x414A53 #endif #ifndef EXOFS_SUPER_MAGIC #define EXOFS_SUPER_MAGIC 0x5DF5 #endif #ifndef EXT_SUPER_MAGIC #define EXT_SUPER_MAGIC 0x137D #endif #ifndef EXT2_OLD_SUPER_MAGIC #define EXT2_OLD_SUPER_MAGIC 0xEF51 #endif #ifndef EXT2_SUPER_MAGIC #define EXT2_SUPER_MAGIC 0xEF53 #endif #ifndef EXT3_SUPER_MAGIC #define EXT3_SUPER_MAGIC 0xEF53 #endif #ifndef EXT4_SUPER_MAGIC #define EXT4_SUPER_MAGIC 0xEF53 #endif #ifndef FUSE_CTL_SUPER_MAGIC #define FUSE_CTL_SUPER_MAGIC 0x65735543 #endif #ifndef FUSE_SUPER_MAGIC #define FUSE_SUPER_MAGIC 0x65735546 #endif #ifndef FUTEXFS_SUPER_MAGIC #define FUTEXFS_SUPER_MAGIC 0xBAD1DEA #endif #ifndef GFS2_MAGIC #define GFS2_MAGIC 0x01161970 #endif #ifndef GPFS_SUPER_MAGIC #define GPFS_SUPER_MAGIC 0x47504653 #endif #ifndef HFS_SUPER_MAGIC #define HFS_SUPER_MAGIC 0x4244 #endif #ifndef HFSPLUS_SUPER_MAGIC #define HFSPLUS_SUPER_MAGIC 0x482b #endif #ifndef HOSTFS_SUPER_MAGIC #define HOSTFS_SUPER_MAGIC 0x00c0ffee #endif #ifndef HPFS_SUPER_MAGIC #define HPFS_SUPER_MAGIC 0xf995e849 #endif #ifndef HPPFS_SUPER_MAGIC #define HPPFS_SUPER_MAGIC 0xb00000ee #endif #ifndef HUGETLBFS_MAGIC #define HUGETLBFS_MAGIC 0x958458f6 #endif #ifndef INOTIFYFS_SUPER_MAGIC #define INOTIFYFS_SUPER_MAGIC 0x2BAD1DEA #endif #ifndef ISOFS_SUPER_MAGIC #define ISOFS_SUPER_MAGIC 0x9660 #endif #ifndef JFFS2_SUPER_MAGIC #define JFFS2_SUPER_MAGIC 0x72b6 #endif #ifndef JFS_SUPER_MAGIC #define JFS_SUPER_MAGIC 0x3153464a #endif #ifndef LL_SUPER_MAGIC #define LL_SUPER_MAGIC 0x0BD00BD0 #endif #ifndef MINIX_SUPER_MAGIC #define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ #endif #ifndef MINIX_SUPER_MAGIC2 #define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ #endif #ifndef MINIX2_SUPER_MAGIC #define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */ #endif #ifndef MINIX2_SUPER_MAGIC2 #define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */ #endif #ifndef MINIX3_SUPER_MAGIC #define MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 fs */ #endif #ifndef MSDOS_SUPER_MAGIC #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */ #endif #ifndef NCP_SUPER_MAGIC #define NCP_SUPER_MAGIC 0x564c /* Guess, what 0x564c is :-) */ #endif #ifndef NFS_SUPER_MAGIC #define NFS_SUPER_MAGIC 0x6969 /* Network File System by Sun */ #endif #ifndef NTFS_SB_MAGIC #define NTFS_SB_MAGIC 0x5346544e #endif #ifndef OCFS2_SUPER_MAGIC #define OCFS2_SUPER_MAGIC 0x7461636f #endif #ifndef OPENPROM_SUPER_MAGIC #define OPENPROM_SUPER_MAGIC 0x9fa1 #endif #ifndef PAN_KERNEL_FS_CLIENT_SUPER_MAGIC #define PAN_KERNEL_FS_CLIENT_SUPER_MAGIC 0xAAD7AAEA /* Panasas FS */ #endif #ifndef PROC_SUPER_MAGIC #define PROC_SUPER_MAGIC 0x9fa0 /* Proc virtual file system */ #endif #ifndef PVFS2_SUPER_MAGIC #define PVFS2_SUPER_MAGIC 0x20030528 /* Parallel Virtual File System 2 -- note PVFS(1) was a library and therefore in userspace) */ #endif #ifndef QNX4_SUPER_MAGIC #define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */ #endif #ifndef REISERFS_SUPER_MAGIC #define REISERFS_SUPER_MAGIC 0x52654973 /* used by gcc */ #endif #ifndef ROMFS_MAGIC #define ROMFS_MAGIC 0x7275 #endif #ifndef SECURITYFS_MAGIC #define SECURITYFS_MAGIC 0x73636673 #endif #ifndef SELINUX_MAGIC #define SELINUX_MAGIC 0xf97cff8c #endif #ifndef SMB_SUPER_MAGIC #define SMB_SUPER_MAGIC 0x517B #endif #ifndef SQUASHFS_MAGIC #define SQUASHFS_MAGIC 0x73717368 #endif #ifndef SYSFS_MAGIC #define SYSFS_MAGIC 0x62656572 #endif #ifndef SYSV2_SUPER_MAGIC #define SYSV2_SUPER_MAGIC 0x012FF7B6 #endif #ifndef SYSV4_SUPER_MAGIC #define SYSV4_SUPER_MAGIC 0x012FF7B5 #endif #ifndef TMPFS_MAGIC #define TMPFS_MAGIC 0x01021994 #endif #ifndef UBIFS_SUPER_MAGIC #define UBIFS_SUPER_MAGIC 0x24051905 #endif #ifndef UDF_SUPER_MAGIC #define UDF_SUPER_MAGIC 0x15013346 #endif #ifndef UFS_MAGIC #define UFS_MAGIC 0x00011954 #endif #ifndef UFS2_MAGIC #define UFS2_MAGIC 0x19540119 #endif #ifndef USBDEVICE_SUPER_MAGIC #define USBDEVICE_SUPER_MAGIC 0x9fa2 #endif #ifndef VXFS_SUPER_MAGIC #define VXFS_SUPER_MAGIC 0xa501FCF5 #endif #ifndef XENIX_SUPER_MAGIC #define XENIX_SUPER_MAGIC 0x012FF7B4 #endif #ifndef XFS_SUPER_MAGIC #define XFS_SUPER_MAGIC 0x58465342 #endif #ifndef _XIAFS_SUPER_MAGIC #define _XIAFS_SUPER_MAGIC 0x012FD16D #endif #define MASK1 0xff #define MASK2 0xffff #define MASK3 0xffffff #define MASK4 0xffffffff #define F_FLAGS_VIRTUAL 0x1 #define F_FLAGS_PHYSICAL 0x2 #define F_FLAGS_PARALLEL 0x4 #define F_FLAGS_JOURNALING_POSSIBLE 0x8 #define F_FLAGS_JOURNALING_ALWAYS 0x10 #define F_FLAGS_JOURNALING_ALWAYS 0x10 struct fs_type_names_t { unsigned long long f_fsid; unsigned long long f_mask; // unsigned long long f_flags; char * f_fsname; } fs_type_names[] = { {ADFS_SUPER_MAGIC, MASK2, "ADFS"}, {AFFS_SUPER_MAGIC, MASK2, "AFFS"}, {AFS_SUPER_MAGIC, MASK4, "AFS"}, {AUTOFS_SUPER_MAGIC, MASK2, "AUTOFS"}, {BEFS_SUPER_MAGIC, MASK4, "BEFS"}, {BFS_MAGIC, MASK4, "BFS"}, {BINFMT_MISC_SUPER_MAGIC, MASK4, "BINFMT_MISC"}, {CGROUP_SUPER_MAGIC, MASK3, "CGROUP"}, {CIFS_MAGIC_NUMBER, MASK4, "CIFS"}, {CODA_SUPER_MAGIC, MASK4, "CODA"}, {COH_SUPER_MAGIC, MASK4, "COH"}, {CRAMFS_MAGIC, MASK4, "CRAMFS"}, {DEBUGFS_MAGIC, MASK4, "DEBUGFS"}, {DEVFS_SUPER_MAGIC, MASK2, "DEVFS"}, {DEVPTS_SUPER_MAGIC, MASK2, "DEVPTS"}, {ECRYPTFS_SUPER_MAGIC, MASK4, "ECRYPTFS"}, {EFS_SUPER_MAGIC, MASK3, "EFS"}, {EXOFS_SUPER_MAGIC, MASK2, "EXOFS"}, {EXT_SUPER_MAGIC, MASK2, "EXT"}, {EXT2_OLD_SUPER_MAGIC, MASK2, "EXT2 (old)"}, {EXT2_SUPER_MAGIC, MASK2, "EXT2/EXT3/EXT4"}, /* Attributes distinguish EXT2-EXT4 */ {EXT3_SUPER_MAGIC, MASK2, "EXT3/EXT4"}, /* Attributes distinguish EXT2-EXT4 */ {EXT4_SUPER_MAGIC, MASK2, "EXT4"}, /* Attributes distinguish EXT2-EXT4 */ {FUSE_CTL_SUPER_MAGIC, MASK4, "FUSE (ctl)"}, {FUSE_SUPER_MAGIC, MASK4, "FUSE"}, {FUTEXFS_SUPER_MAGIC, MASK4, "FUTEXFS"}, {GFS2_MAGIC, MASK4, "GFS2"}, {GPFS_SUPER_MAGIC, MASK4, "GPFS"}, {HFS_SUPER_MAGIC, MASK2, "HFS"}, {HFSPLUS_SUPER_MAGIC, MASK2, "HFSPLUS"}, {HOSTFS_SUPER_MAGIC, MASK4, "HOSTFS"}, {HPFS_SUPER_MAGIC, MASK4, "HPFS"}, {HPPFS_SUPER_MAGIC, MASK4, "HPPFS"}, {HUGETLBFS_MAGIC, MASK4, "HUGETLBFS"}, {INOTIFYFS_SUPER_MAGIC, MASK4, "INOTIFY"}, {ISOFS_SUPER_MAGIC, MASK2, "ISOFS"}, {JFFS2_SUPER_MAGIC, MASK2, "JFFS2"}, {JFS_SUPER_MAGIC, MASK4, "JFS"}, {LL_SUPER_MAGIC, MASK4, "LUSTRE"}, {MINIX_SUPER_MAGIC, MASK2, "MINIX"}, {MINIX_SUPER_MAGIC2, MASK2, "MINIX (alternative)"}, {MINIX2_SUPER_MAGIC, MASK2, "MINIX2"}, {MINIX2_SUPER_MAGIC2, MASK2, "MINIX2 (alternative)"}, {MINIX3_SUPER_MAGIC, MASK2, "MINIX3"}, {MSDOS_SUPER_MAGIC, MASK2, "MSDOS"}, {NCP_SUPER_MAGIC, MASK2, "NCP"}, {NFS_SUPER_MAGIC, MASK2, "NFS"}, {NTFS_SB_MAGIC, MASK4, "NTFS"}, {OCFS2_SUPER_MAGIC, MASK4, "OCFS2"}, {OPENPROM_SUPER_MAGIC, MASK2, "OPENPROM"}, {PAN_KERNEL_FS_CLIENT_SUPER_MAGIC, MASK4, "PANFS"}, {PROC_SUPER_MAGIC, MASK2, "PROC"}, {PVFS2_SUPER_MAGIC, MASK4, "PVFS2"}, {QNX4_SUPER_MAGIC, MASK2, "QNX4"}, {REISERFS_SUPER_MAGIC, MASK4, "REISERFS"}, {ROMFS_MAGIC, MASK2, "ROMFS"}, {SECURITYFS_MAGIC, MASK4, "SECURITYFS"}, {SELINUX_MAGIC, MASK4, "SELINUX"}, {SMB_SUPER_MAGIC, MASK2, "SMB"}, {SQUASHFS_MAGIC, MASK4, "SQUASHFS"}, {SYSFS_MAGIC, MASK4, "SYSFS"}, {SYSV2_SUPER_MAGIC, MASK4, "SYSV2"}, {SYSV4_SUPER_MAGIC, MASK4, "SYSV4"}, {TMPFS_MAGIC, MASK4, "TMPFS"}, {UBIFS_SUPER_MAGIC, MASK4, "UBIFS"}, {UDF_SUPER_MAGIC, MASK4, "UDF"}, {UFS_MAGIC, MASK4, "UFS"}, {UFS2_MAGIC, MASK4, "UFS2"}, {USBDEVICE_SUPER_MAGIC, MASK2, "USBDEVICE"}, {VXFS_SUPER_MAGIC, MASK4, "VXFS"}, {XENIX_SUPER_MAGIC, MASK4, "XENIX"}, {XFS_SUPER_MAGIC, MASK4, "XFS"}, {_XIAFS_SUPER_MAGIC, MASK4, "_XIAFS"} }; int main(int argc, char * argv[]) { char * path = "/"; struct statfs statfs_buf; if (argc > 1) { path = argv[1]; } printf ("--------------- statfs() output-----------------\n"); #if 0 /* On Linux */ struct statfs { long f_type; /* type of file system (see below) */ long f_bsize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in file system */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ long f_namelen; /* maximum length of filenames */ }; /* On MacOSX: */ #define MFSTYPENAMELEN 16 /* length of fs type name including null */ #define MAXPATHLEN 1024 #define MNAMELEN MAXPATHLEN struct statfs { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */ uint32_t f_bsize; /* fundamental file system block size */ int32_t f_iosize; /* optimal transfer block size */ uint64_t f_blocks; /* total data blocks in file system */ uint64_t f_bfree; /* free blocks in fs */ uint64_t f_bavail; /* free blocks avail to non-superuser */ uint64_t f_files; /* total file nodes in file system */ uint64_t f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ uid_t f_owner; /* user that mounted the filesystem */ uint32_t f_type; /* type of filesystem */ uint32_t f_flags; /* copy of mount exported flags */ uint32_t f_fssubtype; /* fs sub-type (flavor) */ char f_fstypename[MFSTYPENAMELEN]; /* fs type name */ char f_mntonname[MAXPATHLEN]; /* directory on which mounted */ char f_mntfromname[MAXPATHLEN]; /* mounted filesystem */ uint32_t f_reserved[8]; /* For future use */ }; #endif if (-1 == statfs (path, &statfs_buf)) { perror("statfs() error"); } else { int i; char *fs_name = "Unknown"; for (i=0; i < sizeof (fs_type_names) / sizeof (fs_type_names[0]); i++) { if (fs_type_names[i].f_fsid == (statfs_buf.f_type & fs_type_names[i].f_mask)) { fs_name = fs_type_names[i].f_fsname; break; } } printf ("statfs() returned the following information\n"); printf ("about file system of path (%s):\n", path); printf(" f_type : %s (%lx)\n", fs_name, statfs_buf.f_type); printf(" f_bsize : %ld\n", statfs_buf.f_frsize); printf(" f_blocks : %ld\n", statfs_buf.f_blocks); printf(" f_bfree : %ld\n", statfs_buf.f_bfree); printf(" f_bavail : %ld\n", statfs_buf.f_bavail); printf(" f_files : %ld\n", statfs_buf.f_files); printf(" f_ffree : %ld\n", statfs_buf.f_ffree); #if !defined(__APPLE__) printf(" f_namelen : %ld\n", statfs_buf.f_namelen); #endif } return 0; }