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