Lines Matching +full:pre +full:- +full:verified
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
27 * Overall design --
34 * where <name> is constructed from a null-terminated ascii string
36 * (1 ... 65535 bytes). The in-memory format is
39 * +-------+--------+--------+----------------+-------------------+
42 * +-------+--------+--------+----------------+-------------------+
47 * +------------+-------------------+--------------------+-----
50 * +------------+-------------------+--------------------+-----
52 * On-disk:
55 * written directly. An EA list may be in-lined in the inode if there is
77 * Mapping of on-disk attribute names: for on-disk attribute names with an
97 if (is_known_namespace(ea->name)) in name_size()
98 return ea->namelen; in name_size()
100 return ea->namelen + XATTR_OS2_PREFIX_LEN; in name_size()
105 int len = ea->namelen; in copy_name()
107 if (!is_known_namespace(ea->name)) { in copy_name()
112 memcpy(buffer, ea->name, ea->namelen); in copy_name()
113 buffer[ea->namelen] = 0; in copy_name()
126 * PRE CONDITIONS:
127 * Already verified that the specified EA is small enough to fit inline
130 * ip - Inode pointer
131 * ealist - EA list pointer
132 * size - size of ealist in bytes
133 * ea - dxd_t structure to be filled in with necessary EA information
141 * RETURNS: 0 for successful copy to inline area; -1 if area not available
149 * Make sure we have an EA -- the NULL EA list is valid, but you in ea_write_inline()
153 assert(size <= sizeof (ji->i_inline_ea)); in ea_write_inline()
159 if (!(ji->mode2 & INLINEEA) && !(ji->ea.flag & DXD_INLINE)) in ea_write_inline()
160 return -EPERM; in ea_write_inline()
165 memcpy(ji->i_inline_ea, ealist, size); in ea_write_inline()
166 ea->flag = DXD_INLINE; in ea_write_inline()
167 ji->mode2 &= ~INLINEEA; in ea_write_inline()
169 ea->flag = 0; in ea_write_inline()
175 if (ji->ea.flag & DXD_INLINE) in ea_write_inline()
176 ji->mode2 |= INLINEEA; in ea_write_inline()
187 * PRE CONDITIONS: EA has been verified
190 * ip - Inode pointer
191 * ealist - EA list pointer
192 * size - size of ealist in bytes
193 * ea - dxd_t structure to be filled in appropriately with where the
204 struct super_block *sb = ip->i_sb; in ea_write()
216 * Quick check to see if this is an in-linable EA. Short EAs in ea_write()
217 * and empty EAs are all in-linable, provided the space exists. in ea_write()
219 if (!ealist || size <= sizeof (ji->i_inline_ea)) { in ea_write()
225 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits; in ea_write()
246 for (i = 0; i < nblocks; i += sbi->nbperpage) { in ea_write()
253 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits)) in ea_write()
254 << sb->s_blocksize_bits; in ea_write()
257 rc = -EIO; in ea_write()
261 memcpy(mp->data, cp, nb); in ea_write()
265 * forced writes like this one. --hch in ea_write()
272 * the write failed -- this means that the buffer in ea_write()
284 nbytes -= nb; in ea_write()
287 ea->flag = DXD_EXTENT; in ea_write()
288 DXDsize(ea, le32_to_cpu(ealist->size)); in ea_write()
293 if (ji->ea.flag & DXD_INLINE) in ea_write()
294 ji->mode2 |= INLINEEA; in ea_write()
312 * ip - Inode pointer
313 * ealist - Pointer to buffer to fill in with EA
320 int ea_size = sizeDXD(&ji->ea); in ea_read_inline()
323 ealist->size = 0; in ea_read_inline()
328 if ((sizeDXD(&ji->ea) > sizeof (ji->i_inline_ea))) in ea_read_inline()
329 return -EIO; in ea_read_inline()
330 if (le32_to_cpu(((struct jfs_ea_list *) &ji->i_inline_ea)->size) in ea_read_inline()
332 return -EIO; in ea_read_inline()
334 memcpy(ealist, ji->i_inline_ea, ea_size); in ea_read_inline()
344 * ip - Inode pointer
345 * ealist - Pointer to buffer to fill in with EA
353 struct super_block *sb = ip->i_sb; in ea_read()
364 /* quick check for in-line EA */ in ea_read()
365 if (ji->ea.flag & DXD_INLINE) in ea_read()
368 nbytes = sizeDXD(&ji->ea); in ea_read()
371 return -EIO; in ea_read()
378 nblocks = lengthDXD(&ji->ea) << sbi->l2nbperpage; in ea_read()
379 blkno = addressDXD(&ji->ea) << sbi->l2nbperpage; in ea_read()
386 for (i = 0; i < nblocks; i += sbi->nbperpage) { in ea_read()
393 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits)) in ea_read()
394 << sb->s_blocksize_bits; in ea_read()
397 return -EIO; in ea_read()
399 memcpy(cp, mp->data, nb); in ea_read()
403 nbytes -= nb; in ea_read()
420 * inode - Inode pointer
421 * ea_buf - Structure to be populated with ealist and its metadata
422 * min_size- minimum size of buffer to be returned
429 struct super_block *sb = inode->i_sb; in ea_get()
431 int ea_size = sizeDXD(&ji->ea); in ea_get()
438 if (ji->ea.flag == 0) in ea_get()
443 ea_buf->flag = 0; in ea_get()
444 ea_buf->max_size = 0; in ea_get()
445 ea_buf->xattr = NULL; in ea_get()
448 if ((min_size <= sizeof (ji->i_inline_ea)) && in ea_get()
449 (ji->mode2 & INLINEEA)) { in ea_get()
450 ea_buf->flag = EA_INLINE | EA_NEW; in ea_get()
451 ea_buf->max_size = sizeof (ji->i_inline_ea); in ea_get()
452 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea; in ea_get()
453 DXDlength(&ea_buf->new_ea, 0); in ea_get()
454 DXDaddress(&ea_buf->new_ea, 0); in ea_get()
455 ea_buf->new_ea.flag = DXD_INLINE; in ea_get()
456 DXDsize(&ea_buf->new_ea, min_size); in ea_get()
460 } else if (ji->ea.flag & DXD_INLINE) { in ea_get()
461 if (min_size <= sizeof (ji->i_inline_ea)) { in ea_get()
462 ea_buf->flag = EA_INLINE; in ea_get()
463 ea_buf->max_size = sizeof (ji->i_inline_ea); in ea_get()
464 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea; in ea_get()
469 if (!(ji->ea.flag & DXD_EXTENT)) { in ea_get()
471 return -EIO; in ea_get()
473 current_blocks = (ea_size + sb->s_blocksize - 1) >> in ea_get()
474 sb->s_blocksize_bits; in ea_get()
484 ea_buf->max_size = (size + sb->s_blocksize - 1) & in ea_get()
485 ~(sb->s_blocksize - 1); in ea_get()
487 ea_buf->xattr = kmalloc(ea_buf->max_size, GFP_KERNEL); in ea_get()
488 if (ea_buf->xattr == NULL) in ea_get()
489 return -ENOMEM; in ea_get()
491 ea_buf->flag = EA_MALLOC; in ea_get()
496 if ((rc = ea_read(inode, ea_buf->xattr))) { in ea_get()
497 kfree(ea_buf->xattr); in ea_get()
498 ea_buf->xattr = NULL; in ea_get()
503 blocks_needed = (min_size + sb->s_blocksize - 1) >> in ea_get()
504 sb->s_blocksize_bits; in ea_get()
510 return -EDQUOT; in ea_get()
519 DXDlength(&ea_buf->new_ea, blocks_needed); in ea_get()
520 DXDaddress(&ea_buf->new_ea, blkno); in ea_get()
521 ea_buf->new_ea.flag = DXD_EXTENT; in ea_get()
522 DXDsize(&ea_buf->new_ea, min_size); in ea_get()
524 ea_buf->flag = EA_EXTENT | EA_NEW; in ea_get()
526 ea_buf->mp = get_metapage(inode, blkno, in ea_get()
527 blocks_needed << sb->s_blocksize_bits, in ea_get()
529 if (ea_buf->mp == NULL) { in ea_get()
531 rc = -EIO; in ea_get()
534 ea_buf->xattr = ea_buf->mp->data; in ea_get()
535 ea_buf->max_size = (min_size + sb->s_blocksize - 1) & in ea_get()
536 ~(sb->s_blocksize - 1); in ea_get()
539 if ((rc = ea_read(inode, ea_buf->xattr))) { in ea_get()
540 discard_metapage(ea_buf->mp); in ea_get()
546 ea_buf->flag = EA_EXTENT; in ea_get()
547 ea_buf->mp = read_metapage(inode, addressDXD(&ji->ea), in ea_get()
548 lengthDXD(&ji->ea) << sb->s_blocksize_bits, in ea_get()
550 if (ea_buf->mp == NULL) { in ea_get()
551 rc = -EIO; in ea_get()
554 ea_buf->xattr = ea_buf->mp->data; in ea_get()
555 ea_buf->max_size = (ea_size + sb->s_blocksize - 1) & in ea_get()
556 ~(sb->s_blocksize - 1); in ea_get()
559 if (EALIST_SIZE(ea_buf->xattr) != ea_size) { in ea_get()
562 ea_buf->xattr, ea_size, 1); in ea_get()
564 rc = -EIO; in ea_get()
580 if (ea_buf->flag & EA_MALLOC) in ea_release()
581 kfree(ea_buf->xattr); in ea_release()
582 else if (ea_buf->flag & EA_EXTENT) { in ea_release()
583 assert(ea_buf->mp); in ea_release()
584 release_metapage(ea_buf->mp); in ea_release()
586 if (ea_buf->flag & EA_NEW) in ea_release()
587 dbFree(inode, addressDXD(&ea_buf->new_ea), in ea_release()
588 lengthDXD(&ea_buf->new_ea)); in ea_release()
602 } else if (ea_buf->flag & EA_INLINE) { in ea_put()
603 assert(new_size <= sizeof (ji->i_inline_ea)); in ea_put()
604 ji->mode2 &= ~INLINEEA; in ea_put()
605 ea_buf->new_ea.flag = DXD_INLINE; in ea_put()
606 DXDsize(&ea_buf->new_ea, new_size); in ea_put()
607 DXDaddress(&ea_buf->new_ea, 0); in ea_put()
608 DXDlength(&ea_buf->new_ea, 0); in ea_put()
609 } else if (ea_buf->flag & EA_MALLOC) { in ea_put()
610 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea); in ea_put()
611 kfree(ea_buf->xattr); in ea_put()
612 } else if (ea_buf->flag & EA_NEW) { in ea_put()
614 flush_metapage(ea_buf->mp); in ea_put()
616 /* ->xattr must point to original ea's metapage */ in ea_put()
617 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea); in ea_put()
618 discard_metapage(ea_buf->mp); in ea_put()
625 if (ji->ea.flag & DXD_EXTENT) { in ea_put()
626 invalidate_dxd_metapages(inode, ji->ea); in ea_put()
627 old_blocks = lengthDXD(&ji->ea); in ea_put()
631 txEA(tid, inode, &ji->ea, &ea_buf->new_ea); in ea_put()
632 if (ea_buf->new_ea.flag & DXD_EXTENT) { in ea_put()
633 new_blocks = lengthDXD(&ea_buf->new_ea); in ea_put()
634 if (ji->ea.flag & DXD_INLINE) in ea_put()
635 ji->mode2 |= INLINEEA; in ea_put()
637 ji->ea = ea_buf->new_ea; in ea_put()
639 txEA(tid, inode, &ji->ea, NULL); in ea_put()
640 if (ji->ea.flag & DXD_INLINE) in ea_put()
641 ji->mode2 |= INLINEEA; in ea_put()
642 ji->ea.flag = 0; in ea_put()
643 ji->ea.size = 0; in ea_put()
650 inode->i_ctime = current_time(inode); in ea_put()
669 down_write(&JFS_IP(inode)->xattr_sem); in __jfs_setxattr()
684 if ((namelen == ea->namelen) && in __jfs_setxattr()
685 (memcmp(name, ea->name, namelen) == 0)) { in __jfs_setxattr()
688 rc = -EEXIST; in __jfs_setxattr()
701 rc = -ENODATA; in __jfs_setxattr()
729 length = (char *) END_EALIST(ealist) - (char *) next_ea; in __jfs_setxattr()
732 xattr_size -= old_ea_size; in __jfs_setxattr()
742 * The size of EA value is limitted by on-disk format up to in __jfs_setxattr()
745 * we can pre-checkup the value size against USHRT_MAX, and in __jfs_setxattr()
746 * return -E2BIG in this case, which is consistent with the in __jfs_setxattr()
750 rc = -E2BIG; in __jfs_setxattr()
755 ea->flag = 0; in __jfs_setxattr()
756 ea->namelen = namelen; in __jfs_setxattr()
757 ea->valuelen = (cpu_to_le16(value_len)); in __jfs_setxattr()
758 memcpy(ea->name, name, namelen); in __jfs_setxattr()
759 ea->name[namelen] = 0; in __jfs_setxattr()
761 memcpy(&ea->name[namelen + 1], value, value_len); in __jfs_setxattr()
765 /* DEBUG - If we did this right, these number match */ in __jfs_setxattr()
771 rc = -EINVAL; in __jfs_setxattr()
781 ealist->size = cpu_to_le32(new_size); in __jfs_setxattr()
789 up_write(&JFS_IP(inode)->xattr_sem); in __jfs_setxattr()
805 down_read(&JFS_IP(inode)->xattr_sem); in __jfs_getxattr()
821 if ((namelen == ea->namelen) && in __jfs_getxattr()
822 memcmp(name, ea->name, namelen) == 0) { in __jfs_getxattr()
824 size = le16_to_cpu(ea->valuelen); in __jfs_getxattr()
828 size = -ERANGE; in __jfs_getxattr()
831 value = ((char *) &ea->name) + ea->namelen + 1; in __jfs_getxattr()
836 size = -ENODATA; in __jfs_getxattr()
840 up_read(&JFS_IP(inode)->xattr_sem); in __jfs_getxattr()
850 return (strncmp(ea->name, XATTR_TRUSTED_PREFIX, in can_list()
865 down_read(&JFS_IP(inode)->xattr_sem); in jfs_listxattr()
888 size = -ERANGE; in jfs_listxattr()
904 up_read(&JFS_IP(inode)->xattr_sem); in jfs_listxattr()
915 tid = txBegin(inode->i_sb, 0); in __jfs_xattr_set()
916 mutex_lock(&ji->commit_mutex); in __jfs_xattr_set()
921 mutex_unlock(&ji->commit_mutex); in __jfs_xattr_set()
949 return -EOPNOTSUPP; in jfs_xattr_get_os2()
960 return -EOPNOTSUPP; in jfs_xattr_set_os2()
1010 for (xattr = xattr_array; xattr->name != NULL; xattr++) { in jfs_initxattrs()
1012 strlen(xattr->name) + 1, GFP_NOFS); in jfs_initxattrs()
1014 err = -ENOMEM; in jfs_initxattrs()
1018 strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name); in jfs_initxattrs()
1021 xattr->value, xattr->value_len, 0); in jfs_initxattrs()