summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/fs/smbsrv/smb2_qinfo_file.c
blob: 6f70a8d74b5c1b153b00115145e1422ebf0e464c (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
/*
 * 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 2019 Nexenta by DDN, Inc. All rights reserved.
 * Copyright 2022 RackTop Systems, Inc.
 */

/*
 * Dispatch function for SMB2_QUERY_INFO
 *
 * [MS-FSCC 2.4] If a file system does not support ...
 * an Information Classs, NT_STATUS_INVALID_PARAMETER...
 */

#include <smbsrv/smb2_kproto.h>
#include <smbsrv/smb_fsops.h>
#include <smbsrv/ntifs.h>

static uint32_t smb2_qif_all(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_basic(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_standard(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_internal(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_ea_size(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_access(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_name(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_normalized_name(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_position(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_full_ea(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_mode(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_alignment(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_all(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_altname(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_stream(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_pipe(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_pipe_lcl(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_pipe_rem(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_compr(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_opens(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_tags(smb_request_t *, smb_queryinfo_t *);
static uint32_t smb2_qif_id_info(smb_request_t *, smb_queryinfo_t *);


uint32_t
smb2_qinfo_file(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_ofile_t *of = sr->fid_ofile;
	uint_t mask = 0;
	boolean_t getstd = B_FALSE;
	boolean_t getname = B_FALSE;
	uint32_t status;

	/*
	 * Which attributes do we need from the FS?
	 */
	switch (qi->qi_InfoClass) {
	case FileBasicInformation:
		mask = SMB_AT_BASIC;
		break;
	case FileStandardInformation:
		mask = SMB_AT_STANDARD;
		getstd = B_TRUE;
		break;
	case FileInternalInformation:
		mask = SMB_AT_NODEID;
		break;
	case FileAllInformation:
		mask = SMB_AT_ALL;
		getstd = B_TRUE;
		if (sr->session->dialect < SMB_VERS_3_11) {
			/* See smb2_qif_all() */
			getname = B_TRUE;
		}
		break;

	case FileNameInformation:
	case FileNormalizedNameInformation:
		getname = B_TRUE;
		break;

	case FileAlternateNameInformation:
		mask = SMB_AT_NODEID;
		getname = B_TRUE;
		break;

	case FileStreamInformation:
		mask = SMB_AT_STANDARD;
		getstd = B_TRUE;
		break;

	case FileCompressionInformation:
		mask = SMB_AT_SIZE | SMB_AT_ALLOCSZ;
		break;

	case FileNetworkOpenInformation:
		mask = SMB_AT_BASIC | SMB_AT_STANDARD;
		break;

	case FileIdInformation:
		mask = SMB_AT_NODEID;
		break;

	default:
		break;
	}

	qi->qi_attr.sa_mask = mask;
	qi->qi_node = of->f_node;
	if (mask & SMB_AT_ALL) {
		status = smb2_ofile_getattr(sr, of, &qi->qi_attr);
		if (status)
			return (status);
	}
	if (getstd) {
		status = smb2_ofile_getstd(of, qi);
		if (status)
			return (status);
	}
	if (getname) {
		status = smb2_ofile_getname(of, qi);
		if (status)
			return (status);
	}

	switch (qi->qi_InfoClass) {
	case FileBasicInformation:
		status = smb2_qif_basic(sr, qi);
		break;
	case FileStandardInformation:
		status = smb2_qif_standard(sr, qi);
		break;
	case FileInternalInformation:
		status = smb2_qif_internal(sr, qi);
		break;
	case FileEaInformation:
		status = smb2_qif_ea_size(sr, qi);
		break;
	case FileAccessInformation:
		status = smb2_qif_access(sr, qi);
		break;
	case FileNameInformation:
		status = smb2_qif_name(sr, qi);
		break;
	case FileNormalizedNameInformation:
		status = smb2_qif_normalized_name(sr, qi);
		break;
	case FilePositionInformation:
		status = smb2_qif_position(sr, qi);
		break;
	case FileFullEaInformation:
		status = smb2_qif_full_ea(sr, qi);
		break;
	case FileModeInformation:
		status = smb2_qif_mode(sr, qi);
		break;
	case FileAlignmentInformation:
		status = smb2_qif_alignment(sr, qi);
		break;
	case FileAllInformation:
		status = smb2_qif_all(sr, qi);
		break;
	case FileAlternateNameInformation:
		status = smb2_qif_altname(sr, qi);
		break;
	case FileStreamInformation:
		status = smb2_qif_stream(sr, qi);
		break;
	case FilePipeInformation:
		status = smb2_qif_pipe(sr, qi);
		break;
	case FilePipeLocalInformation:
		status = smb2_qif_pipe_lcl(sr, qi);
		break;
	case FilePipeRemoteInformation:
		status = smb2_qif_pipe_rem(sr, qi);
		break;
	case FileCompressionInformation:
		status = smb2_qif_compr(sr, qi);
		break;
	case FileNetworkOpenInformation:
		status = smb2_qif_opens(sr, qi);
		break;
	case FileAttributeTagInformation:
		status = smb2_qif_tags(sr, qi);
		break;
	case FileIdInformation:
		status = smb2_qif_id_info(sr, qi);
		break;
	default:
		status = NT_STATUS_INVALID_INFO_CLASS;
		break;
	}

	return (status);
}

/*
 * FileAllInformation
 *
 * This returns a concatenation of:
 *	FileBasicInformation
 *	FileStandardInformation
 *	FileInternalInformation
 *	FileEaInformation
 *	FilePositionInformation
 *	FileModeInformation
 *	FileAlignmentInformation
 *	FileNameInformation
 *
 * Note: FileNameInformation is all zero on Win2016 and later.
 */
static uint32_t
smb2_qif_all(smb_request_t *sr, smb_queryinfo_t *qi)
{
	uint32_t status;

	status = smb2_qif_basic(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_standard(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_internal(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_ea_size(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_position(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_mode(sr, qi);
	if (status)
		return (status);
	status = smb2_qif_alignment(sr, qi);
	if (status)
		return (status);

	/*
	 * MS-SMB2 3.3.5.20.1 says (in a windows behavior note) that
	 * 2012R2 and older fill in the FileNameInformation.
	 * We could let this depend on sr->sr_cfg->skc_version
	 * but doing it based on dialect is a lot easier and
	 * has nearly the same effect.
	 */
	if (sr->session->dialect < SMB_VERS_3_11) {
		/* Win2012r2 and earlier fill it in. (SMB 3.0) */
		status = smb2_qif_name(sr, qi);
	} else {
		/* Win2016 and later just put zeros (SMB 3.11) */
		int rc = smb_mbc_encodef(&sr->raw_data, "10.");
		status = (rc == 0) ? 0 : NT_STATUS_BUFFER_OVERFLOW;
	}

	return (status);
}

/*
 * FileBasicInformation
 * See also:
 *	case SMB_QUERY_FILE_BASIC_INFO:
 *	case SMB_FILE_BASIC_INFORMATION:
 */
static uint32_t
smb2_qif_basic(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	int rc;

	ASSERT((sa->sa_mask & SMB_AT_BASIC) == SMB_AT_BASIC);

	rc = smb_mbc_encodef(
	    &sr->raw_data, "TTTTll",
	    &sa->sa_crtime,		/* T */
	    &sa->sa_vattr.va_atime,	/* T */
	    &sa->sa_vattr.va_mtime,	/* T */
	    &sa->sa_vattr.va_ctime,	/* T */
	    sa->sa_dosattr,		/* l */
	    0); /* reserved */		/* l */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileStandardInformation
 * See also:
 *	SMB_QUERY_FILE_STANDARD_INFO
 *	SMB_FILE_STANDARD_INFORMATION
 */
static uint32_t
smb2_qif_standard(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	int rc;

	ASSERT((sa->sa_mask & SMB_AT_STANDARD) == SMB_AT_STANDARD);

	rc = smb_mbc_encodef(
	    &sr->raw_data, "qqlbbw",
	    sa->sa_allocsz,		/* q */
	    sa->sa_vattr.va_size,	/* q */
	    sa->sa_vattr.va_nlink,	/* l */
	    qi->qi_delete_on_close,	/* b */
	    qi->qi_isdir,		/* b */
	    0); /* reserved */		/* w */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileInternalInformation
 * See also:
 *	SMB_FILE_INTERNAL_INFORMATION
 */
static uint32_t
smb2_qif_internal(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	u_longlong_t nodeid;
	int rc;

	ASSERT((sa->sa_mask & SMB_AT_NODEID) == SMB_AT_NODEID);
	nodeid = sa->sa_vattr.va_nodeid;

	if (smb2_aapl_use_file_ids == 0 &&
	    (sr->session->s_flags & SMB_SSN_AAPL_CCEXT) != 0)
		nodeid = 0;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "q",
	    nodeid);	/* q */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileEaInformation
 * See also:
 *	SMB_QUERY_FILE_EA_INFO
 *	SMB_FILE_EA_INFORMATION
 */
static uint32_t
smb2_qif_ea_size(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	int rc;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "l", 0);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileFullEaInformation
 * We could put EAs in a named stream...
 */
/* ARGSUSED */
static uint32_t
smb2_qif_full_ea(smb_request_t *sr, smb_queryinfo_t *qi)
{
	return (NT_STATUS_NO_EAS_ON_FILE);
}

/*
 * FileAccessInformation
 */
static uint32_t
smb2_qif_access(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	smb_ofile_t *of = sr->fid_ofile;
	int rc;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "l",
	    of->f_granted_access);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileNameInformation
 * See also:
 *	SMB_QUERY_FILE_NAME_INFO
 *	SMB_FILE_NAME_INFORMATION
 */
static uint32_t
smb2_qif_name(smb_request_t *sr, smb_queryinfo_t *qi)
{
	char *name;
	uint32_t nlen;
	int rc;

	/* SMB2 leaves off the leading / */
	nlen = qi->qi_namelen;
	name = qi->qi_name;
	if (qi->qi_name[0] == '\\') {
		name++;
		nlen -= 2;
	}

	rc = smb_mbc_encodef(
	    &sr->raw_data, "llU",
	    0, /* FileIndex	 (l) */
	    nlen,	/* l */
	    name);	/* U */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileNormalizedNameInformation
 */
static uint32_t
smb2_qif_normalized_name(smb_request_t *sr, smb_queryinfo_t *qi)
{
	char *name;
	uint32_t nlen;
	int rc;

	/* SMB2 leaves off the leading / */
	nlen = qi->qi_namelen;
	name = qi->qi_name;
	if (qi->qi_name[0] == '\\') {
		name++;
		nlen -= 2;
	}

	rc = smb_mbc_encodef(
	    &sr->raw_data, "lU",
	    nlen,	/* l */
	    name);	/* U */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FilePositionInformation
 */
static uint32_t
smb2_qif_position(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	smb_ofile_t *of = sr->fid_ofile;
	uint64_t pos;
	int rc;

	mutex_enter(&of->f_mutex);
	pos = of->f_seek_pos;
	mutex_exit(&of->f_mutex);

	rc = smb_mbc_encodef(
	    &sr->raw_data, "q", pos);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileModeInformation [MS-FSA 2.4.24]
 */
static uint32_t
smb2_qif_mode(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	smb_ofile_t *of = sr->fid_ofile;
	uint32_t mode;
	int rc;

	/*
	 * See MS-FSA description of Open.Mode
	 * For now, we have these in...
	 */
	mode = of->f_create_options &
	    (FILE_WRITE_THROUGH | FILE_SEQUENTIAL_ONLY |
	    FILE_NO_INTERMEDIATE_BUFFERING | FILE_DELETE_ON_CLOSE);

	/*
	 * The ofile level DoC flag is currently in of->f_flags
	 * (SMB_OFLAGS_SET_DELETE_ON_CLOSE) though probably it
	 * should be in f_create_options (and perhaps rename
	 * that field to f_mode or something closer to the
	 * Open.Mode terminology used in MS-FSA).
	 */
	if (of->f_flags & SMB_OFLAGS_SET_DELETE_ON_CLOSE)
		mode |= FILE_DELETE_ON_CLOSE;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "l", mode);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileAlignmentInformation
 */
static uint32_t
smb2_qif_alignment(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	int rc;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "l", 0);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileAlternateNameInformation
 * See also:
 *	SMB_QUERY_FILE_ALT_NAME_INFO
 *	SMB_FILE_ALT_NAME_INFORMATION
 */
static uint32_t
smb2_qif_altname(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_ofile_t *of = sr->fid_ofile;
	int rc;

	ASSERT(qi->qi_namelen > 0);
	ASSERT(qi->qi_attr.sa_mask & SMB_AT_NODEID);

	if (of->f_ftype != SMB_FTYPE_DISK)
		return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
	if ((of->f_tree->t_flags & SMB_TREE_SHORTNAMES) == 0)
		return (NT_STATUS_OBJECT_NAME_NOT_FOUND);

	/* fill in qi->qi_shortname */
	smb_query_shortname(of->f_node, qi);

	rc = smb_mbc_encodef(
	    &sr->raw_data, "%lU", sr,
	    smb_wcequiv_strlen(qi->qi_shortname),
	    qi->qi_shortname);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileStreamInformation
 */
static uint32_t
smb2_qif_stream(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_ofile_t *of = sr->fid_ofile;
	smb_attr_t *attr = &qi->qi_attr;
	uint32_t status;

	ASSERT((attr->sa_mask & SMB_AT_STANDARD) == SMB_AT_STANDARD);
	if (of->f_ftype != SMB_FTYPE_DISK) {
		(void) smb_mbc_encodef(
		    &sr->raw_data, "l", 0);
		return (0);
	}

	status = smb_query_stream_info(sr, &sr->raw_data, qi);
	return (status);
}

/*
 * FilePipeInformation
 */
static uint32_t
smb2_qif_pipe(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	smb_ofile_t *of = sr->fid_ofile;
	uint32_t	pipe_mode;
	uint32_t	nonblock;
	int		rc;

	switch (of->f_ftype) {
	case SMB_FTYPE_BYTE_PIPE:
		pipe_mode = 0;	/* FILE_PIPE_BYTE_STREAM_MODE */
		break;
	case SMB_FTYPE_MESG_PIPE:
		pipe_mode = 1;	/* FILE_PIPE_MESSAGE_MODE */
		break;
	case SMB_FTYPE_DISK:
	case SMB_FTYPE_PRINTER:
	default:
		return (NT_STATUS_INVALID_PARAMETER);
	}
	nonblock = 0;	/* XXX todo: Get this from the pipe handle. */

	rc = smb_mbc_encodef(
	    &sr->raw_data, "ll",
	    pipe_mode, nonblock);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FilePipeLocalInformation
 */
/* ARGSUSED */
static uint32_t
smb2_qif_pipe_lcl(smb_request_t *sr, smb_queryinfo_t *qi)
{
	return (NT_STATUS_INVALID_PARAMETER); /* XXX todo */
}

/*
 * FilePipeRemoteInformation
 */
/* ARGSUSED */
static uint32_t
smb2_qif_pipe_rem(smb_request_t *sr, smb_queryinfo_t *qi)
{
	return (NT_STATUS_INVALID_PARAMETER); /* XXX todo */
}

/*
 * FileCompressionInformation
 * XXX: For now, just say "not compressed".
 */
static uint32_t
smb2_qif_compr(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	uint16_t CompressionFormat = 0;	/* COMPRESSION_FORMAT_NONE */
	int rc;

	ASSERT(sa->sa_mask & SMB_AT_SIZE);

	rc = smb_mbc_encodef(
	    &sr->raw_data, "qw6.",
	    sa->sa_vattr.va_size,	/* q */
	    CompressionFormat);		/* w */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileNetworkOpenInformation
 */
static uint32_t
smb2_qif_opens(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	int rc;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "TTTTqqll",
	    &sa->sa_crtime,		/* T */
	    &sa->sa_vattr.va_atime,	/* T */
	    &sa->sa_vattr.va_mtime,	/* T */
	    &sa->sa_vattr.va_ctime,	/* T */
	    sa->sa_allocsz,		/* q */
	    sa->sa_vattr.va_size,	/* q */
	    sa->sa_dosattr,		/* l */
	    0); /* reserved */		/* l */
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileAttributeTagInformation
 *
 * If dattr includes FILE_ATTRIBUTE_REPARSE_POINT, the
 * second dword should be the reparse tag.  Otherwise
 * the tag value should be set to zero.
 * We don't support reparse points, so we set the tag
 * to zero.
 */
static uint32_t
smb2_qif_tags(smb_request_t *sr, smb_queryinfo_t *qi)
{
	_NOTE(ARGUNUSED(qi))
	int rc;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "ll", 0, 0);
	if (rc != 0)
		return (NT_STATUS_BUFFER_OVERFLOW);

	return (0);
}

/*
 * FileIdInformation
 *
 * Returns a A FILE_ID_INFORMATION
 *	VolumeSerialNumber (8 bytes)
 *	FileId (16 bytes)
 *
 * Take the volume serial from the share root,
 * and compose the FileId from the nodeid and fsid
 * of the file (in case we crossed mounts)
 */
static uint32_t
smb2_qif_id_info(smb_request_t *sr, smb_queryinfo_t *qi)
{
	smb_attr_t *sa = &qi->qi_attr;
	smb_ofile_t *of = sr->fid_ofile;
	smb_tree_t *tree = sr->tid_tree;
	vfs_t	*f_vfs;	// file
	vfs_t	*s_vfs;	// share
	uint64_t nodeid;
	int rc;

	ASSERT((sa->sa_mask & SMB_AT_NODEID) != 0);
	if (of->f_ftype != SMB_FTYPE_DISK)
		return (NT_STATUS_INVALID_INFO_CLASS);

	s_vfs = SMB_NODE_VFS(tree->t_snode);
	f_vfs = SMB_NODE_VFS(of->f_node);
	nodeid = (uint64_t)sa->sa_vattr.va_nodeid;

	rc = smb_mbc_encodef(
	    &sr->raw_data, "llqll",
	    s_vfs->vfs_fsid.val[0],	/* l */
	    s_vfs->vfs_fsid.val[1],	/* l */
	    nodeid,			/* q */
	    f_vfs->vfs_fsid.val[0],	/* l */
	    f_vfs->vfs_fsid.val[1]);	/* l */
	if (rc != 0)
		return (NT_STATUS_INFO_LENGTH_MISMATCH);

	return (0);
}