XINU
device
lfs
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
*/
9
devcall
lflputc
(
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
++;
53
Lf_data
.
lf_dirdirty
=
TRUE
;
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
}
lflcblk::lfbyte
char * lfbyte
Definition:
lfilesys.h:161
lflcblk::lfdirptr
struct ldentry * lfdirptr
Definition:
lfilesys.h:147
dentry::dvminor
int32 dvminor
Definition:
conf.h:8
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
lflcblk
Definition:
lfilesys.h:142
Lf_data
struct lfdata Lf_data
Definition:
lfsinit.c:5
LF_USED
#define LF_USED
Definition:
lfilesys.h:53
lfltab
struct lflcblk lfltab[]
Definition:
lflinit.c:5
OK
#define OK
処理が成功した場合
Definition:
kernel.h:77
lflcblk::lfmutex
sid32 lfmutex
Definition:
lfilesys.h:146
lfsetup
status lfsetup(struct lflcblk *)
Definition:
lfsetup.c:10
dentry
Definition:
conf.h:6
LF_BLKSIZ
#define LF_BLKSIZ
Definition:
lfilesys.h:48
lflcblk::lfstate
byte lfstate
Definition:
lfilesys.h:144
TRUE
#define TRUE
Boolean True(1)
Definition:
kernel.h:65
ldentry
Definition:
lfilesys.h:96
ldentry::ld_size
uint32 ld_size
Definition:
lfilesys.h:98
lflputc
devcall lflputc(struct dentry *devptr, char ch)
Definition:
lflputc.c:9
lflcblk::lfdbdirty
bool8 lfdbdirty
Definition:
lfilesys.h:166
lfdata::lf_dirdirty
bool8 lf_dirdirty
Definition:
lfilesys.h:137
wait
syscall wait(sid32)
Definition:
wait.c:9
signal
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition:
signal.c:18
lflcblk::lfpos
uint32 lfpos
Definition:
lfilesys.h:150
lflcblk::lfdblock
char lfdblock[LF_BLKSIZ]
Definition:
lfilesys.h:159
devcall
int32 devcall
デバイスコール関数 返り値の型
Definition:
kernel.h:49
Generated by
1.8.13