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

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

unix.superglobalmegacorp.com

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