XINU
include
lfilesys.h
Go to the documentation of this file.
1
/* lfilesys.h - ib2sect, ib2disp */
2
3
/************************************************************************/
4
/* */
5
/* Local File System Data Structures */
6
/* */
7
/* A local file system uses a random-access disk composed of 512-byte */
8
/* sectors numbered 0 through N-1. We assume disk hardware can read or */
9
/* write any sector at random, but must transfer an entire sector. */
10
/* Thus, to write a few bytes, the file system must read the sector, */
11
/* replace the bytes, and then write the sector back to disk. Xinu's */
12
/* local file system divides the disk as follows: sector 0 is a */
13
/* directory, the next K sectors constitute an index area, and the */
14
/* remaining sectors comprise a data area. The data area is easiest to */
15
/* understand: each sector holds one data block (d-block) that stores */
16
/* contents from one of the files (or is on a free list of unused data */
17
/* blocks). We think of the index area as holding an array of index */
18
/* blocks (i-blocks) numbered 0 through I-1. A given sector in the */
19
/* index area holds 7 of the index blocks, which are each 72 bytes */
20
/* long. Given an i-block number, the file system must calculate the */
21
/* disk sector in which the i-block is located and the byte offset */
22
/* within the sector at which the i-block resides. Internally, a file */
23
/* is known by the i-block index of the first i-block for the file. */
24
/* The directory contains a list of file names and the i-block number */
25
/* of the first i-block for the file. The directory also holds the */
26
/* i-block number for a list of free i-blocks and a data block number */
27
/* of the first data block on a list of free data blocks. */
28
/* */
29
/************************************************************************/
30
31
#ifndef Nlfl
32
#define Nlfl 1
33
#endif
34
35
/* Use the remote disk device if no disk is defined (file system */
36
/* *assumes* the underlying disk has a block size of 512 bytes) */
37
38
#ifndef LF_DISK_DEV
39
#define LF_DISK_DEV SYSERR
40
#endif
41
42
#define LF_MODE_R F_MODE_R
/* Mode bit for "read" */
43
#define LF_MODE_W F_MODE_W
/* Mode bit for "write" */
44
#define LF_MODE_RW F_MODE_RW
/* Mode bits for "read or write"*/
45
#define LF_MODE_O F_MODE_O
/* Mode bit for "old" */
46
#define LF_MODE_N F_MODE_N
/* Mode bit for "new" */
47
48
#define LF_BLKSIZ 512
/* Assumes 512-byte disk blocks */
49
#define LF_NAME_LEN 16
/* Length of name plus null */
50
#define LF_NUM_DIR_ENT 20
/* Num. of files in a directory */
51
52
#define LF_FREE 0
/* Slave device is available */
53
#define LF_USED 1
/* Slave device is in use */
54
55
#define LF_INULL (ibid32) -1
/* Index block null pointer */
56
#define LF_DNULL (dbid32) -1
/* Data block null pointer */
57
#define LF_IBLEN 16
/* Data block ptrs per i-block */
58
#define LF_IDATA 8192
/* Bytes of data indexed by a */
59
/* single index block */
60
#define LF_IMASK 0x00001fff
/* Mask for the data indexed by */
61
/* one index block (i.e., */
62
/* bytes 0 through 8191). */
63
#define LF_DMASK 0x000001ff
/* Mask for the data in a data */
64
/* block (0 through 511) */
65
66
#define LF_AREA_IB 1
/* First sector of i-blocks */
67
#define LF_AREA_DIR 0
/* First sector of directory */
68
69
/* Structure of an index block on disk */
70
71
struct
lfiblk
{
/* Format of index block */
72
ibid32
ib_next
;
/* Address of next index block */
73
uint32
ib_offset
;
/* First data byte of the file */
74
/* Indexed by this i-block */
75
dbid32
ib_dba
[
LF_IBLEN
];
/* Ptrs to data blocks indexed */
76
};
77
78
/* File System ID */
79
80
#define LFS_ID 0x58696E75
/* ID for Xinu Local File System*/
81
82
/* Conversion functions below assume 7 index blocks per disk block */
83
84
/* Conversion between index block number and disk sector number */
85
86
#define ib2sect(ib) (((ib)/7)+LF_AREA_IB)
87
88
/* Conversion between index block number and the relative offset within */
89
/* a disk sector */
90
91
#define ib2disp(ib) (((ib)%7)*sizeof(struct lfiblk))
92
93
94
/* Structure used in each directory entry for the local file system */
95
96
struct
ldentry
{
/* Description of entry for one */
97
/* file in the directory */
98
uint32
ld_size
;
/* Curr. size of file in bytes */
99
ibid32
ld_ilist
;
/* ID of first i-block for file */
100
/* or IB_NULL for empty file */
101
char
ld_name[
LF_NAME_LEN
];
/* Null-terminated file name */
102
};
103
104
/* Structure of a data block when on the free list on disk */
105
106
struct
lfdbfree
{
107
dbid32
lf_nextdb
;
/* Next data block on the list */
108
char
lf_unused[
LF_BLKSIZ
-
sizeof
(
dbid32
)];
109
};
110
111
/* Format of the file system directory, either on disk or in memory */
112
113
#pragma pack(2)
114
struct
lfdir
{
/* Entire directory on disk */
115
uint32
lfd_fsysid
;
/* File system ID */
116
int16
lfd_vers
;
/* File system version */
117
int16
lfd_subvers
;
/* File system subversion */
118
uint32
lfd_allzeros
;
/* All 0 bits */
119
uint32
lfd_allones
;
/* All 1 bits */
120
dbid32
lfd_dfree
;
/* List of free d-blocks on disk*/
121
ibid32
lfd_ifree
;
/* List of free i-blocks on disk*/
122
int32
lfd_nfiles
;
/* Current number of files */
123
struct
ldentry
lfd_files[
LF_NUM_DIR_ENT
];
/* Set of files */
124
uint32
lfd_revid
;
/* fsysid in reverse byte order */
125
};
126
#pragma pack()
127
128
/* Global data used by local file system */
129
130
struct
lfdata
{
/* Local file system data */
131
did32
lf_dskdev
;
/* Device ID of disk to use */
132
sid32
lf_mutex
;
/* Mutex for the directory and */
133
/* index/data free lists */
134
struct
lfdir
lf_dir;
/* In-memory copy of directory */
135
bool8
lf_dirpresent
;
/* True when directory is in */
136
/* memory (1st file is open) */
137
bool8
lf_dirdirty
;
/* Has the directory changed? */
138
};
139
140
/* Control block for local file pseudo-device */
141
142
struct
lflcblk
{
/* Local file control block */
143
/* (one for each open file) */
144
byte
lfstate
;
/* Is entry free or used */
145
did32
lfdev
;
/* Device ID of this device */
146
sid32
lfmutex
;
/* Mutex for this file */
147
struct
ldentry
*
lfdirptr
;
/* Ptr to file's entry in the */
148
/* in-memory directory */
149
int32
lfmode
;
/* Mode (read/write/both) */
150
uint32
lfpos
;
/* Byte position of next byte */
151
/* to read or write */
152
char
lfname[
LF_NAME_LEN
];
/* Name of the file */
153
ibid32
lfinum
;
/* ID of current index block in */
154
/* lfiblock or LF_INULL */
155
struct
lfiblk
lfiblock;
/* In-mem copy of current index */
156
/* block */
157
dbid32
lfdnum
;
/* Number of current data block */
158
/* in lfdblock or LF_DNULL */
159
char
lfdblock[
LF_BLKSIZ
];
/* In-mem copy of current data */
160
/* block */
161
char
*
lfbyte
;
/* Ptr to byte in lfdblock or */
162
/* address one beyond lfdblock*/
163
/* if current file pos lies */
164
/* outside lfdblock */
165
bool8
lfibdirty
;
/* Has lfiblock changed? */
166
bool8
lfdbdirty
;
/* Has lfdblock changed? */
167
};
168
169
extern
struct
lfdata
Lf_data
;
170
extern
struct
lflcblk
lfltab
[];
171
172
/* Control functions */
173
174
#define LF_CTL_DEL F_CTL_DEL
/* Delete a file */
175
#define LF_CTL_TRUNC F_CTL_TRUNC
/* Truncate a file */
176
#define LF_CTL_SIZE F_CTL_SIZE
/* Obtain the size of a file */
dbid32
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition:
kernel.h:42
lflcblk::lfbyte
char * lfbyte
Definition:
lfilesys.h:161
lfdbfree::lf_nextdb
dbid32 lf_nextdb
Definition:
lfilesys.h:107
lflcblk::lfdirptr
struct ldentry * lfdirptr
Definition:
lfilesys.h:147
byte
unsigned char byte
符号なし8ビット値(unsigned char)
Definition:
kernel.h:7
ibid32
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition:
kernel.h:40
ldentry::ld_ilist
ibid32 ld_ilist
Definition:
lfilesys.h:99
lfdata::lf_mutex
sid32 lf_mutex
Definition:
lfilesys.h:132
lfdir::lfd_fsysid
uint32 lfd_fsysid
Definition:
lfilesys.h:115
lflcblk
Definition:
lfilesys.h:142
Lf_data
struct lfdata Lf_data
Definition:
lfsinit.c:5
lfdbfree
Definition:
lfilesys.h:106
lfdir::lfd_ifree
ibid32 lfd_ifree
Definition:
lfilesys.h:121
lfdata::lf_dskdev
did32 lf_dskdev
Definition:
lfilesys.h:131
lfdir::lfd_subvers
int16 lfd_subvers
Definition:
lfilesys.h:117
lfltab
struct lflcblk lfltab[]
Definition:
lflinit.c:5
LF_NAME_LEN
#define LF_NAME_LEN
Definition:
lfilesys.h:49
lfdir
Definition:
lfilesys.h:114
LF_IBLEN
#define LF_IBLEN
Definition:
lfilesys.h:57
bool8
byte bool8
Boolean値
Definition:
kernel.h:36
lflcblk::lfmutex
sid32 lfmutex
Definition:
lfilesys.h:146
lfdata::lf_dirpresent
bool8 lf_dirpresent
Definition:
lfilesys.h:135
lfiblk
Definition:
lfilesys.h:71
lfdir::lfd_dfree
dbid32 lfd_dfree
Definition:
lfilesys.h:120
lflcblk::lfinum
ibid32 lfinum
Definition:
lfilesys.h:153
LF_BLKSIZ
#define LF_BLKSIZ
Definition:
lfilesys.h:48
lflcblk::lfstate
byte lfstate
Definition:
lfilesys.h:144
ldentry
Definition:
lfilesys.h:96
lflcblk::lfdnum
dbid32 lfdnum
Definition:
lfilesys.h:157
lfiblk::ib_next
ibid32 ib_next
Definition:
lfilesys.h:72
ldentry::ld_size
uint32 ld_size
Definition:
lfilesys.h:98
lfdir::lfd_revid
uint32 lfd_revid
Definition:
lfilesys.h:124
lflcblk::lfdbdirty
bool8 lfdbdirty
Definition:
lfilesys.h:166
lfdata::lf_dirdirty
bool8 lf_dirdirty
Definition:
lfilesys.h:137
int16
short int16
符号あり16ビット整数(short)
Definition:
kernel.h:13
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
lfdir::lfd_nfiles
int32 lfd_nfiles
Definition:
lfilesys.h:122
did32
int32 did32
デバイスID
Definition:
kernel.h:28
lfiblk::ib_offset
uint32 ib_offset
Definition:
lfilesys.h:73
lfiblk::ib_dba
dbid32 ib_dba[LF_IBLEN]
Definition:
lfilesys.h:75
lfdata
Definition:
lfilesys.h:130
lflcblk::lfdev
did32 lfdev
Definition:
lfilesys.h:145
lflcblk::lfmode
int32 lfmode
Definition:
lfilesys.h:149
lflcblk::lfibdirty
bool8 lfibdirty
Definition:
lfilesys.h:165
lflcblk::lfpos
uint32 lfpos
Definition:
lfilesys.h:150
lfdir::lfd_allzeros
uint32 lfd_allzeros
Definition:
lfilesys.h:118
lfdir::lfd_allones
uint32 lfd_allones
Definition:
lfilesys.h:119
uint32
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition:
kernel.h:15
lfdir::lfd_vers
int16 lfd_vers
Definition:
lfilesys.h:116
sid32
int32 sid32
セマフォID
Definition:
kernel.h:22
LF_NUM_DIR_ENT
#define LF_NUM_DIR_ENT
Definition:
lfilesys.h:50
Generated by
1.8.13