Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Symbolic link of device object is not visile in winobj global section

Ankit_JainAnkit_Jain Member - All Emails Posts: 5
Hi,

Please help me..

I'm creating a windows device object in the handler function of user land IOCTL. Device is getting created and IocreateSymblicname() also returnred successfully. But symbolic link is not shown in winobj.

code:-

Ioctl func(){

switch (code) {
case IOCTL_BUSE_DEVICE_ADD: {
DbgPrint("IOCTL_BUSE_DEVICE_ADD for device %i.\n", device_extension->DeviceNumber);


if (inputBufferLength < sizeof(BUSE_ADD_DISK)) {
DbgPrint("Invalid input buffer size. Got: %u Expected at least: %u.\n",
inputBufferLength, (int)(sizeof(BUSE_ADD_DISK)));
status = STATUS_INVALID_PARAMETER;
break;
}

else if (outputBufferLength < sizeof(BUSE_ADD_DISK_RESPONSE)) {
DbgPrint("Invalid output buffer size. Got: %u Expected at least: %u.\n",
outputBufferLength, (int)(sizeof(BUSE_ADD_DISK_RESPONSE)));
status = STATUS_INVALID_PARAMETER;
break;
}

DbgPrint("Referencing handle %p.\n", *(PHANDLE)Irp->AssociatedIrp.SystemBuffer);
PBUSE_ADD_DISK add_disk = (PBUSE_ADD_DISK)buffer;
DbgPrint("IOCTL_BUSE_DEVICE_ADD info dev no %u, sec size %u, dev_size %u.\n",
add_disk->ad_dev_number, add_disk->ad_dev_sec_size, add_disk->ad_dev_size_MB);

status = BuseDiskAddDisk(DeviceObj->DriverObject, add_disk, L"G:");
if (!NT_SUCCESS(status)) {
DbgPrint("Cannot add disk device (%#x).\n", status);
return status;
}
}


NTSTATUS BuseDiskAddDisk(PDRIVER_OBJECT DriverObject, PBUSE_ADD_DISK add_disk, PCWSTR letter) {
PDEVICE_EXTENSION pDeviceExtension = NULL;
UNICODE_STRING ntDeviceName;
NTSTATUS status;
WCHAR VirtVolInstanceName[128];
PDEVICE_OBJECT DeviceObject;
ULONG device_characteristics;
DEVICE_TYPE device_type;

device_type = FILE_DEVICE_DISK;
device_characteristics = 0;

RtlStringCchPrintfW(VirtVolInstanceName, RTL_NUMBER_OF(VirtVolInstanceName), L"\\Device\\BuseVol%d", add_disk->ad_dev_number);
RtlInitUnicodeString(&ntDeviceName, VirtVolInstanceName);

DbgPrint("Creating device '%ws'. Device type %#x, characteristics %#x.\n", (PWSTR)VirtVolInstanceName, device_type, device_characteristics);

status = IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION),
&ntDeviceName,
device_type,
device_characteristics,
FALSE,
&DeviceObject);

if (!NT_SUCCESS(status)) {
DbgPrint("Cannot create DeviceObject (%#x).\n", status);
return status;
}

DeviceObject->Flags |= DO_DIRECT_IO;

pDeviceExtension = (PDEVICE_EXTENSION)(DeviceObject)->DeviceExtension;
RtlZeroMemory(pDeviceExtension, sizeof(DEVICE_EXTENSION));

// Allocate memory for the volume image.
pDeviceExtension->DevSz = add_disk->ad_dev_size_MB * BUSE_MB_TO_BYTES;
pDeviceExtension->VolumeImage = ExAllocatePoolWithTag(NonPagedPool, pDeviceExtension->DevSz, BUSE_VOL_TAG);
if (pDeviceExtension->VolumeImage) {
RtlZeroMemory(pDeviceExtension->VolumeImage, pDeviceExtension->DevSz);
pDeviceExtension->DiskGeometry.BytesPerSector = add_disk->ad_dev_sec_size;
pDeviceExtension->DiskGeometry.SectorsPerTrack = 32;
pDeviceExtension->DiskGeometry.TracksPerCylinder = 2;
pDeviceExtension->DiskGeometry.Cylinders.QuadPart =
pDeviceExtension->DevSz / pDeviceExtension->DiskGeometry.BytesPerSector / 32 / 2;

// Our media type is FixedMedia
pDeviceExtension->DiskGeometry.MediaType = FixedMedia;

pDeviceExtension->DeviceNumber = add_disk->ad_dev_number;
status = ExUuidCreate(&pDeviceExtension->UniqueIdGuid);

UNICODE_STRING win32Name;
RtlInitUnicodeString(&win32Name, DOS_DEVICE_NAME);
pDeviceExtension->SymbolicLink.Buffer = (PWSTR)&pDeviceExtension->DosDeviceNameBuffer;
pDeviceExtension->SymbolicLink.MaximumLength = sizeof(pDeviceExtension->DosDeviceNameBuffer);
pDeviceExtension->SymbolicLink.Length = win32Name.Length;

UNICODE_STRING driveletter;
RtlInitUnicodeString(&driveletter, letter);
pDeviceExtension->DriveLetter.Buffer = (PWSTR)&pDeviceExtension->DriveLetterBuffer;
pDeviceExtension->DriveLetter.MaximumLength = sizeof(pDeviceExtension->DriveLetterBuffer);
pDeviceExtension->DriveLetter.Length = driveletter.Length;
RtlCopyUnicodeString(&pDeviceExtension->DriveLetter, &driveletter);

RtlCopyUnicodeString(&pDeviceExtension->SymbolicLink, &win32Name);
RtlAppendUnicodeStringToString(&pDeviceExtension->SymbolicLink, &driveletter);


DbgPrint("Creating device '%ws'. Device symb '%ws'\n", (PWSTR)VirtVolInstanceName, (PWSTR)pDeviceExtension->DriveLetterBuffer);


status = IoCreateUnprotectedSymbolicLink(&pDeviceExtension->SymbolicLink, &ntDeviceName);
if (!NT_SUCCESS(status)) {
DbgPrint("Cannot create pDeviceExtension device symblink (%#x).\n", status);
IoDeleteDevice(DeviceObject);
return status;
}

UNICODE_STRING ntName;
RtlInitUnicodeString(&ntName, VirtVolInstanceName);
pDeviceExtension->NtDeviceName.Buffer = (PWSTR)&pDeviceExtension->NtDeviceNameBuffer;
pDeviceExtension->NtDeviceName.MaximumLength = sizeof(pDeviceExtension->NtDeviceNameBuffer);
pDeviceExtension->NtDeviceName.Length = ntName.Length;
RtlCopyUnicodeString(&pDeviceExtension->NtDeviceName, &ntName);

}
else {
DbgPrint("Unable to grab memory\n");
}

return status;
}

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 6,837
    Good heavens!

    WHAT do we have to do to get people to stop writing drivers like this using WDM?

    Showing us the output produced in the debugger would help.. what is your DOS device name that you?re trying to assign?

    Peter
    OSR
    @OSRDrivers

    Peter Viscarola
    OSR
    @OSRDrivers

  • Ankit_JainAnkit_Jain Member - All Emails Posts: 5
    << >>
    WHAT do we have to do to get people to stop writing drivers like this using WDM?

    I'm new in windows world and learning windows driver :).

    << >>

    << >>
    what is your DOS device name that you?re trying to assign?

    L"\\DosDevices\\E:"

    << >>
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 6,837
    <quote>
    I'm new in windows world and learning windows driver :)
    </quote>

    Then learn how to write the RIGHT KIND of driver. Under NO circumstances do you want to write a WDM driver. You want to use WDF: that is, KMDF or UMDF.

    Please. WDM is an old, outdated, complex, bug provoking, interface. You will either hate yourself while debugging your WDM driver or you will happily and unknowingly create a driver with many bugs.

    Peter
    OSR
    @OSRDrivers

    Peter Viscarola
    OSR
    @OSRDrivers

  • Ankit_JainAnkit_Jain Member - All Emails Posts: 5
    I was referring Ramdisk sample code for achieving this task (WDF model). I want to expose virtual drive when user perform add device IOCTL.

    But unable to find out the way of creating a new device object outside DriverEntry() or addDeviceEvt(). If you have any idea please guide me.
  • Ankit_JainAnkit_Jain Member - All Emails Posts: 5
    Please let me know any standard example in WDF for learning purpose. It would be very helpful if you can point any standard book for it.
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 6,837
    Use the toaster sample from the WDK.

    There a book on WDF by Orwick and Fischer. It?s better than nothing.

    Peter
    OSR
    @OSRDrivers

    Peter Viscarola
    OSR
    @OSRDrivers

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 12,717
    xxxxx@outlook.com wrote:
    > I was referring Ramdisk sample code for achieving this task (WDF model). I want to expose virtual drive when user perform add device IOCTL.
    >
    > But unable to find out the way of creating a new device object outside DriverEntry() or addDeviceEvt(). If you have any idea please guide me.

    You already said that IoCreateDevice worked, right?  Then you have found
    the way.  There's nothing particularly special about DriverEntry or
    AddDevice.

    Can you see your \Device in winobj?  (Not the symbolic link, but the
    base device.)  Did you do a "Refresh" in winobj after sending your
    ioctl?  Does the G: drive letter work?

    --
    Tim Roberts, xxxxx@probo.com
    Providenza & Boekelheide, Inc.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Ankit_JainAnkit_Jain Member - All Emails Posts: 5
    << >>
    Can you see your \Device in winobj?? (Not the symbolic link, but the base device.)? Did you do a "Refresh" in winobj after sending your ioctl?? Does the G: drive letter work?

    Yes, I've refreshed it multiple times but still no luck. Unable to see drive as well as symbolic link.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!