updated .gitignore
[kvm-coreboot.git] / packages / kexec-boot-loader / makedevs.patch
blob4d42ec00a6d38a5c528f88d817012bf6e1568065
1 Index: kexec-boot-loader/main.c
2 ===================================================================
3 --- kexec-boot-loader.orig/main.c 2006-06-26 21:41:34.000000000 -0600
4 +++ kexec-boot-loader/main.c 2006-06-26 21:48:21.000000000 -0600
5 @@ -1,5 +1,8 @@
6 #include <stdio.h>
7 #include <sys/mount.h>
8 +#include <sys/stat.h>
9 +#include <fcntl.h>
10 +#include <unistd.h>
11 #include <errno.h>
12 #include "ui.h"
13 #include "mount.h"
14 @@ -20,6 +23,77 @@
15 return do_mount(0, "/proc", "proc");
18 +#define iseol(_c) ((_c == '\n') || (_c == 0))
19 +#define isspace(_c) ((_c == ' ') || (_c == '\t'))
21 +/* Make a series of devices based on a file (the same format as makedevs) */
23 +int makedevs(const char *filename) {
25 + char *argv[10];
26 + char buffer[128];
28 + int i;
29 + FILE *stream = fopen(filename, "r");
31 + if (stream == NULL)
32 + return -1;
34 + while(!feof(stream)) {
35 + char *str = fgets(buffer, sizeof(buffer) - 1, stream);
37 + if (str == NULL)
38 + continue;
40 + for(i = 0; i < 10; i++) {
41 + argv[i] = str;
42 + for( ; !isspace(*str) && !iseol(*str); str++);
44 + if (iseol(*str))
45 + break;
47 + *str++ = 0;
49 + for( ;isspace(*str) && !iseol(*str); str++);
51 + if (iseol(*str))
52 + break;
53 + }
55 + /* The first 4 columns need to be there */
57 + if (i < 2)
58 + continue;
60 + /* Note - everything is created as 0 0, regardless of what is specified */
62 + if (*argv[1] == 'd' ) {
63 + mode_t mode = atoi(argv[2]);
64 + if (mkdir(argv[0], mode))
65 + print("Couldn't make directory %s\n", argv[0]);
66 + }
67 + else if (*argv[1] == 'c' || *argv[1] == 'b') {
68 + if (i >= 6) {
69 + mode_t mode = atoi(argv[2]);
71 + int major = atoi(argv[5]);
72 + int minor = atoi(argv[6]);
74 + if (*argv[2] == 'b')
75 + mode |= S_IFBLK;
76 + else
77 + mode |= S_IFCHR;
79 + if (mknod(argv[0], mode, major << 8 | minor))
80 + print("Couldn't make nod %s(%d,%d)\n", argv[0], major, minor);
81 + }
82 + }
83 + }
85 + fclose(stream);
86 + return 0;
89 int main (void)
91 int ret;
92 @@ -27,6 +101,7 @@
93 print("Kexec boot loader\n\n");
95 mount_proc();
96 + makedevs("/device.txt");
98 create_mountpath(mntpoint);