Add per-device polling support.
[dragonfly.git] / release / sysinstall / dev2c.sh
1 :
2 #
3 # ----------------------------------------------------------------------------
4 # "THE BEER-WARE LICENSE" (Revision 42):
5 # <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
6 # can do whatever you want with this stuff. If we meet some day, and you think
7 # this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
8 # ----------------------------------------------------------------------------
9 #
10 # $FreeBSD: src/release/sysinstall/dev2c.sh,v 1.4.2.1 2002/07/02 21:27:28 jhb Exp $
11 # $DragonFly: src/release/sysinstall/Attic/dev2c.sh,v 1.2 2003/06/17 04:27:21 dillon Exp $
12 #
13 # During installation, we suffer badly of we have to run MAKEDEV.  MAKEDEV
14 # need sh, ln, chown, mknod, awk, rm, test and probably emacs too when
15 # we come down to it.  So instead this script will make a C-procedure which
16 # makes all the B & C nodes of a specified directory.
17 #
18 # Poul-Henning
19
20 (cd $1; ls -li ) | sed 's/,//' | awk '
21 BEGIN   {
22         while (getline < "/etc/passwd") {
23                 split($0,a,":")
24                 uid[a[1]] = a[3]
25         }
26         while (getline < "/etc/group") {
27                 split($0,a,":")
28                 gid[a[1]] = a[3]
29         }
30         printf("/*\n");
31         printf(" * This file is generated from the contents of /dev\n");
32         printf(" */\n");
33         printf("#define CHK(foo) {i = foo;}\n");
34         printf("#include <unistd.h>\n");
35         printf("#include <sys/types.h>\n");
36         printf("#include <sys/stat.h>\n");
37         printf("int makedevs()\n{\n\tint i=0;\n");
38         }
39         {
40         printf ("/* %s */\n",$0)
41         $4 = uid[$4]
42         $5 = gid[$5]
43         if (substr($2,1,1) == "b") {
44                 k="S_IFBLK"
45         } else if (substr($2,1,1) == "c") {
46                 k="S_IFCHR"
47         } else if (substr($2,1,1) == "d") {
48                 next
49         } else if (substr($2,1,1) == "-") {
50                 next
51         } else {
52                 next
53         }
54         m = 0;
55         if (substr($2,2,1)  == "r") m += 400;
56         if (substr($2,3,1)  == "w") m += 200;
57         if (substr($2,4,1)  == "x") m += 100;
58         if (substr($2,5,1)  == "r") m += 40;
59         if (substr($2,6,1)  == "w") m += 20;
60         if (substr($2,7,1)  == "x") m += 10;
61         if (substr($2,8,1)  == "r") m += 4;
62         if (substr($2,9,1)  == "w") m += 2;
63         if (substr($2,10,1) == "x") m += 1;
64         
65         if (a[$1] != 0) {
66                 printf ("\tCHK(link(\"%s\",\"%s\"));\n", \
67                         a[$1],$11)
68         } else {
69                 printf ("\tCHK(mknod(\"%s\",%s,makedev(%d,%d)));\n", \
70                         $11, k, $6, $7)
71                 printf ("\tCHK(chmod(\"%s\",0%d));\n", \
72                         $11, m)
73                 printf ("\tCHK(chown(\"%s\",%d,%d));\n", \
74                         $11, $4,$5)
75                 a[$1] = $11
76         }
77         }
78 END     {
79         printf("\treturn i;\n}\n");
80         }
81 '