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

Go to the source code of this file.

Functions

devcall rfscontrol (struct dentry *devptr, int32 func, int32 arg1, int32 arg2)
 

Function Documentation

◆ rfscontrol()

devcall rfscontrol ( struct dentry devptr,
int32  func,
int32  arg1,
int32  arg2 
)

Definition at line 9 of file rfscontrol.c.

References htons, kprintf(), memset(), ntohl, NULLCH, OK, Rf_data, RF_MSG_DREQ, RF_MSG_MREQ, RF_MSG_SREQ, RF_MSG_TREQ, RF_MSG_XREQ, rfdata::rf_mutex, RF_NAMLEN, RFS_CTL_DEL, RFS_CTL_MKDIR, RFS_CTL_RMDIR, RFS_CTL_SIZE, RFS_CTL_TRUNC, rfscomm(), rfsndmsg(), signal(), SYSERR, TIMEOUT, and wait().

15 {
16  int32 len; /* Length of name */
17  struct rf_msg_sreq msg; /* Buffer for size request */
18  struct rf_msg_sres resp; /* Buffer for size response */
19  char *to, *from; /* Used during name copy */
20  int32 retval; /* Return value */
21 
22  /* Wait for exclusive access */
23 
25 
26  /* Check length of name (copy during the check even though the */
27  /* copy is only used for a size request) */
28 
29  from = (char *)arg1;
30  to = msg.rf_name;
31  len = 0;
32  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zeroes */
33  while ( (*to++ = *from++) ) { /* Copy name to message */
34  len++;
35  if (len >= (RF_NAMLEN - 1) ) {
37  return SYSERR;
38  }
39  }
40 
41  switch (func) {
42 
43  /* Delete a file */
44 
45  case RFS_CTL_DEL:
46  if (rfsndmsg(RF_MSG_DREQ, (char *)arg1) == SYSERR) {
48  return SYSERR;
49  }
50  break;
51 
52  /* Truncate a file */
53 
54  case RFS_CTL_TRUNC:
55  if (rfsndmsg(RF_MSG_TREQ, (char *)arg1) == SYSERR) {
57  return SYSERR;
58  }
59  break;
60 
61 
62 
63  /* Make a directory */
64 
65  case RFS_CTL_MKDIR:
66  if (rfsndmsg(RF_MSG_MREQ, (char *)arg1) == SYSERR) {
68  return SYSERR;
69  }
70  break;
71 
72  /* Remove a directory */
73 
74  case RFS_CTL_RMDIR:
75  if (rfsndmsg(RF_MSG_XREQ, (char *)arg1) == SYSERR) {
77  return SYSERR;
78  }
79  break;
80 
81  /* Obtain current file size (cannot use rfsndmsg because a */
82  /* response contains a value in addition to the header) */
83 
84  case RFS_CTL_SIZE:
85 
86  /* Hand-craft a size request message */
87 
88  msg.rf_type = htons(RF_MSG_SREQ);
89  msg.rf_status = htons(0);
90  msg.rf_seq = 0; /* Rfscomm will set the seq num */
91 
92  /* Send the request to server and obtain a response */
93 
94  retval = rfscomm( (struct rf_msg_hdr *)&msg,
95  sizeof(struct rf_msg_sreq),
96  (struct rf_msg_hdr *)&resp,
97  sizeof(struct rf_msg_sres) );
98  if ( (retval == SYSERR) || (retval == TIMEOUT) ) {
100  return SYSERR;
101  } else {
103  return ntohl(resp.rf_size);
104  }
105 
106  default:
107  kprintf("rfscontrol: function %d not valid\n", func);
109  return SYSERR;
110  }
111 
113  return OK;
114 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RF_MSG_DREQ
Definition: rfilesys.h:92
#define RF_MSG_SREQ
Definition: rfilesys.h:98
status rfsndmsg(uint16, char *)
Definition: rfsndmsg.c:9
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RFS_CTL_DEL
Definition: rfilesys.h:67
#define OK
処理が成功した場合
Definition: kernel.h:77
#define RFS_CTL_MKDIR
Definition: rfilesys.h:69
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define RF_MSG_XREQ
Definition: rfilesys.h:104
#define RF_NAMLEN
Definition: rfilesys.h:9
#define RFS_CTL_RMDIR
Definition: rfilesys.h:70
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
#define RFS_CTL_SIZE
Definition: rfilesys.h:71
#define RF_MSG_MREQ
Definition: rfilesys.h:101
#define RFS_CTL_TRUNC
Definition: rfilesys.h:68
sid32 rf_mutex
Definition: rfilesys.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define RF_MSG_TREQ
Definition: rfilesys.h:95
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function: