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

Go to the source code of this file.

Functions

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

Function Documentation

◆ rflread()

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

Definition at line 9 of file rflread.c.

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

Referenced by rflgetc().

14 {
15  struct rflcblk *rfptr; /* Pointer to control block */
16  int32 retval; /* Return value */
17  struct rf_msg_rreq msg; /* Request message to send */
18  struct rf_msg_rres resp; /* Buffer for response */
19  int32 i; /* Counts bytes copied */
20  char *from, *to; /* Used during name copy */
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 */
35 
36  rfptr = &rfltab[devptr->dvminor];
37 
38  /* If device not currently in use, report an error */
39 
40  if (rfptr->rfstate == RF_FREE) {
42  return SYSERR;
43  }
44 
45  /* Verify pseudo-device allows reading */
46 
47  if ((rfptr->rfmode & RF_MODE_R) == 0) {
49  return SYSERR;
50  }
51 
52  /* Form read request */
53 
54  msg.rf_type = htons(RF_MSG_RREQ);
55  msg.rf_status = htons(0);
56  msg.rf_seq = 0; /* Rfscomm will set sequence */
57  from = rfptr->rfname;
58  to = msg.rf_name;
59  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zero bytes */
60  len = 0;
61  while ( (*to++ = *from++) ) { /* Copy name to request */
62  if (++len >= RF_NAMLEN) {
64  return SYSERR;
65  }
66  }
67  msg.rf_pos = htonl(rfptr->rfpos);/* Set file position */
68  msg.rf_len = htonl(count); /* Set count of bytes to read */
69 
70  /* Send message and receive response */
71 
72  retval = rfscomm((struct rf_msg_hdr *)&msg,
73  sizeof(struct rf_msg_rreq),
74  (struct rf_msg_hdr *)&resp,
75  sizeof(struct rf_msg_rres) );
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  /* Copy data to application buffer and update file position */
92 
93  for (i=0; i<ntohl(resp.rf_len); i++) {
94  *buff++ = resp.rf_data[i];
95  }
96  rfptr->rfpos += ntohl(resp.rf_len);
97 
99  return ntohl(resp.rf_len);
100 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RF_MODE_R
Definition: rfilesys.h:11
int32 dvminor
Definition: conf.h:8
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
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_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
#define RF_MSG_RREQ
Definition: rfilesys.h:83
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: