Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_xattr.h revision 1.2.2.2
      1  1.2.2.2  pgoyette /*	$NetBSD: ext2fs_xattr.h,v 1.2.2.2 2016/09/14 03:04:19 pgoyette Exp $	*/
      2  1.2.2.2  pgoyette 
      3  1.2.2.2  pgoyette /*-
      4  1.2.2.2  pgoyette  * Copyright (c) 2016 The NetBSD Foundation, Inc.
      5  1.2.2.2  pgoyette  * All rights reserved.
      6  1.2.2.2  pgoyette  *
      7  1.2.2.2  pgoyette  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.2  pgoyette  * by Jaromir Dolecek.
      9  1.2.2.2  pgoyette  *
     10  1.2.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
     11  1.2.2.2  pgoyette  * modification, are permitted provided that the following conditions
     12  1.2.2.2  pgoyette  * are met:
     13  1.2.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     18  1.2.2.2  pgoyette  *
     19  1.2.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.2.2  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.2.2  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.2.2  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.2.2  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.2.2  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.2.2  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.2.2  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.2.2  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.2.2  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.2.2  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.2.2  pgoyette  */
     31  1.2.2.2  pgoyette 
     32  1.2.2.2  pgoyette #ifndef _UFS_EXT2FS_EXT2FS_XATTR_H_
     33  1.2.2.2  pgoyette #define _UFS_EXT2FS_EXT2FS_XATTR_H_
     34  1.2.2.2  pgoyette 
     35  1.2.2.2  pgoyette #include <sys/cdefs.h>
     36  1.2.2.2  pgoyette __KERNEL_RCSID(0, "$NetBSD: ext2fs_xattr.h,v 1.2.2.2 2016/09/14 03:04:19 pgoyette Exp $");
     37  1.2.2.2  pgoyette 
     38  1.2.2.2  pgoyette #ifdef _KERNEL
     39  1.2.2.2  pgoyette 
     40  1.2.2.2  pgoyette #define EXT2FS_XATTR_MAGIC 	0xEA020000
     41  1.2.2.2  pgoyette 
     42  1.2.2.2  pgoyette #define EXT2FS_XATTR_NAME_LEN_MAX	255
     43  1.2.2.2  pgoyette #define EXT2FS_XATTR_REFCOUNT_MAX	1024
     44  1.2.2.2  pgoyette 
     45  1.2.2.2  pgoyette /*
     46  1.2.2.2  pgoyette  * This is used as header for extended attribute block within inode
     47  1.2.2.2  pgoyette  */
     48  1.2.2.2  pgoyette struct ext2fs_xattr_ibody_header {
     49  1.2.2.2  pgoyette 	uint32_t h_magic;	/* Magic number - 0xEA020000 */
     50  1.2.2.2  pgoyette };
     51  1.2.2.2  pgoyette 
     52  1.2.2.2  pgoyette /*
     53  1.2.2.2  pgoyette  * This is used as header for extended attribute on separate disk block
     54  1.2.2.2  pgoyette  */
     55  1.2.2.2  pgoyette struct ext2fs_xattr_header {
     56  1.2.2.2  pgoyette 	uint32_t h_magic;	/* Magic number - 0xEA020000 */
     57  1.2.2.2  pgoyette 	uint32_t h_refcount;	/* Reference count */
     58  1.2.2.2  pgoyette 	uint32_t h_blocks;	/* Number of blocks - only 1 supported */
     59  1.2.2.2  pgoyette 	uint32_t h_hash;	/* Hash of all attributes */
     60  1.2.2.2  pgoyette  	uint32_t h_checksum;	/* Checksum of the extended attribute block */
     61  1.2.2.2  pgoyette 	uint32_t h_reserved[3];
     62  1.2.2.2  pgoyette };
     63  1.2.2.2  pgoyette 
     64  1.2.2.2  pgoyette /*
     65  1.2.2.2  pgoyette  * Extended attribute on-disk header structure
     66  1.2.2.2  pgoyette  */
     67  1.2.2.2  pgoyette struct ext2fs_xattr_entry {
     68  1.2.2.2  pgoyette         uint8_t  e_name_len;		/* Name length */
     69  1.2.2.2  pgoyette         uint8_t  e_name_index;		/* Name prefix index (see below) */
     70  1.2.2.2  pgoyette         uint16_t e_value_offs;		/* Offset of value within block */
     71  1.2.2.2  pgoyette         uint32_t e_value_block;		/* Value block - not supported (always zero) */
     72  1.2.2.2  pgoyette         uint32_t e_value_size;		/* Length of value */
     73  1.2.2.2  pgoyette         uint32_t e_hash;		/* Hash (not supported) */
     74  1.2.2.2  pgoyette         char e_name[0];			/* Name string (e_name_len bytes) */
     75  1.2.2.2  pgoyette };
     76  1.2.2.2  pgoyette 
     77  1.2.2.2  pgoyette /*
     78  1.2.2.2  pgoyette  * Linux kernel checks only the 0, we also check that the current entry
     79  1.2.2.2  pgoyette  * doesn't overflow past end.
     80  1.2.2.2  pgoyette  */
     81  1.2.2.2  pgoyette #define EXT2FS_XATTR_IS_LAST_ENTRY(entry, end) \
     82  1.2.2.2  pgoyette 	(*((uint32_t *)(entry)) == 0 || (uintptr_t)EXT2FS_XATTR_NEXT(entry) > (uintptr_t)end)
     83  1.2.2.2  pgoyette 
     84  1.2.2.2  pgoyette /*
     85  1.2.2.2  pgoyette  * Each ext2fs_xattr_entry starts on next 4-byte boundary, pad if necessary.
     86  1.2.2.2  pgoyette  */
     87  1.2.2.2  pgoyette #define EXT2FS_XATTR_PAD	4
     88  1.2.2.2  pgoyette #define EXT2FS_XATTR_ROUND	(EXT2FS_XATTR_PAD - 1)
     89  1.2.2.2  pgoyette #define EXT2FS_XATTR_LEN(name_len) \
     90  1.2.2.2  pgoyette 	(((name_len) + EXT2FS_XATTR_ROUND + \
     91  1.2.2.2  pgoyette 	sizeof(struct ext2fs_xattr_entry)) & ~EXT2FS_XATTR_ROUND)
     92  1.2.2.2  pgoyette #define EXT2FS_XATTR_NEXT(entry) \
     93  1.2.2.2  pgoyette 	(struct ext2fs_xattr_entry *)(((uint8_t *)(entry)) + EXT2FS_XATTR_LEN((entry)->e_name_len))
     94  1.2.2.2  pgoyette 
     95  1.2.2.2  pgoyette #define EXT2FS_XATTR_IFIRST(h) (void *)&(h)[1]
     96  1.2.2.2  pgoyette #define EXT2FS_XATTR_BFIRST(h) EXT2FS_XATTR_IFIRST(h)
     97  1.2.2.2  pgoyette 
     98  1.2.2.2  pgoyette /*
     99  1.2.2.2  pgoyette  * Name prefixes
    100  1.2.2.2  pgoyette  */
    101  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_NONE		0 /* no prefix */
    102  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_USER		1 /* "user." */
    103  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_POSIX_ACCESS	2 /* "system.posix_acl_access" */
    104  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_POSIX_DEFAULT1	3 /* "system.posix_acl_default" */
    105  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_TRUSTED		4 /* "trusted." */
    106  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_SECURITY		6 /* "security." */
    107  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_SYSTEM		7 /* "system." */
    108  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_SYSTEM_RICHACL	8 /* "system.richacl" */
    109  1.2.2.2  pgoyette #define EXT2FS_XATTR_PREFIX_ENCRYPTION		9 /* "c" */
    110  1.2.2.2  pgoyette 
    111  1.2.2.2  pgoyette int ext2fs_getextattr(void *);
    112  1.2.2.2  pgoyette int ext2fs_setextattr(void *);
    113  1.2.2.2  pgoyette int ext2fs_listextattr(void *);
    114  1.2.2.2  pgoyette int ext2fs_deleteextattr(void *);
    115  1.2.2.2  pgoyette #endif /* _KERNEL */
    116  1.2.2.2  pgoyette 
    117  1.2.2.2  pgoyette #endif /* _UFS_EXT2FS_EXT2FS_XATTR_H_ */
    118