Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / netbsd / dev.c
blobd7e37a2dfc5d415db28ad6c5698f28d69e431260
1 /* $NetBSD: dev.c,v 1.1 2008/12/22 00:56:59 haad Exp $ */
3 /*
4 * NetBSD specific device routines are added to this file.
5 */
7 #include <sys/param.h>
8 #include <sys/types.h>
10 #include <sys/sysctl.h>
12 #include <dirent.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <ctype.h>
17 #include <fcntl.h>
18 #include <limits.h>
20 #include "netbsd.h"
22 #define LVM_FAILURE -1
25 * Find major numbers for char/block parts of all block devices.
26 * In NetBSD every block device has it's char counter part.
27 * Return success only for device drivers with defined char/block
28 * major numbers.
30 int
31 nbsd_check_dev(int major, const char *path)
34 size_t val_len,i;
36 struct kinfo_drivers *kd;
38 /* XXX HACK */
39 if (strcmp(path,"/dev/console") == 0)
40 return LVM_FAILURE;
42 /* get size kernel drivers array from kernel*/
43 if (sysctlbyname("kern.drivers",NULL,&val_len,NULL,0) < 0) {
44 printf("sysctlbyname failed");
45 return LVM_FAILURE;
48 if ((kd = malloc (val_len)) == NULL){
49 printf("malloc kd info error\n");
50 return LVM_FAILURE;
53 /* get array from kernel */
54 if (sysctlbyname("kern.drivers", kd, &val_len, NULL, 0) < 0) {
55 printf("sysctlbyname failed kd");
56 return LVM_FAILURE;
59 for (i = 0, val_len /= sizeof(*kd); i < val_len; i++)
60 /* We select only devices with correct char/block major number. */
61 if (kd[i].d_cmajor != -1 && kd[i].d_bmajor != -1) {
63 if (kd[i].d_cmajor == major)
64 return 0;
67 return LVM_FAILURE;