From 43e2ef52507af6c461efaadc60a295fc1c61cca8 Mon Sep 17 00:00:00 2001
From: Carl Fredrik Hammar <hammy.lite@gmail.com>
Date: Sat, 27 Jun 2009 15:37:55 +0200
Subject: [PATCH] Declare trivfs hooks external and provide defaults

* libtrivfs/trivfs.h
(trivfs_check_access_hook)
(trivfs_check_open_hook)
(trivfs_open_hook)
(trivfs_protid_create_hook)
(trivfs_peropen_create_hook)
(trivfs_protid_destroy_hook)
(trivfs_peropen_destroy_hook)
(trivfs_getroot_hook): Declare external.
* libtrivfs/hooks.c: New file.
* libtrivfs/Makefile (OTHERSRCS): Add `hooks.c'.
---
 libtrivfs/Makefile |    2 +-
 libtrivfs/hooks.c  |   31 +++++++++++++++++++++++++++++++
 libtrivfs/trivfs.h |   51 +++++++++++++++++++++++++++------------------------
 3 files changed, 59 insertions(+), 25 deletions(-)
 create mode 100644 libtrivfs/hooks.c

diff --git a/libtrivfs/Makefile b/libtrivfs/Makefile
index ddce1e6..015d471 100644
--- a/libtrivfs/Makefile
+++ b/libtrivfs/Makefile
@@ -40,7 +40,7 @@ FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-stubs.c fsys-syncfs.c \
 OTHERSRCS=demuxer.c protid-clean.c protid-dup.c cntl-create.c \
 	cntl-clean.c migsupport.c times.c startup.c open.c \
 	runtime-argp.c set-options.c append-args.c dyn-classes.c \
-	protid-classes.c cntl-classes.c
+	protid-classes.c cntl-classes.c hooks.c
 
 SRCS=$(FSSRCS) $(IOSRCS) $(FSYSSRCS) $(OTHERSRCS)
 
diff --git a/libtrivfs/hooks.c b/libtrivfs/hooks.c
new file mode 100644
index 0000000..18b7bd2
--- /dev/null
+++ b/libtrivfs/hooks.c
@@ -0,0 +1,31 @@
+/* Default values for hooks.
+
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with the GNU Hurd; see the file COPYING.  If not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+   MA 02110-1301 USA.  */
+
+#include "trivfs.h"
+
+typeof (trivfs_check_access_hook) trivfs_check_access_hook;
+typeof (trivfs_check_open_hook) trivfs_check_open_hook;
+typeof (trivfs_open_hook) trivfs_open_hook;
+typeof (trivfs_protid_create_hook) trivfs_protid_create_hook;
+typeof (trivfs_peropen_create_hook) trivfs_peropen_create_hook;
+typeof (trivfs_protid_destroy_hook) trivfs_protid_destroy_hook;
+typeof (trivfs_peropen_destroy_hook) trivfs_peropen_destroy_hook;
+typeof (trivfs_getroot_hook) trivfs_getroot_hook;
diff --git a/libtrivfs/trivfs.h b/libtrivfs/trivfs.h
index 6e087f3..8c66490 100644
--- a/libtrivfs/trivfs.h
+++ b/libtrivfs/trivfs.h
@@ -104,10 +104,10 @@ void trivfs_modify_stat (struct trivfs_protid *cred, io_statbuf_t *);
    file permits to USER instead of checking the underlying node.
    REALNODE is the underlying node, and CNTL is the trivfs control
    object.  The access permissions are returned in ALLOWED.  */
-error_t (*trivfs_check_access_hook) (struct trivfs_control *cntl,
-				     struct iouser *user,
-				     mach_port_t realnode,
-				     int *allowed);
+extern error_t (*trivfs_check_access_hook) (struct trivfs_control *cntl,
+					    struct iouser *user,
+					    mach_port_t realnode,
+					    int *allowed);
 
 /* If this variable is set, it is called every time an open happens.
    USER and FLAGS are from the open; CNTL identifies the
@@ -115,45 +115,48 @@ error_t (*trivfs_check_access_hook) (struct trivfs_control *cntl,
    node.  This call can block as necessary, unless O_NONBLOCK is set
    in FLAGS.  Any desired error can be returned, which will be reflected
    to the user and prevent the open from succeeding.  */
-error_t (*trivfs_check_open_hook) (struct trivfs_control *cntl,
-				   struct iouser *user, int flags);
+extern error_t (*trivfs_check_open_hook) (struct trivfs_control *cntl,
+					  struct iouser *user, int flags);
 
 /* If this variable is set, it is called in place of `trivfs_open' (below).  */
-error_t (*trivfs_open_hook) (struct trivfs_control *fsys,
-			     struct iouser *user,
-			     mach_port_t dotdot,
-			     int flags,
-			     mach_port_t realnode,
-			     struct trivfs_protid **cred);
+extern error_t (*trivfs_open_hook) (struct trivfs_control *fsys,
+				    struct iouser *user,
+				    mach_port_t dotdot,
+				    int flags,
+				    mach_port_t realnode,
+				    struct trivfs_protid **cred);
 
 /* If this variable is set, it is called every time a new protid
    structure is created and initialized. */
-error_t (*trivfs_protid_create_hook) (struct trivfs_protid *);
+extern error_t (*trivfs_protid_create_hook) (struct trivfs_protid *);
 
 /* If this variable is set, it is called every time a new peropen
    structure is created and initialized. */
-error_t (*trivfs_peropen_create_hook) (struct trivfs_peropen *);
+extern error_t (*trivfs_peropen_create_hook) (struct trivfs_peropen *);
 
 /* If this variable is set, it is called every time a protid structure
    is about to be destroyed. */
-void (*trivfs_protid_destroy_hook) (struct trivfs_protid *);
+extern void (*trivfs_protid_destroy_hook) (struct trivfs_protid *);
 
 /* If this variable is set, it is called every time a peropen structure
    is about to be destroyed. */
-void (*trivfs_peropen_destroy_hook) (struct trivfs_peropen *);
+extern void (*trivfs_peropen_destroy_hook) (struct trivfs_peropen *);
 
 /* If this variable is set, it is called by trivfs_S_fsys_getroot before any
    other processing takes place; if the return value is EAGAIN, normal trivfs
    getroot processing continues, otherwise the rpc returns with that return
    value.  */
-error_t (*trivfs_getroot_hook) (struct trivfs_control *cntl,
-				mach_port_t reply_port,
-				mach_msg_type_name_t reply_port_type,
-				mach_port_t dotdot,
-				uid_t *uids, u_int nuids, uid_t *gids, u_int ngids,
-				int flags,
-				retry_type *do_retry, char *retry_name,
-				mach_port_t *node, mach_msg_type_name_t *node_type);
+extern error_t (*trivfs_getroot_hook) (struct trivfs_control *cntl,
+				       mach_port_t reply_port,
+				       mach_msg_type_name_t reply_port_type,
+				       mach_port_t dotdot,
+				       uid_t *uids, u_int nuids,
+				       uid_t *gids, u_int ngids,
+				       int flags,
+				       retry_type *do_retry,
+				       char *retry_name,
+				       mach_port_t *node,
+				       mach_msg_type_name_t *node_type);
 
 /* Creates a control port for this filesystem and sends it to BOOTSTRAP with
    fsys_startup.  CONTROL_CLASS & CONTROL_BUCKET are passed to the ports
-- 
1.6.3.1

