zfs_prop.c revision f3861e1a2ceec23a5b699c24d814b7775a9e0b52
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 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;
} prop_desc_t;
B_FALSE },
B_TRUE },
};
{
}
static boolean_t
{
#ifndef _KERNEL
int c;
#endif
#ifndef _KERNEL
return (B_FALSE);
#endif
return (B_TRUE);
#ifndef _KERNEL
return (B_FALSE);
for (c = 0; c < len; c++)
break;
return (colname[c] == '\0');
#else
return (B_FALSE);
#endif
}
/*
* 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);
}
return (ZFS_PROP_INVAL);
}
/*
* For user property names, we allow all lowercase alphanumeric characters, plus
* a few useful punctuation characters.
*/
static int
valid_char(char c)
{
return ((c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '-' || c == '_' || c == '.' || c == ':');
}
/*
* Returns true if this is a valid user-defined property (one with a ':').
*/
zfs_prop_user(const char *name)
{
int i;
char c;
c = name[i];
if (!valid_char(c))
return (B_FALSE);
if (c == ':')
}
if (!foundsep)
return (B_FALSE);
return (B_TRUE);
}
/*
* Return the default value for the given property.
*/
const char *
{
}
{
}
/*
* Returns TRUE if the property is readonly.
*/
int
{
}
/*
* Given a property ID, returns the corresponding name.
*/
const char *
{
}
/*
* Returns TRUE if the property is inheritable.
*/
int
{
}
typedef struct zfs_index {
const char *name;
} zfs_index_t;
static zfs_index_t checksum_table[] = {
{ "on", ZIO_CHECKSUM_ON },
{ "off", ZIO_CHECKSUM_OFF },
{ "fletcher2", ZIO_CHECKSUM_FLETCHER_2 },
{ "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
{ "sha256", ZIO_CHECKSUM_SHA256 },
{ NULL }
};
static zfs_index_t compress_table[] = {
{ "on", ZIO_COMPRESS_ON },
{ "off", ZIO_COMPRESS_OFF },
{ "lzjb", ZIO_COMPRESS_LZJB },
{ NULL }
};
static zfs_index_t snapdir_table[] = {
{ "hidden", ZFS_SNAPDIR_HIDDEN },
{ "visible", ZFS_SNAPDIR_VISIBLE },
{ NULL }
};
static zfs_index_t acl_mode_table[] = {
{ "discard", ZFS_ACL_DISCARD },
{ "groupmask", ZFS_ACL_GROUPMASK },
{ "passthrough", ZFS_ACL_PASSTHROUGH },
{ NULL }
};
static zfs_index_t acl_inherit_table[] = {
{ "discard", ZFS_ACL_DISCARD },
{ "noallow", ZFS_ACL_NOALLOW },
{ "secure", ZFS_ACL_SECURE },
{ "passthrough", ZFS_ACL_PASSTHROUGH },
{ NULL }
};
static zfs_index_t *
{
switch (prop) {
case ZFS_PROP_CHECKSUM:
return (checksum_table);
case ZFS_PROP_COMPRESSION:
return (compress_table);
case ZFS_PROP_SNAPDIR:
return (snapdir_table);
case ZFS_PROP_ACLMODE:
return (acl_mode_table);
case ZFS_PROP_ACLINHERIT:
return (acl_inherit_table);
default:
return (NULL);
}
}
/*
* Tables of index types, plus functions to convert between the user view
* (strings) and internal representation (uint64_t).
*/
int
{
int i;
return (-1);
return (0);
}
}
return (-1);
}
int
{
int i;
return (-1);
return (0);
}
}
return (-1);
}
#ifndef _KERNEL
/*
* 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 whether the given property should be displayed right-justified for
* 'zfs list'.
*/
{
}
/*
* Determines the minimum width for the column, and indicates whether it's fixed
* or not. Only string columns are non-fixed.
*/
{
int i;
/*
* Start with the width of the column name.
*/
/*
* For fixed-width values, make sure the width is large enough to hold
* any possible value.
*/
switch (pd->pd_proptype) {
case prop_type_number:
/*
* The maximum length of a human-readable number is 5 characters
* ("20.4M", for example).
*/
if (ret < 5)
ret = 5;
/*
* 'creation' is handled specially because it's a number
* internally, but displayed as a date string.
*/
if (prop == ZFS_PROP_CREATION)
break;
case prop_type_boolean:
/*
* The maximum length of a boolean value is 3 characters, for
* "off".
*/
if (ret < 3)
ret = 3;
break;
case prop_type_index:
}
break;
case prop_type_string:
break;
}
return (ret);
}
#endif