2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler_floppy.cc. See fhandler.h for a description of the
|
|
|
|
fhandler classes.
|
|
|
|
|
* child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright.
2002-02-10 21:50:13 +08:00
|
|
|
Copyright 1999, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/termios.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include <winioctl.h>
|
2002-11-07 22:16:29 +08:00
|
|
|
#include <asm/socket.h>
|
|
|
|
#include <cygwin/hdreg.h>
|
|
|
|
#include <cygwin/fs.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
2001-02-06 00:10:06 +08:00
|
|
|
#include "cygerrno.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/* fhandler_dev_floppy */
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_floppy::is_eom (int win_error)
|
|
|
|
{
|
|
|
|
int ret = (win_error == ERROR_INVALID_PARAMETER);
|
|
|
|
if (ret)
|
|
|
|
debug_printf ("end of medium");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_dev_floppy::is_eof (int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if (ret)
|
|
|
|
debug_printf ("end of file");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
fhandler_dev_floppy::fhandler_dev_floppy (int unit) : fhandler_dev_raw (FH_FLOPPY, unit)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-04 10:34:20 +08:00
|
|
|
fhandler_dev_floppy::open (path_conv *real_path, int flags, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* The correct size of the buffer would be 512 bytes,
|
|
|
|
* which is the atomic size, supported by WinNT.
|
|
|
|
* Unfortunately, the performance is worse than
|
|
|
|
* access to file system on same device!
|
|
|
|
* Setting buffer size to a relatively big value
|
|
|
|
* increases performance by means.
|
|
|
|
* The new ioctl call with 'rdevio.h' header file
|
|
|
|
* supports changing this value.
|
|
|
|
*
|
|
|
|
* Let's be smart: Let's take a multiplier of typical tar
|
|
|
|
* and cpio buffer sizes by default!
|
|
|
|
*/
|
|
|
|
devbufsiz = 61440L; /* 512L; */
|
2001-10-04 10:34:20 +08:00
|
|
|
return fhandler_dev_raw::open (real_path, flags);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_floppy::close (void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = writebuf ();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
fhandler_dev_raw::close ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return fhandler_dev_raw::close ();
|
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t
|
|
|
|
fhandler_dev_floppy::lseek (_off64_t offset, int whence)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-02-06 00:10:06 +08:00
|
|
|
int ret;
|
|
|
|
char buf[512];
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t drive_size = 0;
|
|
|
|
_off64_t lloffset = offset;
|
|
|
|
_off64_t current_position;
|
|
|
|
_off64_t sector_aligned_offset;
|
|
|
|
_off64_t bytes_left;
|
2001-02-28 17:59:54 +08:00
|
|
|
DWORD low;
|
|
|
|
LONG high = 0;
|
|
|
|
|
2001-09-05 18:14:15 +08:00
|
|
|
DISK_GEOMETRY di;
|
|
|
|
PARTITION_INFORMATION pi;
|
|
|
|
DWORD bytes_read;
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
if (!DeviceIoControl (get_handle (),
|
2001-09-05 18:14:15 +08:00
|
|
|
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
NULL, 0,
|
|
|
|
&di, sizeof (di),
|
|
|
|
&bytes_read, NULL))
|
2001-02-06 00:10:06 +08:00
|
|
|
{
|
2001-09-05 18:14:15 +08:00
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
|
|
|
|
di.Cylinders.LowPart,
|
|
|
|
di.TracksPerCylinder,
|
|
|
|
di.SectorsPerTrack,
|
|
|
|
di.BytesPerSector);
|
|
|
|
if (DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_PARTITION_INFO,
|
|
|
|
NULL, 0,
|
|
|
|
&pi, sizeof (pi),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
debug_printf ("partition info: %ld (%ld)",
|
|
|
|
pi.StartingOffset.LowPart,
|
|
|
|
pi.PartitionLength.LowPart);
|
2002-02-26 01:47:51 +08:00
|
|
|
drive_size = pi.PartitionLength.QuadPart;
|
2001-09-05 18:14:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-26 01:47:51 +08:00
|
|
|
drive_size = di.Cylinders.QuadPart * di.TracksPerCylinder *
|
2001-09-05 18:14:15 +08:00
|
|
|
di.SectorsPerTrack * di.BytesPerSector;
|
2001-02-06 00:10:06 +08:00
|
|
|
}
|
2001-09-05 18:14:15 +08:00
|
|
|
debug_printf ("drive size: %ld", drive_size);
|
2001-02-28 17:59:54 +08:00
|
|
|
|
|
|
|
if (whence == SEEK_END && drive_size > 0)
|
2001-02-06 00:10:06 +08:00
|
|
|
{
|
2001-02-28 17:59:54 +08:00
|
|
|
lloffset = offset + drive_size;
|
2001-03-03 11:56:34 +08:00
|
|
|
whence = SEEK_SET;
|
2001-02-28 17:59:54 +08:00
|
|
|
}
|
2001-02-06 00:10:06 +08:00
|
|
|
|
2001-02-28 17:59:54 +08:00
|
|
|
if (whence == SEEK_CUR)
|
|
|
|
{
|
2001-02-06 00:10:06 +08:00
|
|
|
low = SetFilePointer (get_handle (), 0, &high, FILE_CURRENT);
|
|
|
|
if (low == INVALID_SET_FILE_POINTER && GetLastError ())
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2003-04-02 00:11:41 +08:00
|
|
|
current_position = low + ((_off64_t) high << 32);
|
2001-02-06 00:10:06 +08:00
|
|
|
if (is_writing)
|
2001-02-28 17:59:54 +08:00
|
|
|
current_position += devbufend - devbufstart;
|
2001-02-06 00:10:06 +08:00
|
|
|
else
|
2001-02-28 17:59:54 +08:00
|
|
|
current_position -= devbufend - devbufstart;
|
|
|
|
|
|
|
|
lloffset += current_position;
|
|
|
|
whence = SEEK_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lloffset < 0 ||
|
|
|
|
drive_size > 0 && lloffset > drive_size)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: sector can possibly be not 512 bytes long */
|
2002-02-26 01:47:51 +08:00
|
|
|
sector_aligned_offset = (lloffset / 512) * 512;
|
|
|
|
bytes_left = lloffset - sector_aligned_offset;
|
2001-02-28 17:59:54 +08:00
|
|
|
|
|
|
|
if (whence == SEEK_SET)
|
|
|
|
{
|
2001-02-06 00:10:06 +08:00
|
|
|
/* Invalidate buffer. */
|
|
|
|
ret = writebuf ();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
devbufstart = devbufend = 0;
|
|
|
|
|
2002-02-26 01:47:51 +08:00
|
|
|
low = sector_aligned_offset & 0xffffffff;
|
|
|
|
high = sector_aligned_offset >> 32;
|
|
|
|
if (SetFilePointer (get_handle (), low, &high, FILE_BEGIN)
|
|
|
|
== INVALID_SET_FILE_POINTER && GetLastError ())
|
2001-09-08 05:32:07 +08:00
|
|
|
{
|
2001-02-06 00:10:06 +08:00
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2002-12-14 12:01:32 +08:00
|
|
|
|
|
|
|
size_t len = bytes_left;
|
|
|
|
raw_read (buf, len);
|
|
|
|
return sector_aligned_offset + bytes_left;
|
2001-02-06 00:10:06 +08:00
|
|
|
}
|
2001-02-28 17:59:54 +08:00
|
|
|
|
2001-02-06 00:10:06 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_floppy::ioctl (unsigned int cmd, void *buf)
|
|
|
|
{
|
2002-11-07 22:16:29 +08:00
|
|
|
DISK_GEOMETRY di;
|
|
|
|
PARTITION_INFORMATION pi;
|
|
|
|
DWORD bytes_read;
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t drive_size = 0;
|
|
|
|
_off64_t start = 0;
|
2002-11-07 22:16:29 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case HDIO_GETGEO:
|
|
|
|
{
|
2003-01-26 14:42:40 +08:00
|
|
|
debug_printf ("HDIO_GETGEO");
|
|
|
|
if (!DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
NULL, 0,
|
|
|
|
&di, sizeof (di),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
|
|
|
|
di.Cylinders.LowPart,
|
|
|
|
di.TracksPerCylinder,
|
|
|
|
di.SectorsPerTrack,
|
|
|
|
di.BytesPerSector);
|
|
|
|
if (DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_PARTITION_INFO,
|
|
|
|
NULL, 0,
|
|
|
|
&pi, sizeof (pi),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
debug_printf ("partition info: %ld (%ld)",
|
|
|
|
pi.StartingOffset.LowPart,
|
|
|
|
pi.PartitionLength.LowPart);
|
|
|
|
start = pi.StartingOffset.QuadPart >> 9ULL;
|
|
|
|
}
|
|
|
|
struct hd_geometry *geo = (struct hd_geometry *) buf;
|
|
|
|
geo->heads = di.TracksPerCylinder;
|
|
|
|
geo->sectors = di.SectorsPerTrack;
|
|
|
|
geo->cylinders = di.Cylinders.LowPart;
|
|
|
|
geo->start = start;
|
|
|
|
return 0;
|
2002-11-07 22:16:29 +08:00
|
|
|
}
|
|
|
|
case BLKGETSIZE:
|
|
|
|
case BLKGETSIZE64:
|
|
|
|
{
|
2003-01-26 14:42:40 +08:00
|
|
|
debug_printf ("BLKGETSIZE");
|
|
|
|
if (!DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
NULL, 0,
|
|
|
|
&di, sizeof (di),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
|
|
|
|
di.Cylinders.LowPart,
|
|
|
|
di.TracksPerCylinder,
|
|
|
|
di.SectorsPerTrack,
|
|
|
|
di.BytesPerSector);
|
|
|
|
if (DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_PARTITION_INFO,
|
|
|
|
NULL, 0,
|
|
|
|
&pi, sizeof (pi),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
debug_printf ("partition info: %ld (%ld)",
|
|
|
|
pi.StartingOffset.LowPart,
|
|
|
|
pi.PartitionLength.LowPart);
|
|
|
|
drive_size = pi.PartitionLength.QuadPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drive_size = di.Cylinders.QuadPart * di.TracksPerCylinder *
|
|
|
|
di.SectorsPerTrack * di.BytesPerSector;
|
|
|
|
}
|
|
|
|
if (cmd == BLKGETSIZE)
|
|
|
|
*(long *)buf = drive_size >> 9UL;
|
|
|
|
else
|
2003-04-02 00:11:41 +08:00
|
|
|
*(_off64_t *)buf = drive_size;
|
2003-01-26 14:42:40 +08:00
|
|
|
return 0;
|
2002-11-07 22:16:29 +08:00
|
|
|
}
|
|
|
|
case BLKRRPART:
|
|
|
|
{
|
2003-01-26 14:42:40 +08:00
|
|
|
debug_printf ("BLKRRPART");
|
|
|
|
if (!DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_UPDATE_DRIVE_SIZE,
|
|
|
|
NULL, 0,
|
|
|
|
&di, sizeof (di),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2002-11-07 22:16:29 +08:00
|
|
|
}
|
|
|
|
case BLKSSZGET:
|
|
|
|
{
|
2003-01-26 14:42:40 +08:00
|
|
|
debug_printf ("BLKSSZGET");
|
|
|
|
if (!DeviceIoControl (get_handle (),
|
|
|
|
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
NULL, 0,
|
|
|
|
&di, sizeof (di),
|
|
|
|
&bytes_read, NULL))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
|
|
|
|
di.Cylinders.LowPart,
|
|
|
|
di.TracksPerCylinder,
|
|
|
|
di.SectorsPerTrack,
|
|
|
|
di.BytesPerSector);
|
|
|
|
*(int *)buf = di.BytesPerSector;
|
|
|
|
return 0;
|
2002-11-07 22:16:29 +08:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return fhandler_dev_raw::ioctl (cmd, buf);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|