Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
  4 * Copyright 2005-2006 Ian Kent <raven@themaw.net>
  5 */
  6
  7#include <linux/seq_file.h>
  8#include <linux/pagemap.h>
  9#include <linux/parser.h>
 10
 11#include "autofs_i.h"
 12
 13struct autofs_info *autofs_new_ino(struct autofs_sb_info *sbi)
 14{
 15	struct autofs_info *ino;
 16
 17	ino = kzalloc(sizeof(*ino), GFP_KERNEL);
 18	if (ino) {
 19		INIT_LIST_HEAD(&ino->active);
 20		INIT_LIST_HEAD(&ino->expiring);
 21		ino->last_used = jiffies;
 22		ino->sbi = sbi;
 
 23		ino->count = 1;
 24	}
 25	return ino;
 26}
 27
 28void autofs_clean_ino(struct autofs_info *ino)
 29{
 30	ino->uid = GLOBAL_ROOT_UID;
 31	ino->gid = GLOBAL_ROOT_GID;
 
 32	ino->last_used = jiffies;
 33}
 34
 35void autofs_free_ino(struct autofs_info *ino)
 36{
 37	kfree_rcu(ino, rcu);
 38}
 39
 40void autofs_kill_sb(struct super_block *sb)
 41{
 42	struct autofs_sb_info *sbi = autofs_sbi(sb);
 43
 44	/*
 45	 * In the event of a failure in get_sb_nodev the superblock
 46	 * info is not present so nothing else has been setup, so
 47	 * just call kill_anon_super when we are called from
 48	 * deactivate_super.
 49	 */
 50	if (sbi) {
 51		/* Free wait queues, close pipe */
 52		autofs_catatonic_mode(sbi);
 53		put_pid(sbi->oz_pgrp);
 54	}
 55
 56	pr_debug("shutting down\n");
 57	kill_litter_super(sb);
 58	if (sbi)
 59		kfree_rcu(sbi, rcu);
 60}
 61
 62static int autofs_show_options(struct seq_file *m, struct dentry *root)
 63{
 64	struct autofs_sb_info *sbi = autofs_sbi(root->d_sb);
 65	struct inode *root_inode = d_inode(root->d_sb->s_root);
 66
 67	if (!sbi)
 68		return 0;
 69
 70	seq_printf(m, ",fd=%d", sbi->pipefd);
 71	if (!uid_eq(root_inode->i_uid, GLOBAL_ROOT_UID))
 72		seq_printf(m, ",uid=%u",
 73			from_kuid_munged(&init_user_ns, root_inode->i_uid));
 74	if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
 75		seq_printf(m, ",gid=%u",
 76			from_kgid_munged(&init_user_ns, root_inode->i_gid));
 77	seq_printf(m, ",pgrp=%d", pid_vnr(sbi->oz_pgrp));
 78	seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
 79	seq_printf(m, ",minproto=%d", sbi->min_proto);
 80	seq_printf(m, ",maxproto=%d", sbi->max_proto);
 81
 82	if (autofs_type_offset(sbi->type))
 83		seq_puts(m, ",offset");
 84	else if (autofs_type_direct(sbi->type))
 85		seq_puts(m, ",direct");
 86	else
 87		seq_puts(m, ",indirect");
 88	if (sbi->flags & AUTOFS_SBI_STRICTEXPIRE)
 89		seq_puts(m, ",strictexpire");
 90	if (sbi->flags & AUTOFS_SBI_IGNORE)
 91		seq_puts(m, ",ignore");
 92#ifdef CONFIG_CHECKPOINT_RESTORE
 93	if (sbi->pipe)
 94		seq_printf(m, ",pipe_ino=%ld", file_inode(sbi->pipe)->i_ino);
 95	else
 96		seq_puts(m, ",pipe_ino=-1");
 97#endif
 98	return 0;
 99}
100
101static void autofs_evict_inode(struct inode *inode)
102{
103	clear_inode(inode);
104	kfree(inode->i_private);
105}
106
107static const struct super_operations autofs_sops = {
108	.statfs		= simple_statfs,
109	.show_options	= autofs_show_options,
110	.evict_inode	= autofs_evict_inode,
111};
112
113enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
114	Opt_indirect, Opt_direct, Opt_offset, Opt_strictexpire,
115	Opt_ignore};
116
117static const match_table_t tokens = {
118	{Opt_fd, "fd=%u"},
119	{Opt_uid, "uid=%u"},
120	{Opt_gid, "gid=%u"},
121	{Opt_pgrp, "pgrp=%u"},
122	{Opt_minproto, "minproto=%u"},
123	{Opt_maxproto, "maxproto=%u"},
124	{Opt_indirect, "indirect"},
125	{Opt_direct, "direct"},
126	{Opt_offset, "offset"},
127	{Opt_strictexpire, "strictexpire"},
128	{Opt_ignore, "ignore"},
129	{Opt_err, NULL}
130};
131
132static int parse_options(char *options,
133			 struct inode *root, int *pgrp, bool *pgrp_set,
134			 struct autofs_sb_info *sbi)
135{
136	char *p;
137	substring_t args[MAX_OPT_ARGS];
138	int option;
139	int pipefd = -1;
140	kuid_t uid;
141	kgid_t gid;
 
 
 
 
142
143	root->i_uid = current_uid();
144	root->i_gid = current_gid();
 
 
 
 
145
146	sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
147	sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
 
 
 
 
 
 
 
 
 
148
149	sbi->pipefd = -1;
 
 
 
 
 
 
 
 
 
 
150
151	if (!options)
152		return 1;
 
 
 
 
153
154	while ((p = strsep(&options, ",")) != NULL) {
155		int token;
156
157		if (!*p)
158			continue;
 
 
 
159
160		token = match_token(p, tokens, args);
161		switch (token) {
162		case Opt_fd:
163			if (match_int(args, &pipefd))
164				return 1;
165			sbi->pipefd = pipefd;
166			break;
167		case Opt_uid:
168			if (match_int(args, &option))
169				return 1;
170			uid = make_kuid(current_user_ns(), option);
171			if (!uid_valid(uid))
172				return 1;
173			root->i_uid = uid;
174			break;
175		case Opt_gid:
176			if (match_int(args, &option))
177				return 1;
178			gid = make_kgid(current_user_ns(), option);
179			if (!gid_valid(gid))
180				return 1;
181			root->i_gid = gid;
182			break;
183		case Opt_pgrp:
184			if (match_int(args, &option))
185				return 1;
186			*pgrp = option;
187			*pgrp_set = true;
188			break;
189		case Opt_minproto:
190			if (match_int(args, &option))
191				return 1;
192			sbi->min_proto = option;
193			break;
194		case Opt_maxproto:
195			if (match_int(args, &option))
196				return 1;
197			sbi->max_proto = option;
198			break;
199		case Opt_indirect:
200			set_autofs_type_indirect(&sbi->type);
201			break;
202		case Opt_direct:
203			set_autofs_type_direct(&sbi->type);
204			break;
205		case Opt_offset:
206			set_autofs_type_offset(&sbi->type);
207			break;
208		case Opt_strictexpire:
209			sbi->flags |= AUTOFS_SBI_STRICTEXPIRE;
210			break;
211		case Opt_ignore:
212			sbi->flags |= AUTOFS_SBI_IGNORE;
213			break;
214		default:
215			return 1;
216		}
217	}
218	return (sbi->pipefd < 0);
 
219}
220
221int autofs_fill_super(struct super_block *s, void *data, int silent)
222{
223	struct inode *root_inode;
224	struct dentry *root;
225	struct file *pipe;
226	struct autofs_sb_info *sbi;
227	struct autofs_info *ino;
228	int pgrp = 0;
229	bool pgrp_set = false;
230	int ret = -EINVAL;
231
232	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
233	if (!sbi)
234		return -ENOMEM;
235	pr_debug("starting up, sbi = %p\n", sbi);
236
237	s->s_fs_info = sbi;
238	sbi->magic = AUTOFS_SBI_MAGIC;
239	sbi->pipefd = -1;
240	sbi->pipe = NULL;
241	sbi->exp_timeout = 0;
242	sbi->oz_pgrp = NULL;
243	sbi->sb = s;
244	sbi->version = 0;
245	sbi->sub_version = 0;
246	sbi->flags = AUTOFS_SBI_CATATONIC;
 
 
 
 
247	set_autofs_type_indirect(&sbi->type);
248	sbi->min_proto = 0;
249	sbi->max_proto = 0;
250	mutex_init(&sbi->wq_mutex);
251	mutex_init(&sbi->pipe_mutex);
252	spin_lock_init(&sbi->fs_lock);
253	sbi->queues = NULL;
254	spin_lock_init(&sbi->lookup_lock);
255	INIT_LIST_HEAD(&sbi->active_list);
256	INIT_LIST_HEAD(&sbi->expiring_list);
257	s->s_blocksize = 1024;
258	s->s_blocksize_bits = 10;
259	s->s_magic = AUTOFS_SUPER_MAGIC;
260	s->s_op = &autofs_sops;
261	s->s_d_op = &autofs_dentry_operations;
262	s->s_time_gran = 1;
263
264	/*
265	 * Get the root inode and dentry, but defer checking for errors.
266	 */
267	ino = autofs_new_ino(sbi);
268	if (!ino) {
269		ret = -ENOMEM;
270		goto fail_free;
271	}
272	root_inode = autofs_get_inode(s, S_IFDIR | 0755);
273	root = d_make_root(root_inode);
274	if (!root) {
275		ret = -ENOMEM;
276		goto fail_ino;
277	}
278	pipe = NULL;
279
280	root->d_fsdata = ino;
281
282	/* Can this call block? */
283	if (parse_options(data, root_inode, &pgrp, &pgrp_set, sbi)) {
284		pr_err("called with bogus options\n");
285		goto fail_dput;
286	}
287
288	/* Test versions first */
289	if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
290	    sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
291		pr_err("kernel does not match daemon version "
292		       "daemon (%d, %d) kernel (%d, %d)\n",
293		       sbi->min_proto, sbi->max_proto,
294		       AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
295		goto fail_dput;
296	}
297
298	/* Establish highest kernel protocol version */
299	if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
300		sbi->version = AUTOFS_MAX_PROTO_VERSION;
301	else
302		sbi->version = sbi->max_proto;
303	sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
304
305	if (pgrp_set) {
306		sbi->oz_pgrp = find_get_pid(pgrp);
307		if (!sbi->oz_pgrp) {
308			pr_err("could not find process group %d\n",
309				pgrp);
310			goto fail_dput;
311		}
312	} else {
313		sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
314	}
315
316	if (autofs_type_trigger(sbi->type))
317		__managed_dentry_set_managed(root);
 
 
 
 
 
 
 
 
 
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319	root_inode->i_fop = &autofs_root_operations;
320	root_inode->i_op = &autofs_dir_inode_operations;
321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322	pr_debug("pipe fd = %d, pgrp = %u\n",
323		 sbi->pipefd, pid_nr(sbi->oz_pgrp));
324	pipe = fget(sbi->pipefd);
325
326	if (!pipe) {
327		pr_err("could not open pipe file descriptor\n");
328		goto fail_put_pid;
329	}
330	ret = autofs_prepare_pipe(pipe);
331	if (ret < 0)
332		goto fail_fput;
333	sbi->pipe = pipe;
334	sbi->flags &= ~AUTOFS_SBI_CATATONIC;
 
 
335
336	/*
337	 * Success! Install the root dentry now to indicate completion.
338	 */
339	s->s_root = root;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340	return 0;
341
342	/*
343	 * Failure ... clean up.
344	 */
345fail_fput:
346	pr_err("pipe file descriptor does not contain proper ops\n");
347	fput(pipe);
348fail_put_pid:
349	put_pid(sbi->oz_pgrp);
350fail_dput:
351	dput(root);
352	goto fail_free;
353fail_ino:
354	autofs_free_ino(ino);
355fail_free:
356	kfree(sbi);
357	s->s_fs_info = NULL;
358	return ret;
359}
360
361struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
362{
363	struct inode *inode = new_inode(sb);
364
365	if (inode == NULL)
366		return NULL;
367
368	inode->i_mode = mode;
369	if (sb->s_root) {
370		inode->i_uid = d_inode(sb->s_root)->i_uid;
371		inode->i_gid = d_inode(sb->s_root)->i_gid;
372	}
373	inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
374	inode->i_ino = get_next_ino();
375
376	if (S_ISDIR(mode)) {
377		set_nlink(inode, 2);
378		inode->i_op = &autofs_dir_inode_operations;
379		inode->i_fop = &autofs_dir_operations;
380	} else if (S_ISLNK(mode)) {
381		inode->i_op = &autofs_symlink_inode_operations;
382	} else
383		WARN_ON(1);
384
385	return inode;
386}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
  4 * Copyright 2005-2006 Ian Kent <raven@themaw.net>
  5 */
  6
  7#include <linux/seq_file.h>
  8#include <linux/pagemap.h>
 
  9
 10#include "autofs_i.h"
 11
 12struct autofs_info *autofs_new_ino(struct autofs_sb_info *sbi)
 13{
 14	struct autofs_info *ino;
 15
 16	ino = kzalloc(sizeof(*ino), GFP_KERNEL);
 17	if (ino) {
 18		INIT_LIST_HEAD(&ino->active);
 19		INIT_LIST_HEAD(&ino->expiring);
 20		ino->last_used = jiffies;
 21		ino->sbi = sbi;
 22		ino->exp_timeout = -1;
 23		ino->count = 1;
 24	}
 25	return ino;
 26}
 27
 28void autofs_clean_ino(struct autofs_info *ino)
 29{
 30	ino->uid = GLOBAL_ROOT_UID;
 31	ino->gid = GLOBAL_ROOT_GID;
 32	ino->exp_timeout = -1;
 33	ino->last_used = jiffies;
 34}
 35
 36void autofs_free_ino(struct autofs_info *ino)
 37{
 38	kfree_rcu(ino, rcu);
 39}
 40
 41void autofs_kill_sb(struct super_block *sb)
 42{
 43	struct autofs_sb_info *sbi = autofs_sbi(sb);
 44
 45	/*
 46	 * In the event of a failure in get_sb_nodev the superblock
 47	 * info is not present so nothing else has been setup, so
 48	 * just call kill_anon_super when we are called from
 49	 * deactivate_super.
 50	 */
 51	if (sbi) {
 52		/* Free wait queues, close pipe */
 53		autofs_catatonic_mode(sbi);
 54		put_pid(sbi->oz_pgrp);
 55	}
 56
 57	pr_debug("shutting down\n");
 58	kill_litter_super(sb);
 59	if (sbi)
 60		kfree_rcu(sbi, rcu);
 61}
 62
 63static int autofs_show_options(struct seq_file *m, struct dentry *root)
 64{
 65	struct autofs_sb_info *sbi = autofs_sbi(root->d_sb);
 66	struct inode *root_inode = d_inode(root->d_sb->s_root);
 67
 68	if (!sbi)
 69		return 0;
 70
 71	seq_printf(m, ",fd=%d", sbi->pipefd);
 72	if (!uid_eq(root_inode->i_uid, GLOBAL_ROOT_UID))
 73		seq_printf(m, ",uid=%u",
 74			from_kuid_munged(&init_user_ns, root_inode->i_uid));
 75	if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
 76		seq_printf(m, ",gid=%u",
 77			from_kgid_munged(&init_user_ns, root_inode->i_gid));
 78	seq_printf(m, ",pgrp=%d", pid_vnr(sbi->oz_pgrp));
 79	seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
 80	seq_printf(m, ",minproto=%d", sbi->min_proto);
 81	seq_printf(m, ",maxproto=%d", sbi->max_proto);
 82
 83	if (autofs_type_offset(sbi->type))
 84		seq_puts(m, ",offset");
 85	else if (autofs_type_direct(sbi->type))
 86		seq_puts(m, ",direct");
 87	else
 88		seq_puts(m, ",indirect");
 89	if (sbi->flags & AUTOFS_SBI_STRICTEXPIRE)
 90		seq_puts(m, ",strictexpire");
 91	if (sbi->flags & AUTOFS_SBI_IGNORE)
 92		seq_puts(m, ",ignore");
 93#ifdef CONFIG_CHECKPOINT_RESTORE
 94	if (sbi->pipe)
 95		seq_printf(m, ",pipe_ino=%ld", file_inode(sbi->pipe)->i_ino);
 96	else
 97		seq_puts(m, ",pipe_ino=-1");
 98#endif
 99	return 0;
100}
101
102static void autofs_evict_inode(struct inode *inode)
103{
104	clear_inode(inode);
105	kfree(inode->i_private);
106}
107
108static const struct super_operations autofs_sops = {
109	.statfs		= simple_statfs,
110	.show_options	= autofs_show_options,
111	.evict_inode	= autofs_evict_inode,
112};
113
114enum {
115	Opt_direct,
116	Opt_fd,
117	Opt_gid,
118	Opt_ignore,
119	Opt_indirect,
120	Opt_maxproto,
121	Opt_minproto,
122	Opt_offset,
123	Opt_pgrp,
124	Opt_strictexpire,
125	Opt_uid,
 
 
 
 
 
126};
127
128const struct fs_parameter_spec autofs_param_specs[] = {
129	fsparam_flag	("direct",		Opt_direct),
130	fsparam_fd	("fd",			Opt_fd),
131	fsparam_gid	("gid",			Opt_gid),
132	fsparam_flag	("ignore",		Opt_ignore),
133	fsparam_flag	("indirect",		Opt_indirect),
134	fsparam_u32	("maxproto",		Opt_maxproto),
135	fsparam_u32	("minproto",		Opt_minproto),
136	fsparam_flag	("offset",		Opt_offset),
137	fsparam_u32	("pgrp",		Opt_pgrp),
138	fsparam_flag	("strictexpire",	Opt_strictexpire),
139	fsparam_uid	("uid",			Opt_uid),
140	{}
141};
142
143struct autofs_fs_context {
144	kuid_t	uid;
145	kgid_t	gid;
146	int	pgrp;
147	bool	pgrp_set;
148};
149
150/*
151 * Open the fd.  We do it here rather than in get_tree so that it's done in the
152 * context of the system call that passed the data and not the one that
153 * triggered the superblock creation, lest the fd gets reassigned.
154 */
155static int autofs_parse_fd(struct fs_context *fc, struct autofs_sb_info *sbi,
156			   struct fs_parameter *param,
157			   struct fs_parse_result *result)
158{
159	struct file *pipe;
160	int ret;
161
162	if (param->type == fs_value_is_file) {
163		/* came through the new api */
164		pipe = param->file;
165		param->file = NULL;
166	} else {
167		pipe = fget(result->uint_32);
168	}
169	if (!pipe) {
170		errorf(fc, "could not open pipe file descriptor");
171		return -EBADF;
172	}
173
174	ret = autofs_check_pipe(pipe);
175	if (ret < 0) {
176		errorf(fc, "Invalid/unusable pipe");
177		fput(pipe);
178		return -EBADF;
179	}
180
181	autofs_set_packet_pipe_flags(pipe);
 
182
183	if (sbi->pipe)
184		fput(sbi->pipe);
185
186	sbi->pipefd = result->uint_32;
187	sbi->pipe = pipe;
188
189	return 0;
190}
191
192static int autofs_parse_param(struct fs_context *fc, struct fs_parameter *param)
193{
194	struct autofs_fs_context *ctx = fc->fs_private;
195	struct autofs_sb_info *sbi = fc->s_fs_info;
196	struct fs_parse_result result;
197	int opt;
198
199	opt = fs_parse(fc, autofs_param_specs, param, &result);
200	if (opt < 0)
201		return opt;
202
203	switch (opt) {
204	case Opt_fd:
205		return autofs_parse_fd(fc, sbi, param, &result);
206	case Opt_uid:
207		ctx->uid = result.uid;
208		break;
209	case Opt_gid:
210		ctx->gid = result.gid;
211		break;
212	case Opt_pgrp:
213		ctx->pgrp = result.uint_32;
214		ctx->pgrp_set = true;
215		break;
216	case Opt_minproto:
217		sbi->min_proto = result.uint_32;
218		break;
219	case Opt_maxproto:
220		sbi->max_proto = result.uint_32;
221		break;
222	case Opt_indirect:
223		set_autofs_type_indirect(&sbi->type);
224		break;
225	case Opt_direct:
226		set_autofs_type_direct(&sbi->type);
227		break;
228	case Opt_offset:
229		set_autofs_type_offset(&sbi->type);
230		break;
231	case Opt_strictexpire:
232		sbi->flags |= AUTOFS_SBI_STRICTEXPIRE;
233		break;
234	case Opt_ignore:
235		sbi->flags |= AUTOFS_SBI_IGNORE;
 
 
 
 
 
 
 
 
 
 
236	}
237
238	return 0;
239}
240
241static struct autofs_sb_info *autofs_alloc_sbi(void)
242{
 
 
 
243	struct autofs_sb_info *sbi;
 
 
 
 
244
245	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
246	if (!sbi)
247		return NULL;
 
248
 
249	sbi->magic = AUTOFS_SBI_MAGIC;
 
 
 
 
 
 
 
250	sbi->flags = AUTOFS_SBI_CATATONIC;
251	sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
252	sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
253	sbi->pipefd = -1;
254
255	set_autofs_type_indirect(&sbi->type);
 
 
256	mutex_init(&sbi->wq_mutex);
257	mutex_init(&sbi->pipe_mutex);
258	spin_lock_init(&sbi->fs_lock);
 
259	spin_lock_init(&sbi->lookup_lock);
260	INIT_LIST_HEAD(&sbi->active_list);
261	INIT_LIST_HEAD(&sbi->expiring_list);
 
 
 
 
 
 
262
263	return sbi;
264}
265
266static int autofs_validate_protocol(struct fs_context *fc)
267{
268	struct autofs_sb_info *sbi = fc->s_fs_info;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
270	/* Test versions first */
271	if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
272	    sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
273		errorf(fc, "kernel does not match daemon version "
274		       "daemon (%d, %d) kernel (%d, %d)\n",
275		       sbi->min_proto, sbi->max_proto,
276		       AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
277		return -EINVAL;
278	}
279
280	/* Establish highest kernel protocol version */
281	if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
282		sbi->version = AUTOFS_MAX_PROTO_VERSION;
283	else
284		sbi->version = sbi->max_proto;
 
285
286	switch (sbi->version) {
287	case 4:
288		sbi->sub_version = 7;
289		break;
290	case 5:
291		sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
292		break;
293	default:
294		sbi->sub_version = 0;
295	}
296
297	return 0;
298}
299
300static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
301{
302	struct autofs_fs_context *ctx = fc->fs_private;
303	struct autofs_sb_info *sbi = s->s_fs_info;
304	struct inode *root_inode;
305	struct autofs_info *ino;
306
307	pr_debug("starting up, sbi = %p\n", sbi);
308
309	sbi->sb = s;
310	s->s_blocksize = 1024;
311	s->s_blocksize_bits = 10;
312	s->s_magic = AUTOFS_SUPER_MAGIC;
313	s->s_op = &autofs_sops;
314	s->s_d_op = &autofs_dentry_operations;
315	s->s_time_gran = 1;
316
317	/*
318	 * Get the root inode and dentry, but defer checking for errors.
319	 */
320	ino = autofs_new_ino(sbi);
321	if (!ino)
322		return -ENOMEM;
323
324	root_inode = autofs_get_inode(s, S_IFDIR | 0755);
325	if (!root_inode)
326		return -ENOMEM;
327
328	root_inode->i_uid = ctx->uid;
329	root_inode->i_gid = ctx->gid;
330	root_inode->i_fop = &autofs_root_operations;
331	root_inode->i_op = &autofs_dir_inode_operations;
332
333	s->s_root = d_make_root(root_inode);
334	if (unlikely(!s->s_root)) {
335		autofs_free_ino(ino);
336		return -ENOMEM;
337	}
338	s->s_root->d_fsdata = ino;
339
340	if (ctx->pgrp_set) {
341		sbi->oz_pgrp = find_get_pid(ctx->pgrp);
342		if (!sbi->oz_pgrp)
343			return invalf(fc, "Could not find process group %d",
344				      ctx->pgrp);
345	} else
346		sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
347
348	if (autofs_type_trigger(sbi->type))
349		/* s->s_root won't be contended so there's little to
350		 * be gained by not taking the d_lock when setting
351		 * d_flags, even when a lot mounts are being done.
352		 */
353		managed_dentry_set_managed(s->s_root);
354
355	pr_debug("pipe fd = %d, pgrp = %u\n",
356		 sbi->pipefd, pid_nr(sbi->oz_pgrp));
 
357
 
 
 
 
 
 
 
 
358	sbi->flags &= ~AUTOFS_SBI_CATATONIC;
359	return 0;
360}
361
362/*
363 * Validate the parameters and then request a superblock.
364 */
365static int autofs_get_tree(struct fs_context *fc)
366{
367	struct autofs_sb_info *sbi = fc->s_fs_info;
368	int ret;
369
370	ret = autofs_validate_protocol(fc);
371	if (ret)
372		return ret;
373
374	if (sbi->pipefd < 0)
375		return invalf(fc, "No control pipe specified");
376
377	return get_tree_nodev(fc, autofs_fill_super);
378}
379
380static void autofs_free_fc(struct fs_context *fc)
381{
382	struct autofs_fs_context *ctx = fc->fs_private;
383	struct autofs_sb_info *sbi = fc->s_fs_info;
384
385	if (sbi) {
386		if (sbi->pipe)
387			fput(sbi->pipe);
388		kfree(sbi);
389	}
390	kfree(ctx);
391}
392
393static const struct fs_context_operations autofs_context_ops = {
394	.free		= autofs_free_fc,
395	.parse_param	= autofs_parse_param,
396	.get_tree	= autofs_get_tree,
397};
398
399/*
400 * Set up the filesystem mount context.
401 */
402int autofs_init_fs_context(struct fs_context *fc)
403{
404	struct autofs_fs_context *ctx;
405	struct autofs_sb_info *sbi;
406
407	ctx = kzalloc(sizeof(struct autofs_fs_context), GFP_KERNEL);
408	if (!ctx)
409		goto nomem;
410
411	ctx->uid = current_uid();
412	ctx->gid = current_gid();
413
414	sbi = autofs_alloc_sbi();
415	if (!sbi)
416		goto nomem_ctx;
417
418	fc->fs_private = ctx;
419	fc->s_fs_info = sbi;
420	fc->ops = &autofs_context_ops;
421	return 0;
422
423nomem_ctx:
424	kfree(ctx);
425nomem:
426	return -ENOMEM;
 
 
 
 
 
 
 
 
 
 
 
 
 
427}
428
429struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
430{
431	struct inode *inode = new_inode(sb);
432
433	if (inode == NULL)
434		return NULL;
435
436	inode->i_mode = mode;
437	if (sb->s_root) {
438		inode->i_uid = d_inode(sb->s_root)->i_uid;
439		inode->i_gid = d_inode(sb->s_root)->i_gid;
440	}
441	simple_inode_init_ts(inode);
442	inode->i_ino = get_next_ino();
443
444	if (S_ISDIR(mode)) {
445		set_nlink(inode, 2);
446		inode->i_op = &autofs_dir_inode_operations;
447		inode->i_fop = &autofs_dir_operations;
448	} else if (S_ISLNK(mode)) {
449		inode->i_op = &autofs_symlink_inode_operations;
450	} else
451		WARN_ON(1);
452
453	return inode;
454}