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