/* FUNCTIONS ***************************************************************/
-BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
- IN ULONG DiskSector,
- IN ULONG SectorCount,
- IN UCHAR* Buffer)
+BOOLEAN
+VFATReadSectors (IN PDEVICE_OBJECT pDeviceObject,
+ IN ULONG DiskSector, IN ULONG SectorCount, IN UCHAR * Buffer)
{
- LARGE_INTEGER sectorNumber;
- PIRP irp;
- IO_STATUS_BLOCK ioStatus;
- KEVENT event;
- NTSTATUS status;
- ULONG sectorSize;
-
- sectorNumber.u.LowPart = DiskSector << 9;
- sectorNumber.u.HighPart = DiskSector >> 23;
-
- KeInitializeEvent(&event, NotificationEvent, FALSE);
- sectorSize = BLOCKSIZE * SectorCount;
-
-
- DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
- pDeviceObject,
- DiskSector,
- Buffer);
- DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n",
- (unsigned long int)sectorNumber.u.LowPart,
- (unsigned long int)sectorNumber.u.HighPart,
- sectorSize);
-
-
- DPRINT("Building synchronous FSD Request...\n");
- irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
- pDeviceObject,
- Buffer,
- sectorSize,
- §orNumber,
- &event,
- &ioStatus );
-
- if (!irp) {
- DbgPrint("READ failed!!!\n");
- return FALSE;
+ LARGE_INTEGER sectorNumber;
+ PIRP irp;
+ IO_STATUS_BLOCK ioStatus;
+ KEVENT event;
+ NTSTATUS status;
+ ULONG sectorSize;
+
+ sectorNumber.u.LowPart = DiskSector << 9;
+ sectorNumber.u.HighPart = DiskSector >> 23;
+
+ KeInitializeEvent (&event, NotificationEvent, FALSE);
+ sectorSize = BLOCKSIZE * SectorCount;
+
+
+ DPRINT ("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
+ pDeviceObject, DiskSector, Buffer);
+ DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
+ (unsigned long int) sectorNumber.u.LowPart,
+ (unsigned long int) sectorNumber.u.HighPart, sectorSize);
+
+
+ DPRINT ("Building synchronous FSD Request...\n");
+ irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
+ pDeviceObject,
+ Buffer,
+ sectorSize,
+ §orNumber, &event, &ioStatus);
+
+ if (!irp)
+ {
+ DbgPrint ("READ failed!!!\n");
+ return FALSE;
}
- DPRINT("Calling IO Driver... with irp %x\n", irp);
- status = IoCallDriver(pDeviceObject,
- irp);
-
- DPRINT("Waiting for IO Operation for %x\n", irp);
- if (status == STATUS_PENDING)
- {
- DPRINT("Operation pending\n");
- KeWaitForSingleObject(&event,
- Suspended,
- KernelMode,
- FALSE,
- NULL);
- DPRINT("Getting IO Status... for %x\n", irp);
- status = ioStatus.Status;
+ DPRINT ("Calling IO Driver... with irp %x\n", irp);
+ status = IoCallDriver (pDeviceObject, irp);
+
+ DPRINT ("Waiting for IO Operation for %x\n", irp);
+ if (status == STATUS_PENDING)
+ {
+ DPRINT ("Operation pending\n");
+ KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
+ DPRINT ("Getting IO Status... for %x\n", irp);
+ status = ioStatus.Status;
}
- if (!NT_SUCCESS(status)) {
- DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status);
- DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
- pDeviceObject,
- DiskSector,
- Buffer,
- sectorNumber.u.HighPart,
- sectorNumber.u.LowPart);
- return FALSE;
+ if (!NT_SUCCESS (status))
+ {
+ DbgPrint ("IO failed!!! VFATREadSectors : Error code: %x\n", status);
+ DbgPrint
+ ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
+ pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
+ sectorNumber.u.LowPart);
+ return FALSE;
}
- DPRINT("Block request succeeded for %x\n", irp);
- return TRUE;
+ DPRINT ("Block request succeeded for %x\n", irp);
+ return TRUE;
}
-BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
- IN ULONG DiskSector,
- IN ULONG SectorCount,
- IN UCHAR* Buffer)
+BOOLEAN
+VFATWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
+ IN ULONG DiskSector,
+ IN ULONG SectorCount, IN UCHAR * Buffer)
{
- LARGE_INTEGER sectorNumber;
- PIRP irp;
- IO_STATUS_BLOCK ioStatus;
- KEVENT event;
- NTSTATUS status;
- ULONG sectorSize;
-
- DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
- pDeviceObject,DiskSector,Buffer);
-
- sectorNumber.u.LowPart = DiskSector << 9;
- sectorNumber.u.HighPart = DiskSector >> 23;
-
- KeInitializeEvent(&event, NotificationEvent, FALSE);
-
- sectorSize = BLOCKSIZE*SectorCount;
-
- DPRINT("Building synchronous FSD Request...\n");
- irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
- pDeviceObject,
- Buffer,
- sectorSize,
- §orNumber,
- &event,
- &ioStatus );
-
- if (!irp) {
- DbgPrint("WRITE failed!!!\n");
- return FALSE;
+ LARGE_INTEGER sectorNumber;
+ PIRP irp;
+ IO_STATUS_BLOCK ioStatus;
+ KEVENT event;
+ NTSTATUS status;
+ ULONG sectorSize;
+
+ DPRINT ("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
+ pDeviceObject, DiskSector, Buffer);
+
+ sectorNumber.u.LowPart = DiskSector << 9;
+ sectorNumber.u.HighPart = DiskSector >> 23;
+
+ KeInitializeEvent (&event, NotificationEvent, FALSE);
+
+ sectorSize = BLOCKSIZE * SectorCount;
+
+ DPRINT ("Building synchronous FSD Request...\n");
+ irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE,
+ pDeviceObject,
+ Buffer,
+ sectorSize,
+ §orNumber, &event, &ioStatus);
+
+ if (!irp)
+ {
+ DbgPrint ("WRITE failed!!!\n");
+ return FALSE;
}
- DPRINT("Calling IO Driver...\n");
- status = IoCallDriver(pDeviceObject,
- irp);
-
- DPRINT("Waiting for IO Operation...\n");
- if (status == STATUS_PENDING) {
- KeWaitForSingleObject(&event,
- Suspended,
- KernelMode,
- FALSE,
- NULL);
- DPRINT("Getting IO Status...\n");
- status = ioStatus.Status;
+ DPRINT ("Calling IO Driver...\n");
+ status = IoCallDriver (pDeviceObject, irp);
+
+ DPRINT ("Waiting for IO Operation...\n");
+ if (status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
+ DPRINT ("Getting IO Status...\n");
+ status = ioStatus.Status;
}
- if (!NT_SUCCESS(status)) {
- DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
- return FALSE;
+ if (!NT_SUCCESS (status))
+ {
+ DbgPrint ("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
+ return FALSE;
}
- DPRINT("Block request succeeded\n");
- return TRUE;
+ DPRINT ("Block request succeeded\n");
+ return TRUE;
}
-
-/* $Id: close.c,v 1.2 2000/09/12 10:12:13 jean Exp $
+/* $Id: close.c,v 1.3 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* FUNCTIONS ****************************************************************/
-NTSTATUS FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
+NTSTATUS
+VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
/*
* FUNCTION: Closes a file
*/
{
- PVFATFCB pFcb;
- PVFATCCB pCcb;
- KIRQL oldIrql;
-
- DPRINT("FsdCloseFile(DeviceExt %x, FileObject %x)\n",
- DeviceExt,FileObject);
-
- //FIXME : update entry in directory ?
- pCcb = (PVFATCCB)(FileObject->FsContext2);
-
- DPRINT("pCcb %x\n",pCcb);
- if (pCcb == NULL)
- {
- return(STATUS_SUCCESS);
- }
-
- pFcb = pCcb->pFcb;
-
- pFcb->RefCount--;
- if(pFcb->RefCount<=0)
- {
- KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
- RemoveEntryList(&pFcb->FcbListEntry);
- KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
- ExFreePool(pFcb);
- }
- ExFreePool(pCcb);
- return STATUS_SUCCESS;
+ PVFATFCB pFcb;
+ PVFATCCB pCcb;
+ KIRQL oldIrql;
+
+ DPRINT ("FsdCloseFile(DeviceExt %x, FileObject %x)\n",
+ DeviceExt, FileObject);
+
+ //FIXME : update entry in directory ?
+ pCcb = (PVFATCCB) (FileObject->FsContext2);
+
+ DPRINT ("pCcb %x\n", pCcb);
+ if (pCcb == NULL)
+ {
+ return (STATUS_SUCCESS);
+ }
+
+ pFcb = pCcb->pFcb;
+
+ pFcb->RefCount--;
+ if (pFcb->RefCount <= 0)
+ {
+ KeAcquireSpinLock (&DeviceExt->FcbListLock, &oldIrql);
+ RemoveEntryList (&pFcb->FcbListEntry);
+ KeReleaseSpinLock (&DeviceExt->FcbListLock, oldIrql);
+ ExFreePool (pFcb);
+ }
+ ExFreePool (pCcb);
+ return STATUS_SUCCESS;
}
-NTSTATUS STDCALL FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Closes a file
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
- PFILE_OBJECT FileObject = Stack->FileObject;
- PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
- NTSTATUS Status;
-
- DPRINT("FsdClose(DeviceObject %x, Irp %x)\n",DeviceObject, Irp);
-
- Status = FsdCloseFile(DeviceExtension,FileObject);
-
- Irp->IoStatus.Status = Status;
- Irp->IoStatus.Information = 0;
-
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return(Status);
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+ PFILE_OBJECT FileObject = Stack->FileObject;
+ PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
+ NTSTATUS Status;
+
+ DPRINT ("FsdClose(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
+
+ Status = VfatCloseFile (DeviceExtension, FileObject);
+
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = 0;
+
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return (Status);
}
/* EOF */
-/* $Id: create.c,v 1.9 2000/12/08 17:12:43 jean Exp $
+/* $Id: create.c,v 1.10 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
-#include <ddk/cctypes.h>
#include <wchar.h>
#include <limits.h>
/* FUNCTIONS ****************************************************************/
-BOOLEAN IsLastEntry(PVOID Block, ULONG Offset)
+BOOLEAN
+IsLastEntry (PVOID Block, ULONG Offset)
/*
* FUNCTION: Determine if the given directory entry is the last
*/
{
- return(((FATDirEntry *)Block)[Offset].Filename[0] == 0);
+ return (((FATDirEntry *) Block)[Offset].Filename[0] == 0);
}
-BOOLEAN IsVolEntry(PVOID Block, ULONG Offset)
+BOOLEAN
+IsVolEntry (PVOID Block, ULONG Offset)
/*
* FUNCTION: Determine if the given directory entry is a vol entry
*/
{
- if( (((FATDirEntry *)Block)[Offset].Attrib)==0x28 ) return TRUE;
- else return FALSE;
+ if ((((FATDirEntry *) Block)[Offset].Attrib) == 0x28)
+ return TRUE;
+ else
+ return FALSE;
}
-BOOLEAN IsDeletedEntry(PVOID Block, ULONG Offset)
+BOOLEAN
+IsDeletedEntry (PVOID Block, ULONG Offset)
/*
* FUNCTION: Determines if the given entry is a deleted one
*/
{
- /* Checks special character */
+ /* Checks special character */
- return ((((FATDirEntry *)Block)[Offset].Filename[0] == 0xe5) || (((FATDirEntry *)Block)[Offset].Filename[0] == 0));
+ return ((((FATDirEntry *) Block)[Offset].Filename[0] == 0xe5) ||
+ (((FATDirEntry *) Block)[Offset].Filename[0] == 0));
}
-BOOLEAN GetEntryName(PVOID Block, PULONG _Offset, PWSTR Name, PULONG _jloop,
- PDEVICE_EXTENSION DeviceExt, ULONG * _StartingSector)
+BOOLEAN
+GetEntryName (PVOID Block, PULONG _Offset, PWSTR Name, PULONG _jloop,
+ PDEVICE_EXTENSION DeviceExt, ULONG * _StartingSector)
/*
* FUNCTION: Retrieves the file name, be it in short or long file name format
*/
{
- FATDirEntry* test;
- slot* test2;
- ULONG Offset = *_Offset;
- ULONG StartingSector = *_StartingSector;
- ULONG jloop = *_jloop;
- ULONG cpos;
-
- test = (FATDirEntry *)Block;
- test2 = (slot *)Block;
-
- *Name = 0;
-
- if (IsDeletedEntry(Block,Offset))
- {
- return(FALSE);
- }
-
- if(test2[Offset].attr == 0x0f)
- {
- vfat_initstr(Name, 256);
- vfat_wcsncpy(Name,test2[Offset].name0_4,5);
- vfat_wcsncat(Name,test2[Offset].name5_10,5,6);
- vfat_wcsncat(Name,test2[Offset].name11_12,11,2);
-
- cpos=0;
- while((test2[Offset].id!=0x41) && (test2[Offset].id!=0x01) &&
- (test2[Offset].attr>0))
- {
- Offset++;
- if(Offset==ENTRIES_PER_SECTOR) {
- Offset=0;
- StartingSector++;//FIXME : nor always the next sector
- jloop++;
- VFATReadSectors(DeviceExt->StorageDevice,StartingSector,1,Block);
- test2 = (slot *)Block;
- }
- cpos++;
- vfat_movstr(Name, 13, 0, cpos*13);
- vfat_wcsncpy(Name, test2[Offset].name0_4, 5);
- vfat_wcsncat(Name,test2[Offset].name5_10,5,6);
- vfat_wcsncat(Name,test2[Offset].name11_12,11,2);
-
- }
-
- if (IsDeletedEntry(Block,Offset+1))
- {
- Offset++;
- *_Offset = Offset;
- *_jloop = jloop;
- *_StartingSector = StartingSector;
- return(FALSE);
- }
-
- *_Offset = Offset;
- *_jloop = jloop;
- *_StartingSector = StartingSector;
-
- return(TRUE);
- }
-
- RtlAnsiToUnicode(Name,test[Offset].Filename,8);
- if (test[Offset].Ext[0]!=' ')
- {
- RtlCatAnsiToUnicode(Name,".",1);
- }
- RtlCatAnsiToUnicode(Name,test[Offset].Ext,3);
-
- *_Offset = Offset;
-
- return(TRUE);
+ FATDirEntry *test;
+ slot *test2;
+ ULONG Offset = *_Offset;
+ ULONG StartingSector = *_StartingSector;
+ ULONG jloop = *_jloop;
+ ULONG cpos;
+
+ test = (FATDirEntry *) Block;
+ test2 = (slot *) Block;
+
+ *Name = 0;
+
+ if (IsDeletedEntry (Block, Offset))
+ {
+ return (FALSE);
+ }
+
+ if (test2[Offset].attr == 0x0f)
+ {
+ vfat_initstr (Name, 256);
+ vfat_wcsncpy (Name, test2[Offset].name0_4, 5);
+ vfat_wcsncat (Name, test2[Offset].name5_10, 5, 6);
+ vfat_wcsncat (Name, test2[Offset].name11_12, 11, 2);
+
+ cpos = 0;
+ while ((test2[Offset].id != 0x41) && (test2[Offset].id != 0x01) &&
+ (test2[Offset].attr > 0))
+ {
+ Offset++;
+ if (Offset == ENTRIES_PER_SECTOR)
+ {
+ Offset = 0;
+ StartingSector++; //FIXME : nor always the next sector
+ jloop++;
+ VFATReadSectors (DeviceExt->StorageDevice,
+ StartingSector, 1, Block);
+ test2 = (slot *) Block;
+ }
+ cpos++;
+ vfat_movstr (Name, 13, 0, cpos * 13);
+ vfat_wcsncpy (Name, test2[Offset].name0_4, 5);
+ vfat_wcsncat (Name, test2[Offset].name5_10, 5, 6);
+ vfat_wcsncat (Name, test2[Offset].name11_12, 11, 2);
+
+ }
+
+ if (IsDeletedEntry (Block, Offset + 1))
+ {
+ Offset++;
+ *_Offset = Offset;
+ *_jloop = jloop;
+ *_StartingSector = StartingSector;
+ return (FALSE);
+ }
+
+ *_Offset = Offset;
+ *_jloop = jloop;
+ *_StartingSector = StartingSector;
+
+ return (TRUE);
+ }
+
+ RtlAnsiToUnicode (Name, test[Offset].Filename, 8);
+ if (test[Offset].Ext[0] != ' ')
+ {
+ RtlCatAnsiToUnicode (Name, ".", 1);
+ }
+ RtlCatAnsiToUnicode (Name, test[Offset].Ext, 3);
+
+ *_Offset = Offset;
+
+ return (TRUE);
}
-NTSTATUS ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb)
+NTSTATUS
+ReadVolumeLabel (PDEVICE_EXTENSION DeviceExt, PVPB Vpb)
/*
* FUNCTION: Read the volume label
*/
{
- ULONG i = 0;
- ULONG j;
- ULONG Size;
- char* block;
- ULONG StartingSector;
- ULONG NextCluster;
-
- Size = DeviceExt->rootDirectorySectors;//FIXME : in fat32, no limit
- StartingSector = DeviceExt->rootStart;
- NextCluster=0;
-
- block = ExAllocatePool(NonPagedPool,BLOCKSIZE);
- DPRINT("FindFile : start at sector %lx, entry %ld\n",StartingSector,i);
- for (j=0; j<Size; j++)
- {
- VFATReadSectors(DeviceExt->StorageDevice,StartingSector,1,block);
-
- for (i=0; i<ENTRIES_PER_SECTOR; i++)
- {
- if (IsVolEntry((PVOID)block,i))
- {
- FATDirEntry *test = (FATDirEntry *)block;
-
- /* copy volume label */
- RtlAnsiToUnicode(Vpb->VolumeLabel,test[i].Filename,8);
- RtlCatAnsiToUnicode(Vpb->VolumeLabel,test[i].Ext,3);
- Vpb->VolumeLabelLength = wcslen(Vpb->VolumeLabel);
-
- ExFreePool(block);
- return(STATUS_SUCCESS);
- }
- if (IsLastEntry((PVOID)block,i))
- {
- *(Vpb->VolumeLabel) = 0;
- Vpb->VolumeLabelLength = 0;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
- }
- }
- // not found in this sector, try next :
-
- /* directory can be fragmented although it is best to keep them
- unfragmented */
- StartingSector++;
- if (DeviceExt->FatType ==FAT32)
- {
- if(StartingSector==ClusterToSector(DeviceExt,NextCluster+1))
- {
- NextCluster = GetNextCluster(DeviceExt,NextCluster);
- if (NextCluster == 0||NextCluster==0xffffffff)
- {
- *(Vpb->VolumeLabel) = 0;
- Vpb->VolumeLabelLength = 0;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
- }
- StartingSector = ClusterToSector(DeviceExt,NextCluster);
- }
- }
- }
- *(Vpb->VolumeLabel) = 0;
- Vpb->VolumeLabelLength = 0;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
+ ULONG i = 0;
+ ULONG j;
+ ULONG Size;
+ char *block;
+ ULONG StartingSector;
+ ULONG NextCluster;
+
+ Size = DeviceExt->rootDirectorySectors; //FIXME : in fat32, no limit
+ StartingSector = DeviceExt->rootStart;
+ NextCluster = 0;
+
+ block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
+ for (j = 0; j < Size; j++)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
+
+ for (i = 0; i < ENTRIES_PER_SECTOR; i++)
+ {
+ if (IsVolEntry ((PVOID) block, i))
+ {
+ FATDirEntry *test = (FATDirEntry *) block;
+
+ /* copy volume label */
+ RtlAnsiToUnicode (Vpb->VolumeLabel, test[i].Filename, 8);
+ RtlCatAnsiToUnicode (Vpb->VolumeLabel, test[i].Ext, 3);
+ Vpb->VolumeLabelLength = wcslen (Vpb->VolumeLabel);
+
+ ExFreePool (block);
+ return (STATUS_SUCCESS);
+ }
+ if (IsLastEntry ((PVOID) block, i))
+ {
+ *(Vpb->VolumeLabel) = 0;
+ Vpb->VolumeLabelLength = 0;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ }
+ // not found in this sector, try next :
+
+ /* directory can be fragmented although it is best to keep them
+ unfragmented */
+ StartingSector++;
+ if (DeviceExt->FatType == FAT32)
+ {
+ if (StartingSector == ClusterToSector (DeviceExt, NextCluster + 1))
+ {
+ NextCluster = GetNextCluster (DeviceExt, NextCluster);
+ if (NextCluster == 0 || NextCluster == 0xffffffff)
+ {
+ *(Vpb->VolumeLabel) = 0;
+ Vpb->VolumeLabelLength = 0;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ StartingSector = ClusterToSector (DeviceExt, NextCluster);
+ }
+ }
+ }
+ *(Vpb->VolumeLabel) = 0;
+ Vpb->VolumeLabelLength = 0;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
}
-NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
- PVFATFCB Parent, PWSTR FileToFind,ULONG *StartSector,ULONG *Entry)
+NTSTATUS
+FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
+ PVFATFCB Parent, PWSTR FileToFind, ULONG * StartSector,
+ ULONG * Entry)
/*
* FUNCTION: Find a file
*/
{
- ULONG i, j;
- ULONG Size;
- char* block;
- WCHAR name[256];
- ULONG StartingSector;
- ULONG NextCluster;
- WCHAR TempStr[2];
-
- DPRINT("FindFile(Parent %x, FileToFind '%S')\n",Parent,FileToFind);
-
- if (wcslen(FileToFind)==0)
- {
- CHECKPOINT;
- TempStr[0] = (WCHAR)'.';
- TempStr[1] = 0;
- FileToFind=(PWSTR)&TempStr;
- }
- if (Parent != NULL)
- {
- DPRINT("Parent->entry.FirstCluster %d\n",Parent->entry.FirstCluster);
- }
-
- DPRINT("FindFile '%S'\n", FileToFind);
- if (Parent == NULL||Parent->entry.FirstCluster==1)
- {
- CHECKPOINT;
- Size = DeviceExt->rootDirectorySectors; /* FIXME : in fat32, no limit */
- StartingSector = DeviceExt->rootStart;
- NextCluster=0;
- if(FileToFind[0]==0 ||(FileToFind[0]=='\\' && FileToFind[1]==0) ||
- (FileToFind[0]=='.' && FileToFind[1]==0))
- {
- /* it's root : complete essentials fields then return ok */
- CHECKPOINT;
- memset(Fcb,0,sizeof(VFATFCB));
- memset(Fcb->entry.Filename,' ',11);
- Fcb->entry.FileSize=DeviceExt->rootDirectorySectors*BLOCKSIZE;
- Fcb->entry.Attrib=FILE_ATTRIBUTE_DIRECTORY;
- if (DeviceExt->FatType == FAT32)
- Fcb->entry.FirstCluster=2;
- else
- Fcb->entry.FirstCluster=1; /* FIXME : is 1 the good value for mark root? */
- if(StartSector)
- *StartSector=StartingSector;
- if(Entry)
- *Entry=0;
- return(STATUS_SUCCESS);
- }
- }
- else
- {
- DPRINT("Parent->entry.FileSize %x\n",Parent->entry.FileSize);
-
- Size = ULONG_MAX;
- if (DeviceExt->FatType == FAT32)
- NextCluster = Parent->entry.FirstCluster
- +Parent->entry.FirstClusterHigh*65536;
- else
- NextCluster = Parent->entry.FirstCluster;
- StartingSector = ClusterToSector(DeviceExt, NextCluster);
- if(Parent->entry.FirstCluster==1 && DeviceExt->FatType!=FAT32)
- {
- /* read of root directory in FAT16 or FAT12 */
- StartingSector=DeviceExt->rootStart;
- }
- }
- CHECKPOINT;
- block = ExAllocatePool(NonPagedPool,BLOCKSIZE);
- CHECKPOINT;
- if (StartSector && (*StartSector)) StartingSector=*StartSector;
- i=(Entry)?(*Entry):0;
- DPRINT("FindFile : start at sector %lx, entry %ld\n",StartingSector,i);
- for (j=0; j<Size; j++)
- {
- VFATReadSectors(DeviceExt->StorageDevice,StartingSector,1,block);
-
- for (i=(Entry)?(*Entry):0; i<ENTRIES_PER_SECTOR; i++)
- {
- if (IsVolEntry((PVOID)block,i))
- continue;
- if (IsLastEntry((PVOID)block,i))
- {
- if(StartSector) *StartSector=StartingSector;
- if(Entry) *Entry=i;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
- }
- if (GetEntryName((PVOID)block,&i,name,&j,DeviceExt,&StartingSector))
- {
- if (wstrcmpjoki(name,FileToFind))
- {
- /* In the case of a long filename, the firstcluster is stored in
- the next record -- where it's short name is */
- if(((FATDirEntry *)block)[i].Attrib==0x0f) i++;
- if( i==(ENTRIES_PER_SECTOR))
- {
- /* entry is in next sector */
- StartingSector++;
- /* FIXME : treat case of next sector fragmented */
- VFATReadSectors(DeviceExt->StorageDevice,StartingSector,1,block);
- i=0;
- }
- memcpy(&Fcb->entry,&((FATDirEntry *)block)[i],
- sizeof(FATDirEntry));
- vfat_wcsncpy(Fcb->ObjectName,name,MAX_PATH);
- if(StartSector) *StartSector=StartingSector;
- if(Entry) *Entry=i;
- ExFreePool(block);
- return(STATUS_SUCCESS);
- }
- }
- }
- /* not found in this sector, try next : */
-
- /* directory can be fragmented although it is best to keep them
- unfragmented */
- if(Entry) *Entry=0;
- StartingSector++;
- if ((Parent != NULL && Parent->entry.FirstCluster!=1)
- || DeviceExt->FatType ==FAT32)
- {
- if(StartingSector==ClusterToSector(DeviceExt,NextCluster+1))
- {
- NextCluster = GetNextCluster(DeviceExt,NextCluster);
- if (NextCluster == 0||NextCluster==0xffffffff)
+ ULONG i, j;
+ ULONG Size;
+ char *block;
+ WCHAR name[256];
+ ULONG StartingSector;
+ ULONG NextCluster;
+ WCHAR TempStr[2];
+
+ DPRINT ("FindFile(Parent %x, FileToFind '%S')\n", Parent, FileToFind);
+
+ if (wcslen (FileToFind) == 0)
+ {
+ CHECKPOINT;
+ TempStr[0] = (WCHAR) '.';
+ TempStr[1] = 0;
+ FileToFind = (PWSTR) & TempStr;
+ }
+ if (Parent != NULL)
+ {
+ DPRINT ("Parent->entry.FirstCluster %d\n", Parent->entry.FirstCluster);
+ }
+
+ DPRINT ("FindFile '%S'\n", FileToFind);
+ if (Parent == NULL || Parent->entry.FirstCluster == 1)
+ {
+ CHECKPOINT;
+ Size = DeviceExt->rootDirectorySectors; /* FIXME : in fat32, no limit */
+ StartingSector = DeviceExt->rootStart;
+ NextCluster = 0;
+ if (FileToFind[0] == 0 || (FileToFind[0] == '\\' && FileToFind[1] == 0)
+ || (FileToFind[0] == '.' && FileToFind[1] == 0))
+ {
+ /* it's root : complete essentials fields then return ok */
+ CHECKPOINT;
+ memset (Fcb, 0, sizeof (VFATFCB));
+ memset (Fcb->entry.Filename, ' ', 11);
+ Fcb->entry.FileSize = DeviceExt->rootDirectorySectors * BLOCKSIZE;
+ Fcb->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
+ if (DeviceExt->FatType == FAT32)
+ Fcb->entry.FirstCluster = 2;
+ else
+ Fcb->entry.FirstCluster = 1; /* FIXME : is 1 the good value for mark root? */
+ if (StartSector)
+ *StartSector = StartingSector;
+ if (Entry)
+ *Entry = 0;
+ return (STATUS_SUCCESS);
+ }
+ }
+ else
+ {
+ DPRINT ("Parent->entry.FileSize %x\n", Parent->entry.FileSize);
+
+ Size = ULONG_MAX;
+ if (DeviceExt->FatType == FAT32)
+ NextCluster = Parent->entry.FirstCluster
+ + Parent->entry.FirstClusterHigh * 65536;
+ else
+ NextCluster = Parent->entry.FirstCluster;
+ StartingSector = ClusterToSector (DeviceExt, NextCluster);
+ if (Parent->entry.FirstCluster == 1 && DeviceExt->FatType != FAT32)
+ {
+ /* read of root directory in FAT16 or FAT12 */
+ StartingSector = DeviceExt->rootStart;
+ }
+ }
+ CHECKPOINT;
+ block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ CHECKPOINT;
+ if (StartSector && (*StartSector))
+ StartingSector = *StartSector;
+ i = (Entry) ? (*Entry) : 0;
+ DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
+ for (j = 0; j < Size; j++)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
+
+ for (i = (Entry) ? (*Entry) : 0; i < ENTRIES_PER_SECTOR; i++)
+ {
+ if (IsVolEntry ((PVOID) block, i))
+ continue;
+ if (IsLastEntry ((PVOID) block, i))
+ {
+ if (StartSector)
+ *StartSector = StartingSector;
+ if (Entry)
+ *Entry = i;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ if (GetEntryName
+ ((PVOID) block, &i, name, &j, DeviceExt, &StartingSector))
+ {
+ if (wstrcmpjoki (name, FileToFind))
+ {
+ /* In the case of a long filename, the firstcluster is stored in
+ the next record -- where it's short name is */
+ if (((FATDirEntry *) block)[i].Attrib == 0x0f)
+ i++;
+ if (i == (ENTRIES_PER_SECTOR))
{
- if(StartSector) *StartSector=StartingSector;
- if(Entry) *Entry=i;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
+ /* entry is in next sector */
+ StartingSector++;
+ /* FIXME : treat case of next sector fragmented */
+ VFATReadSectors (DeviceExt->StorageDevice,
+ StartingSector, 1, block);
+ i = 0;
}
- StartingSector = ClusterToSector(DeviceExt,NextCluster);
- }
- }
- }
- if(StartSector) *StartSector=StartingSector;
- if(Entry) *Entry=i;
- ExFreePool(block);
- return(STATUS_UNSUCCESSFUL);
+ memcpy (&Fcb->entry, &((FATDirEntry *) block)[i],
+ sizeof (FATDirEntry));
+ vfat_wcsncpy (Fcb->ObjectName, name, MAX_PATH);
+ if (StartSector)
+ *StartSector = StartingSector;
+ if (Entry)
+ *Entry = i;
+ ExFreePool (block);
+ return (STATUS_SUCCESS);
+ }
+ }
+ }
+ /* not found in this sector, try next : */
+
+ /* directory can be fragmented although it is best to keep them
+ unfragmented */
+ if (Entry)
+ *Entry = 0;
+ StartingSector++;
+ if ((Parent != NULL && Parent->entry.FirstCluster != 1)
+ || DeviceExt->FatType == FAT32)
+ {
+ if (StartingSector == ClusterToSector (DeviceExt, NextCluster + 1))
+ {
+ NextCluster = GetNextCluster (DeviceExt, NextCluster);
+ if (NextCluster == 0 || NextCluster == 0xffffffff)
+ {
+ if (StartSector)
+ *StartSector = StartingSector;
+ if (Entry)
+ *Entry = i;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ StartingSector = ClusterToSector (DeviceExt, NextCluster);
+ }
+ }
+ }
+ if (StartSector)
+ *StartSector = StartingSector;
+ if (Entry)
+ *Entry = i;
+ ExFreePool (block);
+ return (STATUS_UNSUCCESSFUL);
}
-NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
- PWSTR FileName)
+NTSTATUS
+FsdOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+ PWSTR FileName)
/*
* FUNCTION: Opens a file
*/
{
- PWSTR current = NULL;
- PWSTR next;
- PWSTR string;
- PVFATFCB ParentFcb;
- PVFATFCB Fcb,pRelFcb;
- PVFATFCB Temp;
- PVFATCCB newCCB,pRelCcb;
- NTSTATUS Status;
- PFILE_OBJECT pRelFileObject;
- PWSTR AbsFileName=NULL;
- short i,j;
- PLIST_ENTRY current_entry;
- KIRQL oldIrql;
-
- DPRINT("FsdOpenFile(%08lx, %08lx, %S)\n",
- DeviceExt,
- FileObject,
- FileName);
-
- /* FIXME : treat relative name */
- if(FileObject->RelatedFileObject)
- {
- DbgPrint("try related for %S\n",FileName);
- pRelFileObject=FileObject->RelatedFileObject;
- pRelCcb=pRelFileObject->FsContext2;
- assert(pRelCcb);
- pRelFcb=pRelCcb->pFcb;
- assert(pRelFcb);
- /*
- * verify related object is a directory and target name don't start with \.
- */
- if( !(pRelFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)
- || (FileName[0]!= '\\') )
- {
- Status=STATUS_INVALID_PARAMETER;
- return Status;
- }
- /* construct absolute path name */
- AbsFileName=ExAllocatePool(NonPagedPool,MAX_PATH);
- for (i=0;pRelFcb->PathName[i];i++)
- AbsFileName[i]=pRelFcb->PathName[i];
- AbsFileName[i++]='\\';
- for (j=0;FileName[j]&&i<MAX_PATH;j++)
- AbsFileName[i++]=FileName[j];
- assert(i<MAX_PATH);
- AbsFileName[i]=0;
- FileName=AbsFileName;
- }
-
- /*
- * try first to find an existing FCB in memory
- */
- CHECKPOINT;
-
- KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
- current_entry = DeviceExt->FcbListHead.Flink;
- while (current_entry != &DeviceExt->FcbListHead)
- {
- Fcb = CONTAINING_RECORD(current_entry, VFATFCB, FcbListEntry);
-
- DPRINT("Scanning %x\n", Fcb);
- DPRINT("Scanning %S\n", Fcb->PathName);
-
- if (DeviceExt==Fcb->pDevExt
- && wstrcmpi(FileName,Fcb->PathName))
- {
- Fcb->RefCount++;
- KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
- FileObject->FsContext =(PVOID) &Fcb->NTRequiredFCB;
- newCCB = ExAllocatePool(NonPagedPool,sizeof(VFATCCB));
- memset(newCCB,0,sizeof(VFATCCB));
- FileObject->FsContext2 = newCCB;
- newCCB->pFcb=Fcb;
- newCCB->PtrFileObject=FileObject;
- if(AbsFileName)ExFreePool(AbsFileName);
- return(STATUS_SUCCESS);
- }
-
- current_entry = current_entry->Flink;
- }
- KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
-
-CHECKPOINT;
-DPRINT("FileName %S\n", FileName);
-
- string = FileName;
- ParentFcb = NULL;
- Fcb = ExAllocatePool(NonPagedPool, sizeof(VFATFCB));
- memset(Fcb,0,sizeof(VFATFCB));
- Fcb->ObjectName=Fcb->PathName;
- next = &string[0];
-
- CHECKPOINT;
- if(*next==0) // root
- {
- memset(Fcb->entry.Filename,' ',11);
- Fcb->entry.FileSize=DeviceExt->rootDirectorySectors*BLOCKSIZE;
- Fcb->entry.Attrib=FILE_ATTRIBUTE_DIRECTORY;
- if (DeviceExt->FatType == FAT32)Fcb->entry.FirstCluster=2;
- else Fcb->entry.FirstCluster=1;
- //FIXME : is 1 the good value for mark root?
- ParentFcb=Fcb;
- Fcb=NULL;
- }
- else
- {
- while (TRUE)
- {
- CHECKPOINT;
- *next = '\\';
- current = next+1;
- next = wcschr(next+1,'\\');
- if (next!=NULL)
+ PWSTR current = NULL;
+ PWSTR next;
+ PWSTR string;
+ PVFATFCB ParentFcb;
+ PVFATFCB Fcb, pRelFcb;
+ PVFATFCB Temp;
+ PVFATCCB newCCB, pRelCcb;
+ NTSTATUS Status;
+ PFILE_OBJECT pRelFileObject;
+ PWSTR AbsFileName = NULL;
+ short i, j;
+ PLIST_ENTRY current_entry;
+ KIRQL oldIrql;
+
+ DPRINT ("FsdOpenFile(%08lx, %08lx, %S)\n", DeviceExt, FileObject, FileName);
+
+ /* FIXME : treat relative name */
+ if (FileObject->RelatedFileObject)
+ {
+ DbgPrint ("try related for %S\n", FileName);
+ pRelFileObject = FileObject->RelatedFileObject;
+ pRelCcb = pRelFileObject->FsContext2;
+ assert (pRelCcb);
+ pRelFcb = pRelCcb->pFcb;
+ assert (pRelFcb);
+ /*
+ * verify related object is a directory and target name don't start with
+ * \.
+ */
+ if (!(pRelFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+ || (FileName[0] != '\\'))
{
- *next=0;
+ Status = STATUS_INVALID_PARAMETER;
+ return Status;
}
+ /* construct absolute path name */
+ AbsFileName = ExAllocatePool (NonPagedPool, MAX_PATH);
+ for (i = 0; pRelFcb->PathName[i]; i++)
+ AbsFileName[i] = pRelFcb->PathName[i];
+ AbsFileName[i++] = '\\';
+ for (j = 0; FileName[j] && i < MAX_PATH; j++)
+ AbsFileName[i++] = FileName[j];
+ assert (i < MAX_PATH);
+ AbsFileName[i] = 0;
+ FileName = AbsFileName;
+ }
+
+ /*
+ * try first to find an existing FCB in memory
+ */
+ CHECKPOINT;
+
+ KeAcquireSpinLock (&DeviceExt->FcbListLock, &oldIrql);
+ current_entry = DeviceExt->FcbListHead.Flink;
+ while (current_entry != &DeviceExt->FcbListHead)
+ {
+ Fcb = CONTAINING_RECORD (current_entry, VFATFCB, FcbListEntry);
+
+ DPRINT ("Scanning %x\n", Fcb);
+ DPRINT ("Scanning %S\n", Fcb->PathName);
+
+ if (DeviceExt == Fcb->pDevExt && wstrcmpi (FileName, Fcb->PathName))
+ {
+ Fcb->RefCount++;
+ KeReleaseSpinLock (&DeviceExt->FcbListLock, oldIrql);
+ FileObject->FsContext = (PVOID)&Fcb->RFCB;
+ newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
+ memset (newCCB, 0, sizeof (VFATCCB));
+ FileObject->FsContext2 = newCCB;
+ newCCB->pFcb = Fcb;
+ newCCB->PtrFileObject = FileObject;
+ if (AbsFileName)
+ ExFreePool (AbsFileName);
+ return (STATUS_SUCCESS);
+ }
+
+ current_entry = current_entry->Flink;
+ }
+ KeReleaseSpinLock (&DeviceExt->FcbListLock, oldIrql);
+
+ CHECKPOINT;
+ DPRINT ("FileName %S\n", FileName);
+
+ string = FileName;
+ ParentFcb = NULL;
+ Fcb = ExAllocatePool (NonPagedPool, sizeof (VFATFCB));
+ memset (Fcb, 0, sizeof (VFATFCB));
+ Fcb->ObjectName = Fcb->PathName;
+ next = &string[0];
+
+ CHECKPOINT;
+ if (*next == 0) // root
+ {
+ memset (Fcb->entry.Filename, ' ', 11);
+ Fcb->entry.FileSize = DeviceExt->rootDirectorySectors * BLOCKSIZE;
+ Fcb->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
+ if (DeviceExt->FatType == FAT32)
+ Fcb->entry.FirstCluster = 2;
else
+ Fcb->entry.FirstCluster = 1;
+ /* FIXME : is 1 the good value for mark root? */
+ ParentFcb = Fcb;
+ Fcb = NULL;
+ }
+ else
+ {
+ while (TRUE)
{
- /* reached the last path component */
- DPRINT("exiting: current '%S'\n",current);
- break;
+ CHECKPOINT;
+ *next = '\\';
+ current = next + 1;
+ next = wcschr (next + 1, '\\');
+ if (next != NULL)
+ {
+ *next = 0;
+ }
+ else
+ {
+ /* reached the last path component */
+ DPRINT ("exiting: current '%S'\n", current);
+ break;
+ }
+
+ DPRINT ("current '%S'\n", current);
+ Status = FindFile (DeviceExt, Fcb, ParentFcb, current, NULL, NULL);
+ if (Status != STATUS_SUCCESS)
+ {
+ CHECKPOINT;
+ if (Fcb != NULL)
+ ExFreePool (Fcb);
+ if (ParentFcb != NULL)
+ ExFreePool (ParentFcb);
+ if (AbsFileName)
+ ExFreePool (AbsFileName);
+
+ DPRINT ("error STATUS_OBJECT_PATH_NOT_FOUND\n");
+ return STATUS_OBJECT_PATH_NOT_FOUND;
+ }
+ Temp = Fcb;
+ CHECKPOINT;
+ if (ParentFcb == NULL)
+ {
+ CHECKPOINT;
+ Fcb = ExAllocatePool (NonPagedPool, sizeof (VFATFCB));
+ memset (Fcb, 0, sizeof (VFATFCB));
+ Fcb->ObjectName = Fcb->PathName;
+ }
+ else
+ Fcb = ParentFcb;
+ CHECKPOINT;
+ ParentFcb = Temp;
}
- DPRINT("current '%S'\n",current);
- Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
+ /* searching for last path component */
+ DPRINT ("current '%S'\n", current);
+ Status = FindFile (DeviceExt, Fcb, ParentFcb, current, NULL, NULL);
if (Status != STATUS_SUCCESS)
{
- CHECKPOINT;
- if (Fcb != NULL)
- ExFreePool(Fcb);
- if (ParentFcb != NULL)
- ExFreePool(ParentFcb);
- if(AbsFileName)
- ExFreePool(AbsFileName);
-
- DPRINT("error STATUS_OBJECT_PATH_NOT_FOUND\n");
- return STATUS_OBJECT_PATH_NOT_FOUND;
+ /* file does not exist */
+ CHECKPOINT;
+ if (Fcb != NULL)
+ ExFreePool (Fcb);
+ if (ParentFcb != NULL)
+ ExFreePool (ParentFcb);
+ if (AbsFileName)
+ ExFreePool (AbsFileName);
+
+ return STATUS_OBJECT_NAME_NOT_FOUND;
}
+
Temp = Fcb;
-CHECKPOINT;
if (ParentFcb == NULL)
{
- CHECKPOINT;
- Fcb = ExAllocatePool(NonPagedPool,sizeof(VFATFCB));
- memset(Fcb,0,sizeof(VFATFCB));
- Fcb->ObjectName=Fcb->PathName;
+ CHECKPOINT;
+ Fcb = ExAllocatePool (NonPagedPool, sizeof (VFATFCB));
+ memset (Fcb, 0, sizeof (VFATFCB));
+ Fcb->ObjectName = Fcb->PathName;
}
else
- Fcb = ParentFcb;
-CHECKPOINT;
+ Fcb = ParentFcb;
ParentFcb = Temp;
- }
-
- /* searching for last path component */
- DPRINT("current '%S'\n",current);
- Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
- if (Status != STATUS_SUCCESS)
- {
- /* file does not exist */
- CHECKPOINT;
- if (Fcb != NULL)
- ExFreePool(Fcb);
- if (ParentFcb != NULL)
- ExFreePool(ParentFcb);
- if(AbsFileName)
- ExFreePool(AbsFileName);
-
- return STATUS_OBJECT_NAME_NOT_FOUND;
- }
-
- Temp = Fcb;
- if (ParentFcb == NULL)
- {
- CHECKPOINT;
- Fcb = ExAllocatePool(NonPagedPool,sizeof(VFATFCB));
- memset(Fcb,0,sizeof(VFATFCB));
- Fcb->ObjectName=Fcb->PathName;
- }
- else
- Fcb = ParentFcb;
- ParentFcb = Temp;
- }
-
-
- FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
- newCCB = ExAllocatePool(NonPagedPool,sizeof(VFATCCB));
- memset(newCCB,0,sizeof(VFATCCB));
- FileObject->FsContext2 = newCCB;
- newCCB->pFcb=ParentFcb;
- newCCB->PtrFileObject=FileObject;
- ParentFcb->RefCount++;
- //FIXME : initialize all fields in FCB and CCB
-
- KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
- InsertTailList(&DeviceExt->FcbListHead, &ParentFcb->FcbListEntry);
- KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
-
- vfat_wcsncpy(ParentFcb->PathName,FileName,MAX_PATH);
- ParentFcb->ObjectName=ParentFcb->PathName+(current-FileName);
- ParentFcb->pDevExt=DeviceExt;
- DPRINT("file open, fcb=%x\n",ParentFcb);
- DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
- if(Fcb)
- ExFreePool(Fcb);
- if(AbsFileName)
- ExFreePool(AbsFileName);
- CHECKPOINT;
-
- return(STATUS_SUCCESS);
+ }
+
+
+ FileObject->FsContext = (PVOID)&ParentFcb->RFCB;
+ newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
+ memset (newCCB, 0, sizeof (VFATCCB));
+ FileObject->FsContext2 = newCCB;
+ newCCB->pFcb = ParentFcb;
+ newCCB->PtrFileObject = FileObject;
+ ParentFcb->RefCount++;
+ /* FIXME : initialize all fields in FCB and CCB */
+
+ KeAcquireSpinLock (&DeviceExt->FcbListLock, &oldIrql);
+ InsertTailList (&DeviceExt->FcbListHead, &ParentFcb->FcbListEntry);
+ KeReleaseSpinLock (&DeviceExt->FcbListLock, oldIrql);
+
+ vfat_wcsncpy (ParentFcb->PathName, FileName, MAX_PATH);
+ ParentFcb->ObjectName = ParentFcb->PathName + (current - FileName);
+ ParentFcb->pDevExt = DeviceExt;
+ Status = CcInitializeFileCache(FileObject, &ParentFcb->RFCB.Bcb);
+ if (!NT_SUCCESS(Status))
+ {
+ DbgPrint("CcInitializeFileCache failed\n");
+ KeBugCheck(0);
+ }
+ DPRINT ("file open, fcb=%x\n", ParentFcb);
+ DPRINT ("FileSize %d\n", ParentFcb->entry.FileSize);
+ if (Fcb)
+ ExFreePool (Fcb);
+ if (AbsFileName)
+ ExFreePool (AbsFileName);
+ CHECKPOINT;
+
+ return (STATUS_SUCCESS);
}
-NTSTATUS FsdCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS
+VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Create or open a file
*/
{
- PIO_STACK_LOCATION Stack;
- PFILE_OBJECT FileObject;
- NTSTATUS Status=STATUS_SUCCESS;
- PDEVICE_EXTENSION DeviceExt;
- ULONG RequestedDisposition,RequestedOptions;
- PVFATCCB pCcb;
- PVFATFCB pFcb;
-
- Stack = IoGetCurrentIrpStackLocation(Irp);
- assert(Stack);
- RequestedDisposition = ((Stack->Parameters.Create.Options>>24)&0xff);
- RequestedOptions=Stack->Parameters.Create.Options&FILE_VALID_OPTION_FLAGS;
- if( (RequestedOptions&FILE_DIRECTORY_FILE)
- && RequestedDisposition==FILE_SUPERSEDE)
- return STATUS_INVALID_PARAMETER;
- FileObject = Stack->FileObject;
- DeviceExt = DeviceObject->DeviceExtension;
- assert(DeviceExt);
-
- Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
-
- CHECKPOINT;
- Irp->IoStatus.Information = 0;
- if (Status == STATUS_OBJECT_PATH_NOT_FOUND)
- {
- Irp->IoStatus.Status = Status;
- return Status;
- }
-
- CHECKPOINT;
- if(!NT_SUCCESS(Status))
- {
- if(RequestedDisposition==FILE_CREATE
- ||RequestedDisposition==FILE_OPEN_IF
- ||RequestedDisposition==FILE_OVERWRITE_IF
- ||RequestedDisposition==FILE_SUPERSEDE)
- {
-CHECKPOINT;
- Status=addEntry(DeviceExt,FileObject,RequestedOptions
- ,(Stack->Parameters.Create.FileAttributes & FILE_ATTRIBUTE_VALID_FLAGS));
- if(NT_SUCCESS(Status))
- Irp->IoStatus.Information = FILE_CREATED;
- // FIXME set size if AllocationSize requested
- // FIXME set extended attributes ?
- // FIXME set share access
- // IoSetShareAccess(DesiredAccess,ShareAccess,FileObject
- // ,((PVfatCCB)(FileObject->FsContext2))->pFcb->FCBShareAccess);
- }
- }
- else
- {
- if(RequestedDisposition==FILE_CREATE)
- {
- Irp->IoStatus.Information = FILE_EXISTS;
- Status=STATUS_OBJECT_NAME_COLLISION;
- }
- pCcb=FileObject->FsContext2;
- pFcb=pCcb->pFcb;
- if(RequestedDisposition==FILE_SUPERSEDE)
- {
- ULONG Cluster,NextCluster;
- /* FIXME set size to 0 and free clusters */
- pFcb->entry.FileSize = 0;
- if (DeviceExt->FatType == FAT32)
- Cluster = pFcb->entry.FirstCluster
- +pFcb->entry.FirstClusterHigh*65536;
- else
- Cluster = pFcb->entry.FirstCluster;
- pFcb->entry.FirstCluster = 0;
- pFcb->entry.FirstClusterHigh = 0;
- updEntry(DeviceExt,FileObject);
- while (Cluster != 0xffffffff && Cluster >1)
- {
- NextCluster = GetNextCluster(DeviceExt, Cluster);
- WriteCluster(DeviceExt, Cluster,0);
- Cluster = NextCluster;
- }
- }
- if( (RequestedOptions&FILE_NON_DIRECTORY_FILE)
- && (pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
- {
- Status=STATUS_FILE_IS_A_DIRECTORY;
- }
- if( (RequestedOptions&FILE_DIRECTORY_FILE)
- && !(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
- {
- Status=STATUS_NOT_A_DIRECTORY;
- }
- // FIXME : test share access
- // FIXME : test write access if requested
- if(!NT_SUCCESS(Status))
- FsdCloseFile(DeviceExt,FileObject);
- else Irp->IoStatus.Information = FILE_OPENED;
- // FIXME : make supersed or overwrite if requested
- }
-
-CHECKPOINT;
- Irp->IoStatus.Status = Status;
-
- return Status;
+ PIO_STACK_LOCATION Stack;
+ PFILE_OBJECT FileObject;
+ NTSTATUS Status = STATUS_SUCCESS;
+ PDEVICE_EXTENSION DeviceExt;
+ ULONG RequestedDisposition, RequestedOptions;
+ PVFATCCB pCcb;
+ PVFATFCB pFcb;
+
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ assert (Stack);
+ RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
+ RequestedOptions =
+ Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
+ if ((RequestedOptions & FILE_DIRECTORY_FILE)
+ && RequestedDisposition == FILE_SUPERSEDE)
+ return STATUS_INVALID_PARAMETER;
+ FileObject = Stack->FileObject;
+ DeviceExt = DeviceObject->DeviceExtension;
+ assert (DeviceExt);
+
+ Status = FsdOpenFile (DeviceExt, FileObject, FileObject->FileName.Buffer);
+
+ CHECKPOINT;
+ Irp->IoStatus.Information = 0;
+ if (Status == STATUS_OBJECT_PATH_NOT_FOUND)
+ {
+ Irp->IoStatus.Status = Status;
+ return Status;
+ }
+
+ CHECKPOINT;
+ if (!NT_SUCCESS (Status))
+ {
+ if (RequestedDisposition == FILE_CREATE
+ || RequestedDisposition == FILE_OPEN_IF
+ || RequestedDisposition == FILE_OVERWRITE_IF
+ || RequestedDisposition == FILE_SUPERSEDE)
+ {
+ CHECKPOINT;
+ Status =
+ addEntry (DeviceExt, FileObject, RequestedOptions,
+ (Stack->Parameters.
+ Create.FileAttributes & FILE_ATTRIBUTE_VALID_FLAGS));
+ if (NT_SUCCESS (Status))
+ Irp->IoStatus.Information = FILE_CREATED;
+ /* FIXME set size if AllocationSize requested */
+ /* FIXME set extended attributes? */
+ /* FIXME set share access */
+ /* IoSetShareAccess(DesiredAccess,ShareAccess,FileObject,
+ * ((PVfatCCB)(FileObject->FsContext2))->pFcb->FCBShareAccess);
+ */
+ }
+ }
+ else
+ {
+ if (RequestedDisposition == FILE_CREATE)
+ {
+ Irp->IoStatus.Information = FILE_EXISTS;
+ Status = STATUS_OBJECT_NAME_COLLISION;
+ }
+ pCcb = FileObject->FsContext2;
+ pFcb = pCcb->pFcb;
+ if (RequestedDisposition == FILE_SUPERSEDE)
+ {
+ ULONG Cluster, NextCluster;
+ /* FIXME set size to 0 and free clusters */
+ pFcb->entry.FileSize = 0;
+ if (DeviceExt->FatType == FAT32)
+ Cluster = pFcb->entry.FirstCluster
+ + pFcb->entry.FirstClusterHigh * 65536;
+ else
+ Cluster = pFcb->entry.FirstCluster;
+ pFcb->entry.FirstCluster = 0;
+ pFcb->entry.FirstClusterHigh = 0;
+ updEntry (DeviceExt, FileObject);
+ while (Cluster != 0xffffffff && Cluster > 1)
+ {
+ NextCluster = GetNextCluster (DeviceExt, Cluster);
+ WriteCluster (DeviceExt, Cluster, 0);
+ Cluster = NextCluster;
+ }
+ }
+ if ((RequestedOptions & FILE_NON_DIRECTORY_FILE)
+ && (pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ Status = STATUS_FILE_IS_A_DIRECTORY;
+ }
+ if ((RequestedOptions & FILE_DIRECTORY_FILE)
+ && !(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ Status = STATUS_NOT_A_DIRECTORY;
+ }
+ /* FIXME : test share access */
+ /* FIXME : test write access if requested */
+ if (!NT_SUCCESS (Status))
+ VfatCloseFile (DeviceExt, FileObject);
+ else
+ Irp->IoStatus.Information = FILE_OPENED;
+ /* FIXME : make supersed or overwrite if requested */
+ }
+
+ Irp->IoStatus.Status = Status;
+
+ return Status;
}
-NTSTATUS STDCALL FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Create or open a file
*/
{
- NTSTATUS Status=STATUS_SUCCESS;
- PDEVICE_EXTENSION DeviceExt;
-
- assert(DeviceObject);
- assert(Irp);
-
- if (DeviceObject->Size==sizeof(DEVICE_OBJECT))
- {
- /* DeviceObject represent FileSystem instead of logical volume */
- DbgPrint("FsdCreate called with file system\n");
- Irp->IoStatus.Status=Status;
- Irp->IoStatus.Information=FILE_OPENED;
- IoCompleteRequest(Irp,IO_NO_INCREMENT);
- return(Status);
- }
-
- DeviceExt = DeviceObject->DeviceExtension;
- assert(DeviceExt);
- ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
-
- Status = FsdCreateFile (DeviceObject, Irp);
-
- ExReleaseResourceLite(&DeviceExt->DirResource);
-
- Irp->IoStatus.Status = Status;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
- return Status;
+ NTSTATUS Status = STATUS_SUCCESS;
+ PDEVICE_EXTENSION DeviceExt;
+
+ assert (DeviceObject);
+ assert (Irp);
+
+ if (DeviceObject->Size == sizeof (DEVICE_OBJECT))
+ {
+ /* DeviceObject represents FileSystem instead of logical volume */
+ DbgPrint ("FsdCreate called with file system\n");
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = FILE_OPENED;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return (Status);
+ }
+
+ DeviceExt = DeviceObject->DeviceExtension;
+ assert (DeviceExt);
+ ExAcquireResourceExclusiveLite (&DeviceExt->DirResource, TRUE);
+
+ Status = VfatCreateFile (DeviceObject, Irp);
+
+ ExReleaseResourceLite (&DeviceExt->DirResource);
+
+ Irp->IoStatus.Status = Status;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+
+ return Status;
}
/* EOF */
// function like DosDateTimeToFileTime
-BOOL FsdDosDateTimeToFileTime(WORD wDosDate,WORD wDosTime, TIME *FileTime)
+BOOL FsdDosDateTimeToFileTime (WORD wDosDate, WORD wDosTime, TIME * FileTime)
{
- PDOSTIME pdtime = (PDOSTIME)&wDosTime;
- PDOSDATE pddate = (PDOSDATE)&wDosDate;
+ PDOSTIME pdtime = (PDOSTIME) & wDosTime;
+ PDOSDATE pddate = (PDOSDATE) & wDosDate;
TIME_FIELDS TimeFields;
if (FileTime == NULL)
TimeFields.Month = pddate->Month;
TimeFields.Year = 1980 + pddate->Year;
- RtlTimeFieldsToTime(&TimeFields, (PLARGE_INTEGER)FileTime);
+ RtlTimeFieldsToTime (&TimeFields, (PLARGE_INTEGER) FileTime);
return TRUE;
}
// function like FileTimeToDosDateTime
-BOOL FsdFileTimeToDosDateTime(TIME *FileTime,WORD *pwDosDate,WORD *pwDosTime)
+BOOL
+FsdFileTimeToDosDateTime (TIME * FileTime, WORD * pwDosDate, WORD * pwDosTime)
{
- PDOSTIME pdtime = (PDOSTIME)pwDosTime;
- PDOSDATE pddate = (PDOSDATE)pwDosDate;
+ PDOSTIME pdtime = (PDOSTIME) pwDosTime;
+ PDOSDATE pddate = (PDOSDATE) pwDosDate;
TIME_FIELDS TimeFields;
if (FileTime == NULL)
return FALSE;
- RtlTimeToTimeFields((PLARGE_INTEGER)FileTime, &TimeFields);
+ RtlTimeToTimeFields ((PLARGE_INTEGER) FileTime, &TimeFields);
if (pdtime)
- {
- pdtime->Second = TimeFields.Second / 2;
- pdtime->Minute = TimeFields.Minute;
- pdtime->Hour = TimeFields.Hour;
- }
+ {
+ pdtime->Second = TimeFields.Second / 2;
+ pdtime->Minute = TimeFields.Minute;
+ pdtime->Hour = TimeFields.Hour;
+ }
if (pddate)
- {
- pddate->Day = TimeFields.Day;
- pddate->Month = TimeFields.Month;
- pddate->Year = TimeFields.Year - 1980;
- }
+ {
+ pddate->Day = TimeFields.Day;
+ pddate->Month = TimeFields.Month;
+ pddate->Year = TimeFields.Year - 1980;
+ }
return TRUE;
}
-unsigned long vfat_wstrlen(PWSTR s)
+unsigned long
+vfat_wstrlen (PWSTR s)
{
- WCHAR c=' ';
- unsigned int len=0;
+ WCHAR c = ' ';
+ unsigned int len = 0;
- while(c!=0) {
- c=*s;
- s++;
- len++;
- };
- s-=len;
+ while (c != 0)
+ {
+ c = *s;
+ s++;
+ len++;
+ };
+ s -= len;
- return len-1;
+ return len - 1;
}
+
#define DWORD_ROUND_UP(x) ( (((ULONG)(x))%32) ? ((((ULONG)x)&(~0x1f))+0x20) : ((ULONG)x) )
-NTSTATUS FsdGetFileNameInformation(PVFATFCB pFcb,
- PFILE_NAMES_INFORMATION pInfo,ULONG BufferLength)
+NTSTATUS
+VfatGetFileNameInformation (PVFATFCB pFcb,
+ PFILE_NAMES_INFORMATION pInfo, ULONG BufferLength)
{
- ULONG Length;
- Length=vfat_wstrlen(pFcb->ObjectName);
- if( (sizeof(FILE_DIRECTORY_INFORMATION)+Length) >BufferLength)
- return STATUS_BUFFER_OVERFLOW;
- pInfo->FileNameLength=Length;
- pInfo->NextEntryOffset=DWORD_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION)+Length);
- memcpy(pInfo->FileName,pFcb->ObjectName
- ,sizeof(WCHAR)*(pInfo->FileNameLength));
+ ULONG Length;
+ Length = vfat_wstrlen (pFcb->ObjectName);
+ if ((sizeof (FILE_DIRECTORY_INFORMATION) + Length) > BufferLength)
+ return STATUS_BUFFER_OVERFLOW;
+ pInfo->FileNameLength = Length;
+ pInfo->NextEntryOffset =
+ DWORD_ROUND_UP (sizeof (FILE_DIRECTORY_INFORMATION) + Length);
+ memcpy (pInfo->FileName, pFcb->ObjectName,
+ sizeof (WCHAR) * (pInfo->FileNameLength));
return STATUS_SUCCESS;
}
-NTSTATUS FsdGetFileDirectoryInformation(PVFATFCB pFcb,
- PDEVICE_EXTENSION DeviceExt,
- PFILE_DIRECTORY_INFORMATION pInfo,ULONG BufferLength)
+NTSTATUS
+VfatGetFileDirectoryInformation (PVFATFCB pFcb,
+ PDEVICE_EXTENSION DeviceExt,
+ PFILE_DIRECTORY_INFORMATION pInfo,
+ ULONG BufferLength)
{
- unsigned long long AllocSize;
- ULONG Length;
- Length=vfat_wstrlen(pFcb->ObjectName);
- if( (sizeof(FILE_DIRECTORY_INFORMATION)+Length) >BufferLength)
- return STATUS_BUFFER_OVERFLOW;
- pInfo->FileNameLength=Length;
- pInfo->NextEntryOffset=DWORD_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION)+Length);
- memcpy(pInfo->FileName,pFcb->ObjectName
- ,sizeof(WCHAR)*(pInfo->FileNameLength));
+ unsigned long long AllocSize;
+ ULONG Length;
+ Length = vfat_wstrlen (pFcb->ObjectName);
+ if ((sizeof (FILE_DIRECTORY_INFORMATION) + Length) > BufferLength)
+ return STATUS_BUFFER_OVERFLOW;
+ pInfo->FileNameLength = Length;
+ pInfo->NextEntryOffset =
+ DWORD_ROUND_UP (sizeof (FILE_DIRECTORY_INFORMATION) + Length);
+ memcpy (pInfo->FileName, pFcb->ObjectName,
+ sizeof (WCHAR) * (pInfo->FileNameLength));
// pInfo->FileIndex=;
- FsdDosDateTimeToFileTime(pFcb->entry.CreationDate,pFcb->entry.CreationTime
- ,&pInfo->CreationTime);
- FsdDosDateTimeToFileTime(pFcb->entry.AccessDate,0
- ,&pInfo->LastAccessTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->LastWriteTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->ChangeTime);
- pInfo->EndOfFile=RtlConvertUlongToLargeInteger(pFcb->entry.FileSize);
+ FsdDosDateTimeToFileTime (pFcb->entry.CreationDate,
+ pFcb->entry.CreationTime, &pInfo->CreationTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.AccessDate, 0,
+ &pInfo->LastAccessTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->LastWriteTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->ChangeTime);
+ pInfo->EndOfFile = RtlConvertUlongToLargeInteger (pFcb->entry.FileSize);
/* Make allocsize a rounded up multiple of BytesPerCluster */
- AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
- DeviceExt->BytesPerCluster) *
- DeviceExt->BytesPerCluster;
+ AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
+ DeviceExt->BytesPerCluster) * DeviceExt->BytesPerCluster;
pInfo->AllocationSize.QuadPart = AllocSize;
- pInfo->FileAttributes=pFcb->entry.Attrib;
+ pInfo->FileAttributes = pFcb->entry.Attrib;
return STATUS_SUCCESS;
}
-NTSTATUS FsdGetFileFullDirectoryInformation(PVFATFCB pFcb,
- PDEVICE_EXTENSION DeviceExt,
- PFILE_FULL_DIRECTORY_INFORMATION pInfo,ULONG BufferLength)
+NTSTATUS
+VfatGetFileFullDirectoryInformation (PVFATFCB pFcb,
+ PDEVICE_EXTENSION DeviceExt,
+ PFILE_FULL_DIRECTORY_INFORMATION pInfo,
+ ULONG BufferLength)
{
- unsigned long long AllocSize;
- ULONG Length;
- Length=vfat_wstrlen(pFcb->ObjectName);
- if( (sizeof(FILE_FULL_DIRECTORY_INFORMATION)+Length) >BufferLength)
- return STATUS_BUFFER_OVERFLOW;
- pInfo->FileNameLength=Length;
- pInfo->NextEntryOffset=DWORD_ROUND_UP(sizeof(FILE_FULL_DIRECTORY_INFORMATION)+Length);
- memcpy(pInfo->FileName,pFcb->ObjectName
- ,sizeof(WCHAR)*(pInfo->FileNameLength));
+ unsigned long long AllocSize;
+ ULONG Length;
+ Length = vfat_wstrlen (pFcb->ObjectName);
+ if ((sizeof (FILE_FULL_DIRECTORY_INFORMATION) + Length) > BufferLength)
+ return STATUS_BUFFER_OVERFLOW;
+ pInfo->FileNameLength = Length;
+ pInfo->NextEntryOffset =
+ DWORD_ROUND_UP (sizeof (FILE_FULL_DIRECTORY_INFORMATION) + Length);
+ memcpy (pInfo->FileName, pFcb->ObjectName,
+ sizeof (WCHAR) * (pInfo->FileNameLength));
// pInfo->FileIndex=;
- FsdDosDateTimeToFileTime(pFcb->entry.CreationDate,pFcb->entry.CreationTime
- ,&pInfo->CreationTime);
- FsdDosDateTimeToFileTime(pFcb->entry.AccessDate,0
- ,&pInfo->LastAccessTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->LastWriteTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->ChangeTime);
- pInfo->EndOfFile=RtlConvertUlongToLargeInteger(pFcb->entry.FileSize);
+ FsdDosDateTimeToFileTime (pFcb->entry.CreationDate,
+ pFcb->entry.CreationTime, &pInfo->CreationTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.AccessDate, 0,
+ &pInfo->LastAccessTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->LastWriteTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->ChangeTime);
+ pInfo->EndOfFile = RtlConvertUlongToLargeInteger (pFcb->entry.FileSize);
/* Make allocsize a rounded up multiple of BytesPerCluster */
- AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
- DeviceExt->BytesPerCluster) *
- DeviceExt->BytesPerCluster;
+ AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
+ DeviceExt->BytesPerCluster) * DeviceExt->BytesPerCluster;
pInfo->AllocationSize.QuadPart = AllocSize;
- pInfo->FileAttributes=pFcb->entry.Attrib;
+ pInfo->FileAttributes = pFcb->entry.Attrib;
// pInfo->EaSize=;
return STATUS_SUCCESS;
}
-NTSTATUS FsdGetFileBothInformation(PVFATFCB pFcb,
- PDEVICE_EXTENSION DeviceExt,
- PFILE_BOTH_DIRECTORY_INFORMATION pInfo,ULONG BufferLength)
+NTSTATUS
+VfatGetFileBothInformation (PVFATFCB pFcb,
+ PDEVICE_EXTENSION DeviceExt,
+ PFILE_BOTH_DIRECTORY_INFORMATION pInfo,
+ ULONG BufferLength)
{
- short i;
- unsigned long long AllocSize;
- ULONG Length;
- Length=vfat_wstrlen(pFcb->ObjectName);
- if( (sizeof(FILE_BOTH_DIRECTORY_INFORMATION)+Length) >BufferLength)
- return STATUS_BUFFER_OVERFLOW;
- pInfo->FileNameLength=Length;
- pInfo->NextEntryOffset=DWORD_ROUND_UP(sizeof(FILE_BOTH_DIRECTORY_INFORMATION)+Length);
- memcpy(pInfo->FileName,pFcb->ObjectName
- ,sizeof(WCHAR)*(pInfo->FileNameLength));
+ short i;
+ unsigned long long AllocSize;
+ ULONG Length;
+ Length = vfat_wstrlen (pFcb->ObjectName);
+ if ((sizeof (FILE_BOTH_DIRECTORY_INFORMATION) + Length) > BufferLength)
+ return STATUS_BUFFER_OVERFLOW;
+ pInfo->FileNameLength = Length;
+ pInfo->NextEntryOffset =
+ DWORD_ROUND_UP (sizeof (FILE_BOTH_DIRECTORY_INFORMATION) + Length);
+ memcpy (pInfo->FileName, pFcb->ObjectName,
+ sizeof (WCHAR) * (pInfo->FileNameLength));
// pInfo->FileIndex=;
- FsdDosDateTimeToFileTime(pFcb->entry.CreationDate,pFcb->entry.CreationTime
- ,&pInfo->CreationTime);
- FsdDosDateTimeToFileTime(pFcb->entry.AccessDate,0
- ,&pInfo->LastAccessTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->LastWriteTime);
- FsdDosDateTimeToFileTime(pFcb->entry.UpdateDate,pFcb->entry.UpdateTime
- ,&pInfo->ChangeTime);
- pInfo->EndOfFile=RtlConvertUlongToLargeInteger(pFcb->entry.FileSize);
+ FsdDosDateTimeToFileTime (pFcb->entry.CreationDate,
+ pFcb->entry.CreationTime, &pInfo->CreationTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.AccessDate, 0,
+ &pInfo->LastAccessTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->LastWriteTime);
+ FsdDosDateTimeToFileTime (pFcb->entry.UpdateDate, pFcb->entry.UpdateTime,
+ &pInfo->ChangeTime);
+ pInfo->EndOfFile = RtlConvertUlongToLargeInteger (pFcb->entry.FileSize);
/* Make allocsize a rounded up multiple of BytesPerCluster */
- AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
- DeviceExt->BytesPerCluster) *
- DeviceExt->BytesPerCluster;
+ AllocSize = ((pFcb->entry.FileSize + DeviceExt->BytesPerCluster - 1) /
+ DeviceExt->BytesPerCluster) * DeviceExt->BytesPerCluster;
pInfo->AllocationSize.QuadPart = AllocSize;
- pInfo->FileAttributes=pFcb->entry.Attrib;
+ pInfo->FileAttributes = pFcb->entry.Attrib;
// pInfo->EaSize=;
- for (i=0;i<8 && (pFcb->entry.Filename[i]!=' ') ;i++)
- pInfo->ShortName[i]=pFcb->entry.Filename[i];
- pInfo->ShortNameLength=i;
- pInfo->ShortName[i]='.';
- for (i=0 ;i<3 && (pFcb->entry.Ext[i]!=' ') ;i++)
- pInfo->ShortName[i+1+pInfo->ShortNameLength]=pFcb->entry.Ext[i];
- if(i) pInfo->ShortNameLength += (i+1);
+ for (i = 0; i < 8 && (pFcb->entry.Filename[i] != ' '); i++)
+ pInfo->ShortName[i] = pFcb->entry.Filename[i];
+ pInfo->ShortNameLength = i;
+ pInfo->ShortName[i] = '.';
+ for (i = 0; i < 3 && (pFcb->entry.Ext[i] != ' '); i++)
+ pInfo->ShortName[i + 1 + pInfo->ShortNameLength] = pFcb->entry.Ext[i];
+ if (i)
+ pInfo->ShortNameLength += (i + 1);
return STATUS_SUCCESS;
}
-NTSTATUS DoQuery(PDEVICE_OBJECT DeviceObject, PIRP Irp,PIO_STACK_LOCATION Stack)
+NTSTATUS
+DoQuery (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION Stack)
{
- NTSTATUS RC=STATUS_SUCCESS;
- long BufferLength = 0;
- PUNICODE_STRING pSearchPattern = NULL;
- FILE_INFORMATION_CLASS FileInformationClass;
- unsigned long FileIndex = 0;
- unsigned char *Buffer = NULL;
- PFILE_NAMES_INFORMATION Buffer0 = NULL;
- PFILE_OBJECT pFileObject = NULL;
- PVFATFCB pFcb;
- VFATFCB tmpFcb;
- PVFATCCB pCcb;
- PDEVICE_EXTENSION DeviceExt;
- WCHAR star[5],*pCharPattern;
- unsigned long OldEntry,OldSector;
+ NTSTATUS RC = STATUS_SUCCESS;
+ long BufferLength = 0;
+ PUNICODE_STRING pSearchPattern = NULL;
+ FILE_INFORMATION_CLASS FileInformationClass;
+ unsigned long FileIndex = 0;
+ unsigned char *Buffer = NULL;
+ PFILE_NAMES_INFORMATION Buffer0 = NULL;
+ PFILE_OBJECT pFileObject = NULL;
+ PVFATFCB pFcb;
+ VFATFCB tmpFcb;
+ PVFATCCB pCcb;
+ PDEVICE_EXTENSION DeviceExt;
+ WCHAR star[5], *pCharPattern;
+ unsigned long OldEntry, OldSector;
DeviceExt = DeviceObject->DeviceExtension;
// Obtain the callers parameters
BufferLength = Stack->Parameters.QueryDirectory.Length;
pSearchPattern = Stack->Parameters.QueryDirectory.FileName;
- FileInformationClass = Stack->Parameters.QueryDirectory.FileInformationClass;
+ FileInformationClass =
+ Stack->Parameters.QueryDirectory.FileInformationClass;
FileIndex = Stack->Parameters.QueryDirectory.FileIndex;
pFileObject = Stack->FileObject;
- pCcb =(PVFATCCB)pFileObject->FsContext2;
+ pCcb = (PVFATCCB) pFileObject->FsContext2;
pFcb = pCcb->pFcb;
- if(Stack->Flags & SL_RESTART_SCAN)
- {//FIXME : what is really use of RestartScan ?
- pCcb->StartEntry=pCcb->StartSector=0;
- }
+ if (Stack->Flags & SL_RESTART_SCAN)
+ { //FIXME : what is really use of RestartScan ?
+ pCcb->StartEntry = pCcb->StartSector = 0;
+ }
// determine Buffer for result :
- if (Irp->MdlAddress)
- Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
+ if (Irp->MdlAddress)
+ Buffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
else
Buffer = Irp->UserBuffer;
- DPRINT("Buffer=%x tofind=%S\n",Buffer,pSearchPattern->Buffer);
- if (pSearchPattern==NULL)
- {
- star[0]='*';
- star[1]=0;
- pCharPattern=star;
- }
- else pCharPattern=pSearchPattern->Buffer;
- tmpFcb.ObjectName=tmpFcb.PathName;
- while(RC==STATUS_SUCCESS && BufferLength >0)
- {
- OldSector=pCcb->StartSector;
- OldEntry=pCcb->StartEntry;
- if(OldSector)pCcb->StartEntry++;
- RC=FindFile(DeviceExt,&tmpFcb,pFcb,pCharPattern,&pCcb->StartSector,&pCcb->StartEntry);
-DPRINT("Found %S,RC=%x, sector %x entry %x\n",tmpFcb.ObjectName,RC
- ,pCcb->StartSector,pCcb->StartEntry);
- if (NT_SUCCESS(RC))
+ DPRINT ("Buffer=%x tofind=%S\n", Buffer, pSearchPattern->Buffer);
+ if (pSearchPattern == NULL)
{
- switch(FileInformationClass)
- {
- case FileNameInformation:
- RC=FsdGetFileNameInformation(&tmpFcb
- ,(PFILE_NAMES_INFORMATION)Buffer,BufferLength);
- break;
- case FileDirectoryInformation:
- RC= FsdGetFileDirectoryInformation(&tmpFcb
- ,DeviceExt,(PFILE_DIRECTORY_INFORMATION)Buffer,BufferLength);
- break;
- case FileFullDirectoryInformation :
- RC= FsdGetFileFullDirectoryInformation(&tmpFcb
- ,DeviceExt,(PFILE_FULL_DIRECTORY_INFORMATION)Buffer,BufferLength);
- break;
- case FileBothDirectoryInformation :
- RC=FsdGetFileBothInformation(&tmpFcb
- ,DeviceExt,(PFILE_BOTH_DIRECTORY_INFORMATION)Buffer,BufferLength);
- break;
- default:
- RC=STATUS_INVALID_INFO_CLASS;
- }
- }
- else
- {
- if(Buffer0) Buffer0->NextEntryOffset=0;
- break;
+ star[0] = '*';
+ star[1] = 0;
+ pCharPattern = star;
}
- if(RC==STATUS_BUFFER_OVERFLOW)
+ else
+ pCharPattern = pSearchPattern->Buffer;
+ tmpFcb.ObjectName = tmpFcb.PathName;
+ while (RC == STATUS_SUCCESS && BufferLength > 0)
{
- if(Buffer0) Buffer0->NextEntryOffset=0;
- pCcb->StartSector=OldSector;
- pCcb->StartEntry=OldEntry;
- break;
+ OldSector = pCcb->StartSector;
+ OldEntry = pCcb->StartEntry;
+ if (OldSector)
+ pCcb->StartEntry++;
+ RC =
+ FindFile (DeviceExt, &tmpFcb, pFcb, pCharPattern, &pCcb->StartSector,
+ &pCcb->StartEntry);
+ DPRINT ("Found %S,RC=%x, sector %x entry %x\n", tmpFcb.ObjectName, RC,
+ pCcb->StartSector, pCcb->StartEntry);
+ if (NT_SUCCESS (RC))
+ {
+ switch (FileInformationClass)
+ {
+ case FileNameInformation:
+ RC =
+ VfatGetFileNameInformation (&tmpFcb,
+ (PFILE_NAMES_INFORMATION) Buffer,
+ BufferLength);
+ break;
+ case FileDirectoryInformation:
+ RC =
+ VfatGetFileDirectoryInformation (&tmpFcb, DeviceExt,
+ (PFILE_DIRECTORY_INFORMATION)
+ Buffer, BufferLength);
+ break;
+ case FileFullDirectoryInformation:
+ RC =
+ VfatGetFileFullDirectoryInformation (&tmpFcb, DeviceExt,
+ (PFILE_FULL_DIRECTORY_INFORMATION)
+ Buffer, BufferLength);
+ break;
+ case FileBothDirectoryInformation:
+ RC =
+ VfatGetFileBothInformation (&tmpFcb, DeviceExt,
+ (PFILE_BOTH_DIRECTORY_INFORMATION)
+ Buffer, BufferLength);
+ break;
+ default:
+ RC = STATUS_INVALID_INFO_CLASS;
+ }
+ }
+ else
+ {
+ if (Buffer0)
+ Buffer0->NextEntryOffset = 0;
+ break;
+ }
+ if (RC == STATUS_BUFFER_OVERFLOW)
+ {
+ if (Buffer0)
+ Buffer0->NextEntryOffset = 0;
+ pCcb->StartSector = OldSector;
+ pCcb->StartEntry = OldEntry;
+ break;
+ }
+ Buffer0 = (PFILE_NAMES_INFORMATION) Buffer;
+ Buffer0->FileIndex = FileIndex++;
+ if (Stack->Flags & SL_RETURN_SINGLE_ENTRY)
+ break;
+ BufferLength -= Buffer0->NextEntryOffset;
+ Buffer += Buffer0->NextEntryOffset;
}
- Buffer0=(PFILE_NAMES_INFORMATION)Buffer;
- Buffer0->FileIndex=FileIndex++;
- if(Stack->Flags & SL_RETURN_SINGLE_ENTRY) break;
- BufferLength -= Buffer0->NextEntryOffset;
- Buffer += Buffer0->NextEntryOffset;
- }
- if(Buffer0) Buffer0->NextEntryOffset=0;
- if(FileIndex>0) return STATUS_SUCCESS;
+ if (Buffer0)
+ Buffer0->NextEntryOffset = 0;
+ if (FileIndex > 0)
+ return STATUS_SUCCESS;
return RC;
}
-NTSTATUS STDCALL FsdDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatDirectoryControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: directory control : read/write directory informations
*/
{
- NTSTATUS RC = STATUS_SUCCESS;
- PFILE_OBJECT FileObject = NULL;
- PIO_STACK_LOCATION Stack;
- Stack = IoGetCurrentIrpStackLocation(Irp);
- CHECKPOINT;
- FileObject = Stack->FileObject;
- switch (Stack->MinorFunction)
- {
+ NTSTATUS RC = STATUS_SUCCESS;
+ PFILE_OBJECT FileObject = NULL;
+ PIO_STACK_LOCATION Stack;
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ CHECKPOINT;
+ FileObject = Stack->FileObject;
+ switch (Stack->MinorFunction)
+ {
case IRP_MN_QUERY_DIRECTORY:
- RC=DoQuery(DeviceObject,Irp,Stack);
+ RC = DoQuery (DeviceObject, Irp, Stack);
break;
case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
- DPRINT(" vfat, dir : change\n");
- RC=STATUS_NOT_IMPLEMENTED;
+ DPRINT (" vfat, dir : change\n");
+ RC = STATUS_NOT_IMPLEMENTED;
break;
default:
// error
- DbgPrint("unexpected minor function %x in VFAT driver\n",Stack->MinorFunction);
- RC = STATUS_INVALID_DEVICE_REQUEST;
- break;
- }
- Irp->IoStatus.Status = RC;
- Irp->IoStatus.Information = 0;
-
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return RC;
-}
+ DbgPrint ("unexpected minor function %x in VFAT driver\n",
+ Stack->MinorFunction);
+ RC = STATUS_INVALID_DEVICE_REQUEST;
+ break;
+ }
+ Irp->IoStatus.Status = RC;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return RC;
+}
-/* $Id: dirwr.c,v 1.13 2000/06/29 23:35:50 dwelch Exp $
+/* $Id: dirwr.c,v 1.14 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* from complaining.
*/
static VOID
-FillSlot (slot *Slot, WCHAR *FileName)
+FillSlot (slot * Slot, WCHAR * FileName)
{
- BOOLEAN fill = FALSE;
- WCHAR *src = FileName;
- WCHAR *dst;
- int i;
+ BOOLEAN fill = FALSE;
+ WCHAR *src = FileName;
+ WCHAR *dst;
+ int i;
- i = 5;
- dst = Slot->name0_4;
- while (i-- > 0)
- {
- if (fill == FALSE)
- *dst = *src;
- else
- *dst = 0xffff;
+ i = 5;
+ dst = Slot->name0_4;
+ while (i-- > 0)
+ {
+ if (fill == FALSE)
+ *dst = *src;
+ else
+ *dst = 0xffff;
- if (fill == FALSE && (*src == 0))
- fill = TRUE;
- dst++;
- src++;
- }
+ if (fill == FALSE && (*src == 0))
+ fill = TRUE;
+ dst++;
+ src++;
+ }
- i = 6;
- dst = Slot->name5_10;
- while (i-- > 0)
- {
- if (fill == FALSE)
- *dst = *src;
- else
- *dst = 0xffff;
+ i = 6;
+ dst = Slot->name5_10;
+ while (i-- > 0)
+ {
+ if (fill == FALSE)
+ *dst = *src;
+ else
+ *dst = 0xffff;
- if (fill == FALSE && (*src == 0))
- fill = TRUE;
- dst++;
- src++;
- }
+ if (fill == FALSE && (*src == 0))
+ fill = TRUE;
+ dst++;
+ src++;
+ }
- i = 2;
- dst = Slot->name11_12;
- while (i-- > 0)
- {
- if (fill == FALSE)
- *dst = *src;
- else
- *dst = 0xffff;
+ i = 2;
+ dst = Slot->name11_12;
+ while (i-- > 0)
+ {
+ if (fill == FALSE)
+ *dst = *src;
+ else
+ *dst = 0xffff;
- if (fill == FALSE && (*src == 0))
- fill = TRUE;
- dst++;
- src++;
- }
+ if (fill == FALSE && (*src == 0))
+ fill = TRUE;
+ dst++;
+ src++;
+ }
}
-NTSTATUS updEntry(PDEVICE_EXTENSION DeviceExt,PFILE_OBJECT pFileObject)
+NTSTATUS updEntry (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT pFileObject)
/*
update an existing FAT entry
*/
{
- WCHAR DirName[MAX_PATH],*FileName,*PathFileName;
- VFATFCB FileFcb;
- ULONG Sector=0,Entry=0;
- PUCHAR Buffer;
- FATDirEntry * pEntries;
- NTSTATUS status;
- FILE_OBJECT FileObject;
- PVFATCCB pDirCcb;
- PVFATFCB pDirFcb,pFcb;
- short i,posCar,NameLen;
+ WCHAR DirName[MAX_PATH], *FileName, *PathFileName;
+ VFATFCB FileFcb;
+ ULONG Sector = 0, Entry = 0;
+ PUCHAR Buffer;
+ FATDirEntry *pEntries;
+ NTSTATUS status;
+ FILE_OBJECT FileObject;
+ PVFATCCB pDirCcb;
+ PVFATFCB pDirFcb, pFcb;
+ short i, posCar, NameLen;
- PathFileName=pFileObject->FileName.Buffer;
- pFcb=((PVFATCCB)pFileObject->FsContext2)->pFcb;
- DPRINT("PathFileName \'%S\'\n", PathFileName);
+ PathFileName = pFileObject->FileName.Buffer;
+ pFcb = ((PVFATCCB) pFileObject->FsContext2)->pFcb;
+ DPRINT ("PathFileName \'%S\'\n", PathFileName);
- //find last \ in PathFileName
- posCar=-1;
- for(i=0;PathFileName[i];i++)
- if(PathFileName[i]=='\\')posCar=i;
- if(posCar==-1)
- return STATUS_UNSUCCESSFUL;
- FileName=&PathFileName[posCar+1];
- for(NameLen=0;FileName[NameLen];NameLen++);
+ //find last \ in PathFileName
+ posCar = -1;
+ for (i = 0; PathFileName[i]; i++)
+ if (PathFileName[i] == '\\')
+ posCar = i;
+ if (posCar == -1)
+ return STATUS_UNSUCCESSFUL;
+ FileName = &PathFileName[posCar + 1];
+ for (NameLen = 0; FileName[NameLen]; NameLen++);
- // extract directory name from pathname
- if( posCar == 0 )
- {
- // root dir
- DirName[0] = L'\\';
- DirName[1] = 0;
- }
- else {
- memcpy(DirName,PathFileName,posCar*sizeof(WCHAR));
- DirName[posCar]=0;
- }
- if(FileName[0]==0 && DirName[0]==0)
- return STATUS_SUCCESS;//root : nothing to do ?
- memset(&FileObject,0,sizeof(FILE_OBJECT));
- DPRINT("open directory \'%S\' for update of entry \'%S\'\n",DirName,FileName);
- status=FsdOpenFile(DeviceExt,&FileObject,DirName);
- if (!NT_SUCCESS(status))
- {
- DbgPrint ("Failed to open \'%S\'. Status %lx\n", DirName, status);
- return status;
- }
- pDirCcb=(PVFATCCB)FileObject.FsContext2;
- assert(pDirCcb);
- pDirFcb=pDirCcb->pFcb;
- assert(pDirFcb);
- FileFcb.ObjectName=&FileFcb.PathName[0];
- status=FindFile(DeviceExt,&FileFcb,pDirFcb,FileName,&Sector,&Entry);
- if(NT_SUCCESS(status))
- {
- Buffer=ExAllocatePool(NonPagedPool,BLOCKSIZE);
- DPRINT("update entry: sector %d, entry %d\n",Sector,Entry);
- VFATReadSectors(DeviceExt->StorageDevice,Sector,1,Buffer);
- pEntries=(FATDirEntry *)Buffer;
- memcpy(&pEntries[Entry],&pFcb->entry,sizeof(FATDirEntry));
- VFATWriteSectors(DeviceExt->StorageDevice,Sector,1,Buffer);
- ExFreePool(Buffer);
- }
- FsdCloseFile(DeviceExt,&FileObject);
- return status;
+ // extract directory name from pathname
+ if (posCar == 0)
+ {
+ // root dir
+ DirName[0] = L'\\';
+ DirName[1] = 0;
+ }
+ else
+ {
+ memcpy (DirName, PathFileName, posCar * sizeof (WCHAR));
+ DirName[posCar] = 0;
+ }
+ if (FileName[0] == 0 && DirName[0] == 0)
+ return STATUS_SUCCESS; //root : nothing to do ?
+ memset (&FileObject, 0, sizeof (FILE_OBJECT));
+ DPRINT ("open directory \'%S\' for update of entry \'%S\'\n", DirName,
+ FileName);
+ status = FsdOpenFile (DeviceExt, &FileObject, DirName);
+ if (!NT_SUCCESS (status))
+ {
+ DbgPrint ("Failed to open \'%S\'. Status %lx\n", DirName, status);
+ return status;
+ }
+ pDirCcb = (PVFATCCB) FileObject.FsContext2;
+ assert (pDirCcb);
+ pDirFcb = pDirCcb->pFcb;
+ assert (pDirFcb);
+ FileFcb.ObjectName = &FileFcb.PathName[0];
+ status = FindFile (DeviceExt, &FileFcb, pDirFcb, FileName, &Sector, &Entry);
+ if (NT_SUCCESS (status))
+ {
+ Buffer = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ DPRINT ("update entry: sector %d, entry %d\n", Sector, Entry);
+ VFATReadSectors (DeviceExt->StorageDevice, Sector, 1, Buffer);
+ pEntries = (FATDirEntry *) Buffer;
+ memcpy (&pEntries[Entry], &pFcb->entry, sizeof (FATDirEntry));
+ VFATWriteSectors (DeviceExt->StorageDevice, Sector, 1, Buffer);
+ ExFreePool (Buffer);
+ }
+ VfatCloseFile (DeviceExt, &FileObject);
+ return status;
}
-NTSTATUS addEntry(PDEVICE_EXTENSION DeviceExt,
- PFILE_OBJECT pFileObject,
- ULONG RequestedOptions,
- UCHAR ReqAttr)
+NTSTATUS
+addEntry (PDEVICE_EXTENSION DeviceExt,
+ PFILE_OBJECT pFileObject, ULONG RequestedOptions, UCHAR ReqAttr)
/*
create a new FAT entry
*/
{
- WCHAR DirName[MAX_PATH],*FileName,*PathFileName;
- VFATFCB DirFcb,FileFcb;
- FATDirEntry FatEntry;
- NTSTATUS status;
- FILE_OBJECT FileObject;
- FATDirEntry *pEntry;
- slot *pSlots;
- ULONG LengthRead,Offset;
- short nbSlots=0,nbFree=0,i,j,posCar,NameLen;
- PUCHAR Buffer,Buffer2;
- BOOLEAN needTilde=FALSE,needLong=FALSE;
- PVFATFCB newFCB;
- PVFATCCB newCCB;
- ULONG CurrentCluster;
- KIRQL oldIrql;
- LARGE_INTEGER SystemTime, LocalTime;
+ WCHAR DirName[MAX_PATH], *FileName, *PathFileName;
+ VFATFCB DirFcb, FileFcb;
+ FATDirEntry FatEntry;
+ NTSTATUS status;
+ FILE_OBJECT FileObject;
+ FATDirEntry *pEntry;
+ slot *pSlots;
+ ULONG LengthRead, Offset;
+ short nbSlots = 0, nbFree = 0, i, j, posCar, NameLen;
+ PUCHAR Buffer, Buffer2;
+ BOOLEAN needTilde = FALSE, needLong = FALSE;
+ PVFATFCB newFCB;
+ PVFATCCB newCCB;
+ ULONG CurrentCluster;
+ KIRQL oldIrql;
+ LARGE_INTEGER SystemTime, LocalTime;
- PathFileName=pFileObject->FileName.Buffer;
- DPRINT("addEntry: Pathname=%S\n",PathFileName);
- //find last \ in PathFileName
- posCar=-1;
- for(i=0;PathFileName[i];i++)
- if(PathFileName[i]=='\\')posCar=i;
- if(posCar==-1)
- return STATUS_UNSUCCESSFUL;
- FileName=&PathFileName[posCar+1];
- for(NameLen=0;FileName[NameLen];NameLen++);
- // extract directory name from pathname
- memcpy(DirName,PathFileName,posCar*sizeof(WCHAR));
- DirName[posCar]=0;
- // open parent directory
- memset(&FileObject,0,sizeof(FILE_OBJECT));
- status=FsdOpenFile(DeviceExt,&FileObject,DirName);
- nbSlots=(NameLen+12)/13+1;//nb of entry needed for long name+normal entry
- DPRINT("NameLen= %d, nbSlots =%d\n",NameLen,nbSlots);
- Buffer=ExAllocatePool(NonPagedPool,(nbSlots+1)*sizeof(FATDirEntry));
- memset(Buffer,0,(nbSlots+1)*sizeof(FATDirEntry));
- pEntry=(FATDirEntry *)(Buffer+(nbSlots-1)*sizeof(FATDirEntry));
- pSlots=(slot *)Buffer;
- // create 8.3 name
- needTilde=FALSE;
- // find last point in name
- posCar=0;
- for(i=0;FileName[i];i++)
- if(FileName[i]=='.')posCar=i;
- if(!posCar) posCar=i;
- if(posCar>8) needTilde=TRUE;
- //copy 8 characters max
- memset(pEntry,' ',11);
- for(i=0,j=0;j<8 && i<posCar;i++)
- {
- //FIXME : is there other characters to ignore ?
- if( FileName[i]!='.'
- && FileName[i]!=' '
- && FileName[i]!='+'
- && FileName[i]!=','
- && FileName[i]!=';'
- && FileName[i]!='='
- && FileName[i]!='['
- && FileName[i]!=']'
- )
- pEntry->Filename[j++]=toupper((char) FileName[i]);
- else
- needTilde=TRUE;
- }
- //copy extension
- if(FileName[posCar])
- for(j=0,i=posCar+1;FileName[i] && i<posCar+4;i++)
- {
- pEntry->Ext[j++]=toupper((char)( FileName[i] &0x7F));
- }
- if(FileName[i])
- needTilde=TRUE;
- //find good value for tilde
- if(needTilde)
- {
- needLong=TRUE;
- DPRINT("searching a good value for tilde\n");
- for(i=0;i<6;i++)
- DirName[i]=pEntry->Filename[i];
- for(i=0;i<3;i++)
- DirName[i+8]=pEntry->Ext[i];
- //try first with xxxxxx~y.zzz
- DirName[6]='~';
- pEntry->Filename[6]='~';
- DirName[8]='.';
- DirName[12]=0;
- for(i=1;i<9;i++)
+ PathFileName = pFileObject->FileName.Buffer;
+ DPRINT ("addEntry: Pathname=%S\n", PathFileName);
+ //find last \ in PathFileName
+ posCar = -1;
+ for (i = 0; PathFileName[i]; i++)
+ if (PathFileName[i] == '\\')
+ posCar = i;
+ if (posCar == -1)
+ return STATUS_UNSUCCESSFUL;
+ FileName = &PathFileName[posCar + 1];
+ for (NameLen = 0; FileName[NameLen]; NameLen++);
+ // extract directory name from pathname
+ memcpy (DirName, PathFileName, posCar * sizeof (WCHAR));
+ DirName[posCar] = 0;
+ // open parent directory
+ memset (&FileObject, 0, sizeof (FILE_OBJECT));
+ status = FsdOpenFile (DeviceExt, &FileObject, DirName);
+ nbSlots = (NameLen + 12) / 13 + 1; //nb of entry needed for long name+normal entry
+ DPRINT ("NameLen= %d, nbSlots =%d\n", NameLen, nbSlots);
+ Buffer =
+ ExAllocatePool (NonPagedPool, (nbSlots + 1) * sizeof (FATDirEntry));
+ memset (Buffer, 0, (nbSlots + 1) * sizeof (FATDirEntry));
+ pEntry = (FATDirEntry *) (Buffer + (nbSlots - 1) * sizeof (FATDirEntry));
+ pSlots = (slot *) Buffer;
+ // create 8.3 name
+ needTilde = FALSE;
+ // find last point in name
+ posCar = 0;
+ for (i = 0; FileName[i]; i++)
+ if (FileName[i] == '.')
+ posCar = i;
+ if (!posCar)
+ posCar = i;
+ if (posCar > 8)
+ needTilde = TRUE;
+ //copy 8 characters max
+ memset (pEntry, ' ', 11);
+ for (i = 0, j = 0; j < 8 && i < posCar; i++)
+ {
+ //FIXME : is there other characters to ignore ?
+ if (FileName[i] != '.'
+ && FileName[i] != ' '
+ && FileName[i] != '+'
+ && FileName[i] != ','
+ && FileName[i] != ';'
+ && FileName[i] != '=' && FileName[i] != '[' && FileName[i] != ']')
+ pEntry->Filename[j++] = toupper ((char) FileName[i]);
+ else
+ needTilde = TRUE;
+ }
+ //copy extension
+ if (FileName[posCar])
+ for (j = 0, i = posCar + 1; FileName[i] && i < posCar + 4; i++)
{
- DirName[7]='0'+i;
- pEntry->Filename[7]='0'+i;
- status=FindFile(DeviceExt,&FileFcb
- ,&DirFcb,DirName,NULL,NULL);
- if(status!=STATUS_SUCCESS)break;
+ pEntry->Ext[j++] = toupper ((char) (FileName[i] & 0x7F));
}
+ if (FileName[i])
+ needTilde = TRUE;
+ //find good value for tilde
+ if (needTilde)
+ {
+ needLong = TRUE;
+ DPRINT ("searching a good value for tilde\n");
+ for (i = 0; i < 6; i++)
+ DirName[i] = pEntry->Filename[i];
+ for (i = 0; i < 3; i++)
+ DirName[i + 8] = pEntry->Ext[i];
+ //try first with xxxxxx~y.zzz
+ DirName[6] = '~';
+ pEntry->Filename[6] = '~';
+ DirName[8] = '.';
+ DirName[12] = 0;
+ for (i = 1; i < 9; i++)
+ {
+ DirName[7] = '0' + i;
+ pEntry->Filename[7] = '0' + i;
+ status =
+ FindFile (DeviceExt, &FileFcb, &DirFcb, DirName, NULL, NULL);
+ if (status != STATUS_SUCCESS)
+ break;
+ }
//try second with xxxxx~yy.zzz
- if(i==10)
- {
- DirName[5]='~';
- for( ;i<99;i++)
- {
- DirName[7]='0'+i;
- pEntry->Filename[7]='0'+i;
- status=FindFile(DeviceExt,&FileFcb
- ,&DirFcb,DirName,NULL,NULL);
- if(status!=STATUS_SUCCESS)break;
- }
- }
- if(i==100)//FIXME : what to do after 99 tilde ?
- {
- FsdCloseFile(DeviceExt,&FileObject);
- ExFreePool(Buffer);
- return STATUS_UNSUCCESSFUL;
- }
- }
- else
- {
-DPRINT("check if long name entry needed, needlong=%d\n",needLong);
- for(i=0;i<posCar;i++)
- if((USHORT)pEntry->Filename[i]!=FileName[i])
- {
-DPRINT("i=%d,%d,%d\n",i,pEntry->Filename[i],FileName[i]);
- needLong=TRUE;
- }
- if(FileName[i])
- {
- i++;//jump on point char
- for(j=0,i=posCar+1;FileName[i] && i<posCar+4;i++)
- if((USHORT)pEntry->Ext[j++]!= FileName[i])
- {
-DPRINT("i=%d,j=%d,%d,%d\n",i,j,pEntry->Filename[i],FileName[i]);
- needLong=TRUE;
- }
- }
- }
- if(needLong==FALSE)
- {
- nbSlots=1;
- memcpy(Buffer,pEntry,sizeof(FATDirEntry));
- memset(pEntry,0,sizeof(FATDirEntry));
- pEntry=(FATDirEntry *)Buffer;
- }
- else
- {
- memset(DirName,0xff,sizeof(DirName));
- memcpy(DirName,FileName,NameLen*sizeof(WCHAR));
- DirName[NameLen]=0;
- }
- DPRINT("dos name=%11.11s\n",pEntry->Filename);
+ if (i == 10)
+ {
+ DirName[5] = '~';
+ for (; i < 99; i++)
+ {
+ DirName[7] = '0' + i;
+ pEntry->Filename[7] = '0' + i;
+ status =
+ FindFile (DeviceExt, &FileFcb, &DirFcb, DirName, NULL, NULL);
+ if (status != STATUS_SUCCESS)
+ break;
+ }
+ }
+ if (i == 100) //FIXME : what to do after 99 tilde ?
+ {
+ VfatCloseFile (DeviceExt, &FileObject);
+ ExFreePool (Buffer);
+ return STATUS_UNSUCCESSFUL;
+ }
+ }
+ else
+ {
+ DPRINT ("check if long name entry needed, needlong=%d\n", needLong);
+ for (i = 0; i < posCar; i++)
+ if ((USHORT) pEntry->Filename[i] != FileName[i])
+ {
+ DPRINT ("i=%d,%d,%d\n", i, pEntry->Filename[i], FileName[i]);
+ needLong = TRUE;
+ }
+ if (FileName[i])
+ {
+ i++; //jump on point char
+ for (j = 0, i = posCar + 1; FileName[i] && i < posCar + 4; i++)
+ if ((USHORT) pEntry->Ext[j++] != FileName[i])
+ {
+ DPRINT ("i=%d,j=%d,%d,%d\n", i, j, pEntry->Filename[i],
+ FileName[i]);
+ needLong = TRUE;
+ }
+ }
+ }
+ if (needLong == FALSE)
+ {
+ nbSlots = 1;
+ memcpy (Buffer, pEntry, sizeof (FATDirEntry));
+ memset (pEntry, 0, sizeof (FATDirEntry));
+ pEntry = (FATDirEntry *) Buffer;
+ }
+ else
+ {
+ memset (DirName, 0xff, sizeof (DirName));
+ memcpy (DirName, FileName, NameLen * sizeof (WCHAR));
+ DirName[NameLen] = 0;
+ }
+ DPRINT ("dos name=%11.11s\n", pEntry->Filename);
- /* set attributes */
- pEntry->Attrib=ReqAttr;
- if(RequestedOptions&FILE_DIRECTORY_FILE)
- pEntry->Attrib |= FILE_ATTRIBUTE_DIRECTORY;
+ /* set attributes */
+ pEntry->Attrib = ReqAttr;
+ if (RequestedOptions & FILE_DIRECTORY_FILE)
+ pEntry->Attrib |= FILE_ATTRIBUTE_DIRECTORY;
- /* set dates and times */
- KeQuerySystemTime (&SystemTime);
- ExSystemTimeToLocalTime (&SystemTime,
- &LocalTime);
- FsdFileTimeToDosDateTime ((TIME*)&LocalTime,
- &pEntry->CreationDate,
- &pEntry->CreationTime);
- pEntry->UpdateDate = pEntry->CreationDate;
- pEntry->UpdateTime = pEntry->CreationTime;
- pEntry->AccessDate = pEntry->CreationDate;
+ /* set dates and times */
+ KeQuerySystemTime (&SystemTime);
+ ExSystemTimeToLocalTime (&SystemTime, &LocalTime);
+ FsdFileTimeToDosDateTime ((TIME *) & LocalTime,
+ &pEntry->CreationDate, &pEntry->CreationTime);
+ pEntry->UpdateDate = pEntry->CreationDate;
+ pEntry->UpdateTime = pEntry->CreationTime;
+ pEntry->AccessDate = pEntry->CreationDate;
- // calculate checksum for 8.3 name
- for(pSlots[0].alias_checksum=i=0;i<11;i++)
- {
- pSlots[0].alias_checksum=(((pSlots[0].alias_checksum&1)<<7
- |((pSlots[0].alias_checksum&0xfe)>>1))
- +pEntry->Filename[i]);
- }
- //construct slots and entry
- for(i=nbSlots-2;i>=0;i--)
- {
- DPRINT("construct slot %d\n",i);
- pSlots[i].attr=0xf;
+ // calculate checksum for 8.3 name
+ for (pSlots[0].alias_checksum = i = 0; i < 11; i++)
+ {
+ pSlots[0].alias_checksum = (((pSlots[0].alias_checksum & 1) << 7
+ | ((pSlots[0].alias_checksum & 0xfe) >> 1))
+ + pEntry->Filename[i]);
+ }
+ //construct slots and entry
+ for (i = nbSlots - 2; i >= 0; i--)
+ {
+ DPRINT ("construct slot %d\n", i);
+ pSlots[i].attr = 0xf;
if (i)
- pSlots[i].id=nbSlots-i-1;
+ pSlots[i].id = nbSlots - i - 1;
else
- pSlots[i].id=nbSlots-i-1+0x40;
- pSlots[i].alias_checksum=pSlots[0].alias_checksum;
+ pSlots[i].id = nbSlots - i - 1 + 0x40;
+ pSlots[i].alias_checksum = pSlots[0].alias_checksum;
//FIXME pSlots[i].start=;
- FillSlot (&pSlots[i], FileName+(nbSlots-i-2)*13);
- }
+ FillSlot (&pSlots[i], FileName + (nbSlots - i - 2) * 13);
+ }
- //try to find nbSlots contiguous entries frees in directory
- for(i=0,status=STATUS_SUCCESS;status==STATUS_SUCCESS;i++)
- {
- status=FsdReadFile(DeviceExt,&FileObject,&FatEntry
- ,sizeof(FATDirEntry),i*sizeof(FATDirEntry),&LengthRead);
- if( status == STATUS_END_OF_FILE )
- break;
- if( !NT_SUCCESS( status ) )
+ //try to find nbSlots contiguous entries frees in directory
+ for (i = 0, status = STATUS_SUCCESS; status == STATUS_SUCCESS; i++)
+ {
+ status =
+ VfatReadFile (DeviceExt, &FileObject, &FatEntry, sizeof (FATDirEntry),
+ i * sizeof (FATDirEntry), &LengthRead);
+ if (status == STATUS_END_OF_FILE)
+ break;
+ if (!NT_SUCCESS (status))
{
- DPRINT1( "FsdReadFile failed to read the directory entry\n" );
+ DPRINT1 ("VfatReadFile failed to read the directory entry\n");
break;
}
- if( LengthRead != sizeof( FATDirEntry ) )
+ if (LengthRead != sizeof (FATDirEntry))
{
- DPRINT1( "FsdReadFile did not read a complete directory entry\n" );
+ DPRINT1 ("VfatReadFile did not read a complete directory entry\n");
break;
}
- if(IsDeletedEntry(&FatEntry,0))
- nbFree++;
+ if (IsDeletedEntry (&FatEntry, 0))
+ nbFree++;
else
- nbFree=0;
+ nbFree = 0;
+
+ if (nbFree == nbSlots)
+ break;
+ }
+ DPRINT ("nbSlots %d nbFree %d, entry number %d\n", nbSlots, nbFree, i);
+
+ if (RequestedOptions & FILE_DIRECTORY_FILE)
+ {
+ CurrentCluster = GetNextWriteCluster (DeviceExt, 0);
+ // zero the cluster
+ Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
+ memset (Buffer2, 0, DeviceExt->BytesPerCluster);
+ VFATWriteCluster (DeviceExt, Buffer2, CurrentCluster);
+ ExFreePool (Buffer2);
+ if (DeviceExt->FatType == FAT32)
+ {
+ pEntry->FirstClusterHigh = CurrentCluster >> 16;
+ pEntry->FirstCluster = CurrentCluster;
+ }
+ else
+ pEntry->FirstCluster = CurrentCluster;
+ }
+ if (nbFree == nbSlots)
+ { //use old slots
+ Offset = (i - nbSlots + 1) * sizeof (FATDirEntry);
+ status =
+ VfatWriteFile (DeviceExt, &FileObject, Buffer,
+ sizeof (FATDirEntry) * nbSlots, Offset);
+ DPRINT ("VfatWriteFile() returned: %x\n", status);
+ }
+ else
+ { //write at end of directory
+ Offset = (i - nbFree) * sizeof (FATDirEntry);
+ status =
+ VfatWriteFile (DeviceExt, &FileObject, Buffer,
+ sizeof (FATDirEntry) * (nbSlots + 1), Offset);
+ }
+ DPRINT ("write entry offset %d status=%x\n", Offset, status);
+ newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
+ newFCB = ExAllocatePool (NonPagedPool, sizeof (VFATFCB));
+ memset (newCCB, 0, sizeof (VFATCCB));
+ memset (newFCB, 0, sizeof (VFATFCB));
+ newCCB->pFcb = newFCB;
+ newCCB->PtrFileObject = pFileObject;
+ newFCB->RefCount++;
+
+ /*
+ * FIXME : initialize all fields in FCB and CCB
+ */
+ KeAcquireSpinLock (&DeviceExt->FcbListLock, &oldIrql);
+ InsertTailList (&DeviceExt->FcbListHead, &newFCB->FcbListEntry);
+ KeReleaseSpinLock (&DeviceExt->FcbListLock, oldIrql);
- if (nbFree==nbSlots)
- break;
- }
- DPRINT("nbSlots %d nbFree %d, entry number %d\n",nbSlots,nbFree,i);
- if(RequestedOptions&FILE_DIRECTORY_FILE)
- {
- CurrentCluster=GetNextWriteCluster(DeviceExt,0);
- // zero the cluster
- Buffer2=ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster);
- memset(Buffer2,0,DeviceExt->BytesPerCluster);
- VFATWriteCluster(DeviceExt,Buffer2,CurrentCluster);
- ExFreePool(Buffer2);
- if (DeviceExt->FatType == FAT32)
- {
- pEntry->FirstClusterHigh=CurrentCluster>>16;
- pEntry->FirstCluster=CurrentCluster;
- }
- else
- pEntry->FirstCluster=CurrentCluster;
- }
- if(nbFree==nbSlots)
- {//use old slots
- Offset=(i-nbSlots+1)*sizeof(FATDirEntry);
- status=FsdWriteFile(DeviceExt,&FileObject,Buffer
- ,sizeof(FATDirEntry)*nbSlots,Offset);
- DPRINT( "FsdWriteFile() returned: %x\n", status );
- }
- else
- {//write at end of directory
- Offset=(i-nbFree)*sizeof(FATDirEntry);
- status=FsdWriteFile(DeviceExt,&FileObject,Buffer
- ,sizeof(FATDirEntry)*(nbSlots+1),Offset);
- }
- DPRINT("write entry offset %d status=%x\n",Offset,status);
- newCCB = ExAllocatePool(NonPagedPool,sizeof(VFATCCB));
- newFCB = ExAllocatePool(NonPagedPool,sizeof(VFATFCB));
- memset(newCCB,0,sizeof(VFATCCB));
- memset(newFCB,0,sizeof(VFATFCB));
- newCCB->pFcb=newFCB;
- newCCB->PtrFileObject=pFileObject;
- newFCB->RefCount++;
-
- /*
- * FIXME : initialize all fields in FCB and CCB
- */
- KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
- InsertTailList(&DeviceExt->FcbListHead, &newFCB->FcbListEntry);
- KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
-
-
- memcpy(&newFCB->entry,pEntry,sizeof(FATDirEntry));
-DPRINT("new : entry=%11.11s\n",newFCB->entry.Filename);
-DPRINT("new : entry=%11.11s\n",pEntry->Filename);
- vfat_wcsncpy(newFCB->PathName,PathFileName,MAX_PATH);
- newFCB->ObjectName=newFCB->PathName+(PathFileName-FileName);
- newFCB->pDevExt=DeviceExt;
- pFileObject->FsContext =(PVOID) &newFCB->NTRequiredFCB;
- pFileObject->FsContext2 = newCCB;
- if(RequestedOptions&FILE_DIRECTORY_FILE)
- {
- // create . and ..
- memcpy(pEntry->Filename,". ",11);
- status=FsdWriteFile(DeviceExt,pFileObject,pEntry
- ,sizeof(FATDirEntry),0L);
- pEntry->FirstCluster
- =((VFATCCB *)(FileObject.FsContext2))->pFcb->entry.FirstCluster;
- pEntry->FirstClusterHigh
- =((VFATCCB *)(FileObject.FsContext2))->pFcb->entry.FirstClusterHigh;
- memcpy(pEntry->Filename,".. ",11);
- if(pEntry->FirstCluster==1 && DeviceExt->FatType!=FAT32)
- pEntry->FirstCluster=0;
- status=FsdWriteFile(DeviceExt,pFileObject,pEntry
- ,sizeof(FATDirEntry),sizeof(FATDirEntry));
- }
- FsdCloseFile(DeviceExt,&FileObject);
- ExFreePool(Buffer);
-DPRINT("addentry ok\n");
- return STATUS_SUCCESS;
+ memcpy (&newFCB->entry, pEntry, sizeof (FATDirEntry));
+ DPRINT ("new : entry=%11.11s\n", newFCB->entry.Filename);
+ DPRINT ("new : entry=%11.11s\n", pEntry->Filename);
+ vfat_wcsncpy (newFCB->PathName, PathFileName, MAX_PATH);
+ newFCB->ObjectName = newFCB->PathName + (PathFileName - FileName);
+ newFCB->pDevExt = DeviceExt;
+ pFileObject->FsContext = (PVOID)&newFCB->RFCB;
+ pFileObject->FsContext2 = newCCB;
+ if (RequestedOptions & FILE_DIRECTORY_FILE)
+ {
+ // create . and ..
+ memcpy (pEntry->Filename, ". ", 11);
+ status =
+ VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry),
+ 0L);
+ pEntry->FirstCluster =
+ ((VFATCCB *) (FileObject.FsContext2))->pFcb->entry.FirstCluster;
+ pEntry->FirstClusterHigh =
+ ((VFATCCB *) (FileObject.FsContext2))->pFcb->entry.FirstClusterHigh;
+ memcpy (pEntry->Filename, ".. ", 11);
+ if (pEntry->FirstCluster == 1 && DeviceExt->FatType != FAT32)
+ pEntry->FirstCluster = 0;
+ status =
+ VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry),
+ sizeof (FATDirEntry));
+ }
+ VfatCloseFile (DeviceExt, &FileObject);
+ ExFreePool (Buffer);
+ DPRINT ("addentry ok\n");
+ return STATUS_SUCCESS;
}
/* EOF */
/*
- * $Id: fat.c,v 1.8 2000/12/28 03:38:08 dwelch Exp $
+ * $Id: fat.c,v 1.9 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <ddk/ntddk.h>
#include <wchar.h>
-#include <ddk/cctypes.h>
#define NDEBUG
#include <debug.h>
/* FUNCTIONS ****************************************************************/
-ULONG
-Fat32GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
+ULONG
+Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
/*
* FUNCTION: Retrieve the next FAT32 cluster from the FAT table via a physical
* disk read
*/
{
- ULONG FATsector;
- ULONG FATeis;
- PULONG Block;
-
- Block = ExAllocatePool(NonPagedPool,1024);
- FATsector=CurrentCluster/(512/sizeof(ULONG));
- FATeis=CurrentCluster-(FATsector*(512/sizeof(ULONG)));
- VFATReadSectors(DeviceExt->StorageDevice
- ,(ULONG)(DeviceExt->FATStart+FATsector), 1,(UCHAR*) Block);
- CurrentCluster = Block[FATeis];
- if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
+ ULONG FATsector;
+ ULONG FATeis;
+ PULONG Block;
+
+ Block = ExAllocatePool (NonPagedPool, 1024);
+ FATsector = CurrentCluster / (512 / sizeof (ULONG));
+ FATeis = CurrentCluster - (FATsector * (512 / sizeof (ULONG)));
+ VFATReadSectors (DeviceExt->StorageDevice,
+ (ULONG) (DeviceExt->FATStart + FATsector), 1,
+ (UCHAR *) Block);
+ CurrentCluster = Block[FATeis];
+ if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
CurrentCluster = 0xffffffff;
- ExFreePool(Block);
- return(CurrentCluster);
+ ExFreePool (Block);
+ return (CurrentCluster);
}
-ULONG
-Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
+ULONG
+Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
/*
* FUNCTION: Retrieve the next FAT16 cluster from the FAT table from the
* in-memory FAT
*/
{
- PUSHORT Block;
- Block=(PUSHORT)DeviceExt->FAT;
- CurrentCluster = Block[CurrentCluster];
- if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
- CurrentCluster = 0xffffffff;
- DPRINT("Returning %x\n",CurrentCluster);
- return(CurrentCluster);
+ PUSHORT Block;
+ Block = (PUSHORT) DeviceExt->FAT;
+ CurrentCluster = Block[CurrentCluster];
+ if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
+ CurrentCluster = 0xffffffff;
+ DPRINT ("Returning %x\n", CurrentCluster);
+ return (CurrentCluster);
}
-ULONG
-Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
+ULONG
+Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
/*
* FUNCTION: Retrieve the next FAT12 cluster from the FAT table from the
* in-memory FAT
*/
{
- unsigned char* CBlock;
- ULONG FATOffset;
- ULONG Entry;
- CBlock = DeviceExt->FAT;
- FATOffset = (CurrentCluster * 12)/ 8;//first byte containing value
- if ((CurrentCluster % 2) == 0)
- {
- Entry = CBlock[FATOffset];
- Entry |= ((CBlock[FATOffset+1] & 0xf)<<8);
- }
- else
- {
- Entry = (CBlock[FATOffset] >> 4);
- Entry |= (CBlock[FATOffset+1] << 4);
- }
- DPRINT("Entry %x\n",Entry);
- if (Entry >= 0xff8 && Entry <= 0xfff)
+ unsigned char *CBlock;
+ ULONG FATOffset;
+ ULONG Entry;
+ CBlock = DeviceExt->FAT;
+ FATOffset = (CurrentCluster * 12) / 8; //first byte containing value
+ if ((CurrentCluster % 2) == 0)
+ {
+ Entry = CBlock[FATOffset];
+ Entry |= ((CBlock[FATOffset + 1] & 0xf) << 8);
+ }
+ else
+ {
+ Entry = (CBlock[FATOffset] >> 4);
+ Entry |= (CBlock[FATOffset + 1] << 4);
+ }
+ DPRINT ("Entry %x\n", Entry);
+ if (Entry >= 0xff8 && Entry <= 0xfff)
Entry = 0xffffffff;
- DPRINT("Returning %x\n",Entry);
- return(Entry);
+ DPRINT ("Returning %x\n", Entry);
+ return (Entry);
}
-ULONG
-GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
+ULONG
+GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
/*
* FUNCTION: Retrieve the next cluster depending on the FAT type
*/
{
- ULONG NextCluster;
-
- DPRINT("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
- DeviceExt,CurrentCluster);
-
- ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
-
- if (DeviceExt->FatType == FAT16)
- {
- NextCluster = Fat16GetNextCluster(DeviceExt, CurrentCluster);
- }
- else if (DeviceExt->FatType == FAT32)
- {
- NextCluster = Fat32GetNextCluster(DeviceExt, CurrentCluster);
- }
- else
- {
- NextCluster = Fat12GetNextCluster(DeviceExt, CurrentCluster);
- }
-
- ExReleaseResourceLite(&DeviceExt->FatResource);
-
- return(NextCluster);
+ ULONG NextCluster;
+
+ DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
+ DeviceExt, CurrentCluster);
+
+ ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
+
+ if (DeviceExt->FatType == FAT16)
+ {
+ NextCluster = Fat16GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ else if (DeviceExt->FatType == FAT32)
+ {
+ NextCluster = Fat32GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ else
+ {
+ NextCluster = Fat12GetNextCluster (DeviceExt, CurrentCluster);
+ }
+
+ ExReleaseResourceLite (&DeviceExt->FatResource);
+
+ return (NextCluster);
}
-ULONG
-FAT16FindAvailableCluster(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Finds the first available cluster in a FAT16 table
*/
{
- PUSHORT Block;
- int i;
- Block=(PUSHORT)DeviceExt->FAT;
- for(i=2;i<(DeviceExt->Boot->FATSectors*256) ;i++)
- if(Block[i]==0)
- return (i);
- /* Give an error message (out of disk space) if we reach here) */
- return 0;
+ PUSHORT Block;
+ int i;
+ Block = (PUSHORT) DeviceExt->FAT;
+ for (i = 2; i < (DeviceExt->Boot->FATSectors * 256); i++)
+ if (Block[i] == 0)
+ return (i);
+ /* Give an error message (out of disk space) if we reach here) */
+ return 0;
}
-ULONG
-FAT12FindAvailableCluster(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Finds the first available cluster in a FAT12 table
*/
{
- ULONG FATOffset;
- ULONG Entry;
- PUCHAR CBlock=DeviceExt->FAT;
- ULONG i;
- for(i=2;i<((DeviceExt->Boot->FATSectors*512*8)/12) ;i++)
- {
- FATOffset = (i * 12)/8;
- if ((i % 2) == 0)
- {
- Entry = CBlock[FATOffset];
- Entry |= ((CBlock[FATOffset + 1] & 0xf)<<8);
- }
- else
- {
- Entry = (CBlock[FATOffset] >> 4);
- Entry |= (CBlock[FATOffset + 1] << 4);
- }
- if(Entry==0)
- return (i);
- }
- /* Give an error message (out of disk space) if we reach here) */
- DbgPrint("Disk full, %d clusters used\n",i);
- return 0;
+ ULONG FATOffset;
+ ULONG Entry;
+ PUCHAR CBlock = DeviceExt->FAT;
+ ULONG i;
+ for (i = 2; i < ((DeviceExt->Boot->FATSectors * 512 * 8) / 12); i++)
+ {
+ FATOffset = (i * 12) / 8;
+ if ((i % 2) == 0)
+ {
+ Entry = CBlock[FATOffset];
+ Entry |= ((CBlock[FATOffset + 1] & 0xf) << 8);
+ }
+ else
+ {
+ Entry = (CBlock[FATOffset] >> 4);
+ Entry |= (CBlock[FATOffset + 1] << 4);
+ }
+ if (Entry == 0)
+ return (i);
+ }
+ /* Give an error message (out of disk space) if we reach here) */
+ DbgPrint ("Disk full, %d clusters used\n", i);
+ return 0;
}
-ULONG
-FAT32FindAvailableCluster(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Finds the first available cluster in a FAT32 table
*/
{
- ULONG sector;
- PULONG Block;
- int i;
- Block = ExAllocatePool(NonPagedPool,BLOCKSIZE);
- for(sector=0
- ;sector< ((struct _BootSector32*)(DeviceExt->Boot))->FATSectors32
- ;sector++)
- {
- VFATReadSectors(DeviceExt->StorageDevice
- ,(ULONG)(DeviceExt->FATStart+sector), 1,(UCHAR*) Block);
-
- for(i=0; i<512; i++)
- {
- if(Block[i]==0)
- {
- ExFreePool(Block);
- return (i+sector*128);
- }
- }
- }
- /* Give an error message (out of disk space) if we reach here) */
- ExFreePool(Block);
- return 0;
+ ULONG sector;
+ PULONG Block;
+ int i;
+ Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ for (sector = 0;
+ sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
+ sector++)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ (ULONG) (DeviceExt->FATStart + sector), 1,
+ (UCHAR *) Block);
+
+ for (i = 0; i < 512; i++)
+ {
+ if (Block[i] == 0)
+ {
+ ExFreePool (Block);
+ return (i + sector * 128);
+ }
+ }
+ }
+ /* Give an error message (out of disk space) if we reach here) */
+ ExFreePool (Block);
+ return 0;
}
-ULONG
-FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Counts free cluster in a FAT12 table
*/
{
- ULONG FATOffset;
- ULONG Entry;
- PUCHAR CBlock=DeviceExt->FAT;
- ULONG ulCount = 0;
- ULONG i;
-
- ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
-
- for(i=2;i<((DeviceExt->Boot->FATSectors*512*8)/12) ;i++)
- {
- FATOffset = (i * 12)/8;
- if ((i % 2) == 0)
- {
- Entry = CBlock[FATOffset];
- Entry |= ((CBlock[FATOffset + 1] & 0xf)<<8);
- }
- else
- {
- Entry = (CBlock[FATOffset] >> 4);
- Entry |= (CBlock[FATOffset + 1] << 4);
- }
- if(Entry==0)
- ulCount++;
- }
-
- ExReleaseResourceLite(&DeviceExt->FatResource);
-
- return ulCount;
+ ULONG FATOffset;
+ ULONG Entry;
+ PUCHAR CBlock = DeviceExt->FAT;
+ ULONG ulCount = 0;
+ ULONG i;
+
+ ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
+
+ for (i = 2; i < ((DeviceExt->Boot->FATSectors * 512 * 8) / 12); i++)
+ {
+ FATOffset = (i * 12) / 8;
+ if ((i % 2) == 0)
+ {
+ Entry = CBlock[FATOffset];
+ Entry |= ((CBlock[FATOffset + 1] & 0xf) << 8);
+ }
+ else
+ {
+ Entry = (CBlock[FATOffset] >> 4);
+ Entry |= (CBlock[FATOffset + 1] << 4);
+ }
+ if (Entry == 0)
+ ulCount++;
+ }
+
+ ExReleaseResourceLite (&DeviceExt->FatResource);
+
+ return ulCount;
}
-ULONG
-FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Counts free clusters in a FAT16 table
*/
{
- PUSHORT Block;
- ULONG ulCount = 0;
- ULONG i;
-
- ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
-
- Block=(PUSHORT)DeviceExt->FAT;
- for(i=2;i<(DeviceExt->Boot->FATSectors*256);i++)
- {
- if(Block[i]==0)
- ulCount++;
- }
-
- ExReleaseResourceLite(&DeviceExt->FatResource);
-
- return ulCount;
+ PUSHORT Block;
+ ULONG ulCount = 0;
+ ULONG i;
+
+ ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
+
+ Block = (PUSHORT) DeviceExt->FAT;
+ for (i = 2; i < (DeviceExt->Boot->FATSectors * 256); i++)
+ {
+ if (Block[i] == 0)
+ ulCount++;
+ }
+
+ ExReleaseResourceLite (&DeviceExt->FatResource);
+
+ return ulCount;
}
-ULONG
-FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
+ULONG
+FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
/*
* FUNCTION: Counts free clusters in a FAT32 table
*/
{
- ULONG sector;
- PULONG Block;
- ULONG ulCount = 0;
- ULONG i;
-
- ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
-
- Block = ExAllocatePool(NonPagedPool,BLOCKSIZE);
- for(sector=0
- ;sector< ((struct _BootSector32*)(DeviceExt->Boot))->FATSectors32
- ;sector++)
- {
- VFATReadSectors(DeviceExt->StorageDevice
- ,(ULONG)(DeviceExt->FATStart+sector), 1,(UCHAR*) Block);
-
- for(i=0; i<512; i++)
- {
- if(Block[i]==0)
- ulCount++;
- }
- }
- /* Give an error message (out of disk space) if we reach here) */
- ExFreePool(Block);
- ExReleaseResourceLite(&DeviceExt->FatResource);
- return ulCount;
+ ULONG sector;
+ PULONG Block;
+ ULONG ulCount = 0;
+ ULONG i;
+
+ ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
+
+ Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ for (sector = 0;
+ sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
+ sector++)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ (ULONG) (DeviceExt->FATStart + sector), 1,
+ (UCHAR *) Block);
+
+ for (i = 0; i < 512; i++)
+ {
+ if (Block[i] == 0)
+ ulCount++;
+ }
+ }
+ /* Give an error message (out of disk space) if we reach here) */
+ ExFreePool (Block);
+ ExReleaseResourceLite (&DeviceExt->FatResource);
+ return ulCount;
}
-VOID
-FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
- ULONG NewValue)
+VOID
+FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
+ ULONG NewValue)
/*
* FUNCTION: Writes a cluster to the FAT12 physical and in-memory tables
*/
{
- ULONG FATsector;
- ULONG FATOffset;
- PUCHAR CBlock=DeviceExt->FAT;
- int i;
- FATOffset = (ClusterToWrite * 12)/8;
- if ((ClusterToWrite % 2) == 0)
- {
- CBlock[FATOffset]=NewValue;
- CBlock[FATOffset + 1] &=0xf0;
- CBlock[FATOffset + 1]
- |= (NewValue&0xf00)>>8;
- }
- else
- {
- CBlock[FATOffset] &=0x0f;
- CBlock[FATOffset]
- |= (NewValue&0xf)<<4;
- CBlock[FATOffset+1]=NewValue>>4;
- }
- /* Write the changed FAT sector(s) to disk */
- FATsector=FATOffset/BLOCKSIZE;
- for(i=0;i<DeviceExt->Boot->FATCount;i++)
- {
- if( (FATOffset%BLOCKSIZE)==(BLOCKSIZE-1))//entry is on 2 sectors
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- DeviceExt->FATStart+FATsector
- +i*DeviceExt->Boot->FATSectors,
- 2,
- CBlock+FATsector*512);
- }
+ ULONG FATsector;
+ ULONG FATOffset;
+ PUCHAR CBlock = DeviceExt->FAT;
+ int i;
+ FATOffset = (ClusterToWrite * 12) / 8;
+ if ((ClusterToWrite % 2) == 0)
+ {
+ CBlock[FATOffset] = NewValue;
+ CBlock[FATOffset + 1] &= 0xf0;
+ CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8;
+ }
+ else
+ {
+ CBlock[FATOffset] &= 0x0f;
+ CBlock[FATOffset] |= (NewValue & 0xf) << 4;
+ CBlock[FATOffset + 1] = NewValue >> 4;
+ }
+ /* Write the changed FAT sector(s) to disk */
+ FATsector = FATOffset / BLOCKSIZE;
+ for (i = 0; i < DeviceExt->Boot->FATCount; i++)
+ {
+ if ((FATOffset % BLOCKSIZE) == (BLOCKSIZE - 1)) //entry is on 2 sectors
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ DeviceExt->FATStart + FATsector
+ + i * DeviceExt->Boot->FATSectors,
+ 2, CBlock + FATsector * 512);
+ }
else
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- DeviceExt->FATStart+FATsector
- +i*DeviceExt->Boot->FATSectors,
- 1,
- CBlock+FATsector*512);
- }
- }
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ DeviceExt->FATStart + FATsector
+ + i * DeviceExt->Boot->FATSectors,
+ 1, CBlock + FATsector * 512);
+ }
+ }
}
-VOID
-FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
- ULONG NewValue)
+VOID
+FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
+ ULONG NewValue)
/*
* FUNCTION: Writes a cluster to the FAT16 physical and in-memory tables
*/
{
- ULONG FATsector;
- PUSHORT Block;
- ULONG Start;
- int i;
-
- DbgPrint("FAT16WriteCluster %u : %u\n", ClusterToWrite, NewValue);
-
- Block=(PUSHORT)DeviceExt->FAT;
- FATsector=ClusterToWrite/(512/sizeof(USHORT));
-
- /* Update the in-memory FAT */
- Block[ClusterToWrite] = NewValue;
-
- /* Write the changed FAT sector to disk (all FAT's) */
- Start = DeviceExt->FATStart + FATsector;
- for (i = 0; i < DeviceExt->Boot->FATCount; i++)
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- Start,
- 1,
- ((UCHAR *)Block)+FATsector*512);
- Start += DeviceExt->Boot->FATSectors;
- }
+ ULONG FATsector;
+ PUSHORT Block;
+ ULONG Start;
+ int i;
+
+ DbgPrint ("FAT16WriteCluster %u : %u\n", ClusterToWrite, NewValue);
+
+ Block = (PUSHORT) DeviceExt->FAT;
+ FATsector = ClusterToWrite / (512 / sizeof (USHORT));
+
+ /* Update the in-memory FAT */
+ Block[ClusterToWrite] = NewValue;
+
+ /* Write the changed FAT sector to disk (all FAT's) */
+ Start = DeviceExt->FATStart + FATsector;
+ for (i = 0; i < DeviceExt->Boot->FATCount; i++)
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ Start, 1, ((UCHAR *) Block) + FATsector * 512);
+ Start += DeviceExt->Boot->FATSectors;
+ }
}
-VOID
-FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
- ULONG NewValue)
+VOID
+FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
+ ULONG NewValue)
/*
* FUNCTION: Writes a cluster to the FAT32 physical tables
*/
{
- ULONG FATsector;
- ULONG FATeis;
- PUSHORT Block;
- ULONG Start;
- int i;
- struct _BootSector32 *pBoot;
-DbgPrint("FAT32WriteCluster %u : %u\n",ClusterToWrite,NewValue);
- Block = ExAllocatePool(NonPagedPool,BLOCKSIZE);
- FATsector=ClusterToWrite/128;
- FATeis=ClusterToWrite-(FATsector*128);
- /* load sector, change value, then rewrite sector */
- VFATReadSectors(DeviceExt->StorageDevice,
- DeviceExt->FATStart+FATsector,
- 1,
- (UCHAR *)Block);
- Block[FATeis] = NewValue;
- /* Write the changed FAT sector to disk (all FAT's) */
- Start = DeviceExt->FATStart + FATsector;
- pBoot = (struct _BootSector32*) DeviceExt->Boot;
- for (i = 0; i < pBoot->FATCount; i++)
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- Start,
- 1,
- (UCHAR *)Block);
- Start += pBoot->FATSectors;
- }
- ExFreePool(Block);
+ ULONG FATsector;
+ ULONG FATeis;
+ PUSHORT Block;
+ ULONG Start;
+ int i;
+ struct _BootSector32 *pBoot;
+ DbgPrint ("FAT32WriteCluster %u : %u\n", ClusterToWrite, NewValue);
+ Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
+ FATsector = ClusterToWrite / 128;
+ FATeis = ClusterToWrite - (FATsector * 128);
+ /* load sector, change value, then rewrite sector */
+ VFATReadSectors (DeviceExt->StorageDevice,
+ DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block);
+ Block[FATeis] = NewValue;
+ /* Write the changed FAT sector to disk (all FAT's) */
+ Start = DeviceExt->FATStart + FATsector;
+ pBoot = (struct _BootSector32 *) DeviceExt->Boot;
+ for (i = 0; i < pBoot->FATCount; i++)
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice, Start, 1, (UCHAR *) Block);
+ Start += pBoot->FATSectors;
+ }
+ ExFreePool (Block);
}
-VOID
-WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
- ULONG NewValue)
+VOID
+WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
+ ULONG NewValue)
/*
* FUNCTION: Write a changed FAT entry
*/
{
- if (DeviceExt->FatType==FAT16)
- {
- FAT16WriteCluster(DeviceExt, ClusterToWrite, NewValue);
- }
- else if (DeviceExt->FatType==FAT32)
- {
- FAT32WriteCluster(DeviceExt, ClusterToWrite, NewValue);
- }
- else
- {
- FAT12WriteCluster(DeviceExt, ClusterToWrite, NewValue);
- }
+ if (DeviceExt->FatType == FAT16)
+ {
+ FAT16WriteCluster (DeviceExt, ClusterToWrite, NewValue);
+ }
+ else if (DeviceExt->FatType == FAT32)
+ {
+ FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue);
+ }
+ else
+ {
+ FAT12WriteCluster (DeviceExt, ClusterToWrite, NewValue);
+ }
}
-ULONG
-GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
+ULONG
+GetNextWriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
/*
* FUNCTION: Determines the next cluster to be written
*/
{
- ULONG LastCluster, NewCluster;
- UCHAR *Buffer2;
-
- DPRINT("GetNextWriteCluster(DeviceExt %x, CurrentCluster %x)\n",
- DeviceExt,CurrentCluster);
-
- /* Find out what was happening in the last cluster's AU */
- LastCluster=GetNextCluster(DeviceExt,
- CurrentCluster);
- /* Check to see if we must append or overwrite */
- if (LastCluster == 0xffffffff)
- {
- /* we are after last existing cluster : we must add one to file */
- /* Append */
- /* Firstly, find the next available open allocation unit */
- if (DeviceExt->FatType == FAT16)
- {
- NewCluster = FAT16FindAvailableCluster(DeviceExt);
- DPRINT1("NewCluster %x\n", NewCluster);
- }
- else if (DeviceExt->FatType == FAT32)
- {
- NewCluster = FAT32FindAvailableCluster(DeviceExt);
- }
- else
- {
- NewCluster = FAT12FindAvailableCluster(DeviceExt);
- DPRINT( "NewFat12Cluster: %x\n", NewCluster );
- }
- /* Mark the new AU as the EOF */
- WriteCluster(DeviceExt, NewCluster, 0xFFFFFFFF);
- /* Now, write the AU of the LastCluster with the value of the newly
- found AU */
- if(CurrentCluster)
- {
- WriteCluster(DeviceExt, CurrentCluster, NewCluster);
- }
- // fill cluster with zero
- Buffer2=ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster);
- memset(Buffer2,0,DeviceExt->BytesPerCluster);
- VFATWriteCluster(DeviceExt,Buffer2,NewCluster);
- ExFreePool(Buffer2);
- /* Return NewCluster as CurrentCluster */
- return NewCluster;
- }
- else
- {
- /* Overwrite: Return LastCluster as CurrentCluster */
- return LastCluster;
- }
+ ULONG LastCluster, NewCluster;
+ UCHAR *Buffer2;
+
+ DPRINT ("GetNextWriteCluster(DeviceExt %x, CurrentCluster %x)\n",
+ DeviceExt, CurrentCluster);
+
+ /* Find out what was happening in the last cluster's AU */
+ LastCluster = GetNextCluster (DeviceExt, CurrentCluster);
+ /* Check to see if we must append or overwrite */
+ if (LastCluster == 0xffffffff)
+ {
+ /* we are after last existing cluster : we must add one to file */
+ /* Append */
+ /* Firstly, find the next available open allocation unit */
+ if (DeviceExt->FatType == FAT16)
+ {
+ NewCluster = FAT16FindAvailableCluster (DeviceExt);
+ DPRINT1 ("NewCluster %x\n", NewCluster);
+ }
+ else if (DeviceExt->FatType == FAT32)
+ {
+ NewCluster = FAT32FindAvailableCluster (DeviceExt);
+ }
+ else
+ {
+ NewCluster = FAT12FindAvailableCluster (DeviceExt);
+ DPRINT ("NewFat12Cluster: %x\n", NewCluster);
+ }
+ /* Mark the new AU as the EOF */
+ WriteCluster (DeviceExt, NewCluster, 0xFFFFFFFF);
+ /* Now, write the AU of the LastCluster with the value of the newly
+ found AU */
+ if (CurrentCluster)
+ {
+ WriteCluster (DeviceExt, CurrentCluster, NewCluster);
+ }
+ // fill cluster with zero
+ Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
+ memset (Buffer2, 0, DeviceExt->BytesPerCluster);
+ VFATWriteCluster (DeviceExt, Buffer2, NewCluster);
+ ExFreePool (Buffer2);
+ /* Return NewCluster as CurrentCluster */
+ return NewCluster;
+ }
+ else
+ {
+ /* Overwrite: Return LastCluster as CurrentCluster */
+ return LastCluster;
+ }
}
-ULONG
-ClusterToSector(PDEVICE_EXTENSION DeviceExt,
- unsigned long Cluster)
+ULONG
+ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
/*
* FUNCTION: Converts the cluster number to a sector number for this physical
* device
*/
{
- return DeviceExt->dataStart+((Cluster-2)*DeviceExt->Boot->SectorsPerCluster);
+ return DeviceExt->dataStart +
+ ((Cluster - 2) * DeviceExt->Boot->SectorsPerCluster);
}
VOID
-VFATLoadCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
+VFATLoadCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
/*
* FUNCTION: Load a cluster from the physical device
*/
{
- ULONG Sector;
+ ULONG Sector;
- DPRINT("VFATLoadCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
- DeviceExt,Buffer,Cluster);
+ DPRINT ("VFATLoadCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
+ DeviceExt, Buffer, Cluster);
- Sector = ClusterToSector(DeviceExt, Cluster);
+ Sector = ClusterToSector (DeviceExt, Cluster);
- VFATReadSectors(DeviceExt->StorageDevice,
- Sector,
- DeviceExt->Boot->SectorsPerCluster,
- Buffer);
- DPRINT("Finished VFATReadSectors\n");
+ VFATReadSectors (DeviceExt->StorageDevice,
+ Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
+ DPRINT ("Finished VFATReadSectors\n");
}
-VOID
-VFATWriteCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
+VOID
+VFATWriteCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
/*
* FUNCTION: Write a cluster to the physical device
*/
{
- ULONG Sector;
- DPRINT("VFATWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
- DeviceExt,Buffer,Cluster);
-
- Sector = ClusterToSector(DeviceExt, Cluster);
-
- VFATWriteSectors(DeviceExt->StorageDevice,
- Sector,
- DeviceExt->Boot->SectorsPerCluster,
- Buffer);
-}
+ ULONG Sector;
+ DPRINT ("VFATWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
+ DeviceExt, Buffer, Cluster);
+ Sector = ClusterToSector (DeviceExt, Cluster);
+
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
+}
-/* $Id: finfo.c,v 1.4 2000/09/12 10:12:13 jean Exp $
+/* $Id: finfo.c,v 1.5 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <ddk/ntddk.h>
#include <wchar.h>
-#include <ddk/cctypes.h>
#define NDEBUG
#include <debug.h>
/* FUNCTIONS ****************************************************************/
-NTSTATUS FsdGetStandardInformation(PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
- PFILE_STANDARD_INFORMATION StandardInfo)
+NTSTATUS
+VfatGetStandardInformation (PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
+ PFILE_STANDARD_INFORMATION StandardInfo)
/*
* FUNCTION: Retrieve the standard file information
*/
DeviceExtension = DeviceObject->DeviceExtension;
/* PRECONDITION */
- assert(DeviceExtension != NULL);
- assert(DeviceExtension->BytesPerCluster != 0);
- assert(StandardInfo != NULL);
- assert(FCB != NULL);
+ assert (DeviceExtension != NULL);
+ assert (DeviceExtension->BytesPerCluster != 0);
+ assert (StandardInfo != NULL);
+ assert (FCB != NULL);
- RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
+ RtlZeroMemory (StandardInfo, sizeof (FILE_STANDARD_INFORMATION));
/* Make allocsize a rounded up multiple of BytesPerCluster */
- AllocSize = ((FCB->entry.FileSize + DeviceExtension->BytesPerCluster - 1) /
- DeviceExtension->BytesPerCluster) *
- DeviceExtension->BytesPerCluster;
-
- StandardInfo->AllocationSize = RtlConvertUlongToLargeInteger(AllocSize);
- StandardInfo->EndOfFile = RtlConvertUlongToLargeInteger(FCB->entry.FileSize);
- StandardInfo->NumberOfLinks = 0;
- StandardInfo->DeletePending = FALSE;
- if((FCB->entry.Attrib & 0x10)>0) {
- StandardInfo->Directory = TRUE;
- } else {
- StandardInfo->Directory = FALSE;
- }
+ AllocSize = ((FCB->entry.FileSize + DeviceExtension->BytesPerCluster - 1) /
+ DeviceExtension->BytesPerCluster) *
+ DeviceExtension->BytesPerCluster;
+
+ StandardInfo->AllocationSize = RtlConvertUlongToLargeInteger (AllocSize);
+ StandardInfo->EndOfFile =
+ RtlConvertUlongToLargeInteger (FCB->entry.FileSize);
+ StandardInfo->NumberOfLinks = 0;
+ StandardInfo->DeletePending = FALSE;
+ if ((FCB->entry.Attrib & 0x10) > 0)
+ {
+ StandardInfo->Directory = TRUE;
+ }
+ else
+ {
+ StandardInfo->Directory = FALSE;
+ }
return STATUS_SUCCESS;
}
-NTSTATUS FsdSetPositionInformation(PFILE_OBJECT FileObject,
- PVFATFCB FCB,
- PDEVICE_OBJECT DeviceObject,
- PFILE_POSITION_INFORMATION PositionInfo)
- {
- DPRINT("FsdSetPositionInformation()\n");
-
- DPRINT("PositionInfo %x\n", PositionInfo);
- DPRINT("Setting position %d\n", PositionInfo->CurrentByteOffset.u.LowPart);
- memcpy(&FileObject->CurrentByteOffset,&PositionInfo->CurrentByteOffset,
- sizeof(LARGE_INTEGER));
-
- return(STATUS_SUCCESS);
- }
-
-NTSTATUS FsdGetPositionInformation(PFILE_OBJECT FileObject,
- PVFATFCB FCB,
- PDEVICE_OBJECT DeviceObject,
- PFILE_POSITION_INFORMATION PositionInfo)
- {
- DPRINT("FsdGetPositionInformation()\n");
-
- memcpy(&PositionInfo->CurrentByteOffset, &FileObject->CurrentByteOffset,
- sizeof(LARGE_INTEGER));
- DPRINT("Getting position %x\n", PositionInfo->CurrentByteOffset.u.LowPart);
- return(STATUS_SUCCESS);
- }
-
-NTSTATUS FsdGetBasicInformation(PFILE_OBJECT FileObject,
- PVFATFCB FCB,
- PDEVICE_OBJECT DeviceObject,
- PFILE_BASIC_INFORMATION BasicInfo)
+NTSTATUS
+VfatSetPositionInformation (PFILE_OBJECT FileObject,
+ PVFATFCB FCB,
+ PDEVICE_OBJECT DeviceObject,
+ PFILE_POSITION_INFORMATION PositionInfo)
{
- DPRINT("FsdGetBasicInformation()\n");
+ DPRINT ("FsdSetPositionInformation()\n");
- FsdDosDateTimeToFileTime(FCB->entry.CreationDate,FCB->entry.CreationTime,
- &BasicInfo->CreationTime);
- FsdDosDateTimeToFileTime(FCB->entry.AccessDate,0,
- &BasicInfo->LastAccessTime);
- FsdDosDateTimeToFileTime(FCB->entry.UpdateDate,FCB->entry.UpdateTime,
- &BasicInfo->LastWriteTime);
- FsdDosDateTimeToFileTime(FCB->entry.UpdateDate,FCB->entry.UpdateTime,
- &BasicInfo->ChangeTime);
+ DPRINT ("PositionInfo %x\n", PositionInfo);
+ DPRINT ("Setting position %d\n", PositionInfo->CurrentByteOffset.u.LowPart);
+ memcpy (&FileObject->CurrentByteOffset, &PositionInfo->CurrentByteOffset,
+ sizeof (LARGE_INTEGER));
- BasicInfo->FileAttributes = FCB->entry.Attrib;
+ return (STATUS_SUCCESS);
+}
- DPRINT("Getting attributes %x\n", BasicInfo->FileAttributes);
+NTSTATUS
+VfatGetPositionInformation (PFILE_OBJECT FileObject,
+ PVFATFCB FCB,
+ PDEVICE_OBJECT DeviceObject,
+ PFILE_POSITION_INFORMATION PositionInfo)
+{
+ DPRINT ("VfatGetPositionInformation()\n");
- return(STATUS_SUCCESS);
+ memcpy (&PositionInfo->CurrentByteOffset, &FileObject->CurrentByteOffset,
+ sizeof (LARGE_INTEGER));
+ DPRINT ("Getting position %x\n", PositionInfo->CurrentByteOffset.u.LowPart);
+ return (STATUS_SUCCESS);
}
+NTSTATUS
+VfatGetBasicInformation (PFILE_OBJECT FileObject,
+ PVFATFCB FCB,
+ PDEVICE_OBJECT DeviceObject,
+ PFILE_BASIC_INFORMATION BasicInfo)
+{
+ DPRINT ("VfatGetBasicInformation()\n");
+
+ FsdDosDateTimeToFileTime (FCB->entry.CreationDate, FCB->entry.CreationTime,
+ &BasicInfo->CreationTime);
+ FsdDosDateTimeToFileTime (FCB->entry.AccessDate, 0,
+ &BasicInfo->LastAccessTime);
+ FsdDosDateTimeToFileTime (FCB->entry.UpdateDate, FCB->entry.UpdateTime,
+ &BasicInfo->LastWriteTime);
+ FsdDosDateTimeToFileTime (FCB->entry.UpdateDate, FCB->entry.UpdateTime,
+ &BasicInfo->ChangeTime);
+
+ BasicInfo->FileAttributes = FCB->entry.Attrib;
+
+ DPRINT ("Getting attributes %x\n", BasicInfo->FileAttributes);
-NTSTATUS FsdSetDispositionInformation(PFILE_OBJECT FileObject,
- PVFATFCB FCB,
- PDEVICE_OBJECT DeviceObject,
- PFILE_DISPOSITION_INFORMATION DispositionInfo)
+ return (STATUS_SUCCESS);
+}
+
+
+NTSTATUS
+VfatSetDispositionInformation (PFILE_OBJECT FileObject,
+ PVFATFCB FCB,
+ PDEVICE_OBJECT DeviceObject,
+ PFILE_DISPOSITION_INFORMATION DispositionInfo)
{
- DPRINT("FsdSetDispositionInformation()\n");
+ DPRINT ("FsdSetDispositionInformation()\n");
- FileObject->DeletePending = DispositionInfo->DoDeleteFile;
-
- return(STATUS_SUCCESS);
+ FileObject->DeletePending = DispositionInfo->DoDeleteFile;
+
+ return (STATUS_SUCCESS);
}
-NTSTATUS STDCALL FsdQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatQueryInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Retrieve the specified file information
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
- FILE_INFORMATION_CLASS FileInformationClass =
- Stack->Parameters.QueryFile.FileInformationClass;
- PFILE_OBJECT FileObject = NULL;
- PVFATFCB FCB = NULL;
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+ FILE_INFORMATION_CLASS FileInformationClass =
+ Stack->Parameters.QueryFile.FileInformationClass;
+ PFILE_OBJECT FileObject = NULL;
+ PVFATFCB FCB = NULL;
// PVFATCCB CCB = NULL;
- NTSTATUS RC = STATUS_SUCCESS;
- void *SystemBuffer;
+ NTSTATUS RC = STATUS_SUCCESS;
+ void *SystemBuffer;
- /* PRECONDITION */
- assert(DeviceObject != NULL);
- assert(Irp != NULL);
+ /* PRECONDITION */
+ assert (DeviceObject != NULL);
+ assert (Irp != NULL);
- /* INITIALIZATION */
- Stack = IoGetCurrentIrpStackLocation(Irp);
- FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
- FileObject = Stack->FileObject;
+ /* INITIALIZATION */
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
+ FileObject = Stack->FileObject;
// CCB = (PVFATCCB)(FileObject->FsContext2);
// FCB = CCB->Buffer; // Should be CCB->FCB???
- FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
+ FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
// FIXME : determine Buffer for result :
- if (Irp->MdlAddress)
- SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
+ if (Irp->MdlAddress)
+ SystemBuffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
else
SystemBuffer = Irp->UserBuffer;
// SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
- switch(FileInformationClass) {
- case FileStandardInformation:
- RC = FsdGetStandardInformation(FCB, DeviceObject, SystemBuffer);
+ switch (FileInformationClass)
+ {
+ case FileStandardInformation:
+ RC = VfatGetStandardInformation (FCB, DeviceObject, SystemBuffer);
break;
- case FilePositionInformation:
- RC = FsdGetPositionInformation(FileObject,
- FCB,
- DeviceObject,
- SystemBuffer);
+ case FilePositionInformation:
+ RC = VfatGetPositionInformation (FileObject,
+ FCB, DeviceObject, SystemBuffer);
break;
- case FileBasicInformation:
- RC = FsdGetBasicInformation(FileObject,
- FCB,
- DeviceObject,
- SystemBuffer);
+ case FileBasicInformation:
+ RC = VfatGetBasicInformation (FileObject,
+ FCB, DeviceObject, SystemBuffer);
break;
- default:
- RC=STATUS_NOT_IMPLEMENTED;
- }
+ default:
+ RC = STATUS_NOT_IMPLEMENTED;
+ }
- Irp->IoStatus.Status = RC;
- Irp->IoStatus.Information = 0;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ Irp->IoStatus.Status = RC;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
- return RC;
+ return RC;
}
-NTSTATUS STDCALL VfatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatSetInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Retrieve the specified file information
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
- FILE_INFORMATION_CLASS FileInformationClass;
- PFILE_OBJECT FileObject = NULL;
- PVFATFCB FCB = NULL;
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+ FILE_INFORMATION_CLASS FileInformationClass;
+ PFILE_OBJECT FileObject = NULL;
+ PVFATFCB FCB = NULL;
// PVFATCCB CCB = NULL;
- NTSTATUS RC = STATUS_SUCCESS;
- PVOID SystemBuffer;
-
- /* PRECONDITION */
- assert(DeviceObject != NULL);
- assert(Irp != NULL);
-
- DPRINT("FsdSetInformation(DeviceObject %x, Irp %x)\n",
- DeviceObject,Irp);
-
- /* INITIALIZATION */
- Stack = IoGetCurrentIrpStackLocation(Irp);
- FileInformationClass = Stack->Parameters.SetFile.FileInformationClass;
- FileObject = Stack->FileObject;
- FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
-
- // FIXME : determine Buffer for result :
- if (Irp->MdlAddress)
- SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
- else
- SystemBuffer = Irp->UserBuffer;
- // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
-
- DPRINT("FileInformationClass %d\n",FileInformationClass);
- DPRINT("SystemBuffer %x\n",SystemBuffer);
-
- switch(FileInformationClass)
- {
- case FilePositionInformation:
- RC = FsdSetPositionInformation(FileObject,
- FCB,
- DeviceObject,
- SystemBuffer);
- break;
- case FileDispositionInformation:
- RC = FsdSetDispositionInformation(FileObject,
- FCB,
- DeviceObject,
- SystemBuffer);
- break;
- default:
- RC = STATUS_NOT_IMPLEMENTED;
- }
-
- Irp->IoStatus.Status = RC;
- Irp->IoStatus.Information = 0;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
- return RC;
-}
+ NTSTATUS RC = STATUS_SUCCESS;
+ PVOID SystemBuffer;
+ /* PRECONDITION */
+ assert (DeviceObject != NULL);
+ assert (Irp != NULL);
+
+ DPRINT ("VfatSetInformation(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
+
+ /* INITIALIZATION */
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ FileInformationClass = Stack->Parameters.SetFile.FileInformationClass;
+ FileObject = Stack->FileObject;
+ FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
+
+ // FIXME : determine Buffer for result :
+ if (Irp->MdlAddress)
+ SystemBuffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
+ else
+ SystemBuffer = Irp->UserBuffer;
+ // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
+
+ DPRINT ("FileInformationClass %d\n", FileInformationClass);
+ DPRINT ("SystemBuffer %x\n", SystemBuffer);
+
+ switch (FileInformationClass)
+ {
+ case FilePositionInformation:
+ RC = VfatSetPositionInformation (FileObject,
+ FCB, DeviceObject, SystemBuffer);
+ break;
+ case FileDispositionInformation:
+ RC = VfatSetDispositionInformation (FileObject,
+ FCB, DeviceObject, SystemBuffer);
+ break;
+ default:
+ RC = STATUS_NOT_IMPLEMENTED;
+ }
+ Irp->IoStatus.Status = RC;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return RC;
+}
-/* $Id: iface.c,v 1.44 2000/12/29 13:45:01 ekohl Exp $
+/* $Id: iface.c,v 1.45 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* UPDATE HISTORY:
* ?? Created
* 24-10-1998 Fixed bugs in long filename support
- * Fixed a bug that prevented unsuccessful file open requests being reported
- * Now works with long filenames that span over a sector boundary
+ * Fixed a bug that prevented unsuccessful file open requests
+ * being reported
+ * Now works with long filenames that span over a sector
+ * boundary
* 28-10-1998 Reads entire FAT into memory
- * VFatReadSector modified to read in more than one sector at a time
- * 7-11-1998 Fixed bug that assumed that directory data could be fragmented
+ * VFatReadSector modified to read in more than one sector at a
+ * time
+ * 7-11-1998 Fixed bug that assumed that directory data could be
+ * fragmented
* 8-12-1998 Added FAT32 support
* Added initial writability functions
* WARNING: DO NOT ATTEMPT TO TEST WRITABILITY FUNCTIONS!!!
/* FUNCTIONS ****************************************************************/
-BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
+BOOLEAN
+VfatHasFileSystem (PDEVICE_OBJECT DeviceToMount)
/*
* FUNCTION: Tests if the device contains a filesystem that can be mounted
* by this fsd
*/
{
- BootSector* Boot;
-
- Boot = ExAllocatePool(NonPagedPool,512);
-
- VFATReadSectors(DeviceToMount, 0, 1, (UCHAR *)Boot);
-
- DPRINT("Boot->SysType %.5s\n", Boot->SysType);
- if (strncmp(Boot->SysType,"FAT12",5)==0 ||
- strncmp(Boot->SysType,"FAT16",5)==0 ||
- strncmp(((struct _BootSector32 *)(Boot))->SysType,"FAT32",5)==0)
- {
- ExFreePool(Boot);
- return(TRUE);
- }
- ExFreePool(Boot);
- return(FALSE);
+ BootSector *Boot;
+
+ Boot = ExAllocatePool (NonPagedPool, 512);
+
+ VFATReadSectors (DeviceToMount, 0, 1, (UCHAR *) Boot);
+
+ DPRINT ("Boot->SysType %.5s\n", Boot->SysType);
+ if (strncmp (Boot->SysType, "FAT12", 5) == 0 ||
+ strncmp (Boot->SysType, "FAT16", 5) == 0 ||
+ strncmp (((struct _BootSector32 *) (Boot))->SysType, "FAT32", 5) == 0)
+ {
+ ExFreePool (Boot);
+ return (TRUE);
+ }
+ ExFreePool (Boot);
+ return (FALSE);
}
-NTSTATUS FsdMountDevice(PDEVICE_EXTENSION DeviceExt,
- PDEVICE_OBJECT DeviceToMount)
+NTSTATUS
+VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
/*
* FUNCTION: Mounts the device
*/
{
- DPRINT("Mounting VFAT device...");
- DPRINT("DeviceExt %x\n",DeviceExt);
+ DPRINT ("Mounting VFAT device...");
+ DPRINT ("DeviceExt %x\n", DeviceExt);
- DeviceExt->Boot = ExAllocatePool(NonPagedPool,512);
- VFATReadSectors(DeviceToMount, 0, 1, (UCHAR *)DeviceExt->Boot);
-
- DPRINT("DeviceExt->Boot->BytesPerSector %x\n",
+ DeviceExt->Boot = ExAllocatePool (NonPagedPool, 512);
+ VFATReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
+
+ DPRINT ("DeviceExt->Boot->BytesPerSector %x\n",
DeviceExt->Boot->BytesPerSector);
-
- DeviceExt->FATStart=DeviceExt->Boot->ReservedSectors;
- DeviceExt->rootDirectorySectors=
- (DeviceExt->Boot->RootEntries*32)/DeviceExt->Boot->BytesPerSector;
- DeviceExt->rootStart=
- DeviceExt->FATStart+DeviceExt->Boot->FATCount*DeviceExt->Boot->FATSectors;
- DeviceExt->dataStart=DeviceExt->rootStart+DeviceExt->rootDirectorySectors;
- DeviceExt->FATEntriesPerSector=DeviceExt->Boot->BytesPerSector/32;
- DeviceExt->BytesPerCluster = DeviceExt->Boot->SectorsPerCluster *
- DeviceExt->Boot->BytesPerSector;
-
- if (strncmp(DeviceExt->Boot->SysType,"FAT12",5)==0)
- {
- DeviceExt->FatType = FAT12;
- }
- else if (strncmp(((struct _BootSector32 *)(DeviceExt->Boot))->SysType,"FAT32",5)==0)
- {
+
+ DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
+ DeviceExt->rootDirectorySectors =
+ (DeviceExt->Boot->RootEntries * 32) / DeviceExt->Boot->BytesPerSector;
+ DeviceExt->rootStart =
+ DeviceExt->FATStart +
+ DeviceExt->Boot->FATCount * DeviceExt->Boot->FATSectors;
+ DeviceExt->dataStart =
+ DeviceExt->rootStart + DeviceExt->rootDirectorySectors;
+ DeviceExt->FATEntriesPerSector = DeviceExt->Boot->BytesPerSector / 32;
+ DeviceExt->BytesPerCluster = DeviceExt->Boot->SectorsPerCluster *
+ DeviceExt->Boot->BytesPerSector;
+
+ if (strncmp (DeviceExt->Boot->SysType, "FAT12", 5) == 0)
+ {
+ DeviceExt->FatType = FAT12;
+ }
+ else
+ if (strncmp
+ (((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32",
+ 5) == 0)
+ {
DeviceExt->FatType = FAT32;
- DeviceExt->rootDirectorySectors=DeviceExt->Boot->SectorsPerCluster;
- DeviceExt->rootStart=
- DeviceExt->FATStart+DeviceExt->Boot->FATCount
- *((struct _BootSector32 *)( DeviceExt->Boot))->FATSectors32;
- DeviceExt->dataStart=DeviceExt->rootStart;
- }
- else
- {
- DeviceExt->FatType = FAT16;
- }
-
- // with FAT32 it's not a good idea to load always fat in memory
- // because on a 8GB partition with 2 KO clusters, the fat = 8 MO
- if(DeviceExt->FatType!=FAT32)
- {
- DeviceExt->FAT = ExAllocatePool(NonPagedPool, BLOCKSIZE*DeviceExt->Boot->FATSectors);
- VFATReadSectors(DeviceToMount, DeviceExt->FATStart, DeviceExt->Boot->FATSectors, (UCHAR *)DeviceExt->FAT);
- }
- return STATUS_SUCCESS;
+ DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster;
+ DeviceExt->rootStart =
+ DeviceExt->FATStart + DeviceExt->Boot->FATCount
+ * ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
+ DeviceExt->dataStart = DeviceExt->rootStart;
+ }
+ else
+ {
+ DeviceExt->FatType = FAT16;
+ }
+
+ // with FAT32 it's not a good idea to load always fat in memory
+ // because on a 8GB partition with 2 KO clusters, the fat = 8 MO
+ if (DeviceExt->FatType != FAT32)
+ {
+ DeviceExt->FAT =
+ ExAllocatePool (NonPagedPool,
+ BLOCKSIZE * DeviceExt->Boot->FATSectors);
+ VFATReadSectors (DeviceToMount, DeviceExt->FATStart,
+ DeviceExt->Boot->FATSectors, (UCHAR *) DeviceExt->FAT);
+ }
+ return STATUS_SUCCESS;
}
-NTSTATUS FsdMount(PDEVICE_OBJECT DeviceToMount)
+NTSTATUS
+VfatMount (PDEVICE_OBJECT DeviceToMount)
/*
* FUNCTION: Mount the filesystem
*/
{
- PDEVICE_OBJECT DeviceObject;
- PDEVICE_EXTENSION DeviceExt;
-
- IoCreateDevice(VfatDriverObject,
- sizeof(DEVICE_EXTENSION),
- NULL,
- FILE_DEVICE_FILE_SYSTEM,
- 0,
- FALSE,
- &DeviceObject);
- DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
- DeviceExt = (PVOID)DeviceObject->DeviceExtension;
- // use same vpb as device disk
- DeviceObject->Vpb=DeviceToMount->Vpb;
- FsdMountDevice(DeviceExt,DeviceToMount);
- DeviceObject->Vpb->Flags |= VPB_MOUNTED;
- DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
+ PDEVICE_OBJECT DeviceObject;
+ PDEVICE_EXTENSION DeviceExt;
+
+ IoCreateDevice (VfatDriverObject,
+ sizeof (DEVICE_EXTENSION),
+ NULL, FILE_DEVICE_FILE_SYSTEM, 0, FALSE, &DeviceObject);
+ DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
+ DeviceExt = (PVOID) DeviceObject->DeviceExtension;
+ // use same vpb as device disk
+ DeviceObject->Vpb = DeviceToMount->Vpb;
+ VfatMountDevice (DeviceExt, DeviceToMount);
+ DeviceObject->Vpb->Flags |= VPB_MOUNTED;
+ DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack (DeviceObject,
DeviceToMount);
- ExInitializeResourceLite(&DeviceExt->DirResource);
- ExInitializeResourceLite(&DeviceExt->FatResource);
-
- KeInitializeSpinLock(&DeviceExt->FcbListLock);
- InitializeListHead(&DeviceExt->FcbListHead);
-
- /* read serial number */
- if (DeviceExt->FatType == FAT12 || DeviceExt->FatType == FAT16)
- DeviceObject->Vpb->SerialNumber =
- ((struct _BootSector *)(DeviceExt->Boot))->VolumeID;
- else if (DeviceExt->FatType == FAT32)
- DeviceObject->Vpb->SerialNumber =
- ((struct _BootSector32 *)(DeviceExt->Boot))->VolumeID;
-
- /* read volume label */
- ReadVolumeLabel (DeviceExt, DeviceObject->Vpb);
-
- return(STATUS_SUCCESS);
+ ExInitializeResourceLite (&DeviceExt->DirResource);
+ ExInitializeResourceLite (&DeviceExt->FatResource);
+
+ KeInitializeSpinLock (&DeviceExt->FcbListLock);
+ InitializeListHead (&DeviceExt->FcbListHead);
+
+ /* read serial number */
+ if (DeviceExt->FatType == FAT12 || DeviceExt->FatType == FAT16)
+ DeviceObject->Vpb->SerialNumber =
+ ((struct _BootSector *) (DeviceExt->Boot))->VolumeID;
+ else if (DeviceExt->FatType == FAT32)
+ DeviceObject->Vpb->SerialNumber =
+ ((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID;
+
+ /* read volume label */
+ ReadVolumeLabel (DeviceExt, DeviceObject->Vpb);
+
+ return (STATUS_SUCCESS);
}
-NTSTATUS STDCALL FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: File system control
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
-// PVPB vpb = Stack->Parameters.Mount.Vpb;
- PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
- NTSTATUS Status;
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+// PVPB vpb = Stack->Parameters.Mount.Vpb;
+ PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
+ NTSTATUS Status;
// DPRINT("VFAT FSC\n");
- DbgPrint("VFAT FSC\n");
-
- /* FIXME: should make sure that this is actually a mount request! */
-
- if (FsdHasFileSystem(DeviceToMount))
- {
- DPRINT("VFAT: Recognized volume\n");
- Status = FsdMount(DeviceToMount);
- }
- else
- {
- DPRINT("VFAT: Unrecognized Volume\n");
- Status = STATUS_UNRECOGNIZED_VOLUME;
- }
-
- Irp->IoStatus.Status = Status;
- Irp->IoStatus.Information = 0;
-
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return(Status);
+ DbgPrint ("VFAT FSC\n");
+
+ /* FIXME: should make sure that this is actually a mount request! */
+
+ if (VfatHasFileSystem (DeviceToMount))
+ {
+ DPRINT ("VFAT: Recognized volume\n");
+ Status = VfatMount (DeviceToMount);
+ }
+ else
+ {
+ DPRINT ("VFAT: Unrecognized Volume\n");
+ Status = STATUS_UNRECOGNIZED_VOLUME;
+ }
+
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = 0;
+
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return (Status);
}
-NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT _DriverObject,
- PUNICODE_STRING RegistryPath)
+NTSTATUS STDCALL
+DriverEntry (PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
/*
* FUNCTION: Called by the system to initalize the driver
* ARGUMENTS:
* RETURNS: Success or failure
*/
{
- PDEVICE_OBJECT DeviceObject;
- NTSTATUS ret;
- UNICODE_STRING DeviceName;
-
- DbgPrint("VFAT 0.0.6\n");
-
- VfatDriverObject = _DriverObject;
-
- RtlInitUnicodeString(&DeviceName, L"\\Device\\Vfat");
- ret = IoCreateDevice(VfatDriverObject,0,&DeviceName,
- FILE_DEVICE_FILE_SYSTEM,0,FALSE,&DeviceObject);
- if (ret!=STATUS_SUCCESS)
- {
- return(ret);
- }
-
- DeviceObject->Flags = DO_DIRECT_IO;
- VfatDriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose;
- VfatDriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate;
- VfatDriverObject->MajorFunction[IRP_MJ_READ] = FsdRead;
- VfatDriverObject->MajorFunction[IRP_MJ_WRITE] = FsdWrite;
- VfatDriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
- FsdFileSystemControl;
- VfatDriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
- FsdQueryInformation;
- VfatDriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
- VfatSetInformation;
- VfatDriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
- FsdDirectoryControl;
- VfatDriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
- VfatQueryVolumeInformation;
- VfatDriverObject->MajorFunction[IRP_MJ_SHUTDOWN] =
- VfatShutdown;
-
- VfatDriverObject->DriverUnload = NULL;
-
- IoRegisterFileSystem(DeviceObject);
-
- return(STATUS_SUCCESS);
+ PDEVICE_OBJECT DeviceObject;
+ NTSTATUS ret;
+ UNICODE_STRING DeviceName;
+
+ DbgPrint ("VFAT 0.0.6\n");
+
+ VfatDriverObject = _DriverObject;
+
+ RtlInitUnicodeString (&DeviceName, L"\\Device\\Vfat");
+ ret = IoCreateDevice (VfatDriverObject, 0, &DeviceName,
+ FILE_DEVICE_FILE_SYSTEM, 0, FALSE, &DeviceObject);
+ if (ret != STATUS_SUCCESS)
+ {
+ return (ret);
+ }
+
+ DeviceObject->Flags = DO_DIRECT_IO;
+ VfatDriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatClose;
+ VfatDriverObject->MajorFunction[IRP_MJ_CREATE] = VfatCreate;
+ VfatDriverObject->MajorFunction[IRP_MJ_READ] = VfatRead;
+ VfatDriverObject->MajorFunction[IRP_MJ_WRITE] = VfatWrite;
+ VfatDriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
+ VfatFileSystemControl;
+ VfatDriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
+ VfatQueryInformation;
+ VfatDriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
+ VfatSetInformation;
+ VfatDriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
+ VfatDirectoryControl;
+ VfatDriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
+ VfatQueryVolumeInformation;
+ VfatDriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
+
+ VfatDriverObject->DriverUnload = NULL;
+
+ IoRegisterFileSystem (DeviceObject);
+
+ return (STATUS_SUCCESS);
}
-
-/* $Id: rw.c,v 1.11 2000/12/05 17:12:16 jean Exp $
+/* $Id: rw.c,v 1.12 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <ddk/ntddk.h>
#include <wchar.h>
-#include <ddk/cctypes.h>
#include <ntos/minmax.h>
#define NDEBUG
/* FUNCTIONS ****************************************************************/
-NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
- PVOID Buffer, ULONG Length, ULONG ReadOffset,
- PULONG LengthRead)
+NTSTATUS
+VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+ PVOID Buffer, ULONG Length, ULONG ReadOffset, PULONG LengthRead)
/*
* FUNCTION: Reads data from a file
*/
{
- ULONG CurrentCluster;
- ULONG FileOffset;
- ULONG FirstCluster;
- PVFATFCB Fcb;
- PVOID Temp;
- ULONG TempLength;
-
- /* PRECONDITION */
- assert(DeviceExt != NULL);
- assert(DeviceExt->BytesPerCluster != 0);
- assert(FileObject != NULL);
- assert(FileObject->FsContext != NULL);
-
- DPRINT("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
- "Length %d, ReadOffset %d)\n",DeviceExt,FileObject,Buffer,
- Length,ReadOffset);
-
- Fcb = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
- if (DeviceExt->FatType == FAT32)
- CurrentCluster = Fcb->entry.FirstCluster
- +Fcb->entry.FirstClusterHigh*65536;
- else
- CurrentCluster = Fcb->entry.FirstCluster;
- FirstCluster=CurrentCluster;
- DPRINT("DeviceExt->BytesPerCluster %x\n",DeviceExt->BytesPerCluster);
-
- if ( !(Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
- {
- if (ReadOffset >= Fcb->entry.FileSize)
- {
- return(STATUS_END_OF_FILE);
- }
- if ((ReadOffset + Length) > Fcb->entry.FileSize)
- {
- Length = Fcb->entry.FileSize - ReadOffset;
- }
- }
-CHECKPOINT;
- *LengthRead = 0;
- /* FIXME: optimize by remembering the last cluster read and using if possible */
- Temp = ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster);
- if(!Temp) return STATUS_UNSUCCESSFUL;
- if (FirstCluster==1)
- { //root of FAT16 or FAT12
- CurrentCluster=DeviceExt->rootStart+ReadOffset
- /(DeviceExt->BytesPerCluster)*DeviceExt->Boot->SectorsPerCluster;
- }
- else
- for (FileOffset=0; FileOffset < ReadOffset / DeviceExt->BytesPerCluster
- ; FileOffset++)
- {
- CurrentCluster = GetNextCluster(DeviceExt,CurrentCluster);
- }
- CHECKPOINT;
- if ((ReadOffset % DeviceExt->BytesPerCluster)!=0)
- {
- if (FirstCluster == 1)
- {
- VFATReadSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
- CurrentCluster = GetNextCluster(DeviceExt, CurrentCluster);
- }
- TempLength = min(Length,DeviceExt->BytesPerCluster -
- (ReadOffset % DeviceExt->BytesPerCluster));
-
- memcpy(Buffer, Temp + ReadOffset % DeviceExt->BytesPerCluster,
- TempLength);
-
- (*LengthRead) = (*LengthRead) + TempLength;
- Length = Length - TempLength;
- Buffer = Buffer + TempLength;
- }
- CHECKPOINT;
- while (Length >= DeviceExt->BytesPerCluster)
- {
- if (FirstCluster == 1)
- {
- VFATReadSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Buffer);
- CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- VFATLoadCluster(DeviceExt,Buffer,CurrentCluster);
- CurrentCluster = GetNextCluster(DeviceExt, CurrentCluster);
- }
- if (CurrentCluster == 0xffffffff)
- {
- ExFreePool(Temp);
- return(STATUS_SUCCESS);
- }
-
- (*LengthRead) = (*LengthRead) + DeviceExt->BytesPerCluster;
- Buffer = Buffer + DeviceExt->BytesPerCluster;
- Length = Length - DeviceExt->BytesPerCluster;
- }
- CHECKPOINT;
- if (Length > 0)
- {
- (*LengthRead) = (*LengthRead) + Length;
- if (FirstCluster == 1)
- {
- VFATReadSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
- CurrentCluster = GetNextCluster(DeviceExt, CurrentCluster);
- }
- memcpy(Buffer, Temp, Length);
- }
- ExFreePool(Temp);
- return(STATUS_SUCCESS);
+ ULONG CurrentCluster;
+ ULONG FileOffset;
+ ULONG FirstCluster;
+ PVFATFCB Fcb;
+ PVOID Temp;
+ ULONG TempLength;
+
+ /* PRECONDITION */
+ assert (DeviceExt != NULL);
+ assert (DeviceExt->BytesPerCluster != 0);
+ assert (FileObject != NULL);
+ assert (FileObject->FsContext != NULL);
+
+ DPRINT ("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
+ "Length %d, ReadOffset %d)\n", DeviceExt, FileObject, Buffer,
+ Length, ReadOffset);
+
+ Fcb = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
+ if (DeviceExt->FatType == FAT32)
+ CurrentCluster = Fcb->entry.FirstCluster
+ + Fcb->entry.FirstClusterHigh * 65536;
+ else
+ CurrentCluster = Fcb->entry.FirstCluster;
+ FirstCluster = CurrentCluster;
+ DPRINT ("DeviceExt->BytesPerCluster %x\n", DeviceExt->BytesPerCluster);
+
+ if (!(Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ if (ReadOffset >= Fcb->entry.FileSize)
+ {
+ return (STATUS_END_OF_FILE);
+ }
+ if ((ReadOffset + Length) > Fcb->entry.FileSize)
+ {
+ Length = Fcb->entry.FileSize - ReadOffset;
+ }
+ }
+ CHECKPOINT;
+ *LengthRead = 0;
+ /* FIXME: optimize by remembering the last cluster read and using if possible */
+ Temp = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
+ if (!Temp)
+ return STATUS_UNSUCCESSFUL;
+ if (FirstCluster == 1)
+ { //root of FAT16 or FAT12
+ CurrentCluster = DeviceExt->rootStart + ReadOffset
+ / (DeviceExt->BytesPerCluster) * DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ for (FileOffset = 0; FileOffset < ReadOffset / DeviceExt->BytesPerCluster;
+ FileOffset++)
+ {
+ CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ CHECKPOINT;
+ if ((ReadOffset % DeviceExt->BytesPerCluster) != 0)
+ {
+ if (FirstCluster == 1)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
+ CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ TempLength = min (Length, DeviceExt->BytesPerCluster -
+ (ReadOffset % DeviceExt->BytesPerCluster));
+
+ memcpy (Buffer, Temp + ReadOffset % DeviceExt->BytesPerCluster,
+ TempLength);
+
+ (*LengthRead) = (*LengthRead) + TempLength;
+ Length = Length - TempLength;
+ Buffer = Buffer + TempLength;
+ }
+ CHECKPOINT;
+ while (Length >= DeviceExt->BytesPerCluster)
+ {
+ if (FirstCluster == 1)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Buffer);
+ CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ VFATLoadCluster (DeviceExt, Buffer, CurrentCluster);
+ CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ if (CurrentCluster == 0xffffffff)
+ {
+ ExFreePool (Temp);
+ return (STATUS_SUCCESS);
+ }
+
+ (*LengthRead) = (*LengthRead) + DeviceExt->BytesPerCluster;
+ Buffer = Buffer + DeviceExt->BytesPerCluster;
+ Length = Length - DeviceExt->BytesPerCluster;
+ }
+ CHECKPOINT;
+ if (Length > 0)
+ {
+ (*LengthRead) = (*LengthRead) + Length;
+ if (FirstCluster == 1)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
+ CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
+ }
+ memcpy (Buffer, Temp, Length);
+ }
+ ExFreePool (Temp);
+ return (STATUS_SUCCESS);
}
-NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
- PVOID Buffer, ULONG Length, ULONG WriteOffset)
+NTSTATUS
+VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+ PVOID Buffer, ULONG Length, ULONG WriteOffset)
/*
* FUNCTION: Writes data to file
*/
{
- ULONG CurrentCluster;
- ULONG FileOffset;
- ULONG FirstCluster;
- PVFATFCB Fcb;
- PVFATCCB pCcb;
- PVOID Temp;
- ULONG TempLength,Length2=Length;
- LARGE_INTEGER SystemTime, LocalTime;
-
- DPRINT1("FsdWriteFile(FileObject %x, Buffer %x, Length %x, "
+ ULONG CurrentCluster;
+ ULONG FileOffset;
+ ULONG FirstCluster;
+ PVFATFCB Fcb;
+ PVFATCCB pCcb;
+ PVOID Temp;
+ ULONG TempLength, Length2 = Length;
+ LARGE_INTEGER SystemTime, LocalTime;
+
+ DPRINT1 ("FsdWriteFile(FileObject %x, Buffer %x, Length %x, "
"WriteOffset %x\n", FileObject, Buffer, Length, WriteOffset);
-
- /* Locate the first cluster of the file */
- assert(FileObject);
- pCcb=(PVFATCCB)(FileObject->FsContext2);
- assert(pCcb);
- Fcb = pCcb->pFcb;
- assert(Fcb);
- if (DeviceExt->FatType == FAT32)
- {
- CurrentCluster =
- Fcb->entry.FirstCluster+Fcb->entry.FirstClusterHigh*65536;
- }
- else
- {
- CurrentCluster = Fcb->entry.FirstCluster;
- }
- FirstCluster=CurrentCluster;
-
- /* Allocate a buffer to hold 1 cluster of data */
- Temp = ExAllocatePool(NonPagedPool, DeviceExt->BytesPerCluster);
- assert(Temp);
-
- /* Find the cluster according to the offset in the file */
- if (CurrentCluster==1)
- {
- CurrentCluster=DeviceExt->rootStart+WriteOffset
- / DeviceExt->BytesPerCluster*DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- if (CurrentCluster==0)
- {
- /*
- * File of size zero
- */
- CurrentCluster=GetNextWriteCluster(DeviceExt,0);
- if (DeviceExt->FatType == FAT32)
- {
- Fcb->entry.FirstClusterHigh = CurrentCluster>>16;
- Fcb->entry.FirstCluster = CurrentCluster;
- }
- else
- Fcb->entry.FirstCluster=CurrentCluster;
- }
- else
- {
- for (FileOffset=0;
- FileOffset < WriteOffset / DeviceExt->BytesPerCluster;
- FileOffset++)
- {
- CurrentCluster = GetNextWriteCluster(DeviceExt,CurrentCluster);
- }
- }
- CHECKPOINT;
- }
-
- /*
- * If the offset in the cluster doesn't fall on the cluster boundary
- * then we have to write only from the specified offset
- */
-
- if ((WriteOffset % DeviceExt->BytesPerCluster)!=0)
- {
- CHECKPOINT;
- TempLength = min(Length,DeviceExt->BytesPerCluster -
- (WriteOffset % DeviceExt->BytesPerCluster));
- /* Read in the existing cluster data */
- if (FirstCluster==1)
- {
- VFATReadSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- }
- else
- {
- VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
- }
-
- /* Overwrite the last parts of the data as necessary */
- memcpy(Temp + (WriteOffset % DeviceExt->BytesPerCluster),
- Buffer,
- TempLength);
-
- /* Write the cluster back */
- Length2 -= TempLength;
- if (FirstCluster==1)
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- VFATWriteCluster(DeviceExt,Temp,CurrentCluster);
- if (Length2 >0)
- CurrentCluster = GetNextWriteCluster(DeviceExt, CurrentCluster);
- }
- Buffer = Buffer + TempLength;
- }
- CHECKPOINT;
-
- /* Write the buffer in chunks of 1 cluster */
-
- while (Length2 >= DeviceExt->BytesPerCluster)
- {
- CHECKPOINT;
- if (CurrentCluster == 0)
- {
- ExFreePool(Temp);
- return(STATUS_UNSUCCESSFUL);
- }
- Length2 -= DeviceExt->BytesPerCluster;
- if (FirstCluster==1)
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Buffer);
- CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
- }
- else
- {
- VFATWriteCluster(DeviceExt,Buffer,CurrentCluster);
- if (Length2 >0)
- CurrentCluster = GetNextWriteCluster(DeviceExt, CurrentCluster);
- }
- Buffer = Buffer + DeviceExt->BytesPerCluster;
- }
- CHECKPOINT;
-
- /* Write the remainder */
-
- if (Length2 > 0)
- {
- CHECKPOINT;
- if (CurrentCluster == 0)
- {
- ExFreePool(Temp);
- return(STATUS_UNSUCCESSFUL);
- }
- CHECKPOINT;
- /* Read in the existing cluster data */
- if (FirstCluster==1)
- {
- VFATReadSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- }
- else
- {
- VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
- CHECKPOINT;
- memcpy(Temp, Buffer, Length2);
- CHECKPOINT;
- if (FirstCluster==1)
- {
- VFATWriteSectors(DeviceExt->StorageDevice,
- CurrentCluster,
- DeviceExt->Boot->SectorsPerCluster,
- Temp);
- }
- else
- {
- VFATWriteCluster(DeviceExt,Temp,CurrentCluster);
- }
- }
- CHECKPOINT;
- }
-
-
- /* set dates and times */
- KeQuerySystemTime (&SystemTime);
- ExSystemTimeToLocalTime (&SystemTime,
- &LocalTime);
- FsdFileTimeToDosDateTime ((TIME*)&LocalTime,
- &Fcb->entry.UpdateDate,
- &Fcb->entry.UpdateTime);
- Fcb->entry.AccessDate = Fcb->entry.UpdateDate;
-
- if (Fcb->entry.FileSize < WriteOffset+Length
- && ! (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
- {
- Fcb->entry.FileSize = WriteOffset+Length;
- /*
- * update entry in directory
- */
- updEntry(DeviceExt,FileObject);
- }
-
- ExFreePool(Temp);
- return (STATUS_SUCCESS);
+
+ /* Locate the first cluster of the file */
+ assert (FileObject);
+ pCcb = (PVFATCCB) (FileObject->FsContext2);
+ assert (pCcb);
+ Fcb = pCcb->pFcb;
+ assert (Fcb);
+ if (DeviceExt->FatType == FAT32)
+ {
+ CurrentCluster =
+ Fcb->entry.FirstCluster + Fcb->entry.FirstClusterHigh * 65536;
+ }
+ else
+ {
+ CurrentCluster = Fcb->entry.FirstCluster;
+ }
+ FirstCluster = CurrentCluster;
+
+ /* Allocate a buffer to hold 1 cluster of data */
+ Temp = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
+ assert (Temp);
+
+ /* Find the cluster according to the offset in the file */
+ if (CurrentCluster == 1)
+ {
+ CurrentCluster = DeviceExt->rootStart + WriteOffset
+ / DeviceExt->BytesPerCluster * DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ if (CurrentCluster == 0)
+ {
+ /*
+ * File of size zero
+ */
+ CurrentCluster = GetNextWriteCluster (DeviceExt, 0);
+ if (DeviceExt->FatType == FAT32)
+ {
+ Fcb->entry.FirstClusterHigh = CurrentCluster >> 16;
+ Fcb->entry.FirstCluster = CurrentCluster;
+ }
+ else
+ Fcb->entry.FirstCluster = CurrentCluster;
+ }
+ else
+ {
+ for (FileOffset = 0;
+ FileOffset < WriteOffset / DeviceExt->BytesPerCluster;
+ FileOffset++)
+ {
+ CurrentCluster =
+ GetNextWriteCluster (DeviceExt, CurrentCluster);
+ }
+ }
+ CHECKPOINT;
+ }
+
+ /*
+ * If the offset in the cluster doesn't fall on the cluster boundary
+ * then we have to write only from the specified offset
+ */
+
+ if ((WriteOffset % DeviceExt->BytesPerCluster) != 0)
+ {
+ CHECKPOINT;
+ TempLength = min (Length, DeviceExt->BytesPerCluster -
+ (WriteOffset % DeviceExt->BytesPerCluster));
+ /* Read in the existing cluster data */
+ if (FirstCluster == 1)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ }
+ else
+ {
+ VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
+ }
+
+ /* Overwrite the last parts of the data as necessary */
+ memcpy (Temp + (WriteOffset % DeviceExt->BytesPerCluster),
+ Buffer, TempLength);
+
+ /* Write the cluster back */
+ Length2 -= TempLength;
+ if (FirstCluster == 1)
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ VFATWriteCluster (DeviceExt, Temp, CurrentCluster);
+ if (Length2 > 0)
+ CurrentCluster = GetNextWriteCluster (DeviceExt, CurrentCluster);
+ }
+ Buffer = Buffer + TempLength;
+ }
+ CHECKPOINT;
+
+ /* Write the buffer in chunks of 1 cluster */
+
+ while (Length2 >= DeviceExt->BytesPerCluster)
+ {
+ CHECKPOINT;
+ if (CurrentCluster == 0)
+ {
+ ExFreePool (Temp);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ Length2 -= DeviceExt->BytesPerCluster;
+ if (FirstCluster == 1)
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Buffer);
+ CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ VFATWriteCluster (DeviceExt, Buffer, CurrentCluster);
+ if (Length2 > 0)
+ CurrentCluster = GetNextWriteCluster (DeviceExt, CurrentCluster);
+ }
+ Buffer = Buffer + DeviceExt->BytesPerCluster;
+ }
+ CHECKPOINT;
+
+ /* Write the remainder */
+
+ if (Length2 > 0)
+ {
+ CHECKPOINT;
+ if (CurrentCluster == 0)
+ {
+ ExFreePool (Temp);
+ return (STATUS_UNSUCCESSFUL);
+ }
+ CHECKPOINT;
+ /* Read in the existing cluster data */
+ if (FirstCluster == 1)
+ {
+ VFATReadSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ }
+ else
+ {
+ VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
+ CHECKPOINT;
+ memcpy (Temp, Buffer, Length2);
+ CHECKPOINT;
+ if (FirstCluster == 1)
+ {
+ VFATWriteSectors (DeviceExt->StorageDevice,
+ CurrentCluster,
+ DeviceExt->Boot->SectorsPerCluster, Temp);
+ }
+ else
+ {
+ VFATWriteCluster (DeviceExt, Temp, CurrentCluster);
+ }
+ }
+ CHECKPOINT;
+ }
+
+
+ /* set dates and times */
+ KeQuerySystemTime (&SystemTime);
+ ExSystemTimeToLocalTime (&SystemTime, &LocalTime);
+ FsdFileTimeToDosDateTime ((TIME *) & LocalTime,
+ &Fcb->entry.UpdateDate, &Fcb->entry.UpdateTime);
+ Fcb->entry.AccessDate = Fcb->entry.UpdateDate;
+
+ if (Fcb->entry.FileSize < WriteOffset + Length
+ && !(Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ Fcb->entry.FileSize = WriteOffset + Length;
+ /*
+ * update entry in directory
+ */
+ updEntry (DeviceExt, FileObject);
+ }
+
+ ExFreePool (Temp);
+ return (STATUS_SUCCESS);
}
-NTSTATUS STDCALL FsdWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Write to a file
*/
{
- ULONG Length;
- PVOID Buffer;
- ULONG Offset;
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
- PFILE_OBJECT FileObject = Stack->FileObject;
- PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
- NTSTATUS Status;
-
- DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
-
- Length = Stack->Parameters.Write.Length;
- Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
- Offset = Stack->Parameters.Write.ByteOffset.u.LowPart;
-
- Status = FsdWriteFile(DeviceExt,FileObject,Buffer,Length,Offset);
-
- Irp->IoStatus.Status = Status;
- Irp->IoStatus.Information = Length;
- IoCompleteRequest(Irp,IO_NO_INCREMENT);
-
- return(Status);
+ ULONG Length;
+ PVOID Buffer;
+ ULONG Offset;
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+ PFILE_OBJECT FileObject = Stack->FileObject;
+ PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
+ NTSTATUS Status;
+
+ DPRINT ("VfatWrite(DeviceObject %x Irp %x)\n", DeviceObject, Irp);
+
+ Length = Stack->Parameters.Write.Length;
+ Buffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
+ Offset = Stack->Parameters.Write.ByteOffset.u.LowPart;
+
+ Status = VfatWriteFile (DeviceExt, FileObject, Buffer, Length, Offset);
+
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = Length;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+
+ return (Status);
}
-NTSTATUS STDCALL FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatRead (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Read from a file
*/
{
- ULONG Length;
- PVOID Buffer;
- ULONG Offset;
- PIO_STACK_LOCATION Stack;
- PFILE_OBJECT FileObject;
- PDEVICE_EXTENSION DeviceExt;
- NTSTATUS Status;
- ULONG LengthRead;
- PVFATFCB Fcb;
-
- DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
-
- /* Precondition / Initialization */
- assert(Irp != NULL);
- Stack = IoGetCurrentIrpStackLocation(Irp);
- assert(Stack != NULL);
- FileObject = Stack->FileObject;
- assert(FileObject != NULL);
- DeviceExt = DeviceObject->DeviceExtension;
- assert(DeviceExt != NULL);
-
- Length = Stack->Parameters.Read.Length;
- Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
- Offset = Stack->Parameters.Read.ByteOffset.u.LowPart;
-
- /* fail if file is a directory */
- Fcb = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
- if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)
- {
- Status = STATUS_FILE_IS_A_DIRECTORY;
- }
- else
- {
- Status = FsdReadFile(DeviceExt,
- FileObject,
- Buffer,
- Length,
- Offset,
- &LengthRead);
- }
+ ULONG Length;
+ PVOID Buffer;
+ ULONG Offset;
+ PIO_STACK_LOCATION Stack;
+ PFILE_OBJECT FileObject;
+ PDEVICE_EXTENSION DeviceExt;
+ NTSTATUS Status;
+ ULONG LengthRead;
+ PVFATFCB Fcb;
- Irp->IoStatus.Status = Status;
- Irp->IoStatus.Information = LengthRead;
- IoCompleteRequest(Irp,IO_NO_INCREMENT);
+ DPRINT ("VfatRead(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
- return(Status);
-}
+ /* Precondition / Initialization */
+ assert (Irp != NULL);
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ assert (Stack != NULL);
+ FileObject = Stack->FileObject;
+ assert (FileObject != NULL);
+ DeviceExt = DeviceObject->DeviceExtension;
+ assert (DeviceExt != NULL);
+
+ Length = Stack->Parameters.Read.Length;
+ Buffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
+ Offset = Stack->Parameters.Read.ByteOffset.u.LowPart;
+
+ /* fail if file is a directory */
+ Fcb = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
+ if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ Status = STATUS_FILE_IS_A_DIRECTORY;
+ }
+ else
+ {
+ Status = VfatReadFile (DeviceExt,
+ FileObject, Buffer, Length, Offset, &LengthRead);
+ }
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = LengthRead;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ return (Status);
+}
-/* $Id: string.c,v 1.3 2000/06/29 23:35:51 dwelch Exp $
+/* $Id: string.c,v 1.4 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <ddk/ntddk.h>
#include <wchar.h>
-#include <ddk/cctypes.h>
#define NDEBUG
#include <debug.h>
-/* $Id: vfat.h,v 1.18 2000/12/29 13:45:01 ekohl Exp $ */
+/* $Id: vfat.h,v 1.19 2000/12/29 23:17:12 dwelch Exp $ */
+
+#include <ddk/ntifs.h>
struct _BootSector {
unsigned char magic0, res0, magic1;
int FATEntriesPerSector, FATUnit;
ULONG BytesPerCluster;
ULONG FatType;
- unsigned char* FAT;
-
+ unsigned char* FAT;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
-typedef struct _FSRTL_COMMON_FCB_HEADER{
- char IsFastIoPossible;//is char the realtype ?
- ERESOURCE Resource;
- ERESOURCE PagingIoResource;
- ULONG Flags;// is long the real type ?
- LARGE_INTEGER AllocationSize;
- LARGE_INTEGER FileSize;
- LARGE_INTEGER ValidDataLength;
- // other fields ??
-} FSRTL_COMMON_FCB_HEADER;
-
-typedef struct _SFsdNTRequiredFCB {
- FSRTL_COMMON_FCB_HEADER CommonFCBHeader;
- SECTION_OBJECT_POINTERS SectionObject;
- ERESOURCE MainResource;
- ERESOURCE PagingIoResource;
-} SFsdNTRequiredFCB, *PtrSFsdNTRequiredFCB;
-
typedef struct _VFATFCB
{
- SFsdNTRequiredFCB NTRequiredFCB;
- FATDirEntry entry;
- WCHAR *ObjectName; // point on filename (250 chars max) in PathName
- WCHAR PathName[MAX_PATH];// path+filename 260 max
- long RefCount;
- PDEVICE_EXTENSION pDevExt;
- LIST_ENTRY FcbListEntry;
- struct _VFATFCB * parentFcb;
+ REACTOS_COMMON_FCB_HEADER RFCB;
+ FATDirEntry entry;
+ /* point on filename (250 chars max) in PathName */
+ WCHAR *ObjectName;
+ /* path+filename 260 max */
+ WCHAR PathName[MAX_PATH];
+ LONG RefCount;
+ PDEVICE_EXTENSION pDevExt;
+ LIST_ENTRY FcbListEntry;
+ struct _VFATFCB* parentFcb;
} VFATFCB, *PVFATFCB;
typedef struct _VFATCCB
LIST_ENTRY NextCCB;
PFILE_OBJECT PtrFileObject;
LARGE_INTEGER CurrentByteOffset;
- ULONG StartSector; // for DirectoryControl
- ULONG StartEntry; //for DirectoryControl
-// PSTRING DirectorySearchPattern;// for DirectoryControl ?
+ /* for DirectoryControl */
+ ULONG StartSector;
+ /* for DirectoryControl */
+ ULONG StartEntry;
+ // PSTRING DirectorySearchPattern;// for DirectoryControl ?
} VFATCCB, *PVFATCCB;
WORD Year:5;
} DOSDATE, *PDOSDATE;
-// functions called by i/o manager :
-NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT _DriverObject,PUNICODE_STRING RegistryPath);
-NTSTATUS STDCALL FsdDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-NTSTATUS STDCALL FsdQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
-
-
-// internal functions in blockdev.c
-BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
- IN ULONG DiskSector,
- IN ULONG SectorCount,
- IN UCHAR* Buffer);
-
-BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
- IN ULONG DiskSector,
- IN ULONG SectorCount,
- IN UCHAR* Buffer);
-
-//internal functions in dir.c :
+/* functions called by i/o manager : */
+NTSTATUS STDCALL
+DriverEntry(PDRIVER_OBJECT _DriverObject,PUNICODE_STRING RegistryPath);
+NTSTATUS STDCALL
+VfatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+
+
+/* internal functions in blockdev.c */
+BOOLEAN
+VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
+ IN ULONG DiskSector,
+ IN ULONG SectorCount,
+ IN UCHAR* Buffer);
+
+BOOLEAN
+VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
+ IN ULONG DiskSector,
+ IN ULONG SectorCount,
+ IN UCHAR* Buffer);
+
+/* internal functions in dir.c : */
BOOL FsdDosDateTimeToFileTime(WORD wDosDate,WORD wDosTime, TIME *FileTime);
BOOL FsdFileTimeToDosDateTime(TIME *FileTime,WORD *pwDosDate,WORD *pwDosTime);
-//internal functions in iface.c :
-NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
- PVFATFCB Parent, PWSTR FileToFind,ULONG *StartSector,ULONG *Entry);
-NTSTATUS FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject);
-NTSTATUS FsdGetStandardInformation(PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
+/* internal functions in iface.c : */
+NTSTATUS
+FindFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
+ PVFATFCB Parent, PWSTR FileToFind,ULONG *StartSector,ULONG *Entry);
+NTSTATUS
+VfatCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject);
+NTSTATUS
+VfatGetStandardInformation(PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
PFILE_STANDARD_INFORMATION StandardInfo);
-NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
- PWSTR FileName);
-NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
- PVOID Buffer, ULONG Length, ULONG ReadOffset,
+NTSTATUS
+VfatOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+ PWSTR FileName);
+NTSTATUS
+VfatReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+ PVOID Buffer, ULONG Length, ULONG ReadOffset,
PULONG LengthRead);
-NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
+NTSTATUS
+VfatWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
PVOID Buffer, ULONG Length, ULONG WriteOffset);
-ULONG GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
-BOOLEAN IsDeletedEntry(PVOID Block, ULONG Offset);
-BOOLEAN IsLastEntry(PVOID Block, ULONG Offset);
-wchar_t * vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
-void VFATWriteCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
-
-//internal functions in dirwr.c
-NTSTATUS addEntry(PDEVICE_EXTENSION DeviceExt
- ,PFILE_OBJECT pFileObject,ULONG RequestedOptions,UCHAR ReqAttr);
-NTSTATUS updEntry(PDEVICE_EXTENSION DeviceExt,PFILE_OBJECT pFileObject);
-
-
-
+ULONG
+GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
+BOOLEAN
+IsDeletedEntry(PVOID Block, ULONG Offset);
+BOOLEAN
+IsLastEntry(PVOID Block, ULONG Offset);
+wchar_t*
+vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
+VOID
+VFATWriteCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
+
+/* internal functions in dirwr.c */
+NTSTATUS
+addEntry(PDEVICE_EXTENSION DeviceExt,
+ PFILE_OBJECT pFileObject,ULONG RequestedOptions,UCHAR ReqAttr);
+NTSTATUS
+updEntry(PDEVICE_EXTENSION DeviceExt,PFILE_OBJECT pFileObject);
/*
* String functions
*/
-void RtlAnsiToUnicode(PWSTR Dest, PCH Source, ULONG Length);
-void RtlCatAnsiToUnicode(PWSTR Dest, PCH Source, ULONG Length);
-void vfat_initstr(wchar_t *wstr, ULONG wsize);
-wchar_t * vfat_wcsncat(wchar_t * dest, const wchar_t * src,size_t wstart, size_t wcount);
-wchar_t * vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
-wchar_t * vfat_movstr(wchar_t *src, ULONG dpos, ULONG spos, ULONG len);
-BOOLEAN wstrcmpi(PWSTR s1, PWSTR s2);
-BOOLEAN wstrcmpjoki(PWSTR s1, PWSTR s2);
+VOID
+RtlAnsiToUnicode(PWSTR Dest, PCH Source, ULONG Length);
+VOID
+RtlCatAnsiToUnicode(PWSTR Dest, PCH Source, ULONG Length);
+VOID
+vfat_initstr(wchar_t *wstr, ULONG wsize);
+wchar_t*
+vfat_wcsncat(wchar_t * dest, const wchar_t * src,size_t wstart, size_t wcount);
+wchar_t*
+vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
+wchar_t*
+vfat_movstr(wchar_t *src, ULONG dpos, ULONG spos, ULONG len);
+BOOLEAN
+wstrcmpi(PWSTR s1, PWSTR s2);
+BOOLEAN
+wstrcmpjoki(PWSTR s1, PWSTR s2);
/*
* functions from fat.c
*/
-ULONG ClusterToSector(PDEVICE_EXTENSION DeviceExt, ULONG Cluster);
-ULONG GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
-VOID VFATLoadCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
-ULONG FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
-ULONG FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
-ULONG FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
+ULONG
+ClusterToSector(PDEVICE_EXTENSION DeviceExt, ULONG Cluster);
+ULONG
+GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
+VOID
+VFATLoadCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
+ULONG
+FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
+ULONG
+FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
+ULONG
+FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
/*
* functions from volume.c
*/
-NTSTATUS STDCALL VfatQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
/*
* functions from finfo.c
*/
-NTSTATUS STDCALL VfatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+NTSTATUS STDCALL
+VfatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
/*
* From create.c
*/
-NTSTATUS ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb);
+NTSTATUS
+ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb);
/*
* functions from shutdown.c
*/
NTSTATUS STDCALL VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+
-/* $Id: volume.c,v 1.4 2000/09/12 10:12:13 jean Exp $
+/* $Id: volume.c,v 1.5 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <ddk/ntddk.h>
#include <wchar.h>
-#include <ddk/cctypes.h>
#define NDEBUG
#include <debug.h>
/* FUNCTIONS ****************************************************************/
-NTSTATUS FsdGetFsVolumeInformation(PFILE_OBJECT FileObject,
- PVFATFCB FCB,
- PDEVICE_OBJECT DeviceObject,
- PFILE_FS_VOLUME_INFORMATION FsVolumeInfo)
+NTSTATUS
+FsdGetFsVolumeInformation (PFILE_OBJECT FileObject,
+ PVFATFCB FCB,
+ PDEVICE_OBJECT DeviceObject,
+ PFILE_FS_VOLUME_INFORMATION FsVolumeInfo)
{
- DPRINT("FsdGetFsVolumeInformation()\n");
- DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo);
+ DPRINT ("FsdGetFsVolumeInformation()\n");
+ DPRINT ("FsVolumeInfo = %p\n", FsVolumeInfo);
- if (!FsVolumeInfo)
- return(STATUS_SUCCESS);
+ if (!FsVolumeInfo)
+ return (STATUS_SUCCESS);
- /* valid entries */
- FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
- FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
- wcscpy (FsVolumeInfo->VolumeLabel, DeviceObject->Vpb->VolumeLabel);
+ /* valid entries */
+ FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
+ FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
+ wcscpy (FsVolumeInfo->VolumeLabel, DeviceObject->Vpb->VolumeLabel);
- /* dummy entries */
- FsVolumeInfo->VolumeCreationTime.QuadPart = 0;
- FsVolumeInfo->SupportsObjects = FALSE;
+ /* dummy entries */
+ FsVolumeInfo->VolumeCreationTime.QuadPart = 0;
+ FsVolumeInfo->SupportsObjects = FALSE;
- DPRINT("Finished FsdGetFsVolumeInformation()\n");
+ DPRINT ("Finished FsdGetFsVolumeInformation()\n");
- return(STATUS_SUCCESS);
+ return (STATUS_SUCCESS);
}
-NTSTATUS FsdGetFsAttributeInformation(PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo)
+NTSTATUS
+FsdGetFsAttributeInformation (PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo)
{
- DPRINT("FsdGetFsAttributeInformation()\n");
- DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo);
+ DPRINT ("FsdGetFsAttributeInformation()\n");
+ DPRINT ("FsAttributeInfo = %p\n", FsAttributeInfo);
- if (!FsAttributeInfo)
- return(STATUS_SUCCESS);
+ if (!FsAttributeInfo)
+ return (STATUS_SUCCESS);
- FsAttributeInfo->FileSystemAttributes = FS_CASE_IS_PRESERVED;
- FsAttributeInfo->MaximumComponentNameLength = 255;
- FsAttributeInfo->FileSystemNameLength = 3;
- wcscpy (FsAttributeInfo->FileSystemName, L"FAT");
+ FsAttributeInfo->FileSystemAttributes = FS_CASE_IS_PRESERVED;
+ FsAttributeInfo->MaximumComponentNameLength = 255;
+ FsAttributeInfo->FileSystemNameLength = 3;
+ wcscpy (FsAttributeInfo->FileSystemName, L"FAT");
- DPRINT("Finished FsdGetFsAttributeInformation()\n");
+ DPRINT ("Finished FsdGetFsAttributeInformation()\n");
- return(STATUS_SUCCESS);
+ return (STATUS_SUCCESS);
}
-NTSTATUS FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
- PFILE_FS_SIZE_INFORMATION FsSizeInfo)
+NTSTATUS
+FsdGetFsSizeInformation (PDEVICE_OBJECT DeviceObject,
+ PFILE_FS_SIZE_INFORMATION FsSizeInfo)
{
- PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
+ PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
- DPRINT("FsdGetFsSizeInformation()\n");
- DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
+ DPRINT ("FsdGetFsSizeInformation()\n");
+ DPRINT ("FsSizeInfo = %p\n", FsSizeInfo);
- if (!FsSizeInfo)
- return(STATUS_SUCCESS);
+ if (!FsSizeInfo)
+ return (STATUS_SUCCESS);
- if (DeviceExt->FatType == FAT32)
+ if (DeviceExt->FatType == FAT32)
{
- struct _BootSector32 *BootSect = (struct _BootSector32 *)DeviceExt->Boot;
+ struct _BootSector32 *BootSect =
+ (struct _BootSector32 *) DeviceExt->Boot;
- if (BootSect->Sectors)
- FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
- else
- FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
+ if (BootSect->Sectors)
+ FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
+ else
+ FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
- FsSizeInfo->AvailableAllocationUnits.QuadPart =
- FAT32CountAvailableClusters(DeviceExt);
+ FsSizeInfo->AvailableAllocationUnits.QuadPart =
+ FAT32CountAvailableClusters (DeviceExt);
- FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
- FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
+ FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
+ FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
}
- else
+ else
{
- struct _BootSector *BootSect = (struct _BootSector *)DeviceExt->Boot;
-
- if (BootSect->Sectors)
- FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
- else
- FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
-
- if (DeviceExt->FatType == FAT16)
- FsSizeInfo->AvailableAllocationUnits.QuadPart =
- FAT16CountAvailableClusters(DeviceExt);
- else
- FsSizeInfo->AvailableAllocationUnits.QuadPart =
- FAT12CountAvailableClusters(DeviceExt);
-
- FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
- FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
+ struct _BootSector *BootSect = (struct _BootSector *) DeviceExt->Boot;
+
+ if (BootSect->Sectors)
+ FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
+ else
+ FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
+
+ if (DeviceExt->FatType == FAT16)
+ FsSizeInfo->AvailableAllocationUnits.QuadPart =
+ FAT16CountAvailableClusters (DeviceExt);
+ else
+ FsSizeInfo->AvailableAllocationUnits.QuadPart =
+ FAT12CountAvailableClusters (DeviceExt);
+
+ FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
+ FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
}
- DPRINT("Finished FsdGetFsSizeInformation()\n");
+ DPRINT ("Finished FsdGetFsSizeInformation()\n");
- return(STATUS_SUCCESS);
+ return (STATUS_SUCCESS);
}
-NTSTATUS STDCALL VfatQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS STDCALL
+VfatQueryVolumeInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Retrieve the specified file information
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
- FILE_INFORMATION_CLASS FileInformationClass =
- Stack->Parameters.QueryVolume.FileInformationClass;
- PFILE_OBJECT FileObject = NULL;
- PVFATFCB FCB = NULL;
+ PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
+ FILE_INFORMATION_CLASS FileInformationClass =
+ Stack->Parameters.QueryVolume.FileInformationClass;
+ PFILE_OBJECT FileObject = NULL;
+ PVFATFCB FCB = NULL;
// PVfatCCB CCB = NULL;
- NTSTATUS RC = STATUS_SUCCESS;
- void *SystemBuffer;
+ NTSTATUS RC = STATUS_SUCCESS;
+ void *SystemBuffer;
- /* PRECONDITION */
- assert(DeviceObject != NULL);
- assert(Irp != NULL);
+ /* PRECONDITION */
+ assert (DeviceObject != NULL);
+ assert (Irp != NULL);
- DPRINT("FsdQueryVolumeInformation(DeviceObject %x, Irp %x)\n",
- DeviceObject,Irp);
+ DPRINT ("FsdQueryVolumeInformation(DeviceObject %x, Irp %x)\n",
+ DeviceObject, Irp);
- /* INITIALIZATION */
- Stack = IoGetCurrentIrpStackLocation(Irp);
- FileInformationClass = Stack->Parameters.QueryVolume.FileInformationClass;
- FileObject = Stack->FileObject;
+ /* INITIALIZATION */
+ Stack = IoGetCurrentIrpStackLocation (Irp);
+ FileInformationClass = Stack->Parameters.QueryVolume.FileInformationClass;
+ FileObject = Stack->FileObject;
// CCB = (PVfatCCB)(FileObject->FsContext2);
// FCB = CCB->Buffer; // Should be CCB->FCB???
- FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
+ FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
// FIXME : determine Buffer for result :
- if (Irp->MdlAddress)
- SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
+ if (Irp->MdlAddress)
+ SystemBuffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
else
SystemBuffer = Irp->UserBuffer;
// SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
- DPRINT("FileInformationClass %d\n",FileInformationClass);
- DPRINT("SystemBuffer %x\n",SystemBuffer);
+ DPRINT ("FileInformationClass %d\n", FileInformationClass);
+ DPRINT ("SystemBuffer %x\n", SystemBuffer);
- switch (FileInformationClass)
- {
- case FileFsVolumeInformation:
- RC = FsdGetFsVolumeInformation(FileObject,
- FCB,
- DeviceObject,
- SystemBuffer);
- break;
+ switch (FileInformationClass)
+ {
+ case FileFsVolumeInformation:
+ RC = FsdGetFsVolumeInformation (FileObject,
+ FCB, DeviceObject, SystemBuffer);
+ break;
- case FileFsAttributeInformation:
- RC = FsdGetFsAttributeInformation(SystemBuffer);
- break;
+ case FileFsAttributeInformation:
+ RC = FsdGetFsAttributeInformation (SystemBuffer);
+ break;
- case FileFsSizeInformation:
- RC = FsdGetFsSizeInformation(DeviceObject, SystemBuffer);
- break;
+ case FileFsSizeInformation:
+ RC = FsdGetFsSizeInformation (DeviceObject, SystemBuffer);
+ break;
- default:
- RC=STATUS_NOT_IMPLEMENTED;
- }
+ default:
+ RC = STATUS_NOT_IMPLEMENTED;
+ }
- Irp->IoStatus.Status = RC;
- Irp->IoStatus.Information = 0;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ Irp->IoStatus.Status = RC;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest (Irp, IO_NO_INCREMENT);
- return RC;
+ return RC;
}
-
-
typedef VOID (*PFLUSH_TO_LSN)(IN PVOID LogHandle, IN LARGE_INTEGER Lsn);
+typedef struct _REACTOS_COMMON_FCB_HEADER
+{
+ PBCB Bcb;
+} REACTOS_COMMON_FCB_HEADER;
+
#endif /* __INCLUDE_DDK_CCTYPES_H */
-/* $Id: iotypes.h,v 1.20 2000/10/06 22:53:21 ekohl Exp $
+/* $Id: iotypes.h,v 1.21 2000/12/29 23:17:11 dwelch Exp $
*
*/
#define FO_HANDLE_CREATED 0x00040000
#define FO_FILE_FAST_IO_READ 0x00080000
+#define FO_DIRECT_CACHE_READ 0x72000001
+#define FO_DIRECT_CACHE_WRITE 0x72000002
+#define FO_DIRECT_CACHE_PAGING_READ 0x72000004
+#define FO_DIRECT_CACHE_PAGING_WRITE 0x72000008
+
typedef struct _FILE_OBJECT
{
CSHORT Type;
PBCB Bcb;
} CACHE_SEGMENT, *PCACHE_SEGMENT;
-NTSTATUS
-STDCALL
-CcFlushCachePage (
- PCACHE_SEGMENT CacheSeg
- );
-NTSTATUS
-STDCALL
-CcReleaseCachePage (
- PBCB Bcb,
- PCACHE_SEGMENT CacheSeg,
- BOOLEAN Valid
- );
-NTSTATUS
-STDCALL
-CcRequestCachePage (
- PBCB Bcb,
- ULONG FileOffset,
- PVOID * BaseAddress,
- PBOOLEAN UptoDate,
- PCACHE_SEGMENT * CacheSeg
- );
-NTSTATUS
-STDCALL
-CcInitializeFileCache (
- PFILE_OBJECT FileObject,
- PBCB * Bcb
- );
-NTSTATUS
-STDCALL
-CcReleaseFileCache (
- PFILE_OBJECT FileObject,
- PBCB Bcb
- );
+NTSTATUS STDCALL
+CcFlushCachePage (PCACHE_SEGMENT CacheSeg);
+NTSTATUS STDCALL
+CcReleaseCachePage (PBCB Bcb,
+ PCACHE_SEGMENT CacheSeg,
+ BOOLEAN Valid);
+NTSTATUS STDCALL
+CcRequestCachePage (PBCB Bcb,
+ ULONG FileOffset,
+ PVOID* BaseAddress,
+ PBOOLEAN UptoDate,
+ PCACHE_SEGMENT* CacheSeg);
+NTSTATUS STDCALL
+CcInitializeFileCache (PFILE_OBJECT FileObject,
+ PBCB* Bcb);
+NTSTATUS STDCALL
+CcReleaseFileCache (PFILE_OBJECT FileObject,
+ PBCB Bcb);
#include <ddk/cctypes.h>
NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG Count);
NTSTATUS
MmCreatePhysicalMemorySection(VOID);
+PVOID
+MmGetContinuousPages(ULONG NumberOfBytes,
+ PHYSICAL_ADDRESS HighestAcceptableAddress);
#define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
-/* $Id: cont.c,v 1.4 2000/03/29 13:11:54 dwelch Exp $
+/* $Id: cont.c,v 1.5 2000/12/29 23:17:12 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
+#include <internal/mm.h>
#include <internal/debug.h>
* REVISIONS
*
*/
-PVOID STDCALL MmAllocateContiguousMemory (
- IN ULONG NumberOfBytes,
- IN PHYSICAL_ADDRESS HighestAcceptableAddress)
+PVOID STDCALL
+MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
+ IN PHYSICAL_ADDRESS HighestAcceptableAddress)
{
- UNIMPLEMENTED;
+ PMEMORY_AREA MArea;
+ NTSTATUS Status;
+ PVOID BaseAddress;
+ PVOID PBase;
+ ULONG i;
+
+ Status = MmCreateMemoryArea(NULL,
+ MmGetKernelAddressSpace(),
+ MEMORY_AREA_CONTINUOUS_MEMORY,
+ &BaseAddress,
+ NumberOfBytes,
+ 0,
+ &MArea);
+ if (!NT_SUCCESS(Status))
+ {
+ return(NULL);
+ }
+
+ PBase = MmGetContinuousPages(NumberOfBytes,
+ HighestAcceptableAddress);
+ for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
+ {
+ MmCreateVirtualMapping(NULL,
+ BaseAddress + (i * 4096),
+ PAGE_EXECUTE_READWRITE,
+ (ULONG)(PBase + (i * 4096)));
+ }
+ return(BaseAddress);
}
* REVISIONS
*
*/
-VOID STDCALL MmFreeContiguousMemory(IN PVOID BaseAddress)
+VOID STDCALL
+MmFreeContiguousMemory(IN PVOID BaseAddress)
{
- UNIMPLEMENTED;
+ MmFreeMemoryArea(MmGetKernelAddressSpace(),
+ BaseAddress,
+ 0,
+ TRUE);
}
/* FUNCTIONS *************************************************************/
+PVOID
+MmGetContinuousPages(ULONG NumberOfBytes,
+ PHYSICAL_ADDRESS HighestAcceptableAddress)
+{
+ ULONG NrPages;
+ ULONG i;
+ ULONG start;
+ ULONG length;
+ KIRQL oldIrql;
+
+ NrPages = PAGE_ROUND_UP(NumberOfBytes) / PAGESIZE;
+
+ KeAcquireSpinLock(&PageListLock, &oldIrql);
+
+ start = -1;
+ length = 0;
+ for (i = 0; i < (HighestAcceptableAddress.QuadPart / PAGESIZE); i++)
+ {
+ if (MmPageArray[i].Flags & MM_PHYSICAL_PAGE_FREE)
+ {
+ if (start == -1)
+ {
+ start = i;
+ length = 1;
+ }
+ else
+ {
+ length++;
+ }
+ if (length == NrPages)
+ {
+ break;
+ }
+ }
+ else if (start != -1)
+ {
+ start = -1;
+ }
+ }
+ if (start == -1)
+ {
+ KeReleaseSpinLock(&PageListLock, oldIrql);
+ return(NULL);
+ }
+ for (i = start; i < (start + length); i++)
+ {
+ RemoveEntryList(&MmPageArray[i].ListEntry);
+ MmPageArray[i].Flags = MM_PHYSICAL_PAGE_USED;
+ MmPageArray[i].ReferenceCount = 1;
+ MmPageArray[i].LockCount = 0;
+ MmPageArray[i].SavedSwapEntry = 0;
+ InsertTailList(&UsedPageListHead, &MmPageArray[i].ListEntry);
+ }
+ return((PVOID)(start * 4096));
+}
+
PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
PVOID LastPhysKernelAddress,
ULONG MemorySizeInPages,