Re: drive present detection?



On Mar 18, 11:07 pm, Uwe Sieber <m...@xxxxxxxxxxxxx> wrote:
Jim Michaels wrote:
On Mar 18, 5:20 pm, Jim Michaels <jmich...@xxxxxxxxx> wrote:
how do I do drive present detection without causing a crash?
I know about FindFirstFile() but that causes a crash.
I know about GetDiskFreeSpaceEx() which is what I am after, but that
causes a crash.
I know about GetDriveType() but it does not give enough information.
I know about GetLogicalDrives().

It all doesn't seem to add up to enough.
somehow Adobe Photoshop Album 3.0 autodetects memory cards when they
are inserted and it is done by the OS somehow or lauched by the OS
somehow.

regardless, mine is a disk free space application and I want to get
the free space of all online drives.
Jim Michaels

I forgot to mention that I have a card reader that lists itself as a
removeable device. I have no idea how to check if the removeable item
is inserted or not, be it bernoulli, floppy, superdrive, zip disk,
Magneto-Optical drive, Tape Drive, etc.
whatever the device, it must be a logical drive letter (logical
volume).

If GetDiskFreeSpaceEx makes your app crash then you
do something wrong. Show your code.

To receive media insertion and removal notifications
you have to register for these.
Some time ago I've made a sample to demonstrate a
bug in Vista x64 (which is btw not fixed by SP1).http://groups.google.com/group/microsoft.public.win32.programmer.kern...

But for a free space app you will poll anyway, so,
device notifications might be over engineered here.

Uwe

it's long. like I said before, the thing is, it only crashes when it
hits removeable drives that are not there, like my empty card reader
which has 4 drive letters.
it always causes the following exception which I would like to be able
to handle:
["Windows - No Disk:
Exception Processing Message c0000013 Parameters 75b6bf7c 4 75b6bf7c
75b6bf7c"
cancel, try again, ignore]

c0000013 means STATUS_NO_MEDIA_IN_DEVICE.

char * dirpath[26]= {
"A:\\", "B:\\", "C:\\", "D:\\", "E:\\", "F:\\",
"G:\\",
"H:\\", "I:\\", "J:\\", "K:\\", "L:\\", "M:\\",
"N:\\",
"O:\\", "P:\\", "Q:\\", "R:\\", "S:\\", "T:\\",
"U:\\",
"V:\\", "W:\\", "X:\\", "Y:\\", "Z:\\"
};
char * drivename[26]= {
"A:", "B:", "C:", "D:", "E:", "F:", "G:",
"H:",
"I:", "J:", "K:", "L:", "M:", "N:", "O:",
"P:",
"Q:", "R:", "S:", "T:", "U:", "V:", "W:",
"X:",
"Y:", "Z:"
};

void ShowDrive(int drive, bool verbose) {
// 0 is current drive, 1 is a:, 2 is b:, 3 is c:... up to lastdrive.
long double total, davail;
__int64 iTotal, iDAvail;
ULARGE_INTEGER lfreebytes, ltotbytes, ltotfreebytes;
int percent;
TRY {
GetDiskFreeSpaceEx(
dirpath[drive],
&lfreebytes,
&ltotbytes,
&ltotfreebytes
);
} CATCH(CException, e) {

}
// cout.setf(ios::fixed);
// cout.unsetf(ios::scientific);
iDAvail=lfreebytes.QuadPart;
iTotal=ltotbytes.QuadPart;
// printf("%I64d %I64d\n", iDAvail, iTotal);
// fflush(stdout);
// return;
davail = double(lfreebytes.QuadPart);
total = double(ltotbytes.QuadPart);
iTotalDAvail += iDAvail;
iTotalTotal += iTotal;
if (drive == thisDrive) { // if current drive, show it.
printf("*");
} else {
printf(" ");
}

printf("%s", drivename[drive]);

if (verbose) {
printf("%I64d/%I64d (%I64d%%)\n",
iDAvail,
iTotal,
(iDAvail*100)/iTotal
);
} else { //if verbose

//-----disk usage graph
for (percent = 1; percent <= int(graphLength); percent++)
{
if ((double(percent)/graphLength) >= (davail/total)) {
//right part of graph
if (isAscii) {
printf("-"); //░
} else {
printf("░");
}
} else {
//left part of graph
if (isAscii) {
printf("*");
} else {
printf("█");
}
}
}
//-----disk free/total disk numbers
PrintSINum(davail);
printf("/");
PrintSINum(total);
double nd=davail*100.0;nd/=total;
printf(" (%4.2f%%)\n", nd);
} //end if verbose
}



I have never done what is below before. I find a little documentation
on IRPs in the copy of the MSDN I have.
from the msdn I have what is below. that is all fine and good for
people with $800 microsoft compilers. mine is not and I can't use the
DDK so I can't use IRPs.
the ability to check the status of a removable drive (cdrom, disk)
would be wonderful. I know the drive number, drive letter, and path.
help


At its discretion, the file system can send an IRP to the device
driver's Dispatch entry point for IRP_MJ_DEVICE_CONTROL requests with
Parameters.DeviceIoControl.IoControlCode in the I/O stack location set
to the following:

IOCTL_XXX_CHECK_VERIFY
where XXX is the type of device, such as DISK, TAPE, or CDROM.
The type DISK includes both unpartitionable (floppy) and partitionable
removable-media devices.

If the underlying device driver determines that the media has not
changed, the driver should complete the IRP, returning the IoStatus
block with the following values: Status
set to STATUS_SUCCESS

Information
set to zero



In addition, if the device type is DISK or CDROM and the caller
specified an output buffer, the driver returns the media change count
in the buffer at
Irp->AssociatedSystemBuffer and sets IoStatus.Information to sizeof
(ULONG). By returning this count the driver gives the caller an
opportunity to determine whether the media has changed from its
perspective.

If the underlying device driver determines that the media has changed,
it should do the following:

If the volume is mounted (the VPB_MOUNTED flag is set in the VPB):

Set the Flags in the DeviceObject by ORing Flags with
DO_VERIFY_VOLUME.

Set the IoStatus block in the IRP to the following:
Status STATUS_VERIFY_REQUIRED

Information zero

3. Call IoCompleteRequest with the input IRP.


If the volume is not mounted, the driver must not set the
DO_VERIFY_VOLUME bit. The driver should set IoStatus.Status to
STATUS_IO_DEVICE_ERROR, set IoStatus.Information to zero, and call
IoCompleteRequest with the IRP.
Notifying the File System of Possible Media Changes
An NT removable-media device driver must ensure that the media is not
changed for the device represented by the DeviceObject (input to every
driver routine that is sent an IRP) whenever the driver processes an
IRP that requests a transfer to/from the media or a device I/O control
operation that affects the media. The best possible time to check for
changed media is just after the transition from a no-media-present
state to a media-present state if the physical device always notifies
the driver about these state changes.

If its physical device indicates that the state of the media might
have changed before the driver begins an I/O operation or during an
operation, the driver must do the following:

Ensure that the volume is mounted by checking the VPB_MOUNTED flag in
the VPB. (If the volume is not mounted, the driver must not set the
DO_VERIFY_VOLUME bit. The driver should set IoStatus.Status to
STATUS_VERIFY_REQUIRED, set IoStatus.Information to zero, and call
IoCompleteRequest with the IRP.)

Set the Flags in the DeviceObject by ORing Flags with
DO_VERIFY_VOLUME.

Set the IoStatus block in the IRP to the following:
Status STATUS_VERIFY_REQUIRED

Information zero


Before completing any IRP with an IoStatus block in which the Status
field is not set to STATUS_SUCCESS, the driver must call
IoIsErrorUserInduced, which returns a Boolean TRUE for any of the
following Status values:
STATUS_VERIFY_REQUIRED
STATUS_NO_MEDIA_IN_DEVICE
STATUS_WRONG_VOLUME
STATUS_UNRECOGNIZED_MEDIA
STATUS_MEDIA_WRITE_PROTECTED
STATUS_IO_TIMEOUT
STATUS_DEVICE_NOT_READY
.



Relevant Pages

  • Re: [9fans] devsd & media changed errors
    ... the ctl file and then the media changes, ... i ejected a blank disk and reinserted it. ... (some sata drives have loopy firmware.) ... the sdmv driver is not quite driving the disks right). ...
    (comp.os.plan9)
  • Re: Help with solving an error message on a cpio backup
    ... > installed with the 'bhba' driver. ... tape is coming up soon" marker on the tape. ... Shoeshining shortens the life of both the drive and the media. ... -- you'd like it to be _immediately_ after, but in practice, most drives ...
    (comp.unix.sco.misc)
  • [2.6 patch] remove the documentation for the legacy CDROM drivers
    ... This patch removes the documentation for the removed legacy CDROM drivers. ... SC1200 WDT DRIVER ... LaTeX document on standardizing the CD-ROM programming interface. ... THIS DRIVER WILL WORK WITH THE CD-ROM DRIVES LISTED, ...
    (Linux-Kernel)
  • [PATCH 18-rc2] Fix typos in /Documentation : N-P
    ... Again, if you're not gonna do synchronization with disk drives (dang, ... -the kernel. ... There are two options specific to PSX driver portion. ... The driver uses the settings from the EEPROM set in the SCSI BIOS ...
    (Linux-Kernel)
  • Re: [PATCH, RFT, v4] sata_mv: convert to new EH
    ... check both new and old drives with SMART ... Use a HIGHMEM enabled kernel. ... ACPI: PM-Timer IO Port: 0xe408 ... Real Time Clock Driver v1.12ac ...
    (Linux-Kernel)

Loading