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