2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/namei.h>
16 #include <linux/utsname.h>
18 #include <linux/xattr.h>
19 #include <linux/posix_acl.h>
20 #include <linux/gfs2_ondisk.h>
21 #include <linux/crc32.h>
22 #include <linux/lm_interface.h>
23 #include <asm/uaccess.h>
35 #include "ops_dentry.h"
36 #include "ops_inode.h"
43 * gfs2_create - Create a file
44 * @dir: The directory in which to create the file
45 * @dentry: The dentry of the new file
46 * @mode: The mode of the new file
51 static int gfs2_create(struct inode *dir, struct dentry *dentry,
52 int mode, struct nameidata *nd)
54 struct gfs2_inode *dip = GFS2_I(dir);
55 struct gfs2_sbd *sdp = GFS2_SB(dir);
56 struct gfs2_holder ghs[2];
59 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
62 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
65 if (dip->i_alloc.al_rgd)
66 gfs2_inplace_release(dip);
67 gfs2_quota_unlock(dip);
69 gfs2_glock_dq_uninit_m(2, ghs);
70 mark_inode_dirty(inode);
72 } else if (PTR_ERR(inode) != -EEXIST ||
73 (nd->intent.open.flags & O_EXCL)) {
74 gfs2_holder_uninit(ghs);
75 return PTR_ERR(inode);
78 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
81 gfs2_holder_uninit(ghs);
84 gfs2_holder_uninit(ghs);
85 return PTR_ERR(inode);
90 d_instantiate(dentry, inode);
96 * gfs2_lookup - Look up a filename in a directory and return its inode
97 * @dir: The directory inode
98 * @dentry: The dentry of the new inode
99 * @nd: passed from Linux VFS, ignored by us
101 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
106 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
107 struct nameidata *nd)
109 struct inode *inode = NULL;
111 dentry->d_op = &gfs2_dops;
113 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
114 if (inode && IS_ERR(inode))
115 return ERR_PTR(PTR_ERR(inode));
118 return d_splice_alias(inode, dentry);
119 d_add(dentry, inode);
125 * gfs2_link - Link to a file
126 * @old_dentry: The inode to link
127 * @dir: Add link to this directory
128 * @dentry: The name of the link
130 * Link the inode in "old_dentry" into the directory "dir" with the
136 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
137 struct dentry *dentry)
139 struct gfs2_inode *dip = GFS2_I(dir);
140 struct gfs2_sbd *sdp = GFS2_SB(dir);
141 struct inode *inode = old_dentry->d_inode;
142 struct gfs2_inode *ip = GFS2_I(inode);
143 struct gfs2_holder ghs[2];
147 if (S_ISDIR(inode->i_mode))
150 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
151 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
153 error = gfs2_glock_nq_m(2, ghs);
157 error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
161 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
172 if (!dip->i_inode.i_nlink)
175 if (dip->i_di.di_entries == (u32)-1)
178 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
181 if (!ip->i_inode.i_nlink)
184 if (ip->i_inode.i_nlink == (u32)-1)
187 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
192 if (alloc_required) {
193 struct gfs2_alloc *al = gfs2_alloc_get(dip);
195 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
199 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
203 al->al_requested = sdp->sd_max_dirres;
205 error = gfs2_inplace_reserve(dip);
209 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
210 al->al_rgd->rd_ri.ri_length +
211 2 * RES_DINODE + RES_STATFS +
216 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
221 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
222 IF2DT(inode->i_mode));
226 error = gfs2_change_nlink(ip, +1);
232 gfs2_inplace_release(dip);
235 gfs2_quota_unlock(dip);
240 gfs2_glock_dq_m(2, ghs);
242 gfs2_holder_uninit(ghs);
243 gfs2_holder_uninit(ghs + 1);
245 atomic_inc(&inode->i_count);
246 d_instantiate(dentry, inode);
247 mark_inode_dirty(inode);
253 * gfs2_unlink - Unlink a file
254 * @dir: The inode of the directory containing the file to unlink
255 * @dentry: The file itself
257 * Unlink a file. Call gfs2_unlinki()
262 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
264 struct gfs2_inode *dip = GFS2_I(dir);
265 struct gfs2_sbd *sdp = GFS2_SB(dir);
266 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
267 struct gfs2_holder ghs[2];
270 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
271 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
273 error = gfs2_glock_nq_m(2, ghs);
277 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
281 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
285 error = gfs2_dir_del(dip, &dentry->d_name);
289 error = gfs2_change_nlink(ip, -1);
294 gfs2_glock_dq_m(2, ghs);
296 gfs2_holder_uninit(ghs);
297 gfs2_holder_uninit(ghs + 1);
302 * gfs2_symlink - Create a symlink
303 * @dir: The directory to create the symlink in
304 * @dentry: The dentry to put the symlink in
305 * @symname: The thing which the link points to
310 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
313 struct gfs2_inode *dip = GFS2_I(dir), *ip;
314 struct gfs2_sbd *sdp = GFS2_SB(dir);
315 struct gfs2_holder ghs[2];
317 struct buffer_head *dibh;
321 /* Must be stuffed with a null terminator for gfs2_follow_link() */
322 size = strlen(symname);
323 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
324 return -ENAMETOOLONG;
326 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
328 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
330 gfs2_holder_uninit(ghs);
331 return PTR_ERR(inode);
334 ip = ghs[1].gh_gl->gl_object;
336 ip->i_di.di_size = size;
338 error = gfs2_meta_inode_buffer(ip, &dibh);
340 if (!gfs2_assert_withdraw(sdp, !error)) {
341 gfs2_dinode_out(ip, dibh->b_data);
342 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
348 if (dip->i_alloc.al_rgd)
349 gfs2_inplace_release(dip);
350 gfs2_quota_unlock(dip);
353 gfs2_glock_dq_uninit_m(2, ghs);
355 d_instantiate(dentry, inode);
356 mark_inode_dirty(inode);
362 * gfs2_mkdir - Make a directory
363 * @dir: The parent directory of the new one
364 * @dentry: The dentry of the new directory
365 * @mode: The mode of the new directory
370 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
372 struct gfs2_inode *dip = GFS2_I(dir), *ip;
373 struct gfs2_sbd *sdp = GFS2_SB(dir);
374 struct gfs2_holder ghs[2];
376 struct buffer_head *dibh;
379 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
381 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
383 gfs2_holder_uninit(ghs);
384 return PTR_ERR(inode);
387 ip = ghs[1].gh_gl->gl_object;
389 ip->i_inode.i_nlink = 2;
390 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
391 ip->i_di.di_flags |= GFS2_DIF_JDATA;
392 ip->i_di.di_entries = 2;
394 error = gfs2_meta_inode_buffer(ip, &dibh);
396 if (!gfs2_assert_withdraw(sdp, !error)) {
397 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
398 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
401 gfs2_str2qstr(&str, ".");
402 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
403 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
404 dent->de_inum = di->di_num; /* already GFS2 endian */
405 dent->de_type = cpu_to_be16(DT_DIR);
406 di->di_entries = cpu_to_be32(1);
408 gfs2_str2qstr(&str, "..");
409 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
410 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
412 gfs2_inum_out(&dip->i_num, &dent->de_inum);
413 dent->de_type = cpu_to_be16(DT_DIR);
415 gfs2_dinode_out(ip, di);
420 error = gfs2_change_nlink(dip, +1);
421 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
424 if (dip->i_alloc.al_rgd)
425 gfs2_inplace_release(dip);
426 gfs2_quota_unlock(dip);
429 gfs2_glock_dq_uninit_m(2, ghs);
431 d_instantiate(dentry, inode);
432 mark_inode_dirty(inode);
438 * gfs2_rmdir - Remove a directory
439 * @dir: The parent directory of the directory to be removed
440 * @dentry: The dentry of the directory to remove
442 * Remove a directory. Call gfs2_rmdiri()
447 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
449 struct gfs2_inode *dip = GFS2_I(dir);
450 struct gfs2_sbd *sdp = GFS2_SB(dir);
451 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
452 struct gfs2_holder ghs[2];
455 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
456 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
458 error = gfs2_glock_nq_m(2, ghs);
462 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
466 if (ip->i_di.di_entries < 2) {
467 if (gfs2_consist_inode(ip))
468 gfs2_dinode_print(ip);
472 if (ip->i_di.di_entries > 2) {
477 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
481 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
486 gfs2_glock_dq_m(2, ghs);
488 gfs2_holder_uninit(ghs);
489 gfs2_holder_uninit(ghs + 1);
494 * gfs2_mknod - Make a special file
495 * @dir: The directory in which the special file will reside
496 * @dentry: The dentry of the special file
497 * @mode: The mode of the special file
498 * @rdev: The device specification of the special file
502 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
505 struct gfs2_inode *dip = GFS2_I(dir);
506 struct gfs2_sbd *sdp = GFS2_SB(dir);
507 struct gfs2_holder ghs[2];
510 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
512 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
514 gfs2_holder_uninit(ghs);
515 return PTR_ERR(inode);
519 if (dip->i_alloc.al_rgd)
520 gfs2_inplace_release(dip);
521 gfs2_quota_unlock(dip);
524 gfs2_glock_dq_uninit_m(2, ghs);
526 d_instantiate(dentry, inode);
527 mark_inode_dirty(inode);
533 * gfs2_rename - Rename a file
534 * @odir: Parent directory of old file name
535 * @odentry: The old dentry of the file
536 * @ndir: Parent directory of new file name
537 * @ndentry: The new dentry of the file
542 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
543 struct inode *ndir, struct dentry *ndentry)
545 struct gfs2_inode *odip = GFS2_I(odir);
546 struct gfs2_inode *ndip = GFS2_I(ndir);
547 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
548 struct gfs2_inode *nip = NULL;
549 struct gfs2_sbd *sdp = GFS2_SB(odir);
550 struct gfs2_holder ghs[4], r_gh;
557 if (ndentry->d_inode) {
558 nip = GFS2_I(ndentry->d_inode);
563 /* Make sure we aren't trying to move a dirctory into it's subdir */
565 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
568 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
573 error = gfs2_ok_to_move(ip, ndip);
579 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
581 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
584 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
588 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
592 error = gfs2_glock_nq_m(num_gh, ghs);
596 /* Check out the old directory */
598 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
602 /* Check out the new directory */
605 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
609 if (S_ISDIR(nip->i_inode.i_mode)) {
610 if (nip->i_di.di_entries < 2) {
611 if (gfs2_consist_inode(nip))
612 gfs2_dinode_print(nip);
616 if (nip->i_di.di_entries > 2) {
622 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
626 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
638 if (!ndip->i_inode.i_nlink) {
642 if (ndip->i_di.di_entries == (u32)-1) {
646 if (S_ISDIR(ip->i_inode.i_mode) &&
647 ndip->i_inode.i_nlink == (u32)-1) {
654 /* Check out the dir to be renamed */
657 error = permission(odentry->d_inode, MAY_WRITE, NULL);
662 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
667 if (alloc_required) {
668 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
670 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
674 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
678 al->al_requested = sdp->sd_max_dirres;
680 error = gfs2_inplace_reserve(ndip);
684 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
685 al->al_rgd->rd_ri.ri_length +
686 4 * RES_DINODE + 4 * RES_LEAF +
687 RES_STATFS + RES_QUOTA, 0);
691 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
697 /* Remove the target file, if it exists */
700 if (S_ISDIR(nip->i_inode.i_mode))
701 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
703 error = gfs2_dir_del(ndip, &ndentry->d_name);
706 error = gfs2_change_nlink(nip, -1);
714 gfs2_str2qstr(&name, "..");
716 error = gfs2_change_nlink(ndip, +1);
719 error = gfs2_change_nlink(odip, -1);
723 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
727 struct buffer_head *dibh;
728 error = gfs2_meta_inode_buffer(ip, &dibh);
731 ip->i_inode.i_ctime.tv_sec = get_seconds();
732 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
733 gfs2_dinode_out(ip, dibh->b_data);
737 error = gfs2_dir_del(odip, &odentry->d_name);
741 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
742 IF2DT(ip->i_inode.i_mode));
750 gfs2_inplace_release(ndip);
753 gfs2_quota_unlock(ndip);
756 gfs2_alloc_put(ndip);
758 gfs2_glock_dq_m(num_gh, ghs);
760 for (x = 0; x < num_gh; x++)
761 gfs2_holder_uninit(ghs + x);
764 gfs2_glock_dq_uninit(&r_gh);
770 * gfs2_readlink - Read the value of a symlink
771 * @dentry: the symlink
772 * @buf: the buffer to read the symlink data into
773 * @size: the size of the buffer
778 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
781 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
782 char array[GFS2_FAST_NAME_SIZE], *buf = array;
783 unsigned int len = GFS2_FAST_NAME_SIZE;
786 error = gfs2_readlinki(ip, &buf, &len);
790 if (user_size > len - 1)
793 if (copy_to_user(user_buf, buf, user_size))
805 * gfs2_follow_link - Follow a symbolic link
806 * @dentry: The dentry of the link
807 * @nd: Data that we pass to vfs_follow_link()
809 * This can handle symlinks of any size. It is optimised for symlinks
810 * under GFS2_FAST_NAME_SIZE.
812 * Returns: 0 on success or error code
815 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
817 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
818 char array[GFS2_FAST_NAME_SIZE], *buf = array;
819 unsigned int len = GFS2_FAST_NAME_SIZE;
822 error = gfs2_readlinki(ip, &buf, &len);
824 error = vfs_follow_link(nd, buf);
829 return ERR_PTR(error);
836 * @nd: passed from Linux VFS, ignored by us
841 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
843 struct gfs2_inode *ip = GFS2_I(inode);
844 struct gfs2_holder i_gh;
847 if (ip->i_vn == ip->i_gl->gl_vn)
848 return generic_permission(inode, mask, gfs2_check_acl);
850 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
852 error = generic_permission(inode, mask, gfs2_check_acl_locked);
853 gfs2_glock_dq_uninit(&i_gh);
859 static int setattr_size(struct inode *inode, struct iattr *attr)
861 struct gfs2_inode *ip = GFS2_I(inode);
864 if (attr->ia_size != ip->i_di.di_size) {
865 error = vmtruncate(inode, attr->ia_size);
870 error = gfs2_truncatei(ip, attr->ia_size);
877 static int setattr_chown(struct inode *inode, struct iattr *attr)
879 struct gfs2_inode *ip = GFS2_I(inode);
880 struct gfs2_sbd *sdp = GFS2_SB(inode);
881 struct buffer_head *dibh;
882 u32 ouid, ogid, nuid, ngid;
890 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
891 ouid = nuid = NO_QUOTA_CHANGE;
892 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
893 ogid = ngid = NO_QUOTA_CHANGE;
897 error = gfs2_quota_lock(ip, nuid, ngid);
901 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
902 error = gfs2_quota_check(ip, nuid, ngid);
907 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
911 error = gfs2_meta_inode_buffer(ip, &dibh);
915 error = inode_setattr(inode, attr);
916 gfs2_assert_warn(sdp, !error);
918 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
919 gfs2_dinode_out(ip, dibh->b_data);
922 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
923 gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid);
924 gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid);
930 gfs2_quota_unlock(ip);
937 * gfs2_setattr - Change attributes on an inode
938 * @dentry: The dentry which is changing
939 * @attr: The structure describing the change
941 * The VFS layer wants to change one or more of an inodes attributes. Write
942 * that change out to disk.
947 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
949 struct inode *inode = dentry->d_inode;
950 struct gfs2_inode *ip = GFS2_I(inode);
951 struct gfs2_holder i_gh;
954 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
959 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
962 error = inode_change_ok(inode, attr);
966 if (attr->ia_valid & ATTR_SIZE)
967 error = setattr_size(inode, attr);
968 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
969 error = setattr_chown(inode, attr);
970 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
971 error = gfs2_acl_chmod(ip, attr);
973 error = gfs2_setattr_simple(ip, attr);
976 gfs2_glock_dq_uninit(&i_gh);
978 mark_inode_dirty(inode);
983 * gfs2_getattr - Read out an inode's attributes
984 * @mnt: The vfsmount the inode is being accessed from
985 * @dentry: The dentry to stat
986 * @stat: The inode's stats
991 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
994 struct inode *inode = dentry->d_inode;
995 struct gfs2_inode *ip = GFS2_I(inode);
996 struct gfs2_holder gh;
999 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1001 generic_fillattr(inode, stat);
1002 gfs2_glock_dq_uninit(&gh);
1008 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1009 const void *data, size_t size, int flags)
1011 struct inode *inode = dentry->d_inode;
1012 struct gfs2_ea_request er;
1014 memset(&er, 0, sizeof(struct gfs2_ea_request));
1015 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1016 if (er.er_type == GFS2_EATYPE_UNUSED)
1018 er.er_data = (char *)data;
1019 er.er_name_len = strlen(er.er_name);
1020 er.er_data_len = size;
1021 er.er_flags = flags;
1023 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1025 return gfs2_ea_set(GFS2_I(inode), &er);
1028 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1029 void *data, size_t size)
1031 struct gfs2_ea_request er;
1033 memset(&er, 0, sizeof(struct gfs2_ea_request));
1034 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1035 if (er.er_type == GFS2_EATYPE_UNUSED)
1038 er.er_name_len = strlen(er.er_name);
1039 er.er_data_len = size;
1041 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1044 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1046 struct gfs2_ea_request er;
1048 memset(&er, 0, sizeof(struct gfs2_ea_request));
1049 er.er_data = (size) ? buffer : NULL;
1050 er.er_data_len = size;
1052 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1055 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1057 struct gfs2_ea_request er;
1059 memset(&er, 0, sizeof(struct gfs2_ea_request));
1060 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1061 if (er.er_type == GFS2_EATYPE_UNUSED)
1063 er.er_name_len = strlen(er.er_name);
1065 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1068 struct inode_operations gfs2_file_iops = {
1069 .permission = gfs2_permission,
1070 .setattr = gfs2_setattr,
1071 .getattr = gfs2_getattr,
1072 .setxattr = gfs2_setxattr,
1073 .getxattr = gfs2_getxattr,
1074 .listxattr = gfs2_listxattr,
1075 .removexattr = gfs2_removexattr,
1078 struct inode_operations gfs2_dev_iops = {
1079 .permission = gfs2_permission,
1080 .setattr = gfs2_setattr,
1081 .getattr = gfs2_getattr,
1082 .setxattr = gfs2_setxattr,
1083 .getxattr = gfs2_getxattr,
1084 .listxattr = gfs2_listxattr,
1085 .removexattr = gfs2_removexattr,
1088 struct inode_operations gfs2_dir_iops = {
1089 .create = gfs2_create,
1090 .lookup = gfs2_lookup,
1092 .unlink = gfs2_unlink,
1093 .symlink = gfs2_symlink,
1094 .mkdir = gfs2_mkdir,
1095 .rmdir = gfs2_rmdir,
1096 .mknod = gfs2_mknod,
1097 .rename = gfs2_rename,
1098 .permission = gfs2_permission,
1099 .setattr = gfs2_setattr,
1100 .getattr = gfs2_getattr,
1101 .setxattr = gfs2_setxattr,
1102 .getxattr = gfs2_getxattr,
1103 .listxattr = gfs2_listxattr,
1104 .removexattr = gfs2_removexattr,
1107 struct inode_operations gfs2_symlink_iops = {
1108 .readlink = gfs2_readlink,
1109 .follow_link = gfs2_follow_link,
1110 .permission = gfs2_permission,
1111 .setattr = gfs2_setattr,
1112 .getattr = gfs2_getattr,
1113 .setxattr = gfs2_setxattr,
1114 .getxattr = gfs2_getxattr,
1115 .listxattr = gfs2_listxattr,
1116 .removexattr = gfs2_removexattr,