Partially addresses #11581
Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>
| ... | ... |
@@ -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) |
| ... | ... |
@@ -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) |
| ... | ... |
@@ -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,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) |