gopkg.in/hugelgupf/u-root.v9@v9.0.0-20180831063832-3f6f1057f09b/cmds/mknod/mknod_linux_test.go (about) 1 // Copyright 2018 the u-root 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 5 package main 6 7 import ( 8 "io/ioutil" 9 "os" 10 "os/user" 11 "path/filepath" 12 "testing" 13 14 "github.com/u-root/u-root/pkg/testutil" 15 "golang.org/x/sys/unix" 16 ) 17 18 // Test major and minor numbers greater then 255. 19 // 20 // This is supported since Linux 2.6. The major/minor numbers used for this 21 // test are (1110, 74616). According to "kdev_t.h": 22 // 23 // mkdev(1110, 74616) 24 // = mkdev(0x456, 0x12378) 25 // = (0x12378 & 0xff) | (0x456 << 8) | ((0x12378 & ~0xff) << 12) 26 // = 0x12345678 27 func TestLargeDevNumber(t *testing.T) { 28 if user, err := user.Current(); err != nil || user.Uid != "0" { 29 t.Skip("test requires root.") 30 } 31 32 // Make a temporary directory. 33 tmpDir, err := ioutil.TempDir("", "ls") 34 if err != nil { 35 t.Fatal(err) 36 } 37 defer os.RemoveAll(tmpDir) 38 file := filepath.Join(tmpDir, "large_node") 39 40 // Run "mknod large_node b 1110 74616". 41 err = testutil.Command(t, file, "b", "1110", "74616").Run() 42 if err != nil { 43 t.Fatal(err) 44 } 45 46 // Check the device number. 47 var s unix.Stat_t 48 err = unix.Stat(file, &s) 49 if err != nil { 50 t.Fatal(err) 51 } 52 if s.Rdev != 0x12345678 { 53 t.Fatalf("expected the device number to be 0x12345678, got %#x", s.Rdev) 54 } 55 }