zfs_prop.c revision 91ebeef555ce7f899b6270a3c2df47b51f7ad59a
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_ioctl.h>
#include <sys/zfs_znode.h>
#include "zfs_prop.h"
#include "zfs_deleg.h"
#if defined(_KERNEL)
#else
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#endif
typedef enum {
} prop_attr_t;
typedef struct zfs_index {
const char *name;
} zfs_index_t;
typedef struct {
const char *pd_name; /* human-readable property name */
const char *pd_strdefault; /* default for strings */
int pd_types; /* bitfield of valid dataset types */
/* fs | vol | snap; or pool */
const char *pd_values; /* string telling acceptable values */
const char *pd_colname; /* column header for "zfs list" */
/* "zfs get" help message */
/* defining the possible values */
} prop_desc_t;
static void
{
}
static void
const char *colname)
{
}
static void
{
}
static void
{
}
static void
const zfs_index_t *table)
{
}
static void
{
}
void
zfs_prop_init(void)
{
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 },
{ "gzip-1", ZIO_COMPRESS_GZIP_1 },
{ "gzip-2", ZIO_COMPRESS_GZIP_2 },
{ "gzip-3", ZIO_COMPRESS_GZIP_3 },
{ "gzip-4", ZIO_COMPRESS_GZIP_4 },
{ "gzip-5", ZIO_COMPRESS_GZIP_5 },
{ "gzip-6", ZIO_COMPRESS_GZIP_6 },
{ "gzip-7", ZIO_COMPRESS_GZIP_7 },
{ "gzip-8", ZIO_COMPRESS_GZIP_8 },
{ "gzip-9", ZIO_COMPRESS_GZIP_9 },
{ 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 copies_table[] = {
{ "1", 1 },
{ "2", 2 },
{ "3", 3 },
{ NULL }
};
static zfs_index_t version_table[] = {
{ "1", 1 },
{ "2", 2 },
{ "current", ZPL_VERSION },
{ NULL }
};
/* inherit index properties */
"on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
"discard | noallow | secure | passthrough", "ACLINHERIT",
/* string properties */
/* readonly number properties */
"<size>", "AVAIL");
"<1.00x or higher if compressed>", "RATIO");
/* default number properties */
/* inherit number properties */
/* readonly boolean properties */
/* default boolean properties */
/* inherit boolean properties */
/* hidden properties */
/* oddball properties */
}
/*
* Returns TRUE if the property applies to any of the given dataset types.
*/
int
{
}
/*
* Determine if the specified property is visible or not.
*/
{
if (prop < 0)
return (B_FALSE);
}
/*
* A comparison function we can use to order indexes into the
* zfs_prop_table[]
*/
static int
{
}
}
/*
* Iterate over all properties, calling back into the specified function
* for each property. We will continue to iterate until we either
* reach the end or the callback function something other than
* ZFS_PROP_CONT.
*/
{
int i;
for (int j = 0; j < ZFS_NUM_PROPS; j++)
order[j] = j;
if (ordered) {
}
for (i = 0; i < ZFS_NUM_PROPS; i++) {
return (order[i]);
}
}
return (ZFS_PROP_CONT);
}
{
}
{
}
{
B_FALSE));
}
{
}
{
}
static boolean_t
{
#ifndef _KERNEL
int c;
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
}
{
return (prop);
return (ZFS_PROP_CONT);
}
/*
* Given a property name and its type, returns the corresponding property ID.
*/
{
}
/*
* Given a zfs dataset property name, returns the corresponding property ID.
*/
zfs_name_to_prop(const char *propname)
{
}
/*
* Given a pool property name, returns the corresponding property ID.
*/
zpool_name_to_prop(const char *propname)
{
}
{
}
/*
* 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 *
{
}
const char *
{
}
{
}
{
}
/*
* Returns TRUE if the property is readonly.
*/
int
{
}
/*
* Given a dataset property ID, returns the corresponding name.
* Assuming the zfs dataset property ID is valid.
*/
const char *
{
}
/*
* Given a pool property ID, returns the corresponding name.
* Assuming the pool property ID is valid.
*/
const char *
{
}
/*
* Returns TRUE if the property is inheritable.
*/
int
{
}
/*
* Tables of index types, plus functions to convert between the user view
* (strings) and internal representation (uint64_t).
*/
int
{
const zfs_index_t *table;
int i;
return (-1);
return (0);
}
}
return (-1);
}
int
{
const zfs_index_t *table;
int i;
return (-1);
return (0);
}
}
return (-1);
}
#ifndef _KERNEL
/*
* Returns a string describing the set of acceptable values for the given
* zfs property, or NULL if it cannot be set.
*/
const char *
{
return (NULL);
}
/*
* Returns a string describing the set of acceptable values for the given
* zpool property, or NULL if it cannot be set.
*/
const char *
{
return (NULL);
}
/*
* 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.
*/
{
const zfs_index_t *idx;
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