Sample Code

windows driver samples/ cdfs file system driver/ C++/ volinfo.c/

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
/*++
 
Copyright (c) 1989-2000 Microsoft Corporation
 
Module Name:
 
    VolInfo.c
 
Abstract:
 
    This module implements the volume information routines for Cdfs called by
    the dispatch driver.
 
 
--*/
 
#include "CdProcs.h"
 
//
//  The Bug check file id for this module
//
 
#define BugCheckFileId                   (CDFS_BUG_CHECK_VOLINFO)
 
//
//  Local support routines
//
 
_Requires_lock_held_(_Global_critical_region_)
NTSTATUS
CdQueryFsVolumeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_VOLUME_INFORMATION Buffer,
    _Inout_ PULONG Length
    );
 
NTSTATUS
CdQueryFsSizeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_SIZE_INFORMATION Buffer,
    _Inout_ PULONG Length
    );
 
NTSTATUS
CdQueryFsDeviceInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_DEVICE_INFORMATION Buffer,
    _Inout_ PULONG Length
    );
 
NTSTATUS
CdQueryFsAttributeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_ATTRIBUTE_INFORMATION Buffer,
    _Inout_ PULONG Length
    );
 
NTSTATUS
CdQueryFsSectorSizeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_writes_bytes_(*Length) PFILE_FS_SECTOR_SIZE_INFORMATION Buffer,
    _Inout_ PULONG Length
    );
 
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, CdCommonQueryVolInfo)
#pragma alloc_text(PAGE, CdQueryFsAttributeInfo)
#pragma alloc_text(PAGE, CdQueryFsDeviceInfo)
#pragma alloc_text(PAGE, CdQueryFsSizeInfo)
#pragma alloc_text(PAGE, CdQueryFsVolumeInfo)
#pragma alloc_text(PAGE, CdQueryFsSectorSizeInfo)
#endif
 
_Requires_lock_held_(_Global_critical_region_)
NTSTATUS
CdCommonQueryVolInfo (
    _Inout_ PIRP_CONTEXT IrpContext,
    _Inout_ PIRP Irp
    )
 
/*++
 
Routine Description:
 
    This is the common routine for querying volume information called by both
    the fsd and fsp threads.
 
Arguments:
 
    Irp - Supplies the Irp being processed
 
Return Value:
 
    NTSTATUS - The return status for the operation
 
--*/
 
{
    NTSTATUS Status = STATUS_INVALID_PARAMETER;
    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
 
    ULONG Length;
 
    TYPE_OF_OPEN TypeOfOpen;
    PFCB Fcb;
    PCCB Ccb;
 
    PAGED_CODE();
 
    //
    //  Reference our input parameters to make things easier
    //
 
    Length = IrpSp->Parameters.QueryVolume.Length;
 
    //
    //  Decode the file object and fail if this an unopened file object.
    //
 
    TypeOfOpen = CdDecodeFileObject( IrpContext, IrpSp->FileObject, &Fcb, &Ccb );
 
    if (TypeOfOpen == UnopenedFileObject) {
 
        CdCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER );
        return STATUS_INVALID_PARAMETER;
    }
 
    //
    //  Acquire the Vcb for this volume.
    //
 
    CdAcquireVcbShared( IrpContext, Fcb->Vcb, FALSE );
 
    //
    //  Use a try-finally to facilitate cleanup.
    //
 
    try {
 
        //
        //  Verify the Vcb.
        //
 
        CdVerifyVcb( IrpContext, Fcb->Vcb );
 
        //
        //  Based on the information class we'll do different actions.  Each
        //  of the procedures that we're calling fills up the output buffer
        //  if possible and returns true if it successfully filled the buffer
        //  and false if it couldn't wait for any I/O to complete.
        //
 
        switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
 
        case FileFsSizeInformation:
 
            Status = CdQueryFsSizeInfo( IrpContext, Fcb->Vcb, Irp->AssociatedIrp.SystemBuffer, &Length );
            break;
 
        case FileFsVolumeInformation:
 
            Status = CdQueryFsVolumeInfo( IrpContext, Fcb->Vcb, Irp->AssociatedIrp.SystemBuffer, &Length );
            break;
 
        case FileFsDeviceInformation:
 
            Status = CdQueryFsDeviceInfo( IrpContext, Fcb->Vcb, Irp->AssociatedIrp.SystemBuffer, &Length );
            break;
 
        case FileFsAttributeInformation:
 
            Status = CdQueryFsAttributeInfo( IrpContext, Fcb->Vcb, Irp->AssociatedIrp.SystemBuffer, &Length );
            break;
 
#if (NTDDI_VERSION >= NTDDI_WIN8)
        case FileFsSectorSizeInformation:
 
            Status = CdQueryFsSectorSizeInfo( IrpContext, Fcb->Vcb, Irp->AssociatedIrp.SystemBuffer, &Length );
            break;
#endif
        }
 
        //
        //  Set the information field to the number of bytes actually filled in
        //
 
        Irp->IoStatus.Information = IrpSp->Parameters.QueryVolume.Length - Length;
 
    } finally {
 
        //
        //  Release the Vcb.
        //
 
        CdReleaseVcb( IrpContext, Fcb->Vcb );
    }
 
    //
    //  Complete the request if we didn't raise.
    //
 
    CdCompleteRequest( IrpContext, Irp, Status );
 
    return Status;
}
 
//
//  Local support routine
//
 
_Requires_lock_held_(_Global_critical_region_)
NTSTATUS
CdQueryFsVolumeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_VOLUME_INFORMATION Buffer,
    _Inout_ PULONG Length
    )
 
/*++
 
Routine Description:
 
    This routine implements the query volume info call
 
Arguments:
 
    Vcb - Vcb for this volume.
 
    Buffer - Supplies a pointer to the output buffer where the information
        is to be returned
 
    Length - Supplies the length of the buffer in byte.  This variable
        upon return recieves the remaining bytes free in the buffer
 
Return Value:
 
    NTSTATUS - Returns the status for the query
 
--*/
 
{
    ULONG BytesToCopy;
 
    NTSTATUS Status = STATUS_SUCCESS;
 
    PAGED_CODE();
 
    UNREFERENCED_PARAMETER( IrpContext );
 
    //
    //  Fill in the data from the Vcb.
    //
 
    Buffer->VolumeCreationTime = *((PLARGE_INTEGER) &Vcb->VolumeDasdFcb->CreationTime);
    Buffer->VolumeSerialNumber = Vcb->Vpb->SerialNumber;
 
    Buffer->SupportsObjects = FALSE;
 
    *Length -= FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel[0] );
 
    //
    //  Check if the buffer we're given is long enough
    //
 
    if (*Length >= (ULONG) Vcb->Vpb->VolumeLabelLength) {
 
        BytesToCopy = Vcb->Vpb->VolumeLabelLength;
 
    } else {
 
        BytesToCopy = *Length;
 
        Status = STATUS_BUFFER_OVERFLOW;
    }
 
    //
    //  Copy over what we can of the volume label, and adjust *Length
    //
 
    Buffer->VolumeLabelLength = BytesToCopy;
 
    if (BytesToCopy) {
 
        RtlCopyMemory( &Buffer->VolumeLabel[0],
                       &Vcb->Vpb->VolumeLabel[0],
                       BytesToCopy );
    }
 
    *Length -= BytesToCopy;
 
    //
    //  Set our status and return to our caller
    //
 
    return Status;
}
 
//
//  Local support routine
//
 
NTSTATUS
CdQueryFsSizeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_SIZE_INFORMATION Buffer,
    _Inout_ PULONG Length
    )
 
/*++
 
Routine Description:
 
    This routine implements the query volume size call.
 
Arguments:
 
    Vcb - Vcb for this volume.
 
    Buffer - Supplies a pointer to the output buffer where the information
        is to be returned
 
    Length - Supplies the length of the buffer in byte.  This variable
        upon return recieves the remaining bytes free in the buffer
 
Return Value:
 
    NTSTATUS - Returns the status for the query
 
--*/
 
{
    PAGED_CODE();
 
    UNREFERENCED_PARAMETER( IrpContext );
 
    //
    //  Fill in the output buffer.
    //
 
    Buffer->TotalAllocationUnits.QuadPart = LlSectorsFromBytes( Vcb->VolumeDasdFcb->AllocationSize.QuadPart );
 
    Buffer->AvailableAllocationUnits.QuadPart = 0;
    Buffer->SectorsPerAllocationUnit = 1;
    Buffer->BytesPerSector = SECTOR_SIZE;
 
    //
    //  Adjust the length variable
    //
 
    *Length -= sizeof( FILE_FS_SIZE_INFORMATION );
 
    //
    //  And return success to our caller
    //
 
    return STATUS_SUCCESS;
}
 
//
//  Local support routine
//
 
NTSTATUS
CdQueryFsDeviceInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_DEVICE_INFORMATION Buffer,
    _Inout_ PULONG Length
    )
 
/*++
 
Routine Description:
 
    This routine implements the query volume device call.
 
Arguments:
 
    Vcb - Vcb for this volume.
 
    Buffer - Supplies a pointer to the output buffer where the information
        is to be returned
 
    Length - Supplies the length of the buffer in byte.  This variable
        upon return recieves the remaining bytes free in the buffer
 
Return Value:
 
    NTSTATUS - Returns the status for the query
 
--*/
 
