XINU
lflputc.c
Go to the documentation of this file.
1 /* lflputc.c - lfputc */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * lflputc - Write a single byte to an open local file
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr, /* Entry in device switch table */
11  char ch /* Character (byte) to write */
12  )
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
Definition: conf.h:6
#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
devcall lflputc(struct dentry *devptr, char ch)
Definition: lflputc.c:9
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
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49