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-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-05-01 11:23:56 +02:00
|
|
|
if (file->private == NULL)
|
|
|
|
return (-2);
|
|
|
|
if (file->file_op == NULL)
|
|
|
|
return (-3);
|
|
|
|
if (file->file_op->read == NULL)
|
|
|
|
return (-4);
|
2020-03-28 19:52:59 +01:00
|
|
|
|
2020-01-05 09:00:43 +01:00
|
|
|
// Read with FS specifique primitive and return the numbe of reading bytes.
|
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);
|
|
|
|
}
|