|
root / base / usr / src / uts / common / fs / smbsrv / smb2_ofile.c
smb2_ofile.c C 111 lines 2.3 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
 */

/*
 * Helper functions for SMB2 open handles
 */

#include <smbsrv/smb2_kproto.h>

uint32_t
smb2_ofile_getattr(smb_request_t *sr, smb_ofile_t *of, smb_attr_t *ap)
{
	uint_t mask;
	int rc;

	mask = ap->sa_mask;
	bzero(ap, sizeof (*ap));
	ap->sa_mask = mask;

	switch (of->f_ftype) {
	case SMB_FTYPE_DISK:
	case SMB_FTYPE_PRINTER:
		rc = smb_node_getattr(sr, of->f_node, of->f_cr, of, ap);
		break;
	case SMB_FTYPE_BYTE_PIPE:
	case SMB_FTYPE_MESG_PIPE:
		rc = smb_opipe_getattr(of, ap);
		break;
	default:
		rc = ENOTTY;
		break;
	}
	if (rc)
		return (smb_errno2status(rc));

	return (0);
}

/*
 * Get the stuff needed by FileStandardInformation that was
 * not already obtained by smb2_ofile_getattr().
 * (qi_delete_on_close, qi_isdir)
 */
uint32_t
smb2_ofile_getstd(smb_ofile_t *of, smb_queryinfo_t *qi)
{
	smb_node_t *node;

	switch (of->f_ftype) {
	case SMB_FTYPE_DISK:
	case SMB_FTYPE_PRINTER:
		node = of->f_node;
		qi->qi_delete_on_close =
		    (node->flags & NODE_FLAGS_DELETE_ON_CLOSE) != 0;
		qi->qi_isdir = smb_node_is_dir(node);
		break;
	case SMB_FTYPE_BYTE_PIPE:
	case SMB_FTYPE_MESG_PIPE:
		qi->qi_delete_on_close = 1;
		qi->qi_isdir = 0;
		break;
	default:
		return (NT_STATUS_INVALID_DEVICE_REQUEST);
	}

	return (0);
}

/*
 * Get info for FileNameInformation, FileAlternateNameInformation.
 * (qi_name, qi_shortname)
 */
uint32_t
smb2_ofile_getname(smb_ofile_t *of, smb_queryinfo_t *qi)
{
	int rc;

	switch (of->f_ftype) {
	case SMB_FTYPE_DISK:
	case SMB_FTYPE_PRINTER:
		rc = smb_node_getshrpath(of->f_node, of->f_tree,
		    qi->qi_name, MAXPATHLEN);
		break;
	case SMB_FTYPE_BYTE_PIPE:
	case SMB_FTYPE_MESG_PIPE:
		rc = smb_opipe_getname(of, qi->qi_name, MAXPATHLEN);
		break;
	default:
		rc = ENOTTY;
		break;
	}
	if (rc)
		return (smb_errno2status(rc));
	qi->qi_namelen = smb_wcequiv_strlen(qi->qi_name);

	return (0);

}