1
2
3
4
5
6
7 package unix
8
9 import "unsafe"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
26 var ts *Timespec
27 if timeout != nil {
28 ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
29 }
30 return pselect6(nfd, r, w, e, ts, nil)
31 }
32
33
34
35
36
37
38
39 func timespecFromStatxTimestamp(x StatxTimestamp) Timespec {
40 return Timespec{
41 Sec: x.Sec,
42 Nsec: int64(x.Nsec),
43 }
44 }
45
46 func Fstatat(fd int, path string, stat *Stat_t, flags int) error {
47 var r Statx_t
48
49 if err := Statx(fd, path, AT_NO_AUTOMOUNT|flags, STATX_BASIC_STATS, &r); err != nil {
50 return err
51 }
52
53 stat.Dev = Mkdev(r.Dev_major, r.Dev_minor)
54 stat.Ino = r.Ino
55 stat.Mode = uint32(r.Mode)
56 stat.Nlink = r.Nlink
57 stat.Uid = r.Uid
58 stat.Gid = r.Gid
59 stat.Rdev = Mkdev(r.Rdev_major, r.Rdev_minor)
60
61
62 stat.Size = int64(r.Size)
63 stat.Blksize = int32(r.Blksize)
64 stat.Blocks = int64(r.Blocks)
65 stat.Atim = timespecFromStatxTimestamp(r.Atime)
66 stat.Mtim = timespecFromStatxTimestamp(r.Mtime)
67 stat.Ctim = timespecFromStatxTimestamp(r.Ctime)
68
69 return nil
70 }
71
72 func Fstat(fd int, stat *Stat_t) (err error) {
73 return Fstatat(fd, "", stat, AT_EMPTY_PATH)
74 }
75
76 func Stat(path string, stat *Stat_t) (err error) {
77 return Fstatat(AT_FDCWD, path, stat, 0)
78 }
79
80 func Lchown(path string, uid int, gid int) (err error) {
81 return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
82 }
83
84 func Lstat(path string, stat *Stat_t) (err error) {
85 return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
86 }
87
88
89
90
91
92 func Ustat(dev int, ubuf *Ustat_t) (err error) {
93 return ENOSYS
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 func setTimespec(sec, nsec int64) Timespec {
116 return Timespec{Sec: sec, Nsec: nsec}
117 }
118
119 func setTimeval(sec, usec int64) Timeval {
120 return Timeval{Sec: sec, Usec: usec}
121 }
122
123 func Getrlimit(resource int, rlim *Rlimit) (err error) {
124 err = Prlimit(0, resource, nil, rlim)
125 return
126 }
127
128 func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
129 if tv == nil {
130 return utimensat(dirfd, path, nil, 0)
131 }
132
133 ts := []Timespec{
134 NsecToTimespec(TimevalToNsec(tv[0])),
135 NsecToTimespec(TimevalToNsec(tv[1])),
136 }
137 return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
138 }
139
140 func Time(t *Time_t) (Time_t, error) {
141 var tv Timeval
142 err := Gettimeofday(&tv)
143 if err != nil {
144 return 0, err
145 }
146 if t != nil {
147 *t = Time_t(tv.Sec)
148 }
149 return Time_t(tv.Sec), nil
150 }
151
152 func Utime(path string, buf *Utimbuf) error {
153 if buf == nil {
154 return Utimes(path, nil)
155 }
156 tv := []Timeval{
157 {Sec: buf.Actime},
158 {Sec: buf.Modtime},
159 }
160 return Utimes(path, tv)
161 }
162
163 func utimes(path string, tv *[2]Timeval) (err error) {
164 if tv == nil {
165 return utimensat(AT_FDCWD, path, nil, 0)
166 }
167
168 ts := []Timespec{
169 NsecToTimespec(TimevalToNsec(tv[0])),
170 NsecToTimespec(TimevalToNsec(tv[1])),
171 }
172 return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
173 }
174
175 func (r *PtraceRegs) PC() uint64 { return r.Era }
176
177 func (r *PtraceRegs) SetPC(era uint64) { r.Era = era }
178
179 func (iov *Iovec) SetLen(length int) {
180 iov.Len = uint64(length)
181 }
182
183 func (msghdr *Msghdr) SetControllen(length int) {
184 msghdr.Controllen = uint64(length)
185 }
186
187 func (msghdr *Msghdr) SetIovlen(length int) {
188 msghdr.Iovlen = uint64(length)
189 }
190
191 func (cmsg *Cmsghdr) SetLen(length int) {
192 cmsg.Len = uint64(length)
193 }
194
195 func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
196 rsa.Service_name_len = uint64(length)
197 }
198
199 func Pause() error {
200 _, err := ppoll(nil, 0, nil, nil)
201 return err
202 }
203
204 func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
205 return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
206 }
207
208
209
210 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
211 cmdlineLen := len(cmdline)
212 if cmdlineLen > 0 {
213
214
215
216 cmdlineLen++
217 }
218 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
219 }
220
221 const SYS_FSTATAT = SYS_NEWFSTATAT
222
View as plain text