...
1
2
3
4
5
6
7 package unix_test
8
9 import (
10 "os"
11 "testing"
12 "unsafe"
13
14 "golang.org/x/sys/unix"
15 )
16
17 func TestFstatfs(t *testing.T) {
18
19 wd, err := os.Getwd()
20 if err != nil {
21 t.Fatal(err)
22 }
23 file, err := os.Open(wd)
24 if err != nil {
25 t.Fatal(err)
26 }
27
28
29 var stat unix.Statfs_t
30 err = unix.Fstatfs(int(file.Fd()), &stat)
31 if err != nil {
32 t.Fatal(err)
33 }
34 var stat_v unix.Statvfs_t
35 err = unix.Fstatvfs(int(file.Fd()), &stat_v)
36 if stat.Bsize != stat_v.Bsize ||
37 stat.Blocks != stat_v.Blocks ||
38 stat.Bfree != stat_v.Bfree ||
39 stat.Bavail != stat_v.Bavail ||
40 stat.Files != stat_v.Files ||
41 stat.Ffree != stat_v.Ffree ||
42 stat.Fsid != stat_v.Fsid ||
43 stat.Namelen != stat_v.Namemax ||
44 stat.Frsize != stat_v.Frsize ||
45 stat.Flags != stat_v.Flag {
46 t.Errorf("Mismatching fields in Statfs_t and Statvfs_t.\nStatfs_t = %+v\nStatvfs_t = %+v", stat, stat_v)
47 }
48
49
50 var mnt_ent_buffer struct {
51 header unix.W_Mnth
52 filesys_info [128]unix.W_Mntent
53 }
54 var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
55 var fs_count int = -1
56 for fs_count < 0 {
57 fs_count, err = unix.W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
58 if err != nil {
59 t.Fatal(err)
60 }
61 for i := 0; i < fs_count; i++ {
62 if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
63 correct_type := uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
64 if stat.Type != correct_type {
65 t.Errorf("File system type is 0x%x. Should be 0x%x instead", stat.Type, correct_type)
66 }
67 return
68 }
69 }
70 }
71
72 }
73
View as plain text