Blame view

fs/ncpfs/inode.c 27 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
  /*
   *  inode.c
   *
   *  Copyright (C) 1995, 1996 by Volker Lendecke
   *  Modified for big endian by J.F. Chadima and David S. Miller
   *  Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
   *  Modified 1998 Wolfram Pienkoss for NLS
   *  Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
   *
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <linux/module.h>
  
  #include <asm/system.h>
  #include <asm/uaccess.h>
  #include <asm/byteorder.h>
  
  #include <linux/time.h>
  #include <linux/kernel.h>
  #include <linux/mm.h>
  #include <linux/string.h>
  #include <linux/stat.h>
  #include <linux/errno.h>
  #include <linux/file.h>
  #include <linux/fcntl.h>
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
  #include <linux/init.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  #include <linux/vfs.h>
564cd138c   Miklos Szeredi   mount options: fi...
29
30
  #include <linux/mount.h>
  #include <linux/seq_file.h>
34286d666   Nick Piggin   fs: rcu-walk awar...
31
  #include <linux/namei.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
  #include <net/sock.h>
32c419d95   Al Viro   move internal-onl...
34
  #include "ncp_fs.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  #include "getopt.h"
564cd138c   Miklos Szeredi   mount options: fi...
36
37
38
39
  #define NCP_DEFAULT_FILE_MODE 0600
  #define NCP_DEFAULT_DIR_MODE 0700
  #define NCP_DEFAULT_TIME_OUT 10
  #define NCP_DEFAULT_RETRY_COUNT 20
94ee8494a   Al Viro   switch ncpfs to -...
40
  static void ncp_evict_inode(struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  static void ncp_put_super(struct super_block *);
726c33422   David Howells   [PATCH] VFS: Perm...
42
  static int  ncp_statfs(struct dentry *, struct kstatfs *);
34c80b1d9   Al Viro   vfs: switch ->sho...
43
  static int  ncp_show_options(struct seq_file *, struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44

e18b890bb   Christoph Lameter   [PATCH] slab: rem...
45
  static struct kmem_cache * ncp_inode_cachep;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
  
  static struct inode *ncp_alloc_inode(struct super_block *sb)
  {
  	struct ncp_inode_info *ei;
e94b17660   Christoph Lameter   [PATCH] slab: rem...
50
  	ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
53
54
  	if (!ei)
  		return NULL;
  	return &ei->vfs_inode;
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
55
  static void ncp_i_callback(struct rcu_head *head)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
  {
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
57
  	struct inode *inode = container_of(head, struct inode, i_rcu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
  	kmem_cache_free(ncp_inode_cachep, NCP_FINFO(inode));
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
60
61
62
63
  static void ncp_destroy_inode(struct inode *inode)
  {
  	call_rcu(&inode->i_rcu, ncp_i_callback);
  }
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
64
  static void init_once(void *foo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
  {
  	struct ncp_inode_info *ei = (struct ncp_inode_info *) foo;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
67
68
  	mutex_init(&ei->open_mutex);
  	inode_init_once(&ei->vfs_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  }
20c2df83d   Paul Mundt   mm: Remove slab d...
70

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
  static int init_inodecache(void)
  {
  	ncp_inode_cachep = kmem_cache_create("ncp_inode_cache",
  					     sizeof(struct ncp_inode_info),
fffb60f93   Paul Jackson   [PATCH] cpuset me...
75
76
  					     0, (SLAB_RECLAIM_ACCOUNT|
  						SLAB_MEM_SPREAD),
20c2df83d   Paul Mundt   mm: Remove slab d...
77
  					     init_once);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
84
  	if (ncp_inode_cachep == NULL)
  		return -ENOMEM;
  	return 0;
  }
  
  static void destroy_inodecache(void)
  {
1a1d92c10   Alexey Dobriyan   [PATCH] Really ig...
85
  	kmem_cache_destroy(ncp_inode_cachep);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
88
89
90
91
92
  }
  
  static int ncp_remount(struct super_block *sb, int *flags, char* data)
  {
  	*flags |= MS_NODIRATIME;
  	return 0;
  }
ee9b6d61a   Josef 'Jeff' Sipek   [PATCH] Mark stru...
93
  static const struct super_operations ncp_sops =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
96
97
  {
  	.alloc_inode	= ncp_alloc_inode,
  	.destroy_inode	= ncp_destroy_inode,
  	.drop_inode	= generic_delete_inode,
94ee8494a   Al Viro   switch ncpfs to -...
98
  	.evict_inode	= ncp_evict_inode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
101
  	.put_super	= ncp_put_super,
  	.statfs		= ncp_statfs,
  	.remount_fs	= ncp_remount,
564cd138c   Miklos Szeredi   mount options: fi...
102
  	.show_options	= ncp_show_options,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  /*
   * Fill in the ncpfs-specific information in the inode.
   */
  static void ncp_update_dirent(struct inode *inode, struct ncp_entry_info *nwinfo)
  {
  	NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;
  	NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;
  	NCP_FINFO(inode)->volNumber = nwinfo->volume;
  }
  
  void ncp_update_inode(struct inode *inode, struct ncp_entry_info *nwinfo)
  {
  	ncp_update_dirent(inode, nwinfo);
  	NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
  	NCP_FINFO(inode)->access = nwinfo->access;
  	memcpy(NCP_FINFO(inode)->file_handle, nwinfo->file_handle,
  			sizeof(nwinfo->file_handle));
  	DPRINTK("ncp_update_inode: updated %s, volnum=%d, dirent=%u
  ",
  		nwinfo->i.entryName, NCP_FINFO(inode)->volNumber,
  		NCP_FINFO(inode)->dirEntNum);
  }
  
  static void ncp_update_dates(struct inode *inode, struct nw_info_struct *nwi)
  {
  	/* NFS namespace mode overrides others if it's set. */
  	DPRINTK(KERN_DEBUG "ncp_update_dates_and_mode: (%s) nfs.mode=0%o
  ",
  		nwi->entryName, nwi->nfs.mode);
  	if (nwi->nfs.mode) {
  		/* XXX Security? */
  		inode->i_mode = nwi->nfs.mode;
  	}
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
137
  	inode->i_blocks = (i_size_read(inode) + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  
  	inode->i_mtime.tv_sec = ncp_date_dos2unix(nwi->modifyTime, nwi->modifyDate);
  	inode->i_ctime.tv_sec = ncp_date_dos2unix(nwi->creationTime, nwi->creationDate);
  	inode->i_atime.tv_sec = ncp_date_dos2unix(0, nwi->lastAccessDate);
  	inode->i_atime.tv_nsec = 0;
  	inode->i_mtime.tv_nsec = 0;
  	inode->i_ctime.tv_nsec = 0;
  }
  
  static void ncp_update_attrs(struct inode *inode, struct ncp_entry_info *nwinfo)
  {
  	struct nw_info_struct *nwi = &nwinfo->i;
  	struct ncp_server *server = NCP_SERVER(inode);
  
  	if (nwi->attributes & aDIR) {
  		inode->i_mode = server->m.dir_mode;
  		/* for directories dataStreamSize seems to be some
  		   Object ID ??? */
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
156
  		i_size_write(inode, NCP_BLOCK_SIZE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
  	} else {
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
158
  		u32 size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
  		inode->i_mode = server->m.file_mode;
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
160
161
  		size = le32_to_cpu(nwi->dataStreamSize);
  		i_size_write(inode, size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
163
164
165
166
167
  #ifdef CONFIG_NCPFS_EXTRAS
  		if ((server->m.flags & (NCP_MOUNT_EXTRAS|NCP_MOUNT_SYMLINKS)) 
  		 && (nwi->attributes & aSHARED)) {
  			switch (nwi->attributes & (aHIDDEN|aSYSTEM)) {
  				case aHIDDEN:
  					if (server->m.flags & NCP_MOUNT_SYMLINKS) {
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
168
169
  						if (/* (size >= NCP_MIN_SYMLINK_SIZE)
  						 && */ (size <= NCP_MAX_SYMLINK_SIZE)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  							inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFLNK;
  							NCP_FINFO(inode)->flags |= NCPI_KLUDGE_SYMLINK;
  							break;
  						}
  					}
  					/* FALLTHROUGH */
  				case 0:
  					if (server->m.flags & NCP_MOUNT_EXTRAS)
  						inode->i_mode |= S_IRUGO;
  					break;
  				case aSYSTEM:
  					if (server->m.flags & NCP_MOUNT_EXTRAS)
  						inode->i_mode |= (inode->i_mode >> 2) & S_IXUGO;
  					break;
  				/* case aSYSTEM|aHIDDEN: */
  				default:
  					/* reserved combination */
  					break;
  			}
  		}
  #endif
  	}
  	if (nwi->attributes & aRONLY) inode->i_mode &= ~S_IWUGO;
  }
  
  void ncp_update_inode2(struct inode* inode, struct ncp_entry_info *nwinfo)
  {
  	NCP_FINFO(inode)->flags = 0;
  	if (!atomic_read(&NCP_FINFO(inode)->opened)) {
  		NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
  		ncp_update_attrs(inode, nwinfo);
  	}
  
  	ncp_update_dates(inode, &nwinfo->i);
  	ncp_update_dirent(inode, nwinfo);
  }
  
  /*
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
208
   * Fill in the inode based on the ncp_entry_info structure.  Used only for brand new inodes.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
211
212
213
214
215
216
217
218
219
   */
  static void ncp_set_attr(struct inode *inode, struct ncp_entry_info *nwinfo)
  {
  	struct ncp_server *server = NCP_SERVER(inode);
  
  	NCP_FINFO(inode)->flags = 0;
  	
  	ncp_update_attrs(inode, nwinfo);
  
  	DDPRINTK("ncp_read_inode: inode->i_mode = %u
  ", inode->i_mode);
bfe868486   Miklos Szeredi   filesystems: add ...
220
  	set_nlink(inode, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
  	inode->i_uid = server->m.uid;
  	inode->i_gid = server->m.gid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
226
227
228
  
  	ncp_update_dates(inode, &nwinfo->i);
  	ncp_update_inode(inode, nwinfo);
  }
  
  #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
92e1d5be9   Arjan van de Ven   [PATCH] mark stru...
229
  static const struct inode_operations ncp_symlink_inode_operations = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  	.readlink	= generic_readlink,
  	.follow_link	= page_follow_link_light,
  	.put_link	= page_put_link,
  	.setattr	= ncp_notify_change,
  };
  #endif
  
  /*
   * Get a new inode.
   */
  struct inode * 
  ncp_iget(struct super_block *sb, struct ncp_entry_info *info)
  {
  	struct inode *inode;
  
  	if (info == NULL) {
  		printk(KERN_ERR "ncp_iget: info is NULL
  ");
  		return NULL;
  	}
  
  	inode = new_inode(sb);
  	if (inode) {
  		atomic_set(&NCP_FINFO(inode)->opened, info->opened);
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
254
  		inode->i_mapping->backing_dev_info = sb->s_bdi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
  		inode->i_ino = info->ino;
  		ncp_set_attr(inode, info);
  		if (S_ISREG(inode->i_mode)) {
  			inode->i_op = &ncp_file_inode_operations;
  			inode->i_fop = &ncp_file_operations;
  		} else if (S_ISDIR(inode->i_mode)) {
  			inode->i_op = &ncp_dir_inode_operations;
  			inode->i_fop = &ncp_dir_operations;
  #ifdef CONFIG_NCPFS_NFS_NS
  		} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
  			init_special_inode(inode, inode->i_mode,
  				new_decode_dev(info->i.nfs.rdev));
  #endif
  #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
  		} else if (S_ISLNK(inode->i_mode)) {
  			inode->i_op = &ncp_symlink_inode_operations;
  			inode->i_data.a_ops = &ncp_symlink_aops;
  #endif
  		} else {
  			make_bad_inode(inode);
  		}
  		insert_inode_hash(inode);
  	} else
  		printk(KERN_ERR "ncp_iget: iget failed!
  ");
  	return inode;
  }
  
  static void
94ee8494a   Al Viro   switch ncpfs to -...
284
  ncp_evict_inode(struct inode *inode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
  {
fef266580   Mark Fasheh   [PATCH] update fi...
286
  	truncate_inode_pages(&inode->i_data, 0);
94ee8494a   Al Viro   switch ncpfs to -...
287
  	end_writeback(inode);
fef266580   Mark Fasheh   [PATCH] update fi...
288

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
  	if (S_ISDIR(inode->i_mode)) {
94ee8494a   Al Viro   switch ncpfs to -...
290
291
  		DDPRINTK("ncp_evict_inode: put directory %ld
  ", inode->i_ino);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
293
294
295
  	}
  
  	if (ncp_make_closed(inode) != 0) {
  		/* We can't do anything but complain. */
94ee8494a   Al Viro   switch ncpfs to -...
296
297
  		printk(KERN_ERR "ncp_evict_inode: could not close
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
300
301
302
  }
  
  static void ncp_stop_tasks(struct ncp_server *server) {
  	struct sock* sk = server->ncp_sock->sk;
2a4df5d33   Petr Vandrovec   ncpfs: Lock socke...
303
304
  
  	lock_sock(sk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
307
  	sk->sk_error_report = server->error_report;
  	sk->sk_data_ready   = server->data_ready;
  	sk->sk_write_space  = server->write_space;
2a4df5d33   Petr Vandrovec   ncpfs: Lock socke...
308
  	release_sock(sk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
309
  	del_timer_sync(&server->timeout_tm);
5d8e4bddc   Tejun Heo   ncpfs: don't use ...
310
311
312
313
314
315
  
  	flush_work_sync(&server->rcv.tq);
  	if (sk->sk_socket->type == SOCK_STREAM)
  		flush_work_sync(&server->tx.tq);
  	else
  		flush_work_sync(&server->timeout_tq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  }
34c80b1d9   Al Viro   vfs: switch ->sho...
317
  static int  ncp_show_options(struct seq_file *seq, struct dentry *root)
564cd138c   Miklos Szeredi   mount options: fi...
318
  {
34c80b1d9   Al Viro   vfs: switch ->sho...
319
  	struct ncp_server *server = NCP_SBP(root->d_sb);
564cd138c   Miklos Szeredi   mount options: fi...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
  	unsigned int tmp;
  
  	if (server->m.uid != 0)
  		seq_printf(seq, ",uid=%u", server->m.uid);
  	if (server->m.gid != 0)
  		seq_printf(seq, ",gid=%u", server->m.gid);
  	if (server->m.mounted_uid != 0)
  		seq_printf(seq, ",owner=%u", server->m.mounted_uid);
  	tmp = server->m.file_mode & S_IALLUGO;
  	if (tmp != NCP_DEFAULT_FILE_MODE)
  		seq_printf(seq, ",mode=0%o", tmp);
  	tmp = server->m.dir_mode & S_IALLUGO;
  	if (tmp != NCP_DEFAULT_DIR_MODE)
  		seq_printf(seq, ",dirmode=0%o", tmp);
  	if (server->m.time_out != NCP_DEFAULT_TIME_OUT * HZ / 100) {
  		tmp = server->m.time_out * 100 / HZ;
  		seq_printf(seq, ",timeout=%u", tmp);
  	}
  	if (server->m.retry_count != NCP_DEFAULT_RETRY_COUNT)
  		seq_printf(seq, ",retry=%u", server->m.retry_count);
  	if (server->m.flags != 0)
  		seq_printf(seq, ",flags=%lu", server->m.flags);
  	if (server->m.wdog_pid != NULL)
  		seq_printf(seq, ",wdogpid=%u", pid_vnr(server->m.wdog_pid));
  
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
  static const struct ncp_option ncp_opts[] = {
  	{ "uid",	OPT_INT,	'u' },
  	{ "gid",	OPT_INT,	'g' },
  	{ "owner",	OPT_INT,	'o' },
  	{ "mode",	OPT_INT,	'm' },
  	{ "dirmode",	OPT_INT,	'd' },
  	{ "timeout",	OPT_INT,	't' },
  	{ "retry",	OPT_INT,	'r' },
  	{ "flags",	OPT_INT,	'f' },
  	{ "wdogpid",	OPT_INT,	'w' },
  	{ "ncpfd",	OPT_INT,	'n' },
  	{ "infofd",	OPT_INT,	'i' },	/* v5 */
  	{ "version",	OPT_INT,	'v' },
  	{ NULL,		0,		0 } };
  
  static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options) {
  	int optval;
  	char *optarg;
  	unsigned long optint;
  	int version = 0;
1de241268   Eric W. Biederman   [PATCH] ncpfs: en...
367
  	int ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
370
371
  
  	data->flags = 0;
  	data->int_flags = 0;
  	data->mounted_uid = 0;
2154227a2   Eric W. Biederman   [PATCH] ncpfs: Us...
372
  	data->wdog_pid = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
  	data->ncp_fd = ~0;
564cd138c   Miklos Szeredi   mount options: fi...
374
375
  	data->time_out = NCP_DEFAULT_TIME_OUT;
  	data->retry_count = NCP_DEFAULT_RETRY_COUNT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
377
  	data->uid = 0;
  	data->gid = 0;
564cd138c   Miklos Szeredi   mount options: fi...
378
379
  	data->file_mode = NCP_DEFAULT_FILE_MODE;
  	data->dir_mode = NCP_DEFAULT_DIR_MODE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
381
382
383
  	data->info_fd = -1;
  	data->mounted_vol[0] = 0;
  	
  	while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
1de241268   Eric W. Biederman   [PATCH] ncpfs: en...
384
385
386
  		ret = optval;
  		if (ret < 0)
  			goto err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  		switch (optval) {
  			case 'u':
  				data->uid = optint;
  				break;
  			case 'g':
  				data->gid = optint;
  				break;
  			case 'o':
  				data->mounted_uid = optint;
  				break;
  			case 'm':
  				data->file_mode = optint;
  				break;
  			case 'd':
  				data->dir_mode = optint;
  				break;
  			case 't':
  				data->time_out = optint;
  				break;
  			case 'r':
  				data->retry_count = optint;
  				break;
  			case 'f':
  				data->flags = optint;
  				break;
  			case 'w':
2154227a2   Eric W. Biederman   [PATCH] ncpfs: Us...
413
  				data->wdog_pid = find_get_pid(optint);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
414
415
416
417
418
419
420
421
  				break;
  			case 'n':
  				data->ncp_fd = optint;
  				break;
  			case 'i':
  				data->info_fd = optint;
  				break;
  			case 'v':
1de241268   Eric W. Biederman   [PATCH] ncpfs: en...
422
423
424
425
426
  				ret = -ECHRNG;
  				if (optint < NCP_MOUNT_VERSION_V4)
  					goto err;
  				if (optint > NCP_MOUNT_VERSION_V5)
  					goto err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
427
428
429
430
431
432
  				version = optint;
  				break;
  			
  		}
  	}
  	return 0;
1de241268   Eric W. Biederman   [PATCH] ncpfs: en...
433
434
435
436
  err:
  	put_pid(data->wdog_pid);
  	data->wdog_pid = NULL;
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
  }
  
  static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
  {
  	struct ncp_mount_data_kernel data;
  	struct ncp_server *server;
  	struct file *ncp_filp;
  	struct inode *root_inode;
  	struct inode *sock_inode;
  	struct socket *sock;
  	int error;
  	int default_bufsize;
  #ifdef CONFIG_NCPFS_PACKET_SIGNING
  	int options;
  #endif
  	struct ncp_entry_info finfo;
2a5cac17c   Andrew Morton   fs/ncpfs/inode.c:...
453
  	memset(&data, 0, sizeof(data));
f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
454
  	server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
  	if (!server)
  		return -ENOMEM;
  	sb->s_fs_info = server;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458
459
460
461
462
463
464
465
466
467
468
469
  
  	error = -EFAULT;
  	if (raw_data == NULL)
  		goto out;
  	switch (*(int*)raw_data) {
  		case NCP_MOUNT_VERSION:
  			{
  				struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;
  
  				data.flags = md->flags;
  				data.int_flags = NCP_IMOUNT_LOGGEDIN_POSSIBLE;
  				data.mounted_uid = md->mounted_uid;
2154227a2   Eric W. Biederman   [PATCH] ncpfs: Us...
470
  				data.wdog_pid = find_get_pid(md->wdog_pid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
  				data.ncp_fd = md->ncp_fd;
  				data.time_out = md->time_out;
  				data.retry_count = md->retry_count;
  				data.uid = md->uid;
  				data.gid = md->gid;
  				data.file_mode = md->file_mode;
  				data.dir_mode = md->dir_mode;
  				data.info_fd = -1;
  				memcpy(data.mounted_vol, md->mounted_vol,
  					NCP_VOLNAME_LEN+1);
  			}
  			break;
  		case NCP_MOUNT_VERSION_V4:
  			{
  				struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;
  
  				data.flags = md->flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
  				data.mounted_uid = md->mounted_uid;
2154227a2   Eric W. Biederman   [PATCH] ncpfs: Us...
489
  				data.wdog_pid = find_get_pid(md->wdog_pid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
491
492
493
494
495
496
497
  				data.ncp_fd = md->ncp_fd;
  				data.time_out = md->time_out;
  				data.retry_count = md->retry_count;
  				data.uid = md->uid;
  				data.gid = md->gid;
  				data.file_mode = md->file_mode;
  				data.dir_mode = md->dir_mode;
  				data.info_fd = -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
  			}
  			break;
  		default:
  			error = -ECHRNG;
  			if (memcmp(raw_data, "vers", 4) == 0) {
  				error = ncp_parse_options(&data, raw_data);
  			}
  			if (error)
  				goto out;
  			break;
  	}
  	error = -EBADF;
  	ncp_filp = fget(data.ncp_fd);
  	if (!ncp_filp)
  		goto out;
  	error = -ENOTSOCK;
92e5baef8   Josef Sipek   [PATCH] struct pa...
514
  	sock_inode = ncp_filp->f_path.dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  	if (!S_ISSOCK(sock_inode->i_mode))
  		goto out_fput;
  	sock = SOCKET_I(sock_inode);
  	if (!sock)
  		goto out_fput;
  		
  	if (sock->type == SOCK_STREAM)
  		default_bufsize = 0xF000;
  	else
  		default_bufsize = 1024;
  
  	sb->s_flags |= MS_NODIRATIME;	/* probably even noatime */
  	sb->s_maxbytes = 0xFFFFFFFFU;
  	sb->s_blocksize = 1024;	/* Eh...  Is this correct? */
  	sb->s_blocksize_bits = 10;
  	sb->s_magic = NCP_SUPER_MAGIC;
  	sb->s_op = &ncp_sops;
0378c4051   Al Viro   switch ncpfs
532
  	sb->s_d_op = &ncp_dentry_operations;
f1970c73c   Jens Axboe   ncpfs: add bdi ba...
533
  	sb->s_bdi = &server->bdi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
536
  
  	server = NCP_SBP(sb);
  	memset(server, 0, sizeof(*server));
f1970c73c   Jens Axboe   ncpfs: add bdi ba...
537
538
  	error = bdi_setup_and_register(&server->bdi, "ncpfs", BDI_CAP_MAP_COPY);
  	if (error)
759c361eb   Djalal Harouni   fs/ncpfs: fix err...
539
  		goto out_fput;
f1970c73c   Jens Axboe   ncpfs: add bdi ba...
540

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541
542
543
544
545
546
547
548
549
  	server->ncp_filp = ncp_filp;
  	server->ncp_sock = sock;
  	
  	if (data.info_fd != -1) {
  		struct socket *info_sock;
  
  		error = -EBADF;
  		server->info_filp = fget(data.info_fd);
  		if (!server->info_filp)
759c361eb   Djalal Harouni   fs/ncpfs: fix err...
550
  			goto out_bdi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551
  		error = -ENOTSOCK;
92e5baef8   Josef Sipek   [PATCH] struct pa...
552
  		sock_inode = server->info_filp->f_path.dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
554
555
556
557
558
559
560
561
562
563
564
  		if (!S_ISSOCK(sock_inode->i_mode))
  			goto out_fput2;
  		info_sock = SOCKET_I(sock_inode);
  		if (!info_sock)
  			goto out_fput2;
  		error = -EBADFD;
  		if (info_sock->type != SOCK_STREAM)
  			goto out_fput2;
  		server->info_sock = info_sock;
  	}
  
  /*	server->lock = 0;	*/
8e3f90459   Ingo Molnar   [PATCH] sem2mutex...
565
  	mutex_init(&server->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
566
567
568
569
570
  	server->packet = NULL;
  /*	server->buffer_size = 0;	*/
  /*	server->conn_status = 0;	*/
  /*	server->root_dentry = NULL;	*/
  /*	server->root_setuped = 0;	*/
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
571
  	mutex_init(&server->root_setup_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
572
573
574
575
  #ifdef CONFIG_NCPFS_PACKET_SIGNING
  /*	server->sign_wanted = 0;	*/
  /*	server->sign_active = 0;	*/
  #endif
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
576
  	init_rwsem(&server->auth_rwsem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
577
578
579
580
581
582
583
584
  	server->auth.auth_type = NCP_AUTH_NONE;
  /*	server->auth.object_name_len = 0;	*/
  /*	server->auth.object_name = NULL;	*/
  /*	server->auth.object_type = 0;		*/
  /*	server->priv.len = 0;			*/
  /*	server->priv.data = NULL;		*/
  
  	server->m = data;
25985edce   Lucas De Marchi   Fix common misspe...
585
  	/* Although anything producing this is buggy, it happens
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
  	   now because of PATH_MAX changes.. */
  	if (server->m.time_out < 1) {
  		server->m.time_out = 10;
  		printk(KERN_INFO "You need to recompile your ncpfs utils..
  ");
  	}
  	server->m.time_out = server->m.time_out * HZ / 100;
  	server->m.file_mode = (server->m.file_mode & S_IRWXUGO) | S_IFREG;
  	server->m.dir_mode = (server->m.dir_mode & S_IRWXUGO) | S_IFDIR;
  
  #ifdef CONFIG_NCPFS_NLS
  	/* load the default NLS charsets */
  	server->nls_vol = load_nls_default();
  	server->nls_io = load_nls_default();
  #endif /* CONFIG_NCPFS_NLS */
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
601
  	atomic_set(&server->dentry_ttl, 0);	/* no caching */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
602
603
  
  	INIT_LIST_HEAD(&server->tx.requests);
8e3f90459   Ingo Molnar   [PATCH] sem2mutex...
604
  	mutex_init(&server->rcv.creq_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
605
606
  	server->tx.creq		= NULL;
  	server->rcv.creq	= NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
608
609
610
611
612
613
614
615
  
  	init_timer(&server->timeout_tm);
  #undef NCP_PACKET_SIZE
  #define NCP_PACKET_SIZE 131072
  	error = -ENOMEM;
  	server->packet_size = NCP_PACKET_SIZE;
  	server->packet = vmalloc(NCP_PACKET_SIZE);
  	if (server->packet == NULL)
  		goto out_nls;
c5f93cf19   Pierre Ossman   ncpfs: make sure ...
616
617
618
619
620
621
  	server->txbuf = vmalloc(NCP_PACKET_SIZE);
  	if (server->txbuf == NULL)
  		goto out_packet;
  	server->rxbuf = vmalloc(NCP_PACKET_SIZE);
  	if (server->rxbuf == NULL)
  		goto out_txbuf;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
622

2a4df5d33   Petr Vandrovec   ncpfs: Lock socke...
623
624
625
626
627
  	lock_sock(sock->sk);
  	server->data_ready	= sock->sk->sk_data_ready;
  	server->write_space	= sock->sk->sk_write_space;
  	server->error_report	= sock->sk->sk_error_report;
  	sock->sk->sk_user_data	= server;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
629
630
631
632
633
  	sock->sk->sk_data_ready	  = ncp_tcp_data_ready;
  	sock->sk->sk_error_report = ncp_tcp_error_report;
  	if (sock->type == SOCK_STREAM) {
  		server->rcv.ptr = (unsigned char*)&server->rcv.buf;
  		server->rcv.len = 10;
  		server->rcv.state = 0;
c4028958b   David Howells   WorkStruct: make ...
634
635
  		INIT_WORK(&server->rcv.tq, ncp_tcp_rcv_proc);
  		INIT_WORK(&server->tx.tq, ncp_tcp_tx_proc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
636
637
  		sock->sk->sk_write_space = ncp_tcp_write_space;
  	} else {
c4028958b   David Howells   WorkStruct: make ...
638
639
  		INIT_WORK(&server->rcv.tq, ncpdgram_rcv_proc);
  		INIT_WORK(&server->timeout_tq, ncpdgram_timeout_proc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
640
641
642
  		server->timeout_tm.data = (unsigned long)server;
  		server->timeout_tm.function = ncpdgram_timeout_call;
  	}
2a4df5d33   Petr Vandrovec   ncpfs: Lock socke...
643
  	release_sock(sock->sk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
644
645
646
647
648
  
  	ncp_lock_server(server);
  	error = ncp_connect(server);
  	ncp_unlock_server(server);
  	if (error < 0)
c5f93cf19   Pierre Ossman   ncpfs: make sure ...
649
  		goto out_rxbuf;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
  	DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x
  ", (int) NCP_SBP(sb));
  
  	error = -EMSGSIZE;	/* -EREMOTESIDEINCOMPATIBLE */
  #ifdef CONFIG_NCPFS_PACKET_SIGNING
  	if (ncp_negotiate_size_and_options(server, default_bufsize,
  		NCP_DEFAULT_OPTIONS, &(server->buffer_size), &options) == 0)
  	{
  		if (options != NCP_DEFAULT_OPTIONS)
  		{
  			if (ncp_negotiate_size_and_options(server, 
  				default_bufsize,
  				options & 2, 
  				&(server->buffer_size), &options) != 0)
  				
  			{
  				goto out_disconnect;
  			}
  		}
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
669
  		ncp_lock_server(server);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
670
671
  		if (options & 2)
  			server->sign_wanted = 1;
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
672
  		ncp_unlock_server(server);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
  	}
  	else 
  #endif	/* CONFIG_NCPFS_PACKET_SIGNING */
  	if (ncp_negotiate_buffersize(server, default_bufsize,
    				     &(server->buffer_size)) != 0)
  		goto out_disconnect;
  	DPRINTK("ncpfs: bufsize = %d
  ", server->buffer_size);
  
  	memset(&finfo, 0, sizeof(finfo));
  	finfo.i.attributes	= aDIR;
  	finfo.i.dataStreamSize	= 0;	/* ignored */
  	finfo.i.dirEntNum	= 0;
  	finfo.i.DosDirNum	= 0;
  #ifdef CONFIG_NCPFS_SMALLDOS
  	finfo.i.NSCreator	= NW_NS_DOS;
  #endif
  	finfo.volume		= NCP_NUMBER_OF_VOLUMES;
  	/* set dates of mountpoint to Jan 1, 1986; 00:00 */
  	finfo.i.creationTime	= finfo.i.modifyTime
  				= cpu_to_le16(0x0000);
  	finfo.i.creationDate	= finfo.i.modifyDate
  				= finfo.i.lastAccessDate
  				= cpu_to_le16(0x0C21);
  	finfo.i.nameLen		= 0;
  	finfo.i.entryName[0]	= '\0';
  
  	finfo.opened		= 0;
  	finfo.ino		= 2;	/* tradition */
  
  	server->name_space[finfo.volume] = NW_NS_DOS;
  
  	error = -ENOMEM;
          root_inode = ncp_iget(sb, &finfo);
          if (!root_inode)
  		goto out_disconnect;
  	DPRINTK("ncp_fill_super: root vol=%d
  ", NCP_FINFO(root_inode)->volNumber);
  	sb->s_root = d_alloc_root(root_inode);
          if (!sb->s_root)
  		goto out_no_root;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714
715
716
717
718
719
720
721
  	return 0;
  
  out_no_root:
  	iput(root_inode);
  out_disconnect:
  	ncp_lock_server(server);
  	ncp_disconnect(server);
  	ncp_unlock_server(server);
c5f93cf19   Pierre Ossman   ncpfs: make sure ...
722
  out_rxbuf:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
723
  	ncp_stop_tasks(server);
c5f93cf19   Pierre Ossman   ncpfs: make sure ...
724
725
726
727
  	vfree(server->rxbuf);
  out_txbuf:
  	vfree(server->txbuf);
  out_packet:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
728
729
730
731
732
733
  	vfree(server->packet);
  out_nls:
  #ifdef CONFIG_NCPFS_NLS
  	unload_nls(server->nls_io);
  	unload_nls(server->nls_vol);
  #endif
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
734
735
736
  	mutex_destroy(&server->rcv.creq_mutex);
  	mutex_destroy(&server->root_setup_lock);
  	mutex_destroy(&server->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
738
739
  out_fput2:
  	if (server->info_filp)
  		fput(server->info_filp);
f1970c73c   Jens Axboe   ncpfs: add bdi ba...
740
  out_bdi:
759c361eb   Djalal Harouni   fs/ncpfs: fix err...
741
742
  	bdi_destroy(&server->bdi);
  out_fput:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
743
744
  	/* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
  	 * 
e956b4b7e   Matthew Whitworth   Fix comment spell...
745
746
  	 * The previously used put_filp(ncp_filp); was bogus, since
  	 * it doesn't perform proper unlocking.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
747
748
749
  	 */
  	fput(ncp_filp);
  out:
1de241268   Eric W. Biederman   [PATCH] ncpfs: en...
750
  	put_pid(data.wdog_pid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
  	sb->s_fs_info = NULL;
  	kfree(server);
  	return error;
  }
  
  static void ncp_put_super(struct super_block *sb)
  {
  	struct ncp_server *server = NCP_SBP(sb);
  
  	ncp_lock_server(server);
  	ncp_disconnect(server);
  	ncp_unlock_server(server);
  
  	ncp_stop_tasks(server);
  
  #ifdef CONFIG_NCPFS_NLS
  	/* unload the NLS charsets */
6d729e44a   Thomas Gleixner   fs: Make unload_n...
768
769
  	unload_nls(server->nls_vol);
  	unload_nls(server->nls_io);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
770
  #endif /* CONFIG_NCPFS_NLS */
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
771
772
773
  	mutex_destroy(&server->rcv.creq_mutex);
  	mutex_destroy(&server->root_setup_lock);
  	mutex_destroy(&server->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
774
775
776
777
  
  	if (server->info_filp)
  		fput(server->info_filp);
  	fput(server->ncp_filp);
2154227a2   Eric W. Biederman   [PATCH] ncpfs: Us...
778
779
  	kill_pid(server->m.wdog_pid, SIGTERM, 1);
  	put_pid(server->m.wdog_pid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
780

f1970c73c   Jens Axboe   ncpfs: add bdi ba...
781
  	bdi_destroy(&server->bdi);
44db77f33   Pekka Enberg   [PATCH] ncpfs: re...
782
783
  	kfree(server->priv.data);
  	kfree(server->auth.object_name);
c5f93cf19   Pierre Ossman   ncpfs: make sure ...
784
785
  	vfree(server->rxbuf);
  	vfree(server->txbuf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
788
789
  	vfree(server->packet);
  	sb->s_fs_info = NULL;
  	kfree(server);
  }
726c33422   David Howells   [PATCH] VFS: Perm...
790
  static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
791
792
793
794
795
796
  {
  	struct dentry* d;
  	struct inode* i;
  	struct ncp_inode_info* ni;
  	struct ncp_server* s;
  	struct ncp_volume_info vi;
726c33422   David Howells   [PATCH] VFS: Perm...
797
  	struct super_block *sb = dentry->d_sb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
  	int err;
  	__u8 dh;
  	
  	d = sb->s_root;
  	if (!d) {
  		goto dflt;
  	}
  	i = d->d_inode;
  	if (!i) {
  		goto dflt;
  	}
  	ni = NCP_FINFO(i);
  	if (!ni) {
  		goto dflt;
  	}
  	s = NCP_SBP(sb);
  	if (!s) {
  		goto dflt;
  	}
  	if (!s->m.mounted_vol[0]) {
  		goto dflt;
  	}
  
  	err = ncp_dirhandle_alloc(s, ni->volNumber, ni->DosDirNum, &dh);
  	if (err) {
  		goto dflt;
  	}
  	err = ncp_get_directory_info(s, dh, &vi);
  	ncp_dirhandle_free(s, dh);
  	if (err) {
  		goto dflt;
  	}
  	buf->f_type = NCP_SUPER_MAGIC;
  	buf->f_bsize = vi.sectors_per_block * 512;
  	buf->f_blocks = vi.total_blocks;
  	buf->f_bfree = vi.free_blocks;
  	buf->f_bavail = vi.free_blocks;
  	buf->f_files = vi.total_dir_entries;
  	buf->f_ffree = vi.available_dir_entries;
  	buf->f_namelen = 12;
  	return 0;
  
  	/* We cannot say how much disk space is left on a mounted
  	   NetWare Server, because free space is distributed over
  	   volumes, and the current user might have disk quotas. So
  	   free space is not that simple to determine. Our decision
  	   here is to err conservatively. */
  
  dflt:;
  	buf->f_type = NCP_SUPER_MAGIC;
  	buf->f_bsize = NCP_BLOCK_SIZE;
  	buf->f_blocks = 0;
  	buf->f_bfree = 0;
  	buf->f_bavail = 0;
  	buf->f_namelen = 12;
  	return 0;
  }
  
  int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
  {
  	struct inode *inode = dentry->d_inode;
  	int result = 0;
  	__le32 info_mask;
  	struct nw_modify_dos_info info;
  	struct ncp_server *server;
  
  	result = -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
865
  	server = NCP_SERVER(inode);
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
866
  	if (!server)	/* How this could happen? */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
  		goto out;
  
  	/* ageing the dentry to force validation */
  	ncp_age_dentry(server, dentry);
  
  	result = inode_change_ok(inode, attr);
  	if (result < 0)
  		goto out;
  
  	result = -EPERM;
  	if (((attr->ia_valid & ATTR_UID) &&
  	     (attr->ia_uid != server->m.uid)))
  		goto out;
  
  	if (((attr->ia_valid & ATTR_GID) &&
  	     (attr->ia_gid != server->m.gid)))
  		goto out;
  
  	if (((attr->ia_valid & ATTR_MODE) &&
  	     (attr->ia_mode &
  	      ~(S_IFREG | S_IFDIR | S_IRWXUGO))))
  		goto out;
  
  	info_mask = 0;
  	memset(&info, 0, sizeof(info));
  
  #if 1 
          if ((attr->ia_valid & ATTR_MODE) != 0)
          {
  		umode_t newmode = attr->ia_mode;
  
  		info_mask |= DM_ATTRIBUTES;
  
                  if (S_ISDIR(inode->i_mode)) {
                  	newmode &= server->m.dir_mode;
  		} else {
  #ifdef CONFIG_NCPFS_EXTRAS			
  			if (server->m.flags & NCP_MOUNT_EXTRAS) {
  				/* any non-default execute bit set */
  				if (newmode & ~server->m.file_mode & S_IXUGO)
  					info.attributes |= aSHARED | aSYSTEM;
  				/* read for group/world and not in default file_mode */
  				else if (newmode & ~server->m.file_mode & S_IRUGO)
  					info.attributes |= aSHARED;
  			} else
  #endif
  				newmode &= server->m.file_mode;			
                  }
                  if (newmode & S_IWUGO)
                  	info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
                  else
  			info.attributes |=  (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
  
  #ifdef CONFIG_NCPFS_NFS_NS
  		if (ncp_is_nfs_extras(server, NCP_FINFO(inode)->volNumber)) {
  			result = ncp_modify_nfs_info(server,
  						     NCP_FINFO(inode)->volNumber,
  						     NCP_FINFO(inode)->dirEntNum,
  						     attr->ia_mode, 0);
  			if (result != 0)
  				goto out;
  			info.attributes &= ~(aSHARED | aSYSTEM);
  			{
  				/* mark partial success */
  				struct iattr tmpattr;
  				
  				tmpattr.ia_valid = ATTR_MODE;
  				tmpattr.ia_mode = attr->ia_mode;
1025774ce   Christoph Hellwig   remove inode_setattr
935
936
  				setattr_copy(inode, &tmpattr);
  				mark_inode_dirty(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
  			}
  		}
  #endif
          }
  #endif
  
  	/* Do SIZE before attributes, otherwise mtime together with size does not work...
  	 */
  	if ((attr->ia_valid & ATTR_SIZE) != 0) {
  		int written;
  
  		DPRINTK("ncpfs: trying to change size to %ld
  ",
  			attr->ia_size);
  
  		if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {
  			result = -EACCES;
  			goto out;
  		}
  		ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
  			  attr->ia_size, 0, "", &written);
  
  		/* According to ndir, the changes only take effect after
  		   closing the file */
  		ncp_inode_close(inode);
  		result = ncp_make_closed(inode);
  		if (result)
  			goto out;
1025774ce   Christoph Hellwig   remove inode_setattr
965
966
967
  
  		if (attr->ia_size != i_size_read(inode)) {
  			result = vmtruncate(inode, attr->ia_size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
968
969
  			if (result)
  				goto out;
1025774ce   Christoph Hellwig   remove inode_setattr
970
  			mark_inode_dirty(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
  		}
  	}
  	if ((attr->ia_valid & ATTR_CTIME) != 0) {
  		info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
  		ncp_date_unix2dos(attr->ia_ctime.tv_sec,
  			     &info.creationTime, &info.creationDate);
  	}
  	if ((attr->ia_valid & ATTR_MTIME) != 0) {
  		info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
  		ncp_date_unix2dos(attr->ia_mtime.tv_sec,
  				  &info.modifyTime, &info.modifyDate);
  	}
  	if ((attr->ia_valid & ATTR_ATIME) != 0) {
  		__le16 dummy;
  		info_mask |= (DM_LAST_ACCESS_DATE);
  		ncp_date_unix2dos(attr->ia_atime.tv_sec,
  				  &dummy, &info.lastAccessDate);
  	}
  	if (info_mask != 0) {
  		result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
  				      inode, info_mask, &info);
  		if (result != 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
  			if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {
  				/* NetWare seems not to allow this. I
  				   do not know why. So, just tell the
  				   user everything went fine. This is
  				   a terrible hack, but I do not know
  				   how to do this correctly. */
  				result = 0;
  			} else
  				goto out;
  		}
  #ifdef CONFIG_NCPFS_STRONG		
  		if ((!result) && (info_mask & DM_ATTRIBUTES))
  			NCP_FINFO(inode)->nwattr = info.attributes;
  #endif
  	}
1025774ce   Christoph Hellwig   remove inode_setattr
1008
1009
1010
1011
1012
  	if (result)
  		goto out;
  
  	setattr_copy(inode, attr);
  	mark_inode_dirty(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1013
  out:
2e54eb96e   Petr Vandrovec   BKL: Remove BKL f...
1014
1015
  	if (result > 0)
  		result = -EACCES;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1016
1017
  	return result;
  }
3c26ff6e4   Al Viro   convert get_sb_no...
1018
1019
  static struct dentry *ncp_mount(struct file_system_type *fs_type,
  	int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1020
  {
3c26ff6e4   Al Viro   convert get_sb_no...
1021
  	return mount_nodev(fs_type, flags, data, ncp_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022
1023
1024
1025
1026
  }
  
  static struct file_system_type ncp_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "ncpfs",
3c26ff6e4   Al Viro   convert get_sb_no...
1027
  	.mount		= ncp_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1028
  	.kill_sb	= kill_anon_super,
564cd138c   Miklos Szeredi   mount options: fi...
1029
  	.fs_flags	= FS_BINARY_MOUNTDATA,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1030
1031
1032
1033
1034
  };
  
  static int __init init_ncp_fs(void)
  {
  	int err;
7c28cbaed   Robert P. J. Day   NCPFS: update dia...
1035
1036
  	DPRINTK("ncpfs: init_ncp_fs called
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1037

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
  	err = init_inodecache();
  	if (err)
  		goto out1;
  	err = register_filesystem(&ncp_fs_type);
  	if (err)
  		goto out;
  	return 0;
  out:
  	destroy_inodecache();
  out1:
  	return err;
  }
  
  static void __exit exit_ncp_fs(void)
  {
7c28cbaed   Robert P. J. Day   NCPFS: update dia...
1053
1054
  	DPRINTK("ncpfs: exit_ncp_fs called
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1055
1056
  	unregister_filesystem(&ncp_fs_type);
  	destroy_inodecache();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1057
1058
1059
1060
1061
  }
  
  module_init(init_ncp_fs)
  module_exit(exit_ncp_fs)
  MODULE_LICENSE("GPL");