Lines 1-68
Link Here
|
1 |
--- pkg/disk/stat_freebsd.go.orig 2020-02-24 22:16:58 UTC |
|
|
2 |
+++ pkg/disk/stat_freebsd.go |
3 |
@@ -0,0 +1,65 @@ |
4 |
+// +build freebsd |
5 |
+ |
6 |
+/* |
7 |
+ * MinIO Cloud Storage, (C) 2019-2020 MinIO, Inc. |
8 |
+ * |
9 |
+ * Licensed under the Apache License, Version 2.0 (the "License"); |
10 |
+ * you may not use this file except in compliance with the License. |
11 |
+ * You may obtain a copy of the License at |
12 |
+ * |
13 |
+ * http://www.apache.org/licenses/LICENSE-2.0 |
14 |
+ * |
15 |
+ * Unless required by applicable law or agreed to in writing, software |
16 |
+ * distributed under the License is distributed on an "AS IS" BASIS, |
17 |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 |
+ * See the License for the specific language governing permissions and |
19 |
+ * limitations under the License. |
20 |
+ */ |
21 |
+ |
22 |
+package disk |
23 |
+ |
24 |
+import ( |
25 |
+ "os/user" |
26 |
+ "strconv" |
27 |
+ "strings" |
28 |
+ "syscall" |
29 |
+) |
30 |
+ |
31 |
+// GetFileSystemAttrs return the file system attribute as string; containing mode, |
32 |
+// uid, gid, uname, Gname, atime, mtime, ctime and md5 |
33 |
+func GetFileSystemAttrs(file string) (string, error) { |
34 |
+ st := syscall.Stat_t{} |
35 |
+ err := syscall.Stat(file, &st) |
36 |
+ if err != nil { |
37 |
+ return "", err |
38 |
+ } |
39 |
+ |
40 |
+ var fileAttr strings.Builder |
41 |
+ fileAttr.WriteString("atime:") |
42 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Atimespec.Sec))) |
43 |
+ fileAttr.WriteString("/ctime:") |
44 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Ctimespec.Sec))) |
45 |
+ fileAttr.WriteString("/gid:") |
46 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Gid))) |
47 |
+ |
48 |
+ g, err := user.LookupGroupId(strconv.FormatUint(uint64(st.Gid), 10)) |
49 |
+ if err == nil { |
50 |
+ fileAttr.WriteString("/gname:") |
51 |
+ fileAttr.WriteString(g.Name) |
52 |
+ } |
53 |
+ |
54 |
+ fileAttr.WriteString("/mode:") |
55 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Mode))) |
56 |
+ fileAttr.WriteString("/mtime:") |
57 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Mtimespec.Sec))) |
58 |
+ fileAttr.WriteString("/uid:") |
59 |
+ fileAttr.WriteString(strconv.Itoa(int(st.Uid))) |
60 |
+ |
61 |
+ u, err := user.LookupId(strconv.FormatUint(uint64(st.Uid), 10)) |
62 |
+ if err == nil { |
63 |
+ fileAttr.WriteString("/uname:") |
64 |
+ fileAttr.WriteString(u.Username) |
65 |
+ } |
66 |
+ |
67 |
+ return fileAttr.String(), nil |
68 |
+} |