XINU
lfsckfmt.c
Go to the documentation of this file.
1 /* lfckfmt.c - lfckfmt */
2 
3 #include <xinu.h>
4 #include <ramdisk.h>
5 
6 /*------------------------------------------------------------------------
7  * lfckfmt - Check the format of an initially-created disk
8  *------------------------------------------------------------------------
9  */
11  did32 disk /* ID of an open disk device */
12  )
13 {
14  uint32 ibsectors; /* Number of sectors of i-blocks*/
15  struct lfdir dir; /* Buffer to hold the directory */
16  uint32 dblks; /* Total free data blocks */
17  struct lfiblk iblock; /* Space for one i-block */
18  struct lfdbfree dblock; /* Data block on the free list */
19  int32 lfiblks; /* Total free index blocks */
20  int32 retval;
21  ibid32 nextib;
22  dbid32 nextdb;
23 
24  /* Read directory */
25 
26  retval = read(disk,(char *)&dir, LF_AREA_DIR);
27  if (retval == SYSERR) {
28  panic("cannot read directory");
29  }
30  kprintf("Have read directory from disk device %d\n\r",
31  disk);
32 
33  /* Check to see if directory contains a Xinu file system */
34 
35  if (lfscheck(&dir) == SYSERR) {
36  panic("directory does not contain a Xinu file system");
37  }
38  kprintf("Directory corresponds to a local Xinu file system\n");
39 
40  /* Follow index block list */
41 
42  lfiblks = 0;
43  nextib = dir.lfd_ifree;
44  kprintf("initial index block is %d\n\r", nextib);
45  while (nextib != LF_INULL) {
46  lfiblks++;
47  lfibget(disk, nextib, &iblock);
48  nextib = iblock.ib_next;
49  }
50  ibsectors = (lfiblks + 6) /7;
51  kprintf("Found %d index blocks (%d sectors)\n\r", lfiblks, ibsectors);
52 
53  /* Follow data block list */
54 
55  dblks = 0;
56  nextdb = dir.lfd_dfree;
57  kprintf("initial data block is %d\n\r", nextdb);
58  while (nextdb != LF_DNULL) {
59  dblks++;
60  read(disk, (char *)&dblock, nextdb);
61  nextdb = dblock.lf_nextdb;
62  }
63  kprintf("Found %d data blocks\n\r", dblks);
64  return OK;
65 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall read(did32, char *, uint32)
Definition: read.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition: kernel.h:57
void lfibget(did32, ibid32, struct lfiblk *)
Definition: lfibget.c:10
#define LF_INULL
Definition: lfilesys.h:55
#define LF_AREA_DIR
Definition: lfilesys.h:67
status lfsckfmt(did32 disk)
Definition: lfsckfmt.c:10
RAMディスクに関する定義(testing)
ibid32 ib_next
Definition: lfilesys.h:72
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
int32 did32
デバイスID
Definition: kernel.h:28
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
status lfscheck(struct lfdir *)
Definition: lfscheck.c:10