Skip to content

Commit

Permalink
pass through device numbers for block/char devices
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott committed Oct 24, 2023
1 parent c6fdd71 commit 2b12fc2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ func ToFileAttribute(info os.FileInfo) *FileAttribute {
f.Type = FileTypeLink
} else if m&os.ModeCharDevice != 0 {
f.Type = FileTypeCharacter
// TODO: set major/minor dev number
//f.SpecData = 0,0
} else if m&os.ModeDevice != 0 {
f.Type = FileTypeBlock
// TODO: set major/minor dev number
//f.SpecData = 0,0
} else if m&os.ModeSocket != 0 {
f.Type = FileTypeSocket
} else if m&os.ModeNamedPipe != 0 {
Expand All @@ -116,6 +112,7 @@ func ToFileAttribute(info os.FileInfo) *FileAttribute {
f.Nlink = a.Nlink
f.UID = a.UID
f.GID = a.GID
f.SpecData = [2]uint32{a.Major, a.Minor}
}

f.Filesize = uint64(info.Size())
Expand Down
2 changes: 2 additions & 0 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type FileInfo struct {
Nlink uint32
UID uint32
GID uint32
Major uint32
Minor uint32
}

// GetInfo extracts some non-standardized items from the result of a Stat call.
Expand Down
5 changes: 5 additions & 0 deletions file/file_unix.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris

package file

import (
"os"
"syscall"

"golang.org/x/sys/unix"
)

func getInfo(info os.FileInfo) *FileInfo {
Expand All @@ -13,6 +16,8 @@ func getInfo(info os.FileInfo) *FileInfo {
fi.Nlink = uint32(s.Nlink)
fi.UID = s.Uid
fi.GID = s.Gid
fi.Major = unix.Major(uint64(s.Rdev))
fi.Minor = unix.Minor(uint64(s.Rdev))
return fi
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/willscott/go-nfs

go 1.19
go 1.21

require (
github.com/go-git/go-billy/v5 v5.4.1
Expand All @@ -9,12 +9,12 @@ require (
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93
github.com/willscott/go-nfs-client v0.0.0-20200605172546-271fa9065b33
github.com/willscott/memphis v0.0.0-20210922141505-529d4987ab7e
golang.org/x/sys v0.3.0
)

require (
github.com/polydawn/go-timeless-api v0.0.0-20220821201550-b93919e12c56 // indirect
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect
github.com/polydawn/rio v0.0.0-20220823181337-7c31ad9831a4 // indirect
github.com/warpfork/go-errcat v0.0.0-20180917083543-335044ffc86e // indirect
golang.org/x/sys v0.3.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 h1:UVArwN/wkKjMVhh2EQ
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93/go.mod h1:Nfe4efndBz4TibWycNE+lqyJZiMX4ycx+QKV8Ta0f/o=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/warpfork/go-errcat v0.0.0-20180917083543-335044ffc86e h1:FIB2fi7XJGHIdf5rWNsfFQqatIKxutT45G+wNuMQNgs=
github.com/warpfork/go-errcat v0.0.0-20180917083543-335044ffc86e/go.mod h1:/qe02xr3jvTUz8u/PV0FHGpP8t96OQNP7U9BJMwMLEw=
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w=
Expand Down

0 comments on commit 2b12fc2

Please sign in to comment.