1/* -*- c -*- ------------------------------------------------------------- *
2 *
3 * linux/fs/autofs/autofs_i.h
4 *
5 *   Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
6 *
7 * This file is part of the Linux kernel and is made available under
8 * the terms of the GNU General Public License, version 2, or at your
9 * option, any later version, incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/* Internal header file for autofs */
14
15#include <linux/auto_fs4.h>
16#include <linux/list.h>
17
18/* This is the range of ioctl() numbers we claim as ours */
19#define AUTOFS_IOC_FIRST     AUTOFS_IOC_READY
20#define AUTOFS_IOC_COUNT     32
21
22#include <linux/kernel.h>
23#include <linux/slab.h>
24#include <linux/sched.h>
25#include <linux/string.h>
26#include <linux/wait.h>
27#include <asm/uaccess.h>
28
29/* #define DEBUG */
30
31#ifdef DEBUG
32#define DPRINTK(D) do{ printk("pid %d: ", current->pid); printk D; } while(0)
33#else
34#define DPRINTK(D) do {} while(0)
35#endif
36
37#define AUTOFS_SUPER_MAGIC 0x0187
38
39/*
40 * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
41 * kernel will keep the negative response cached for up to the time given
42 * here, although the time can be shorter if the kernel throws the dcache
43 * entry away.  This probably should be settable from user space.
44 */
45#define AUTOFS_NEGATIVE_TIMEOUT (60*HZ)	/* 1 minute */
46
47/* Unified info structure.  This is pointed to by both the dentry and
48   inode structures.  Each file in the filesystem has an instance of this
49   structure.  It holds a reference to the dentry, so dentries are never
50   flushed while the file exists.  All name lookups are dealt with at the
51   dentry level, although the filesystem can interfere in the validation
52   process.  Readdir is implemented by traversing the dentry lists. */
53struct autofs_info {
54	struct dentry	*dentry;
55	struct inode	*inode;
56
57	int		flags;
58
59	struct autofs_sb_info *sbi;
60	unsigned long last_used;
61
62	mode_t	mode;
63	size_t	size;
64
65	void (*free)(struct autofs_info *);
66	union {
67		const char *symlink;
68	} u;
69};
70
71#define AUTOFS_INF_EXPIRING	(1<<0) /* dentry is in the process of expiring */
72
73struct autofs_wait_queue {
74	wait_queue_head_t queue;
75	struct autofs_wait_queue *next;
76	autofs_wqt_t wait_queue_token;
77	/* We use the following to see what we are waiting for */
78	int hash;
79	int len;
80	char *name;
81	/* This is for status reporting upon return */
82	int status;
83	int wait_ctr;
84};
85
86#define AUTOFS_SBI_MAGIC 0x6d4a556d
87
88struct autofs_sb_info {
89	u32 magic;
90	struct file *pipe;
91	pid_t oz_pgrp;
92	int catatonic;
93	int version;
94	unsigned long exp_timeout;
95	struct super_block *sb;
96	struct autofs_wait_queue *queues; /* Wait queue pointer */
97};
98
99static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
100{
101	return (struct autofs_sb_info *)(sb->u.generic_sbp);
102}
103
104static inline struct autofs_info *autofs4_dentry_ino(struct dentry *dentry)
105{
106	return (struct autofs_info *)(dentry->d_fsdata);
107}
108
109/* autofs4_oz_mode(): do we see the man behind the curtain?  (The
110   processes which do manipulations for us in user space sees the raw
111   filesystem without "magic".) */
112
113static inline int autofs4_oz_mode(struct autofs_sb_info *sbi) {
114	return sbi->catatonic || current->pgrp == sbi->oz_pgrp;
115}
116
117/* Does a dentry have some pending activity? */
118static inline int autofs4_ispending(struct dentry *dentry)
119{
120	struct autofs_info *inf = autofs4_dentry_ino(dentry);
121
122	return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
123		(inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
124}
125
126struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
127struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
128void autofs4_free_ino(struct autofs_info *);
129
130/* Expiration */
131int is_autofs4_dentry(struct dentry *);
132int autofs4_expire_run(struct super_block *, struct vfsmount *,
133			struct autofs_sb_info *, struct autofs_packet_expire *);
134int autofs4_expire_multi(struct super_block *, struct vfsmount *,
135			struct autofs_sb_info *, int *);
136
137/* Operations structures */
138
139extern struct inode_operations autofs4_symlink_inode_operations;
140extern struct inode_operations autofs4_dir_inode_operations;
141extern struct inode_operations autofs4_root_inode_operations;
142extern struct file_operations autofs4_root_operations;
143
144/* Initializing function */
145
146struct super_block *autofs4_read_super(struct super_block *, void *,int);
147struct autofs_info *autofs4_init_ino(struct autofs_info *, struct autofs_sb_info *sbi, mode_t mode);
148
149/* Queue management functions */
150
151enum autofs_notify
152{
153	NFY_NONE,
154	NFY_MOUNT,
155	NFY_EXPIRE
156};
157
158int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
159int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
160void autofs4_catatonic_mode(struct autofs_sb_info *);
161