2020-01-05 09:00:43 +01:00
|
|
|
#include <kernel/fs/vfs.h>
|
2020-03-24 13:59:12 +01:00
|
|
|
#include <kernel/devices/earlyterm.h>
|
2020-03-15 00:56:31 +01:00
|
|
|
#include <lib/string.h>
|
2020-01-05 09:00:43 +01:00
|
|
|
|
|
|
|
ssize_t vfs_read(FILE *file, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
//TODO: Check permission !!
|
|
|
|
|
|
|
|
// Check error
|
|
|
|
if (file == NULL || buf == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
// Get / check file's informations
|
2020-01-10 17:21:44 +01:00
|
|
|
if (file->private == NULL ||
|
|
|
|
file->file_op == NULL ||
|
|
|
|
file->file_op->read == NULL)
|
2020-01-05 09:00:43 +01:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
// Read with FS specifique primitive and return the numbe of reading bytes.
|
|
|
|
memset(buf, 0x00, count);
|
2020-01-14 18:41:28 +01:00
|
|
|
ssize_t read = file->file_op->read(((struct dentry*)file->private)->inode, buf, count, file->cursor);
|
2020-03-24 13:59:12 +01:00
|
|
|
if (read > 0)
|
2020-01-05 09:00:43 +01:00
|
|
|
file->cursor = file->cursor + read;
|
|
|
|
return (read);
|
|
|
|
}
|