getvfsbyname.c (ea8d448a923f0d68d7ecf1d2a0583c7d17bdee4e) getvfsbyname.c (5965373e69ca208cedd8ede9716ef0d58e6c3434)
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 27 unchanged lines hidden (view full) ---

36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include <sys/param.h>
41#include <sys/mount.h>
42#include <sys/sysctl.h>
43#include <errno.h>
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 27 unchanged lines hidden (view full) ---

36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include <sys/param.h>
41#include <sys/mount.h>
42#include <sys/sysctl.h>
43#include <errno.h>
44#include <stdlib.h>
45#include <string.h>
44
45/*
46 * Given a filesystem name, determine if it is resident in the kernel,
46
47/*
48 * Given a filesystem name, determine if it is resident in the kernel,
47 * and if it is resident, return its vfsconf structure.
49 * and if it is resident, return its xvfsconf structure.
48 */
50 */
51int
49getvfsbyname(fsname, vfcp)
50 const char *fsname;
52getvfsbyname(fsname, vfcp)
53 const char *fsname;
51 struct vfsconf *vfcp;
54 struct xvfsconf *vfcp;
52{
53#ifdef __NETBSD_SYSCALLS
54 errno = ENOSYS;
55#else
55{
56#ifdef __NETBSD_SYSCALLS
57 errno = ENOSYS;
58#else
56 int name[4], maxtypenum, cnt;
59 struct xvfsconf *xvfsp;
57 size_t buflen;
60 size_t buflen;
61 int cnt, i;
58
62
59 name[0] = CTL_VFS;
60 name[1] = VFS_GENERIC;
61 name[2] = VFS_MAXTYPENUM;
62 buflen = 4;
63 if (sysctl(name, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0)
63 if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
64 return (-1);
64 return (-1);
65 name[2] = VFS_CONF;
66 buflen = sizeof *vfcp;
67 for (cnt = 0; cnt < maxtypenum; cnt++) {
68 name[3] = cnt;
69 if (sysctl(name, 4, vfcp, &buflen, (void *)0, (size_t)0) < 0) {
70 if (errno != EOPNOTSUPP)
71 return (-1);
72 continue;
73 }
74 if (!strcmp(fsname, vfcp->vfc_name))
65 xvfsp = malloc(buflen);
66 if (xvfsp == NULL)
67 return (-1);
68 if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) {
69 free(xvfsp);
70 return (-1);
71 }
72 cnt = buflen / sizeof(struct xvfsconf);
73 for (i = 0; i < cnt; i++) {
74 if (strcmp(fsname, xvfsp[i].vfc_name) == 0) {
75 memcpy(vfcp, xvfsp + i, sizeof(struct xvfsconf));
76 free(xvfsp);
75 return (0);
77 return (0);
78 }
76 }
79 }
80 free(xvfsp);
77 errno = ENOENT;
78#endif
79 return (-1);
80}
81 errno = ENOENT;
82#endif
83 return (-1);
84}