XINU
lflclose.c
Go to the documentation of this file.
1 /* lflclose.c - lflclose.c */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * lflclose - Close a file by flushing output and freeing device entry
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr /* Entry in device switch table */
11  )
12 {
13  struct lflcblk *lfptr; /* Ptr to open file table entry */
14 
15  /* Obtain exclusive use of the file */
16 
17  lfptr = &lfltab[devptr->dvminor];
18  wait(lfptr->lfmutex);
19 
20  /* If file is not open, return an error */
21 
22  if (lfptr->lfstate != LF_USED) {
23  signal(lfptr->lfmutex);
24  return SYSERR;
25  }
26 
27  /* Write index or data blocks to disk if they have changed */
28 
29  if (Lf_data.lf_dirdirty || lfptr->lfdbdirty || lfptr->lfibdirty) {
30  lfflush(lfptr);
31  }
32 
33  /* Set device state to FREE and return to caller */
34 
35  lfptr->lfstate = LF_FREE;
36  signal(lfptr->lfmutex);
37  return OK;
38 }
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
Definition: conf.h:6
devcall lflclose(struct dentry *devptr)
Definition: lflclose.c:9
byte lfstate
Definition: lfilesys.h:144
bool8 lfdbdirty
Definition: lfilesys.h:166
bool8 lf_dirdirty
Definition: lfilesys.h:137
#define LF_FREE
Definition: lfilesys.h:52
bool8 lfibdirty
Definition: lfilesys.h:165
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
status lfflush(struct lflcblk *)
Definition: lfflush.c:10