
#include <stdio.h>

#include "blockdev.h"

FILE* block_device = NULL;
size_t device_size = 0;


int devopen(const char* name, int* reopen)
{
	block_device = fopen(name, "rwb");
	if (!block_device) {
		return 0;
	}
	fseek(block_device, 0, SEEK_END);
	device_size = ftell(block_device);
	return 1;
}


void devclose(void)
{
	if (block_device) {
		fclose(block_device);
	}
	block_device = NULL;
	device_size = 0;
}

int devread(unsigned long sector, unsigned long byte_offset, unsigned long byte_len, void *buf)
{
	if (!block_device) {
		fprintf(stderr, "devread: Device not open.\n");
		return 0;
	}

	const unsigned long offset = sector * 512 + byte_offset;
	if (offset + byte_len > device_size) {
		fprintf(stderr, "devread: Attempt to read beyond device.\n");
		return 0;
	}

	if (fseek(block_device, sector * 512 + byte_offset, SEEK_SET) != 0) {
		fprintf(stderr, "devread: Failed to set offset on device.\n");
		return 0;
	}
	if (fread(buf, byte_len, 1, block_device) != byte_len) {
		fprintf(stderr, "devread: Failed to read from device.\n");
		return 0;
	}
	return 1;
}



//void dev_set_partition(unsigned long start, unsigned long size);
//void dev_get_partition(unsigned long *start, unsigned long *size);

//int file_open(const char *filename);
//int file_read(void *buf, unsigned long len);
//unsigned long file_seek(unsigned long offset);
//unsigned long file_size(void);
//void file_set_size(unsigned long size);
//void file_close(void);
