2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #include "xfs_trans.h"
42 #include "xfs_alloc.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_quota.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_ialloc.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode.h"
58 #include "xfs_rtalloc.h"
59 #include "xfs_error.h"
60 #include "xfs_itable.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
69 #include <linux/xattr.h>
70 #include <linux/namei.h>
74 * Pull the link count and size up from the xfs inode to the linux inode
80 vnode_t
*vp
= LINVFS_GET_VP(ip
);
84 va
.va_mask
= XFS_AT_NLINK
|XFS_AT_SIZE
|XFS_AT_NBLOCKS
;
85 VOP_GETATTR(vp
, &va
, ATTR_LAZY
, NULL
, error
);
87 ip
->i_nlink
= va
.va_nlink
;
88 ip
->i_blocks
= va
.va_nblocks
;
90 /* we're under i_sem so i_size can't change under us */
91 if (i_size_read(ip
) != va
.va_size
)
92 i_size_write(ip
, va
.va_size
);
97 * Determine whether a process has a valid fs_struct (kernel daemons
98 * like knfsd don't have an fs_struct).
100 * XXX(hch): nfsd is broken, better fix it instead.
103 has_fs_struct(struct task_struct
*task
)
105 return (task
->fs
!= init_task
.fs
);
111 struct dentry
*dentry
,
117 vnode_t
*vp
= NULL
, *dvp
= LINVFS_GET_VP(dir
);
118 xfs_acl_t
*default_acl
= NULL
;
119 attrexists_t test_default_acl
= _ACL_DEFAULT_EXISTS
;
123 * Irix uses Missed'em'V split, but doesn't want to see
124 * the upper 5 bits of (14bit) major.
126 if (!sysv_valid_dev(rdev
) || MAJOR(rdev
) & ~0x1ff)
129 if (test_default_acl
&& test_default_acl(dvp
)) {
130 if (!_ACL_ALLOC(default_acl
))
132 if (!_ACL_GET_DEFAULT(dvp
, default_acl
)) {
133 _ACL_FREE(default_acl
);
138 if (IS_POSIXACL(dir
) && !default_acl
&& has_fs_struct(current
))
139 mode
&= ~current
->fs
->umask
;
141 memset(&va
, 0, sizeof(va
));
142 va
.va_mask
= XFS_AT_TYPE
|XFS_AT_MODE
;
145 switch (mode
& S_IFMT
) {
146 case S_IFCHR
: case S_IFBLK
: case S_IFIFO
: case S_IFSOCK
:
147 va
.va_rdev
= sysv_encode_dev(rdev
);
148 va
.va_mask
|= XFS_AT_RDEV
;
151 VOP_CREATE(dvp
, dentry
, &va
, &vp
, NULL
, error
);
154 VOP_MKDIR(dvp
, dentry
, &va
, &vp
, NULL
, error
);
163 error
= _ACL_INHERIT(vp
, &va
, default_acl
);
167 struct dentry teardown
= {};
171 * If we can't add the ACL we must back out.
172 * ENOSPC can hit here, among other things.
174 teardown
.d_inode
= ip
= LINVFS_GET_IP(vp
);
175 teardown
.d_name
= dentry
->d_name
;
180 VOP_RMDIR(dvp
, &teardown
, NULL
, err2
);
182 VOP_REMOVE(dvp
, &teardown
, NULL
, err2
);
186 _ACL_FREE(default_acl
);
191 ip
= LINVFS_GET_IP(vp
);
193 if (S_ISCHR(mode
) || S_ISBLK(mode
))
195 else if (S_ISDIR(mode
))
197 d_instantiate(dentry
, ip
);
198 validate_fields(dir
);
206 struct dentry
*dentry
,
208 struct nameidata
*nd
)
210 return linvfs_mknod(dir
, dentry
, mode
, 0);
216 struct dentry
*dentry
,
219 return linvfs_mknod(dir
, dentry
, mode
|S_IFDIR
, 0);
222 STATIC
struct dentry
*
225 struct dentry
*dentry
,
226 struct nameidata
*nd
)
228 struct vnode
*vp
= LINVFS_GET_VP(dir
), *cvp
;
231 if (dentry
->d_name
.len
>= MAXNAMELEN
)
232 return ERR_PTR(-ENAMETOOLONG
);
234 VOP_LOOKUP(vp
, dentry
, &cvp
, 0, NULL
, NULL
, error
);
236 if (unlikely(error
!= ENOENT
))
237 return ERR_PTR(-error
);
242 return d_splice_alias(LINVFS_GET_IP(cvp
), dentry
);
247 struct dentry
*old_dentry
,
249 struct dentry
*dentry
)
251 struct inode
*ip
; /* inode of guy being linked to */
252 vnode_t
*tdvp
; /* target directory for new name/link */
253 vnode_t
*vp
; /* vp of name being linked */
256 ip
= old_dentry
->d_inode
; /* inode being linked to */
257 if (S_ISDIR(ip
->i_mode
))
260 tdvp
= LINVFS_GET_VP(dir
);
261 vp
= LINVFS_GET_VP(ip
);
263 VOP_LINK(tdvp
, vp
, dentry
, NULL
, error
);
268 d_instantiate(dentry
, ip
);
276 struct dentry
*dentry
)
279 vnode_t
*dvp
; /* directory containing name to remove */
282 inode
= dentry
->d_inode
;
283 dvp
= LINVFS_GET_VP(dir
);
285 VOP_REMOVE(dvp
, dentry
, NULL
, error
);
287 validate_fields(dir
); /* For size only */
288 validate_fields(inode
);
297 struct dentry
*dentry
,
302 vnode_t
*dvp
; /* directory containing name of symlink */
303 vnode_t
*cvp
; /* used to lookup symlink to put in dentry */
306 dvp
= LINVFS_GET_VP(dir
);
309 memset(&va
, 0, sizeof(va
));
310 va
.va_mode
= S_IFLNK
|
311 (irix_symlink_mode
? 0777 & ~current
->fs
->umask
: S_IRWXUGO
);
312 va
.va_mask
= XFS_AT_TYPE
|XFS_AT_MODE
;
315 VOP_SYMLINK(dvp
, dentry
, &va
, (char *)symname
, &cvp
, NULL
, error
);
317 ip
= LINVFS_GET_IP(cvp
);
318 d_instantiate(dentry
, ip
);
319 validate_fields(dir
);
320 validate_fields(ip
); /* size needs update */
328 struct dentry
*dentry
)
330 struct inode
*inode
= dentry
->d_inode
;
331 vnode_t
*dvp
= LINVFS_GET_VP(dir
);
334 VOP_RMDIR(dvp
, dentry
, NULL
, error
);
336 validate_fields(inode
);
337 validate_fields(dir
);
345 struct dentry
*odentry
,
347 struct dentry
*ndentry
)
349 struct inode
*new_inode
= ndentry
->d_inode
;
350 vnode_t
*fvp
; /* from directory */
351 vnode_t
*tvp
; /* target directory */
354 fvp
= LINVFS_GET_VP(odir
);
355 tvp
= LINVFS_GET_VP(ndir
);
357 VOP_RENAME(fvp
, odentry
, tvp
, ndentry
, NULL
, error
);
362 validate_fields(new_inode
);
364 validate_fields(odir
);
366 validate_fields(ndir
);
371 * careful here - this function can get called recursively, so
372 * we need to be very careful about how much stack we use.
373 * uio is kmalloced for this reason...
377 struct dentry
*dentry
,
378 struct nameidata
*nd
)
389 link
= (char *)kmalloc(MAXNAMELEN
+1, GFP_KERNEL
);
391 nd_set_link(nd
, ERR_PTR(-ENOMEM
));
395 uio
= (uio_t
*)kmalloc(sizeof(uio_t
), GFP_KERNEL
);
398 nd_set_link(nd
, ERR_PTR(-ENOMEM
));
402 vp
= LINVFS_GET_VP(dentry
->d_inode
);
405 iov
.iov_len
= MAXNAMELEN
;
409 uio
->uio_segflg
= UIO_SYSSPACE
;
410 uio
->uio_resid
= MAXNAMELEN
;
413 VOP_READLINK(vp
, uio
, 0, NULL
, error
);
416 link
= ERR_PTR(-error
);
418 link
[MAXNAMELEN
- uio
->uio_resid
] = '\0';
422 nd_set_link(nd
, link
);
426 static void linvfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
428 char *s
= nd_get_link(nd
);
433 #ifdef CONFIG_XFS_POSIX_ACL
438 struct nameidata
*nd
)
440 vnode_t
*vp
= LINVFS_GET_VP(inode
);
443 mode
<<= 6; /* convert from linux to vnode access bits */
444 VOP_ACCESS(vp
, mode
, NULL
, error
);
448 #define linvfs_permission NULL
453 struct vfsmount
*mnt
,
454 struct dentry
*dentry
,
457 struct inode
*inode
= dentry
->d_inode
;
458 vnode_t
*vp
= LINVFS_GET_VP(inode
);
461 if (unlikely(vp
->v_flag
& VMODIFIED
))
462 error
= vn_revalidate(vp
);
464 generic_fillattr(inode
, stat
);
470 struct dentry
*dentry
,
473 struct inode
*inode
= dentry
->d_inode
;
474 unsigned int ia_valid
= attr
->ia_valid
;
475 vnode_t
*vp
= LINVFS_GET_VP(inode
);
480 memset(&vattr
, 0, sizeof(vattr_t
));
481 if (ia_valid
& ATTR_UID
) {
482 vattr
.va_mask
|= XFS_AT_UID
;
483 vattr
.va_uid
= attr
->ia_uid
;
485 if (ia_valid
& ATTR_GID
) {
486 vattr
.va_mask
|= XFS_AT_GID
;
487 vattr
.va_gid
= attr
->ia_gid
;
489 if (ia_valid
& ATTR_SIZE
) {
490 vattr
.va_mask
|= XFS_AT_SIZE
;
491 vattr
.va_size
= attr
->ia_size
;
493 if (ia_valid
& ATTR_ATIME
) {
494 vattr
.va_mask
|= XFS_AT_ATIME
;
495 vattr
.va_atime
= attr
->ia_atime
;
497 if (ia_valid
& ATTR_MTIME
) {
498 vattr
.va_mask
|= XFS_AT_MTIME
;
499 vattr
.va_mtime
= attr
->ia_mtime
;
501 if (ia_valid
& ATTR_CTIME
) {
502 vattr
.va_mask
|= XFS_AT_CTIME
;
503 vattr
.va_ctime
= attr
->ia_ctime
;
505 if (ia_valid
& ATTR_MODE
) {
506 vattr
.va_mask
|= XFS_AT_MODE
;
507 vattr
.va_mode
= attr
->ia_mode
;
508 if (!in_group_p(inode
->i_gid
) && !capable(CAP_FSETID
))
509 inode
->i_mode
&= ~S_ISGID
;
512 if (ia_valid
& (ATTR_MTIME_SET
| ATTR_ATIME_SET
))
515 if ((ia_valid
& ATTR_NO_BLOCK
))
516 flags
|= ATTR_NONBLOCK
;
519 VOP_SETATTR(vp
, &vattr
, flags
, NULL
, error
);
530 block_truncate_page(inode
->i_mapping
, inode
->i_size
, linvfs_get_block
);
535 struct dentry
*dentry
,
541 vnode_t
*vp
= LINVFS_GET_VP(dentry
->d_inode
);
542 char *attr
= (char *)name
;
547 namesp
= attr_lookup_namespace(attr
, attr_namespaces
, ATTR_NAMECOUNT
);
550 attr
+= namesp
->attr_namelen
;
551 error
= namesp
->attr_capable(vp
, NULL
);
555 /* Convert Linux syscall to XFS internal ATTR flags */
556 if (flags
& XATTR_CREATE
)
557 xflags
|= ATTR_CREATE
;
558 if (flags
& XATTR_REPLACE
)
559 xflags
|= ATTR_REPLACE
;
560 xflags
|= namesp
->attr_flag
;
561 return namesp
->attr_set(vp
, attr
, (void *)data
, size
, xflags
);
566 struct dentry
*dentry
,
571 vnode_t
*vp
= LINVFS_GET_VP(dentry
->d_inode
);
572 char *attr
= (char *)name
;
577 namesp
= attr_lookup_namespace(attr
, attr_namespaces
, ATTR_NAMECOUNT
);
580 attr
+= namesp
->attr_namelen
;
581 error
= namesp
->attr_capable(vp
, NULL
);
585 /* Convert Linux syscall to XFS internal ATTR flags */
587 xflags
|= ATTR_KERNOVAL
;
590 xflags
|= namesp
->attr_flag
;
591 return namesp
->attr_get(vp
, attr
, (void *)data
, size
, xflags
);
596 struct dentry
*dentry
,
600 vnode_t
*vp
= LINVFS_GET_VP(dentry
->d_inode
);
601 int error
, xflags
= ATTR_KERNAMELS
;
605 xflags
|= ATTR_KERNOVAL
;
606 xflags
|= capable(CAP_SYS_ADMIN
) ? ATTR_KERNFULLS
: ATTR_KERNORMALS
;
608 error
= attr_generic_list(vp
, data
, size
, xflags
, &result
);
616 struct dentry
*dentry
,
619 vnode_t
*vp
= LINVFS_GET_VP(dentry
->d_inode
);
620 char *attr
= (char *)name
;
625 namesp
= attr_lookup_namespace(attr
, attr_namespaces
, ATTR_NAMECOUNT
);
628 attr
+= namesp
->attr_namelen
;
629 error
= namesp
->attr_capable(vp
, NULL
);
632 xflags
|= namesp
->attr_flag
;
633 return namesp
->attr_remove(vp
, attr
, xflags
);
637 struct inode_operations linvfs_file_inode_operations
= {
638 .permission
= linvfs_permission
,
639 .truncate
= linvfs_truncate
,
640 .getattr
= linvfs_getattr
,
641 .setattr
= linvfs_setattr
,
642 .setxattr
= linvfs_setxattr
,
643 .getxattr
= linvfs_getxattr
,
644 .listxattr
= linvfs_listxattr
,
645 .removexattr
= linvfs_removexattr
,
648 struct inode_operations linvfs_dir_inode_operations
= {
649 .create
= linvfs_create
,
650 .lookup
= linvfs_lookup
,
652 .unlink
= linvfs_unlink
,
653 .symlink
= linvfs_symlink
,
654 .mkdir
= linvfs_mkdir
,
655 .rmdir
= linvfs_rmdir
,
656 .mknod
= linvfs_mknod
,
657 .rename
= linvfs_rename
,
658 .permission
= linvfs_permission
,
659 .getattr
= linvfs_getattr
,
660 .setattr
= linvfs_setattr
,
661 .setxattr
= linvfs_setxattr
,
662 .getxattr
= linvfs_getxattr
,
663 .listxattr
= linvfs_listxattr
,
664 .removexattr
= linvfs_removexattr
,
667 struct inode_operations linvfs_symlink_inode_operations
= {
668 .readlink
= generic_readlink
,
669 .follow_link
= linvfs_follow_link
,
670 .put_link
= linvfs_put_link
,
671 .permission
= linvfs_permission
,
672 .getattr
= linvfs_getattr
,
673 .setattr
= linvfs_setattr
,
674 .setxattr
= linvfs_setxattr
,
675 .getxattr
= linvfs_getxattr
,
676 .listxattr
= linvfs_listxattr
,
677 .removexattr
= linvfs_removexattr
,