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

Go to the source code of this file.

Functions

devcall rdsopen (struct dentry *devptr, char *diskid, char *mode)
 

Function Documentation

◆ rdsopen()

devcall rdsopen ( struct dentry devptr,
char *  diskid,
char *  mode 
)

Definition at line 10 of file rdsopen.c.

References dentry::dvminor, dentry::dvnum, htons, kprintf(), memset(), ntohs, NULLCH, RD_FREE, rdscblk::rd_id, RD_IDLEN, RD_MSG_OREQ, RD_OPEN, RD_PEND, rdscblk::rd_state, rdscomm(), rdstab, SYSERR, and TIMEOUT.

15 {
16  struct rdscblk *rdptr; /* Ptr to control block entry */
17  struct rd_msg_oreq msg; /* Message to be sent */
18  struct rd_msg_ores resp; /* Buffer to hold response */
19  int32 retval; /* Return value from rdscomm */
20  int32 len; /* Counts chars in diskid */
21  char *idto; /* Ptr to ID string copy */
22  char *idfrom; /* Pointer into ID string */
23 
24  rdptr = &rdstab[devptr->dvminor];
25 
26  /* Reject if device is already open */
27 
28  if (rdptr->rd_state != RD_FREE) {
29  return SYSERR;
30  }
31  rdptr->rd_state = RD_PEND;
32 
33  /* Copy disk ID into free table slot */
34 
35  idto = rdptr->rd_id;
36  idfrom = diskid;
37  len = 0;
38  while ( (*idto++ = *idfrom++) != NULLCH) {
39  len++;
40  if (len >= RD_IDLEN) { /* ID string is too long */
41  return SYSERR;
42  }
43  }
44 
45  /* Verify that name is non-null */
46 
47  if (len == 0) {
48  return SYSERR;
49  }
50 
51  /* Hand-craft an open request message to be sent to the server */
52 
53  msg.rd_type = htons(RD_MSG_OREQ);/* Request an open */
54  msg.rd_status = htons(0);
55  msg.rd_seq = 0; /* Rdscomm fills in an entry */
56  idto = msg.rd_id;
57  memset(idto, NULLCH, RD_IDLEN);/* initialize ID to zero bytes */
58 
59  idfrom = diskid;
60  while ( (*idto++ = *idfrom++) != NULLCH ) { /* Copy ID to req. */
61  ;
62  }
63 
64  /* Send message and receive response */
65 
66  retval = rdscomm((struct rd_msg_hdr *)&msg,
67  sizeof(struct rd_msg_oreq),
68  (struct rd_msg_hdr *)&resp,
69  sizeof(struct rd_msg_ores),
70  rdptr );
71 
72  /* Check response */
73 
74  if (retval == SYSERR) {
75  rdptr->rd_state = RD_FREE;
76  return SYSERR;
77  } else if (retval == TIMEOUT) {
78  kprintf("Timeout during remote file open\n\r");
79  rdptr->rd_state = RD_FREE;
80  return SYSERR;
81  } else if (ntohs(resp.rd_status) != 0) {
82  rdptr->rd_state = RD_FREE;
83  return SYSERR;
84  }
85 
86  /* Change state of device to indicate currently open */
87 
88  rdptr->rd_state = RD_OPEN;
89 
90  /* Return device descriptor */
91 
92  return devptr->dvnum;
93 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RD_OPEN
Definition: rdisksys.h:37
#define RD_FREE
Definition: rdisksys.h:36
#define RD_PEND
Definition: rdisksys.h:38
int32 dvminor
Definition: conf.h:8
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RD_IDLEN
Definition: rdisksys.h:29
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 dvnum
Definition: conf.h:7
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
#define RD_MSG_OREQ
Definition: rdisksys.h:126
status rdscomm(struct rd_msg_hdr *, int32, struct rd_msg_hdr *, int32, struct rdscblk *)
Definition: rdscomm.c:11
int32 rd_state
Definition: rdisksys.h:69
char rd_id[RD_IDLEN]
Definition: rdisksys.h:70
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function: