2021-09-03 11:03:44 +03:00
|
|
|
#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>
|
|
|
|
|
2021-09-03 18:24:22 +03:00
|
|
|
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));
|
|
|
|
|
2021-09-03 11:03:44 +03:00
|
|
|
struct ntfs_file_handle {
|
|
|
|
struct volume *part;
|
2021-09-03 18:24:22 +03:00
|
|
|
|
|
|
|
struct ntfs_bpb bpb;
|
|
|
|
|
2021-09-28 22:07:43 +03:00
|
|
|
// file record sizes
|
2021-09-28 21:05:50 +03:00
|
|
|
uint64_t file_record_size;
|
|
|
|
uint64_t sectors_per_file_record;
|
|
|
|
|
2021-09-28 22:07:43 +03:00
|
|
|
// MFT info, the offset and its runlist
|
|
|
|
uint64_t mft_offset;
|
|
|
|
uint8_t mft_run_list[256];
|
|
|
|
|
2022-01-21 18:01:03 +03:00
|
|
|
// the runlist of the open file/directory
|
2021-09-28 22:07:43 +03:00
|
|
|
uint8_t run_list[128];
|
2022-01-21 18:01:03 +03:00
|
|
|
|
|
|
|
// The resident index, only for directories,
|
|
|
|
// could be at the same time as a runlist
|
2021-09-29 17:58:29 +03:00
|
|
|
uint8_t resident_index_size;
|
2022-01-28 14:48:21 +03:00
|
|
|
|
2022-01-21 18:01:03 +03:00
|
|
|
// the resident data
|
|
|
|
uint8_t resident_data_size;
|
2022-01-28 14:48:21 +03:00
|
|
|
|
|
|
|
// we are using a union just for having different names, these
|
|
|
|
// won't have need to be used at the same time
|
|
|
|
union {
|
|
|
|
uint8_t resident_index[1024];
|
|
|
|
uint8_t resident_data[1024];
|
|
|
|
};
|
2022-01-21 18:01:03 +03:00
|
|
|
|
2021-09-28 22:07:43 +03:00
|
|
|
// info about the current file
|
2021-09-03 11:03:44 +03:00
|
|
|
uint32_t size_bytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
int ntfs_check_signature(struct volume *part);
|
|
|
|
|
2022-01-21 17:39:18 +03:00
|
|
|
bool ntfs_open(struct ntfs_file_handle *ret, struct volume *part, const char *path);
|
2021-09-03 11:03:44 +03:00
|
|
|
int ntfs_read(struct ntfs_file_handle *file, void *buf, uint64_t loc, uint64_t count);
|
2022-01-21 17:39:18 +03:00
|
|
|
void ntfs_close(struct ntfs_file_handle *file);
|
2021-09-03 11:03:44 +03:00
|
|
|
|
|
|
|
#endif
|