zfs_prop.c revision 4f75c27e43a3c25dcbebc6889ae73f1b2c32e537
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Master property table.
*
* This table keeps track of all the properties supported by ZFS, and their
* various attributes. Not all of these are needed by the kernel, and several
* are only used by a single libzfs client. But having them here centralizes
* all property information in one location.
*
* name The human-readable string representing this property
* proptype Basic type (string, boolean, number)
* default Default value for the property. Sadly, C only allows
* you to initialize the first member of a union, so we
* have two default members for each property.
* attr Attributes (readonly, inheritable) for the property
* types Valid dataset types to which this applies
* values String describing acceptable values for the property
* colname The column header for 'zfs list'
* colfmt The column formatting for 'zfs list'
*
* This table must match the order of property types in libzfs.h.
*/
#include <sys/zfs_ioctl.h>
#include "zfs_prop.h"
#if defined(_KERNEL)
#else
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#endif
typedef enum {
} prop_attr_t;
typedef struct {
const char *pd_name;
const char *pd_strdefault;
int pd_types;
const char *pd_values;
const char *pd_colname;
const char *pd_colfmt;
} prop_desc_t;
"<size>", "REFER", "%5s" },
"<size> | none", "RESERV", "%6s" },
"512 to 128k, power of 2", "RECSIZE", "%7s" },
"<path> | legacy | none", "MOUNTPOINT", "%-20s" },
"on | off | share(1M) options", "SHARENFS", "%-15s" },
"on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", "%10s" },
"on | off | lzjb", "COMPRESS", "%8s" },
"on | off", "ATIME", "%5s" },
"on | off", "DEVICES", "%7s" },
"on | off", "EXEC", "%4s" },
"on | off", "RDONLY", "%6s" },
"on | off", "ZONED", "%5s" },
"hidden | visible", "SNAPDIR", "%7s" },
"discard | groupmask | passthrough", "ACLMODE", "%11s" },
"discard | noallow | secure | passthrough", "ACLINHERIT", "%11s" },
};
{
}
/*
* Given a property name, returns the corresponding property ID.
*/
zfs_name_to_prop(const char *propname)
{
int i;
for (i = 0; i < ZFS_NPROP_ALL; i++) {
return (i);
#ifndef _KERNEL
return (i);
#endif
}
return (ZFS_PROP_INVAL);
}
/*
* Return the default value for the given property.
*/
void
{
/*
* For index types (compression and checksum), we want the numeric value
* in the kernel, but the string value in userland. The kernel will
* call zfs_prop_default_numeric() based on the property type. In
* userland, the zfs_prop_is_string() will return TRUE for index types,
* and we'll return "on" from this function.
*/
else
}
{
}
/*
* Returns TRUE if the property is readonly.
*/
int
{
}
#ifndef _KERNEL
/*
* Given a property ID, returns the corresponding name.
*/
const char *
{
}
/*
* Returns TRUE if the property is inheritable.
*/
int
{
}
/*
* Returns TRUE if the property applies to the given dataset types.
*/
int
{
}
/*
* Returns a string describing the set of acceptable values for the given
* property, or NULL if it cannot be set.
*/
const char *
{
}
/*
* Returns TRUE if this property is a string type. Note that index types
* (compression, checksum) are treated as strings in userland, even though they
* are stored numerically on disk.
*/
int
{
}
/*
* Returns the column header for the given property. Used only in
* 'zfs list -o', but centralized here with the other property information.
*/
const char *
{
}
/*
* Returns the column formatting for the given property. Used only in
* 'zfs list -o', but centralized here with the other property information.
*/
const char *
{
}
/*
* Given a comma-separated list of fields, fills in the specified array with a
* list of properties. The keyword "all" can be used to specify all properties.
* The 'count' parameter returns the number of matching properties placed into
* the list. The 'props' parameter must point to an array of at least
* ZFS_NPROP_ALL elements.
*/
int
{
int i;
char *s, *p;
*count = 0;
/*
* Check for the special value "all", which indicates all properties
* should be displayed.
*/
if (max < ZFS_NPROP_VISIBLE)
return (EOVERFLOW);
for (i = 0; i < ZFS_NPROP_VISIBLE; i++)
props[i] = i;
return (0);
}
/*
* It would be nice to use getsubopt() here, but the inclusion of column
* aliases makes this more effort than it's worth.
*/
s = fields;
while (*s != '\0') {
p = s + len;
} else {
len = p - s;
}
/*
* Check for empty options.
*/
if (len == 0) {
*badopt = "";
return (EINVAL);
}
/*
* Check all regular property names.
*/
for (i = 0; i < ZFS_NPROP_ALL; i++) {
continue;
break;
}
/*
* Check all abbreviated column names.
*/
if (i == ZFS_NPROP_ALL) {
for (i = 0; i < ZFS_NPROP_ALL; i++) {
continue;
if (len ==
len) == 0)
break;
}
}
/*
* If no column is specified, then return failure, setting
* 'badopt' to point to the invalid option.
*/
if (i == ZFS_NPROP_ALL) {
s[len] = '\0';
*badopt = s;
return (EINVAL);
}
/*
* If the user specified too many options (by using the same one
* multiple times). return an error with 'badopt' set to NULL to
* indicate this condition.
*/
return (EOVERFLOW);
*count += 1;
s = p;
if (*s == ',')
s++;
}
/*
* If no fields were specified, return an error.
*/
if (*count == 0) {
*badopt = "";
return (EINVAL);
}
return (0);
}
#endif