📄 rpcserv.c
字号:
/*volume not on line error (was Ejected)*/
case nsDrvErr: tcs_err = TCS_ENODEV; break;
/*no such drive (tried to mount a bad drive num)*/
case volGoneErr: tcs_err = TCS_ENODEV; break;
/*Server volume has been disconnected.*/
case fsDataTooBigErr: tcs_err = TCS_EFBIG; break;
/*file or volume is too big for system*/
case ioErr: tcs_err = TCS_EEIO; break;
/*I/O error (bummers)*/
case controlErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case statusErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case readErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case writErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case badUnitErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case unitEmptyErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case openErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case closErr: tcs_err = TCS_EEIO; break;
/*I/O System Errors*/
case abortErr: tcs_err = TCS_EEIO; break;
/*IO call aborted by KillIO*/
case dsMemFullErr: tcs_err = TCS_ENOMEM; break;
/*out of memory!*/
case mFulErr: tcs_err = TCS_ENOMEM; break;
/*memory full (open) or file won't fit (load)*/
case iMemFullErr: tcs_err = TCS_ENOMEM; break;
/*memory full (open) or file won't fit (load)*/
case dsAddressErr: tcs_err = TCS_EFAULT; break;
/*address error*/
#endif
default:
if (err < 0)
/* Catch-all for any negative errors. */
tcs_err = TCS_EPERM;
else
/*If we haven't heard of the error, we return it untranslated.
At least this is non-0.*/
tcs_err = convert_tcs_long (err);
/*Undo the following convert_host_long ()---they commute.*/
break;
}
return convert_host_long (tcs_err);
}
/* -------------------------------------------- */
static Int32 convert_tcs_fcntl_cmd (int tcscmd)
{
if (tcscmd != TCS_F_BINARY) return _O_BINARY;
return 0;
}
/* -------------------------------------------- */
static Int32 convert_tcs_fcntl_flags (int tcsflags)
{
return tcsflags;
}
/*----------------------------- Errno functions ------------------------------*/
static Int32 last_io_errno (void)
{
#if defined _WIN32
return _doserrno;
#else
return errno;
#endif
}
/* -------------------------------------------- */
static Int32 last_net_errno (void)
{
#if defined _WIN32
return h_errno;
#else
return errno;
#endif
}
/* -------------------------------------------- */
static Int32 last_other_errno (void)
{
return errno;
}
/*----------------------------- Host functions -------------------------------*/
static Int32 host_open( RPCServ_NodeInfo *ninfo, String path, Int32 oflag, Int32 mode )
{
if (strcmp(path,TCS_STDIN_NAME )==0) return ninfo->Stdin;
if (strcmp(path,TCS_STDOUT_NAME)==0) return ninfo->Stdout;
if (strcmp(path,TCS_STDERR_NAME)==0) return ninfo->Stderr;
#ifdef __MWERKS__
/* Metrowerks MSL Posix.1 5.3.1.2 fix. */
if (oflag & O_APPEND)
{
Int32 fd = open( path, oflag);
int i;
if (fd > 0)
{
for (i = 0; i < FOPEN_MAX; i++)
{
if (!mac_fd[i])
{
number_mac_files++;
mac_fd[i] = fd;
break;
}
}
}
return fd;
}
else
return open( path, oflag);
#else
return parm_open( path, oflag, mode );
#endif
}
/* -------------------------------------------- */
static Int32 host_close( RPCServ_NodeInfo *ninfo, UInt32 fildes )
{
if (fildes == ninfo->Stdin ) return 0;
if (fildes == ninfo->Stdout) return 0;
if (fildes == ninfo->Stderr) return 0;
#ifdef __MWERKS__
/* Metrowerks MSL Posix.1 5.3.1.2 fix. */
if (1)
{
int i;
for (i = 0; i < FOPEN_MAX; i++)
{
if (fildes == mac_fd[i])
{
number_mac_files--;
mac_fd[i] = 0;
break;
}
}
}
#endif
return parm_close( fildes );
}
/* -------------------------------------------- */
static void host_exit( RPCServ_NodeInfo *ninfo, Int32 status )
{
RPCServ_remove_node_info(ninfo->node_number);
parm_exit( ninfo->node_number, status );
}
/* -------------------------------------------- */
void *host_readdir(Pointer result, TCS_DIR result_buff, DIR* host_dir )
{
struct dirent *dd;
errno = 0; /*it is only possible to distinguish between successful
and unsuccesful calls if errno is clear on entry*/
dd = readdir(host_dir);
if (dd == 0) {
return Null;
} else {
Int d_namlen= strlen(dd->d_name) + 1;
if (d_namlen > TCS_MAX_NAME) {
errno= ENAMETOOLONG;
return Null;
} else {
result_buff->d_ino = convert_host_long (dd->d_ino);
result_buff->d_namlen = convert_host_long (d_namlen);
strcpy(result_buff->d_name, dd->d_name);
return result;
}
}
}
/* -------------------------------------------- */
static Int32 host_fstat( RPCServ_NodeInfo *ninfo, Int32 fildes, TCS_Stat *buf)
{
struct stat host_buf;
Int32 result = parm_fstat(fildes, &host_buf);
convert_host_stat (ninfo, buf, &host_buf);
return result;
}
/* -------------------------------------------- */
static Int32 host_stat( RPCServ_NodeInfo *ninfo, String name, TCS_Stat *buf)
{
struct stat host_buf;
Int32 result = parm_stat(name, &host_buf);
convert_host_stat (ninfo, buf, &host_buf);
return result;
}
/*--------------------------- Argument String Functions ----------------------*/
/*
* Return the length of the Null separated
* concatenation of all command line arguments:
*/
static Int32 argument_string_length( RPCServ_NodeInfo *ninfo )
{
Int32 i;
Int32 result=0;
Int32 argc= ninfo->argc;
String *argv= ninfo->argv;
for (i=0; i<argc; i++) {
result += strlen(argv[i])+1;
}
return result;
}
/*
* Construct the Null separated
* concatenation of all command line arguments
* into specified buffer:
*/
static void pass_argument_string( RPCServ_NodeInfo *ninfo, String buffer )
{
Int32 i;
Int32 argc= ninfo->argc;
String *argv= ninfo->argv;
for (i=0; i<argc; i++) {
strcpy(buffer, argv[i]);
buffer += strlen(buffer)+1;
}
}
/*-------------------------------- Server Function ---------------------------*/
/*
* Function : Serve a command, using the node specific information
* provided with RPCServ_add_node, and the I/O functions
* provided with RPCServ_init.
* Parameters : raw_command (I) Raw pointer to command, as obtained
* from target. The command still has to
* be address translated and endian
* converted.
* Function Result : True iff serving succeeded.
*/
Bool RPCServ_serve (Pointer raw_command)
{
Int32 saved;
String intermediate_result;
HostCall_command *command;
UInt32 sending_node;
RPCServ_NodeInfo *ninfo;
ninfo = RPCServ_raw_to_info (raw_command);
sending_node = ninfo->node_number;
command = (Pointer) COMMAND_BUFFER (raw_command);
switch (convert_tcs_long (command->code))
{
/* -------------------------------------------- */
case HostCall_OPEN:
command->parameters.open_args.retval=
convert_host_long (
host_open (ninfo,
IN_BUFFER (command->parameters.open_args.path),
convert_tcs_o (command->parameters.open_args.oflag),
convert_tcs_long (command->parameters.open_args.mode)));
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_OPENDLL:
command->parameters.open_args.retval=
convert_host_long (
parm_open_dll (
IN_BUFFER (command->parameters.open_dll_args.path)));
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_FSTAT:
command->parameters.fstat_args.retval=
convert_host_long (
host_fstat (
ninfo,
(Int32) convert_tcs_long (command->parameters.fstat_args.fildes),
(TCS_Stat *) RESULT_BUFFER (command->parameters.fstat_args.buf)));
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_STAT:
command->parameters.stat_args.retval=
convert_host_long (
host_stat (ninfo,
IN_BUFFER (command->parameters.stat_args.path),
(TCS_Stat *) RESULT_BUFFER (command->parameters.stat_args.buf)));
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_ISATTY:
command->parameters.isatty_args.retval=
convert_host_long (
parm_isatty (convert_tcs_long (command->parameters.isatty_args.fildes)));
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_READ:
command->parameters.read_args.retval=
convert_host_long (
parm_read (
convert_tcs_long (command->parameters.read_args.fildes),
RESULT_BUFFER (command->parameters.read_args.buf),
convert_tcs_long (command->parameters.read_args.nbyte)));
PCI_STABILISE (&command->code, &saved);
command->returned_errno = convert_host_errno (last_io_errno ());
command->notification_status = convert_host_long (HostCall_DONE);
break;
/* -------------------------------------------- */
case HostCall_WRITE:
#ifdef __MWERKS__
/* Metrowerks MSL Posix.1 5.3.1.2 fix. */
{
int i;
for (i = 0; i < FOPEN_MAX; i++)
if (convert_tcs_long (command->parameters.write_args.fildes) == mac_fd[i])
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -