diff --git a/pkg/system/lstat.go b/pkg/system/lstat.go index 6c1ed2e386..a966cd4881 100644 --- a/pkg/system/lstat.go +++ b/pkg/system/lstat.go @@ -6,6 +6,10 @@ import ( "syscall" ) +// Lstat takes a path to a file and returns +// a system.Stat_t type pertaining to that file. +// +// Throws an error if the file does not exist func Lstat(path string) (*Stat_t, error) { s := &syscall.Stat_t{} err := syscall.Lstat(path, s) diff --git a/pkg/system/lstat_test.go b/pkg/system/lstat_test.go index 9bab4d7b0c..6bac492eb1 100644 --- a/pkg/system/lstat_test.go +++ b/pkg/system/lstat_test.go @@ -5,6 +5,7 @@ import ( "testing" ) +// TestLstat tests Lstat for existing and non existing files func TestLstat(t *testing.T) { file, invalid, _, dir := prepareFiles(t) defer os.RemoveAll(dir) diff --git a/pkg/system/meminfo_linux.go b/pkg/system/meminfo_linux.go index b7de3ff776..e2ca140092 100644 --- a/pkg/system/meminfo_linux.go +++ b/pkg/system/meminfo_linux.go @@ -15,8 +15,8 @@ var ( ErrMalformed = errors.New("malformed file") ) -// Retrieve memory statistics of the host system and parse them into a MemInfo -// type. +// ReadMemInfo retrieves memory statistics of the host system and returns a +// MemInfo type. func ReadMemInfo() (*MemInfo, error) { file, err := os.Open("/proc/meminfo") if err != nil { @@ -26,6 +26,10 @@ func ReadMemInfo() (*MemInfo, error) { return parseMemInfo(file) } +// parseMemInfo parses the /proc/meminfo file into +// a MemInfo object given a io.Reader to the file. +// +// Throws error if there are problems reading from the file func parseMemInfo(reader io.Reader) (*MemInfo, error) { meminfo := &MemInfo{} scanner := bufio.NewScanner(reader) diff --git a/pkg/system/meminfo_linux_test.go b/pkg/system/meminfo_linux_test.go index 377405ea69..10ddf796c6 100644 --- a/pkg/system/meminfo_linux_test.go +++ b/pkg/system/meminfo_linux_test.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/pkg/units" ) +// TestMemInfo tests parseMemInfo with a static meminfo string func TestMemInfo(t *testing.T) { const input = ` MemTotal: 1 kB diff --git a/pkg/system/mknod.go b/pkg/system/mknod.go index 06f9c6afbb..26617eb08f 100644 --- a/pkg/system/mknod.go +++ b/pkg/system/mknod.go @@ -6,6 +6,8 @@ import ( "syscall" ) +// Mknod creates a filesystem node (file, device special file or named pipe) named path +// with attributes specified by mode and dev func Mknod(path string, mode uint32, dev int) error { return syscall.Mknod(path, mode, dev) } diff --git a/pkg/system/stat.go b/pkg/system/stat.go index 186e85287d..ba22b4dd9d 100644 --- a/pkg/system/stat.go +++ b/pkg/system/stat.go @@ -4,6 +4,8 @@ import ( "syscall" ) +// Stat_t type contains status of a file. It contains metadata +// like permission, owner, group, size, etc about a file type Stat_t struct { mode uint32 uid uint32 diff --git a/pkg/system/stat_linux.go b/pkg/system/stat_linux.go index 072728d0a1..928ba89e69 100644 --- a/pkg/system/stat_linux.go +++ b/pkg/system/stat_linux.go @@ -4,6 +4,7 @@ import ( "syscall" ) +// fromStatT converts a syscall.Stat_t type to a system.Stat_t type func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { return &Stat_t{size: s.Size, mode: s.Mode, @@ -13,6 +14,10 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { mtim: s.Mtim}, nil } +// Stat takes a path to a file and returns +// a system.Stat_t type pertaining to that file. +// +// Throws an error if the file does not exist func Stat(path string) (*Stat_t, error) { s := &syscall.Stat_t{} err := syscall.Stat(path, s) diff --git a/pkg/system/stat_test.go b/pkg/system/stat_test.go index abcc8ea7a6..4534129200 100644 --- a/pkg/system/stat_test.go +++ b/pkg/system/stat_test.go @@ -6,6 +6,7 @@ import ( "testing" ) +// TestFromStatT tests fromStatT for a tempfile func TestFromStatT(t *testing.T) { file, _, _, dir := prepareFiles(t) defer os.RemoveAll(dir) diff --git a/pkg/system/stat_unsupported.go b/pkg/system/stat_unsupported.go index 66323eee21..7e0d0348fa 100644 --- a/pkg/system/stat_unsupported.go +++ b/pkg/system/stat_unsupported.go @@ -6,6 +6,7 @@ import ( "syscall" ) +// fromStatT creates a system.Stat_t type from a syscall.Stat_t type func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { return &Stat_t{size: s.Size, mode: uint32(s.Mode), diff --git a/pkg/system/utimes_test.go b/pkg/system/utimes_test.go index 1dea47cc15..350cce1ead 100644 --- a/pkg/system/utimes_test.go +++ b/pkg/system/utimes_test.go @@ -8,6 +8,7 @@ import ( "testing" ) +// prepareFiles creates files for testing in the temp directory func prepareFiles(t *testing.T) (string, string, string, string) { dir, err := ioutil.TempDir("", "docker-system-test") if err != nil {