]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
f5fc4aca | 23 | * Copyright (c) 2011 by Delphix. All rights reserved. |
632a242e | 24 | * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. |
34dc7c2f BB |
25 | */ |
26 | ||
428870ff BB |
27 | /* Portions Copyright 2010 Robert Milkowski */ |
28 | ||
34dc7c2f BB |
29 | #include <sys/zio.h> |
30 | #include <sys/spa.h> | |
31 | #include <sys/u8_textprep.h> | |
32 | #include <sys/zfs_acl.h> | |
33 | #include <sys/zfs_ioctl.h> | |
34 | #include <sys/zfs_znode.h> | |
35 | ||
36 | #include "zfs_prop.h" | |
37 | #include "zfs_deleg.h" | |
38 | ||
39 | #if defined(_KERNEL) | |
40 | #include <sys/systm.h> | |
41 | #else | |
42 | #include <stdlib.h> | |
43 | #include <string.h> | |
44 | #include <ctype.h> | |
45 | #endif | |
46 | ||
47 | static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; | |
48 | ||
9babb374 BB |
49 | /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ |
50 | const char *zfs_userquota_prop_prefixes[] = { | |
51 | "userused@", | |
52 | "userquota@", | |
53 | "groupused@", | |
54 | "groupquota@" | |
55 | }; | |
56 | ||
34dc7c2f BB |
57 | zprop_desc_t * |
58 | zfs_prop_get_table(void) | |
59 | { | |
60 | return (zfs_prop_table); | |
61 | } | |
62 | ||
63 | void | |
64 | zfs_prop_init(void) | |
65 | { | |
66 | static zprop_index_t checksum_table[] = { | |
67 | { "on", ZIO_CHECKSUM_ON }, | |
68 | { "off", ZIO_CHECKSUM_OFF }, | |
69 | { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, | |
70 | { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, | |
71 | { "sha256", ZIO_CHECKSUM_SHA256 }, | |
72 | { NULL } | |
73 | }; | |
74 | ||
428870ff BB |
75 | static zprop_index_t dedup_table[] = { |
76 | { "on", ZIO_CHECKSUM_ON }, | |
77 | { "off", ZIO_CHECKSUM_OFF }, | |
78 | { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, | |
79 | { "sha256", ZIO_CHECKSUM_SHA256 }, | |
80 | { "sha256,verify", | |
81 | ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, | |
82 | { NULL } | |
83 | }; | |
84 | ||
34dc7c2f BB |
85 | static zprop_index_t compress_table[] = { |
86 | { "on", ZIO_COMPRESS_ON }, | |
87 | { "off", ZIO_COMPRESS_OFF }, | |
88 | { "lzjb", ZIO_COMPRESS_LZJB }, | |
89 | { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ | |
90 | { "gzip-1", ZIO_COMPRESS_GZIP_1 }, | |
91 | { "gzip-2", ZIO_COMPRESS_GZIP_2 }, | |
92 | { "gzip-3", ZIO_COMPRESS_GZIP_3 }, | |
93 | { "gzip-4", ZIO_COMPRESS_GZIP_4 }, | |
94 | { "gzip-5", ZIO_COMPRESS_GZIP_5 }, | |
95 | { "gzip-6", ZIO_COMPRESS_GZIP_6 }, | |
96 | { "gzip-7", ZIO_COMPRESS_GZIP_7 }, | |
97 | { "gzip-8", ZIO_COMPRESS_GZIP_8 }, | |
98 | { "gzip-9", ZIO_COMPRESS_GZIP_9 }, | |
428870ff | 99 | { "zle", ZIO_COMPRESS_ZLE }, |
9759c60f | 100 | { "lz4", ZIO_COMPRESS_LZ4 }, |
34dc7c2f BB |
101 | { NULL } |
102 | }; | |
103 | ||
104 | static zprop_index_t snapdir_table[] = { | |
105 | { "hidden", ZFS_SNAPDIR_HIDDEN }, | |
106 | { "visible", ZFS_SNAPDIR_VISIBLE }, | |
107 | { NULL } | |
108 | }; | |
109 | ||
0b4d1b58 ED |
110 | static zprop_index_t snapdev_table[] = { |
111 | { "hidden", ZFS_SNAPDEV_HIDDEN }, | |
112 | { "visible", ZFS_SNAPDEV_VISIBLE }, | |
113 | { NULL } | |
114 | }; | |
115 | ||
023699cd MM |
116 | static zprop_index_t acltype_table[] = { |
117 | { "off", ZFS_ACLTYPE_OFF }, | |
118 | { "disabled", ZFS_ACLTYPE_OFF }, | |
119 | { "noacl", ZFS_ACLTYPE_OFF }, | |
120 | { "posixacl", ZFS_ACLTYPE_POSIXACL }, | |
121 | { NULL } | |
122 | }; | |
123 | ||
34dc7c2f BB |
124 | static zprop_index_t acl_inherit_table[] = { |
125 | { "discard", ZFS_ACL_DISCARD }, | |
126 | { "noallow", ZFS_ACL_NOALLOW }, | |
127 | { "restricted", ZFS_ACL_RESTRICTED }, | |
128 | { "passthrough", ZFS_ACL_PASSTHROUGH }, | |
129 | { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ | |
b128c09f | 130 | { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, |
34dc7c2f BB |
131 | { NULL } |
132 | }; | |
133 | ||
134 | static zprop_index_t case_table[] = { | |
135 | { "sensitive", ZFS_CASE_SENSITIVE }, | |
136 | { "insensitive", ZFS_CASE_INSENSITIVE }, | |
137 | { "mixed", ZFS_CASE_MIXED }, | |
138 | { NULL } | |
139 | }; | |
140 | ||
141 | static zprop_index_t copies_table[] = { | |
142 | { "1", 1 }, | |
143 | { "2", 2 }, | |
144 | { "3", 3 }, | |
145 | { NULL } | |
146 | }; | |
147 | ||
148 | /* | |
149 | * Use the unique flags we have to send to u8_strcmp() and/or | |
150 | * u8_textprep() to represent the various normalization property | |
151 | * values. | |
152 | */ | |
153 | static zprop_index_t normalize_table[] = { | |
154 | { "none", 0 }, | |
155 | { "formD", U8_TEXTPREP_NFD }, | |
156 | { "formKC", U8_TEXTPREP_NFKC }, | |
157 | { "formC", U8_TEXTPREP_NFC }, | |
158 | { "formKD", U8_TEXTPREP_NFKD }, | |
159 | { NULL } | |
160 | }; | |
161 | ||
162 | static zprop_index_t version_table[] = { | |
163 | { "1", 1 }, | |
164 | { "2", 2 }, | |
165 | { "3", 3 }, | |
9babb374 | 166 | { "4", 4 }, |
428870ff | 167 | { "5", 5 }, |
34dc7c2f BB |
168 | { "current", ZPL_VERSION }, |
169 | { NULL } | |
170 | }; | |
171 | ||
172 | static zprop_index_t boolean_table[] = { | |
173 | { "off", 0 }, | |
174 | { "on", 1 }, | |
175 | { NULL } | |
176 | }; | |
177 | ||
428870ff BB |
178 | static zprop_index_t logbias_table[] = { |
179 | { "latency", ZFS_LOGBIAS_LATENCY }, | |
180 | { "throughput", ZFS_LOGBIAS_THROUGHPUT }, | |
181 | { NULL } | |
182 | }; | |
183 | ||
34dc7c2f BB |
184 | static zprop_index_t canmount_table[] = { |
185 | { "off", ZFS_CANMOUNT_OFF }, | |
186 | { "on", ZFS_CANMOUNT_ON }, | |
187 | { "noauto", ZFS_CANMOUNT_NOAUTO }, | |
188 | { NULL } | |
189 | }; | |
190 | ||
b128c09f BB |
191 | static zprop_index_t cache_table[] = { |
192 | { "none", ZFS_CACHE_NONE }, | |
193 | { "metadata", ZFS_CACHE_METADATA }, | |
194 | { "all", ZFS_CACHE_ALL }, | |
195 | { NULL } | |
196 | }; | |
197 | ||
428870ff BB |
198 | static zprop_index_t sync_table[] = { |
199 | { "standard", ZFS_SYNC_STANDARD }, | |
200 | { "always", ZFS_SYNC_ALWAYS }, | |
201 | { "disabled", ZFS_SYNC_DISABLED }, | |
202 | { NULL } | |
203 | }; | |
204 | ||
82a37189 BB |
205 | static zprop_index_t xattr_table[] = { |
206 | { "off", ZFS_XATTR_OFF }, | |
207 | { "on", ZFS_XATTR_DIR }, | |
208 | { "sa", ZFS_XATTR_SA }, | |
209 | { "dir", ZFS_XATTR_DIR }, | |
210 | { NULL } | |
211 | }; | |
212 | ||
34dc7c2f | 213 | /* inherit index properties */ |
428870ff | 214 | zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, |
34dc7c2f | 215 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, |
428870ff BB |
216 | "standard | always | disabled", "SYNC", |
217 | sync_table); | |
218 | zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", | |
219 | ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | | |
220 | ZFS_TYPE_VOLUME, | |
34dc7c2f BB |
221 | "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", |
222 | checksum_table); | |
428870ff BB |
223 | zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, |
224 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
225 | "on | off | verify | sha256[,verify]", "DEDUP", | |
226 | dedup_table); | |
227 | zprop_register_index(ZFS_PROP_COMPRESSION, "compression", | |
34dc7c2f BB |
228 | ZIO_COMPRESS_DEFAULT, PROP_INHERIT, |
229 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
9759c60f | 230 | "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS", |
428870ff BB |
231 | compress_table); |
232 | zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, | |
34dc7c2f BB |
233 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, |
234 | "hidden | visible", "SNAPDIR", snapdir_table); | |
0b4d1b58 ED |
235 | zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN, |
236 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
237 | "hidden | visible", "SNAPDEV", snapdev_table); | |
023699cd MM |
238 | zprop_register_index(ZFS_PROP_ACLTYPE, "acltype", ZFS_ACLTYPE_OFF, |
239 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, | |
240 | "noacl | posixacl", "ACLTYPE", acltype_table); | |
428870ff BB |
241 | zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", |
242 | ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, | |
b128c09f | 243 | "discard | noallow | restricted | passthrough | passthrough-x", |
34dc7c2f | 244 | "ACLINHERIT", acl_inherit_table); |
428870ff BB |
245 | zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, |
246 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
34dc7c2f | 247 | "1 | 2 | 3", "COPIES", copies_table); |
428870ff | 248 | zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", |
b128c09f BB |
249 | ZFS_CACHE_ALL, PROP_INHERIT, |
250 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, | |
251 | "all | none | metadata", "PRIMARYCACHE", cache_table); | |
428870ff | 252 | zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", |
b128c09f BB |
253 | ZFS_CACHE_ALL, PROP_INHERIT, |
254 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, | |
255 | "all | none | metadata", "SECONDARYCACHE", cache_table); | |
428870ff BB |
256 | zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, |
257 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
258 | "latency | throughput", "LOGBIAS", logbias_table); | |
82a37189 BB |
259 | zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR, |
260 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, | |
261 | "on | off | dir | sa", "XATTR", xattr_table); | |
34dc7c2f BB |
262 | |
263 | /* inherit index (boolean) properties */ | |
428870ff | 264 | zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, |
34dc7c2f | 265 | ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); |
428870ff | 266 | zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, |
34dc7c2f BB |
267 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", |
268 | boolean_table); | |
428870ff | 269 | zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, |
34dc7c2f BB |
270 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", |
271 | boolean_table); | |
428870ff | 272 | zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, |
34dc7c2f BB |
273 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", |
274 | boolean_table); | |
428870ff | 275 | zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, |
34dc7c2f BB |
276 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", |
277 | boolean_table); | |
428870ff | 278 | zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, |
34dc7c2f | 279 | ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); |
428870ff | 280 | zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, |
82a37189 | 281 | ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table); |
428870ff | 282 | zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, |
34dc7c2f BB |
283 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", |
284 | boolean_table); | |
285 | ||
286 | /* default index properties */ | |
428870ff | 287 | zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, |
34dc7c2f | 288 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
330d06f9 | 289 | "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table); |
428870ff | 290 | zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, |
34dc7c2f BB |
291 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", |
292 | "CANMOUNT", canmount_table); | |
293 | ||
294 | /* readonly index (boolean) properties */ | |
428870ff | 295 | zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, |
34dc7c2f | 296 | ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); |
428870ff | 297 | zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, |
45d1cae3 BB |
298 | PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", |
299 | boolean_table); | |
34dc7c2f BB |
300 | |
301 | /* set once index properties */ | |
428870ff | 302 | zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, |
34dc7c2f BB |
303 | PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
304 | "none | formC | formD | formKC | formKD", "NORMALIZATION", | |
305 | normalize_table); | |
428870ff BB |
306 | zprop_register_index(ZFS_PROP_CASE, "casesensitivity", |
307 | ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | | |
308 | ZFS_TYPE_SNAPSHOT, | |
34dc7c2f BB |
309 | "sensitive | insensitive | mixed", "CASE", case_table); |
310 | ||
311 | /* set once index (boolean) properties */ | |
428870ff | 312 | zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, |
34dc7c2f BB |
313 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
314 | "on | off", "UTF8ONLY", boolean_table); | |
315 | ||
316 | /* string properties */ | |
428870ff | 317 | zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, |
34dc7c2f | 318 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); |
330d06f9 MA |
319 | zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY, |
320 | ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES"); | |
428870ff BB |
321 | zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", |
322 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", | |
323 | "MOUNTPOINT"); | |
324 | zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", | |
325 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", | |
326 | "SHARENFS"); | |
327 | zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, | |
34dc7c2f | 328 | ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); |
428870ff BB |
329 | zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", |
330 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, | |
331 | "on | off | sharemgr(1M) options", "SHARESMB"); | |
332 | zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", | |
333 | ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, | |
334 | "<sensitivity label>", "MLSLABEL"); | |
34dc7c2f BB |
335 | |
336 | /* readonly number properties */ | |
428870ff | 337 | zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, |
34dc7c2f | 338 | ZFS_TYPE_DATASET, "<size>", "USED"); |
428870ff | 339 | zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, |
34dc7c2f | 340 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); |
428870ff BB |
341 | zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, |
342 | PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); | |
343 | zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, | |
34dc7c2f BB |
344 | PROP_READONLY, ZFS_TYPE_DATASET, |
345 | "<1.00x or higher if compressed>", "RATIO"); | |
f5fc4aca MA |
346 | zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, |
347 | PROP_READONLY, ZFS_TYPE_DATASET, | |
348 | "<1.00x or higher if compressed>", "REFRATIO"); | |
428870ff BB |
349 | zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", |
350 | ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, | |
34dc7c2f | 351 | ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); |
428870ff BB |
352 | zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, |
353 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
354 | "USEDSNAP"); | |
355 | zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, | |
356 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
357 | "USEDDS"); | |
358 | zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, | |
359 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
360 | "USEDCHILD"); | |
361 | zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, | |
b128c09f BB |
362 | PROP_READONLY, |
363 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); | |
428870ff | 364 | zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, |
45d1cae3 | 365 | ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); |
330d06f9 MA |
366 | zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY, |
367 | ZFS_TYPE_DATASET, "<size>", "WRITTEN"); | |
34dc7c2f BB |
368 | |
369 | /* default number properties */ | |
428870ff | 370 | zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, |
34dc7c2f | 371 | ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); |
428870ff BB |
372 | zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, |
373 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
374 | "<size> | none", "RESERV"); | |
375 | zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, | |
34dc7c2f | 376 | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); |
428870ff | 377 | zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, |
34dc7c2f | 378 | ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); |
428870ff | 379 | zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, |
34dc7c2f BB |
380 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, |
381 | "<size> | none", "REFRESERV"); | |
382 | ||
383 | /* inherit number properties */ | |
428870ff BB |
384 | zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", |
385 | SPA_MAXBLOCKSIZE, PROP_INHERIT, | |
34dc7c2f BB |
386 | ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); |
387 | ||
388 | /* hidden properties */ | |
428870ff BB |
389 | zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, |
390 | PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); | |
391 | zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, | |
392 | PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); | |
393 | zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, | |
34dc7c2f | 394 | PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); |
428870ff BB |
395 | zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", |
396 | PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); | |
397 | zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", | |
9babb374 BB |
398 | PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, |
399 | "STMF_SBD_LU"); | |
428870ff BB |
400 | zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, |
401 | PROP_READONLY, ZFS_TYPE_DATASET, "GUID"); | |
402 | zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", | |
403 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, | |
404 | "USERACCOUNTING"); | |
405 | zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, | |
406 | PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); | |
407 | zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, | |
408 | PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); | |
409 | ||
410 | /* | |
411 | * Property to be removed once libbe is integrated | |
412 | */ | |
413 | zprop_register_hidden(ZFS_PROP_PRIVATE, "priv_prop", | |
414 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_FILESYSTEM, | |
415 | "PRIV_PROP"); | |
34dc7c2f BB |
416 | |
417 | /* oddball properties */ | |
428870ff BB |
418 | zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, |
419 | NULL, PROP_READONLY, ZFS_TYPE_DATASET, | |
34dc7c2f BB |
420 | "<date>", "CREATION", B_FALSE, B_TRUE, NULL); |
421 | } | |
422 | ||
423 | boolean_t | |
424 | zfs_prop_delegatable(zfs_prop_t prop) | |
425 | { | |
426 | zprop_desc_t *pd = &zfs_prop_table[prop]; | |
428870ff BB |
427 | |
428 | /* The mlslabel property is never delegatable. */ | |
429 | if (prop == ZFS_PROP_MLSLABEL) | |
430 | return (B_FALSE); | |
431 | ||
34dc7c2f BB |
432 | return (pd->pd_attr != PROP_READONLY); |
433 | } | |
434 | ||
435 | /* | |
436 | * Given a zfs dataset property name, returns the corresponding property ID. | |
437 | */ | |
438 | zfs_prop_t | |
439 | zfs_name_to_prop(const char *propname) | |
440 | { | |
441 | return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); | |
442 | } | |
443 | ||
34dc7c2f BB |
444 | /* |
445 | * For user property names, we allow all lowercase alphanumeric characters, plus | |
446 | * a few useful punctuation characters. | |
447 | */ | |
448 | static int | |
449 | valid_char(char c) | |
450 | { | |
451 | return ((c >= 'a' && c <= 'z') || | |
452 | (c >= '0' && c <= '9') || | |
453 | c == '-' || c == '_' || c == '.' || c == ':'); | |
454 | } | |
455 | ||
456 | /* | |
457 | * Returns true if this is a valid user-defined property (one with a ':'). | |
458 | */ | |
459 | boolean_t | |
460 | zfs_prop_user(const char *name) | |
461 | { | |
462 | int i; | |
463 | char c; | |
464 | boolean_t foundsep = B_FALSE; | |
465 | ||
466 | for (i = 0; i < strlen(name); i++) { | |
467 | c = name[i]; | |
468 | if (!valid_char(c)) | |
469 | return (B_FALSE); | |
470 | if (c == ':') | |
471 | foundsep = B_TRUE; | |
472 | } | |
473 | ||
474 | if (!foundsep) | |
475 | return (B_FALSE); | |
476 | ||
477 | return (B_TRUE); | |
478 | } | |
479 | ||
9babb374 BB |
480 | /* |
481 | * Returns true if this is a valid userspace-type property (one with a '@'). | |
482 | * Note that after the @, any character is valid (eg, another @, for SID | |
483 | * user@domain). | |
484 | */ | |
485 | boolean_t | |
486 | zfs_prop_userquota(const char *name) | |
487 | { | |
488 | zfs_userquota_prop_t prop; | |
489 | ||
490 | for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { | |
491 | if (strncmp(name, zfs_userquota_prop_prefixes[prop], | |
492 | strlen(zfs_userquota_prop_prefixes[prop])) == 0) { | |
493 | return (B_TRUE); | |
494 | } | |
495 | } | |
496 | ||
497 | return (B_FALSE); | |
498 | } | |
499 | ||
330d06f9 MA |
500 | /* |
501 | * Returns true if this is a valid written@ property. | |
502 | * Note that after the @, any character is valid (eg, another @, for | |
503 | * written@pool/fs@origin). | |
504 | */ | |
505 | boolean_t | |
506 | zfs_prop_written(const char *name) | |
507 | { | |
508 | static const char *prefix = "written@"; | |
509 | return (strncmp(name, prefix, strlen(prefix)) == 0); | |
510 | } | |
511 | ||
34dc7c2f BB |
512 | /* |
513 | * Tables of index types, plus functions to convert between the user view | |
514 | * (strings) and internal representation (uint64_t). | |
515 | */ | |
516 | int | |
517 | zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) | |
518 | { | |
519 | return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); | |
520 | } | |
521 | ||
522 | int | |
523 | zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) | |
524 | { | |
525 | return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); | |
526 | } | |
527 | ||
428870ff BB |
528 | uint64_t |
529 | zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) | |
530 | { | |
531 | return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); | |
532 | } | |
533 | ||
34dc7c2f BB |
534 | /* |
535 | * Returns TRUE if the property applies to any of the given dataset types. | |
536 | */ | |
b128c09f | 537 | boolean_t |
34dc7c2f BB |
538 | zfs_prop_valid_for_type(int prop, zfs_type_t types) |
539 | { | |
540 | return (zprop_valid_for_type(prop, types)); | |
541 | } | |
542 | ||
543 | zprop_type_t | |
544 | zfs_prop_get_type(zfs_prop_t prop) | |
545 | { | |
546 | return (zfs_prop_table[prop].pd_proptype); | |
547 | } | |
548 | ||
549 | /* | |
550 | * Returns TRUE if the property is readonly. | |
551 | */ | |
552 | boolean_t | |
553 | zfs_prop_readonly(zfs_prop_t prop) | |
554 | { | |
555 | return (zfs_prop_table[prop].pd_attr == PROP_READONLY || | |
556 | zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
557 | } | |
558 | ||
559 | /* | |
560 | * Returns TRUE if the property is only allowed to be set once. | |
561 | */ | |
562 | boolean_t | |
563 | zfs_prop_setonce(zfs_prop_t prop) | |
564 | { | |
565 | return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
566 | } | |
567 | ||
568 | const char * | |
569 | zfs_prop_default_string(zfs_prop_t prop) | |
570 | { | |
571 | return (zfs_prop_table[prop].pd_strdefault); | |
572 | } | |
573 | ||
574 | uint64_t | |
575 | zfs_prop_default_numeric(zfs_prop_t prop) | |
576 | { | |
577 | return (zfs_prop_table[prop].pd_numdefault); | |
578 | } | |
579 | ||
580 | /* | |
581 | * Given a dataset property ID, returns the corresponding name. | |
582 | * Assuming the zfs dataset property ID is valid. | |
583 | */ | |
584 | const char * | |
585 | zfs_prop_to_name(zfs_prop_t prop) | |
586 | { | |
587 | return (zfs_prop_table[prop].pd_name); | |
588 | } | |
589 | ||
590 | /* | |
591 | * Returns TRUE if the property is inheritable. | |
592 | */ | |
593 | boolean_t | |
594 | zfs_prop_inheritable(zfs_prop_t prop) | |
595 | { | |
596 | return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || | |
597 | zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
598 | } | |
599 | ||
600 | #ifndef _KERNEL | |
601 | ||
602 | /* | |
603 | * Returns a string describing the set of acceptable values for the given | |
604 | * zfs property, or NULL if it cannot be set. | |
605 | */ | |
606 | const char * | |
607 | zfs_prop_values(zfs_prop_t prop) | |
608 | { | |
609 | return (zfs_prop_table[prop].pd_values); | |
610 | } | |
611 | ||
612 | /* | |
613 | * Returns TRUE if this property is a string type. Note that index types | |
614 | * (compression, checksum) are treated as strings in userland, even though they | |
615 | * are stored numerically on disk. | |
616 | */ | |
617 | int | |
618 | zfs_prop_is_string(zfs_prop_t prop) | |
619 | { | |
620 | return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || | |
621 | zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); | |
622 | } | |
623 | ||
624 | /* | |
625 | * Returns the column header for the given property. Used only in | |
626 | * 'zfs list -o', but centralized here with the other property information. | |
627 | */ | |
628 | const char * | |
629 | zfs_prop_column_name(zfs_prop_t prop) | |
630 | { | |
631 | return (zfs_prop_table[prop].pd_colname); | |
632 | } | |
633 | ||
634 | /* | |
635 | * Returns whether the given property should be displayed right-justified for | |
636 | * 'zfs list'. | |
637 | */ | |
638 | boolean_t | |
639 | zfs_prop_align_right(zfs_prop_t prop) | |
640 | { | |
641 | return (zfs_prop_table[prop].pd_rightalign); | |
642 | } | |
643 | ||
644 | #endif | |
c28b2279 BB |
645 | |
646 | #if defined(_KERNEL) && defined(HAVE_SPL) | |
647 | ||
648 | static int zcommon_init(void) { return 0; } | |
649 | static int zcommon_fini(void) { return 0; } | |
650 | ||
651 | spl_module_init(zcommon_init); | |
652 | spl_module_exit(zcommon_fini); | |
653 | ||
654 | MODULE_DESCRIPTION("Generic ZFS support"); | |
655 | MODULE_AUTHOR(ZFS_META_AUTHOR); | |
656 | MODULE_LICENSE(ZFS_META_LICENSE); | |
657 | ||
658 | /* zfs dataset property functions */ | |
659 | EXPORT_SYMBOL(zfs_userquota_prop_prefixes); | |
660 | EXPORT_SYMBOL(zfs_prop_init); | |
661 | EXPORT_SYMBOL(zfs_prop_get_type); | |
662 | EXPORT_SYMBOL(zfs_prop_get_table); | |
663 | EXPORT_SYMBOL(zfs_prop_delegatable); | |
664 | ||
665 | /* Dataset property functions shared between libzfs and kernel. */ | |
666 | EXPORT_SYMBOL(zfs_prop_default_string); | |
667 | EXPORT_SYMBOL(zfs_prop_default_numeric); | |
668 | EXPORT_SYMBOL(zfs_prop_readonly); | |
669 | EXPORT_SYMBOL(zfs_prop_inheritable); | |
670 | EXPORT_SYMBOL(zfs_prop_setonce); | |
671 | EXPORT_SYMBOL(zfs_prop_to_name); | |
672 | EXPORT_SYMBOL(zfs_name_to_prop); | |
673 | EXPORT_SYMBOL(zfs_prop_user); | |
674 | EXPORT_SYMBOL(zfs_prop_userquota); | |
675 | EXPORT_SYMBOL(zfs_prop_index_to_string); | |
676 | EXPORT_SYMBOL(zfs_prop_string_to_index); | |
677 | EXPORT_SYMBOL(zfs_prop_valid_for_type); | |
678 | ||
679 | #endif |