|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.3 ! root 7: //
! 8: // UFS 読み込み
! 9: //
! 10:
1.1 root 11: #pragma once
12:
13: #include "device.h"
14: #include "ffs_dinode.h"
15: #include "ffs_fs.h"
16:
17: // ディスクラベル (1セクタ目)
18: // svnweb.freebsd.org/csrg/sys/luna68k/stand/omron_disklabel.h
19: struct scd_dk_label
20: {
21: char asciilabel[128]; /* for compatibility */
22: char pad[512 - (128 + 8*8 + 11*2 + 4)];
23: uint16 badchk; /* checksum of bad track */
24: uint32 maxblk; /* # of total logical block */
25: uint16 dtype; /* disk drive type */
26: uint16 ndisk; /* # of disk drives */
27: uint16 ncyl; /* # of data cylinders */
28: uint16 acyl; /* # of altenate cylinders */
29: uint16 nhead; /* # of heads in this partition */
30: uint16 nsect; /* # of 512 byte sectors per track */
31: uint16 bhead; /* identifies proper label locations */
32: uint16 ppart; /* physical partition # */
33: struct { /* logical partitions */
34: uint32 blkno; /* starting block */
35: uint32 nblk; /* number of blocks */
36: } map[8];
37: uint16 magic; /* identifies this label format */
38: uint16 cksum; /* xor checksum of sector */
39:
40: static const uint16 DKL_MAGIC = 0xdabe;
41: };
42: static_assert(sizeof(scd_dk_label) == 512, "size must be 512");
43:
44: // オレオレ inode 情報クラス
45: class inodefile final
46: {
47: public:
48: inodefile(Device *parent_);
49: ~inodefile();
50:
51: // ディレクトリエントリからファイルを検索
52: uint32 FindFile(const std::string& name);
53:
54: uint32 ino {}; // inode 番号
55: struct ufs1_dinode di {}; // disk inode 情報 (ゲストエンディアンで保持)
56: std::vector<uint8> data {}; // ファイル(またはディレクトリ)本文
57: private:
58: Device *parent {}; // 親デバイス
59: };
60:
61: // ファイルシステムハンドルっぽいもの
62: class Filesys final
63: {
64: public:
65: Filesys(Device *parent_);
66: ~Filesys();
67:
68: // ファイルシステムをオープン
1.1.1.2 root 69: bool Mount(SCSIDisk *hd_, uint32 start, uint32 size);
1.1 root 70:
71: // ファイル名からファイルを探す
72: bool OpenFile(inodefile& inode, const std::string& filename);
73:
74: // inode で示されるファイルかディレクトリの中身を読み込む
75: void ReadData(inodefile& inode);
76:
77: std::string errstr {}; // エラーメッセージ
78:
79: private:
80: // inode 情報を読み込む
81: void Readi(inodefile& inode);
82:
83: // 指定のブロックを読み出す
84: void PeekBlock(void *buf, uint32 b, uint32 len) const;
85:
86: Device *parent {}; // 親デバイス
1.1.1.2 root 87: SCSIDisk *hd {}; // ターゲット SCSI Disk
1.1 root 88:
89: // パーティション情報
90: uint32 part_start {}; // パーティションの先頭セクタ
91: uint32 part_size {}; // パーティションのサイズ(セクタ数)
92:
93: // スーパーブロック情報
94: // fs の(たぶんほとんどの)整数パラメータは読み込み時にホストエンディアン
95: // に変換してあるのでそのままアクセスしてよい。構造体とかまでは全部対応
96: // してないので、必要になったら書き足すこと。
97: struct fs *fs {}; // 体裁を揃えるためポインタを使いたい
98: struct fs fs0 {}; // こっちが実体
99: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.