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 /*
22*8622ec45SGordon Ross * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23148c5f43SAlan Wright * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2489dc44ceSjose borrego */
2589dc44ceSjose borrego
2689dc44ceSjose borrego /*
2789dc44ceSjose borrego * Volume Copy Shadow Services (VSS) provides a way for users to
2889dc44ceSjose borrego * restore/recover deleted files/directories.
2989dc44ceSjose borrego * For the server to support VSS for Microsoft clients, there is
3089dc44ceSjose borrego * two basic functions that need to be implemented.
3189dc44ceSjose borrego * The first is to intercept the NT_TRANSACT_IOCTL command with
3289dc44ceSjose borrego * the function code of FSCTL_SRV_ENUMERATE_SNAPSHOTS (0x00144064).
3389dc44ceSjose borrego * This is to report the count or the count and list of snapshots
3489dc44ceSjose borrego * for that share.
3589dc44ceSjose borrego * The second function need to trap commands with the
3689dc44ceSjose borrego * SMB_FLAGS2_REPARSE_PATH bit set in the smb header. This bit
3789dc44ceSjose borrego * means that there is a @GMT token in path that needs to be
3889dc44ceSjose borrego * processed. The @GMT token means to process this command, but
3989dc44ceSjose borrego * in the snapshot.
4089dc44ceSjose borrego */
4189dc44ceSjose borrego
42bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
43bbf6f00cSJordan Brown #include <smbsrv/string.h>
4489dc44ceSjose borrego #include <smbsrv/winioctl.h>
459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_door.h>
4689dc44ceSjose borrego
4789dc44ceSjose borrego /* Size of the token on the wire due to encoding */
4889dc44ceSjose borrego #define SMB_VSS_GMT_NET_SIZE(sr) (smb_ascii_or_unicode_null_len(sr) * \
4989dc44ceSjose borrego SMB_VSS_GMT_SIZE)
5089dc44ceSjose borrego
5189dc44ceSjose borrego #define SMB_VSS_COUNT_SIZE 16
5289dc44ceSjose borrego
539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_vss_is_gmttoken(const char *);
549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static const char *smb_vss_find_gmttoken(const char *);
559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_vss_encode_gmttokens(smb_request_t *, smb_xa_t *,
569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int32_t, smb_gmttoken_response_t *);
579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_vss_remove_first_token_from_path(char *);
589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
59*8622ec45SGordon Ross static uint32_t smb_vss_get_count(smb_tree_t *, char *);
60*8622ec45SGordon Ross static void smb_vss_map_gmttoken(smb_tree_t *, char *, char *, char *);
61*8622ec45SGordon Ross static void smb_vss_get_snapshots(smb_tree_t *, char *,
62*8622ec45SGordon Ross uint32_t, smb_gmttoken_response_t *);
639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_vss_get_snapshots_free(smb_gmttoken_response_t *);
64148c5f43SAlan Wright static int smb_vss_lookup_node(smb_request_t *sr, smb_node_t *, vnode_t *,
65148c5f43SAlan Wright char *, smb_node_t *, char *, smb_node_t **);
6689dc44ceSjose borrego
6789dc44ceSjose borrego /*
6889dc44ceSjose borrego * This is to respond to the nt_transact_ioctl to either respond with the
6989dc44ceSjose borrego * number of snapshots, or to respond with the list. It needs to be sorted
7089dc44ceSjose borrego * before the reply. If the the max data bytes to return is
7189dc44ceSjose borrego * SMB_VSS_COUNT_SIZE, then all that is requested is the count, otherwise
7289dc44ceSjose borrego * return the count and the list of @GMT tokens (one token for each
7389dc44ceSjose borrego * snapshot).
7489dc44ceSjose borrego */
7589dc44ceSjose borrego uint32_t
smb_vss_ioctl_enumerate_snaps(smb_request_t * sr,smb_xa_t * xa)7689dc44ceSjose borrego smb_vss_ioctl_enumerate_snaps(smb_request_t *sr, smb_xa_t *xa)
7789dc44ceSjose borrego {
7889dc44ceSjose borrego uint32_t count = 0;
7989dc44ceSjose borrego char *root_path;
80b1352070SAlan Wright uint32_t status = NT_STATUS_SUCCESS;
819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_node_t *tnode;
829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_gmttoken_response_t gmttokens;
839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(sr->tid_tree);
859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(sr->tid_tree->t_snode);
8689dc44ceSjose borrego
87b1352070SAlan Wright if (xa->smb_mdrcnt < SMB_VSS_COUNT_SIZE)
88b1352070SAlan Wright return (NT_STATUS_INVALID_PARAMETER);
8989dc44ceSjose borrego
909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States tnode = sr->tid_tree->t_snode;
9189dc44ceSjose borrego root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_node_getmntpath(tnode, root_path, MAXPATHLEN) != 0)
93b1352070SAlan Wright return (NT_STATUS_INVALID_PARAMETER);
9489dc44ceSjose borrego
9589dc44ceSjose borrego if (xa->smb_mdrcnt == SMB_VSS_COUNT_SIZE) {
96*8622ec45SGordon Ross count = smb_vss_get_count(sr->tid_tree, root_path);
9789dc44ceSjose borrego if (smb_mbc_encodef(&xa->rep_data_mb, "lllw", count, 0,
9889dc44ceSjose borrego (count * SMB_VSS_GMT_NET_SIZE(sr) +
9989dc44ceSjose borrego smb_ascii_or_unicode_null_len(sr)), 0) != 0) {
100b1352070SAlan Wright status = NT_STATUS_INVALID_PARAMETER;
10189dc44ceSjose borrego }
10289dc44ceSjose borrego } else {
10389dc44ceSjose borrego count = xa->smb_mdrcnt / SMB_VSS_GMT_NET_SIZE(sr);
10489dc44ceSjose borrego
105*8622ec45SGordon Ross smb_vss_get_snapshots(sr->tid_tree, root_path,
106*8622ec45SGordon Ross count, &gmttokens);
10789dc44ceSjose borrego
108b1352070SAlan Wright status = smb_vss_encode_gmttokens(sr, xa, count, &gmttokens);
10989dc44ceSjose borrego
1109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_vss_get_snapshots_free(&gmttokens);
11189dc44ceSjose borrego }
11289dc44ceSjose borrego
11389dc44ceSjose borrego kmem_free(root_path, MAXPATHLEN);
114b1352070SAlan Wright return (status);
11589dc44ceSjose borrego }
11689dc44ceSjose borrego
11789dc44ceSjose borrego /*
11889dc44ceSjose borrego * sr - the request info, used to find root of dataset,
11989dc44ceSjose borrego * unicode or ascii, where the share is rooted in the
12089dc44ceSjose borrego * dataset
12189dc44ceSjose borrego * root_node - root of the share
12289dc44ceSjose borrego * cur_node - where in the share for the command
12389dc44ceSjose borrego * buf - is the path for the command to be processed
12489dc44ceSjose borrego * returned without @GMT if processed
12589dc44ceSjose borrego * vss_cur_node - returned value for the snapshot version
12689dc44ceSjose borrego * of the cur_node
12789dc44ceSjose borrego * vss_root_node - returned value for the snapshot version
12889dc44ceSjose borrego * of the root_node
12989dc44ceSjose borrego *
13089dc44ceSjose borrego * This routine is the processing for handling the
13189dc44ceSjose borrego * SMB_FLAGS2_REPARSE_PATH bit being set in the smb header.
13289dc44ceSjose borrego *
13389dc44ceSjose borrego * By using the cur_node passed in, a new node is found or
13489dc44ceSjose borrego * created that is the same place in the directory tree, but
13589dc44ceSjose borrego * in the snapshot. We also use root_node to do the same for
13689dc44ceSjose borrego * the root.
137148c5f43SAlan Wright * Once the new smb node is found, the path is modified by
13889dc44ceSjose borrego * removing the @GMT token from the path in the buf.
13989dc44ceSjose borrego */
14089dc44ceSjose borrego int
smb_vss_lookup_nodes(smb_request_t * sr,smb_node_t * root_node,smb_node_t * cur_node,char * buf,smb_node_t ** vss_cur_node,smb_node_t ** vss_root_node)14189dc44ceSjose borrego smb_vss_lookup_nodes(smb_request_t *sr, smb_node_t *root_node,
14289dc44ceSjose borrego smb_node_t *cur_node, char *buf, smb_node_t **vss_cur_node,
14389dc44ceSjose borrego smb_node_t **vss_root_node)
14489dc44ceSjose borrego {
14589dc44ceSjose borrego const char *p;
1469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_node_t *tnode;
147148c5f43SAlan Wright char *snapname, *path;
14889dc44ceSjose borrego char gmttoken[SMB_VSS_GMT_SIZE];
149148c5f43SAlan Wright vnode_t *fsrootvp = NULL;
15089dc44ceSjose borrego int err = 0;
15189dc44ceSjose borrego
15289dc44ceSjose borrego if (sr->tid_tree == NULL)
15389dc44ceSjose borrego return (ESTALE);
15489dc44ceSjose borrego
155148c5f43SAlan Wright tnode = sr->tid_tree->t_snode;
15689dc44ceSjose borrego
157148c5f43SAlan Wright ASSERT(tnode);
158148c5f43SAlan Wright ASSERT(tnode->vp);
159148c5f43SAlan Wright ASSERT(tnode->vp->v_vfsp);
160148c5f43SAlan Wright
161148c5f43SAlan Wright /* get gmttoken from buf and find corresponding snapshot name */
1626e3e9d9cSafshin salek ardakani - Sun Microsystems - Irvine United States if ((p = smb_vss_find_gmttoken(buf)) == NULL)
16389dc44ceSjose borrego return (ENOENT);
16489dc44ceSjose borrego
16589dc44ceSjose borrego bcopy(p, gmttoken, SMB_VSS_GMT_SIZE);
16689dc44ceSjose borrego gmttoken[SMB_VSS_GMT_SIZE - 1] = '\0';
16789dc44ceSjose borrego
168148c5f43SAlan Wright path = smb_srm_alloc(sr, MAXPATHLEN);
169148c5f43SAlan Wright snapname = smb_srm_alloc(sr, MAXPATHLEN);
170148c5f43SAlan Wright
171148c5f43SAlan Wright err = smb_node_getmntpath(tnode, path, MAXPATHLEN);
172148c5f43SAlan Wright if (err != 0)
173148c5f43SAlan Wright return (err);
174148c5f43SAlan Wright
175148c5f43SAlan Wright *snapname = '\0';
176*8622ec45SGordon Ross smb_vss_map_gmttoken(sr->tid_tree, path, gmttoken, snapname);
177148c5f43SAlan Wright if (!*snapname)
178148c5f43SAlan Wright return (ENOENT);
179148c5f43SAlan Wright
180148c5f43SAlan Wright /* find snapshot nodes */
1819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States err = VFS_ROOT(tnode->vp->v_vfsp, &fsrootvp);
1826e3e9d9cSafshin salek ardakani - Sun Microsystems - Irvine United States if (err != 0)
1836e3e9d9cSafshin salek ardakani - Sun Microsystems - Irvine United States return (err);
18489dc44ceSjose borrego
185148c5f43SAlan Wright /* find snapshot node corresponding to root_node */
186148c5f43SAlan Wright err = smb_vss_lookup_node(sr, root_node, fsrootvp,
187148c5f43SAlan Wright snapname, cur_node, gmttoken, vss_root_node);
188148c5f43SAlan Wright if (err == 0) {
189148c5f43SAlan Wright /* find snapshot node corresponding to cur_node */
190148c5f43SAlan Wright err = smb_vss_lookup_node(sr, cur_node, fsrootvp,
191148c5f43SAlan Wright snapname, cur_node, gmttoken, vss_cur_node);
1926e3e9d9cSafshin salek ardakani - Sun Microsystems - Irvine United States if (err != 0)
193148c5f43SAlan Wright smb_node_release(*vss_root_node);
19489dc44ceSjose borrego }
19589dc44ceSjose borrego
19689dc44ceSjose borrego VN_RELE(fsrootvp);
19789dc44ceSjose borrego
198148c5f43SAlan Wright smb_vss_remove_first_token_from_path(buf);
19989dc44ceSjose borrego return (err);
20089dc44ceSjose borrego }
20189dc44ceSjose borrego
202148c5f43SAlan Wright /*
203148c5f43SAlan Wright * Find snapshot node corresponding to 'node', and return it in
204148c5f43SAlan Wright * 'vss_node', as follows:
205148c5f43SAlan Wright * - find the path from fsrootvp to node, appending it to the
206148c5f43SAlan Wright * the snapshot path
207148c5f43SAlan Wright * - lookup the vnode and smb_node (vss_node).
208148c5f43SAlan Wright */
209148c5f43SAlan Wright static int
smb_vss_lookup_node(smb_request_t * sr,smb_node_t * node,vnode_t * fsrootvp,char * snapname,smb_node_t * dnode,char * odname,smb_node_t ** vss_node)210148c5f43SAlan Wright smb_vss_lookup_node(smb_request_t *sr, smb_node_t *node, vnode_t *fsrootvp,
211148c5f43SAlan Wright char *snapname, smb_node_t *dnode, char *odname, smb_node_t **vss_node)
212148c5f43SAlan Wright {
213148c5f43SAlan Wright char *p, *path;
214148c5f43SAlan Wright int err, len;
215148c5f43SAlan Wright vnode_t *vp = NULL;
216148c5f43SAlan Wright
217148c5f43SAlan Wright *vss_node = NULL;
218148c5f43SAlan Wright
219148c5f43SAlan Wright path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
220148c5f43SAlan Wright (void) snprintf(path, MAXPATHLEN, ".zfs/snapshot/%s/", snapname);
221148c5f43SAlan Wright len = strlen(path);
222148c5f43SAlan Wright p = path + len;
223148c5f43SAlan Wright
224148c5f43SAlan Wright err = smb_node_getpath(node, fsrootvp, p, MAXPATHLEN - len);
225148c5f43SAlan Wright if (err == 0) {
226148c5f43SAlan Wright vp = smb_lookuppathvptovp(sr, path, fsrootvp, fsrootvp);
227148c5f43SAlan Wright if (vp) {
228*8622ec45SGordon Ross *vss_node = smb_node_lookup(sr, NULL, zone_kcred(),
229*8622ec45SGordon Ross vp, odname, dnode, NULL);
230148c5f43SAlan Wright VN_RELE(vp);
231148c5f43SAlan Wright }
232148c5f43SAlan Wright }
233148c5f43SAlan Wright
234148c5f43SAlan Wright kmem_free(path, MAXPATHLEN);
235148c5f43SAlan Wright
236148c5f43SAlan Wright if (*vss_node != NULL)
237148c5f43SAlan Wright return (0);
238148c5f43SAlan Wright
239148c5f43SAlan Wright return (err ? err : ENOENT);
240148c5f43SAlan Wright }
241148c5f43SAlan Wright
242148c5f43SAlan Wright
24389dc44ceSjose borrego static boolean_t
smb_vss_is_gmttoken(const char * s)24489dc44ceSjose borrego smb_vss_is_gmttoken(const char *s)
24589dc44ceSjose borrego {
24689dc44ceSjose borrego char *t = "@GMT-NNNN.NN.NN-NN.NN.NN";
24789dc44ceSjose borrego const char *str;
24889dc44ceSjose borrego char *template;
24989dc44ceSjose borrego
25089dc44ceSjose borrego template = t;
25189dc44ceSjose borrego str = s;
25289dc44ceSjose borrego
25389dc44ceSjose borrego while (*template) {
25489dc44ceSjose borrego if (*template == 'N') {
255bbf6f00cSJordan Brown if (!smb_isdigit(*str))
25689dc44ceSjose borrego return (B_FALSE);
25789dc44ceSjose borrego } else if (*template != *str) {
25889dc44ceSjose borrego return (B_FALSE);
25989dc44ceSjose borrego }
26089dc44ceSjose borrego
26189dc44ceSjose borrego template++;
26289dc44ceSjose borrego str++;
26389dc44ceSjose borrego }
26489dc44ceSjose borrego
26589dc44ceSjose borrego /* Make sure it is JUST the @GMT token */
26689dc44ceSjose borrego if ((*str == '\0') || (*str == '/'))
26789dc44ceSjose borrego return (B_TRUE);
26889dc44ceSjose borrego
26989dc44ceSjose borrego return (B_FALSE);
27089dc44ceSjose borrego }
27189dc44ceSjose borrego
27289dc44ceSjose borrego static const char *
smb_vss_find_gmttoken(const char * path)27389dc44ceSjose borrego smb_vss_find_gmttoken(const char *path)
27489dc44ceSjose borrego {
27589dc44ceSjose borrego const char *p;
27689dc44ceSjose borrego
27789dc44ceSjose borrego p = path;
27889dc44ceSjose borrego
27989dc44ceSjose borrego while (*p) {
28089dc44ceSjose borrego if (smb_vss_is_gmttoken(p))
28189dc44ceSjose borrego return (p);
28289dc44ceSjose borrego p++;
28389dc44ceSjose borrego }
28489dc44ceSjose borrego return (NULL);
28589dc44ceSjose borrego }
28689dc44ceSjose borrego
28789dc44ceSjose borrego static uint32_t
smb_vss_encode_gmttokens(smb_request_t * sr,smb_xa_t * xa,int32_t count,smb_gmttoken_response_t * snap_data)28889dc44ceSjose borrego smb_vss_encode_gmttokens(smb_request_t *sr, smb_xa_t *xa,
2899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int32_t count, smb_gmttoken_response_t *snap_data)
29089dc44ceSjose borrego {
29189dc44ceSjose borrego uint32_t i;
29289dc44ceSjose borrego uint32_t returned_count;
29389dc44ceSjose borrego uint32_t num_gmttokens;
29489dc44ceSjose borrego char **gmttokens;
295b1352070SAlan Wright uint32_t status = NT_STATUS_SUCCESS;
29689dc44ceSjose borrego uint32_t data_size;
29789dc44ceSjose borrego
2989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States returned_count = snap_data->gtr_count;
2999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States num_gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_len;
3009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_val;
30189dc44ceSjose borrego
302b1352070SAlan Wright if (returned_count > count)
303b1352070SAlan Wright status = NT_STATUS_BUFFER_TOO_SMALL;
30489dc44ceSjose borrego
30589dc44ceSjose borrego data_size = returned_count * SMB_VSS_GMT_NET_SIZE(sr) +
30689dc44ceSjose borrego smb_ascii_or_unicode_null_len(sr);
30789dc44ceSjose borrego
30889dc44ceSjose borrego if (smb_mbc_encodef(&xa->rep_data_mb, "lll", returned_count,
309b1352070SAlan Wright num_gmttokens, data_size) != 0)
310b1352070SAlan Wright return (NT_STATUS_INVALID_PARAMETER);
31189dc44ceSjose borrego
312b1352070SAlan Wright if (status == NT_STATUS_SUCCESS) {
31389dc44ceSjose borrego for (i = 0; i < num_gmttokens; i++) {
31489dc44ceSjose borrego if (smb_mbc_encodef(&xa->rep_data_mb, "%u", sr,
315b1352070SAlan Wright *gmttokens) != 0)
316b1352070SAlan Wright status = NT_STATUS_INVALID_PARAMETER;
31789dc44ceSjose borrego gmttokens++;
31889dc44ceSjose borrego }
31989dc44ceSjose borrego }
32089dc44ceSjose borrego
321b1352070SAlan Wright return (status);
32289dc44ceSjose borrego }
32389dc44ceSjose borrego
32489dc44ceSjose borrego /* This removes the first @GMT from the path */
32589dc44ceSjose borrego static void
smb_vss_remove_first_token_from_path(char * path)32689dc44ceSjose borrego smb_vss_remove_first_token_from_path(char *path)
32789dc44ceSjose borrego {
32889dc44ceSjose borrego boolean_t found;
32989dc44ceSjose borrego char *src, *dest;
33089dc44ceSjose borrego
33189dc44ceSjose borrego src = path;
33289dc44ceSjose borrego dest = path;
33389dc44ceSjose borrego
33489dc44ceSjose borrego found = B_FALSE;
33589dc44ceSjose borrego
33689dc44ceSjose borrego while (*src != '\0') {
33789dc44ceSjose borrego if (!found && smb_vss_is_gmttoken(src)) {
33889dc44ceSjose borrego src += SMB_VSS_GMT_SIZE - 1;
33989dc44ceSjose borrego if (*src == '/')
34089dc44ceSjose borrego src += 1;
34189dc44ceSjose borrego found = B_TRUE;
34289dc44ceSjose borrego continue;
34389dc44ceSjose borrego }
34489dc44ceSjose borrego *dest = *src;
34589dc44ceSjose borrego src++;
34689dc44ceSjose borrego dest++;
34789dc44ceSjose borrego }
34889dc44ceSjose borrego *dest = *src;
34989dc44ceSjose borrego }
3509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
3529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * This returns the number of snapshots for the dataset
3539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * of the path provided.
3549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */
3559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t
smb_vss_get_count(smb_tree_t * tree,char * resource_path)356*8622ec45SGordon Ross smb_vss_get_count(smb_tree_t *tree, char *resource_path)
3579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t count = 0;
3599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int rc;
3609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_string_t path;
3619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States path.buf = resource_path;
3639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
364*8622ec45SGordon Ross rc = smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_COUNT,
3659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &path, smb_string_xdr, &count, xdr_uint32_t);
3669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (rc != 0)
3689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States count = 0;
3699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (count);
3719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
3729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
3749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * This takes a path for the root of the dataset and gets the counts of
3759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * snapshots for that dataset and the list of @GMT tokens (one for each
3769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * snapshot) up to the count provided.
3779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States *
3789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Call smb_vss_get_snapshots_free after to free up the data.
3799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */
3809fb67ea3Safshin 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)381*8622ec45SGordon Ross smb_vss_get_snapshots(smb_tree_t *tree, char *resource_path,
382*8622ec45SGordon Ross uint32_t count, smb_gmttoken_response_t *gmttokens)
3839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_gmttoken_query_t request;
3859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States request.gtq_count = count;
3879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States request.gtq_path = resource_path;
3889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bzero(gmttokens, sizeof (smb_gmttoken_response_t));
3899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
390*8622ec45SGordon Ross (void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_SNAPSHOTS,
3919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &request, smb_gmttoken_query_xdr,
3929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States gmttokens, smb_gmttoken_response_xdr);
3939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
3949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
3959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
smb_vss_get_snapshots_free(smb_gmttoken_response_t * reply)3969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_vss_get_snapshots_free(smb_gmttoken_response_t *reply)
3979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States xdr_free(smb_gmttoken_response_xdr, (char *)reply);
3999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
4009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
4019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
4029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Returns the snapshot name for the @GMT token provided for the dataset
4039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * of the path. If the snapshot cannot be found, a string with a NULL
4049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * is returned.
4059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */
4069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
smb_vss_map_gmttoken(smb_tree_t * tree,char * path,char * gmttoken,char * snapname)407*8622ec45SGordon Ross smb_vss_map_gmttoken(smb_tree_t *tree, char *path, char *gmttoken,
408*8622ec45SGordon Ross char *snapname)
4099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
4109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_gmttoken_snapname_t request;
4119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_string_t result;
4129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
4139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bzero(&result, sizeof (smb_string_t));
4149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States result.buf = snapname;
4159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
4169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States request.gts_path = path;
4179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States request.gts_gmttoken = gmttoken;
4189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
419*8622ec45SGordon Ross (void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_MAP_GMTTOKEN,
4209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &request, smb_gmttoken_snapname_xdr,
4219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &result, smb_string_xdr);
4229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
423