Browse code

Add some documentation to pkg/system

Partially addresses #11581

Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>

Ankush Agarwal authored on 2015/03/31 17:03:31
Showing 10 changed files
... ...
@@ -6,6 +6,10 @@ import (
6 6
 	"syscall"
7 7
 )
8 8
 
9
+// Lstat takes a path to a file and returns
10
+// a system.Stat_t type pertaining to that file.
11
+//
12
+// Throws an error if the file does not exist
9 13
 func Lstat(path string) (*Stat_t, error) {
10 14
 	s := &syscall.Stat_t{}
11 15
 	err := syscall.Lstat(path, s)
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"testing"
6 6
 )
7 7
 
8
+// TestLstat tests Lstat for existing and non existing files
8 9
 func TestLstat(t *testing.T) {
9 10
 	file, invalid, _, dir := prepareFiles(t)
10 11
 	defer os.RemoveAll(dir)
... ...
@@ -15,8 +15,8 @@ var (
15 15
 	ErrMalformed = errors.New("malformed file")
16 16
 )
17 17
 
18
-// Retrieve memory statistics of the host system and parse them into a MemInfo
19
-// type.
18
+// ReadMemInfo retrieves memory statistics of the host system and returns a
19
+//  MemInfo type.
20 20
 func ReadMemInfo() (*MemInfo, error) {
21 21
 	file, err := os.Open("/proc/meminfo")
22 22
 	if err != nil {
... ...
@@ -26,6 +26,10 @@ func ReadMemInfo() (*MemInfo, error) {
26 26
 	return parseMemInfo(file)
27 27
 }
28 28
 
29
+// parseMemInfo parses the /proc/meminfo file into
30
+// a MemInfo object given a io.Reader to the file.
31
+//
32
+// Throws error if there are problems reading from the file
29 33
 func parseMemInfo(reader io.Reader) (*MemInfo, error) {
30 34
 	meminfo := &MemInfo{}
31 35
 	scanner := bufio.NewScanner(reader)
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"github.com/docker/docker/pkg/units"
8 8
 )
9 9
 
10
+// TestMemInfo tests parseMemInfo with a static meminfo string
10 11
 func TestMemInfo(t *testing.T) {
11 12
 	const input = `
12 13
 	MemTotal:      1 kB
... ...
@@ -6,6 +6,8 @@ import (
6 6
 	"syscall"
7 7
 )
8 8
 
9
+// Mknod creates a filesystem node (file, device special file or named pipe) named path
10
+// with attributes specified by mode and dev
9 11
 func Mknod(path string, mode uint32, dev int) error {
10 12
 	return syscall.Mknod(path, mode, dev)
11 13
 }
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"syscall"
5 5
 )
6 6
 
7
+// Stat_t type contains status of a file. It contains metadata
8
+// like permission, owner, group, size, etc about a file
7 9
 type Stat_t struct {
8 10
 	mode uint32
9 11
 	uid  uint32
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"syscall"
5 5
 )
6 6
 
7
+// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
7 8
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
8 9
 	return &Stat_t{size: s.Size,
9 10
 		mode: s.Mode,
... ...
@@ -13,6 +14,10 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
13 13
 		mtim: s.Mtim}, nil
14 14
 }
15 15
 
16
+// Stat takes a path to a file and returns
17
+// a system.Stat_t type pertaining to that file.
18
+//
19
+// Throws an error if the file does not exist
16 20
 func Stat(path string) (*Stat_t, error) {
17 21
 	s := &syscall.Stat_t{}
18 22
 	err := syscall.Stat(path, s)
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"testing"
7 7
 )
8 8
 
9
+// TestFromStatT tests fromStatT for a tempfile
9 10
 func TestFromStatT(t *testing.T) {
10 11
 	file, _, _, dir := prepareFiles(t)
11 12
 	defer os.RemoveAll(dir)
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"syscall"
7 7
 )
8 8
 
9
+// fromStatT creates a system.Stat_t type from a syscall.Stat_t type
9 10
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
10 11
 	return &Stat_t{size: s.Size,
11 12
 		mode: uint32(s.Mode),
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"testing"
9 9
 )
10 10
 
11
+// prepareFiles creates files for testing in the temp directory
11 12
 func prepareFiles(t *testing.T) (string, string, string, string) {
12 13
 	dir, err := ioutil.TempDir("", "docker-system-test")
13 14
 	if err != nil {