*/
#include <ata.h>
#include <disk.h>
-#include <ext2.h>
#include <ide.h>
#include <io.h>
#include <irq.h>
}
}
-// 读hda0 的 super block
-void ata_read_ext2_sb() {
- ide_part_t *part = ide_drives[0].partions + 1;
- const int size = 1024;
- const int offset = 1024;
- char *buf = kmalloc(size, 0);
- disk_request_t r;
- r.dev = MAKE_DEV(DEV_MAJOR_IDE0, 1);
- r.command = DISK_REQ_READ;
- r.pos = part->lba_start + offset / SECT_SIZE;
- r.count = size / SECT_SIZE;
- r.buf = buf;
- send_disk_request(&r);
- ext2_sb_t *p = (ext2_sb_t *)buf;
- printk("inodes count %u inodes per group %u free %u\n", p->s_inodes_count, p->s_inodes_per_group,
- p->s_free_inodes_count);
- printk("blocks count %u blocks per group %u free %u magic %04x\n", p->s_blocks_count, p->s_blocks_per_group,
- p->s_free_blocks_count, p->s_magic);
- printk("first ino %u inode size %u first data block %u\n", p->s_first_ino, p->s_inode_size, p->s_first_data_block);
- printk("log block size %u write time %u\n", p->s_log_block_size, p->s_wtime);
- p->s_volume_name[63] = 0;
- printk("volume %s\n", p->s_volume_name);
- kfree(buf);
-}
-
// 《AT Attachment 8 - ATA/ATAPI Command Set》
void ide_ata_init() {
for (int i = 0; i < MAX_IDE_DRIVE_CNT; i++) {
}
}
-void ide_disk_read(dev_t dev, uint32_t block, uint32_t size, char *buf) {
+void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char *buf) {
ide_drive_t *drv = ide_get_drive(dev);
uint64_t lba_offset = drv->partions[DEV_MINOR((dev))].lba_start;
disk_request_t r;
r.dev = dev;
r.command = DISK_REQ_READ;
- r.pos = lba_offset + block / SECT_SIZE;
- r.count = size / SECT_SIZE;
+ r.pos = lba_offset + sect_nr;
+ r.count = count;
r.buf = buf;
send_disk_request(&r);
}
#include <fs.h>
#include <ide.h>
-blk_buffer_t *block_read(dev_t dev, uint32_t block, uint32_t size) {
+#define BLOCK_BUFFER_HASH_TABLE_SIZE 37
+atomic_t hash_cnt;
+blk_buffer_t *block_buffer_hash_table[BLOCK_BUFFER_HASH_TABLE_SIZE] = {
+ 0,
+};
+
+int hash(dev_t dev, uint32_t block) { return ((co ~dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE; }
+
+blk_buffer_t *get_hash_block_buffer(dev_t dev, uint32_t block, uint16_t size) {}
+
+blk_buffer_t *block_read(dev_t dev, uint32_t block) {
blk_buffer_t *bb = 0;
assert(DEV_MAJOR(dev) == DEV_MAJOR_IDE0);
// 目前不提供hash表组强起来的缓冲功能
// 直接读
- ide_disk_read(dev, block, size, bb->data);
+ // TODO:根据dev得到正确的blocksize
+ const int blocksize = 1024;
+
+ bb->data = kmalloc(blocksize, 0); // debug
+
+ ide_disk_read(dev, block * blocksize / 512, 1, bb->data);
return bb;
}
+
+#include <ext2.h>
+// 读hda1 的 super block
+void ata_read_ext2_sb() {
+ // 初始默认blocksize = 1024
+ // 则ext2_superblock应该在第1个block的offset为0的位置
+ // ext2_superblock默认大小1024
+
+ const int offset = 0;
+ const int size = offset + 1024;
+ const int block = 1;
+
+ blk_buffer_t *bb = block_read(MAKE_DEV(DEV_MAJOR_IDE0, 1), block);
+
+ ext2_sb_t *p = (ext2_sb_t *)(bb->data + offset);
+ printk("inodes count %u inodes per group %u free %u\n", p->s_inodes_count, p->s_inodes_per_group,
+ p->s_free_inodes_count);
+ printk("blocks count %u blocks per group %u free %u magic %04x\n", p->s_blocks_count, p->s_blocks_per_group,
+ p->s_free_blocks_count, p->s_magic);
+ printk("first ino %u inode size %u first data block %u\n", p->s_first_ino, p->s_inode_size, p->s_first_data_block);
+ printk("log block size %u write time %u\n", p->s_log_block_size, p->s_wtime);
+ p->s_volume_name[63] = 0;
+ printk("volume %s\n", p->s_volume_name);
+ kfree(bb->data);
+}
void send_disk_request(disk_request_t *r);
-void ide_disk_read(dev_t dev, uint32_t block, uint32_t size, char *buf);
+void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char *buf);
typedef uint32_t dev_t;
-typedef struct blk_bufer {
- uint32_t blocknr; // block number
- char *data; //
- uint16_t size; // block size
+typedef struct blk_buffer {
+ uint32_t block; // block number
+ char *data; //
+ uint16_t block_size; // block size
dev_t dev;
page_t *page;
+ struct blk_buffer *next;
+ struct blk_buffer *hash_next;
} blk_buffer_t;
#endif //_FS_H