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 tv := []Timeval{
154 {Sec: buf.Actime},
155 {Sec: buf.Modtime},
156 }
157 return Utimes(path, tv)
158 }
159
160 func utimes(path string, tv *[2]Timeval) (err error) {
161 if tv == nil {
162 return utimensat(AT_FDCWD, path, nil, 0)
163 }
164
165 ts := []Timespec{
166 NsecToTimespec(TimevalToNsec(tv[0])),
167 NsecToTimespec(TimevalToNsec(tv[1])),
168 }
169 return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
170 }
171
172 func (r *PtraceRegs) PC() uint64 { return r.Era }
173
174 func (r *PtraceRegs) SetPC(era uint64) { r.Era = era }
175
176 func (iov *Iovec) SetLen(length int) {
177 iov.Len = uint64(length)
178 }
179
180 func (msghdr *Msghdr) SetControllen(length int) {
181 msghdr.Controllen = uint64(length)
182 }
183
184 func (msghdr *Msghdr) SetIovlen(length int) {
185 msghdr.Iovlen = uint64(length)
186 }
187
188 func (cmsg *Cmsghdr) SetLen(length int) {
189 cmsg.Len = uint64(length)
190 }
191
192 func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
193 rsa.Service_name_len = uint64(length)
194 }
195
196 func Pause() error {
197 _, err := ppoll(nil, 0, nil, nil)
198 return err
199 }
200
201 func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
202 return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
203 }
204
205
206
207 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
208 cmdlineLen := len(cmdline)
209 if cmdlineLen > 0 {
210
211
212
213 cmdlineLen++
214 }
215 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
216 }
217
218 const SYS_FSTATAT = SYS_NEWFSTATAT
219
View as plain text