summaryrefslogtreecommitdiffstats
path: root/fs/autofs4
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2000-02-18 00:24:27 +0000
committerRalf Baechle <ralf@linux-mips.org>2000-02-18 00:24:27 +0000
commitb9558d5f86c471a125abf1fb3a3882fb053b1f8c (patch)
tree707b53ec64e740a7da87d5f36485e3cd9b1c794e /fs/autofs4
parentb3ac367c7a3e6047abe74817db27e34e759f279f (diff)
Merge with Linux 2.3.41.
Diffstat (limited to 'fs/autofs4')
-rw-r--r--fs/autofs4/.cvsignore2
-rw-r--r--fs/autofs4/Makefile35
-rw-r--r--fs/autofs4/autofs_i.h175
-rw-r--r--fs/autofs4/expire.c234
-rw-r--r--fs/autofs4/init.c35
-rw-r--r--fs/autofs4/inode.c423
-rw-r--r--fs/autofs4/inohash.c68
-rw-r--r--fs/autofs4/root.c624
-rw-r--r--fs/autofs4/symlink.c34
-rw-r--r--fs/autofs4/waitq.c251
10 files changed, 1881 insertions, 0 deletions
diff --git a/fs/autofs4/.cvsignore b/fs/autofs4/.cvsignore
new file mode 100644
index 000000000..857dd22e9
--- /dev/null
+++ b/fs/autofs4/.cvsignore
@@ -0,0 +1,2 @@
+.depend
+.*.flags
diff --git a/fs/autofs4/Makefile b/fs/autofs4/Makefile
new file mode 100644
index 000000000..0095b8aed
--- /dev/null
+++ b/fs/autofs4/Makefile
@@ -0,0 +1,35 @@
+#
+# Makefile for the linux autofs-filesystem routines.
+#
+# We can build this either out of the kernel tree or the autofs tools tree.
+#
+
+O_TARGET := autofs4.o
+O_OBJS := inohash.o init.o inode.o root.o symlink.o waitq.o expire.o
+
+M_OBJS := $(O_TARGET)
+
+ifdef TOPDIR
+#
+# Part of the kernel code
+#
+include $(TOPDIR)/Rules.make
+else
+#
+# Standalone (handy for development)
+#
+include ../Makefile.rules
+
+CFLAGS += -D__KERNEL__ -DMODULE $(KFLAGS) -I../include -I$(KINCLUDE) $(MODFLAGS)
+
+all: $(O_TARGET)
+
+$(O_TARGET): $(O_OBJS)
+ $(LD) -r -o $(O_TARGET) $(O_OBJS)
+
+install: $(O_TARGET)
+ install -c $(O_TARGET) /lib/modules/`uname -r`/fs
+
+clean:
+ rm -f *.o *.s
+endif
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
new file mode 100644
index 000000000..e8487efd6
--- /dev/null
+++ b/fs/autofs4/autofs_i.h
@@ -0,0 +1,175 @@
+/* -*- linux-c -*- ------------------------------------------------------- *
+ *
+ * linux/fs/autofs/autofs_i.h
+ *
+ * Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/* Internal header file for autofs */
+
+#include <linux/auto_fs.h>
+#include <linux/list.h>
+
+/* This is the range of ioctl() numbers we claim as ours */
+#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
+#define AUTOFS_IOC_COUNT 32
+
+#include <linux/kernel.h>
+#include <linux/malloc.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/wait.h>
+#include <asm/uaccess.h>
+
+/* #define DEBUG */
+
+#ifdef DEBUG
+#define DPRINTK(D) do{ printk("pid %d: ", current->pid); printk D; } while(0)
+#else
+#define DPRINTK(D) do {} while(0)
+#endif
+
+#define AUTOFS_SUPER_MAGIC 0x0187
+
+/*
+ * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
+ * kernel will keep the negative response cached for up to the time given
+ * here, although the time can be shorter if the kernel throws the dcache
+ * entry away. This probably should be settable from user space.
+ */
+#define AUTOFS_NEGATIVE_TIMEOUT (60*HZ) /* 1 minute */
+
+/* Unified info structure. This is pointed to by both the dentry and
+ inode structures. Each file in the filesystem has an instance of this
+ structure. It holds a reference to the dentry, so dentries are never
+ flushed while the file exists. All name lookups are dealt with at the
+ dentry level, although the filesystem can interfere in the validation
+ process. Readdir is implemented by traversing the dentry lists. */
+struct autofs_info {
+ struct dentry *dentry;
+ struct inode *inode;
+
+ int flags;
+
+ struct autofs_sb_info *sbi;
+ struct list_head ino_hash;
+ unsigned long last_used;
+
+ ino_t ino;
+ mode_t mode;
+ size_t size;
+
+ void (*free)(struct autofs_info *);
+ union {
+ const char *symlink;
+ } u;
+};
+
+#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
+
+struct autofs_inohash {
+ struct list_head head;
+};
+
+struct autofs_wait_queue {
+ wait_queue_head_t queue;
+ struct autofs_wait_queue *next;
+ autofs_wqt_t wait_queue_token;
+ /* We use the following to see what we are waiting for */
+ int hash;
+ int len;
+ char *name;
+ /* This is for status reporting upon return */
+ int status;
+ int wait_ctr;
+};
+
+#define AUTOFS_ROOT_INO 1
+#define AUTOFS_FIRST_INO 2
+
+#define AUTOFS_SBI_MAGIC 0x6d4a556d
+
+struct autofs_sb_info {
+ u32 magic;
+ struct file *pipe;
+ pid_t oz_pgrp;
+ int catatonic;
+ int version;
+ unsigned long exp_timeout;
+ ino_t next_ino;
+ struct super_block *sb;
+ struct autofs_wait_queue *queues; /* Wait queue pointer */
+ struct autofs_inohash ihash;
+};
+
+static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
+{
+ return (struct autofs_sb_info *)(sb->u.generic_sbp);
+}
+
+static inline struct autofs_info *autofs4_dentry_ino(struct dentry *dentry)
+{
+ return (struct autofs_info *)(dentry->d_fsdata);
+}
+
+/* autofs4_oz_mode(): do we see the man behind the curtain? (The
+ processes which do manipulations for us in user space sees the raw
+ filesystem without "magic".) */
+
+static inline int autofs4_oz_mode(struct autofs_sb_info *sbi) {
+ return sbi->catatonic || current->pgrp == sbi->oz_pgrp;
+}
+
+/* Does a dentry have some pending activity? */
+static inline int autofs4_ispending(struct dentry *dentry)
+{
+ struct autofs_info *inf = autofs4_dentry_ino(dentry);
+
+ return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
+ (inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
+}
+
+/* Inode hash operations */
+void autofs4_init_ihash(struct autofs_inohash *);
+void autofs4_ihash_insert(struct autofs_inohash *ih, struct autofs_info *ino);
+void autofs4_ihash_delete(struct autofs_info *ino);
+void autofs4_ihash_nuke(struct autofs_inohash *ih);
+struct autofs_info *autofs4_ihash_find(struct autofs_inohash *ih, ino_t ino);
+
+struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
+void autofs4_free_ino(struct autofs_info *);
+
+/* Expiration */
+int is_autofs4_dentry(struct dentry *);
+int autofs4_expire_run(struct super_block *, struct autofs_sb_info *,
+ struct autofs_packet_expire *);
+int autofs4_expire_multi(struct super_block *, struct autofs_sb_info *, int *);
+
+/* Operations structures */
+
+extern struct inode_operations autofs4_symlink_inode_operations;
+extern struct inode_operations autofs4_dir_inode_operations;
+extern struct inode_operations autofs4_root_inode_operations;
+
+/* Initializing function */
+
+struct super_block *autofs4_read_super(struct super_block *, void *,int);
+struct autofs_info *autofs4_init_ino(struct autofs_info *, struct autofs_sb_info *sbi, mode_t mode);
+
+/* Queue management functions */
+
+enum autofs_notify
+{
+ NFY_NONE,
+ NFY_MOUNT,
+ NFY_EXPIRE
+};
+
+int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
+int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
+void autofs4_catatonic_mode(struct autofs_sb_info *);
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
new file mode 100644
index 000000000..2318b9aec
--- /dev/null
+++ b/fs/autofs4/expire.c
@@ -0,0 +1,234 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/expire.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ * Copyright 1999 Jeremy Fitzhardinge <jeremy@goop.org>
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include "autofs_i.h"
+
+/*
+ * Determine if a dentry tree is in use. This is much the
+ * same as the standard is_root_busy() function, except
+ * that :-
+ * - the extra dentry reference in autofs dentries is not
+ * considered to be busy
+ * - mountpoints within the tree are not busy
+ * - it traverses across mountpoints
+ * XXX doesn't consider children of covered dentries at mountpoints
+ */
+static int is_tree_busy(struct dentry *root)
+{
+ struct dentry *this_parent;
+ struct list_head *next;
+ int count;
+
+ root = root->d_mounts;
+
+ count = root->d_count;
+ this_parent = root;
+
+ DPRINTK(("is_tree_busy: starting at %.*s/%.*s, d_count=%d\n",
+ root->d_covers->d_parent->d_name.len,
+ root->d_covers->d_parent->d_name.name,
+ root->d_name.len, root->d_name.name,
+ root->d_count));
+
+ /* Ignore autofs's extra reference */
+ if (is_autofs4_dentry(root)) {
+ DPRINTK(("is_tree_busy: autofs\n"));
+ count--;
+ }
+
+ /* Mountpoints don't count */
+ if (root->d_mounts != root ||
+ root->d_covers != root) {
+ DPRINTK(("is_tree_busy: mountpoint\n"));
+ count--;
+ }
+
+repeat:
+ next = this_parent->d_mounts->d_subdirs.next;
+resume:
+ while (next != &this_parent->d_mounts->d_subdirs) {
+ int adj = 0;
+ struct list_head *tmp = next;
+ struct dentry *dentry = list_entry(tmp, struct dentry,
+ d_child);
+
+ next = tmp->next;
+
+ dentry = dentry->d_mounts;
+
+ DPRINTK(("is_tree_busy: considering %.*s/%.*s, d_count=%d, count=%d\n",
+ this_parent->d_name.len,
+ this_parent->d_name.name,
+ dentry->d_covers->d_name.len,
+ dentry->d_covers->d_name.name,
+ dentry->d_count, count));
+
+ /* Decrement count for unused children */
+ count += (dentry->d_count - 1);
+
+ /* Mountpoints don't count */
+ if (dentry->d_mounts != dentry ||
+ dentry->d_covers != dentry) {
+ DPRINTK(("is_tree_busy: mountpoint\n"));
+ adj++;
+ }
+
+ /* Ignore autofs's extra reference */
+ if (is_autofs4_dentry(dentry)) {
+ DPRINTK(("is_tree_busy: autofs\n"));
+ adj++;
+ }
+
+ count -= adj;
+
+ if (!list_empty(&dentry->d_mounts->d_subdirs)) {
+ this_parent = dentry->d_mounts;
+ goto repeat;
+ }
+
+ /* root is busy if any leaf is busy */
+ if (dentry->d_count != adj) {
+ DPRINTK(("is_tree_busy: busy leaf (d_count=%d adj=%d)\n",
+ dentry->d_count, adj));
+ return 1;
+ }
+ }
+ /*
+ * All done at this level ... ascend and resume the search.
+ */
+ if (this_parent != root) {
+ next = this_parent->d_covers->d_child.next;
+ this_parent = this_parent->d_covers->d_parent;
+ goto resume;
+ }
+
+ DPRINTK(("is_tree_busy: count=%d\n", count));
+ return count != 0; /* remaining users? */
+}
+
+/*
+ * Find an eligible tree to time-out
+ * A tree is eligible if :-
+ * - it is unused by any user process
+ * - it has been unused for exp_timeout time
+ */
+static struct dentry *autofs4_expire(struct super_block *sb,
+ struct autofs_sb_info *sbi,
+ int do_now)
+{
+ unsigned long now = jiffies; /* snapshot of now */
+ unsigned long timeout;
+ struct dentry *root = sb->s_root;
+ struct list_head *tmp;
+
+ if (!sbi->exp_timeout || !root)
+ return NULL;
+
+ timeout = sbi->exp_timeout;
+
+ for(tmp = root->d_subdirs.next;
+ tmp != &root->d_subdirs;
+ tmp = tmp->next) {
+ struct autofs_info *ino;
+ struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
+
+ if (dentry->d_inode == NULL)
+ continue;
+
+ ino = autofs4_dentry_ino(dentry);
+
+ if (ino == NULL) {
+ /* dentry in the process of being deleted */
+ continue;
+ }
+
+ /* No point expiring a pending mount */
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
+ continue;
+
+ if (!do_now) {
+ /* Too young to die */
+ if (time_after(ino->last_used+timeout, now))
+ continue;
+
+ /* update last_used here :-
+ - obviously makes sense if it is in use now
+ - less obviously, prevents rapid-fire expire
+ attempts if expire fails the first time */
+ ino->last_used = now;
+ }
+
+ if (!is_tree_busy(dentry)) {
+ DPRINTK(("autofs_expire: returning %p %.*s\n",
+ dentry, dentry->d_name.len, dentry->d_name.name));
+ /* Start from here next time */
+ list_del(&root->d_subdirs);
+ list_add(&root->d_subdirs, &dentry->d_child);
+ return dentry;
+ }
+ }
+
+ return NULL;
+}
+
+/* Perform an expiry operation */
+int autofs4_expire_run(struct super_block *sb,
+ struct autofs_sb_info *sbi,
+ struct autofs_packet_expire *pkt_p)
+{
+ struct autofs_packet_expire pkt;
+ struct dentry *dentry;
+
+ memset(&pkt,0,sizeof pkt);
+
+ pkt.hdr.proto_version = sbi->version;
+ pkt.hdr.type = autofs_ptype_expire;
+
+ if ((dentry = autofs4_expire(sb, sbi, 0)) == NULL)
+ return -EAGAIN;
+
+ pkt.len = dentry->d_name.len;
+ memcpy(pkt.name, dentry->d_name.name, pkt.len);
+ pkt.name[pkt.len] = '\0';
+
+ if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
+ return -EFAULT;
+
+ return 0;
+}
+
+/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
+ more to be done */
+int autofs4_expire_multi(struct super_block *sb,
+ struct autofs_sb_info *sbi, int *arg)
+{
+ struct dentry *dentry;
+ int ret = -EAGAIN;
+ int do_now = 0;
+
+ if (arg && get_user(do_now, arg))
+ return -EFAULT;
+
+ if ((dentry = autofs4_expire(sb, sbi, do_now)) != NULL) {
+ struct autofs_info *de_info = autofs4_dentry_ino(dentry);
+
+ /* This is synchronous because it makes the daemon a
+ little easier */
+ de_info->flags |= AUTOFS_INF_EXPIRING;
+ ret = autofs4_wait(sbi, &dentry->d_name, NFY_EXPIRE);
+ de_info->flags &= ~AUTOFS_INF_EXPIRING;
+ }
+
+ return ret;
+}
+
diff --git a/fs/autofs4/init.c b/fs/autofs4/init.c
new file mode 100644
index 000000000..48bf60b5f
--- /dev/null
+++ b/fs/autofs4/init.c
@@ -0,0 +1,35 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/init.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include "autofs_i.h"
+
+static struct file_system_type autofs_fs_type = {
+ "autofs",
+ 0,
+ autofs4_read_super,
+ NULL
+};
+
+static int __init init_autofs4_fs(void)
+{
+ return register_filesystem(&autofs_fs_type);
+}
+
+static void __exit exit_autofs4_fs(void)
+{
+ unregister_filesystem(&autofs_fs_type);
+}
+
+module_init(init_autofs4_fs)
+module_exit(exit_autofs4_fs)
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
new file mode 100644
index 000000000..3d3485c9d
--- /dev/null
+++ b/fs/autofs4/inode.c
@@ -0,0 +1,423 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/inode.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include <linux/kernel.h>
+#include <linux/malloc.h>
+#include <linux/file.h>
+#include <linux/locks.h>
+#include <asm/bitops.h>
+#include "autofs_i.h"
+#define __NO_VERSION__
+#include <linux/module.h>
+
+static void ino_lnkfree(struct autofs_info *ino)
+{
+ if (ino->u.symlink) {
+ kfree(ino->u.symlink);
+ ino->u.symlink = NULL;
+ }
+}
+
+struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
+ struct autofs_sb_info *sbi, mode_t mode)
+{
+ int reinit = 1;
+
+ if (ino == NULL) {
+ reinit = 0;
+ ino = kmalloc(sizeof(*ino), GFP_KERNEL);
+ }
+
+ if (ino == NULL)
+ return NULL;
+
+ ino->flags = 0;
+ ino->ino = sbi->next_ino++;
+ ino->mode = mode;
+ ino->inode = NULL;
+ ino->dentry = NULL;
+ ino->size = 0;
+
+ ino->last_used = jiffies;
+
+ ino->sbi = sbi;
+ INIT_LIST_HEAD(&ino->ino_hash);
+
+ if (reinit && ino->free)
+ (ino->free)(ino);
+
+ memset(&ino->u, 0, sizeof(ino->u));
+
+ ino->free = NULL;
+
+ if (S_ISLNK(mode))
+ ino->free = ino_lnkfree;
+
+ return ino;
+}
+
+void autofs4_free_ino(struct autofs_info *ino)
+{
+ autofs4_ihash_delete(ino);
+ if (ino->dentry) {
+ ino->dentry->d_fsdata = NULL;
+ if (ino->dentry->d_inode)
+ dput(ino->dentry);
+ ino->dentry = NULL;
+ }
+ if (ino->free)
+ (ino->free)(ino);
+ kfree(ino);
+}
+
+/*
+ * Dummy functions - do we ever actually want to do
+ * something here?
+ */
+static void autofs4_put_inode(struct inode *inode)
+{
+}
+
+static void autofs4_clear_inode(struct inode *inode)
+{
+}
+
+static void autofs4_put_super(struct super_block *sb)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(sb);
+
+ sb->u.generic_sbp = NULL;
+
+ if ( !sbi->catatonic )
+ autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
+
+ kfree(sbi);
+
+ DPRINTK(("autofs: shutting down\n"));
+
+#ifdef MODULE
+ MOD_DEC_USE_COUNT;
+#endif
+}
+
+static void autofs4_umount_begin(struct super_block *sb)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(sb);
+
+ if (!sbi->catatonic)
+ autofs4_catatonic_mode(sbi);
+}
+
+static int autofs4_statfs(struct super_block *sb, struct statfs *buf, int bufsiz);
+static void autofs4_read_inode(struct inode *inode);
+static void autofs4_write_inode(struct inode *inode);
+
+static struct super_operations autofs4_sops = {
+ read_inode: autofs4_read_inode,
+ write_inode: autofs4_write_inode,
+ put_inode: autofs4_put_inode,
+ clear_inode: autofs4_clear_inode,
+ put_super: autofs4_put_super,
+ statfs: autofs4_statfs,
+ umount_begin: autofs4_umount_begin,
+};
+
+static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
+ pid_t *pgrp, int *minproto, int *maxproto)
+{
+ char *this_char, *value;
+
+ *uid = current->uid;
+ *gid = current->gid;
+ *pgrp = current->pgrp;
+
+ *minproto = *maxproto = AUTOFS_PROTO_VERSION;
+
+ *pipefd = -1;
+
+ if ( !options ) return 1;
+ for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+ if ((value = strchr(this_char,'=')) != NULL)
+ *value++ = 0;
+ if (!strcmp(this_char,"fd")) {
+ if (!value || !*value)
+ return 1;
+ *pipefd = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else if (!strcmp(this_char,"uid")) {
+ if (!value || !*value)
+ return 1;
+ *uid = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else if (!strcmp(this_char,"gid")) {
+ if (!value || !*value)
+ return 1;
+ *gid = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else if (!strcmp(this_char,"pgrp")) {
+ if (!value || !*value)
+ return 1;
+ *pgrp = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else if (!strcmp(this_char,"minproto")) {
+ if (!value || !*value)
+ return 1;
+ *minproto = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else if (!strcmp(this_char,"maxproto")) {
+ if (!value || !*value)
+ return 1;
+ *maxproto = simple_strtoul(value,&value,0);
+ if (*value)
+ return 1;
+ }
+ else break;
+ }
+ return (*pipefd < 0);
+}
+
+static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
+{
+ struct autofs_info *ino;
+
+ ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
+ if (!ino)
+ return NULL;
+
+ ino->ino = AUTOFS_ROOT_INO;
+
+ return ino;
+}
+
+struct super_block *autofs4_read_super(struct super_block *s, void *data,
+ int silent)
+{
+ struct inode * root_inode;
+ struct dentry * root;
+ struct file * pipe;
+ int pipefd;
+ struct autofs_sb_info *sbi;
+ int minproto, maxproto;
+
+ MOD_INC_USE_COUNT;
+
+ lock_super(s);
+ /* Super block already completed? */
+ if (s->s_root)
+ goto out_unlock;
+
+ sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
+ if ( !sbi )
+ goto fail_unlock;
+ DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
+
+ memset(sbi, 0, sizeof(*sbi));
+
+ s->u.generic_sbp = sbi;
+ sbi->magic = AUTOFS_SBI_MAGIC;
+ sbi->catatonic = 0;
+ sbi->exp_timeout = 0;
+ sbi->oz_pgrp = current->pgrp;
+ sbi->sb = s;
+ sbi->version = 0;
+ autofs4_init_ihash(&sbi->ihash);
+ sbi->queues = NULL;
+ sbi->next_ino = AUTOFS_FIRST_INO;
+ s->s_blocksize = 1024;
+ s->s_blocksize_bits = 10;
+ s->s_magic = AUTOFS_SUPER_MAGIC;
+ s->s_op = &autofs4_sops;
+ s->s_root = NULL;
+ unlock_super(s); /* shouldn't we keep it locked a while longer? */
+
+ /*
+ * Get the root inode and dentry, but defer checking for errors.
+ */
+ autofs4_ihash_insert(&sbi->ihash, autofs4_mkroot(sbi));
+
+ root_inode = iget(s, AUTOFS_ROOT_INO);
+ root = d_alloc_root(root_inode);
+ pipe = NULL;
+
+ /*
+ * Check whether somebody else completed the super block.
+ */
+ if (s->s_root)
+ goto out_dput;
+
+ if (!root)
+ goto fail_iput;
+
+ /* Can this call block? */
+ if (parse_options(data, &pipefd,
+ &root_inode->i_uid, &root_inode->i_gid,
+ &sbi->oz_pgrp,
+ &minproto, &maxproto)) {
+ printk("autofs: called with bogus options\n");
+ goto fail_dput;
+ }
+
+ /* Couldn't this be tested earlier? */
+ if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
+ minproto > AUTOFS_PROTO_VERSION) {
+ printk("autofs: kernel does not match daemon version "
+ "daemon (%d, %d) kernel (%d, %d)\n",
+ minproto, maxproto,
+ AUTOFS_MIN_PROTO_VERSION, AUTOFS_PROTO_VERSION);
+ goto fail_dput;
+ }
+
+ sbi->version = maxproto > AUTOFS_PROTO_VERSION ? AUTOFS_PROTO_VERSION : maxproto;
+
+ DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
+ pipe = fget(pipefd);
+ /*
+ * Check whether somebody else completed the super block.
+ */
+ if (s->s_root)
+ goto out_fput;
+
+ if ( !pipe ) {
+ printk("autofs: could not open pipe file descriptor\n");
+ goto fail_dput;
+ }
+ if ( !pipe->f_op || !pipe->f_op->write )
+ goto fail_fput;
+ sbi->pipe = pipe;
+
+ /*
+ * Success! Install the root dentry now to indicate completion.
+ */
+ s->s_root = root;
+ return s;
+
+ /*
+ * Success ... somebody else completed the super block for us.
+ */
+out_unlock:
+ unlock_super(s);
+ goto out_dec;
+out_fput:
+ if (pipe)
+ fput(pipe);
+out_dput:
+ if (root)
+ dput(root);
+ else
+ iput(root_inode);
+out_dec:
+ MOD_DEC_USE_COUNT;
+ return s;
+
+ /*
+ * Failure ... clear the s_dev slot and clean up.
+ */
+fail_fput:
+ printk("autofs: pipe file descriptor does not contain proper ops\n");
+ /*
+ * fput() can block, so we clear the super block first.
+ */
+ s->s_dev = 0;
+ fput(pipe);
+ /* fall through */
+fail_dput:
+ /*
+ * dput() can block, so we clear the super block first.
+ */
+ s->s_dev = 0;
+ dput(root);
+ goto fail_free;
+fail_iput:
+ printk("autofs: get root dentry failed\n");
+ /*
+ * iput() can block, so we clear the super block first.
+ */
+ s->s_dev = 0;
+ iput(root_inode);
+fail_free:
+ kfree(sbi);
+ goto fail_dec;
+fail_unlock:
+ unlock_super(s);
+fail_dec:
+ s->s_dev = 0;
+ MOD_DEC_USE_COUNT;
+ return NULL;
+}
+
+static int autofs4_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
+{
+ struct statfs tmp;
+
+ tmp.f_type = AUTOFS_SUPER_MAGIC;
+ tmp.f_bsize = 1024;
+ tmp.f_blocks = 0;
+ tmp.f_bfree = 0;
+ tmp.f_bavail = 0;
+ tmp.f_files = 0;
+ tmp.f_ffree = 0;
+ tmp.f_namelen = NAME_MAX;
+ return copy_to_user(buf, &tmp, bufsiz) ? -EFAULT : 0;
+}
+
+static void autofs4_read_inode(struct inode *inode)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
+ struct autofs_info *inf;
+
+ inf = autofs4_ihash_find(&sbi->ihash, inode->i_ino);
+
+ if (inf == NULL || inf->inode != NULL)
+ return;
+
+ inode->i_mode = inf->mode;
+ inode->i_mtime = inode->i_ctime = inode->i_atime = CURRENT_TIME;
+ inode->i_size = inf->size;
+
+ inode->i_blocks = 0;
+ inode->i_blksize = 0;
+ inode->i_nlink = 1;
+
+ if (inode->i_sb->s_root) {
+ inode->i_uid = inode->i_sb->s_root->d_inode->i_uid;
+ inode->i_gid = inode->i_sb->s_root->d_inode->i_gid;
+ } else {
+ inode->i_uid = 0;
+ inode->i_gid = 0;
+ }
+
+ inf->inode = inode;
+
+ if (S_ISDIR(inf->mode)) {
+ inode->i_nlink = 2;
+ if (inode->i_ino == AUTOFS_ROOT_INO)
+ inode->i_op = &autofs4_root_inode_operations;
+ else
+ inode->i_op = &autofs4_dir_inode_operations;
+ } else if (S_ISLNK(inf->mode)) {
+ inode->i_op = &autofs4_symlink_inode_operations;
+ }
+}
+
+static void autofs4_write_inode(struct inode *inode)
+{
+}
diff --git a/fs/autofs4/inohash.c b/fs/autofs4/inohash.c
new file mode 100644
index 000000000..6190a55d3
--- /dev/null
+++ b/fs/autofs4/inohash.c
@@ -0,0 +1,68 @@
+/*
+ * "inohash" is a misnomer. Inodes are just stored in a single list,
+ * since this code is only ever asked for the most recently inserted
+ * inode.
+ *
+ * Copyright 1999 Jeremy Fitzhardinge <jeremy@goop.org>
+ */
+
+#include "autofs_i.h"
+
+void autofs4_init_ihash(struct autofs_inohash *ih)
+{
+ INIT_LIST_HEAD(&ih->head);
+}
+
+void autofs4_ihash_insert(struct autofs_inohash *ih,
+ struct autofs_info *ino)
+{
+ DPRINTK(("autofs_ihash_insert: adding ino %ld\n", ino->ino));
+
+ list_add(&ino->ino_hash, &ih->head);
+}
+
+void autofs4_ihash_delete(struct autofs_info *inf)
+{
+ DPRINTK(("autofs_ihash_delete: deleting ino %ld\n", inf->ino));
+
+ if (!list_empty(&inf->ino_hash))
+ list_del(&inf->ino_hash);
+}
+
+struct autofs_info *autofs4_ihash_find(struct autofs_inohash *ih,
+ ino_t inum)
+{
+ struct list_head *tmp;
+
+ for(tmp = ih->head.next;
+ tmp != &ih->head;
+ tmp = tmp->next) {
+ struct autofs_info *ino = list_entry(tmp, struct autofs_info, ino_hash);
+ if (ino->ino == inum) {
+ DPRINTK(("autofs_ihash_find: found %ld -> %p\n",
+ inum, ino));
+ return ino;
+ }
+ }
+ DPRINTK(("autofs_ihash_find: didn't find %ld\n", inum));
+ return NULL;
+}
+
+void autofs4_ihash_nuke(struct autofs_inohash *ih)
+{
+ struct list_head *tmp = ih->head.next;
+ struct list_head *next;
+
+ for(; tmp != &ih->head; tmp = next) {
+ struct autofs_info *ino;
+
+ next = tmp->next;
+
+ ino = list_entry(tmp, struct autofs_info, ino_hash);
+
+ DPRINTK(("autofs_ihash_nuke: nuking %ld\n", ino->ino));
+ autofs4_free_ino(ino);
+ }
+ INIT_LIST_HEAD(&ih->head);
+}
+
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
new file mode 100644
index 000000000..b7e4bcd0c
--- /dev/null
+++ b/fs/autofs4/root.c
@@ -0,0 +1,624 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/root.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ * Copyright 1999 Jeremy Fitzhardinge <jeremy@goop.org>
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include <linux/errno.h>
+#include <linux/stat.h>
+#include <linux/param.h>
+#include "autofs_i.h"
+
+static int autofs4_dir_readdir(struct file *,void *,filldir_t);
+static struct dentry *autofs4_dir_lookup(struct inode *,struct dentry *);
+static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
+static int autofs4_dir_unlink(struct inode *,struct dentry *);
+static int autofs4_dir_rmdir(struct inode *,struct dentry *);
+static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
+static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
+static struct dentry *autofs4_root_lookup(struct inode *,struct dentry *);
+
+static struct file_operations autofs4_root_operations = {
+ readdir: autofs4_dir_readdir, /* readdir */
+ ioctl: autofs4_root_ioctl, /* ioctl */
+};
+
+struct inode_operations autofs4_root_inode_operations = {
+ &autofs4_root_operations, /* file operations */
+
+ lookup: autofs4_root_lookup, /* lookup */
+ unlink: autofs4_dir_unlink, /* unlink */
+ symlink: autofs4_dir_symlink, /* symlink */
+ mkdir: autofs4_dir_mkdir, /* mkdir */
+ rmdir: autofs4_dir_rmdir, /* rmdir */
+};
+
+static struct file_operations autofs4_dir_operations = {
+ readdir: autofs4_dir_readdir, /* readdir */
+};
+
+struct inode_operations autofs4_dir_inode_operations = {
+ &autofs4_dir_operations, /* file operations */
+
+ lookup: autofs4_dir_lookup, /* lookup */
+ unlink: autofs4_dir_unlink, /* unlink */
+ symlink: autofs4_dir_symlink, /* symlink */
+ mkdir: autofs4_dir_mkdir, /* mkdir */
+ rmdir: autofs4_dir_rmdir, /* rmdir */
+};
+
+static inline struct dentry *nth_child(struct dentry *dir, int nr)
+{
+ struct list_head *tmp = dir->d_subdirs.next;
+
+ while(tmp != &dir->d_subdirs) {
+ if (nr-- == 0)
+ return list_entry(tmp, struct dentry, d_child);
+ tmp = tmp->next;
+ }
+ return NULL;
+}
+
+static int autofs4_dir_readdir(struct file *filp, void *dirent,
+ filldir_t filldir)
+{
+ struct autofs_sb_info *sbi;
+ struct autofs_info *ino;
+ struct dentry *dentry = filp->f_dentry;
+ struct dentry *dent_ptr;
+ struct inode *dir = dentry->d_inode;
+ struct list_head *cursor;
+ off_t nr;
+
+ sbi = autofs4_sbi(dir->i_sb);
+ ino = autofs4_dentry_ino(dentry);
+ nr = filp->f_pos;
+
+ switch(nr)
+ {
+ case 0:
+ if (filldir(dirent, ".", 1, nr, dir->i_ino) < 0)
+ return 0;
+ filp->f_pos = ++nr;
+ /* fall through */
+ case 1:
+ if (filldir(dirent, "..", 2, nr, dentry->d_covers->d_parent->d_inode->i_ino) < 0)
+ return 0;
+ filp->f_pos = ++nr;
+ /* fall through */
+ default:
+ dent_ptr = nth_child(dentry, nr-2);
+ if (dent_ptr == NULL)
+ break;
+
+ cursor = &dent_ptr->d_child;
+
+ while(cursor != &dentry->d_subdirs) {
+ dent_ptr = list_entry(cursor, struct dentry, d_child);
+ if (dent_ptr->d_inode &&
+ filldir(dirent, dent_ptr->d_name.name, dent_ptr->d_name.len, nr,
+ dent_ptr->d_inode->i_ino) < 0)
+ return 0;
+ filp->f_pos = ++nr;
+ cursor = cursor->next;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+/* Update usage from here to top of tree, so that scan of
+ top-level directories will give a useful result */
+static void autofs4_update_usage(struct dentry *dentry)
+{
+ struct dentry *top = dentry->d_sb->s_root;
+
+ for(; dentry != top; dentry = dentry->d_parent) {
+ struct autofs_info *ino = autofs4_dentry_ino(dentry->d_covers);
+
+ if (ino) {
+ update_atime(dentry->d_inode);
+ ino->last_used = jiffies;
+ }
+ }
+}
+
+static int try_to_fill_dentry(struct dentry *dentry,
+ struct super_block *sb,
+ struct autofs_sb_info *sbi)
+{
+ struct autofs_info *de_info = autofs4_dentry_ino(dentry);
+ int status = 0;
+
+ /* Block on any pending expiry here; invalidate the dentry
+ when expiration is done to trigger mount request with a new
+ dentry */
+ if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
+ DPRINTK(("try_to_fill_entry: waiting for expire %p name=%.*s, flags&PENDING=%s de_info=%p de_info->flags=%x\n",
+ dentry, dentry->d_name.len, dentry->d_name.name,
+ dentry->d_flags & DCACHE_AUTOFS_PENDING?"t":"f",
+ de_info, de_info?de_info->flags:0));
+ status = autofs4_wait(sbi, &dentry->d_name, NFY_NONE);
+
+ DPRINTK(("try_to_fill_entry: expire done status=%d\n", status));
+
+ return 0;
+ }
+
+ DPRINTK(("try_to_fill_entry: dentry=%p %.*s ino=%p\n",
+ dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode));
+
+ /* Wait for a pending mount, triggering one if there isn't one already */
+ while(dentry->d_inode == NULL) {
+ DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s, de_info=%p de_info->flags=%x\n",
+ dentry->d_name.len, dentry->d_name.name,
+ de_info, de_info?de_info->flags:0));
+ status = autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT);
+
+ DPRINTK(("try_to_fill_entry: mount done status=%d\n", status));
+
+ if (status && dentry->d_inode)
+ return 0; /* Try to get the kernel to invalidate this dentry */
+
+ /* Turn this into a real negative dentry? */
+ if (status == -ENOENT) {
+ dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
+ return 1;
+ } else if (status) {
+ /* Return a negative dentry, but leave it "pending" */
+ return 1;
+ }
+ status = autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT);
+ }
+
+ /* If this is an unused directory that isn't a mount point,
+ bitch at the daemon and fix it in user space */
+ if (S_ISDIR(dentry->d_inode->i_mode) &&
+ dentry->d_mounts == dentry &&
+ list_empty(&dentry->d_subdirs)) {
+ DPRINTK(("try_to_fill_entry: mounting existing dir\n"));
+ return autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT) == 0;
+ }
+
+ /* We don't update the usages for the autofs daemon itself, this
+ is necessary for recursive autofs mounts */
+ if (!autofs4_oz_mode(sbi))
+ autofs4_update_usage(dentry);
+
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
+ return 1;
+}
+
+
+/*
+ * Revalidate is called on every cache lookup. Some of those
+ * cache lookups may actually happen while the dentry is not
+ * yet completely filled in, and revalidate has to delay such
+ * lookups..
+ */
+static int autofs4_root_revalidate(struct dentry * dentry, int flags)
+{
+ struct inode * dir = dentry->d_parent->d_inode;
+ struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
+ struct autofs_info *ino;
+ int oz_mode = autofs4_oz_mode(sbi);
+
+ /* Pending dentry */
+ if (autofs4_ispending(dentry)) {
+ if (autofs4_oz_mode(sbi))
+ return 1;
+ else
+ return try_to_fill_dentry(dentry, dir->i_sb, sbi);
+ }
+
+ /* Negative dentry.. invalidate if "old" */
+ if (dentry->d_inode == NULL)
+ return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
+
+ ino = autofs4_dentry_ino(dentry);
+
+ /* Check for a non-mountpoint directory with no contents */
+ if (S_ISDIR(dentry->d_inode->i_mode) &&
+ dentry->d_mounts == dentry &&
+ list_empty(&dentry->d_subdirs)) {
+ DPRINTK(("autofs_root_revalidate: dentry=%p %.*s, emptydir\n",
+ dentry, dentry->d_name.len, dentry->d_name.name));
+ if (autofs4_oz_mode(sbi))
+ return 1;
+ else
+ return try_to_fill_dentry(dentry, dir->i_sb, sbi);
+ }
+
+ /* Update the usage list */
+ if (!oz_mode)
+ autofs4_update_usage(dentry);
+
+ return 1;
+}
+
+static int autofs4_revalidate(struct dentry *dentry, int flags)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
+
+ if (!autofs4_oz_mode(sbi))
+ autofs4_update_usage(dentry);
+
+ return 1;
+}
+
+static void autofs4_dentry_release(struct dentry *de)
+{
+ struct autofs_info *inf = autofs4_dentry_ino(de);
+
+ DPRINTK(("autofs4_dentry_release: releasing %p\n", de));
+
+ de->d_fsdata = NULL;
+ if (inf) {
+ inf->dentry = NULL;
+ inf->inode = NULL;
+
+ autofs4_free_ino(inf);
+ }
+}
+
+/* For dentries of directories in the root dir */
+static struct dentry_operations autofs4_root_dentry_operations = {
+ d_revalidate: autofs4_root_revalidate, /* d_revalidate */
+ d_release: autofs4_dentry_release,
+};
+
+/* For other dentries */
+static struct dentry_operations autofs4_dentry_operations = {
+ d_revalidate: autofs4_revalidate, /* d_revalidate */
+ d_release: autofs4_dentry_release,
+};
+
+/* Lookups in non-root dirs never find anything - if it's there, it's
+ already in the dcache */
+static struct dentry *autofs4_dir_lookup(struct inode *dir, struct dentry *dentry)
+{
+#if 0
+ DPRINTK(("autofs_dir_lookup: ignoring lookup of %.*s/%.*s\n",
+ dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
+ dentry->d_name.len, dentry->d_name.name));
+#endif
+
+ dentry->d_fsdata = NULL;
+ d_add(dentry, NULL);
+ return NULL;
+}
+
+/* Lookups in the root directory */
+static struct dentry *autofs4_root_lookup(struct inode *dir, struct dentry *dentry)
+{
+ struct autofs_sb_info *sbi;
+ int oz_mode;
+
+ DPRINTK(("autofs_root_lookup: name = %.*s\n",
+ dentry->d_name.len, dentry->d_name.name));
+
+ if (dentry->d_name.len > NAME_MAX)
+ return ERR_PTR(-ENOENT);/* File name too long to exist */
+
+ sbi = autofs4_sbi(dir->i_sb);
+
+ oz_mode = autofs4_oz_mode(sbi);
+ DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
+ current->pid, current->pgrp, sbi->catatonic, oz_mode));
+
+ /*
+ * Mark the dentry incomplete, but add it. This is needed so
+ * that the VFS layer knows about the dentry, and we can count
+ * on catching any lookups through the revalidate.
+ *
+ * Let all the hard work be done by the revalidate function that
+ * needs to be able to do this anyway..
+ *
+ * We need to do this before we release the directory semaphore.
+ */
+ if (dir->i_ino == AUTOFS_ROOT_INO)
+ dentry->d_op = &autofs4_root_dentry_operations;
+ else
+ dentry->d_op = &autofs4_dentry_operations;
+
+ dentry->d_flags |= DCACHE_AUTOFS_PENDING;
+ dentry->d_fsdata = NULL;
+ d_add(dentry, NULL);
+
+ if (dentry->d_op && dentry->d_op->d_revalidate) {
+ up(&dir->i_sem);
+ (dentry->d_op->d_revalidate)(dentry, 0);
+ down(&dir->i_sem);
+ }
+
+ /*
+ * If we are still pending, check if we had to handle
+ * a signal. If so we can force a restart..
+ */
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
+ if (signal_pending(current))
+ return ERR_PTR(-ERESTARTNOINTR);
+ }
+
+ /*
+ * If this dentry is unhashed, then we shouldn't honour this
+ * lookup even if the dentry is positive. Returning ENOENT here
+ * doesn't do the right thing for all system calls, but it should
+ * be OK for the operations we permit from an autofs.
+ */
+ if ( dentry->d_inode && list_empty(&dentry->d_hash) )
+ return ERR_PTR(-ENOENT);
+
+ return NULL;
+}
+
+static int autofs4_dir_symlink(struct inode *dir,
+ struct dentry *dentry,
+ const char *symname)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+ struct inode *inode;
+ char *cp;
+
+ DPRINTK(("autofs_dir_symlink: %s <- %.*s\n", symname,
+ dentry->d_name.len, dentry->d_name.name));
+
+ if (!S_ISDIR(dir->i_mode))
+ return -ENOTDIR;
+
+ if (!autofs4_oz_mode(sbi))
+ return -EACCES;
+
+ if (dentry->d_name.len > NAME_MAX)
+ return -ENAMETOOLONG;
+
+ if (dentry->d_inode != NULL)
+ return -EEXIST;
+
+ ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
+ if (ino == NULL)
+ return -ENOSPC;
+
+ ino->size = strlen(symname);
+ ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
+
+ if (cp == NULL) {
+ kfree(ino);
+ return -ENOSPC;
+ }
+
+ strcpy(cp, symname);
+
+ autofs4_ihash_insert(&sbi->ihash, ino);
+ inode = iget(dir->i_sb,ino->ino);
+ d_instantiate(dentry, inode);
+
+ if (dir->i_ino == AUTOFS_ROOT_INO)
+ dentry->d_op = &autofs4_root_dentry_operations;
+ else
+ dentry->d_op = &autofs4_dentry_operations;
+
+ dentry->d_fsdata = ino;
+ ino->dentry = dget(dentry);
+ ino->inode = inode;
+
+ dir->i_mtime = CURRENT_TIME;
+
+ return 0;
+}
+
+/*
+ * NOTE!
+ *
+ * Normal filesystems would do a "d_delete()" to tell the VFS dcache
+ * that the file no longer exists. However, doing that means that the
+ * VFS layer can turn the dentry into a negative dentry. We don't want
+ * this, because since the unlink is probably the result of an expire.
+ * We simply d_drop it, which allows the dentry lookup to remount it
+ * if necessary.
+ *
+ * If a process is blocked on the dentry waiting for the expire to finish,
+ * it will invalidate the dentry and try to mount with a new one.
+ *
+ * Also see autofs_dir_rmdir()..
+ */
+static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+
+ if (!S_ISDIR(dir->i_mode))
+ return -ENOTDIR;
+
+ if (dentry->d_inode == NULL)
+ return -ENOENT;
+
+ /* This allows root to remove symlinks */
+ if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
+ return -EACCES;
+
+ dput(ino->dentry);
+
+ dentry->d_inode->i_size = 0;
+ dentry->d_inode->i_nlink = 0;
+
+ dir->i_mtime = CURRENT_TIME;
+
+ DPRINTK(("autofs_dir_unlink: unlinking %p %.*s, count=%d\n",
+ dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_count));
+
+ d_drop(dentry);
+
+ return 0;
+}
+
+static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+
+ if (!S_ISDIR(dir->i_mode))
+ return -ENOTDIR;
+
+ if (dentry->d_inode == NULL)
+ return -ENOENT;
+
+ if (!autofs4_oz_mode(sbi))
+ return -EACCES;
+
+ if (!list_empty(&dentry->d_subdirs))
+ return -ENOTEMPTY;
+
+ dput(ino->dentry);
+
+ dentry->d_inode->i_size = 0;
+ dentry->d_inode->i_nlink = 0;
+
+ if (dir->i_nlink)
+ dir->i_nlink--;
+
+ DPRINTK(("autofs_dir_rmdir: rmdir %p %.*s, count=%d\n",
+ dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_count));
+
+ d_drop(dentry);
+
+ return 0;
+}
+
+
+
+static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+ struct inode *inode;
+
+ if (!S_ISDIR(dir->i_mode))
+ return -ENOTDIR;
+
+ if ( !autofs4_oz_mode(sbi) )
+ return -EACCES;
+
+ if ( dentry->d_inode != NULL )
+ return -EEXIST;
+
+ if ( dentry->d_name.len > NAME_MAX )
+ return -ENAMETOOLONG;
+
+ DPRINTK(("autofs_dir_mkdir: dentry %p, creating %.*s\n",
+ dentry, dentry->d_name.len, dentry->d_name.name));
+
+ ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
+ if (ino == NULL)
+ return -ENOSPC;
+
+ autofs4_ihash_insert(&sbi->ihash, ino);
+
+ inode = iget(dir->i_sb, ino->ino);
+ d_instantiate(dentry, inode);
+
+ if (dir->i_ino == AUTOFS_ROOT_INO)
+ dentry->d_op = &autofs4_root_dentry_operations;
+ else
+ dentry->d_op = &autofs4_dentry_operations;
+
+ dentry->d_fsdata = ino;
+ ino->dentry = dget(dentry);
+ ino->inode = inode;
+ dir->i_nlink++;
+ dir->i_mtime = CURRENT_TIME;
+
+ return 0;
+}
+
+/* Get/set timeout ioctl() operation */
+static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
+ unsigned long *p)
+{
+ int rv;
+ unsigned long ntimeout;
+
+ if ( (rv = get_user(ntimeout, p)) ||
+ (rv = put_user(sbi->exp_timeout/HZ, p)) )
+ return rv;
+
+ if ( ntimeout > ULONG_MAX/HZ )
+ sbi->exp_timeout = 0;
+ else
+ sbi->exp_timeout = ntimeout * HZ;
+
+ return 0;
+}
+
+/* Return protocol version */
+static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int *p)
+{
+ return put_user(sbi->version, p);
+}
+
+/* Identify autofs_dentries - this is so we can tell if there's
+ an extra dentry refcount or not. We only hold a refcount on the
+ dentry if its non-negative (ie, d_inode != NULL)
+*/
+int is_autofs4_dentry(struct dentry *dentry)
+{
+ return dentry && dentry->d_inode &&
+ (dentry->d_op == &autofs4_root_dentry_operations ||
+ dentry->d_op == &autofs4_dentry_operations) &&
+ dentry->d_fsdata != NULL;
+}
+
+/*
+ * ioctl()'s on the root directory is the chief method for the daemon to
+ * generate kernel reactions
+ */
+static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
+ unsigned int cmd, unsigned long arg)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
+
+ DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
+ cmd,arg,sbi,current->pgrp));
+
+ if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
+ _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT )
+ return -ENOTTY;
+
+ if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
+ return -EPERM;
+
+ switch(cmd) {
+ case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
+ return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
+ case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
+ return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
+ case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
+ autofs4_catatonic_mode(sbi);
+ return 0;
+ case AUTOFS_IOC_PROTOVER: /* Get protocol version */
+ return autofs4_get_protover(sbi, (int *)arg);
+ case AUTOFS_IOC_SETTIMEOUT:
+ return autofs4_get_set_timeout(sbi,(unsigned long *)arg);
+
+ /* return a single thing to expire */
+ case AUTOFS_IOC_EXPIRE:
+ return autofs4_expire_run(inode->i_sb,sbi,
+ (struct autofs_packet_expire *)arg);
+ /* same as above, but can send multiple expires through pipe */
+ case AUTOFS_IOC_EXPIRE_MULTI:
+ return autofs4_expire_multi(inode->i_sb, sbi, (int *)arg);
+
+ default:
+ return -ENOSYS;
+ }
+}
diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
new file mode 100644
index 000000000..b86b400cf
--- /dev/null
+++ b/fs/autofs4/symlink.c
@@ -0,0 +1,34 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/symlink.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include "autofs_i.h"
+
+static int autofs4_readlink(struct dentry *dentry, char *buffer, int buflen)
+{
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+
+ return vfs_readlink(dentry, buffer, buflen, ino->u.symlink);
+}
+
+static struct dentry * autofs4_follow_link(struct dentry *dentry,
+ struct dentry *base,
+ unsigned int flags)
+{
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+
+ return vfs_follow_link(dentry, base, flags, ino->u.symlink);
+}
+
+struct inode_operations autofs4_symlink_inode_operations = {
+ readlink: autofs4_readlink,
+ follow_link: autofs4_follow_link
+};
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
new file mode 100644
index 000000000..464c940b8
--- /dev/null
+++ b/fs/autofs4/waitq.c
@@ -0,0 +1,251 @@
+/* -*- linux-c -*- --------------------------------------------------------- *
+ *
+ * linux/fs/autofs/waitq.c
+ *
+ * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * ------------------------------------------------------------------------- */
+
+#include <linux/malloc.h>
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/file.h>
+#include "autofs_i.h"
+
+/* We make this a static variable rather than a part of the superblock; it
+ is better if we don't reassign numbers easily even across filesystems */
+static autofs_wqt_t autofs4_next_wait_queue = 1;
+
+/* These are the signals we allow interrupting a pending mount */
+#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT))
+
+void autofs4_catatonic_mode(struct autofs_sb_info *sbi)
+{
+ struct autofs_wait_queue *wq, *nwq;
+
+ DPRINTK(("autofs: entering catatonic mode\n"));
+
+ sbi->catatonic = 1;
+ wq = sbi->queues;
+ sbi->queues = NULL; /* Erase all wait queues */
+ while ( wq ) {
+ nwq = wq->next;
+ wq->status = -ENOENT; /* Magic is gone - report failure */
+ kfree(wq->name);
+ wq->name = NULL;
+ wake_up(&wq->queue);
+ wq = nwq;
+ }
+ if (sbi->pipe) {
+ fput(sbi->pipe); /* Close the pipe */
+ sbi->pipe = NULL;
+ }
+
+ autofs4_ihash_nuke(&sbi->ihash);
+ shrink_dcache_sb(sbi->sb);
+}
+
+static int autofs4_write(struct file *file, const void *addr, int bytes)
+{
+ unsigned long sigpipe, flags;
+ mm_segment_t fs;
+ const char *data = (const char *)addr;
+ ssize_t wr = 0;
+
+ /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
+
+ sigpipe = sigismember(&current->signal, SIGPIPE);
+
+ /* Save pointer to user space and point back to kernel space */
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+
+ while (bytes &&
+ (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) {
+ data += wr;
+ bytes -= wr;
+ }
+
+ set_fs(fs);
+
+ /* Keep the currently executing process from receiving a
+ SIGPIPE unless it was already supposed to get one */
+ if (wr == -EPIPE && !sigpipe) {
+ spin_lock_irqsave(&current->sigmask_lock, flags);
+ sigdelset(&current->signal, SIGPIPE);
+ recalc_sigpending(current);
+ spin_unlock_irqrestore(&current->sigmask_lock, flags);
+ }
+
+ return (bytes > 0);
+}
+
+static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
+ struct autofs_wait_queue *wq,
+ enum autofs_packet_type type)
+{
+ union autofs_packet_union pkt;
+ size_t pktsz;
+
+ DPRINTK(("autofs_notify: wait id = 0x%08lx, name = %.*s, type=%d\n",
+ wq->wait_queue_token, wq->len, wq->name, type));
+
+ memset(&pkt,0,sizeof pkt); /* For security reasons */
+
+ pkt.hdr.proto_version = sbi->version;
+ pkt.hdr.type = type;
+ if (type == autofs_ptype_missing) {
+ struct autofs_packet_missing *mp = &pkt.missing;
+
+ pktsz = sizeof(*mp);
+
+ mp->wait_queue_token = wq->wait_queue_token;
+ mp->len = wq->len;
+ memcpy(mp->name, wq->name, wq->len);
+ mp->name[wq->len] = '\0';
+ } else if (type == autofs_ptype_expire_multi) {
+ struct autofs_packet_expire_multi *ep = &pkt.expire_multi;
+
+ pktsz = sizeof(*ep);
+
+ ep->wait_queue_token = wq->wait_queue_token;
+ ep->len = wq->len;
+ memcpy(ep->name, wq->name, wq->len);
+ ep->name[wq->len] = '\0';
+ } else {
+ printk("autofs_notify_daemon: bad type %d!\n", type);
+ return;
+ }
+
+ if (autofs4_write(sbi->pipe, &pkt, pktsz))
+ autofs4_catatonic_mode(sbi);
+}
+
+int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
+ enum autofs_notify notify)
+{
+ struct autofs_wait_queue *wq;
+ int status;
+
+ /* In catatonic mode, we don't wait for nobody */
+ if ( sbi->catatonic )
+ return -ENOENT;
+
+ /* We shouldn't be able to get here, but just in case */
+ if ( name->len > NAME_MAX )
+ return -ENOENT;
+
+ for ( wq = sbi->queues ; wq ; wq = wq->next ) {
+ if ( wq->hash == name->hash &&
+ wq->len == name->len &&
+ wq->name && !memcmp(wq->name,name->name,name->len) )
+ break;
+ }
+
+ if ( !wq ) {
+ /* Create a new wait queue */
+ wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
+ if ( !wq )
+ return -ENOMEM;
+
+ wq->name = kmalloc(name->len,GFP_KERNEL);
+ if ( !wq->name ) {
+ kfree(wq);
+ return -ENOMEM;
+ }
+ wq->wait_queue_token = autofs4_next_wait_queue;
+ if (++autofs4_next_wait_queue == 0)
+ autofs4_next_wait_queue = 1;
+ init_waitqueue_head(&wq->queue);
+ wq->hash = name->hash;
+ wq->len = name->len;
+ wq->status = -EINTR; /* Status return if interrupted */
+ memcpy(wq->name, name->name, name->len);
+ wq->next = sbi->queues;
+ sbi->queues = wq;
+
+ DPRINTK(("autofs_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+ wq->wait_queue_token, wq->len, wq->name, notify));
+ /* autofs4_notify_daemon() may block */
+ wq->wait_ctr = 2;
+ if (notify != NFY_NONE) {
+ autofs4_notify_daemon(sbi,wq,
+ notify == NFY_MOUNT ? autofs_ptype_missing :
+ autofs_ptype_expire_multi);
+ }
+ } else {
+ wq->wait_ctr++;
+ DPRINTK(("autofs_wait: existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+ wq->wait_queue_token, wq->len, wq->name, notify));
+ }
+
+ /* wq->name is NULL if and only if the lock is already released */
+
+ if ( sbi->catatonic ) {
+ /* We might have slept, so check again for catatonic mode */
+ wq->status = -ENOENT;
+ if ( wq->name ) {
+ kfree(wq->name);
+ wq->name = NULL;
+ }
+ }
+
+ if ( wq->name ) {
+ /* Block all but "shutdown" signals while waiting */
+ sigset_t oldset;
+ unsigned long irqflags;
+
+ spin_lock_irqsave(&current->sigmask_lock, irqflags);
+ oldset = current->blocked;
+ siginitsetinv(&current->blocked, SHUTDOWN_SIGS & ~oldset.sig[0]);
+ recalc_sigpending(current);
+ spin_unlock_irqrestore(&current->sigmask_lock, irqflags);
+
+ interruptible_sleep_on(&wq->queue);
+
+ spin_lock_irqsave(&current->sigmask_lock, irqflags);
+ current->blocked = oldset;
+ recalc_sigpending(current);
+ spin_unlock_irqrestore(&current->sigmask_lock, irqflags);
+ } else {
+ DPRINTK(("autofs_wait: skipped sleeping\n"));
+ }
+
+ status = wq->status;
+
+ if (--wq->wait_ctr == 0) /* Are we the last process to need status? */
+ kfree(wq);
+
+ return status;
+}
+
+
+int autofs4_wait_release(struct autofs_sb_info *sbi, autofs_wqt_t wait_queue_token, int status)
+{
+ struct autofs_wait_queue *wq, **wql;
+
+ for ( wql = &sbi->queues ; (wq = *wql) ; wql = &wq->next ) {
+ if ( wq->wait_queue_token == wait_queue_token )
+ break;
+ }
+ if ( !wq )
+ return -EINVAL;
+
+ *wql = wq->next; /* Unlink from chain */
+ kfree(wq->name);
+ wq->name = NULL; /* Do not wait on this queue */
+
+ wq->status = status;
+
+ if (--wq->wait_ctr == 0) /* Is anyone still waiting for this guy? */
+ kfree(wq);
+ else
+ wake_up(&wq->queue);
+
+ return 0;
+}
+