3d067b255d73c1b54e9acdf0fb07f785c520a1dc
2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
18 #include <sys/types.h>
29 #include "libblkid-tiny.h"
33 static char buf
[PATH_MAX
];
34 static char buf2
[PATH_MAX
];
35 static unsigned int mode
= 0600;
37 static void make_dev(const char *path
, bool block
, int major
, int minor
)
39 unsigned int _mode
= mode
| (block
? S_IFBLK
: S_IFCHR
);
41 mknod(path
, _mode
, makedev(major
, minor
));
44 static void find_devs(bool block
)
46 char *path
= block
? "/sys/dev/block" : "/sys/dev/char";
54 path
= buf2
+ sprintf(buf2
, "%s/", path
);
55 while ((dp
= readdir(dir
)) != NULL
) {
57 int major
= 0, minor
= 0;
60 if (dp
->d_type
!= DT_LNK
)
63 if (sscanf(dp
->d_name
, "%d:%d", &major
, &minor
) != 2)
66 strcpy(path
, dp
->d_name
);
67 len
= readlink(buf2
, buf
, sizeof(buf
));
73 c
= strrchr(buf
, '/');
79 make_dev(c
, block
, major
, minor
);