20 #include <linux/capability.h>
22 #include <linux/xattr.h>
24 #include <linux/slab.h>
83 #define EA_INLINE 0x0001
84 #define EA_EXTENT 0x0002
86 #define EA_MALLOC 0x0008
89 static int is_known_namespace(
const char *
name)
105 static int is_os2_xattr(
struct jfs_ea *
ea)
107 return !is_known_namespace(ea->
name);
110 static inline int name_size(
struct jfs_ea *
ea)
112 if (is_os2_xattr(ea))
118 static inline int copy_name(
char *
buffer,
struct jfs_ea *ea)
122 if (is_os2_xattr(ea)) {
167 if (ealist && size >
sizeof (
struct jfs_ea_list)) {
168 assert(size <=
sizeof (ji->i_inline_ea));
180 memcpy(ji->i_inline_ea, ealist, size);
234 if (!ealist || size <=
sizeof (ji->i_inline_ea)) {
235 if (!ea_write_inline(ip, ealist, size, ea))
243 rc = dquot_alloc_block(ip, nblocks);
250 dquot_free_block(ip, nblocks);
259 cp = (
char *) ealist;
271 if (!(mp =
get_metapage(ip, blkno +
i, bytes_to_write, 1))) {
285 if ((rc = flush_metapage(mp))) {
315 dquot_free_block(ip, nblocks);
317 dbFree(ip, blkno, nblocks);
349 memcpy(ealist, ji->i_inline_ea, ea_size);
373 char *cp = (
char *) ealist;
381 return ea_read_inline(ip, ealist);
401 for (i = 0; i < nblocks; i += sbi->
nbperpage) {
447 int blocks_needed, current_blocks;
450 int quota_allocation = 0;
463 if ((min_size <=
sizeof (ji->i_inline_ea)) &&
466 ea_buf->
max_size =
sizeof (ji->i_inline_ea);
476 if (min_size <=
sizeof (ji->i_inline_ea)) {
478 ea_buf->
max_size =
sizeof (ji->i_inline_ea);
485 jfs_error(sb,
"ea_get: invalid ea.flag)");
488 current_blocks = (ea_size + sb->
s_blocksize - 1) >>
491 size =
max(min_size, ea_size);
509 if ((rc = ea_read(inode, ea_buf->
xattr))) {
516 blocks_needed = (min_size + sb->
s_blocksize - 1) >>
519 if (blocks_needed > current_blocks) {
521 rc = dquot_alloc_block(inode, blocks_needed);
525 quota_allocation = blocks_needed;
543 dbFree(inode, blkno, (
s64) blocks_needed);
547 ea_buf->
xattr = ea_buf->
mp->data;
552 if ((rc = ea_read(inode, ea_buf->
xattr))) {
553 discard_metapage(ea_buf->
mp);
554 dbFree(inode, blkno, (
s64) blocks_needed);
567 ea_buf->
xattr = ea_buf->
mp->data;
575 ea_buf->
xattr, ea_size, 1);
576 ea_release(inode, ea_buf);
585 if (quota_allocation)
586 dquot_free_block(inode, quota_allocation);
591 static void ea_release(
struct inode *inode,
struct ea_buffer *ea_buf)
605 static int ea_put(
tid_t tid,
struct inode *inode,
struct ea_buffer *ea_buf,
609 unsigned long old_blocks, new_blocks;
613 ea_release(inode, ea_buf);
616 assert(new_size <=
sizeof (ji->i_inline_ea));
623 rc = ea_write(inode, ea_buf->
xattr, new_size, &ea_buf->
new_ea);
627 flush_metapage(ea_buf->
mp);
630 rc = ea_write(inode, ea_buf->
xattr, new_size, &ea_buf->
new_ea);
631 discard_metapage(ea_buf->
mp);
636 old_blocks = new_blocks = 0;
661 dquot_free_block(inode, old_blocks);
674 static int can_set_system_xattr(
struct inode *inode,
const char *
name,
677 #ifdef CONFIG_JFS_POSIX_ACL
697 posix_acl_release(acl);
700 "posix_acl_equiv_mode returned %d\n",
704 mark_inode_dirty(inode);
720 posix_acl_release(acl);
738 static int can_set_xattr(
struct inode *inode,
const char *name,
739 const void *value,
size_t value_len)
742 return can_set_system_xattr(inode, name, value, value_len);
767 const void *value,
size_t value_len,
int flags)
776 char *os2name =
NULL;
793 xattr_size = ea_get(inode, &ea_buf, 0);
794 if (xattr_size < 0) {
806 if ((namelen == ea->
namelen) &&
832 new_size +=
sizeof (
struct jfs_ea) + namelen + 1 + value_len;
839 ea_release(inode, &ea_buf);
840 xattr_size = ea_get(inode, &ea_buf, new_size);
841 if (xattr_size < 0) {
851 length = (
char *)
END_EALIST(ealist) - (
char *) next_ea;
853 memmove(old_ea, next_ea, length);
854 xattr_size -= old_ea_size;
863 ea = (
struct jfs_ea *) ((
char *) ealist + xattr_size);
870 memcpy(&ea->
name[namelen + 1], value, value_len);
875 if (xattr_size != new_size) {
877 "jfs_xsetattr: xattr_size = %d, new_size = %d\n",
878 xattr_size, new_size);
892 rc = ea_put(tid, inode, &ea_buf, new_size);
896 ea_release(inode, &ea_buf);
898 up_write(&JFS_IP(inode)->xattr_sem);
906 size_t value_len,
int flags)
908 struct inode *inode = dentry->
d_inode;
913 if ((rc = can_set_xattr(inode, name, value, value_len)))
946 xattr_size = ea_get(inode, &ea_buf, 0);
948 if (xattr_size < 0) {
960 if ((namelen == ea->
namelen) &&
966 else if (size > buf_size) {
971 memcpy(data, value, size);
977 ea_release(inode, &ea_buf);
979 up_read(&JFS_IP(inode)->xattr_sem);
998 if (is_known_namespace(name))
1010 static inline int can_list(
struct jfs_ea *ea)
1019 struct inode *inode = dentry->
d_inode;
1029 xattr_size = ea_get(inode, &ea_buf, 0);
1030 if (xattr_size < 0) {
1035 if (xattr_size == 0)
1043 size += name_size(ea) + 1;
1049 if (size > buf_size) {
1058 int namelen = copy_name(buffer, ea);
1059 buffer += namelen + 1;
1064 ea_release(inode, &ea_buf);
1066 up_read(&JFS_IP(inode)->xattr_sem);
1072 struct inode *inode = dentry->
d_inode;
1077 if ((rc = can_set_xattr(inode, name,
NULL, 0)))
1091 #ifdef CONFIG_JFS_SECURITY
1092 int jfs_initxattrs(
struct inode *inode,
const struct xattr *xattr_array,
1100 for (xattr = xattr_array; xattr->
name !=
NULL; xattr++) {
1119 int jfs_init_security(
tid_t tid,
struct inode *inode,
struct inode *dir,
1123 &jfs_initxattrs, &tid);