Add -p switch to "zpool get"
[zfs.git] / module / zcommon / zfs_namecheck.c
index a9d109b..8508bc7 100644 (file)
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident  "%Z%%M% %I%     %E% SMI"
-
 /*
  * Common name validation routines for ZFS.  These routines are shared by the
  * userland code as well as the ioctl() layer to ensure that we don't
@@ -61,7 +59,7 @@ valid_char(char c)
  * Snapshot names must be made up of alphanumeric characters plus the following
  * characters:
  *
- *     [-_.:]
+ *     [-_.: ]
  */
 int
 snapshot_namecheck(const char *path, namecheck_err_t *why, char *what)
@@ -144,9 +142,22 @@ dataset_namecheck(const char *path, namecheck_err_t *why, char *what)
         * which is the same as MAXNAMELEN used in the kernel.
         * If ZFS_MAXNAMELEN value is changed, make sure to cleanup all
         * places using MAXNAMELEN.
+        *
+        * When HAVE_KOBJ_NAME_LEN is defined the maximum safe kobject name
+        * length is 20 bytes.  This 20 bytes is broken down as follows to
+        * provide a maximum safe <pool>/<dataset>[@snapshot] length of only
+        * 18 bytes.  To ensure bytes are left for <dataset>[@snapshot] the
+        * <pool> portition is futher limited to 9 bytes.  For 2.6.27 and
+        * newer kernels this limit is set to MAXNAMELEN.
+        *
+        *   <pool>/<dataset> + <partition> + <newline>
+        *   (18)             + (1)         + (1)
         */
-
+#ifdef HAVE_KOBJ_NAME_LEN
+       if (strlen(path) > 18) {
+#else
        if (strlen(path) >= MAXNAMELEN) {
+#endif /* HAVE_KOBJ_NAME_LEN */
                if (why)
                        *why = NAME_ERR_TOOLONG;
                return (-1);
@@ -305,8 +316,22 @@ pool_namecheck(const char *pool, namecheck_err_t *why, char *what)
         * which is the same as MAXNAMELEN used in the kernel.
         * If ZPOOL_MAXNAMELEN value is changed, make sure to cleanup all
         * places using MAXNAMELEN.
+        *
+        * When HAVE_KOBJ_NAME_LEN is defined the maximum safe kobject name
+        * length is 20 bytes.  This 20 bytes is broken down as follows to
+        * provide a maximum safe <pool>/<dataset>[@snapshot] length of only
+        * 18 bytes.  To ensure bytes are left for <dataset>[@snapshot] the
+        * <pool> portition is futher limited to 8 bytes.  For 2.6.27 and
+        * newer kernels this limit is set to MAXNAMELEN.
+        *
+        *   <pool>/<dataset> + <partition> + <newline>
+        *   (18)             + (1)         + (1)
         */
+#ifdef HAVE_KOBJ_NAME_LEN
+       if (strlen(pool) > 8) {
+#else
        if (strlen(pool) >= MAXNAMELEN) {
+#endif /* HAVE_KOBJ_NAME_LEN */
                if (why)
                        *why = NAME_ERR_TOOLONG;
                return (-1);
@@ -346,18 +371,8 @@ pool_namecheck(const char *pool, namecheck_err_t *why, char *what)
        return (0);
 }
 
-/*
- * Check if the dataset name is private for internal usage.
- * '$' is reserved for internal dataset names. e.g. "$MOS"
- *
- * Return 1 if the given name is used internally.
- * Return 0 if it is not.
- */
-int
-dataset_name_hidden(const char *name)
-{
-       if (strchr(name, '$') != NULL)
-               return (1);
-
-       return (0);
-}
+#if defined(_KERNEL) && defined(HAVE_SPL)
+EXPORT_SYMBOL(snapshot_namecheck);
+EXPORT_SYMBOL(pool_namecheck);
+EXPORT_SYMBOL(dataset_namecheck);
+#endif