Ejemplo n.º 1
0
#define ATAPI_STAT_BSY	   0x80
#define ATAPI_STAT_DRDY    0x40
#define ATAPI_STAT_DMARDDF 0x20
#define ATAPI_STAT_SERVDSC 0x10
#define ATAPI_STAT_DRQ     0x08
#define ATAPI_STAT_CORR    0x04
#define ATAPI_STAT_CHECK   0x01

#define ATAPI_INTREASON_COMMAND 0x01
#define ATAPI_INTREASON_IO      0x02
#define ATAPI_INTREASON_RELEASE 0x04

#define ATAPI_REG_DATA		0
#define ATAPI_REG_FEATURES	1
#define ATAPI_REG_INTREASON	2
#define ATAPI_REG_SAMTAG	3
#define ATAPI_REG_COUNTLOW	4
#define ATAPI_REG_COUNTHIGH	5
#define ATAPI_REG_DRIVESEL	6
#define ATAPI_REG_CMDSTATUS	7
#define ATAPI_REG_ERROR		16	// read-only ERROR (write is FEATURES)

#define ATAPI_REG_MAX 24
Ejemplo n.º 2
0
//---------------------------------------------------------------------
// put a local file --> remote 
bool Server::cmdPut(bstring const & localName, bstring const & remotePath, bool exists)
{
	DBGPRINT(("put '%s' '%s' %b\r\n", localName.c_str(), remotePath.c_str(), exists));
	bstring cmd = bstring(exists ? TEXT("reput \"") : TEXT("put \"")) + localName + TEXT("\" \"") + remotePath + TEXT("\"");

	if (!doCommand(cmd))
		return false;

	FILETIME ft;
	HANDLE hFile = CreateFile(localName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile == (HANDLE)HFILE_ERROR)
		return true; // copy succeeded

	GetFileTime(hFile, 0, 0, &ft);
	long fsHigh = 0;
	long fsLow = SetFilePointer(hFile, 0, &fsHigh, FILE_END);

	CloseHandle(hFile);

	bstring chmod = TEXT("----");
	if (defChMod.length() > 0 || exeChMod.length() > 0) {
		chmod = defChMod;
		size_t ldot = remotePath.find_last_of('.');
		if (ldot != (size_t)-1) {
			bstring x = remotePath.substr(ldot);
			std::map<bstring, bstring>::iterator i = exeExtensions.find(x);
			if (i != exeExtensions.end())
				chmod = exeChMod;
		}
		if (chmod.length() > 0) {
			cmd = bstring(TEXT("chmod ")) + chmod + TEXT(" \"") + remotePath + TEXT("\"");
			doCommand(cmd);
		}
	}

	// fake update the directory
	insertFile(remotePath, &ft, fsLow, fsHigh, '-', chmod);

	// we cannot set the file time
	if (disableMtime)
		return true;

	// if setting the mtime failes, do not try it again
	if (!this->cmdMtime(remotePath, &ft))
		disableMtime = true;

	// put already succeeded.
	return true;
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------
// execute a SFTP command
bool Server::doCommand(bstring const & command, bstring & response) {
	Guard guard(this);
	if (!guard.isConnected()) return false;

	gLogProc(gPluginNumber, MSGTYPE_DETAILS, command.c_str());

	bchar buffer[8192];
	*buffer = 0;
	int r = guard.mapper->doSftp(command.c_str(), buffer);

	if (*buffer) {
		response = buffer;
		gLogProc(gPluginNumber, MSGTYPE_OPERATIONCOMPLETE, buffer);
	}
	return 0 != r;
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------
// add a file to the dir content - if not already there
void Server::insertFile(bstring const & remotePath, FILETIME * ft, unsigned long szLo, unsigned long szHi, char kind, bstring const & chmod) {
	bstring path, file;
	file = splitPath(path, remotePath);
	DirCache::iterator i = dirCache.find(path);
	if (i == dirCache.end())
		return;

	my_fxp_names * dir = i->second;	

	int count = dir->nnames;
	for (int i = 0; i < count; ++i) {
		fxp_name * fn = dir->names[i];
		if (file == fn->filename) {
			// already there
			return;
		}
	}
	// create a new structure and fill it
	my_fxp_names * ndir = (my_fxp_names *) malloc(sizeof(my_fxp_names));
	ndir->names = (fxp_name **)malloc(sizeof(fxp_name*) * (count + 1));
	
	fxp_name * n = ndir->names[0] = (fxp_name *)malloc(sizeof(fxp_name));
	RtlZeroMemory(n, sizeof(fxp_name));

	FILETIME ft2;
	SYSTEMTIME st;
	if (ft) {
		FileTimeToSystemTime(ft, &st);
	} else {
		GetSystemTime(&st);
		SystemTimeToFileTime(&st, &ft2);
		ft = &ft2;
	}

	char buffer[32];
	sprintf(buffer, "%d ", szLo);
#ifdef UNICODE
	char * chmod2;
	BCONVERT(char, 32, chmod2, chmod.c_str());
	char * file2;
	BCONVERT(char, 256, file2, file.c_str());
	std::string ln = kind + chmod2 + std::string(" 1 ? ? ") + buffer + " Jan  1 1990 " + file2; 
#else
	std::string ln = kind + chmod + std::string(" 1 ? ? ") + buffer + " Jan  1 1990 " + file; 
#endif
	n->longname = strdup(ln.c_str());
	n->filename = bstrdup(file.c_str());

	n->attrs.size.hi = szHi;
	n->attrs.size.lo = szLo;	
	n->attrs.mtime = FileTimeToUnixTime(ft);

	for (int i = 0; i < count; ++i) {
		ndir->names[i + 1] = dir->names[i];
	}
	ndir->nnames = count + 1;
	
	i->second = ndir;
}
Ejemplo n.º 5
0
//---------------------------------------------------------------------
// get a remote file -> local
bool Server::cmdGet(bstring const & remotePath, bstring const & localName, bool exists)
{
	DBGPRINT(("get '%s' '%s' %b\r\n", remotePath.c_str(), localName.c_str(), exists));
	bstring cmd = bstring(exists ? TEXT("reget \"") : TEXT("get \"")) + remotePath + TEXT("\" \"") + localName + TEXT("\"");

	if (!doCommand(cmd))
		return false;

	FILETIME ft;
	fxp_attrs * attr = currentMapper->getLastAttr();
	if (UnixTimeToFileTime(attr->mtime, &ft)) {
		HANDLE hf = CreateFile(localName.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
		SetFileTime(hf, &ft, &ft, &ft);
		CloseHandle(hf);
	}
	return true;
}
Ejemplo n.º 6
0
//---------------------------------------------------------------------
// update the file attributes
void Server::updateFileAttr(bstring const & path, bstring const & file, bstring const & attrs)
{
	DirCache::iterator i = dirCache.find(path);
	if (i == dirCache.end())
		return;

	my_fxp_names * dir = i->second;	
	int count = dir->nnames;
	for (int i = 0; i < count; ++i) {
		fxp_name * fn = dir->names[i];
		if (file == fn->filename) {
			// got it
			fn->attrs.permissions = bstrtol(attrs.c_str(), '\0', 8);
			return;
		}
	}
}
Ejemplo n.º 7
0
bool Creature::hasCharm(bstring charmed) {
    etag    *cp=0;

    if(charmed == "")
        return(false);

    Player* player = getAsPlayer();

    if(!player)
        return(false);

    cp = player->first_charm;

    while(cp) {
        if(!strcmp(cp->enemy, charmed.c_str()))
            return(true);
        cp = cp->next_tag;
    }

    return(false);
}
Ejemplo n.º 8
0
				atapi_xfermod = 0;
			}

//          printf( "atapi_r: atapi_xferlen=%d\n", atapi_xferlen );
			if( atapi_xferlen != 0 )
			{
				atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
				gdrom_alt_status = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
				atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
			}
			else
			{
				//mame_printf_debug("ATAPI: dropping DRQ\n");
				atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
				gdrom_alt_status = 0;
				atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
			}

			atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
			atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;

			gdrom_raise_irq(machine);
		}

		if( atapi_data_ptr < atapi_data_len )
		{
			data = atapi_data[atapi_data_ptr++];
			data |= ( atapi_data[atapi_data_ptr++] << 8 );
			if( atapi_data_ptr >= atapi_data_len )
			{
//              printf( "atapi_r: read all bytes\n" );
				atapi_data_ptr = 0;
				atapi_data_len = 0;

				if( atapi_xferlen == 0 )
				{
					atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
					gdrom_alt_status = 0;
					atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
					gdrom_raise_irq(machine);
				}
			}
		}
		else
		{
			data = 0;
		}
	}
	else
	{
		reg = offset;

		// get read-only side of read-only/write-only registers from elsewhere
		if (reg == ATAPI_REG_FEATURES)
		{
			reg = ATAPI_REG_ERROR;
		}
		data = atapi_regs[reg];

		#if 0
		switch( reg )
		{
		case ATAPI_REG_DATA:
			printf( "atapi_r: data=%02x\n", data );
			break;
		case ATAPI_REG_ERROR:
			printf( "atapi_r: error=%02x\n", data );
			break;
		case ATAPI_REG_INTREASON:
			printf( "atapi_r: intreason=%02x\n", data );
			break;
		case ATAPI_REG_SAMTAG:
			printf( "atapi_r: samtag=%02x\n", data );
			break;
		case ATAPI_REG_COUNTLOW:
			printf( "atapi_r: countlow=%02x\n", data );
			break;
		case ATAPI_REG_COUNTHIGH:
			printf( "atapi_r: counthigh=%02x\n", data );
			break;
		case ATAPI_REG_DRIVESEL:
			printf( "atapi_r: drivesel=%02x\n", data );
			break;
		case ATAPI_REG_CMDSTATUS:
			printf( "atapi_r: cmdstatus=%02x\n", data );
			break;
		}
		#endif

		mame_printf_debug("ATAPI: read reg %d = %x (PC=%x)\n", reg, data, space.device().safe_pc());
	}

//  printf( "atapi_r( %08x, %08x ) %08x\n", offset, mem_mask, data );
	return data;
}

static WRITE32_HANDLER( atapi_w )
{
	running_machine &machine = space.machine();
	int reg;

//  printf( "atapi_w( %08x, %08x, %08x )\n", offset, mem_mask, data );

	if (mem_mask == 0x0000ffff)	// word-wide command write
	{
//      printf("atapi_w: data=%04x\n", data );

//      printf("ATAPI: packet write %04x\n", data);
		atapi_data[atapi_data_ptr++] = data & 0xff;
		atapi_data[atapi_data_ptr++] = data >> 8;

		if (atapi_cdata_wait)
		{
//                  printf("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait);
			if (atapi_data_ptr == atapi_cdata_wait)
			{
				// send it to the device
				gdrom->WriteData( atapi_data, atapi_cdata_wait );

				// assert IRQ
				gdrom_raise_irq(machine);

				// not sure here, but clear DRQ at least?
				atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
			}
		}

		else if ( atapi_data_ptr == 12 )
		{
			int phase;

//          printf("atapi_w: command %02x\n", atapi_data[0]&0xff );

			// reset data pointer for reading SCSI results
			atapi_data_ptr = 0;
			atapi_data_len = 0;

			// send it to the SCSI device
			gdrom->SetCommand( atapi_data, 12 );
			gdrom->ExecCommand( &atapi_xferlen );
			gdrom->GetPhase( &phase );

			if (atapi_xferlen != -1)
			{
				printf("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen);

				// store the returned command length in the ATAPI regs, splitting into
Ejemplo n.º 9
0
//---------------------------------------------------------------------
// update the file attributes
void Server::updateFileAttr(bstring const & path, bstring const & file, bstring const & attrs) {
  DirCache::iterator i = dirCache.find(path);
  if (i == dirCache.end())
    return;

  my_fxp_names * dir = i->second;
  int count = dir->nnames;
  for (int i = 0; i < count; ++i) {
    fxp_name * fn = dir->names[i];
#ifdef UNICODE
    if (file == fn->ucFilename) {
#else
    if (file == fn->filename) {
#endif
      // got it
      fn->attrs.permissions = bstrtol(attrs.c_str(), '\0', 8);
      return;
    }
  }
}

//---------------------------------------------------------------------
// CT
// init with zeros
Server::Server(bstring const & serverName) :
  name(serverName), currentMapper(0), disableMtime(false), myCfg(0) {
}

//---------------------------------------------------------------------
// free one fxp_name
static void freeFn(fxp_name * fn) {
  if (!fn)
    return;

  free(fn->filename);
  free(fn->longname);
  free(fn);
}

//---------------------------------------------------------------------
// free all fxp_names + my_fxp_names
static void freeMfn(my_fxp_names * dir) {
  if (!dir)
    return;

  for (int i = 0; i < dir->nnames; i++) {
    freeFn(dir->names[i]);
  }
  free(dir);
}

//---------------------------------------------------------------------
// DT
// free all cached structures
Server::~Server() {
  if (currentMapper && currentMapper->hDll && !currentMapper->disconnected()) {
    currentMapper->disconnect();
  }
  delete currentMapper;

  clearDirCache();

  delete myCfg;
}

bool Server::connect() {
  //	Guard guard(this);
  //	return guard.isConnected();
  return true;
}

//---------------------------------------------------------------------
// clear the folder chache
void Server::clearDirCache() {
  for (DirCache::iterator i = dirCache.begin(); i != dirCache.end(); ++i) {
    my_fxp_names * dir = i->second;
    freeMfn(dir);
  }
  dirCache.clear();
}

//---------------------------------------------------------------------
// performs a server lookup by evaluating the remote path
// on success the remote path is also set
Server * Server::findServer(bstring & remotePath, bchar const * const fullPath) {
  bstring serverName = *fullPath == TEXT('\\') ? fullPath + 1 : fullPath;
  int slash = (int) serverName.find_first_of(TEXT('\\'));
  if (slash > 0) {
    remotePath = serverName.substr(slash);
    for (bstring::iterator i = remotePath.begin(); i != remotePath.end(); ++i) {
      if (*i == TEXT('\\'))
        *i = '/';
    }
    serverName = serverName.substr(0, slash);
  } else {
    remotePath = TEXT("/");
  }

  ServerMap::const_iterator i = serverMap.find(serverName);
  Server * server;
  if (i != serverMap.end()) {
    server = i->second;
  } else {
    server = new Server(serverName);
    serverMap.insert(std::make_pair(serverName, server));
  }

  return server;
}