-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevice.c
More file actions
39 lines (30 loc) · 672 Bytes
/
device.c
File metadata and controls
39 lines (30 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <stdio.h>
#include "device.h"
static const char *device_path;
static FILE *f;
int device_open(const char *path)
{
device_path = path;
f = fopen(path, "r+");
return (f != NULL);
}
void device_close()
{
fflush(f);
fclose(f);
}
int device_read_sector(unsigned char buffer[], int sector)
{
fseek(f, sector*SECTOR_SIZE, SEEK_SET);
return ( fread(buffer, 1, SECTOR_SIZE, f) == SECTOR_SIZE );
}
int device_write_sector(unsigned char buffer[], int sector)
{
fseek(f, sector*SECTOR_SIZE, SEEK_SET);
return ( fwrite(buffer, 1, SECTOR_SIZE, f) == SECTOR_SIZE );
}
void device_flush()
{
fflush(f);
}