XINU
Functions
rflwrite.c File Reference
#include <xinu.h>
Include dependency graph for rflwrite.c:

Go to the source code of this file.

Functions

devcall rflwrite (struct dentry *devptr, char *buff, int32 count)
 

Function Documentation

◆ rflwrite()

devcall rflwrite ( struct dentry devptr,
char *  buff,
int32  count 
)

Definition at line 9 of file rflwrite.c.

References dentry::dvminor, htonl, htons, kprintf(), memset(), ntohl, ntohs, NULLCH, Rf_data, rf_msg_wreq::rf_data, RF_DATALEN, RF_FREE, rf_msg_wreq::rf_len, RF_MODE_W, RF_MSG_WREQ, rfdata::rf_mutex, RF_NAMLEN, rf_msg_wreq::rf_pos, rfltab, rflcblk::rfmode, rflcblk::rfname, rflcblk::rfpos, rfscomm(), rflcblk::rfstate, signal(), SYSERR, TIMEOUT, and wait().

Referenced by rflputc().

14 {
15  struct rflcblk *rfptr; /* Pointer to control block */
16  int32 retval; /* Return value */
17  struct rf_msg_wreq msg; /* Request message to send */
18  struct rf_msg_wres resp; /* Buffer for response */
19  char *from, *to; /* Used to copy name */
20  int i; /* Counts bytes copied into req */
21  int32 len; /* Length of name */
22 
23  /* Wait for exclusive access */
24 
26 
27  /* Verify count is legitimate */
28 
29  if ( (count <= 0) || (count > RF_DATALEN) ) {
31  return SYSERR;
32  }
33 
34  /* Verify pseudo-device is in use and mode allows writing */
35 
36  rfptr = &rfltab[devptr->dvminor];
37  if ( (rfptr->rfstate == RF_FREE) ||
38  ! (rfptr->rfmode & RF_MODE_W) ) {
40  return SYSERR;
41  }
42 
43  /* Form write request */
44 
45  msg.rf_type = htons(RF_MSG_WREQ);
46  msg.rf_status = htons(0);
47  msg.rf_seq = 0; /* Rfscomm will set sequence */
48  from = rfptr->rfname;
49  to = msg.rf_name;
50  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zero bytes */
51  len = 0;
52  while ( (*to++ = *from++) ) { /* Copy name to request */
53  if (++len >= RF_NAMLEN) {
55  return SYSERR;
56  }
57  }
58  while ( (*to++ = *from++) ) { /* Copy name into request */
59  ;
60  }
61  msg.rf_pos = htonl(rfptr->rfpos);/* Set file position */
62  msg.rf_len = htonl(count); /* Set count of bytes to write */
63  for (i=0; i<count; i++) { /* Copy data into message */
64  msg.rf_data[i] = *buff++;
65  }
66  while (i < RF_DATALEN) {
67  msg.rf_data[i++] = NULLCH;
68  }
69 
70  /* Send message and receive response */
71 
72  retval = rfscomm((struct rf_msg_hdr *)&msg,
73  sizeof(struct rf_msg_wreq),
74  (struct rf_msg_hdr *)&resp,
75  sizeof(struct rf_msg_wres) );
76 
77  /* Check response */
78 
79  if (retval == SYSERR) {
81  return SYSERR;
82  } else if (retval == TIMEOUT) {
83  kprintf("Timeout during remote file read\n");
85  return SYSERR;
86  } else if (ntohs(resp.rf_status) != 0) {
88  return SYSERR;
89  }
90 
91  /* Report results to caller */
92 
93  rfptr->rfpos += ntohl(resp.rf_len);
94 
96  return ntohl(resp.rf_len);
97 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 dvminor
Definition: conf.h:8
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RF_MODE_W
Definition: rfilesys.h:12
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
#define RF_DATALEN
Definition: rfilesys.h:10
uint32 rfmode
Definition: rfilesys.h:54
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
char rfname[RF_NAMLEN]
Definition: rfilesys.h:52
#define RF_MSG_WREQ
Definition: rfilesys.h:86
#define RF_NAMLEN
Definition: rfilesys.h:9
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 rfpos
Definition: rfilesys.h:53
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:
Here is the caller graph for this function: