Skip to content

Commit fd34548

Browse files
gigaherzHeisSpiter
authored andcommitted
[CDFS_NEW] Replace old driver with a Ms-PL licensed version straight out of the driver samples github repository.
1 parent 87d276f commit fd34548

38 files changed

+5301
-2805
lines changed

drivers/filesystems/cdfs_new/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ list(APPEND SOURCE
66
cachesup.c
77
cddata.c
88
cdinit.c
9+
cdprocssrc.c
910
cleanup.c
1011
close.c
1112
create.c
@@ -24,10 +25,12 @@ list(APPEND SOURCE
2425
prefxsup.c
2526
read.c
2627
resrcsup.c
28+
shutdown.c
2729
strucsup.c
2830
verfysup.c
2931
volinfo.c
30-
workque.c)
32+
workque.c
33+
write.c)
3134

3235
add_library(cdfs SHARED ${SOURCE} cdfs.rc)
3336
set_module_type(cdfs kernelmodedriver)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!---
2+
name: CDFS File System Driver
3+
platform: WDM
4+
language: cpp
5+
category: FileSystem
6+
description: The CD-ROM file system driver (cdfs) sample is a file system driver for removable media.
7+
samplefwlink: http://go.microsoft.com/fwlink/p/?LinkId=617642
8+
--->
9+
10+
11+
CDFS File System Driver
12+
=======================
13+
14+
The CD-ROM file system driver (cdfs) sample is a sample file system driver that you can use to write new file systems.
15+
16+
Cdfs is a read-only file system that addresses various issues such as accessing data on disk, interacting with the cache manager, and handling various I/O operations such as opening files, performing reads on a file, retrieving information on a file, and performing various control operations on the file system. The Cdfs file system is included with the Microsoft Windows operating system.
17+
18+
## Universal Windows Driver Compliant
19+
This sample builds a Universal Windows Driver. It uses only APIs and DDIs that are included in OneCoreUAP.
20+

drivers/filesystems/cdfs_new/allocsup.c

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Module Name:
4444
4545
--*/
4646

47-
#include "cdprocs.h"
47+
#include "CdProcs.h"
4848

4949
//
5050
// The Bug check file id for this module
@@ -58,18 +58,18 @@ Module Name:
5858

5959
ULONG
6060
CdFindMcbEntry (
61-
IN PIRP_CONTEXT IrpContext,
62-
IN PFCB Fcb,
63-
IN LONGLONG FileOffset
61+
_In_ PIRP_CONTEXT IrpContext,
62+
_In_ PFCB Fcb,
63+
_In_ LONGLONG FileOffset
6464
);
6565

6666
VOID
6767
CdDiskOffsetFromMcbEntry (
68-
IN PIRP_CONTEXT IrpContext,
69-
IN PCD_MCB_ENTRY McbEntry,
70-
IN LONGLONG FileOffset,
71-
IN PLONGLONG DiskOffset,
72-
IN PULONG ByteCount
68+
_In_ PIRP_CONTEXT IrpContext,
69+
_In_ PCD_MCB_ENTRY McbEntry,
70+
_In_ LONGLONG FileOffset,
71+
_Out_ PLONGLONG DiskOffset,
72+
_Out_ PULONG ByteCount
7373
);
7474

7575
#ifdef ALLOC_PRAGMA
@@ -84,13 +84,16 @@ CdDiskOffsetFromMcbEntry (
8484
#endif
8585

8686

87+
_Requires_lock_held_(_Global_critical_region_)
8788
VOID
89+
// PREFast currently has no way to express the Fcb==Fcb->Vcb->VolumeDasdFcb early return
90+
#pragma warning(suppress: 6001 6101)
8891
CdLookupAllocation (
89-
IN PIRP_CONTEXT IrpContext,
90-
IN PFCB Fcb,
91-
IN LONGLONG FileOffset,
92-
OUT PLONGLONG DiskOffset,
93-
OUT PULONG ByteCount
92+
_In_ PIRP_CONTEXT IrpContext,
93+
_In_ PFCB Fcb,
94+
_In_ LONGLONG FileOffset,
95+
_Out_ PLONGLONG DiskOffset,
96+
_Out_ PULONG ByteCount
9497
)
9598

9699
/*++
@@ -128,7 +131,7 @@ Return Value:
128131
{
129132
BOOLEAN FirstPass = TRUE;
130133
ULONG McbEntryOffset;
131-
PFCB ParentFcb = NULL; /* ReactOS Change: GCC uninitialized variable bug */
134+
PFCB ParentFcb = NULL;
132135
BOOLEAN CleanupParent = FALSE;
133136

134137
BOOLEAN UnlockFcb = FALSE;
@@ -137,19 +140,31 @@ Return Value:
137140
ULONG CurrentMcbOffset;
138141
PCD_MCB_ENTRY CurrentMcbEntry;
139142

140-
DIRENT_ENUM_CONTEXT DirContext;
141-
DIRENT Dirent;
143+
DIRENT_ENUM_CONTEXT DirContext = {0};
144+
DIRENT Dirent = {0};
142145

143146
PAGED_CODE();
144147

145148
ASSERT_IRP_CONTEXT( IrpContext );
146149
ASSERT_FCB( Fcb );
147150

151+
//
152+
// For DASD IO we already have clamped the read to the volume limits.
153+
// We'll allow reading beyond those limits for extended DASD IO, so
154+
// no MCB lookup here.
155+
//
156+
157+
if (Fcb == Fcb->Vcb->VolumeDasdFcb) {
158+
159+
*DiskOffset = FileOffset;
160+
return;
161+
}
162+
148163
//
149164
// Use a try finally to facilitate cleanup.
150165
//
151166

152-
_SEH2_TRY {
167+
try {
153168

154169
//
155170
// We use a loop to perform the lookup. If we don't find the mapping in the
@@ -215,10 +230,7 @@ Return Value:
215230
// Do an unsafe test to see if we need to create a file object.
216231
//
217232

218-
if (ParentFcb->FileObject == NULL) {
219-
220-
CdCreateInternalStream( IrpContext, ParentFcb->Vcb, ParentFcb );
221-
}
233+
CdVerifyOrCreateDirStreamFile( IrpContext, ParentFcb);
222234

223235
//
224236
// Initialize the local variables to indicate the first dirent
@@ -296,7 +308,7 @@ Return Value:
296308
FirstPass = FALSE;
297309
}
298310

299-
} _SEH2_FINALLY {
311+
} finally {
300312

301313
if (CleanupParent) {
302314

@@ -311,19 +323,19 @@ Return Value:
311323
}
312324

313325
if (UnlockFcb) { CdUnlockFcb( IrpContext, Fcb ); }
314-
} _SEH2_END;
326+
}
315327

316328
return;
317329
}
318330

319331

320332
VOID
321333
CdAddAllocationFromDirent (
322-
IN PIRP_CONTEXT IrpContext,
323-
IN PFCB Fcb,
324-
IN ULONG McbEntryOffset,
325-
IN LONGLONG StartingFileOffset,
326-
IN PDIRENT Dirent
334+
_In_ PIRP_CONTEXT IrpContext,
335+
_Inout_ PFCB Fcb,
336+
_In_ ULONG McbEntryOffset,
337+
_In_ LONGLONG StartingFileOffset,
338+
_In_ PDIRENT Dirent
327339
)
328340

329341
/*++
@@ -358,6 +370,8 @@ Return Value:
358370

359371
PAGED_CODE();
360372

373+
UNREFERENCED_PARAMETER( IrpContext );
374+
361375
ASSERT_IRP_CONTEXT( IrpContext );
362376
ASSERT_FCB( Fcb );
363377
ASSERT_LOCKED_FCB( Fcb );
@@ -466,10 +480,10 @@ Return Value:
466480

467481
VOID
468482
CdAddInitialAllocation (
469-
IN PIRP_CONTEXT IrpContext,
470-
IN PFCB Fcb,
471-
IN ULONG StartingBlock,
472-
IN LONGLONG DataLength
483+
_In_ PIRP_CONTEXT IrpContext,
484+
_Inout_ PFCB Fcb,
485+
_In_ ULONG StartingBlock,
486+
_In_ LONGLONG DataLength
473487
)
474488

475489
/*++
@@ -505,11 +519,13 @@ Return Value:
505519

506520
PAGED_CODE();
507521

522+
UNREFERENCED_PARAMETER( IrpContext );
523+
508524
ASSERT_IRP_CONTEXT( IrpContext );
509525
ASSERT_FCB( Fcb );
510526
ASSERT_LOCKED_FCB( Fcb );
511-
ASSERT( 0 == Fcb->Mcb.CurrentEntryCount);
512-
ASSERT( CDFS_NTC_FCB_DATA != Fcb->NodeTypeCode);
527+
NT_ASSERT( 0 == Fcb->Mcb.CurrentEntryCount);
528+
NT_ASSERT( CDFS_NTC_FCB_DATA != Fcb->NodeTypeCode);
513529

514530
//
515531
// Update the new entry with the input data.
@@ -555,9 +571,9 @@ Return Value:
555571

556572
VOID
557573
CdTruncateAllocation (
558-
IN PIRP_CONTEXT IrpContext,
559-
IN PFCB Fcb,
560-
IN LONGLONG StartingFileOffset
574+
_In_ PIRP_CONTEXT IrpContext,
575+
_Inout_ PFCB Fcb,
576+
_In_ LONGLONG StartingFileOffset
561577
)
562578

563579
/*++
@@ -591,7 +607,7 @@ Return Value:
591607
ASSERT_LOCKED_FCB( Fcb );
592608

593609
//
594-
// Find the entry containing this starting offset.
610+
// Find the entry containg this starting offset.
595611
//
596612

597613
McbEntryOffset = CdFindMcbEntry( IrpContext, Fcb, StartingFileOffset );
@@ -606,10 +622,11 @@ Return Value:
606622
}
607623

608624

625+
_At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
609626
VOID
610627
CdInitializeMcb (
611-
IN PIRP_CONTEXT IrpContext,
612-
IN PFCB Fcb
628+
_In_ PIRP_CONTEXT IrpContext,
629+
_Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
613630
)
614631

615632
/*++
@@ -635,6 +652,8 @@ Return Value:
635652
{
636653
PAGED_CODE();
637654

655+
UNREFERENCED_PARAMETER( IrpContext );
656+
638657
ASSERT_IRP_CONTEXT( IrpContext );
639658
ASSERT_FCB( Fcb );
640659

@@ -652,10 +671,14 @@ Return Value:
652671
}
653672

654673

674+
_At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
675+
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_PATH_TABLE, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
676+
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_INDEX, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
677+
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_DATA, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_DATA)))
655678
VOID
656679
CdUninitializeMcb (
657-
IN PIRP_CONTEXT IrpContext,
658-
IN PFCB Fcb
680+
_In_ PIRP_CONTEXT IrpContext,
681+
_Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
659682
)
660683

661684
/*++
@@ -681,6 +704,8 @@ Return Value:
681704
{
682705
PAGED_CODE();
683706

707+
UNREFERENCED_PARAMETER( IrpContext );
708+
684709
ASSERT_IRP_CONTEXT( IrpContext );
685710
ASSERT_FCB( Fcb );
686711

@@ -698,14 +723,14 @@ Return Value:
698723

699724

700725
//
701-
// Local support routine
726+
// Local suupport routine
702727
//
703728

704729
ULONG
705730
CdFindMcbEntry (
706-
IN PIRP_CONTEXT IrpContext,
707-
IN PFCB Fcb,
708-
IN LONGLONG FileOffset
731+
_In_ PIRP_CONTEXT IrpContext,
732+
_In_ PFCB Fcb,
733+
_In_ LONGLONG FileOffset
709734
)
710735

711736
/*++
@@ -736,6 +761,8 @@ Return Value:
736761

737762
PAGED_CODE();
738763

764+
UNREFERENCED_PARAMETER( IrpContext );
765+
739766
ASSERT_IRP_CONTEXT( IrpContext );
740767
ASSERT_FCB( Fcb );
741768
ASSERT_LOCKED_FCB( Fcb );
@@ -781,11 +808,11 @@ Return Value:
781808

782809
VOID
783810
CdDiskOffsetFromMcbEntry (
784-
IN PIRP_CONTEXT IrpContext,
785-
IN PCD_MCB_ENTRY McbEntry,
786-
IN LONGLONG FileOffset,
787-
IN PLONGLONG DiskOffset,
788-
IN PULONG ByteCount
811+
_In_ PIRP_CONTEXT IrpContext,
812+
_In_ PCD_MCB_ENTRY McbEntry,
813+
_In_ LONGLONG FileOffset,
814+
_Out_ PLONGLONG DiskOffset,
815+
_Out_ PULONG ByteCount
789816
)
790817

791818
/*++
@@ -827,6 +854,9 @@ Return Value:
827854
LONGLONG LocalByteCount;
828855

829856
PAGED_CODE();
857+
858+
UNREFERENCED_PARAMETER( IrpContext );
859+
830860
ASSERT_IRP_CONTEXT( IrpContext );
831861

832862
//

0 commit comments

Comments
 (0)