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

Go to the source code of this file.

Functions

devcall lflputc (struct dentry *devptr, char ch)
 

Function Documentation

◆ lflputc()

devcall lflputc ( struct dentry devptr,
char  ch 
)

Definition at line 9 of file lflputc.c.

References dentry::dvminor, ldentry::ld_size, LF_BLKSIZ, Lf_data, lfdata::lf_dirdirty, LF_USED, lflcblk::lfbyte, lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdirptr, lfltab, lflcblk::lfmutex, lflcblk::lfpos, lfsetup(), lflcblk::lfstate, OK, signal(), SYSERR, TRUE, and wait().

Referenced by lflwrite().

13 {
14  struct lflcblk *lfptr; /* Ptr to open file table entry */
15  struct ldentry *ldptr; /* Ptr to file's entry in the */
16  /* in-memory directory */
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 SYSERR for an attempt to skip bytes beyond the byte */
31  /* that is currently the end of the file */
32 
33  ldptr = lfptr->lfdirptr;
34  if (lfptr->lfpos > ldptr->ld_size) {
35  signal(lfptr->lfmutex);
36  return SYSERR;
37  }
38 
39  /* If pointer is outside current block, set up new block */
40 
41  if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) {
42 
43  /* Set up block for current file position */
44 
45  lfsetup(lfptr);
46  }
47 
48  /* If appending a byte to the file, increment the file size. */
49  /* Note: comparison might be equal, but should not be greater.*/
50 
51  if (lfptr->lfpos >= ldptr->ld_size) {
52  ldptr->ld_size++;
54  }
55 
56  /* Place byte in buffer and mark buffer "dirty" */
57 
58  *lfptr->lfbyte++ = ch;
59  lfptr->lfpos++;
60  lfptr->lfdbdirty = TRUE;
61 
62  signal(lfptr->lfmutex);
63  return OK;
64 }
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
struct lfdata Lf_data
Definition: lfsinit.c:5
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define OK
処理が成功した場合
Definition: kernel.h:77
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
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 ld_size
Definition: lfilesys.h:98
bool8 lfdbdirty
Definition: lfilesys.h:166
bool8 lf_dirdirty
Definition: lfilesys.h:137
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: