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

Go to the source code of this file.

Functions

devcall lflgetc (struct dentry *devptr)
 

Function Documentation

◆ lflgetc()

devcall lflgetc ( struct dentry devptr)

Definition at line 9 of file lflgetc.c.

References dentry::dvminor, EOF, ldentry::ld_size, LF_BLKSIZ, LF_USED, lflcblk::lfbyte, lflcblk::lfdblock, lflcblk::lfdirptr, lfltab, lflcblk::lfmutex, lflcblk::lfpos, lfsetup(), lflcblk::lfstate, signal(), SYSERR, and wait().

Referenced by lflread().

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
#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
Here is the call graph for this function:
Here is the caller graph for this function: