blob: 12d2a702c6c3b45016b5f1f18adfc51fad2f24d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs.h"
33#include "xfs_fs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110034#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110036#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "xfs_trans.h"
38#include "xfs_sb.h"
39#include "xfs_ag.h"
40#include "xfs_dir.h"
41#include "xfs_dir2.h"
42#include "xfs_alloc.h"
43#include "xfs_dmapi.h"
44#include "xfs_quota.h"
45#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110047#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "xfs_dir_sf.h"
50#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110051#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "xfs_dinode.h"
53#include "xfs_inode.h"
54#include "xfs_bmap.h"
Nathan Scotta844f452005-11-02 14:38:42 +110055#include "xfs_btree.h"
56#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include "xfs_rtalloc.h"
58#include "xfs_error.h"
59#include "xfs_itable.h"
60#include "xfs_rw.h"
61#include "xfs_acl.h"
62#include "xfs_cap.h"
63#include "xfs_mac.h"
64#include "xfs_attr.h"
65#include "xfs_buf_item.h"
66#include "xfs_utils.h"
67
68#include <linux/xattr.h>
69#include <linux/namei.h>
70
Nathan Scott4aeb6642005-11-02 11:43:58 +110071/*
72 * Change the requested timestamp in the given inode.
73 * We don't lock across timestamp updates, and we don't log them but
74 * we do record the fact that there is dirty information in core.
75 *
76 * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
77 * with XFS_ICHGTIME_ACC to be sure that access time
78 * update will take. Calling first with XFS_ICHGTIME_ACC
79 * and then XFS_ICHGTIME_MOD may fail to modify the access
80 * timestamp if the filesystem is mounted noacctm.
81 */
82void
83xfs_ichgtime(
84 xfs_inode_t *ip,
85 int flags)
86{
87 struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
88 timespec_t tv;
89
90 /*
91 * We're not supposed to change timestamps in readonly-mounted
92 * filesystems. Throw it away if anyone asks us.
93 */
94 if (unlikely(IS_RDONLY(inode)))
95 return;
96
97 /*
98 * Don't update access timestamps on reads if mounted "noatime".
99 * Throw it away if anyone asks us.
100 */
101 if (unlikely(
102 (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
103 (flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
104 XFS_ICHGTIME_ACC))
105 return;
106
107 nanotime(&tv);
108 if (flags & XFS_ICHGTIME_MOD) {
109 inode->i_mtime = tv;
110 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
111 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
112 }
113 if (flags & XFS_ICHGTIME_ACC) {
114 inode->i_atime = tv;
115 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
116 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
117 }
118 if (flags & XFS_ICHGTIME_CHG) {
119 inode->i_ctime = tv;
120 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
121 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
122 }
123
124 /*
125 * We update the i_update_core field _after_ changing
126 * the timestamps in order to coordinate properly with
127 * xfs_iflush() so that we don't lose timestamp updates.
128 * This keeps us from having to hold the inode lock
129 * while doing this. We use the SYNCHRONIZE macro to
130 * ensure that the compiler does not reorder the update
131 * of i_update_core above the timestamp updates above.
132 */
133 SYNCHRONIZE();
134 ip->i_update_core = 1;
135 if (!(inode->i_state & I_LOCK))
136 mark_inode_dirty_sync(inode);
137}
138
139/*
140 * Variant on the above which avoids querying the system clock
141 * in situations where we know the Linux inode timestamps have
142 * just been updated (and so we can update our inode cheaply).
143 * We also skip the readonly and noatime checks here, they are
144 * also catered for already.
145 */
146void
147xfs_ichgtime_fast(
148 xfs_inode_t *ip,
149 struct inode *inode,
150 int flags)
151{
152 timespec_t *tvp;
153
154 /*
155 * We're not supposed to change timestamps in readonly-mounted
156 * filesystems. Throw it away if anyone asks us.
157 */
158 if (unlikely(IS_RDONLY(inode)))
159 return;
160
161 /*
162 * Don't update access timestamps on reads if mounted "noatime".
163 * Throw it away if anyone asks us.
164 */
165 if (unlikely(
166 (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
167 ((flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
168 XFS_ICHGTIME_ACC)))
169 return;
170
171 if (flags & XFS_ICHGTIME_MOD) {
172 tvp = &inode->i_mtime;
173 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
174 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
175 }
176 if (flags & XFS_ICHGTIME_ACC) {
177 tvp = &inode->i_atime;
178 ip->i_d.di_atime.t_sec = (__int32_t)tvp->tv_sec;
179 ip->i_d.di_atime.t_nsec = (__int32_t)tvp->tv_nsec;
180 }
181 if (flags & XFS_ICHGTIME_CHG) {
182 tvp = &inode->i_ctime;
183 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
184 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
185 }
186
187 /*
188 * We update the i_update_core field _after_ changing
189 * the timestamps in order to coordinate properly with
190 * xfs_iflush() so that we don't lose timestamp updates.
191 * This keeps us from having to hold the inode lock
192 * while doing this. We use the SYNCHRONIZE macro to
193 * ensure that the compiler does not reorder the update
194 * of i_update_core above the timestamp updates above.
195 */
196 SYNCHRONIZE();
197 ip->i_update_core = 1;
198 if (!(inode->i_state & I_LOCK))
199 mark_inode_dirty_sync(inode);
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/*
204 * Pull the link count and size up from the xfs inode to the linux inode
205 */
206STATIC void
207validate_fields(
208 struct inode *ip)
209{
210 vnode_t *vp = LINVFS_GET_VP(ip);
211 vattr_t va;
212 int error;
213
214 va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
215 VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
216 if (likely(!error)) {
217 ip->i_nlink = va.va_nlink;
218 ip->i_blocks = va.va_nblocks;
219
220 /* we're under i_sem so i_size can't change under us */
221 if (i_size_read(ip) != va.va_size)
222 i_size_write(ip, va.va_size);
223 }
224}
225
226/*
227 * Determine whether a process has a valid fs_struct (kernel daemons
228 * like knfsd don't have an fs_struct).
229 *
230 * XXX(hch): nfsd is broken, better fix it instead.
231 */
232STATIC inline int
233has_fs_struct(struct task_struct *task)
234{
235 return (task->fs != init_task.fs);
236}
237
238STATIC int
239linvfs_mknod(
240 struct inode *dir,
241 struct dentry *dentry,
242 int mode,
243 dev_t rdev)
244{
245 struct inode *ip;
246 vattr_t va;
247 vnode_t *vp = NULL, *dvp = LINVFS_GET_VP(dir);
248 xfs_acl_t *default_acl = NULL;
249 attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS;
250 int error;
251
252 /*
253 * Irix uses Missed'em'V split, but doesn't want to see
254 * the upper 5 bits of (14bit) major.
255 */
256 if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
257 return -EINVAL;
258
259 if (test_default_acl && test_default_acl(dvp)) {
260 if (!_ACL_ALLOC(default_acl))
261 return -ENOMEM;
262 if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
263 _ACL_FREE(default_acl);
264 default_acl = NULL;
265 }
266 }
267
268 if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
269 mode &= ~current->fs->umask;
270
271 memset(&va, 0, sizeof(va));
272 va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 va.va_mode = mode;
274
275 switch (mode & S_IFMT) {
276 case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
277 va.va_rdev = sysv_encode_dev(rdev);
278 va.va_mask |= XFS_AT_RDEV;
279 /*FALLTHROUGH*/
280 case S_IFREG:
281 VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
282 break;
283 case S_IFDIR:
284 VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
285 break;
286 default:
287 error = EINVAL;
288 break;
289 }
290
291 if (default_acl) {
292 if (!error) {
293 error = _ACL_INHERIT(vp, &va, default_acl);
294 if (!error) {
295 VMODIFY(vp);
296 } else {
297 struct dentry teardown = {};
298 int err2;
299
300 /* Oh, the horror.
301 * If we can't add the ACL we must back out.
302 * ENOSPC can hit here, among other things.
303 */
304 teardown.d_inode = ip = LINVFS_GET_IP(vp);
305 teardown.d_name = dentry->d_name;
306
307 vn_mark_bad(vp);
308
309 if (S_ISDIR(mode))
310 VOP_RMDIR(dvp, &teardown, NULL, err2);
311 else
312 VOP_REMOVE(dvp, &teardown, NULL, err2);
313 VN_RELE(vp);
314 }
315 }
316 _ACL_FREE(default_acl);
317 }
318
319 if (!error) {
320 ASSERT(vp);
321 ip = LINVFS_GET_IP(vp);
322
323 if (S_ISCHR(mode) || S_ISBLK(mode))
324 ip->i_rdev = rdev;
325 else if (S_ISDIR(mode))
326 validate_fields(ip);
327 d_instantiate(dentry, ip);
328 validate_fields(dir);
329 }
330 return -error;
331}
332
333STATIC int
334linvfs_create(
335 struct inode *dir,
336 struct dentry *dentry,
337 int mode,
338 struct nameidata *nd)
339{
340 return linvfs_mknod(dir, dentry, mode, 0);
341}
342
343STATIC int
344linvfs_mkdir(
345 struct inode *dir,
346 struct dentry *dentry,
347 int mode)
348{
349 return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
350}
351
352STATIC struct dentry *
353linvfs_lookup(
354 struct inode *dir,
355 struct dentry *dentry,
356 struct nameidata *nd)
357{
358 struct vnode *vp = LINVFS_GET_VP(dir), *cvp;
359 int error;
360
361 if (dentry->d_name.len >= MAXNAMELEN)
362 return ERR_PTR(-ENAMETOOLONG);
363
364 VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
365 if (error) {
366 if (unlikely(error != ENOENT))
367 return ERR_PTR(-error);
368 d_add(dentry, NULL);
369 return NULL;
370 }
371
372 return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
373}
374
375STATIC int
376linvfs_link(
377 struct dentry *old_dentry,
378 struct inode *dir,
379 struct dentry *dentry)
380{
381 struct inode *ip; /* inode of guy being linked to */
382 vnode_t *tdvp; /* target directory for new name/link */
383 vnode_t *vp; /* vp of name being linked */
384 int error;
385
386 ip = old_dentry->d_inode; /* inode being linked to */
387 if (S_ISDIR(ip->i_mode))
388 return -EPERM;
389
390 tdvp = LINVFS_GET_VP(dir);
391 vp = LINVFS_GET_VP(ip);
392
393 VOP_LINK(tdvp, vp, dentry, NULL, error);
394 if (!error) {
395 VMODIFY(tdvp);
396 VN_HOLD(vp);
397 validate_fields(ip);
398 d_instantiate(dentry, ip);
399 }
400 return -error;
401}
402
403STATIC int
404linvfs_unlink(
405 struct inode *dir,
406 struct dentry *dentry)
407{
408 struct inode *inode;
409 vnode_t *dvp; /* directory containing name to remove */
410 int error;
411
412 inode = dentry->d_inode;
413 dvp = LINVFS_GET_VP(dir);
414
415 VOP_REMOVE(dvp, dentry, NULL, error);
416 if (!error) {
417 validate_fields(dir); /* For size only */
418 validate_fields(inode);
419 }
420
421 return -error;
422}
423
424STATIC int
425linvfs_symlink(
426 struct inode *dir,
427 struct dentry *dentry,
428 const char *symname)
429{
430 struct inode *ip;
431 vattr_t va;
432 vnode_t *dvp; /* directory containing name of symlink */
433 vnode_t *cvp; /* used to lookup symlink to put in dentry */
434 int error;
435
436 dvp = LINVFS_GET_VP(dir);
437 cvp = NULL;
438
439 memset(&va, 0, sizeof(va));
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000440 va.va_mode = S_IFLNK |
441 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
443
444 error = 0;
445 VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
446 if (!error && cvp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 ip = LINVFS_GET_IP(cvp);
448 d_instantiate(dentry, ip);
449 validate_fields(dir);
450 validate_fields(ip); /* size needs update */
451 }
452 return -error;
453}
454
455STATIC int
456linvfs_rmdir(
457 struct inode *dir,
458 struct dentry *dentry)
459{
460 struct inode *inode = dentry->d_inode;
461 vnode_t *dvp = LINVFS_GET_VP(dir);
462 int error;
463
464 VOP_RMDIR(dvp, dentry, NULL, error);
465 if (!error) {
466 validate_fields(inode);
467 validate_fields(dir);
468 }
469 return -error;
470}
471
472STATIC int
473linvfs_rename(
474 struct inode *odir,
475 struct dentry *odentry,
476 struct inode *ndir,
477 struct dentry *ndentry)
478{
479 struct inode *new_inode = ndentry->d_inode;
480 vnode_t *fvp; /* from directory */
481 vnode_t *tvp; /* target directory */
482 int error;
483
484 fvp = LINVFS_GET_VP(odir);
485 tvp = LINVFS_GET_VP(ndir);
486
487 VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
488 if (error)
489 return -error;
490
491 if (new_inode)
492 validate_fields(new_inode);
493
494 validate_fields(odir);
495 if (ndir != odir)
496 validate_fields(ndir);
497 return 0;
498}
499
500/*
501 * careful here - this function can get called recursively, so
502 * we need to be very careful about how much stack we use.
503 * uio is kmalloced for this reason...
504 */
Al Viro008b1502005-08-20 00:17:39 +0100505STATIC void *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506linvfs_follow_link(
507 struct dentry *dentry,
508 struct nameidata *nd)
509{
510 vnode_t *vp;
511 uio_t *uio;
512 iovec_t iov;
513 int error;
514 char *link;
515
516 ASSERT(dentry);
517 ASSERT(nd);
518
519 link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
520 if (!link) {
521 nd_set_link(nd, ERR_PTR(-ENOMEM));
Al Viro008b1502005-08-20 00:17:39 +0100522 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
525 uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
526 if (!uio) {
527 kfree(link);
528 nd_set_link(nd, ERR_PTR(-ENOMEM));
Al Viro008b1502005-08-20 00:17:39 +0100529 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
532 vp = LINVFS_GET_VP(dentry->d_inode);
533
534 iov.iov_base = link;
535 iov.iov_len = MAXNAMELEN;
536
537 uio->uio_iov = &iov;
538 uio->uio_offset = 0;
539 uio->uio_segflg = UIO_SYSSPACE;
540 uio->uio_resid = MAXNAMELEN;
541 uio->uio_iovcnt = 1;
542
543 VOP_READLINK(vp, uio, 0, NULL, error);
544 if (error) {
545 kfree(link);
546 link = ERR_PTR(-error);
547 } else {
548 link[MAXNAMELEN - uio->uio_resid] = '\0';
549 }
550 kfree(uio);
551
552 nd_set_link(nd, link);
Al Viro008b1502005-08-20 00:17:39 +0100553 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Nathan Scottcde410a2005-09-05 11:47:01 +1000556STATIC void
557linvfs_put_link(
558 struct dentry *dentry,
559 struct nameidata *nd,
560 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
Nathan Scottcde410a2005-09-05 11:47:01 +1000562 char *s = nd_get_link(nd);
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (!IS_ERR(s))
565 kfree(s);
566}
567
568#ifdef CONFIG_XFS_POSIX_ACL
569STATIC int
570linvfs_permission(
571 struct inode *inode,
572 int mode,
573 struct nameidata *nd)
574{
575 vnode_t *vp = LINVFS_GET_VP(inode);
576 int error;
577
578 mode <<= 6; /* convert from linux to vnode access bits */
579 VOP_ACCESS(vp, mode, NULL, error);
580 return -error;
581}
582#else
583#define linvfs_permission NULL
584#endif
585
586STATIC int
587linvfs_getattr(
588 struct vfsmount *mnt,
589 struct dentry *dentry,
590 struct kstat *stat)
591{
592 struct inode *inode = dentry->d_inode;
593 vnode_t *vp = LINVFS_GET_VP(inode);
594 int error = 0;
595
596 if (unlikely(vp->v_flag & VMODIFIED))
597 error = vn_revalidate(vp);
598 if (!error)
599 generic_fillattr(inode, stat);
600 return 0;
601}
602
603STATIC int
604linvfs_setattr(
605 struct dentry *dentry,
606 struct iattr *attr)
607{
608 struct inode *inode = dentry->d_inode;
609 unsigned int ia_valid = attr->ia_valid;
610 vnode_t *vp = LINVFS_GET_VP(inode);
611 vattr_t vattr;
612 int flags = 0;
613 int error;
614
615 memset(&vattr, 0, sizeof(vattr_t));
616 if (ia_valid & ATTR_UID) {
617 vattr.va_mask |= XFS_AT_UID;
618 vattr.va_uid = attr->ia_uid;
619 }
620 if (ia_valid & ATTR_GID) {
621 vattr.va_mask |= XFS_AT_GID;
622 vattr.va_gid = attr->ia_gid;
623 }
624 if (ia_valid & ATTR_SIZE) {
625 vattr.va_mask |= XFS_AT_SIZE;
626 vattr.va_size = attr->ia_size;
627 }
628 if (ia_valid & ATTR_ATIME) {
629 vattr.va_mask |= XFS_AT_ATIME;
630 vattr.va_atime = attr->ia_atime;
631 }
632 if (ia_valid & ATTR_MTIME) {
633 vattr.va_mask |= XFS_AT_MTIME;
634 vattr.va_mtime = attr->ia_mtime;
635 }
636 if (ia_valid & ATTR_CTIME) {
637 vattr.va_mask |= XFS_AT_CTIME;
638 vattr.va_ctime = attr->ia_ctime;
639 }
640 if (ia_valid & ATTR_MODE) {
641 vattr.va_mask |= XFS_AT_MODE;
642 vattr.va_mode = attr->ia_mode;
643 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
644 inode->i_mode &= ~S_ISGID;
645 }
646
647 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
648 flags |= ATTR_UTIME;
649#ifdef ATTR_NO_BLOCK
650 if ((ia_valid & ATTR_NO_BLOCK))
651 flags |= ATTR_NONBLOCK;
652#endif
653
654 VOP_SETATTR(vp, &vattr, flags, NULL, error);
655 if (error)
656 return -error;
657 vn_revalidate(vp);
658 return error;
659}
660
661STATIC void
662linvfs_truncate(
663 struct inode *inode)
664{
665 block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
666}
667
668STATIC int
669linvfs_setxattr(
670 struct dentry *dentry,
671 const char *name,
672 const void *data,
673 size_t size,
674 int flags)
675{
676 vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
677 char *attr = (char *)name;
678 attrnames_t *namesp;
679 int xflags = 0;
680 int error;
681
682 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
683 if (!namesp)
684 return -EOPNOTSUPP;
685 attr += namesp->attr_namelen;
686 error = namesp->attr_capable(vp, NULL);
687 if (error)
688 return error;
689
690 /* Convert Linux syscall to XFS internal ATTR flags */
691 if (flags & XATTR_CREATE)
692 xflags |= ATTR_CREATE;
693 if (flags & XATTR_REPLACE)
694 xflags |= ATTR_REPLACE;
695 xflags |= namesp->attr_flag;
696 return namesp->attr_set(vp, attr, (void *)data, size, xflags);
697}
698
699STATIC ssize_t
700linvfs_getxattr(
701 struct dentry *dentry,
702 const char *name,
703 void *data,
704 size_t size)
705{
706 vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
707 char *attr = (char *)name;
708 attrnames_t *namesp;
709 int xflags = 0;
710 ssize_t error;
711
712 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
713 if (!namesp)
714 return -EOPNOTSUPP;
715 attr += namesp->attr_namelen;
716 error = namesp->attr_capable(vp, NULL);
717 if (error)
718 return error;
719
720 /* Convert Linux syscall to XFS internal ATTR flags */
721 if (!size) {
722 xflags |= ATTR_KERNOVAL;
723 data = NULL;
724 }
725 xflags |= namesp->attr_flag;
726 return namesp->attr_get(vp, attr, (void *)data, size, xflags);
727}
728
729STATIC ssize_t
730linvfs_listxattr(
731 struct dentry *dentry,
732 char *data,
733 size_t size)
734{
735 vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
736 int error, xflags = ATTR_KERNAMELS;
737 ssize_t result;
738
739 if (!size)
740 xflags |= ATTR_KERNOVAL;
741 xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
742
743 error = attr_generic_list(vp, data, size, xflags, &result);
744 if (error < 0)
745 return error;
746 return result;
747}
748
749STATIC int
750linvfs_removexattr(
751 struct dentry *dentry,
752 const char *name)
753{
754 vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
755 char *attr = (char *)name;
756 attrnames_t *namesp;
757 int xflags = 0;
758 int error;
759
760 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
761 if (!namesp)
762 return -EOPNOTSUPP;
763 attr += namesp->attr_namelen;
764 error = namesp->attr_capable(vp, NULL);
765 if (error)
766 return error;
767 xflags |= namesp->attr_flag;
768 return namesp->attr_remove(vp, attr, xflags);
769}
770
771
772struct inode_operations linvfs_file_inode_operations = {
773 .permission = linvfs_permission,
774 .truncate = linvfs_truncate,
775 .getattr = linvfs_getattr,
776 .setattr = linvfs_setattr,
777 .setxattr = linvfs_setxattr,
778 .getxattr = linvfs_getxattr,
779 .listxattr = linvfs_listxattr,
780 .removexattr = linvfs_removexattr,
781};
782
783struct inode_operations linvfs_dir_inode_operations = {
784 .create = linvfs_create,
785 .lookup = linvfs_lookup,
786 .link = linvfs_link,
787 .unlink = linvfs_unlink,
788 .symlink = linvfs_symlink,
789 .mkdir = linvfs_mkdir,
790 .rmdir = linvfs_rmdir,
791 .mknod = linvfs_mknod,
792 .rename = linvfs_rename,
793 .permission = linvfs_permission,
794 .getattr = linvfs_getattr,
795 .setattr = linvfs_setattr,
796 .setxattr = linvfs_setxattr,
797 .getxattr = linvfs_getxattr,
798 .listxattr = linvfs_listxattr,
799 .removexattr = linvfs_removexattr,
800};
801
802struct inode_operations linvfs_symlink_inode_operations = {
803 .readlink = generic_readlink,
804 .follow_link = linvfs_follow_link,
805 .put_link = linvfs_put_link,
806 .permission = linvfs_permission,
807 .getattr = linvfs_getattr,
808 .setattr = linvfs_setattr,
809 .setxattr = linvfs_setxattr,
810 .getxattr = linvfs_getxattr,
811 .listxattr = linvfs_listxattr,
812 .removexattr = linvfs_removexattr,
813};