File ash-1.6.1-suse.initrd.diff of Package ash
--- builtins.def
+++ builtins.def
@@ -91,3 +91,5 @@
#exprcmd expr
raidautoruncmd raidautorun
+createpartitiondevscmd createpartitiondevs
+devnumbercmd devnumber
--- miscbltin.c
+++ miscbltin.c
@@ -430,3 +427,80 @@
}
}
+static void mkdir_p(char *dir) {
+ struct stat stb;
+ char *p;
+
+ if ((p = strrchr(dir, '/')) == 0)
+ return;
+ *p = 0;
+ if (*dir && stat(dir, &stb) == -1)
+ mkdir_p(dir);
+ *p = '/';
+ mkdir(dir, 0755);
+}
+
+createpartitiondevscmd(argc, argv) char **argv; {
+ char line[1024], c, *lp, *l[4], *p;
+ char buf[4096], *bufp = 0;
+ int nl, bufl;
+ dev_t dev;
+ struct stat stb;
+
+ int fd = open("/proc/partitions", O_RDONLY);
+ if (fd < 0)
+ error("/proc/partitions: %s", errmsg(errno, E_OPEN));
+ for (lp = line, nl = 0, bufl = 0;;) {
+ if (bufl == 0) {
+ if ((bufl = read(fd, buf, sizeof(buf))) <= 0)
+ break;
+ bufp = buf;
+ }
+ c = *bufp++;
+ bufl--;
+ if (c == ' ' || c == '\t')
+ c = 0;
+ if (c != '\n') {
+ if (c && nl < 4 && (lp == line || lp[-1] == 0))
+ l[nl++] = lp;
+ if (lp < line + sizeof(line) - 1)
+ *lp++ = c;
+ continue;
+ }
+ if (lp < line + sizeof(line) - 1 && nl == 4 && l[3] >= line + 5) {
+ *lp = 0;
+ lp = l[3];
+ nl = strlen(lp);
+ if (nl > 0 && (lp[nl - 1] >= '0' && lp[nl - 1] <= '9')) {
+ p = strrchr(lp, '/');
+ dev = makedev(atoi(l[0]), atoi(l[1]));
+ lp -= 5;
+ strncpy(lp, "/dev/", 5);
+ if (stat(lp, &stb) < 0) {
+ if (p) {
+ *p = 0;
+ mkdir_p(lp);
+ *p = '/';
+ }
+ mknod(lp, S_IFBLK | 0600, dev);
+ }
+ }
+ }
+ lp = line;
+ nl = 0;
+ }
+ close(fd);
+}
+
+devnumbercmd(argc, argv) char **argv; {
+ struct stat stb;
+
+ if (argc != 2)
+ error("arg count");
+ if (stat(argv[1], &stb))
+ error("%s: %s", argv[1], errmsg(errno, E_OPEN));
+ if (!S_ISCHR(stb.st_mode) && !S_ISBLK(stb.st_mode))
+ error("%s: not a device", argv[1]);
+ printf("%lu\n", (unsigned long)stb.st_rdev);
+}
+