mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-16 03:19:54 +08:00
f098767559
eof_detected status flag. Delete is_eom and is_eof methods. Move drive_size, bytes_per_sector, eom_detected status flag, as well as the methods read_file, write_file, raw_read and raw_write to ... (class fhandler_dev_floppy): ... here. Remove is_eom and is_eof methods. Add dup method. * fhandler_floppy.cc (IS_EOM): New macro. (fhandler_dev_floppy::is_eom): Remove. (fhandler_dev_floppy::is_eof): Remove. (fhandler_dev_floppy::fhandler_dev_floppy): Initialize status flags. (fhandler_dev_floppy::get_drive_info): Only call EX functions on systems supporting them and stop suffering strange delays. (fhandler_dev_floppy::read_file): Move here, drop setting current_position. (fhandler_dev_floppy::write_file): Move here, drop setting current_position. (fhandler_dev_floppy::open): Rearrange comment. (fhandler_dev_floppy::dup): New method. (fhandler_dev_floppy::get_current_position): New inline method. Use instead of former current_position were appropriate. (fhandler_dev_floppy::raw_read): Move here. Drop EOF handling. (fhandler_dev_floppy::raw_write): Move here. Drop EOF handling. (fhandler_dev_floppy::lseek): Remove useless conditions. Convert sector_aligned_offset to LARGE_INTEGER to improve SetFilePointer call. (fhandler_dev_floppy::ioctl): Move blocksize check in RDSETBLK case to here. * fhandler_raw.cc (fhandler_dev_raw::is_eom): Remove. (fhandler_dev_raw::is_eof): Remove. (fhandler_dev_raw::write_file): Remove. (fhandler_dev_raw::read_file): Remove. (fhandler_dev_raw::raw_read): Remove. (fhandler_dev_raw::raw_write): Remove. (fhandler_dev_raw::dup): Drop copying removed members. (fhandler_dev_raw::ioctl): Drop blocksize testing. * wincap.h: Implement has_disk_ex_ioctls throughout. * wincap.cc: Ditto. (wincap_vista): Preliminary wincaps for Windows Vista/Longhorn. (wincapc::init): Add Vista/Longhorn handling.
200 lines
4.1 KiB
C++
200 lines
4.1 KiB
C++
/* fhandler_raw.cc. See fhandler.h for a description of the fhandler classes.
|
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 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 <unistd.h>
|
|
|
|
#include <cygwin/rdevio.h>
|
|
#include <sys/mtio.h>
|
|
#include <ntdef.h>
|
|
#include "cygerrno.h"
|
|
#include "perprocess.h"
|
|
#include "security.h"
|
|
#include "path.h"
|
|
#include "fhandler.h"
|
|
#include "dtable.h"
|
|
#include "cygheap.h"
|
|
#include "ntdll.h"
|
|
|
|
/**********************************************************************/
|
|
/* fhandler_dev_raw */
|
|
|
|
fhandler_dev_raw::fhandler_dev_raw ()
|
|
: fhandler_base (), status ()
|
|
{
|
|
need_fork_fixup (true);
|
|
}
|
|
|
|
fhandler_dev_raw::~fhandler_dev_raw ()
|
|
{
|
|
if (devbufsiz > 1L)
|
|
delete [] devbuf;
|
|
}
|
|
|
|
int __stdcall
|
|
fhandler_dev_raw::fstat (struct __stat64 *buf)
|
|
{
|
|
debug_printf ("here");
|
|
|
|
fhandler_base::fstat (buf);
|
|
if (is_auto_device ())
|
|
{
|
|
if (get_major () == DEV_TAPE_MAJOR)
|
|
buf->st_mode = S_IFCHR | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
|
else
|
|
buf->st_mode = S_IFBLK | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
|
|
|
buf->st_uid = geteuid32 ();
|
|
buf->st_gid = getegid32 ();
|
|
buf->st_nlink = 1;
|
|
buf->st_blksize = S_BLKSIZE;
|
|
time_as_timestruc_t (&buf->st_ctim);
|
|
buf->st_atim = buf->st_mtim = buf->st_ctim;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
fhandler_dev_raw::open (int flags, mode_t)
|
|
{
|
|
if (!wincap.has_raw_devices ())
|
|
{
|
|
set_errno (ENOENT);
|
|
debug_printf ("%s is accessible under NT/W2K only", get_win32_name ());
|
|
return 0;
|
|
}
|
|
|
|
/* Check for illegal flags. */
|
|
if (get_major () != DEV_TAPE_MAJOR && (flags & (O_APPEND | O_EXCL)))
|
|
{
|
|
set_errno (EINVAL);
|
|
return 0;
|
|
}
|
|
|
|
/* Always open a raw device existing and binary. */
|
|
flags &= ~(O_CREAT | O_TRUNC);
|
|
flags |= O_BINARY;
|
|
|
|
/* Write-only doesn't work well with raw devices */
|
|
if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_WRONLY)
|
|
flags = ((flags & ~O_WRONLY) | O_RDWR);
|
|
|
|
int res = fhandler_base::open (flags, 0);
|
|
if (res && devbufsiz > 1L)
|
|
devbuf = new char [devbufsiz];
|
|
|
|
return res;
|
|
}
|
|
|
|
int
|
|
fhandler_dev_raw::dup (fhandler_base *child)
|
|
{
|
|
int ret = fhandler_base::dup (child);
|
|
|
|
if (!ret)
|
|
{
|
|
fhandler_dev_raw *fhc = (fhandler_dev_raw *) child;
|
|
|
|
fhc->devbufsiz = devbufsiz;
|
|
if (devbufsiz > 1L)
|
|
fhc->devbuf = new char [devbufsiz];
|
|
fhc->devbufstart = 0;
|
|
fhc->devbufend = 0;
|
|
fhc->lastblk_to_read (false);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void
|
|
fhandler_dev_raw::fixup_after_fork (HANDLE)
|
|
{
|
|
devbufstart = 0;
|
|
devbufend = 0;
|
|
lastblk_to_read (false);
|
|
}
|
|
|
|
void
|
|
fhandler_dev_raw::fixup_after_exec ()
|
|
{
|
|
if (devbufsiz > 1L)
|
|
devbuf = new char [devbufsiz];
|
|
devbufstart = 0;
|
|
devbufend = 0;
|
|
lastblk_to_read (false);
|
|
}
|
|
|
|
int
|
|
fhandler_dev_raw::ioctl (unsigned int cmd, void *buf)
|
|
{
|
|
int ret = NO_ERROR;
|
|
|
|
if (cmd == RDIOCDOP)
|
|
{
|
|
struct rdop *op = (struct rdop *) buf;
|
|
|
|
if (!op)
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
else
|
|
switch (op->rd_op)
|
|
{
|
|
case RDSETBLK:
|
|
if (get_major () == DEV_TAPE_MAJOR)
|
|
{
|
|
struct mtop mop;
|
|
|
|
mop.mt_op = MTSETBLK;
|
|
mop.mt_count = op->rd_parm;
|
|
ret = ioctl (MTIOCTOP, &mop);
|
|
}
|
|
else if (devbuf && op->rd_parm < devbufend - devbufstart)
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
else if (!devbuf || op->rd_parm != devbufsiz)
|
|
{
|
|
char *buf = new char [op->rd_parm];
|
|
if (devbufsiz > 1L)
|
|
{
|
|
memcpy (buf, devbuf + devbufstart, devbufend - devbufstart);
|
|
devbufend -= devbufstart;
|
|
delete [] devbuf;
|
|
}
|
|
else
|
|
devbufend = 0;
|
|
|
|
devbufstart = 0;
|
|
devbuf = buf;
|
|
devbufsiz = op->rd_parm;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else if (cmd == RDIOCGET)
|
|
{
|
|
struct rdget *get = (struct rdget *) buf;
|
|
|
|
if (!get)
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
else
|
|
get->bufsiz = devbufsiz ? devbufsiz : 1L;
|
|
}
|
|
else
|
|
return fhandler_base::ioctl (cmd, buf);
|
|
|
|
if (ret != NO_ERROR)
|
|
{
|
|
SetLastError (ret);
|
|
__seterrno ();
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|