where appropriate. * globals.cc: New file for generic global variables. * mkglobals_h: New file to generate globals.h. * mkstatic: New Script used to build a (currently non-working) static libcygwin_s.a. * Makefile.in: Add unused rule to build a non-working libcygwin_s.a. (DLL_OFILES): Add globals.o. Make all objects rely on globals.h. (globals.h): New target. Generate globals.h. * cygtls.h: Honor new CYGTLS_HANDLE define to control when the HANDLE operator is allowed in _cygtls. * dcrt0.cc: Move most globals to globals.cc. * init.cc: Ditto. * environ.cc (strip_title_path): Remove now-unneeded extern. * fhandler_serial.cc (fhandler_serial::open): Ditto. * pinfo.cc: Ditto. (commune_process): Ditto. * shared.cc: Ditto. * glob.cc: Ditto. * strace.cc: Ditto. * exceptions.cc: Define CYGTLS_HANDLE before including winsup.h. * path.cc (stat_suffixes): Move here. * security.h: Add forward class path_conv declaration. * smallprint.cc (__small_vsprintf): Make a true c++ function. (__small_sprintf): Ditto. (small_printf): Ditto. (console_printf): Ditto. (__small_vswprintf): Ditto. (__small_swprintf): Ditto. * spawn.cc (spawn_guts): Remove _stdcall decoration in favor of regparm. (hExeced): Move to globals.cc * strfuncs.cc (current_codepage): Ditto. (active_codepage): Ditto. * sync.cc (lock_process::locker): Move here from dcrt0.cc. * syscalls.cc (stat_suffixes): Move to path.cc. * tty.cc (tty::create_master): Uncapitalize fatal warning for consistency. * winsup.h: Include globals.h to declare most of the grab bag list of globals which were previously defined here. * mount.h: Move USER_* defines back to shared_info.h. * speclib: Force temporary directory cleanup.
		
			
				
	
	
		
			202 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			202 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/* fhandler_raw.cc.  See fhandler.h for a description of the fhandler classes.
 | 
						|
 | 
						|
   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
 | 
						|
   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 <cygwin/rdevio.h>
 | 
						|
#include <sys/mtio.h>
 | 
						|
#include "cygerrno.h"
 | 
						|
#include "path.h"
 | 
						|
#include "fhandler.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 = PREFERRED_IO_BLKSIZE;
 | 
						|
      time_as_timestruc_t (&buf->st_ctim);
 | 
						|
      buf->st_atim = buf->st_mtim = buf->st_birthtim = buf->st_ctim;
 | 
						|
    }
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 | 
						|
int
 | 
						|
fhandler_dev_raw::open (int flags, mode_t)
 | 
						|
{
 | 
						|
  /* 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_ACCMODE) == 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 (!close_on_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 <= 1 && (devbufend - devbufstart))
 | 
						|
				 || op->rd_parm < devbufend - devbufstart))
 | 
						|
		     || (op->rd_parm > 1 && (op->rd_parm % 512))
 | 
						|
		     || (get_flags () & O_DIRECT))
 | 
						|
	      /* The conditions for a *valid* parameter are these:
 | 
						|
	         - If there's still data in the current buffer, it must
 | 
						|
		   fit in the new buffer.
 | 
						|
		 - The new size is either 0 or 1, both indicating unbufferd
 | 
						|
		   I/O, or the new buffersize must be a multiple of 512.
 | 
						|
		 - In the O_DIRECT case, the whole request is invalid. */
 | 
						|
	      ret = ERROR_INVALID_PARAMETER;
 | 
						|
	    else if (!devbuf || op->rd_parm != devbufsiz)
 | 
						|
	      {
 | 
						|
		char *buf = NULL;
 | 
						|
		if (op->rd_parm > 1L)
 | 
						|
		  buf = new char [op->rd_parm];
 | 
						|
		if (buf && devbufsiz > 1L)
 | 
						|
		  {
 | 
						|
		    memcpy (buf, devbuf + devbufstart, devbufend - devbufstart);
 | 
						|
		    devbufend -= devbufstart;
 | 
						|
		  }
 | 
						|
		else
 | 
						|
		  devbufend = 0;
 | 
						|
 | 
						|
		if (devbufsiz > 1L)
 | 
						|
		  delete [] devbuf;
 | 
						|
 | 
						|
		devbufstart = 0;
 | 
						|
		devbuf = buf;
 | 
						|
		devbufsiz = op->rd_parm ?: 1L;
 | 
						|
	      }
 | 
						|
	    break;
 | 
						|
	  default:
 | 
						|
	    break;
 | 
						|
	  }
 | 
						|
    }
 | 
						|
  else if (cmd == RDIOCGET)
 | 
						|
    {
 | 
						|
      struct rdget *get = (struct rdget *) buf;
 | 
						|
 | 
						|
      if (!get)
 | 
						|
	ret = ERROR_INVALID_PARAMETER;
 | 
						|
      else
 | 
						|
	get->bufsiz = devbufsiz;
 | 
						|
    }
 | 
						|
  else
 | 
						|
    return fhandler_base::ioctl (cmd, buf);
 | 
						|
 | 
						|
  if (ret != NO_ERROR)
 | 
						|
    {
 | 
						|
      SetLastError (ret);
 | 
						|
      __seterrno ();
 | 
						|
      return -1;
 | 
						|
    }
 | 
						|
  return 0;
 | 
						|
}
 |