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