github.com/crowdsecurity/crowdsec@v1.6.1/pkg/types/getfstype.go (about) 1 //go:build !windows 2 3 package types 4 5 import ( 6 "fmt" 7 "golang.org/x/sys/unix" 8 ) 9 10 // Generated with `man statfs | grep _MAGIC | awk '{split(tolower($1),a,"_"); print $2 ": \"" a[1] "\","}'` 11 // ext2/3/4 duplicates removed to just have ext4 12 // XIAFS removed as well 13 var fsTypeMapping map[int64]string = map[int64]string{ 14 0xadf5: "adfs", 15 0xadff: "affs", 16 0x5346414f: "afs", 17 0x09041934: "anon", 18 0x0187: "autofs", 19 0x62646576: "bdevfs", 20 0x42465331: "befs", 21 0x1badface: "bfs", 22 0x42494e4d: "binfmtfs", 23 0xcafe4a11: "bpf", 24 0x9123683e: "btrfs", 25 0x73727279: "btrfs", 26 0x27e0eb: "cgroup", 27 0x63677270: "cgroup2", 28 0xff534d42: "cifs", 29 0x73757245: "coda", 30 0x012ff7b7: "coh", 31 0x28cd3d45: "cramfs", 32 0x64626720: "debugfs", 33 0x1373: "devfs", 34 0x1cd1: "devpts", 35 0xf15f: "ecryptfs", 36 0xde5e81e4: "efivarfs", 37 0x00414a53: "efs", 38 0x137d: "ext", 39 0xef51: "ext2", 40 0xef53: "ext4", 41 0xf2f52010: "f2fs", 42 0x65735546: "fuse", 43 0xbad1dea: "futexfs", 44 0x4244: "hfs", 45 0x00c0ffee: "hostfs", 46 0xf995e849: "hpfs", 47 0x958458f6: "hugetlbfs", 48 0x9660: "isofs", 49 0x72b6: "jffs2", 50 0x3153464a: "jfs", 51 0x137f: "minix", 52 0x138f: "minix", 53 0x2468: "minix2", 54 0x2478: "minix2", 55 0x4d5a: "minix3", 56 0x19800202: "mqueue", 57 0x4d44: "msdos", 58 0x11307854: "mtd", 59 0x564c: "ncp", 60 0x6969: "nfs", 61 0x3434: "nilfs", 62 0x6e736673: "nsfs", 63 0x5346544e: "ntfs", 64 0x7461636f: "ocfs2", 65 0x9fa1: "openprom", 66 0x794c7630: "overlayfs", 67 0x50495045: "pipefs", 68 0x9fa0: "proc", 69 0x6165676c: "pstorefs", 70 0x002f: "qnx4", 71 0x68191122: "qnx6", 72 0x858458f6: "ramfs", 73 0x52654973: "reiserfs", 74 0x7275: "romfs", 75 0x73636673: "securityfs", 76 0xf97cff8c: "selinux", 77 0x43415d53: "smack", 78 0x517b: "smb", 79 0xfe534d42: "smb2", 80 0x534f434b: "sockfs", 81 0x73717368: "squashfs", 82 0x62656572: "sysfs", 83 0x012ff7b6: "sysv2", 84 0x012ff7b5: "sysv4", 85 0x01021994: "tmpfs", 86 0x74726163: "tracefs", 87 0x15013346: "udf", 88 0x00011954: "ufs", 89 0x9fa2: "usbdevice", 90 0x01021997: "v9fs", 91 0xa501fcf5: "vxfs", 92 0xabba1974: "xenfs", 93 0x012ff7b4: "xenix", 94 0x58465342: "xfs", 95 } 96 97 func GetFSType(path string) (string, error) { 98 var buf unix.Statfs_t 99 100 err := unix.Statfs(path, &buf) 101 102 if err != nil { 103 return "", err 104 } 105 106 fsType, ok := fsTypeMapping[int64(buf.Type)] //nolint:unconvert 107 108 if !ok { 109 return "", fmt.Errorf("unknown fstype %d", buf.Type) 110 } 111 112 return fsType, nil 113 }