{
    PAGED_CODE();
 
    UNREFERENCED_PARAMETER( IrpContext );
 
    //
    //  Update the output buffer.
    //
 
    Buffer->Characteristics = Vcb->TargetDeviceObject->Characteristics;
    Buffer->DeviceType = FILE_DEVICE_CD_ROM;
 
    //
    //  Adjust the length variable
    //
 
    *Length -= sizeof( FILE_FS_DEVICE_INFORMATION );
 
    //
    //  And return success to our caller
    //
 
    return STATUS_SUCCESS;
}
 
//
//  Local support routine
//
 
NTSTATUS
CdQueryFsAttributeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_ PFILE_FS_ATTRIBUTE_INFORMATION Buffer,
    _Inout_ PULONG Length
    )
 
/*++
 
Routine Description:
 
    This routine implements the query volume attribute call.
 
Arguments:
 
    Vcb - Vcb for this volume.
 
    Buffer - Supplies a pointer to the output buffer where the information
        is to be returned
 
    Length - Supplies the length of the buffer in byte.  This variable
        upon return recieves the remaining bytes free in the buffer
 
Return Value:
 
    NTSTATUS - Returns the status for the query
 
--*/
 
{
    ULONG BytesToCopy;
 
    NTSTATUS Status = STATUS_SUCCESS;
 
    PAGED_CODE();
 
    UNREFERENCED_PARAMETER( Vcb );
 
    //
    //  Fill out the fixed portion of the buffer.
    //
 
    Buffer->FileSystemAttributes = FILE_CASE_SENSITIVE_SEARCH |
                                   FILE_READ_ONLY_VOLUME |
                                   FILE_SUPPORTS_OPEN_BY_FILE_ID;
 
    if (FlagOn( IrpContext->Vcb->VcbState, VCB_STATE_JOLIET )) {
 
        SetFlag( Buffer->FileSystemAttributes, FILE_UNICODE_ON_DISK );
 
        Buffer->MaximumComponentNameLength = 110;
 
    } else {
 
        Buffer->MaximumComponentNameLength = 221;
    }
 
    *Length -= FIELD_OFFSET( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName );
 
    //
    //  Make sure we can copy full unicode characters.
    //
 
    ClearFlag( *Length, 1 );
 
    //
    //  Determine how much of the file system name will fit.
    //
 
    if (*Length >= 8) {
 
        BytesToCopy = 8;
 
    } else {
 
        BytesToCopy = *Length;
        Status = STATUS_BUFFER_OVERFLOW;
    }
 
    *Length -= BytesToCopy;
 
    //
    //  Do the file system name.
    //
 
    Buffer->FileSystemNameLength = BytesToCopy;
 
    RtlCopyMemory( &Buffer->FileSystemName[0], L"CDFS", BytesToCopy );
 
    //
    //  And return to our caller
    //
 
    return Status;
}
 
#if (NTDDI_VERSION >= NTDDI_WIN8)
 
NTSTATUS
CdQueryFsSectorSizeInfo (
    _In_ PIRP_CONTEXT IrpContext,
    _In_ PVCB Vcb,
    _Out_writes_bytes_(*Length) PFILE_FS_SECTOR_SIZE_INFORMATION Buffer,
    _Inout_ PULONG Length
    )
 
/*++
 
Routine Description:
 
    This routine implements the query sector size information call
    This operation will work on any handle and requires no privilege.
 
Arguments:
 
    Vcb - Supplies the Vcb being queried
 
    Buffer - Supplies a pointer to the output buffer where the information
        is to be returned
 
    Length - Supplies the length of the buffer in byte.  This variable
        upon return receives the remaining bytes free in the buffer
 
Return Value:
 
    NTSTATUS - Returns the status for the query
 
--*/
 
{
    NTSTATUS Status;
 
    PAGED_CODE();
    UNREFERENCED_PARAMETER( IrpContext );
 
    //
    //  Sufficient buffer size is guaranteed by the I/O manager or the
    //  originating kernel mode driver.
    //
 
    ASSERT( *Length >= sizeof( FILE_FS_SECTOR_SIZE_INFORMATION ));
    _Analysis_assume_( *Length >= sizeof( FILE_FS_SECTOR_SIZE_INFORMATION ));
 
    //
    //  Retrieve the sector size information
    //
 
    Status = FsRtlGetSectorSizeInformation( Vcb->Vpb->RealDevice,
                                            Buffer );
 
    //
    //  Adjust the length variable
    //
 
    if (NT_SUCCESS( Status )) {
 
        *Length -= sizeof( FILE_FS_SECTOR_SIZE_INFORMATION );
    }
 
    return Status;
}
 
#endif

Our Services

  • What our customers say about us?

© 2011-2025 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS