]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/smbfs/inode.c
Remove SLAB_CTOR_CONSTRUCTOR
[mirror_ubuntu-artful-kernel.git] / fs / smbfs / inode.c
1 /*
2 * inode.c
3 *
4 * Copyright (C) 1995, 1996 by Paal-Kr. Engstad and Volker Lendecke
5 * Copyright (C) 1997 by Volker Lendecke
6 *
7 * Please add a note about your changes to smbfs in the ChangeLog file.
8 */
9
10 #include <linux/module.h>
11 #include <linux/time.h>
12 #include <linux/kernel.h>
13 #include <linux/mm.h>
14 #include <linux/string.h>
15 #include <linux/stat.h>
16 #include <linux/errno.h>
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/file.h>
20 #include <linux/dcache.h>
21 #include <linux/smp_lock.h>
22 #include <linux/nls.h>
23 #include <linux/seq_file.h>
24 #include <linux/mount.h>
25 #include <linux/net.h>
26 #include <linux/vfs.h>
27 #include <linux/highuid.h>
28 #include <linux/smb_fs.h>
29 #include <linux/smbno.h>
30 #include <linux/smb_mount.h>
31
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
34
35 #include "smb_debug.h"
36 #include "getopt.h"
37 #include "proto.h"
38
39 /* Always pick a default string */
40 #ifdef CONFIG_SMB_NLS_REMOTE
41 #define SMB_NLS_REMOTE CONFIG_SMB_NLS_REMOTE
42 #else
43 #define SMB_NLS_REMOTE ""
44 #endif
45
46 #define SMB_TTL_DEFAULT 1000
47
48 static void smb_delete_inode(struct inode *);
49 static void smb_put_super(struct super_block *);
50 static int smb_statfs(struct dentry *, struct kstatfs *);
51 static int smb_show_options(struct seq_file *, struct vfsmount *);
52
53 static struct kmem_cache *smb_inode_cachep;
54
55 static struct inode *smb_alloc_inode(struct super_block *sb)
56 {
57 struct smb_inode_info *ei;
58 ei = (struct smb_inode_info *)kmem_cache_alloc(smb_inode_cachep, GFP_KERNEL);
59 if (!ei)
60 return NULL;
61 return &ei->vfs_inode;
62 }
63
64 static void smb_destroy_inode(struct inode *inode)
65 {
66 kmem_cache_free(smb_inode_cachep, SMB_I(inode));
67 }
68
69 static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
70 {
71 struct smb_inode_info *ei = (struct smb_inode_info *) foo;
72
73 inode_init_once(&ei->vfs_inode);
74 }
75
76 static int init_inodecache(void)
77 {
78 smb_inode_cachep = kmem_cache_create("smb_inode_cache",
79 sizeof(struct smb_inode_info),
80 0, (SLAB_RECLAIM_ACCOUNT|
81 SLAB_MEM_SPREAD),
82 init_once, NULL);
83 if (smb_inode_cachep == NULL)
84 return -ENOMEM;
85 return 0;
86 }
87
88 static void destroy_inodecache(void)
89 {
90 kmem_cache_destroy(smb_inode_cachep);
91 }
92
93 static int smb_remount(struct super_block *sb, int *flags, char *data)
94 {
95 *flags |= MS_NODIRATIME;
96 return 0;
97 }
98
99 static const struct super_operations smb_sops =
100 {
101 .alloc_inode = smb_alloc_inode,
102 .destroy_inode = smb_destroy_inode,
103 .drop_inode = generic_delete_inode,
104 .delete_inode = smb_delete_inode,
105 .put_super = smb_put_super,
106 .statfs = smb_statfs,
107 .show_options = smb_show_options,
108 .remount_fs = smb_remount,
109 };
110
111
112 /* We are always generating a new inode here */
113 struct inode *
114 smb_iget(struct super_block *sb, struct smb_fattr *fattr)
115 {
116 struct smb_sb_info *server = SMB_SB(sb);
117 struct inode *result;
118
119 DEBUG1("smb_iget: %p\n", fattr);
120
121 result = new_inode(sb);
122 if (!result)
123 return result;
124 result->i_ino = fattr->f_ino;
125 SMB_I(result)->open = 0;
126 SMB_I(result)->fileid = 0;
127 SMB_I(result)->access = 0;
128 SMB_I(result)->flags = 0;
129 SMB_I(result)->closed = 0;
130 SMB_I(result)->openers = 0;
131 smb_set_inode_attr(result, fattr);
132 if (S_ISREG(result->i_mode)) {
133 result->i_op = &smb_file_inode_operations;
134 result->i_fop = &smb_file_operations;
135 result->i_data.a_ops = &smb_file_aops;
136 } else if (S_ISDIR(result->i_mode)) {
137 if (server->opt.capabilities & SMB_CAP_UNIX)
138 result->i_op = &smb_dir_inode_operations_unix;
139 else
140 result->i_op = &smb_dir_inode_operations;
141 result->i_fop = &smb_dir_operations;
142 } else if (S_ISLNK(result->i_mode)) {
143 result->i_op = &smb_link_inode_operations;
144 } else {
145 init_special_inode(result, result->i_mode, fattr->f_rdev);
146 }
147 insert_inode_hash(result);
148 return result;
149 }
150
151 /*
152 * Copy the inode data to a smb_fattr structure.
153 */
154 void
155 smb_get_inode_attr(struct inode *inode, struct smb_fattr *fattr)
156 {
157 memset(fattr, 0, sizeof(struct smb_fattr));
158 fattr->f_mode = inode->i_mode;
159 fattr->f_nlink = inode->i_nlink;
160 fattr->f_ino = inode->i_ino;
161 fattr->f_uid = inode->i_uid;
162 fattr->f_gid = inode->i_gid;
163 fattr->f_size = inode->i_size;
164 fattr->f_mtime = inode->i_mtime;
165 fattr->f_ctime = inode->i_ctime;
166 fattr->f_atime = inode->i_atime;
167 fattr->f_blocks = inode->i_blocks;
168
169 fattr->attr = SMB_I(inode)->attr;
170 /*
171 * Keep the attributes in sync with the inode permissions.
172 */
173 if (fattr->f_mode & S_IWUSR)
174 fattr->attr &= ~aRONLY;
175 else
176 fattr->attr |= aRONLY;
177 }
178
179 /*
180 * Update the inode, possibly causing it to invalidate its pages if mtime/size
181 * is different from last time.
182 */
183 void
184 smb_set_inode_attr(struct inode *inode, struct smb_fattr *fattr)
185 {
186 struct smb_inode_info *ei = SMB_I(inode);
187
188 /*
189 * A size change should have a different mtime, or same mtime
190 * but different size.
191 */
192 time_t last_time = inode->i_mtime.tv_sec;
193 loff_t last_sz = inode->i_size;
194
195 inode->i_mode = fattr->f_mode;
196 inode->i_nlink = fattr->f_nlink;
197 inode->i_uid = fattr->f_uid;
198 inode->i_gid = fattr->f_gid;
199 inode->i_ctime = fattr->f_ctime;
200 inode->i_blocks = fattr->f_blocks;
201 inode->i_size = fattr->f_size;
202 inode->i_mtime = fattr->f_mtime;
203 inode->i_atime = fattr->f_atime;
204 ei->attr = fattr->attr;
205
206 /*
207 * Update the "last time refreshed" field for revalidation.
208 */
209 ei->oldmtime = jiffies;
210
211 if (inode->i_mtime.tv_sec != last_time || inode->i_size != last_sz) {
212 VERBOSE("%ld changed, old=%ld, new=%ld, oz=%ld, nz=%ld\n",
213 inode->i_ino,
214 (long) last_time, (long) inode->i_mtime.tv_sec,
215 (long) last_sz, (long) inode->i_size);
216
217 if (!S_ISDIR(inode->i_mode))
218 invalidate_remote_inode(inode);
219 }
220 }
221
222 /*
223 * This is called if the connection has gone bad ...
224 * try to kill off all the current inodes.
225 */
226 void
227 smb_invalidate_inodes(struct smb_sb_info *server)
228 {
229 VERBOSE("\n");
230 shrink_dcache_sb(SB_of(server));
231 invalidate_inodes(SB_of(server));
232 }
233
234 /*
235 * This is called to update the inode attributes after
236 * we've made changes to a file or directory.
237 */
238 static int
239 smb_refresh_inode(struct dentry *dentry)
240 {
241 struct inode *inode = dentry->d_inode;
242 int error;
243 struct smb_fattr fattr;
244
245 error = smb_proc_getattr(dentry, &fattr);
246 if (!error) {
247 smb_renew_times(dentry);
248 /*
249 * Check whether the type part of the mode changed,
250 * and don't update the attributes if it did.
251 *
252 * And don't dick with the root inode
253 */
254 if (inode->i_ino == 2)
255 return error;
256 if (S_ISLNK(inode->i_mode))
257 return error; /* VFS will deal with it */
258
259 if ((inode->i_mode & S_IFMT) == (fattr.f_mode & S_IFMT)) {
260 smb_set_inode_attr(inode, &fattr);
261 } else {
262 /*
263 * Big trouble! The inode has become a new object,
264 * so any operations attempted on it are invalid.
265 *
266 * To limit damage, mark the inode as bad so that
267 * subsequent lookup validations will fail.
268 */
269 PARANOIA("%s/%s changed mode, %07o to %07o\n",
270 DENTRY_PATH(dentry),
271 inode->i_mode, fattr.f_mode);
272
273 fattr.f_mode = inode->i_mode; /* save mode */
274 make_bad_inode(inode);
275 inode->i_mode = fattr.f_mode; /* restore mode */
276 /*
277 * No need to worry about unhashing the dentry: the
278 * lookup validation will see that the inode is bad.
279 * But we do want to invalidate the caches ...
280 */
281 if (!S_ISDIR(inode->i_mode))
282 invalidate_remote_inode(inode);
283 else
284 smb_invalid_dir_cache(inode);
285 error = -EIO;
286 }
287 }
288 return error;
289 }
290
291 /*
292 * This is called when we want to check whether the inode
293 * has changed on the server. If it has changed, we must
294 * invalidate our local caches.
295 */
296 int
297 smb_revalidate_inode(struct dentry *dentry)
298 {
299 struct smb_sb_info *s = server_from_dentry(dentry);
300 struct inode *inode = dentry->d_inode;
301 int error = 0;
302
303 DEBUG1("smb_revalidate_inode\n");
304 lock_kernel();
305
306 /*
307 * Check whether we've recently refreshed the inode.
308 */
309 if (time_before(jiffies, SMB_I(inode)->oldmtime + SMB_MAX_AGE(s))) {
310 VERBOSE("up-to-date, ino=%ld, jiffies=%lu, oldtime=%lu\n",
311 inode->i_ino, jiffies, SMB_I(inode)->oldmtime);
312 goto out;
313 }
314
315 error = smb_refresh_inode(dentry);
316 out:
317 unlock_kernel();
318 return error;
319 }
320
321 /*
322 * This routine is called when i_nlink == 0 and i_count goes to 0.
323 * All blocking cleanup operations need to go here to avoid races.
324 */
325 static void
326 smb_delete_inode(struct inode *ino)
327 {
328 DEBUG1("ino=%ld\n", ino->i_ino);
329 truncate_inode_pages(&ino->i_data, 0);
330 lock_kernel();
331 if (smb_close(ino))
332 PARANOIA("could not close inode %ld\n", ino->i_ino);
333 unlock_kernel();
334 clear_inode(ino);
335 }
336
337 static struct option opts[] = {
338 { "version", 0, 'v' },
339 { "win95", SMB_MOUNT_WIN95, 1 },
340 { "oldattr", SMB_MOUNT_OLDATTR, 1 },
341 { "dirattr", SMB_MOUNT_DIRATTR, 1 },
342 { "case", SMB_MOUNT_CASE, 1 },
343 { "uid", 0, 'u' },
344 { "gid", 0, 'g' },
345 { "file_mode", 0, 'f' },
346 { "dir_mode", 0, 'd' },
347 { "iocharset", 0, 'i' },
348 { "codepage", 0, 'c' },
349 { "ttl", 0, 't' },
350 { NULL, 0, 0}
351 };
352
353 static int
354 parse_options(struct smb_mount_data_kernel *mnt, char *options)
355 {
356 int c;
357 unsigned long flags;
358 unsigned long value;
359 char *optarg;
360 char *optopt;
361
362 flags = 0;
363 while ( (c = smb_getopt("smbfs", &options, opts,
364 &optopt, &optarg, &flags, &value)) > 0) {
365
366 VERBOSE("'%s' -> '%s'\n", optopt, optarg ? optarg : "<none>");
367 switch (c) {
368 case 1:
369 /* got a "flag" option */
370 break;
371 case 'v':
372 if (value != SMB_MOUNT_VERSION) {
373 printk ("smbfs: Bad mount version %ld, expected %d\n",
374 value, SMB_MOUNT_VERSION);
375 return 0;
376 }
377 mnt->version = value;
378 break;
379 case 'u':
380 mnt->uid = value;
381 flags |= SMB_MOUNT_UID;
382 break;
383 case 'g':
384 mnt->gid = value;
385 flags |= SMB_MOUNT_GID;
386 break;
387 case 'f':
388 mnt->file_mode = (value & S_IRWXUGO) | S_IFREG;
389 flags |= SMB_MOUNT_FMODE;
390 break;
391 case 'd':
392 mnt->dir_mode = (value & S_IRWXUGO) | S_IFDIR;
393 flags |= SMB_MOUNT_DMODE;
394 break;
395 case 'i':
396 strlcpy(mnt->codepage.local_name, optarg,
397 SMB_NLS_MAXNAMELEN);
398 break;
399 case 'c':
400 strlcpy(mnt->codepage.remote_name, optarg,
401 SMB_NLS_MAXNAMELEN);
402 break;
403 case 't':
404 mnt->ttl = value;
405 break;
406 default:
407 printk ("smbfs: Unrecognized mount option %s\n",
408 optopt);
409 return -1;
410 }
411 }
412 mnt->flags = flags;
413 return c;
414 }
415
416 /*
417 * smb_show_options() is for displaying mount options in /proc/mounts.
418 * It tries to avoid showing settings that were not changed from their
419 * defaults.
420 */
421 static int
422 smb_show_options(struct seq_file *s, struct vfsmount *m)
423 {
424 struct smb_mount_data_kernel *mnt = SMB_SB(m->mnt_sb)->mnt;
425 int i;
426
427 for (i = 0; opts[i].name != NULL; i++)
428 if (mnt->flags & opts[i].flag)
429 seq_printf(s, ",%s", opts[i].name);
430
431 if (mnt->flags & SMB_MOUNT_UID)
432 seq_printf(s, ",uid=%d", mnt->uid);
433 if (mnt->flags & SMB_MOUNT_GID)
434 seq_printf(s, ",gid=%d", mnt->gid);
435 if (mnt->mounted_uid != 0)
436 seq_printf(s, ",mounted_uid=%d", mnt->mounted_uid);
437
438 /*
439 * Defaults for file_mode and dir_mode are unknown to us; they
440 * depend on the current umask of the user doing the mount.
441 */
442 if (mnt->flags & SMB_MOUNT_FMODE)
443 seq_printf(s, ",file_mode=%04o", mnt->file_mode & S_IRWXUGO);
444 if (mnt->flags & SMB_MOUNT_DMODE)
445 seq_printf(s, ",dir_mode=%04o", mnt->dir_mode & S_IRWXUGO);
446
447 if (strcmp(mnt->codepage.local_name, CONFIG_NLS_DEFAULT))
448 seq_printf(s, ",iocharset=%s", mnt->codepage.local_name);
449 if (strcmp(mnt->codepage.remote_name, SMB_NLS_REMOTE))
450 seq_printf(s, ",codepage=%s", mnt->codepage.remote_name);
451
452 if (mnt->ttl != SMB_TTL_DEFAULT)
453 seq_printf(s, ",ttl=%d", mnt->ttl);
454
455 return 0;
456 }
457
458 static void
459 smb_unload_nls(struct smb_sb_info *server)
460 {
461 if (server->remote_nls) {
462 unload_nls(server->remote_nls);
463 server->remote_nls = NULL;
464 }
465 if (server->local_nls) {
466 unload_nls(server->local_nls);
467 server->local_nls = NULL;
468 }
469 }
470
471 static void
472 smb_put_super(struct super_block *sb)
473 {
474 struct smb_sb_info *server = SMB_SB(sb);
475
476 smb_lock_server(server);
477 server->state = CONN_INVALID;
478 smbiod_unregister_server(server);
479
480 smb_close_socket(server);
481
482 if (server->conn_pid)
483 kill_pid(server->conn_pid, SIGTERM, 1);
484
485 kfree(server->ops);
486 smb_unload_nls(server);
487 sb->s_fs_info = NULL;
488 smb_unlock_server(server);
489 put_pid(server->conn_pid);
490 kfree(server);
491 }
492
493 static int smb_fill_super(struct super_block *sb, void *raw_data, int silent)
494 {
495 struct smb_sb_info *server;
496 struct smb_mount_data_kernel *mnt;
497 struct smb_mount_data *oldmnt;
498 struct inode *root_inode;
499 struct smb_fattr root;
500 int ver;
501 void *mem;
502
503 if (!raw_data)
504 goto out_no_data;
505
506 oldmnt = (struct smb_mount_data *) raw_data;
507 ver = oldmnt->version;
508 if (ver != SMB_MOUNT_OLDVERSION && cpu_to_be32(ver) != SMB_MOUNT_ASCII)
509 goto out_wrong_data;
510
511 sb->s_flags |= MS_NODIRATIME;
512 sb->s_blocksize = 1024; /* Eh... Is this correct? */
513 sb->s_blocksize_bits = 10;
514 sb->s_magic = SMB_SUPER_MAGIC;
515 sb->s_op = &smb_sops;
516 sb->s_time_gran = 100;
517
518 server = kzalloc(sizeof(struct smb_sb_info), GFP_KERNEL);
519 if (!server)
520 goto out_no_server;
521 sb->s_fs_info = server;
522
523 server->super_block = sb;
524 server->mnt = NULL;
525 server->sock_file = NULL;
526 init_waitqueue_head(&server->conn_wq);
527 init_MUTEX(&server->sem);
528 INIT_LIST_HEAD(&server->entry);
529 INIT_LIST_HEAD(&server->xmitq);
530 INIT_LIST_HEAD(&server->recvq);
531 server->conn_error = 0;
532 server->conn_pid = NULL;
533 server->state = CONN_INVALID; /* no connection yet */
534 server->generation = 0;
535
536 /* Allocate the global temp buffer and some superblock helper structs */
537 /* FIXME: move these to the smb_sb_info struct */
538 VERBOSE("alloc chunk = %d\n", sizeof(struct smb_ops) +
539 sizeof(struct smb_mount_data_kernel));
540 mem = kmalloc(sizeof(struct smb_ops) +
541 sizeof(struct smb_mount_data_kernel), GFP_KERNEL);
542 if (!mem)
543 goto out_no_mem;
544
545 server->ops = mem;
546 smb_install_null_ops(server->ops);
547 server->mnt = mem + sizeof(struct smb_ops);
548
549 /* Setup NLS stuff */
550 server->remote_nls = NULL;
551 server->local_nls = NULL;
552
553 mnt = server->mnt;
554
555 memset(mnt, 0, sizeof(struct smb_mount_data_kernel));
556 strlcpy(mnt->codepage.local_name, CONFIG_NLS_DEFAULT,
557 SMB_NLS_MAXNAMELEN);
558 strlcpy(mnt->codepage.remote_name, SMB_NLS_REMOTE,
559 SMB_NLS_MAXNAMELEN);
560
561 mnt->ttl = SMB_TTL_DEFAULT;
562 if (ver == SMB_MOUNT_OLDVERSION) {
563 mnt->version = oldmnt->version;
564
565 SET_UID(mnt->uid, oldmnt->uid);
566 SET_GID(mnt->gid, oldmnt->gid);
567
568 mnt->file_mode = (oldmnt->file_mode & S_IRWXUGO) | S_IFREG;
569 mnt->dir_mode = (oldmnt->dir_mode & S_IRWXUGO) | S_IFDIR;
570
571 mnt->flags = (oldmnt->file_mode >> 9) | SMB_MOUNT_UID |
572 SMB_MOUNT_GID | SMB_MOUNT_FMODE | SMB_MOUNT_DMODE;
573 } else {
574 mnt->file_mode = S_IRWXU | S_IRGRP | S_IXGRP |
575 S_IROTH | S_IXOTH | S_IFREG;
576 mnt->dir_mode = S_IRWXU | S_IRGRP | S_IXGRP |
577 S_IROTH | S_IXOTH | S_IFDIR;
578 if (parse_options(mnt, raw_data))
579 goto out_bad_option;
580 }
581 mnt->mounted_uid = current->uid;
582 smb_setcodepage(server, &mnt->codepage);
583
584 /*
585 * Display the enabled options
586 * Note: smb_proc_getattr uses these in 2.4 (but was changed in 2.2)
587 */
588 if (mnt->flags & SMB_MOUNT_OLDATTR)
589 printk("SMBFS: Using core getattr (Win 95 speedup)\n");
590 else if (mnt->flags & SMB_MOUNT_DIRATTR)
591 printk("SMBFS: Using dir ff getattr\n");
592
593 if (smbiod_register_server(server) < 0) {
594 printk(KERN_ERR "smbfs: failed to start smbiod\n");
595 goto out_no_smbiod;
596 }
597
598 /*
599 * Keep the super block locked while we get the root inode.
600 */
601 smb_init_root_dirent(server, &root, sb);
602 root_inode = smb_iget(sb, &root);
603 if (!root_inode)
604 goto out_no_root;
605
606 sb->s_root = d_alloc_root(root_inode);
607 if (!sb->s_root)
608 goto out_no_root;
609
610 smb_new_dentry(sb->s_root);
611
612 return 0;
613
614 out_no_root:
615 iput(root_inode);
616 out_no_smbiod:
617 smb_unload_nls(server);
618 out_bad_option:
619 kfree(mem);
620 out_no_mem:
621 if (!server->mnt)
622 printk(KERN_ERR "smb_fill_super: allocation failure\n");
623 sb->s_fs_info = NULL;
624 kfree(server);
625 goto out_fail;
626 out_wrong_data:
627 printk(KERN_ERR "smbfs: mount_data version %d is not supported\n", ver);
628 goto out_fail;
629 out_no_data:
630 printk(KERN_ERR "smb_fill_super: missing data argument\n");
631 out_fail:
632 return -EINVAL;
633 out_no_server:
634 printk(KERN_ERR "smb_fill_super: cannot allocate struct smb_sb_info\n");
635 return -ENOMEM;
636 }
637
638 static int
639 smb_statfs(struct dentry *dentry, struct kstatfs *buf)
640 {
641 int result;
642
643 lock_kernel();
644
645 result = smb_proc_dskattr(dentry, buf);
646
647 unlock_kernel();
648
649 buf->f_type = SMB_SUPER_MAGIC;
650 buf->f_namelen = SMB_MAXPATHLEN;
651 return result;
652 }
653
654 int smb_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
655 {
656 int err = smb_revalidate_inode(dentry);
657 if (!err)
658 generic_fillattr(dentry->d_inode, stat);
659 return err;
660 }
661
662 int
663 smb_notify_change(struct dentry *dentry, struct iattr *attr)
664 {
665 struct inode *inode = dentry->d_inode;
666 struct smb_sb_info *server = server_from_dentry(dentry);
667 unsigned int mask = (S_IFREG | S_IFDIR | S_IRWXUGO);
668 int error, changed, refresh = 0;
669 struct smb_fattr fattr;
670
671 lock_kernel();
672
673 error = smb_revalidate_inode(dentry);
674 if (error)
675 goto out;
676
677 if ((error = inode_change_ok(inode, attr)) < 0)
678 goto out;
679
680 error = -EPERM;
681 if ((attr->ia_valid & ATTR_UID) && (attr->ia_uid != server->mnt->uid))
682 goto out;
683
684 if ((attr->ia_valid & ATTR_GID) && (attr->ia_uid != server->mnt->gid))
685 goto out;
686
687 if ((attr->ia_valid & ATTR_MODE) && (attr->ia_mode & ~mask))
688 goto out;
689
690 if ((attr->ia_valid & ATTR_SIZE) != 0) {
691 VERBOSE("changing %s/%s, old size=%ld, new size=%ld\n",
692 DENTRY_PATH(dentry),
693 (long) inode->i_size, (long) attr->ia_size);
694
695 filemap_write_and_wait(inode->i_mapping);
696
697 error = smb_open(dentry, O_WRONLY);
698 if (error)
699 goto out;
700 error = server->ops->truncate(inode, attr->ia_size);
701 if (error)
702 goto out;
703 error = vmtruncate(inode, attr->ia_size);
704 if (error)
705 goto out;
706 refresh = 1;
707 }
708
709 if (server->opt.capabilities & SMB_CAP_UNIX) {
710 /* For now we don't want to set the size with setattr_unix */
711 attr->ia_valid &= ~ATTR_SIZE;
712 /* FIXME: only call if we actually want to set something? */
713 error = smb_proc_setattr_unix(dentry, attr, 0, 0);
714 if (!error)
715 refresh = 1;
716
717 goto out;
718 }
719
720 /*
721 * Initialize the fattr and check for changed fields.
722 * Note: CTIME under SMB is creation time rather than
723 * change time, so we don't attempt to change it.
724 */
725 smb_get_inode_attr(inode, &fattr);
726
727 changed = 0;
728 if ((attr->ia_valid & ATTR_MTIME) != 0) {
729 fattr.f_mtime = attr->ia_mtime;
730 changed = 1;
731 }
732 if ((attr->ia_valid & ATTR_ATIME) != 0) {
733 fattr.f_atime = attr->ia_atime;
734 /* Earlier protocols don't have an access time */
735 if (server->opt.protocol >= SMB_PROTOCOL_LANMAN2)
736 changed = 1;
737 }
738 if (changed) {
739 error = smb_proc_settime(dentry, &fattr);
740 if (error)
741 goto out;
742 refresh = 1;
743 }
744
745 /*
746 * Check for mode changes ... we're extremely limited in
747 * what can be set for SMB servers: just the read-only bit.
748 */
749 if ((attr->ia_valid & ATTR_MODE) != 0) {
750 VERBOSE("%s/%s mode change, old=%x, new=%x\n",
751 DENTRY_PATH(dentry), fattr.f_mode, attr->ia_mode);
752 changed = 0;
753 if (attr->ia_mode & S_IWUSR) {
754 if (fattr.attr & aRONLY) {
755 fattr.attr &= ~aRONLY;
756 changed = 1;
757 }
758 } else {
759 if (!(fattr.attr & aRONLY)) {
760 fattr.attr |= aRONLY;
761 changed = 1;
762 }
763 }
764 if (changed) {
765 error = smb_proc_setattr(dentry, &fattr);
766 if (error)
767 goto out;
768 refresh = 1;
769 }
770 }
771 error = 0;
772
773 out:
774 if (refresh)
775 smb_refresh_inode(dentry);
776 unlock_kernel();
777 return error;
778 }
779
780 static int smb_get_sb(struct file_system_type *fs_type,
781 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
782 {
783 return get_sb_nodev(fs_type, flags, data, smb_fill_super, mnt);
784 }
785
786 static struct file_system_type smb_fs_type = {
787 .owner = THIS_MODULE,
788 .name = "smbfs",
789 .get_sb = smb_get_sb,
790 .kill_sb = kill_anon_super,
791 .fs_flags = FS_BINARY_MOUNTDATA,
792 };
793
794 static int __init init_smb_fs(void)
795 {
796 int err;
797 DEBUG1("registering ...\n");
798
799 err = init_inodecache();
800 if (err)
801 goto out_inode;
802 err = smb_init_request_cache();
803 if (err)
804 goto out_request;
805 err = register_filesystem(&smb_fs_type);
806 if (err)
807 goto out;
808 return 0;
809 out:
810 smb_destroy_request_cache();
811 out_request:
812 destroy_inodecache();
813 out_inode:
814 return err;
815 }
816
817 static void __exit exit_smb_fs(void)
818 {
819 DEBUG1("unregistering ...\n");
820 unregister_filesystem(&smb_fs_type);
821 smb_destroy_request_cache();
822 destroy_inodecache();
823 }
824
825 module_init(init_smb_fs)
826 module_exit(exit_smb_fs)
827 MODULE_LICENSE("GPL");