-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysinfo: print file system of datadir
fixes #3098 Signed-off-by: Natanael Copa <[email protected]>
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package probes | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// AssertFileSystem asserts a minimum amount of free disk space. | ||
func AssertFileSystem(parent ParentProbe, fsPath string) { | ||
parent.Set("filesystem:"+fsPath, func(path ProbePath, current Probe) Probe { | ||
return &assertFileSystem{path, fsPath} | ||
}) | ||
} | ||
|
||
type assertFileSystem struct { | ||
path ProbePath | ||
fsPath string | ||
} | ||
|
||
func (a *assertFileSystem) desc() ProbeDesc { | ||
return NewProbeDesc(fmt.Sprintf("File system of %s", a.fsPath), a.path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package probes | ||
|
||
import ( | ||
"os" | ||
"path" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func (a *assertFileSystem) Probe(reporter Reporter) error { | ||
// https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/magic.h | ||
fsTypes := map[int64]string{ | ||
0xadf5: "adfs", | ||
0xadff: "affs", | ||
0x5346414f: "afs", | ||
0x0187: "autofs", | ||
0x00c36400: "ceph", | ||
0x73757245: "coda", | ||
0x28cd3d45: "cramfs", | ||
0x453dcd28: "cramfs (wrong endian)", | ||
0x64626720: "debugfs", | ||
0x73636673: "securityfs", | ||
0xf97cff8c: "selinux", | ||
0x43415d53: "smack", | ||
0x858458f6: "ramfs", | ||
0x01021994: "tmpfs", | ||
0x958458f6: "hugetlbfs", | ||
0x73717368: "squashfs", | ||
0xf15f: "ecryptfs", | ||
0x414a53: "efs", | ||
0xe0f5e1e2: "erofs v1", | ||
0xabba1974: "xenfs", | ||
0xef53: "ext4", | ||
0x9123683e: "btrfs", | ||
0x3434: "nilfs", | ||
0xf2f52010: "f2fs", | ||
0xf995e849: "hpfs", | ||
0x9660: "isofs", | ||
0x72b6: "jffs2", | ||
0x58465342: "xfs", | ||
0x6165676c: "pstore", | ||
0xde5e81e4: "efivarfs", | ||
0x00c0ffee: "hostfs", | ||
0x794c7630: "overlayfs", | ||
0x65735546: "fuse", | ||
0xca451a4e: "bcachefs", | ||
0x137f: "minix", | ||
0x138f: "minix (30 char names)", | ||
0x2468: "minix v2", | ||
0x2478: "minix v2 (30 char names)", | ||
0x4d5a: "minix v3", | ||
0x4d44: "msdos", | ||
0x2011bab0: "exfat", | ||
0x564c: "ncp", | ||
0x6969: "nfs", | ||
0x7461636f: "ocfs2", | ||
0x9fa1: "openprom", | ||
0x002f: "qnx4", | ||
0x68191122: "qnx6", | ||
0x6b414653: "afs", | ||
0x52654973: "reiserfs", | ||
0x517b: "smb", | ||
0xff534d42: "cifs", | ||
0xfe534d42: "smb2", | ||
0x27e0eb: "cgroup", | ||
0x63677270: "cgroup2", | ||
0x7655821: "rdtgroup", | ||
0x57ac6e9d: "stack_end", | ||
0x74726163: "tracefs", | ||
0x01021997: "v9fs", | ||
0x62646576: "bdevfs", | ||
0x64646178: "daxfs", | ||
0x42494e4d: "binfmtfs", | ||
0x1cd1: "devpts", | ||
0x6c6f6f70: "binderfs", | ||
0xbad1dea: "futexfs", | ||
0x50495045: "pipefs", | ||
0x9fa0: "proc", | ||
0x534f434b: "sockfs", | ||
0x62656572: "sysfs", | ||
0x9fa2: "usbdevice", | ||
0x11307854: "mtd_inode_fs", | ||
0x09041934: "anon_inode_fs", | ||
0x73727279: "btrfs_test", | ||
0x6e736673: "nsfs", | ||
0xcafe4a11: "bpf_fs", | ||
0x5a3c69f0: "aafs", | ||
0x5a4f4653: "zonefs", | ||
0x15013346: "udf", | ||
0x444d4142: "dma_buf", | ||
0x454d444d: "devmem", | ||
0x5345434d: "secretmem", | ||
0x50494446: "pid_fs", | ||
} | ||
|
||
var stat unix.Statfs_t | ||
for p := a.fsPath; ; { | ||
if err := unix.Statfs(p, &stat); err != nil { | ||
if os.IsNotExist(err) { | ||
if parent := path.Dir(p); parent != p { | ||
p = parent | ||
continue | ||
} | ||
} | ||
return reporter.Error(a.desc(), err) | ||
} | ||
|
||
break | ||
} | ||
|
||
fs, found := fsTypes[stat.Type] | ||
if !found { | ||
fs = "unknown" | ||
} | ||
return reporter.Pass(a.desc(), StringProp(fs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build !linux | ||
|
||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package probes | ||
|
||
func (a *assertFileSystem) Probe(reporter Reporter) error { | ||
return reporter.Warn(a.desc(), probeUnsupported("Filesystem detection unsupported on this platform"), "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters