-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,74 @@ | ||
#include <sys/mman.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
|
||
#include <stdlib.h> | ||
|
||
#include "../vsd_driver/vsd_ioctl.h" | ||
#include "vsd_device.h" | ||
|
||
static int device; | ||
|
||
int vsd_init() | ||
{ | ||
// TODO | ||
return -1; | ||
device = open("/dev/vsd", O_RDWR); | ||
return (device == -1) ? EXIT_FAILURE : EXIT_SUCCESS; | ||
This comment has been minimized.
Sorry, something went wrong.
eabatalov
Collaborator
|
||
} | ||
|
||
int vsd_deinit() | ||
{ | ||
// TODO | ||
return -1; | ||
return close(device); | ||
} | ||
|
||
int vsd_get_size(size_t *out_size) | ||
{ | ||
// TODO | ||
return -1; | ||
vsd_ioctl_get_size_arg_t size; | ||
|
||
if (ioctl(device, VSD_IOCTL_GET_SIZE, &size) == -1) | ||
return EXIT_FAILURE; | ||
|
||
*out_size = size.size; | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
int vsd_set_size(size_t size) | ||
{ | ||
// TODO | ||
return -1; | ||
vsd_ioctl_set_size_arg_t new_size; | ||
new_size.size = size; | ||
|
||
if (ioctl(device, VSD_IOCTL_SET_SIZE, &new_size) == -1) | ||
return EXIT_FAILURE; | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
ssize_t vsd_read(char* dst, off_t offset, size_t size) | ||
{ | ||
// TODO | ||
return -1; | ||
if (lseek(device, offset, SEEK_SET) < 0) | ||
return -1; | ||
|
||
return read(device, dst, size); | ||
} | ||
|
||
ssize_t vsd_write(const char* src, off_t offset, size_t size) | ||
{ | ||
// TODO | ||
return -1; | ||
if (lseek(device, offset, SEEK_SET) < 0) | ||
return -1; | ||
|
||
return write(device, src, size); | ||
} | ||
|
||
void* vsd_mmap(size_t offset) | ||
{ | ||
// TODO | ||
return MAP_FAILED; | ||
size_t len; | ||
vsd_get_size(&len); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return mmap(0, len - offset, PROT_READ | PROT_WRITE, MAP_SHARED, device, offset); | ||
} | ||
|
||
int vsd_munmap(void* addr, size_t offset) | ||
{ | ||
// TODO | ||
return -1; | ||
size_t len; | ||
vsd_get_size(&len); | ||
return munmap(addr, len - offset); | ||
} |
Need to check for ANY error. It doesn't matter which one has happened. Just return it.