summaryrefslogtreecommitdiffstats
path: root/command-stubs/mknod-stub
blob: bc14c5bd0a1c0ec6551e38b3e5c377486859e2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python

import sys, os
sys.path.append('/usr/lib/anaconda')
import isys
import string
import stat
import os

def usage():
    sys.stderr.write("Usage: %s <path> [b|c] <major> <minor> or\n" %(sys.argv[0],))
    sys.stderr.write("Usage: %s <path>\n" %(sys.argv[0],))
    sys.exit(1)

def main():
    if len(sys.argv) < 2:
        usage()

    if (sys.argv[1] == '-h') or (sys.argv[1] == '--help'):
        usage()

    path = sys.argv[1]
    if (len(sys.argv) == 2):
        drive = path
        # strip off any path elements up until what's useful for making the
        # inode
        while (drive.find('/') != -1):
            if (drive.startswith("cciss") or drive.startswith("ida") or
                drive.startswith("rd") or drive.startswith("ataraid")
                or drive.startswith("iseries") or drive.startswith("i2o")
                or drive.startswith("sx8")):
                break
            drive = drive[drive.find('/') + 1:]
        isys.makeDevInode(drive, path)
        sys.exit(0)

    if len(sys.argv) < 5:
        usage()

    if (sys.argv[2] == 'b'):
        type = stat.S_IFBLK
    elif (sys.argv[2] == 'c'):
        type = stat.S_IFCHR
    else:
        usage()

    major = int(sys.argv[3])
    minor = int(sys.argv[4])
    path = sys.argv[1]
    
    os.mknod(path, 0644 | type, os.makedev(major, minor))

if __name__ == "__main__":
    main()