
#include <stdio.h>
#include <errno.h>
#include <string.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) {
		fprintf(stderr, "devopen: %s.\n", strerror(errno));
		return 0;
	}
	int seek_res = 0;
	seek_res |= fseek(block_device, 0, SEEK_END);
	device_size = ftell(block_device);
	seek_res |= fseek(block_device, 0, SEEK_SET);
	if (seek_res || device_size == -1L || device_size % 512) {
		fprintf(stderr, "devopen: Bad file %s.\n", name);
		devclose();
		return 0;
	}

	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);
