📄 chkmedia.c
字号:
/*
* Media check functions
*/
#include "pcdisk.h"
/* BOOLEAN check_media_entry(int driveno)
*
* Called from the top of the API
* Return TRUE if the drive is mounted and it is okay to proceed with IO on
* a drive
*
* This routine is called from the top of the io layer. If the drive is
* Not mounted it may be (re)mounted as a result of this call and the call
* will return TRUE (it is okay to proceed). A similar call, check_media_io(),
* is called from a lower layer. It will succeed if raw IO is requested
* and the device is ok or if the device is mounted and ok
*
* Inputs:
* int driveno; Drive number 0 .. NDRIVES
*
* Outputs:
* TRUE if is mounted and it is okay to proceed with IO
* FALSE if the drive can't be used and the user did not
* replace it with a usable disk
*
*
*/
BOOLEAN check_media_entry(int driveno) /*__fn__*/
{
/* Call media check
If dev is OK and mounted proceed
If dev is OK and not mounted try to mount.
If dev is changed and mounted but buffers aren't dirty then
unmount and remount.
If dev is changed and mounted but buffers are dirty then unmount and fail
*/
return(check_media(driveno, TRUE, FALSE, TRUE));
}
/* BOOLEAN check_media_io(int driveno, BOOLEAN raw)
*
* Called from the IO layer
* Return TRUE if the device is UP and either raw IO is requested
* or the drive is mounted.
*
*
* Inputs:
* int driveno; Drive number 0 .. NDRIVES
*
* Outputs:
* TRUE if is is okay to proceed with IO
* FALSE If we can't proceed with IO
*
*
*/
BOOLEAN check_media_io(int driveno, BOOLEAN raw) /*__fn__*/
{
/* Call media check
If dev is OK and mounted or raw proceed
If dev is changed and not mounted and raw then proceed
If dev is changed and mounted then unmount and fail
*/
return(check_media(driveno, FALSE, raw, TRUE));
}
/* BOOLEAN check_media(int driveno, BOOLEAN mount)
*
* Return TRUE is it is okay to proceed with IO on a drive
*
* Inputs:
* int driveno; Drive number 0 .. NDRIVES
* BOOLEAN ok_to_automount Automount the drive
* BOOLEAN raw_access_requested Mount not needed but device must
* be functional
*
*/
BOOLEAN check_media(int driveno, BOOLEAN ok_to_automount, BOOLEAN raw_access_requested, BOOLEAN call_crit_err) /*__fn__*/
{
int media_status;
int crit_err_media_status;
DDRIVE *pdr;
int drive_is_dirty;
pdr = pc_drno_to_drive_struct(driveno);
if (!pdr || !(pdr->drive_flags&DRIVE_FLAGS_VALID) )
return(FALSE);
/* Call device check status. Tell the driver if the volume needs to
be flushed. This way the driver writer can force the user to re-insert
the removable device if possible */
drive_is_dirty = (pdr->mount_valid && (pdr->fat_is_dirty || pc_test_all_fil(pdr)));
/* If the device is removable check status to see if we must recover or remount */
/* Note: odd casting is to stop compiler warning of int to pvoid conversion */
if (pdr->drive_flags & DRIVE_FLAGS_REMOVABLE)
media_status = pdr->dev_table_perform_device_ioctl(driveno, DEVCTL_CHECKSTATUS, (PFVOID) ((dword)(drive_is_dirty)));
else
media_status = 0;
crit_err_media_status = 0;
if (media_status==0) /* Device is up */
{
if (pdr->mount_valid) /* already mounted */
{
goto status_is_ok;
}
else
{
if (raw_access_requested) /* Mount not required */
goto status_is_ok;
else if (ok_to_automount)
{
/* Mount the drive if we can -
. Read partition table if required
. Read block zero
*/
if (pc_i_dskopen(driveno))
goto status_is_ok;
else
{
/* Tell the user it is unformatted */
crit_err_media_status = CRERR_BAD_FORMAT;
goto status_is_bad;
}
}
else
{
/* The drive is not mounted. and ok_to_automount is false */
goto status_is_bad;
}
}
}
else if (media_status == DEVTEST_CHANGED)
{
/* If the drive is dirty the user must explicitly abort */
if (drive_is_dirty)
{
crit_err_media_status = CRERR_CHANGED_CARD;
goto status_is_bad;
}
else
{
/* If automount is requested then close the existing
mount and continue. */
if (ok_to_automount)
{
pc_dskfree((int)driveno);
/* Mount the drive if we can */
if (pc_i_dskopen(driveno))
{
goto status_is_ok;
}
else
{
crit_err_media_status = CRERR_BAD_FORMAT;
goto status_is_bad;
}
}
else
{
crit_err_media_status = CRERR_CHANGED_CARD;
goto status_is_bad;
}
}
}
else
{
if (media_status == DEVTEST_NOMEDIA)
crit_err_media_status = CRERR_NO_CARD;
else if (media_status == DEVTEST_UNKMEDIA)
crit_err_media_status = CRERR_BAD_CARD;
else
crit_err_media_status = CRERR_CARD_FAILURE;
goto status_is_bad;
}
status_is_ok:
return(TRUE);
status_is_bad:
if (crit_err_media_status)
{
if (call_crit_err)
critical_error_handler(driveno, crit_err_media_status, 0);
}
/* Abort the current mount */
pc_dskfree((int)driveno);
return(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -