Starting to work on NTFS

This commit is contained in:
Itay Almog 2021-09-03 11:03:44 +03:00
parent 34cfd0e55b
commit f59f18458c
3 changed files with 96 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include <fs/ext2.h>
#include <fs/fat32.h>
#include <fs/iso9660.h>
#include <fs/ntfs.h>
#include <lib/print.h>
#include <lib/blib.h>
#include <mm/pmm.h>
@ -97,6 +98,20 @@ int fopen(struct file_handle *ret, struct volume *part, const char *filename) {
return 0;
}
if (ntfs_check_signature(part)) {
struct ntfs_file_handle *fd = ext_mem_alloc(sizeof(struct ntfs_file_handle));
int r = ntfs_open(fd, part, filename);
if (r)
return r;
ret->fd = (void *)fd;
ret->read = (void *)ntfs_read;
ret->size = fd->size_bytes;
return 0;
}
return -1;
}

20
stage23/fs/ntfs.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __FS__NTFS_H__
#define __FS__NTFS_H__
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <lib/part.h>
#include <lib/blib.h>
struct ntfs_file_handle {
struct volume *part;
uint32_t size_bytes;
};
int ntfs_check_signature(struct volume *part);
int ntfs_open(struct ntfs_file_handle *ret, struct volume *part, const char *path);
int ntfs_read(struct ntfs_file_handle *file, void *buf, uint64_t loc, uint64_t count);
#endif

61
stage23/fs/ntfs.s2.c Normal file
View File

@ -0,0 +1,61 @@
#include <fs/ntfs.h>
struct ntfs_bpb {
uint8_t jump[3];
char oem[8];
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t reserved_sectors;
uint8_t fats_count;
uint16_t directory_entries_count;
uint16_t sector_totals;
uint8_t media_descriptor_type;
uint16_t sectors_per_fat_16;
uint16_t sectors_per_track;
uint16_t heads_count;
uint32_t hidden_sectors_count;
uint32_t large_sectors_count;
// ntfs
uint32_t sectors_per_fat_32;
uint64_t sectors_count_64;
uint64_t mft_cluster;
} __attribute__((packed));
int ntfs_check_signature(struct volume *part) {
struct ntfs_bpb bpb = { 0 };
if (volume_read(part, &bpb, 0, sizeof(bpb))) {
return 1;
}
//
// validate the bpb
//
if (strncmp(bpb.oem, "NTFS ", SIZEOF_ARRAY(bpb.oem))) {
return 1;
}
if (bpb.sector_totals != 0) {
return 1;
}
if (bpb.large_sectors_count != 0) {
return 1;
}
if (bpb.sectors_count_64 == 0) {
return 1;
}
// this is a valid ntfs sector
return 0;
}
int ntfs_open(struct ntfs_file_handle *ret, struct volume *part, const char *path) {
}
int ntfs_read(struct ntfs_file_handle *file, void *buf, uint64_t loc, uint64_t count) {
}