syscall_linux_test.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build linux
  5. package unix_test
  6. import (
  7. "bufio"
  8. "bytes"
  9. "errors"
  10. "fmt"
  11. "io/ioutil"
  12. "os"
  13. "runtime"
  14. "runtime/debug"
  15. "strconv"
  16. "strings"
  17. "testing"
  18. "time"
  19. "golang.org/x/sys/unix"
  20. )
  21. func TestIoctlGetInt(t *testing.T) {
  22. f, err := os.Open("/dev/random")
  23. if err != nil {
  24. t.Fatalf("failed to open device: %v", err)
  25. }
  26. defer f.Close()
  27. v, err := unix.IoctlGetInt(int(f.Fd()), unix.RNDGETENTCNT)
  28. if err != nil {
  29. t.Fatalf("failed to perform ioctl: %v", err)
  30. }
  31. t.Logf("%d bits of entropy available", v)
  32. }
  33. func TestIoctlGetRTCTime(t *testing.T) {
  34. f, err := os.Open("/dev/rtc0")
  35. if err != nil {
  36. t.Skipf("skipping test, %v", err)
  37. }
  38. defer f.Close()
  39. v, err := unix.IoctlGetRTCTime(int(f.Fd()))
  40. if err != nil {
  41. t.Fatalf("failed to perform ioctl: %v", err)
  42. }
  43. t.Logf("RTC time: %04d-%02d-%02d %02d:%02d:%02d", v.Year+1900, v.Mon+1, v.Mday, v.Hour, v.Min, v.Sec)
  44. }
  45. func TestPpoll(t *testing.T) {
  46. if runtime.GOOS == "android" {
  47. t.Skip("mkfifo syscall is not available on android, skipping test")
  48. }
  49. defer chtmpdir(t)()
  50. f, cleanup := mktmpfifo(t)
  51. defer cleanup()
  52. const timeout = 100 * time.Millisecond
  53. ok := make(chan bool, 1)
  54. go func() {
  55. select {
  56. case <-time.After(10 * timeout):
  57. t.Errorf("Ppoll: failed to timeout after %d", 10*timeout)
  58. case <-ok:
  59. }
  60. }()
  61. fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
  62. timeoutTs := unix.NsecToTimespec(int64(timeout))
  63. n, err := unix.Ppoll(fds, &timeoutTs, nil)
  64. ok <- true
  65. if err != nil {
  66. t.Errorf("Ppoll: unexpected error: %v", err)
  67. return
  68. }
  69. if n != 0 {
  70. t.Errorf("Ppoll: wrong number of events: got %v, expected %v", n, 0)
  71. return
  72. }
  73. }
  74. func TestTime(t *testing.T) {
  75. var ut unix.Time_t
  76. ut2, err := unix.Time(&ut)
  77. if err != nil {
  78. t.Fatalf("Time: %v", err)
  79. }
  80. if ut != ut2 {
  81. t.Errorf("Time: return value %v should be equal to argument %v", ut2, ut)
  82. }
  83. var now time.Time
  84. for i := 0; i < 10; i++ {
  85. ut, err = unix.Time(nil)
  86. if err != nil {
  87. t.Fatalf("Time: %v", err)
  88. }
  89. now = time.Now()
  90. if int64(ut) == now.Unix() {
  91. return
  92. }
  93. }
  94. t.Errorf("Time: return value %v should be nearly equal to time.Now().Unix() %v", ut, now.Unix())
  95. }
  96. func TestUtime(t *testing.T) {
  97. defer chtmpdir(t)()
  98. touch(t, "file1")
  99. buf := &unix.Utimbuf{
  100. Modtime: 12345,
  101. }
  102. err := unix.Utime("file1", buf)
  103. if err != nil {
  104. t.Fatalf("Utime: %v", err)
  105. }
  106. fi, err := os.Stat("file1")
  107. if err != nil {
  108. t.Fatal(err)
  109. }
  110. if fi.ModTime().Unix() != 12345 {
  111. t.Errorf("Utime: failed to change modtime: expected %v, got %v", 12345, fi.ModTime().Unix())
  112. }
  113. }
  114. func TestUtimesNanoAt(t *testing.T) {
  115. defer chtmpdir(t)()
  116. symlink := "symlink1"
  117. os.Remove(symlink)
  118. err := os.Symlink("nonexisting", symlink)
  119. if err != nil {
  120. t.Fatal(err)
  121. }
  122. ts := []unix.Timespec{
  123. {Sec: 1111, Nsec: 2222},
  124. {Sec: 3333, Nsec: 4444},
  125. }
  126. err = unix.UtimesNanoAt(unix.AT_FDCWD, symlink, ts, unix.AT_SYMLINK_NOFOLLOW)
  127. if err != nil {
  128. t.Fatalf("UtimesNanoAt: %v", err)
  129. }
  130. var st unix.Stat_t
  131. err = unix.Lstat(symlink, &st)
  132. if err != nil {
  133. t.Fatalf("Lstat: %v", err)
  134. }
  135. // Only check Mtim, Atim might not be supported by the underlying filesystem
  136. expected := ts[1]
  137. if st.Mtim.Nsec == 0 {
  138. // Some filesystems only support 1-second time stamp resolution
  139. // and will always set Nsec to 0.
  140. expected.Nsec = 0
  141. }
  142. if st.Mtim != expected {
  143. t.Errorf("UtimesNanoAt: wrong mtime: expected %v, got %v", expected, st.Mtim)
  144. }
  145. }
  146. func TestRlimitAs(t *testing.T) {
  147. // disable GC during to avoid flaky test
  148. defer debug.SetGCPercent(debug.SetGCPercent(-1))
  149. var rlim unix.Rlimit
  150. err := unix.Getrlimit(unix.RLIMIT_AS, &rlim)
  151. if err != nil {
  152. t.Fatalf("Getrlimit: %v", err)
  153. }
  154. var zero unix.Rlimit
  155. if zero == rlim {
  156. t.Fatalf("Getrlimit: got zero value %#v", rlim)
  157. }
  158. set := rlim
  159. set.Cur = uint64(unix.Getpagesize())
  160. err = unix.Setrlimit(unix.RLIMIT_AS, &set)
  161. if err != nil {
  162. t.Fatalf("Setrlimit: set failed: %#v %v", set, err)
  163. }
  164. // RLIMIT_AS was set to the page size, so mmap()'ing twice the page size
  165. // should fail. See 'man 2 getrlimit'.
  166. _, err = unix.Mmap(-1, 0, 2*unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
  167. if err == nil {
  168. t.Fatal("Mmap: unexpectedly succeeded after setting RLIMIT_AS")
  169. }
  170. err = unix.Setrlimit(unix.RLIMIT_AS, &rlim)
  171. if err != nil {
  172. t.Fatalf("Setrlimit: restore failed: %#v %v", rlim, err)
  173. }
  174. b, err := unix.Mmap(-1, 0, 2*unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
  175. if err != nil {
  176. t.Fatalf("Mmap: %v", err)
  177. }
  178. err = unix.Munmap(b)
  179. if err != nil {
  180. t.Fatalf("Munmap: %v", err)
  181. }
  182. }
  183. func TestSelect(t *testing.T) {
  184. _, err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
  185. if err != nil {
  186. t.Fatalf("Select: %v", err)
  187. }
  188. dur := 150 * time.Millisecond
  189. tv := unix.NsecToTimeval(int64(dur))
  190. start := time.Now()
  191. _, err = unix.Select(0, nil, nil, nil, &tv)
  192. took := time.Since(start)
  193. if err != nil {
  194. t.Fatalf("Select: %v", err)
  195. }
  196. if took < dur {
  197. t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
  198. }
  199. }
  200. func TestPselect(t *testing.T) {
  201. _, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
  202. if err != nil {
  203. t.Fatalf("Pselect: %v", err)
  204. }
  205. dur := 2500 * time.Microsecond
  206. ts := unix.NsecToTimespec(int64(dur))
  207. start := time.Now()
  208. _, err = unix.Pselect(0, nil, nil, nil, &ts, nil)
  209. took := time.Since(start)
  210. if err != nil {
  211. t.Fatalf("Pselect: %v", err)
  212. }
  213. if took < dur {
  214. t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took)
  215. }
  216. }
  217. func TestSchedSetaffinity(t *testing.T) {
  218. runtime.LockOSThread()
  219. defer runtime.UnlockOSThread()
  220. var oldMask unix.CPUSet
  221. err := unix.SchedGetaffinity(0, &oldMask)
  222. if err != nil {
  223. t.Fatalf("SchedGetaffinity: %v", err)
  224. }
  225. var newMask unix.CPUSet
  226. newMask.Zero()
  227. if newMask.Count() != 0 {
  228. t.Errorf("CpuZero: didn't zero CPU set: %v", newMask)
  229. }
  230. cpu := 1
  231. newMask.Set(cpu)
  232. if newMask.Count() != 1 || !newMask.IsSet(cpu) {
  233. t.Errorf("CpuSet: didn't set CPU %d in set: %v", cpu, newMask)
  234. }
  235. cpu = 5
  236. newMask.Set(cpu)
  237. if newMask.Count() != 2 || !newMask.IsSet(cpu) {
  238. t.Errorf("CpuSet: didn't set CPU %d in set: %v", cpu, newMask)
  239. }
  240. newMask.Clear(cpu)
  241. if newMask.Count() != 1 || newMask.IsSet(cpu) {
  242. t.Errorf("CpuClr: didn't clear CPU %d in set: %v", cpu, newMask)
  243. }
  244. if runtime.NumCPU() < 2 {
  245. t.Skip("skipping setaffinity tests on single CPU system")
  246. }
  247. if runtime.GOOS == "android" {
  248. t.Skip("skipping setaffinity tests on android")
  249. }
  250. // On a system like ppc64x where some cores can be disabled using ppc64_cpu,
  251. // setaffinity should only be called with enabled cores. The valid cores
  252. // are found from the oldMask, but if none are found then the setaffinity
  253. // tests are skipped. Issue #27875.
  254. if !oldMask.IsSet(cpu) {
  255. newMask.Zero()
  256. for i := 0; i < len(oldMask); i++ {
  257. if oldMask.IsSet(i) {
  258. newMask.Set(i)
  259. break
  260. }
  261. }
  262. if newMask.Count() == 0 {
  263. t.Skip("skipping setaffinity tests if CPU not available")
  264. }
  265. }
  266. err = unix.SchedSetaffinity(0, &newMask)
  267. if err != nil {
  268. t.Fatalf("SchedSetaffinity: %v", err)
  269. }
  270. var gotMask unix.CPUSet
  271. err = unix.SchedGetaffinity(0, &gotMask)
  272. if err != nil {
  273. t.Fatalf("SchedGetaffinity: %v", err)
  274. }
  275. if gotMask != newMask {
  276. t.Errorf("SchedSetaffinity: returned affinity mask does not match set affinity mask")
  277. }
  278. // Restore old mask so it doesn't affect successive tests
  279. err = unix.SchedSetaffinity(0, &oldMask)
  280. if err != nil {
  281. t.Fatalf("SchedSetaffinity: %v", err)
  282. }
  283. }
  284. func TestStatx(t *testing.T) {
  285. var stx unix.Statx_t
  286. err := unix.Statx(unix.AT_FDCWD, ".", 0, 0, &stx)
  287. if err == unix.ENOSYS || err == unix.EPERM {
  288. t.Skip("statx syscall is not available, skipping test")
  289. } else if err != nil {
  290. t.Fatalf("Statx: %v", err)
  291. }
  292. defer chtmpdir(t)()
  293. touch(t, "file1")
  294. var st unix.Stat_t
  295. err = unix.Stat("file1", &st)
  296. if err != nil {
  297. t.Fatalf("Stat: %v", err)
  298. }
  299. flags := unix.AT_STATX_SYNC_AS_STAT
  300. err = unix.Statx(unix.AT_FDCWD, "file1", flags, unix.STATX_ALL, &stx)
  301. if err != nil {
  302. t.Fatalf("Statx: %v", err)
  303. }
  304. if uint32(stx.Mode) != st.Mode {
  305. t.Errorf("Statx: returned stat mode does not match Stat")
  306. }
  307. ctime := unix.StatxTimestamp{Sec: int64(st.Ctim.Sec), Nsec: uint32(st.Ctim.Nsec)}
  308. mtime := unix.StatxTimestamp{Sec: int64(st.Mtim.Sec), Nsec: uint32(st.Mtim.Nsec)}
  309. if stx.Ctime != ctime {
  310. t.Errorf("Statx: returned stat ctime does not match Stat")
  311. }
  312. if stx.Mtime != mtime {
  313. t.Errorf("Statx: returned stat mtime does not match Stat")
  314. }
  315. err = os.Symlink("file1", "symlink1")
  316. if err != nil {
  317. t.Fatal(err)
  318. }
  319. err = unix.Lstat("symlink1", &st)
  320. if err != nil {
  321. t.Fatalf("Lstat: %v", err)
  322. }
  323. err = unix.Statx(unix.AT_FDCWD, "symlink1", flags, unix.STATX_BASIC_STATS, &stx)
  324. if err != nil {
  325. t.Fatalf("Statx: %v", err)
  326. }
  327. // follow symlink, expect a regulat file
  328. if stx.Mode&unix.S_IFREG == 0 {
  329. t.Errorf("Statx: didn't follow symlink")
  330. }
  331. err = unix.Statx(unix.AT_FDCWD, "symlink1", flags|unix.AT_SYMLINK_NOFOLLOW, unix.STATX_ALL, &stx)
  332. if err != nil {
  333. t.Fatalf("Statx: %v", err)
  334. }
  335. // follow symlink, expect a symlink
  336. if stx.Mode&unix.S_IFLNK == 0 {
  337. t.Errorf("Statx: unexpectedly followed symlink")
  338. }
  339. if uint32(stx.Mode) != st.Mode {
  340. t.Errorf("Statx: returned stat mode does not match Lstat")
  341. }
  342. ctime = unix.StatxTimestamp{Sec: int64(st.Ctim.Sec), Nsec: uint32(st.Ctim.Nsec)}
  343. mtime = unix.StatxTimestamp{Sec: int64(st.Mtim.Sec), Nsec: uint32(st.Mtim.Nsec)}
  344. if stx.Ctime != ctime {
  345. t.Errorf("Statx: returned stat ctime does not match Lstat")
  346. }
  347. if stx.Mtime != mtime {
  348. t.Errorf("Statx: returned stat mtime does not match Lstat")
  349. }
  350. }
  351. // stringsFromByteSlice converts a sequence of attributes to a []string.
  352. // On Linux, each entry is a NULL-terminated string.
  353. func stringsFromByteSlice(buf []byte) []string {
  354. var result []string
  355. off := 0
  356. for i, b := range buf {
  357. if b == 0 {
  358. result = append(result, string(buf[off:i]))
  359. off = i + 1
  360. }
  361. }
  362. return result
  363. }
  364. func TestFaccessat(t *testing.T) {
  365. defer chtmpdir(t)()
  366. touch(t, "file1")
  367. err := unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, 0)
  368. if err != nil {
  369. t.Errorf("Faccessat: unexpected error: %v", err)
  370. }
  371. err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, 2)
  372. if err != unix.EINVAL {
  373. t.Errorf("Faccessat: unexpected error: %v, want EINVAL", err)
  374. }
  375. err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, unix.AT_EACCESS)
  376. if err != nil {
  377. t.Errorf("Faccessat: unexpected error: %v", err)
  378. }
  379. err = os.Symlink("file1", "symlink1")
  380. if err != nil {
  381. t.Fatal(err)
  382. }
  383. err = unix.Faccessat(unix.AT_FDCWD, "symlink1", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
  384. if err != nil {
  385. t.Errorf("Faccessat SYMLINK_NOFOLLOW: unexpected error %v", err)
  386. }
  387. // We can't really test AT_SYMLINK_NOFOLLOW, because there
  388. // doesn't seem to be any way to change the mode of a symlink.
  389. // We don't test AT_EACCESS because such tests are only
  390. // meaningful if run as root.
  391. err = unix.Fchmodat(unix.AT_FDCWD, "file1", 0, 0)
  392. if err != nil {
  393. t.Errorf("Fchmodat: unexpected error %v", err)
  394. }
  395. err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.F_OK, unix.AT_SYMLINK_NOFOLLOW)
  396. if err != nil {
  397. t.Errorf("Faccessat: unexpected error: %v", err)
  398. }
  399. err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
  400. if err != unix.EACCES {
  401. if unix.Getuid() != 0 {
  402. t.Errorf("Faccessat: unexpected error: %v, want EACCES", err)
  403. }
  404. }
  405. }
  406. func TestSyncFileRange(t *testing.T) {
  407. file, err := ioutil.TempFile("", "TestSyncFileRange")
  408. if err != nil {
  409. t.Fatal(err)
  410. }
  411. defer os.Remove(file.Name())
  412. defer file.Close()
  413. err = unix.SyncFileRange(int(file.Fd()), 0, 0, 0)
  414. if err == unix.ENOSYS || err == unix.EPERM {
  415. t.Skip("sync_file_range syscall is not available, skipping test")
  416. } else if err != nil {
  417. t.Fatalf("SyncFileRange: %v", err)
  418. }
  419. // invalid flags
  420. flags := 0xf00
  421. err = unix.SyncFileRange(int(file.Fd()), 0, 0, flags)
  422. if err != unix.EINVAL {
  423. t.Fatalf("SyncFileRange: unexpected error: %v, want EINVAL", err)
  424. }
  425. }
  426. func TestClockNanosleep(t *testing.T) {
  427. delay := 100 * time.Millisecond
  428. // Relative timespec.
  429. start := time.Now()
  430. rel := unix.NsecToTimespec(delay.Nanoseconds())
  431. err := unix.ClockNanosleep(unix.CLOCK_MONOTONIC, 0, &rel, nil)
  432. if err == unix.ENOSYS || err == unix.EPERM {
  433. t.Skip("clock_nanosleep syscall is not available, skipping test")
  434. } else if err != nil {
  435. t.Errorf("ClockNanosleep(CLOCK_MONOTONIC, 0, %#v, nil) = %v", &rel, err)
  436. } else if slept := time.Now().Sub(start); slept < delay {
  437. t.Errorf("ClockNanosleep(CLOCK_MONOTONIC, 0, %#v, nil) slept only %v", &rel, slept)
  438. }
  439. // Absolute timespec.
  440. start = time.Now()
  441. until := start.Add(delay)
  442. abs := unix.NsecToTimespec(until.UnixNano())
  443. err = unix.ClockNanosleep(unix.CLOCK_REALTIME, unix.TIMER_ABSTIME, &abs, nil)
  444. if err != nil {
  445. t.Errorf("ClockNanosleep(CLOCK_REALTIME, TIMER_ABSTIME, %#v (=%v), nil) = %v", &abs, until, err)
  446. } else if slept := time.Now().Sub(start); slept < delay {
  447. t.Errorf("ClockNanosleep(CLOCK_REALTIME, TIMER_ABSTIME, %#v (=%v), nil) slept only %v", &abs, until, slept)
  448. }
  449. // Invalid clock. clock_nanosleep(2) says EINVAL, but it’s actually EOPNOTSUPP.
  450. err = unix.ClockNanosleep(unix.CLOCK_THREAD_CPUTIME_ID, 0, &rel, nil)
  451. if err != unix.EINVAL && err != unix.EOPNOTSUPP {
  452. t.Errorf("ClockNanosleep(CLOCK_THREAD_CPUTIME_ID, 0, %#v, nil) = %v, want EINVAL or EOPNOTSUPP", &rel, err)
  453. }
  454. }
  455. func TestOpenByHandleAt(t *testing.T) {
  456. skipIfNotSupported := func(t *testing.T, name string, err error) {
  457. if err == unix.EPERM {
  458. t.Skipf("skipping %s test without CAP_DAC_READ_SEARCH", name)
  459. }
  460. if err == unix.ENOSYS {
  461. t.Skipf("%s system call not available", name)
  462. }
  463. if err == unix.EOPNOTSUPP {
  464. t.Skipf("%s not supported on this filesystem", name)
  465. }
  466. }
  467. h, mountID, err := unix.NameToHandleAt(unix.AT_FDCWD, "syscall_linux_test.go", 0)
  468. if err != nil {
  469. skipIfNotSupported(t, "name_to_handle_at", err)
  470. t.Fatalf("NameToHandleAt: %v", err)
  471. }
  472. t.Logf("mountID: %v, handle: size=%d, type=%d, bytes=%q", mountID,
  473. h.Size(), h.Type(), h.Bytes())
  474. mount, err := openMountByID(mountID)
  475. if err != nil {
  476. t.Fatalf("openMountByID: %v", err)
  477. }
  478. defer mount.Close()
  479. for _, clone := range []bool{false, true} {
  480. t.Run("clone="+strconv.FormatBool(clone), func(t *testing.T) {
  481. if clone {
  482. h = unix.NewFileHandle(h.Type(), h.Bytes())
  483. }
  484. fd, err := unix.OpenByHandleAt(int(mount.Fd()), h, unix.O_RDONLY)
  485. skipIfNotSupported(t, "open_by_handle_at", err)
  486. if err != nil {
  487. t.Fatalf("OpenByHandleAt: %v", err)
  488. }
  489. defer unix.Close(fd)
  490. t.Logf("opened fd %v", fd)
  491. f := os.NewFile(uintptr(fd), "")
  492. slurp, err := ioutil.ReadAll(f)
  493. if err != nil {
  494. t.Fatal(err)
  495. }
  496. const substr = "Some substring for a test."
  497. if !strings.Contains(string(slurp), substr) {
  498. t.Errorf("didn't find substring %q in opened file; read %d bytes", substr, len(slurp))
  499. }
  500. })
  501. }
  502. }
  503. func openMountByID(mountID int) (f *os.File, err error) {
  504. mi, err := os.Open("/proc/self/mountinfo")
  505. if err != nil {
  506. return nil, err
  507. }
  508. defer mi.Close()
  509. bs := bufio.NewScanner(mi)
  510. wantPrefix := []byte(fmt.Sprintf("%v ", mountID))
  511. for bs.Scan() {
  512. if !bytes.HasPrefix(bs.Bytes(), wantPrefix) {
  513. continue
  514. }
  515. fields := strings.Fields(bs.Text())
  516. dev := fields[4]
  517. return os.Open(dev)
  518. }
  519. if err := bs.Err(); err != nil {
  520. return nil, err
  521. }
  522. return nil, errors.New("mountID not found")
  523. }