FreeBSD/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
/*
 * zfs bookmark <fs@snap> <fs#bmark>
 *
 * Creates a bookmark with the given name from the given snapshot.
 */
zfs bookmark  
Creates a bookmark with the given name from the given snapshot.
zfs bookmark Creates a bookmark with the given name from the given snapshot .
static int
zfs_do_bookmark(int argc, char **argv)
{
	char snapname[ZFS_MAXNAMELEN];
	zfs_handle_t *zhp;
	nvlist_t *nvl;
	int ret = 0;
	int c;
	while ((c = getopt(argc, argv, "")) != -1) {
		switch (c) {
		case '?':
			(void) fprintf(stderr,
			    gettext("invalid option '%c'\n"), optopt);
			goto usage;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc < 1) {
		(void) fprintf(stderr, gettext("missing snapshot argument\n"));
		goto usage;
	}
	if (argc < 2) {
		(void) fprintf(stderr, gettext("missing bookmark argument\n"));
		goto usage;
	}
	if (strchr(argv[1], '#') == NULL) {
		(void) fprintf(stderr,
		    gettext("invalid bookmark name '%s' -- "
		    "must contain a '#'\n"), argv[1]);
		goto usage;
	}
	if (argv[0][0] == '@') {
		(void) strncpy(snapname, argv[1], sizeof (snapname));
		*strchr(snapname, '#') = '\0';
		(void) strlcat(snapname, argv[0], sizeof (snapname));
	} else {
		(void) strncpy(snapname, argv[0], sizeof (snapname));
	}
	zhp = zfs_open(g_zfs, snapname, ZFS_TYPE_SNAPSHOT);
	if (zhp == NULL)
		goto usage;
	zfs_close(zhp);
	nvl = fnvlist_alloc();
	fnvlist_add_string(nvl, argv[1], snapname);
	ret = lzc_bookmark(nvl, NULL);
	fnvlist_free(nvl);
	if (ret != 0) {
		const char *err_msg;
		char errbuf[1024];
		(void) snprintf(errbuf, sizeof (errbuf),
		    dgettext(TEXT_DOMAIN,
		    "cannot create bookmark '%s'"), argv[1]);
		switch (ret) {
		case EXDEV:
			err_msg = "bookmark is in a different pool";
			break;
		case EEXIST:
			err_msg = "bookmark exists";
			break;
		case EINVAL:
			err_msg = "invalid argument";
			break;
		case ENOTSUP:
			err_msg = "bookmark feature not enabled";
			break;
		case ENOSPC:
			err_msg = "out of space";
			break;
		default:
			err_msg = "unknown error";
			break;
		}
		(void) fprintf(stderr, "%s: %s\n", errbuf,
		    dgettext(TEXT_DOMAIN, err_msg));
	}
	return (ret != 0);
usage:
	usage(B_FALSE);
	return (-1);
}
static int zfs_do_bookmark ( int argc , char * * argv ) { char snapname [ ZFS_MAXNAMELEN ] ; zfs_handle_t * zhp ; nvlist_t * nvl ; int ret = 0 ; int c ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : ( void ) fprintf ( stderr , gettext ( " \n " ) , optopt ) ; goto usage ; } } argc -= optind ; argv += optind ; if ( argc < 1 ) { ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; goto usage ; } if ( argc < 2 ) { ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; goto usage ; } if ( strchr ( argv [ 1 ] , ' ' ) == NULL ) { ( void ) fprintf ( stderr , gettext ( " " " \n " ) , argv [ 1 ] ) ; goto usage ; } if ( argv [ 0 ] [ 0 ] == ' ' ) { ( void ) strncpy ( snapname , argv [ 1 ] , sizeof ( snapname ) ) ; * strchr ( snapname , ' ' ) = ' \0 ' ; ( void ) strlcat ( snapname , argv [ 0 ] , sizeof ( snapname ) ) ; } else { ( void ) strncpy ( snapname , argv [ 0 ] , sizeof ( snapname ) ) ; } zhp = zfs_open ( g_zfs , snapname , ZFS_TYPE_SNAPSHOT ) ; if ( zhp == NULL ) goto usage ; zfs_close ( zhp ) ; nvl = fnvlist_alloc ( ) ; fnvlist_add_string ( nvl , argv [ 1 ] , snapname ) ; ret = lzc_bookmark ( nvl , NULL ) ; fnvlist_free ( nvl ) ; if ( ret != 0 ) { const char * err_msg ; char errbuf [ 1024 ] ; ( void ) snprintf ( errbuf , sizeof ( errbuf ) , dgettext ( TEXT_DOMAIN , " " ) , argv [ 1 ] ) ; switch ( ret ) { case EXDEV : err_msg = " " ; break ; case EEXIST : err_msg = " " ; break ; case EINVAL : err_msg = " " ; break ; case ENOTSUP : err_msg = " " ; break ; case ENOSPC : err_msg = " " ; break ; default : err_msg = " " ; break ; } ( void ) fprintf ( stderr , " \n " , errbuf , dgettext ( TEXT_DOMAIN , err_msg ) ) ; } return ( ret != 0 ) ; usage : usage ( B_FALSE ) ; return ( -1 ) ; }
zfs bookmark <fs@snap> <fs#bmark>
 Creates a bookmark with the given name from the given snapshot.
zfs bookmark <fs@snap > <fs#bmark > Creates a bookmark with the given name from the given snapshot .
/* check options */ /* check number of arguments */ /*
		 * Snapshot name begins with @.
		 * Default to same fs as bookmark.
		 */