xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_vss.c (revision a767d70f)
189dc44ceSjose borrego /*
289dc44ceSjose borrego  * CDDL HEADER START
389dc44ceSjose borrego  *
489dc44ceSjose borrego  * The contents of this file are subject to the terms of the
589dc44ceSjose borrego  * Common Development and Distribution License (the "License").
689dc44ceSjose borrego  * You may not use this file except in compliance with the License.
789dc44ceSjose borrego  *
889dc44ceSjose borrego  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
989dc44ceSjose borrego  * or http://www.opensolaris.org/os/licensing.
1089dc44ceSjose borrego  * See the License for the specific language governing permissions
1189dc44ceSjose borrego  * and limitations under the License.
1289dc44ceSjose borrego  *
1389dc44ceSjose borrego  * When distributing Covered Code, include this CDDL HEADER in each
1489dc44ceSjose borrego  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1589dc44ceSjose borrego  * If applicable, add the following below this CDDL HEADER, with the
1689dc44ceSjose borrego  * fields enclosed by brackets "[]" replaced with your own identifying
1789dc44ceSjose borrego  * information: Portions Copyright [yyyy] [name of copyright owner]
1889dc44ceSjose borrego  *
1989dc44ceSjose borrego  * CDDL HEADER END
2089dc44ceSjose borrego  */
2189dc44ceSjose borrego /*
22148c5f43SAlan Wright  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
231bc6aeeeSMatt Barden  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
24*a767d70fSGordon Ross  * Copyright 2022 RackTop Systems, Inc.
2589dc44ceSjose borrego  */
2689dc44ceSjose borrego 
2789dc44ceSjose borrego /*
2889dc44ceSjose borrego  * Volume Copy Shadow Services (VSS) provides a way for users to
2989dc44ceSjose borrego  * restore/recover deleted files/directories.
3089dc44ceSjose borrego  * For the server to support VSS for Microsoft clients, there is
3189dc44ceSjose borrego  * two basic functions that need to be implemented.
3289dc44ceSjose borrego  * The first is to intercept the NT_TRANSACT_IOCTL command with
3389dc44ceSjose borrego  * the function code of FSCTL_SRV_ENUMERATE_SNAPSHOTS (0x00144064).
3489dc44ceSjose borrego  * This is to report the count or the count and list of snapshots
3589dc44ceSjose borrego  * for that share.
3689dc44ceSjose borrego  * The second function need to trap commands with the
3789dc44ceSjose borrego  * SMB_FLAGS2_REPARSE_PATH bit set in the smb header.  This bit
3889dc44ceSjose borrego  * means that there is a @GMT token in path that needs to be
3989dc44ceSjose borrego  * processed.  The @GMT token means to process this command, but
4089dc44ceSjose borrego  * in the snapshot.
4189dc44ceSjose borrego  */
4289dc44ceSjose borrego 
43bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
44bbf6f00cSJordan Brown #include <smbsrv/string.h>
45adee6784SGordon Ross #include <smb/winioctl.h>
469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_door.h>
4789dc44ceSjose borrego 
4889dc44ceSjose borrego /* Size of the token on the wire due to encoding */
4989dc44ceSjose borrego #define	SMB_VSS_GMT_NET_SIZE(sr) (smb_ascii_or_unicode_null_len(sr) * \
5089dc44ceSjose borrego     SMB_VSS_GMT_SIZE)
5189dc44ceSjose borrego 
5289dc44ceSjose borrego #define	SMB_VSS_COUNT_SIZE 16
5389dc44ceSjose borrego 
549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_vss_is_gmttoken(const char *);
559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static const char *smb_vss_find_gmttoken(const char *);
56a90cf9f2SGordon Ross static uint32_t smb_vss_encode_gmttokens(smb_request_t *, smb_fsctl_t *,
579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States     int32_t, smb_gmttoken_response_t *);
589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_vss_remove_first_token_from_path(char *);
599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
608622ec45SGordon Ross static uint32_t smb_vss_get_count(smb_tree_t *, char *);
61a90cf9f2SGordon Ross static void smb_vss_map_gmttoken(smb_tree_t *, char *, char *, time_t, char *);
628622ec45SGordon Ross static void smb_vss_get_snapshots(smb_tree_t *, char *,
638622ec45SGordon Ross     uint32_t, smb_gmttoken_response_t *);
649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_vss_get_snapshots_free(smb_gmttoken_response_t *);
65148c5f43SAlan Wright static int smb_vss_lookup_node(smb_request_t *sr, smb_node_t *, vnode_t *,
66a90cf9f2SGordon Ross     char *, smb_node_t *, smb_node_t **);
6789dc44ceSjose borrego 
6889dc44ceSjose borrego /*
6989dc44ceSjose borrego  * This is to respond to the nt_transact_ioctl to either respond with the
7089dc44ceSjose borrego  * number of snapshots, or to respond with the list.  It needs to be sorted
7189dc44ceSjose borrego  * before the reply.  If the the max data bytes to return is
7289dc44ceSjose borrego  * SMB_VSS_COUNT_SIZE, then all that is requested is the count, otherwise
7389dc44ceSjose borrego  * return the count and the list of @GMT tokens (one token for each
7489dc44ceSjose borrego  * snapshot).
7589dc44ceSjose borrego  */
7689dc44ceSjose borrego uint32_t
smb_vss_enum_snapshots(smb_request_t * sr,smb_fsctl_t * fsctl)77a90cf9f2SGordon Ross smb_vss_enum_snapshots(smb_request_t *sr, smb_fsctl_t *fsctl)
7889dc44ceSjose borrego {
7989dc44ceSjose borrego 	uint32_t count = 0;
8089dc44ceSjose borrego 	char *root_path;
81b1352070SAlan Wright 	uint32_t status = NT_STATUS_SUCCESS;
82a90cf9f2SGordon Ross 	smb_gmttoken_response_t snaps;
839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
841bc6aeeeSMatt Barden 	ASSERT(sr->fid_ofile);
851bc6aeeeSMatt Barden 	ASSERT(sr->fid_ofile->f_node);
8689dc44ceSjose borrego 
87a90cf9f2SGordon Ross 	if (fsctl->MaxOutputResp < SMB_VSS_COUNT_SIZE)
88b1352070SAlan Wright 		return (NT_STATUS_INVALID_PARAMETER);
8989dc44ceSjose borrego 
901bc6aeeeSMatt Barden 	/*
911bc6aeeeSMatt Barden 	 * smbd will find the root of the lowest filesystem from mntpath of a
921bc6aeeeSMatt Barden 	 * file by comparing it agaisnt mnttab, repeatedly removing components
931bc6aeeeSMatt Barden 	 * until one matches.
941bc6aeeeSMatt Barden 	 */
9589dc44ceSjose borrego 	root_path  = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
961bc6aeeeSMatt Barden 	if (smb_node_getmntpath(sr->fid_ofile->f_node, root_path,
971bc6aeeeSMatt Barden 	    MAXPATHLEN) != 0)
98b1352070SAlan Wright 		return (NT_STATUS_INVALID_PARAMETER);
9989dc44ceSjose borrego 
100a90cf9f2SGordon Ross 	if (fsctl->MaxOutputResp == SMB_VSS_COUNT_SIZE) {
1018622ec45SGordon Ross 		count = smb_vss_get_count(sr->tid_tree, root_path);
102a90cf9f2SGordon Ross 		if (smb_mbc_encodef(fsctl->out_mbc, "lllw", count, 0,
10389dc44ceSjose borrego 		    (count * SMB_VSS_GMT_NET_SIZE(sr) +
10489dc44ceSjose borrego 		    smb_ascii_or_unicode_null_len(sr)), 0) != 0) {
105b1352070SAlan Wright 			status = NT_STATUS_INVALID_PARAMETER;
10689dc44ceSjose borrego 		}
10789dc44ceSjose borrego 	} else {
108a90cf9f2SGordon Ross 		count = fsctl->MaxOutputResp / SMB_VSS_GMT_NET_SIZE(sr);
10989dc44ceSjose borrego 
1108622ec45SGordon Ross 		smb_vss_get_snapshots(sr->tid_tree, root_path,
111a90cf9f2SGordon Ross 		    count, &snaps);
11289dc44ceSjose borrego 
113a90cf9f2SGordon Ross 		status = smb_vss_encode_gmttokens(sr, fsctl, count, &snaps);
11489dc44ceSjose borrego 
115a90cf9f2SGordon Ross 		smb_vss_get_snapshots_free(&snaps);
11689dc44ceSjose borrego 	}
11789dc44ceSjose borrego 
11889dc44ceSjose borrego 	kmem_free(root_path, MAXPATHLEN);
119b1352070SAlan Wright 	return (status);
12089dc44ceSjose borrego }
12189dc44ceSjose borrego 
12289dc44ceSjose borrego /*
12389dc44ceSjose borrego  * sr - the request info, used to find root of dataset,
12489dc44ceSjose borrego  *      unicode or ascii, where the share is rooted in the
12589dc44ceSjose borrego  *      dataset
12689dc44ceSjose borrego  * cur_node - where in the share for the command
12789dc44ceSjose borrego  * vss_cur_node - returned value for the snapshot version
12889dc44ceSjose borrego  *                of the cur_node
1291bc6aeeeSMatt Barden  * gmttoken - if SMB1, the gmttoken to be used to find the snapshot.
1301bc6aeeeSMatt Barden  *            Otherwise, NULL.
13189dc44ceSjose borrego  *
13289dc44ceSjose borrego  * This routine is the processing for handling the
13389dc44ceSjose borrego  * SMB_FLAGS2_REPARSE_PATH bit being set in the smb header.
13489dc44ceSjose borrego  *
13589dc44ceSjose borrego  * By using the cur_node passed in, a new node is found or
13689dc44ceSjose borrego  * created that is the same place in the directory tree, but
1371bc6aeeeSMatt Barden  * in the snapshot.
13889dc44ceSjose borrego  */
13989dc44ceSjose borrego int
smb_vss_lookup_nodes(smb_request_t * sr,smb_node_t * cur_node,smb_node_t ** vss_cur_node,char * gmttoken)1401bc6aeeeSMatt Barden smb_vss_lookup_nodes(smb_request_t *sr, smb_node_t *cur_node,
1411bc6aeeeSMatt Barden     smb_node_t **vss_cur_node, char *gmttoken)
14289dc44ceSjose borrego {
143a90cf9f2SGordon Ross 	smb_arg_open_t	*op = &sr->arg.open;
144148c5f43SAlan Wright 	char		*snapname, *path;
145148c5f43SAlan Wright 	vnode_t		*fsrootvp = NULL;
146a90cf9f2SGordon Ross 	time_t		toktime;
147148c5f43SAlan Wright 	int		err = 0;
14889dc44ceSjose borrego 
14989dc44ceSjose borrego 	if (sr->tid_tree == NULL)
15089dc44ceSjose borrego 		return (ESTALE);
15189dc44ceSjose borrego 
1521bc6aeeeSMatt Barden 	if (gmttoken != NULL) {
153a90cf9f2SGordon Ross 		toktime = 0;
154a90cf9f2SGordon Ross 	} else {
155a90cf9f2SGordon Ross 		/* SMB2 and later */
156a90cf9f2SGordon Ross 		toktime = op->timewarp.tv_sec;
157a90cf9f2SGordon Ross 	}
15889dc44ceSjose borrego 
159148c5f43SAlan Wright 	path = smb_srm_alloc(sr, MAXPATHLEN);
160148c5f43SAlan Wright 	snapname = smb_srm_alloc(sr, MAXPATHLEN);
16189dc44ceSjose borrego 
1621bc6aeeeSMatt Barden 	err = smb_node_getmntpath(cur_node, path, MAXPATHLEN);
1636e3e9d9cSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (err != 0)
164148c5f43SAlan Wright 		return (err);
16589dc44ceSjose borrego 
166a90cf9f2SGordon Ross 	/*
167a90cf9f2SGordon Ross 	 * Find the corresponding snapshot name.  If snapname is
168a90cf9f2SGordon Ross 	 * empty after the map call, no such snapshot was found.
169a90cf9f2SGordon Ross 	 */
17089dc44ceSjose borrego 	*snapname = '\0';
171a90cf9f2SGordon Ross 	smb_vss_map_gmttoken(sr->tid_tree, path, gmttoken, toktime,
172a90cf9f2SGordon Ross 	    snapname);
173a90cf9f2SGordon Ross 	if (*snapname == '\0')
174148c5f43SAlan Wright 		return (ENOENT);
17589dc44ceSjose borrego 
176148c5f43SAlan Wright 	/* find snapshot nodes */
1771bc6aeeeSMatt Barden 	err = VFS_ROOT(cur_node->vp->v_vfsp, &fsrootvp);
17889dc44ceSjose borrego 	if (err != 0)
179148c5f43SAlan Wright 		return (err);
18089dc44ceSjose borrego 
1811bc6aeeeSMatt Barden 	/* find snapshot node corresponding to cur_node */
1821bc6aeeeSMatt Barden 	err = smb_vss_lookup_node(sr, cur_node, fsrootvp,
1831bc6aeeeSMatt Barden 	    snapname, cur_node, vss_cur_node);
18489dc44ceSjose borrego 
185148c5f43SAlan Wright 	VN_RELE(fsrootvp);
1867f667e74Sjose borrego 
187148c5f43SAlan Wright 	return (err);
188148c5f43SAlan Wright }
18989dc44ceSjose borrego 
190148c5f43SAlan Wright /*
191148c5f43SAlan Wright  * Find snapshot node corresponding to 'node', and return it in
192148c5f43SAlan Wright  * 'vss_node', as follows:
193148c5f43SAlan Wright  * - find the path from fsrootvp to node, appending it to the
194148c5f43SAlan Wright  *   the snapshot path
195148c5f43SAlan Wright  * - lookup the vnode and smb_node (vss_node).
196148c5f43SAlan Wright  */
197148c5f43SAlan Wright static int
smb_vss_lookup_node(smb_request_t * sr,smb_node_t * node,vnode_t * fsrootvp,char * snapname,smb_node_t * dnode,smb_node_t ** vss_node)198148c5f43SAlan Wright smb_vss_lookup_node(smb_request_t *sr, smb_node_t *node, vnode_t *fsrootvp,
199a90cf9f2SGordon Ross     char *snapname, smb_node_t *dnode, smb_node_t **vss_node)
200148c5f43SAlan Wright {
201148c5f43SAlan Wright 	char *p, *path;
202148c5f43SAlan Wright 	int err, len;
203148c5f43SAlan Wright 	vnode_t *vp = NULL;
20489dc44ceSjose borrego 
205148c5f43SAlan Wright 	*vss_node = NULL;
20689dc44ceSjose borrego 
207148c5f43SAlan Wright 	path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
208148c5f43SAlan Wright 	(void) snprintf(path, MAXPATHLEN, ".zfs/snapshot/%s/", snapname);
209148c5f43SAlan Wright 	len = strlen(path);
210148c5f43SAlan Wright 	p = path + len;
21189dc44ceSjose borrego 
212148c5f43SAlan Wright 	err = smb_node_getpath(node, fsrootvp, p, MAXPATHLEN - len);
213148c5f43SAlan Wright 	if (err == 0) {
214148c5f43SAlan Wright 		vp = smb_lookuppathvptovp(sr, path, fsrootvp, fsrootvp);
21589dc44ceSjose borrego 		if (vp) {
2168622ec45SGordon Ross 			*vss_node = smb_node_lookup(sr, NULL, zone_kcred(),
217a90cf9f2SGordon Ross 			    vp, snapname, dnode, NULL);
2187f667e74Sjose borrego 			VN_RELE(vp);
21989dc44ceSjose borrego 		}
22089dc44ceSjose borrego 	}
22189dc44ceSjose borrego 
222148c5f43SAlan Wright 	kmem_free(path, MAXPATHLEN);
22389dc44ceSjose borrego 
224148c5f43SAlan Wright 	if (*vss_node != NULL)
225148c5f43SAlan Wright 		return (0);
226148c5f43SAlan Wright 
227148c5f43SAlan Wright 	return (err ? err : ENOENT);
22889dc44ceSjose borrego }
22989dc44ceSjose borrego 
230148c5f43SAlan Wright 
23189dc44ceSjose borrego static boolean_t
smb_vss_is_gmttoken(const char * s)23289dc44ceSjose borrego smb_vss_is_gmttoken(const char *s)
23389dc44ceSjose borrego {
23489dc44ceSjose borrego 	char *t = "@GMT-NNNN.NN.NN-NN.NN.NN";
23589dc44ceSjose borrego 	const char *str;
23689dc44ceSjose borrego 	char *template;
23789dc44ceSjose borrego 
23889dc44ceSjose borrego 	template = t;
23989dc44ceSjose borrego 	str = s;
24089dc44ceSjose borrego 
24189dc44ceSjose borrego 	while (*template) {
24289dc44ceSjose borrego 		if (*template == 'N') {
243bbf6f00cSJordan Brown 			if (!smb_isdigit(*str))
24489dc44ceSjose borrego 				return (B_FALSE);
24589dc44ceSjose borrego 		} else if (*template != *str) {
24689dc44ceSjose borrego 			return (B_FALSE);
24789dc44ceSjose borrego 		}
24889dc44ceSjose borrego 
24989dc44ceSjose borrego 		template++;
25089dc44ceSjose borrego 		str++;
25189dc44ceSjose borrego 	}
25289dc44ceSjose borrego 
25389dc44ceSjose borrego 	/* Make sure it is JUST the @GMT token */
25489dc44ceSjose borrego 	if ((*str == '\0') || (*str == '/'))
25589dc44ceSjose borrego 		return (B_TRUE);
25689dc44ceSjose borrego 
25789dc44ceSjose borrego 	return (B_FALSE);
25889dc44ceSjose borrego }
25989dc44ceSjose borrego 
26089dc44ceSjose borrego static const char *
smb_vss_find_gmttoken(const char * path)26189dc44ceSjose borrego smb_vss_find_gmttoken(const char *path)
26289dc44ceSjose borrego {
26389dc44ceSjose borrego 	const char *p;
26489dc44ceSjose borrego 
26589dc44ceSjose borrego 	p = path;
26689dc44ceSjose borrego 
26789dc44ceSjose borrego 	while (*p) {
268a90cf9f2SGordon Ross 		if (*p == '@' && smb_vss_is_gmttoken(p))
26989dc44ceSjose borrego 			return (p);
27089dc44ceSjose borrego 		p++;
27189dc44ceSjose borrego 	}
27289dc44ceSjose borrego 	return (NULL);
27389dc44ceSjose borrego }
27489dc44ceSjose borrego 
27589dc44ceSjose borrego static uint32_t
smb_vss_encode_gmttokens(smb_request_t * sr,smb_fsctl_t * fsctl,int32_t count,smb_gmttoken_response_t * snap_data)276a90cf9f2SGordon Ross smb_vss_encode_gmttokens(smb_request_t *sr, smb_fsctl_t *fsctl,
2779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States     int32_t count, smb_gmttoken_response_t *snap_data)
27889dc44ceSjose borrego {
27989dc44ceSjose borrego 	uint32_t i;
28089dc44ceSjose borrego 	uint32_t returned_count;
28189dc44ceSjose borrego 	uint32_t num_gmttokens;
28289dc44ceSjose borrego 	char **gmttokens;
283b1352070SAlan Wright 	uint32_t status = NT_STATUS_SUCCESS;
28489dc44ceSjose borrego 	uint32_t data_size;
28589dc44ceSjose borrego 
2869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	returned_count = snap_data->gtr_count;
2879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	num_gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_len;
2889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_val;
28989dc44ceSjose borrego 
290b1352070SAlan Wright 	if (returned_count > count)
291b1352070SAlan Wright 		status = NT_STATUS_BUFFER_TOO_SMALL;
29289dc44ceSjose borrego 
29389dc44ceSjose borrego 	data_size = returned_count * SMB_VSS_GMT_NET_SIZE(sr) +
29489dc44ceSjose borrego 	    smb_ascii_or_unicode_null_len(sr);
29589dc44ceSjose borrego 
296a90cf9f2SGordon Ross 	if (smb_mbc_encodef(fsctl->out_mbc, "lll", returned_count,
297b1352070SAlan Wright 	    num_gmttokens, data_size) != 0)
298b1352070SAlan Wright 		return (NT_STATUS_INVALID_PARAMETER);
29989dc44ceSjose borrego 
300b1352070SAlan Wright 	if (status == NT_STATUS_SUCCESS) {
30189dc44ceSjose borrego 		for (i = 0; i < num_gmttokens; i++) {
302a90cf9f2SGordon Ross 			if (smb_mbc_encodef(fsctl->out_mbc, "%u", sr,
303b1352070SAlan Wright 			    *gmttokens) != 0)
304b1352070SAlan Wright 				status = NT_STATUS_INVALID_PARAMETER;
30589dc44ceSjose borrego 			gmttokens++;
30689dc44ceSjose borrego 		}
307*a767d70fSGordon Ross 		// WPTS says there should be a final unicode null.
308*a767d70fSGordon Ross 		(void) smb_mbc_encodef(fsctl->out_mbc, "..");
30989dc44ceSjose borrego 	}
31089dc44ceSjose borrego 
311b1352070SAlan Wright 	return (status);
31289dc44ceSjose borrego }
31389dc44ceSjose borrego 
31489dc44ceSjose borrego /* This removes the first @GMT from the path */
31589dc44ceSjose borrego static void
smb_vss_remove_first_token_from_path(char * path)31689dc44ceSjose borrego smb_vss_remove_first_token_from_path(char *path)
31789dc44ceSjose borrego {
31889dc44ceSjose borrego 	boolean_t found;
31989dc44ceSjose borrego 	char *src, *dest;
32089dc44ceSjose borrego 
32189dc44ceSjose borrego 	src = path;
32289dc44ceSjose borrego 	dest = path;
32389dc44ceSjose borrego 
32489dc44ceSjose borrego 	found = B_FALSE;
32589dc44ceSjose borrego 
32689dc44ceSjose borrego 	while (*src != '\0') {
32789dc44ceSjose borrego 		if (!found && smb_vss_is_gmttoken(src)) {
32889dc44ceSjose borrego 			src += SMB_VSS_GMT_SIZE - 1;
32989dc44ceSjose borrego 			if (*src == '/')
33089dc44ceSjose borrego 				src += 1;
33189dc44ceSjose borrego 			found = B_TRUE;
33289dc44ceSjose borrego 			continue;
33389dc44ceSjose borrego 		}
33489dc44ceSjose borrego 		*dest = *src;
33589dc44ceSjose borrego 		src++;
33689dc44ceSjose borrego 		dest++;
33789dc44ceSjose borrego 	}
33889dc44ceSjose borrego 	*dest = *src;
33989dc44ceSjose borrego }
3409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
3429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * This returns the number of snapshots for the dataset
3439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * of the path provided.
3449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
3459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t
smb_vss_get_count(smb_tree_t * tree,char * resource_path)3468622ec45SGordon Ross smb_vss_get_count(smb_tree_t *tree, char *resource_path)
3479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	uint32_t	count = 0;
3499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	int		rc;
3509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_string_t	path;
3519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	path.buf = resource_path;
3539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3548622ec45SGordon Ross 	rc = smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_COUNT,
3559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    &path, smb_string_xdr, &count, xdr_uint32_t);
3569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (rc != 0)
3589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		count = 0;
3599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (count);
3619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
3629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
3649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * This takes a path for the root of the dataset and gets the counts of
3659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * snapshots for that dataset and the list of @GMT tokens (one for each
3669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * snapshot) up to the count provided.
3679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
3689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Call smb_vss_get_snapshots_free after to free up the data.
3699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
3709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
smb_vss_get_snapshots(smb_tree_t * tree,char * resource_path,uint32_t count,smb_gmttoken_response_t * gmttokens)3718622ec45SGordon Ross smb_vss_get_snapshots(smb_tree_t *tree, char *resource_path,
3728622ec45SGordon Ross     uint32_t count, smb_gmttoken_response_t *gmttokens)
3739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_gmttoken_query_t	request;
3759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	request.gtq_count = count;
3779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	request.gtq_path = resource_path;
3789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	bzero(gmttokens, sizeof (smb_gmttoken_response_t));
3799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3808622ec45SGordon Ross 	(void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_SNAPSHOTS,
3819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    &request, smb_gmttoken_query_xdr,
3829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    gmttokens, smb_gmttoken_response_xdr);
3839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
3849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
smb_vss_get_snapshots_free(smb_gmttoken_response_t * reply)3869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_vss_get_snapshots_free(smb_gmttoken_response_t *reply)
3879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	xdr_free(smb_gmttoken_response_xdr, (char *)reply);
3899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
3909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
3919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
3929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Returns the snapshot name for the @GMT token provided for the dataset
3939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * of the path.  If the snapshot cannot be found, a string with a NULL
3949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * is returned.
3959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
3969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
smb_vss_map_gmttoken(smb_tree_t * tree,char * path,char * gmttoken,time_t toktime,char * snapname)3978622ec45SGordon Ross smb_vss_map_gmttoken(smb_tree_t *tree, char *path, char *gmttoken,
3981bc6aeeeSMatt Barden     time_t toktime, char *snapname)
3999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
4009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_gmttoken_snapname_t	request;
4019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_string_t		result;
4029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
4039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	bzero(&result, sizeof (smb_string_t));
4049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	result.buf = snapname;
4059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
4069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	request.gts_path = path;
4079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	request.gts_gmttoken = gmttoken;
408a90cf9f2SGordon Ross 	request.gts_toktime = toktime;
4099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
4108622ec45SGordon Ross 	(void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_MAP_GMTTOKEN,
4119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    &request, smb_gmttoken_snapname_xdr,
4129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    &result, smb_string_xdr);
4139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
4141bc6aeeeSMatt Barden 
4151bc6aeeeSMatt Barden int
smb_vss_extract_gmttoken(char * buf,char * gmttoken)4161bc6aeeeSMatt Barden smb_vss_extract_gmttoken(char *buf, char *gmttoken)
4171bc6aeeeSMatt Barden {
4181bc6aeeeSMatt Barden 	const char *p;
4191bc6aeeeSMatt Barden 
4201bc6aeeeSMatt Barden 	/* get gmttoken from buf */
4211bc6aeeeSMatt Barden 	if ((p = smb_vss_find_gmttoken(buf)) == NULL)
4221bc6aeeeSMatt Barden 		return (ENOENT);
4231bc6aeeeSMatt Barden 
4241bc6aeeeSMatt Barden 	bcopy(p, gmttoken, SMB_VSS_GMT_SIZE);
4251bc6aeeeSMatt Barden 	gmttoken[SMB_VSS_GMT_SIZE - 1] = '\0';
4261bc6aeeeSMatt Barden 
4271bc6aeeeSMatt Barden 	smb_vss_remove_first_token_from_path(buf);
4281bc6aeeeSMatt Barden 
4291bc6aeeeSMatt Barden 	return (0);
4301bc6aeeeSMatt Barden }
431