diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-10 20:23:13 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-10 20:23:13 +0100 |
commit | 0e50ada984473de20ba47c2ebdbe36b3dad78dd1 (patch) | |
tree | 7864cd0290a112244ef93fd590d018e52bbd16a3 /src/kernel/dev/pciide.c | |
parent | 6d9cd139c42a48f5ddf8f8e284f56873de73fd31 (diff) | |
download | kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.tar.gz kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.zip |
Add mutex to pciide driver (fixes some stuff)
Diffstat (limited to 'src/kernel/dev/pciide.c')
-rw-r--r-- | src/kernel/dev/pciide.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/kernel/dev/pciide.c b/src/kernel/dev/pciide.c index 9a78315..d63abb4 100644 --- a/src/kernel/dev/pciide.c +++ b/src/kernel/dev/pciide.c @@ -654,6 +654,7 @@ typedef struct { uint32_t block_size; // ATA: 512, ATAPI: 2048 uint8_t device; uint8_t type; + mutex_t lock; } ide_vfs_dev_t; bool ide_vfs_open(fs_node_t *n, int mode); @@ -688,6 +689,7 @@ void ide_register_device(ide_controller_t *c, uint8_t device, fs_t *iofs) { d->device = device; d->type = c->devices[device].type; d->block_size = (d->type == IDE_ATAPI ? 2048 : 512); + d->lock = MUTEX_UNLOCKED; char name[40]; @@ -734,10 +736,17 @@ size_t ide_vfs_read(fs_handle_t *h, size_t offset, size_t len, char* buf) { if (offset % d->block_size != 0) return 0; if (len % d->block_size != 0) return 0; + size_t ret = 0; + mutex_lock(&d->lock); + uint8_t err = ide_read_sectors(d->c, d->device, offset / d->block_size, len / d->block_size, buf); - if (err != 0) return 0; + if (err != 0) goto end; + + ret = len; - return len; +end: + mutex_unlock(&d->lock); + return ret; } size_t ide_vfs_write(fs_handle_t *h, size_t offset, size_t len, const char* buf) { @@ -745,11 +754,19 @@ size_t ide_vfs_write(fs_handle_t *h, size_t offset, size_t len, const char* buf) if (offset % d->block_size != 0) return 0; if (len % d->block_size != 0) return 0; -uint8_t err = ide_write_sectors(d->c, d->device, - offset / d->block_size, len / d->block_size, (char*)buf); - if (err != 0) return 0; - return len; + size_t ret = 0; + mutex_lock(&d->lock); + + uint8_t err = ide_write_sectors(d->c, d->device, + offset / d->block_size, len / d->block_size, (char*)buf); + if (err != 0) goto end; + + ret = len; + +end: + mutex_unlock(&d->lock); + return ret; } int ide_vfs_ioctl(fs_handle_t *h, int command, void* data) { |