newlib/winsup/cygwin/fhandler_floppy.cc
Corinna Vinschen acb5617538 * cygwin.din (fstat64): New symbol.
(ftruncate64): Ditto.
	(lseek64): Ditto.
	(lstat64): Ditto.
	(mmap64): Ditto.
	(seekdir64): Ditto.
	(stat64): Ditto.
	(telldir64): Ditto.
	(truncate64): Ditto.
	* dir.cc (telldir64): New function.
	(telldir): Call telldir64().
	(seekdir64): New function.
	(seekdir): Call seekdir64().
	* fhandler.h: Redefine all methods using __off32_t to use __off64_t.
	* fhandler.cc: Use __off64_t and struct __stat64 throughout.
	* fhandler_clipboard.cc: Ditto.
	* fhandler_disk_file.cc: Ditto.
	* fhandler_dsp.cc: Ditto.
	* fhandler_floppy.cc: Ditto.
	* fhandler_mem.cc: Ditto.
	* fhandler_random.cc: Ditto.
	* fhandler_socket.cc: Ditto.
	* fhandler_tape.cc: Ditto.
	* fhandler_zero.cc: Ditto.
	* pipe.cc: Ditto.
	* glob.c: Ditto, call lstat64 and stat64 in Cygwin.
	* mmap.cc: Use __off64_t throughout.
	(mmap64): New function.
	* sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64.
	* syscalls.cc (lseek64): New function.
	(stat64_to_stat32): Ditto.
	(fstat64): Ditto.
	(stat64): Ditto.
	(lstat64): Ditto.
	(ftruncate64): Ditto.
	(truncate64): Ditto.
	(_fstat): Call fstat64.
	(_stat): Call stat64.
	(cygwin_lstat): Rename to avoid declaration problem.  Call lstat64.
	(stat_worker): Use struct __stat64.
	(access): Ditto.
	(ftruncate): Call ftruncate64.
	(truncate): Call truncate64.
	* wincap.cc: Set flag has_64bit_file_access appropriately.
	* wincap.h: Add flag has_64bit_file_access.
	* winsup.h (ILLEGAL_SEEK): Define as __off64_t.
	(stat_dev): Declare using struct __stat64.
	(stat_worker): Ditto.
	* include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin.
	(struct __stat64): Ditto.
	(struct stat): Revert definition with explicitly sized datatypes.
	Eliminate sized field names.
	* include/cygwin/types.h (blksize_t): New type.
	(__blkcnt32_t): Ditto.
	(__blkcnt64_t): Ditto.
	(blkcnt_t): Ditto.
2002-02-25 17:47:51 +00:00

193 lines
4.4 KiB
C++

/* fhandler_floppy.cc. See fhandler.h for a description of the
fhandler classes.
Copyright 1999, 2000, 2001, 2002 Red Hat, Inc.
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. */
#include "winsup.h"
#include <sys/termios.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <winioctl.h>
#include "security.h"
#include "fhandler.h"
#include "cygerrno.h"
/**********************************************************************/
/* 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
fhandler_dev_floppy::is_eof (int)
{
int ret = 0;
if (ret)
debug_printf ("end of file");
return ret;
}
fhandler_dev_floppy::fhandler_dev_floppy (int unit) : fhandler_dev_raw (FH_FLOPPY, unit)
{
}
int
fhandler_dev_floppy::open (path_conv *real_path, int flags, mode_t)
{
/* 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; */
return fhandler_dev_raw::open (real_path, flags);
}
int
fhandler_dev_floppy::close (void)
{
int ret;
ret = writebuf ();
if (ret)
{
fhandler_dev_raw::close ();
return ret;
}
return fhandler_dev_raw::close ();
}
__off64_t
fhandler_dev_floppy::lseek (__off64_t offset, int whence)
{
int ret;
char buf[512];
__off64_t drive_size = 0;
__off64_t lloffset = offset;
__off64_t current_position;
__off64_t sector_aligned_offset;
__off64_t bytes_left;
DWORD low;
LONG high = 0;
DISK_GEOMETRY di;
PARTITION_INFORMATION pi;
DWORD bytes_read;
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;
}
debug_printf ("drive size: %ld", drive_size);
if (whence == SEEK_END && drive_size > 0)
{
lloffset = offset + drive_size;
whence = SEEK_SET;
}
if (whence == SEEK_CUR)
{
low = SetFilePointer (get_handle (), 0, &high, FILE_CURRENT);
if (low == INVALID_SET_FILE_POINTER && GetLastError ())
{
__seterrno ();
return -1;
}
current_position = low + ((__off64_t) high << 32);
if (is_writing)
current_position += devbufend - devbufstart;
else
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 */
sector_aligned_offset = (lloffset / 512) * 512;
bytes_left = lloffset - sector_aligned_offset;
if (whence == SEEK_SET)
{
/* Invalidate buffer. */
ret = writebuf ();
if (ret)
return ret;
devbufstart = devbufend = 0;
low = sector_aligned_offset & 0xffffffff;
high = sector_aligned_offset >> 32;
if (SetFilePointer (get_handle (), low, &high, FILE_BEGIN)
== INVALID_SET_FILE_POINTER && GetLastError ())
{
__seterrno ();
return -1;
}
return sector_aligned_offset + raw_read (buf, bytes_left);
}
set_errno (EINVAL);
return -1;
}
int
fhandler_dev_floppy::ioctl (unsigned int cmd, void *buf)
{
return fhandler_dev_raw::ioctl (cmd, buf);
}