Skip to content

Commit

Permalink
Merge pull request #219 from dokan-dev/renameLabel
Browse files Browse the repository at this point in the history
sys - Handle FileFsLabelInformation
  • Loading branch information
Liryna committed Apr 28, 2016
2 parents b05e50c + de902a0 commit ed70204
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 7 deletions.
4 changes: 3 additions & 1 deletion sys/dokan.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct _DokanDiskControlBlock {
PUNICODE_STRING SymbolicLinkName;
PUNICODE_STRING MountPoint;
PUNICODE_STRING UNCName;
LPWSTR VolumeLabel;

DEVICE_TYPE DeviceType;
DEVICE_TYPE VolumeDeviceType;
Expand Down Expand Up @@ -494,7 +495,8 @@ VOID DokanCompleteLock(__in PIRP_ENTRY IrpEntry,
__in PEVENT_INFORMATION EventInfo);

VOID DokanCompleteQueryVolumeInformation(__in PIRP_ENTRY IrpEntry,
__in PEVENT_INFORMATION EventInfo);
__in PEVENT_INFORMATION EventInfo,
__in PDEVICE_OBJECT DeviceObject);

VOID DokanCompleteFlush(__in PIRP_ENTRY IrpEntry,
__in PEVENT_INFORMATION EventInfo);
Expand Down
2 changes: 1 addition & 1 deletion sys/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ DokanCompleteIrp(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp) {
DokanCompleteQueryInformation(irpEntry, eventInfo);
break;
case IRP_MJ_QUERY_VOLUME_INFORMATION:
DokanCompleteQueryVolumeInformation(irpEntry, eventInfo);
DokanCompleteQueryVolumeInformation(irpEntry, eventInfo, DeviceObject);
break;
case IRP_MJ_CREATE:
DokanCompleteCreate(irpEntry, eventInfo);
Expand Down
87 changes: 82 additions & 5 deletions sys/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,26 @@ DokanDispatchQueryVolumeInformation(__in PDEVICE_OBJECT DeviceObject,
}

VOID DokanCompleteQueryVolumeInformation(__in PIRP_ENTRY IrpEntry,
__in PEVENT_INFORMATION EventInfo) {
__in PEVENT_INFORMATION EventInfo,
__in PDEVICE_OBJECT DeviceObject) {
PIRP irp;
PIO_STACK_LOCATION irpSp;
NTSTATUS status = STATUS_SUCCESS;
ULONG info = 0;
ULONG bufferLen = 0;
PVOID buffer = NULL;
PDokanCCB ccb;
PDokanDCB dcb;
PDokanVCB vcb;

DDbgPrint("==> DokanCompleteQueryVolumeInformation\n");

irp = IrpEntry->Irp;
irpSp = IrpEntry->IrpSp;

ccb = IrpEntry->FileObject->FsContext2;
vcb = DeviceObject->DeviceExtension;
dcb = vcb->Dcb;

// ASSERT(ccb != NULL);

Expand Down Expand Up @@ -292,6 +297,28 @@ VOID DokanCompleteQueryVolumeInformation(__in PIRP_ENTRY IrpEntry,
// copy the information from user-mode to specified buffer
ASSERT(buffer != NULL);

if (irpSp->Parameters.QueryVolume.FsInformationClass ==
FileFsVolumeInformation &&
dcb->VolumeLabel != NULL) {

PFILE_FS_VOLUME_INFORMATION volumeInfo =
(PFILE_FS_VOLUME_INFORMATION)EventInfo->Buffer;

ULONG remainingLength = bufferLen;
remainingLength -=
FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel[0]);
ULONG bytesToCopy = (ULONG)wcslen(dcb->VolumeLabel) * sizeof(WCHAR);
if (remainingLength < bytesToCopy) {
bytesToCopy = remainingLength;
}

volumeInfo->VolumeLabelLength = bytesToCopy;
RtlCopyMemory(volumeInfo->VolumeLabel, dcb->VolumeLabel, bytesToCopy);
remainingLength -= bytesToCopy;

EventInfo->BufferLength = bufferLen - remainingLength;
}

RtlZeroMemory(buffer, bufferLen);
RtlCopyMemory(buffer, EventInfo->Buffer, EventInfo->BufferLength);

Expand All @@ -310,14 +337,64 @@ NTSTATUS
DokanDispatchSetVolumeInformation(__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp) {
NTSTATUS status = STATUS_INVALID_PARAMETER;
PDokanVCB vcb;
PDokanDCB dcb;
PIO_STACK_LOCATION irpSp;
PVOID buffer;
FS_INFORMATION_CLASS FsInformationClass;

__try

UNREFERENCED_PARAMETER(DeviceObject);
{
DDbgPrint("==> DokanSetVolumeInformation\n");

vcb = DeviceObject->DeviceExtension;
if (GetIdentifierType(vcb) != VCB) {
return STATUS_INVALID_PARAMETER;
}

DDbgPrint("==> DokanSetVolumeInformation\n");
dcb = vcb->Dcb;

DokanCompleteIrpRequest(Irp, status, 0);
if (!dcb->Mounted) {
status = STATUS_VOLUME_DISMOUNTED;
__leave;
}

irpSp = IoGetCurrentIrpStackLocation(Irp);
buffer = Irp->AssociatedIrp.SystemBuffer;
FsInformationClass = irpSp->Parameters.SetVolume.FsInformationClass;

switch (FsInformationClass) {
case FileFsLabelInformation:

DDbgPrint(" FileFsLabelInformation\n");

if (sizeof(FILE_FS_LABEL_INFORMATION) >
irpSp->Parameters.SetVolume.Length)
return STATUS_INVALID_PARAMETER;

PFILE_FS_LABEL_INFORMATION Info = (PFILE_FS_LABEL_INFORMATION)buffer;
ExAcquireResourceExclusiveLite(&dcb->Resource, TRUE);
if (dcb->VolumeLabel != NULL)
ExFreePool(dcb->VolumeLabel);
dcb->VolumeLabel =
ExAllocatePool(Info->VolumeLabelLength + sizeof(WCHAR));
RtlCopyMemory(dcb->VolumeLabel, Info->VolumeLabel,
Info->VolumeLabelLength);
dcb->VolumeLabel[Info->VolumeLabelLength / sizeof(WCHAR)] = '\0';
ExReleaseResourceLite(&dcb->Resource);
DDbgPrint(" volume label changed to %ws\n", dcb->VolumeLabel);

status = STATUS_SUCCESS;
break;
}

} __finally {

DokanCompleteIrpRequest(Irp, status, 0);
}

DDbgPrint("<== DokanSetVolumeInformation");
DDbgPrint("<== DokanSetVolumeInformation\n");

return status;
}

0 comments on commit ed70204

Please sign in to comment.