summaryrefslogtreecommitdiffstats
path: root/lib/libautofs
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2004-08-31 16:26:01 +0000
committeralfred <alfred@FreeBSD.org>2004-08-31 16:26:01 +0000
commite39e879ede3eb48cca848118af6f9fb6435c7241 (patch)
tree9b36a14c0b5776cc37fcd05bce3ca649ad5374ea /lib/libautofs
parent07c612deeed1a0a85162274839c59b67c9aa472a (diff)
downloadFreeBSD-src-e39e879ede3eb48cca848118af6f9fb6435c7241.zip
FreeBSD-src-e39e879ede3eb48cca848118af6f9fb6435c7241.tar.gz
Enter the autofs.
Diffstat (limited to 'lib/libautofs')
-rw-r--r--lib/libautofs/Makefile14
-rw-r--r--lib/libautofs/libautofs.3238
-rw-r--r--lib/libautofs/libautofs.c465
-rw-r--r--lib/libautofs/libautofs.h103
4 files changed, 820 insertions, 0 deletions
diff --git a/lib/libautofs/Makefile b/lib/libautofs/Makefile
new file mode 100644
index 0000000..92945c9
--- /dev/null
+++ b/lib/libautofs/Makefile
@@ -0,0 +1,14 @@
+# $Id: Makefile,v 1.3 2004/08/31 08:49:56 bright Exp $
+# $FreeBSD$
+
+LIB=autofs
+SHLIB_MAJOR= 1
+SHLIB_MINOR= 0
+WARNS=4
+CFLAGS+= -I${.CURDIR}/../autofs -Werror
+CFLAGS+= -g
+
+SRCS= libautofs.c
+MAN+= libautofs.3
+
+.include <bsd.lib.mk>
diff --git a/lib/libautofs/libautofs.3 b/lib/libautofs/libautofs.3
new file mode 100644
index 0000000..2875c06
--- /dev/null
+++ b/lib/libautofs/libautofs.3
@@ -0,0 +1,238 @@
+.\" Copyright (c) 2004 Alfred Perlstein <alfred@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $Id: libautofs.3,v 1.3 2004/08/31 15:58:40 bright Exp $
+.\" $FreeBSD$
+.Dd August 30, 2004
+.Dt LIBAUTOFS 3
+.Os
+.Sh NAME
+.Nm libautofs
+.Nd "procedural interface to managing an autofs filesystem"
+.Sh SYNOPSIS
+.In libautofs.h
+.Ft int
+.Fn autoh_get "const char *path" "autoh_t *hndlp"
+.Ft void
+.Fn autoh_free "autoh_t hndl"
+.Ft int
+.Fn autoh_getall "autoh_t **hndlpp" "int *cnt"
+.Ft void
+.Fn autoh_freeall "autoh_t *hndlep"
+.Ft int
+.Fn autoh_fd "autoh_t hndl"
+.Ft const char *
+.Fn autoh_mp "autoh_t hndl"
+.Ft int
+.Fn autoreq_get "autoh_t hndl" "autoreq_t **reqpp" "int *cntp"
+.Ft void
+.Fn autoreq_free "autoh_t hndl" "autoreq_t *reqp"
+.Ft int
+.Fn autoreq_serv "autoh_t hndl" "autoreq_t req"
+.Ft enum autoreq_op
+.Fn autoreq_getop "autoreq_t req"
+.Ft const char *
+.Fn autoreq_getpath "autoreq_t req"
+.Ft autoino_t
+.Fn autoreq_getino "autoreq_t req"
+.Ft autoino_t
+.Fn autoreq_getdirino "autoreq_t req"
+.Ft void
+.Fn autoreq_getaux "autoreq_t req" "void **auxdatap" "size_t *auxsizep"
+.Ft void
+.Fn autoreq_getoffset "autoreq_t req" "off_t *offp"
+.Ft void
+.Fn autoreq_setino "autoreq_t req" "autoino_t ino"
+.Ft void
+.Fn autoreq_seterrno "autoreq_t req" "int errno"
+.Ft void
+.Fn autoreq_setaux "autoreq_t req" "void *auxdata" "size_t auxsize"
+.Ft void
+.Fn autoreq_seteof "autoreq_t req" "int eof"
+.Ft int
+.Fn autoh_togglepath "autoh_t hndl" "int toggle" "pid_t pid" "const char *path"
+.Ft int
+.Fn autoh_togglefd "autoh_t hndl" "int toggle" "pid_t pid" "int fd"
+.Sh DESCRIPTION
+The
+.Nm libautofs
+libarary provides a "mostly" stable interface to the
+.Xr autofs 9
+filesystem.
+.Pp
+The inteface to
+.Xr autofs 9
+is managed via handles of type
+.Fa autoh_t
+and
+.Fa autoreq_t
+which refer to handles to
+.Xr autofs 9
+mount points and requests respectively.
+.Pp
+The
+.Fn autoh_get
+function returns a handle to an
+.Xr autofs 9
+filesystem based on the
+.Fn path
+parameter.
+The handle returned should be freed via the
+.Fn autoh_free
+function.
+.Pp
+The
+.Fn autoh_getall
+function returns an array of handles to all mounted
+.Xr autofs 9
+filesystems, each of which should be released via the
+.Fn autoh_free
+function or released en-mass via the
+.Fn autoh_freeall
+function.
+.Pp
+The
+.Fn autoh_fd
+function returns a file descriptor that can selected or polled on
+for "excecption" data to detect an
+.Xr autofs 9
+event.
+.Pp
+The
+.Fn autoh_mp
+function returns the path to the autofs filesystem that the
+.Fa hndl
+is derived from.
+.Pp
+The
+.Fn autoreq_get
+function returns an array of autofs requests in
+.Fa reqpp ,
+the number of requests is stored into
+.Fa cntp .
+Each request should be released using the
+.Fn autoreq_free
+function.
+.Pp
+Requests that are retrieved via the
+.Fn autoreq_get
+are served via the "autoreq_" functions.
+.Pp
+The following functions returns information about the request.
+.Bl -tag -width indent
+.It Fn autoreq_getop
+return the operation type of the request, that would be one of
+AUTOREQ_OP_UNKNOWN, AUTOREQ_OP_LOOKUP, AUTOREQ_OP_STAT, AUTOREQ_OP_READDIR
+depending on the type of request that
+.Xr autofs 9
+requires service from.
+.It Fn autoreq_getpath
+return the path of the mountpoint associated with the request
+.Fa req .
+.It Fn autoreq_getino
+return the inode associated with the request
+.Fa req .
+.It Fn autoreq_getdirno
+return the directory inode associated with the request
+.Fa req .
+.It Fn autoreq_getaux
+return the auxilliray data associated with the request
+.Fa req .
+.It Fn autoreq_getoffset
+return the offset request associated with the request
+.Fa req .
+(used for readdir request)
+.El
+.Pp
+The following functions allow one to set the response sent to
+.Xr autofs 9
+to the requesting userland application.
+.Bl -tag -width indent
+.It Fn autoreq_setino
+Set the request
+.Fa req
+inode to
+.Fa ino ,
+this is typically unused.
+.It Fn autoreq_seterrno
+set the error returned to the application sending the request, typically
+this is left alone, or set to ENOENT if the request is for a non-existant
+name. The default error is no error. Meaning the application will see
+a successful return.
+.It Fn autoreq_setaux
+used to set the auxilliray data for a request, currently used to set
+the dirent structures for serving a readdir request. Default is no
+auxilliary data.
+.It Fn autoreq_seteof
+used to set the eof flag for readdir requests (default is not eof.)
+.El
+.Pp
+The functions
+.Fn autoh_togglepath
+and
+.Fn autoh_togglefd
+are used to set options on an
+.Xr autofs 9
+directory via
+.Fa path
+and
+.Fa fd
+respectively. The
+.Fa pid
+argument should be set to the pid of the process serving
+.Xr autofs 9
+requests, or -1 to disable the option. The options are
+.Bl -tag -width AUTO_INDIRECT
+.It Fa AUTO_MOUNTER
+set this process as the one responsible for the
+.Xr autofs 9
+node, if this process exits, then requests into the autofs will begin to fail.
+.It Fa AUTO_BROWSE
+dispatch directory read requests for this node to the process identified by
+.Fa pid .
+Specifically, calls to
+.Xr getdirentries 2
+and
+.Xr getdents 2
+will be routed to userland after the current actual directory contents
+are read into userland.
+.It Fa AUTO_DIRECT
+Set the directory as a mount trigger. Any request to enter the directory
+will trigger a callback into the process
+.Fa pid .
+.It Fa AUTO_INDIRECT
+Set the directory as an indirect trigger. Any request for an entry inside
+the directory will be routed to the process identified by
+.Fa pid .
+.El
+.Sh EXAMPLES
+See /usr/share/examples/autofs/driver/
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 6.0 .
+.Sh AUTHORS
+This manual page and the autofs filesystem suite were written by
+.An Alfred Perlstein .
diff --git a/lib/libautofs/libautofs.c b/lib/libautofs/libautofs.c
new file mode 100644
index 0000000..f68e904
--- /dev/null
+++ b/lib/libautofs/libautofs.c
@@ -0,0 +1,465 @@
+/*
+ * Copyright (c) 2004 Alfred Perlstein <alfred@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ * $Id: libautofs.c,v 1.3 2004/08/31 08:49:56 bright Exp $
+ */
+#include <err.h>
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/poll.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+
+#include <autofs.h>
+
+#include "libautofs.h"
+
+struct auto_handle {
+ char ah_mp[MNAMELEN];
+ fsid_t ah_fsid;
+ int ah_fd;
+};
+
+static int autofs_sysctl(int, fsid_t *, void *, size_t *, void *, size_t);
+static void safe_free(void *ptr);
+static int getmntlst(struct statfs **sfsp, int *cntp);
+
+static void
+safe_free(void *ptr)
+{
+ int saved_errno;
+
+ saved_errno = errno;
+ free(ptr);
+ errno = saved_errno;
+}
+
+int
+getmntlst(struct statfs **sfsp, int *cntp)
+{
+ int cnt;
+ long bufsize;
+
+ *sfsp = NULL;
+ cnt = getfsstat(NULL, 0, MNT_NOWAIT);
+ bufsize = cnt * sizeof(**sfsp);
+ fprintf(stderr, "getmntlst bufsize %ld, cnt %d\n", bufsize, cnt);
+ *sfsp = malloc(bufsize);
+ if (sfsp == NULL)
+ goto err;
+ cnt = getfsstat(*sfsp, bufsize, MNT_NOWAIT);
+ if (cnt == -1)
+ goto err;
+ *cntp = cnt;
+ fprintf(stderr, "getmntlst ok, cnt %d\n", cnt);
+ return (0);
+err:
+ safe_free(sfsp);
+ *sfsp = NULL;
+ fprintf(stderr, "getmntlst bad\n");
+ return (-1);
+}
+
+/* get a handle based on a path. */
+int
+autoh_get(const char *path, autoh_t *ahp)
+{
+ struct statfs *sfsp, *sp;
+ int cnt, fd, i;
+ autoh_t ret;
+
+ ret = NULL;
+ /*
+ * We use getfsstat to prevent avoid the lookups on the mountpoints
+ * that statfs(2) would do.
+ */
+ if (getmntlst(&sfsp, &cnt))
+ goto err;
+ for (i = 0; i < cnt; i++) {
+ if (strcmp(sfsp[i].f_mntonname, path) == 0)
+ break;
+ }
+ if (i == cnt) {
+ fprintf(stderr, "autoh_get bad %d %d\n", i, cnt);
+ errno = ENOENT;
+ goto err;
+ }
+ sp = &sfsp[i];
+ if (strcmp(sp->f_fstypename, "autofs")) {
+ errno = ENOTTY;
+ goto err;
+ }
+ fd = open(sp->f_mntonname, O_RDONLY);
+ if (fd == -1)
+ goto err;
+ ret = malloc(sizeof(*ret));
+ if (ret == NULL)
+ goto err;
+
+ ret->ah_fsid = sp->f_fsid;
+ ret->ah_fd = fd;
+ strlcpy(ret->ah_mp, sp->f_mntonname, sizeof(ret->ah_mp));
+ safe_free(sfsp);
+ *ahp = ret;
+ return (0);
+err:
+ safe_free(ret);
+ safe_free(sfsp);
+ return (-1);
+}
+
+/* release. */
+void
+autoh_free(autoh_t ah)
+{
+ int saved_errno;
+
+ saved_errno = errno;
+ close(ah->ah_fd);
+ free(ah);
+ errno = saved_errno;
+}
+
+/*
+ * Get an array of pointers to all the currently mounted autofs
+ * instances.
+ */
+int
+autoh_getall(autoh_t **arrayp, int *cntp)
+{
+ struct statfs *sfsp;
+ int cnt, i, pos;
+ autoh_t *array;
+
+ array = NULL;
+ /*
+ * We use getfsstat to prevent avoid the lookups on the mountpoints
+ * that statfs(2) would do.
+ */
+ if (getmntlst(&sfsp, &cnt))
+ goto err;
+ array = *arrayp = calloc(cnt + 1, sizeof(**arrayp));
+ if (array == NULL)
+ goto err;
+ for (i = 0, pos = 0; i < cnt; i++) {
+ if (autoh_get(sfsp[i].f_mntonname, &array[pos]) == -1) {
+ /* not an autofs entry, that's ok, otherwise bail */
+ if (errno == ENOTTY)
+ continue;
+ goto err;
+ }
+ pos++;
+ }
+ if (pos == 0) {
+ errno = ENOENT;
+ goto err;
+ }
+ *arrayp = array;
+ *cntp = pos;
+ safe_free(sfsp);
+ return (0);
+err:
+ safe_free(sfsp);
+ if (array)
+ autoh_freeall(array);
+ return (-1);
+}
+
+/* release. */
+void
+autoh_freeall(autoh_t *ah)
+{
+
+ while (*ah != NULL) {
+ autoh_free(*ah);
+ ah++;
+ }
+ safe_free(ah);
+}
+
+/* return fd to select on. */
+int
+autoh_fd(autoh_t ah)
+{
+
+ return (ah->ah_fd);
+}
+
+const char *
+autoh_mp(autoh_t ah)
+{
+
+ return (ah->ah_mp);
+}
+
+static int do_autoreq_get(autoh_t ah, autoreq_t *reqp, int *cntp);
+
+/* get an array of pending requests */
+int
+autoreq_get(autoh_t ah, autoreq_t **reqpp, int *cntp)
+{
+ int cnt, i;
+ autoreq_t req, *reqp;
+
+ if (do_autoreq_get(ah, &req, &cnt))
+ return (-1);
+
+ reqp = calloc(cnt + 1, sizeof(*reqp));
+ if (reqp == NULL) {
+ safe_free(req);
+ return (-1);
+ }
+ for (i = 0; i < cnt; i++)
+ reqp[i] = &req[i];
+ *reqpp = reqp;
+ *cntp = cnt;
+ return (0);
+}
+
+int
+do_autoreq_get(autoh_t ah, autoreq_t *reqp, int *cntp)
+{
+ size_t olen;
+ struct autofs_userreq *reqs;
+ int cnt, error;
+ int vers;
+
+ vers = AUTOFS_PROTOVERS;
+
+ error = 0;
+ reqs = NULL;
+ olen = 0;
+ cnt = 0;
+ error = autofs_sysctl(AUTOFS_CTL_GETREQS, &ah->ah_fsid, NULL, &olen,
+ &vers, sizeof(vers));
+ if (error == -1)
+ goto out;
+ if (olen == 0)
+ goto out;
+
+ reqs = malloc(olen);
+ if (reqs == NULL)
+ goto out;
+ error = autofs_sysctl(AUTOFS_CTL_GETREQS, &ah->ah_fsid, reqs, &olen,
+ &vers, sizeof(vers));
+ if (error == -1)
+ goto out;
+out:
+ if (error) {
+ safe_free(reqs);
+ return (-1);
+ }
+ cnt = olen / sizeof(*reqs);
+ *cntp = cnt;
+ *reqp = reqs;
+ return (0);
+}
+
+/* free an array of requests */
+void
+autoreq_free(autoh_t ah __unused, autoreq_t *req)
+{
+
+ free(*req);
+ free(req);
+}
+
+/* serve a request */
+int
+autoreq_serv(autoh_t ah, autoreq_t req)
+{
+ int error;
+
+ error = autofs_sysctl(AUTOFS_CTL_SERVREQ, &ah->ah_fsid, NULL, NULL,
+ req, sizeof(*req));
+ return (error);
+}
+
+enum autoreq_op
+autoreq_getop(autoreq_t req)
+{
+
+ switch (req->au_op) {
+ case AREQ_LOOKUP:
+ return (AUTOREQ_OP_LOOKUP);
+ case AREQ_STAT:
+ return (AUTOREQ_OP_STAT);
+ case AREQ_READDIR:
+ return (AUTOREQ_OP_READDIR);
+ default:
+ return (AUTOREQ_OP_UNKNOWN);
+ }
+}
+
+/* get a request's file name. */
+const char *
+autoreq_getpath(autoreq_t req)
+{
+
+ return (req->au_name);
+}
+
+/* get a request's inode. a indirect mount may return AUTO_INODE_NONE. */
+autoino_t
+autoreq_getino(autoreq_t req)
+{
+
+ return (req->au_ino);
+}
+
+void
+autoreq_setino(autoreq_t req, autoino_t ino)
+{
+
+ req->au_ino = ino;
+}
+
+/* get a request's directory inode. */
+autoino_t
+autoreq_getdirino(autoreq_t req)
+{
+
+ return (req->au_dino);
+}
+
+void
+autoreq_seterrno(autoreq_t req, int error)
+{
+
+ req->au_errno = error;
+}
+
+void
+autoreq_setaux(autoreq_t req, void *auxdata, size_t auxlen)
+{
+
+ req->au_auxdata = auxdata;
+ req->au_auxlen = auxlen;
+}
+
+void
+autoreq_getaux(autoreq_t req, void **auxdatap, size_t *auxlenp)
+{
+
+ *auxdatap = req->au_auxdata;
+ *auxlenp = req->au_auxlen;
+}
+
+void
+autoreq_seteof(autoreq_t req, int eof)
+{
+
+ req->au_eofflag = eof;
+}
+
+void
+autoreq_getoffset(autoreq_t req, off_t *offp)
+{
+
+ *offp = req->au_offset - AUTOFS_USEROFF;
+}
+
+/* toggle by path. args = handle, AUTO_?, pid (-1 to disable), path. */
+int
+autoh_togglepath(autoh_t ah, int op, pid_t pid, const char *path)
+{
+ int fd, ret;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return (-1);
+ ret = autoh_togglefd(ah, op, pid, fd);
+ close(fd);
+ return (ret);
+}
+
+/* toggle by fd. args = handle, AUTO_?, pid (-1 to disable), fd. */
+int
+autoh_togglefd(autoh_t ah, int op, pid_t pid, int fd)
+{
+ struct stat sb;
+ struct autofs_mounterreq mr;
+ int error, realop;
+
+ switch (op) {
+ case AUTO_DIRECT:
+ realop = AUTOFS_CTL_TRIGGER;
+ break;
+ case AUTO_INDIRECT:
+ realop = AUTOFS_CTL_SUBTRIGGER;
+ break;
+ case AUTO_MOUNTER:
+ realop = AUTOFS_CTL_MOUNTER;
+ break;
+ case AUTO_BROWSE:
+ realop = AUTOFS_CTL_BROWSE;
+ break;
+ default:
+ errno = ENOTTY;
+ return (-1);
+ }
+
+ if (fstat(fd, &sb))
+ return (-1);
+ bzero(&mr, sizeof(mr));
+ mr.amu_ino = sb.st_ino;
+ mr.amu_pid = pid;
+ error = autofs_sysctl(realop, &ah->ah_fsid, NULL, NULL,
+ &mr, sizeof(mr));
+ return (error);
+}
+
+int
+autofs_sysctl(op, fsid, oldp, oldlenp, newp, newlen)
+ int op;
+ fsid_t *fsid;
+ void *oldp;
+ size_t *oldlenp;
+ void *newp;
+ size_t newlen;
+{
+ struct vfsidctl vc;
+
+ bzero(&vc, sizeof(vc));
+ vc.vc_op = op;
+ strcpy(vc.vc_fstypename, "*");
+ vc.vc_vers = VFS_CTL_VERS1;
+ vc.vc_fsid = *fsid;
+ vc.vc_ptr = newp;
+ vc.vc_len = newlen;
+ return (sysctlbyname("vfs.autofs.ctl", oldp, oldlenp, &vc, sizeof(vc)));
+}
+
diff --git a/lib/libautofs/libautofs.h b/lib/libautofs/libautofs.h
new file mode 100644
index 0000000..98da2f8
--- /dev/null
+++ b/lib/libautofs/libautofs.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2004 Alfred Perlstein <alfred@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ * $Id: libautofs.h,v 1.3 2004/08/31 08:49:56 bright Exp $
+ */
+#ifndef _LIBAUTOFS_H
+#define _LIBAUTOFS_H
+
+struct auto_handle;
+typedef struct auto_handle * autoh_t;
+struct autofs_userreq;
+typedef struct autofs_userreq * autoreq_t;
+typedef uint64_t autoino_t;
+
+#define AUTO_INODE_NONE 0
+
+#define AUTO_DIRECT 1
+#define AUTO_INDIRECT 2
+#define AUTO_MOUNTER 3
+#define AUTO_BROWSE 4
+
+enum autoreq_op {
+ AUTOREQ_OP_UNKNOWN = 0,
+ AUTOREQ_OP_LOOKUP,
+ AUTOREQ_OP_STAT,
+ AUTOREQ_OP_READDIR
+};
+
+/* get a handle based on a path. */
+int autoh_get(const char *, autoh_t *);
+/* release. */
+void autoh_free(autoh_t);
+
+/*
+ * Get an array of pointers to handles for all autofs mounts, returns count
+ * or -1
+ */
+int autoh_getall(autoh_t **, int *cnt);
+/* free the array of pointers */
+void autoh_freeall(autoh_t *);
+
+/* return fd to select on. */
+int autoh_fd(autoh_t);
+
+/* returns the mount point of the autofs instance. */
+const char *autoh_mp(autoh_t);
+
+/* get an array of pending requests */
+int autoreq_get(autoh_t, autoreq_t **, int *);
+/* free an array of requests */
+void autoreq_free(autoh_t, autoreq_t *);
+/* serve a request */
+int autoreq_serv(autoh_t, autoreq_t);
+
+/* get the operation requested */
+enum autoreq_op autoreq_getop(autoreq_t);
+
+/* get a request's file name. */
+const char *autoreq_getpath(autoreq_t);
+/* get a request's inode. a indirect mount may return AUTO_INODE_NONE. */
+autoino_t autoreq_getino(autoreq_t);
+/*
+ * set a request's inode. an indirect mount may return AUTO_INODE_NONE,
+ * this is a fixup for indirect mounts.
+ */
+void autoreq_setino(autoreq_t, autoino_t);
+/* get a request's directory inode. */
+autoino_t autoreq_getdirino(autoreq_t);
+void autoreq_seterrno(autoreq_t, int);
+void autoreq_setaux(autoreq_t, void *, size_t);
+void autoreq_getaux(autoreq_t, void **, size_t *);
+void autoreq_seteof(autoreq_t req, int eof);
+void autoreq_getoffset(autoreq_t req, off_t *offp);
+
+/* toggle by path. args = handle, AUTO_?, pid (-1 to disable), path. */
+int autoh_togglepath(autoh_t, int, pid_t, const char *);
+/* toggle by fd. args = handle, AUTO_?, pid (-1 to disable), fd. */
+int autoh_togglefd(autoh_t, int, pid_t, int);
+
+#endif
OpenPOWER on IntegriCloud