Annotation of nono/vm/ufs.h, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.