Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
golang-github-shirou-gopsutil
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Debian Go Packaging Team
packages
golang-github-shirou-gopsutil
Commits
ad6c3f60
Commit
ad6c3f60
authored
Aug 14, 2015
by
Shirou WAKAYAMA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disk[freebsd,darwin,windows]: add fstype to DiskUsageStat.
parent
1223e289
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
2 deletions
+101
-2
disk/disk.go
disk/disk.go
+1
-0
disk/disk_darwin.go
disk/disk_darwin.go
+4
-0
disk/disk_freebsd.go
disk/disk_freebsd.go
+4
-0
disk/disk_linux.go
disk/disk_linux.go
+89
-0
disk/disk_test.go
disk/disk_test.go
+2
-1
disk/disk_unix.go
disk/disk_unix.go
+1
-1
No files found.
disk/disk.go
View file @
ad6c3f60
...
...
@@ -6,6 +6,7 @@ import (
type
DiskUsageStat
struct
{
Path
string
`json:"path"`
Fstype
string
`json:"fstype"`
Total
uint64
`json:"total"`
Free
uint64
`json:"free"`
Used
uint64
`json:"used"`
...
...
disk/disk_darwin.go
View file @
ad6c3f60
...
...
@@ -98,3 +98,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
}
return
}
func
getFsType
(
stat
syscall
.
Statfs_t
)
string
{
return
common
.
IntToString
(
stat
.
Fstypename
[
:
])
}
disk/disk_freebsd.go
View file @
ad6c3f60
...
...
@@ -171,3 +171,7 @@ func parseDevstat(buf []byte) (Devstat, error) {
return
ds
,
nil
}
func
getFType
(
stat
syscall
.
Statfs_t
)
string
{
return
common
.
IntToString
(
stat
.
Fstypename
[
:
])
}
disk/disk_linux.go
View file @
ad6c3f60
...
...
@@ -7,6 +7,7 @@ import (
"os/exec"
"strconv"
"strings"
"syscall"
common
"github.com/shirou/gopsutil/common"
)
...
...
@@ -14,6 +15,85 @@ import (
const
(
SectorSize
=
512
)
const
(
// magic.h
ADFS_SUPER_MAGIC
=
0xadf5
AFFS_SUPER_MAGIC
=
0xADFF
BEFS_SUPER_MAGIC
=
0x42465331
BFS_MAGIC
=
0x1BADFACE
CIFS_MAGIC_NUMBER
=
0xFF534D42
CODA_SUPER_MAGIC
=
0x73757245
COH_SUPER_MAGIC
=
0x012FF7B7
CRAMFS_MAGIC
=
0x28cd3d45
DEVFS_SUPER_MAGIC
=
0x1373
EFS_SUPER_MAGIC
=
0x00414A53
EXT_SUPER_MAGIC
=
0x137D
EXT2_OLD_SUPER_MAGIC
=
0xEF51
EXT2_SUPER_MAGIC
=
0xEF53
EXT3_SUPER_MAGIC
=
0xEF53
EXT4_SUPER_MAGIC
=
0xEF53
HFS_SUPER_MAGIC
=
0x4244
HPFS_SUPER_MAGIC
=
0xF995E849
HUGETLBFS_MAGIC
=
0x958458f6
ISOFS_SUPER_MAGIC
=
0x9660
JFFS2_SUPER_MAGIC
=
0x72b6
JFS_SUPER_MAGIC
=
0x3153464a
MINIX_SUPER_MAGIC
=
0x137F
/* orig. minix */
MINIX_SUPER_MAGIC2
=
0x138F
/* 30 char minix */
MINIX2_SUPER_MAGIC
=
0x2468
/* minix V2 */
MINIX2_SUPER_MAGIC2
=
0x2478
/* minix V2, 30 char names */
MSDOS_SUPER_MAGIC
=
0x4d44
NCP_SUPER_MAGIC
=
0x564c
NFS_SUPER_MAGIC
=
0x6969
NTFS_SB_MAGIC
=
0x5346544e
OPENPROM_SUPER_MAGIC
=
0x9fa1
PROC_SUPER_MAGIC
=
0x9fa0
QNX4_SUPER_MAGIC
=
0x002f
REISERFS_SUPER_MAGIC
=
0x52654973
ROMFS_MAGIC
=
0x7275
SMB_SUPER_MAGIC
=
0x517B
SYSV2_SUPER_MAGIC
=
0x012FF7B6
SYSV4_SUPER_MAGIC
=
0x012FF7B5
TMPFS_MAGIC
=
0x01021994
UDF_SUPER_MAGIC
=
0x15013346
UFS_MAGIC
=
0x00011954
USBDEVICE_SUPER_MAGIC
=
0x9fa2
VXFS_SUPER_MAGIC
=
0xa501FCF5
XENIX_SUPER_MAGIC
=
0x012FF7B4
XFS_SUPER_MAGIC
=
0x58465342
_XIAFS_SUPER_MAGIC
=
0x012FD16D
)
var
fsTypeMap
=
map
[
int64
]
string
{
AFFS_SUPER_MAGIC
:
"affs"
,
COH_SUPER_MAGIC
:
"coh"
,
DEVFS_SUPER_MAGIC
:
"devfs"
,
EXT2_OLD_SUPER_MAGIC
:
"old ext2"
,
EXT2_SUPER_MAGIC
:
"ext2"
,
EXT3_SUPER_MAGIC
:
"ext3"
,
EXT4_SUPER_MAGIC
:
"ext4"
,
HFS_SUPER_MAGIC
:
"hfs"
,
HPFS_SUPER_MAGIC
:
"hpfs"
,
ISOFS_SUPER_MAGIC
:
"isofs"
,
MINIX2_SUPER_MAGIC
:
"minix v2"
,
MINIX2_SUPER_MAGIC2
:
"minix v2 30 char"
,
MINIX_SUPER_MAGIC
:
"minix"
,
MINIX_SUPER_MAGIC2
:
"minix 30 char"
,
MSDOS_SUPER_MAGIC
:
"msdos"
,
NCP_SUPER_MAGIC
:
"ncp"
,
NFS_SUPER_MAGIC
:
"nfs"
,
NTFS_SB_MAGIC
:
"ntfs"
,
PROC_SUPER_MAGIC
:
"proc"
,
SMB_SUPER_MAGIC
:
"smb"
,
SYSV2_SUPER_MAGIC
:
"sysv2"
,
SYSV4_SUPER_MAGIC
:
"sysv4"
,
UFS_MAGIC
:
"ufs"
,
USBDEVICE_SUPER_MAGIC
:
"usb"
,
VXFS_SUPER_MAGIC
:
"vxfs"
,
XENIX_SUPER_MAGIC
:
"xenix"
,
XFS_SUPER_MAGIC
:
"xfs"
,
_XIAFS_SUPER_MAGIC
:
"xiafs"
,
}
// Get disk partitions.
// should use setmntent(3) but this implement use /etc/mtab file
...
...
@@ -120,3 +200,12 @@ func GetDiskSerialNumber(name string) string {
}
return
""
}
func
getFsType
(
stat
syscall
.
Statfs_t
)
string
{
t
:=
stat
.
Type
ret
,
ok
:=
fsTypeMap
[
t
]
if
!
ok
{
return
""
}
return
ret
}
disk/disk_test.go
View file @
ad6c3f60
...
...
@@ -61,8 +61,9 @@ func TestDiskUsageStat_String(t *testing.T) {
InodesUsed
:
5000
,
InodesFree
:
6000
,
InodesUsedPercent
:
49.1
,
Fstype
:
"ext4"
,
}
e
:=
`{"path":"/","total":1000,"free":2000,"used":3000,"used_percent":50.1,"inodes_total":4000,"inodes_used":5000,"inodes_free":6000,"inodes_used_percent":49.1}`
e
:=
`{"path":"/","
fstype":"ext4","
total":1000,"free":2000,"used":3000,"used_percent":50.1,"inodes_total":4000,"inodes_used":5000,"inodes_free":6000,"inodes_used_percent":49.1}`
if
e
!=
fmt
.
Sprintf
(
"%v"
,
v
)
{
t
.
Errorf
(
"DiskUsageStat string is invalid: %v"
,
v
)
}
...
...
disk/disk_unix.go
View file @
ad6c3f60
...
...
@@ -10,11 +10,11 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
if
err
!=
nil
{
return
nil
,
err
}
bsize
:=
stat
.
Bsize
ret
:=
&
DiskUsageStat
{
Path
:
path
,
Fstype
:
getFsType
(
stat
),
Total
:
(
uint64
(
stat
.
Blocks
)
*
uint64
(
bsize
)),
Free
:
(
uint64
(
stat
.
Bfree
)
*
uint64
(
bsize
)),
InodesTotal
:
(
uint64
(
stat
.
Files
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment