XINU
lflgetc.c
Go to the documentation of this file.
1 /* lflgetc.c - lfgetc */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * lflgetc - Read the next byte from an open local file
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr /* Entry in device switch table */
11  )
12 {
13  struct lflcblk *lfptr; /* Ptr to open file table entry */
14  struct ldentry *ldptr; /* Ptr to file's entry in the */
15  /* in-memory directory */
16  int32 onebyte; /* Next data byte in the file */
17 
18  /* Obtain exclusive use of the file */
19 
20  lfptr = &lfltab[devptr->dvminor];
21  wait(lfptr->lfmutex);
22 
23  /* If file is not open, return an error */
24 
25  if (lfptr->lfstate != LF_USED) {
26  signal(lfptr->lfmutex);
27  return SYSERR;
28  }
29 
30  /* Return EOF for any attempt to read beyond the end-of-file */
31 
32  ldptr = lfptr->lfdirptr;
33  if (lfptr->lfpos >= ldptr->ld_size) {
34  signal(lfptr->lfmutex);
35  return EOF;
36  }
37 
38  /* If byte pointer is beyond the current data block, set up */
39  /* a new data block */
40 
41  if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) {
42  lfsetup(lfptr);
43  }
44 
45  /* Extract the next byte from block, update file position, and */
46  /* return the byte to the caller */
47 
48  onebyte = 0xff & *lfptr->lfbyte++;
49  lfptr->lfpos++;
50  signal(lfptr->lfmutex);
51  return onebyte;
52 }
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
int32 dvminor
Definition: conf.h:8
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
sid32 lfmutex
Definition: lfilesys.h:146
status lfsetup(struct lflcblk *)
Definition: lfsetup.c:10
devcall lflgetc(struct dentry *devptr)
Definition: lflgetc.c:9
Definition: conf.h:6
#define LF_BLKSIZ
Definition: lfilesys.h:48
byte lfstate
Definition: lfilesys.h:144
uint32 ld_size
Definition: lfilesys.h:98
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49