Implement FORMAT UNIT for magneto-optical disks.
This commit is contained in:
@@ -56,6 +56,11 @@
|
|||||||
#include "../disk/hdc_ide.h"
|
#include "../disk/hdc_ide.h"
|
||||||
#include "mo.h"
|
#include "mo.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Bits of 'status' */
|
/* Bits of 'status' */
|
||||||
#define ERR_STAT 0x01
|
#define ERR_STAT 0x01
|
||||||
@@ -1281,6 +1286,7 @@ do_command(void *p, uint8_t *cdb)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mo_format(dev);
|
||||||
set_phase(dev, SCSI_PHASE_STATUS);
|
set_phase(dev, SCSI_PHASE_STATUS);
|
||||||
command_complete(dev);
|
command_complete(dev);
|
||||||
break;
|
break;
|
||||||
@@ -2764,3 +2770,74 @@ mo_insert(mo_t *dev)
|
|||||||
{
|
{
|
||||||
dev->unit_attention = 1;
|
dev->unit_attention = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
mo_format(mo_t *dev)
|
||||||
|
{
|
||||||
|
long size;
|
||||||
|
int ret;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
DEBUG("Formatting media...\n");
|
||||||
|
|
||||||
|
fseek(dev->drv->f, 0, SEEK_END);
|
||||||
|
size = ftell(dev->drv->f);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
HANDLE fh;
|
||||||
|
|
||||||
|
fd = _fileno(dev->drv->f);
|
||||||
|
fh = (HANDLE)_get_osfhandle(fd);
|
||||||
|
|
||||||
|
ret = (int)SetFilePointerEx(fh, 0, NULL, FILE_BEGIN);
|
||||||
|
|
||||||
|
if(!ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed seek to start of image file\n", dev->id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (int)SetEndOfFile(fh);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed to truncate image file to 0\n", dev->id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (int)SetFilePointerEx(fh, size, NULL, FILE_BEGIN);
|
||||||
|
|
||||||
|
if(!ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed seek to end of image file\n", dev->id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (int)SetEndOfFile(fh);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed to truncate image file to %llu\n", dev->id, size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
fd = fileno(dev->drv->f);
|
||||||
|
|
||||||
|
ret = ftruncate(fd, 0);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed to truncate image file to 0\n", dev->id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ftruncate(fd, size);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
DEBUG("MO %i: Failed to truncate image file to %llu", dev->id, size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ extern int mo_string_to_bus(const char *str);
|
|||||||
extern const char *mo_bus_to_string(int bus);
|
extern const char *mo_bus_to_string(int bus);
|
||||||
extern int mo_load(mo_t *dev, const wchar_t *fn);
|
extern int mo_load(mo_t *dev, const wchar_t *fn);
|
||||||
extern void mo_close(void);
|
extern void mo_close(void);
|
||||||
|
extern void mo_format(mo_t *dev);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user