mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
vfs and tmpfs read
This commit is contained in:
+14
-1
@@ -53,6 +53,19 @@ static int tmpfs_write(int* error, vnode_t* node, void* buff, size_t count, size
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tmpfs_read(int *error, vnode_t* node, void* buff, size_t count, size_t offset){
|
||||||
|
|
||||||
|
size_t sizemax = node->st.st_size - offset;
|
||||||
|
|
||||||
|
if(count > sizemax)
|
||||||
|
count = sizemax;
|
||||||
|
|
||||||
|
memcpy(buff, node->fsdata, count);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static int tmpfs_unmount(fs_t* fs) UNIMPLEMENTED
|
static int tmpfs_unmount(fs_t* fs) UNIMPLEMENTED
|
||||||
static int tmpfs_open(dirnode_t* parent, char* name) UNIMPLEMENTED
|
static int tmpfs_open(dirnode_t* parent, char* name) UNIMPLEMENTED
|
||||||
static int tmpfs_close(vnode_t* node) UNIMPLEMENTED
|
static int tmpfs_close(vnode_t* node) UNIMPLEMENTED
|
||||||
@@ -110,7 +123,7 @@ static int tmpfs_create(dirnode_t* parent, char* name, mode_t mode){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fscalls_t funcs = {
|
static fscalls_t funcs = {
|
||||||
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create, tmpfs_write
|
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create, tmpfs_write, tmpfs_read
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+29
-5
@@ -60,11 +60,15 @@ int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset
|
|||||||
|
|
||||||
int type = GETTYPE(node->st.st_mode);
|
int type = GETTYPE(node->st.st_mode);
|
||||||
|
|
||||||
if(type == TYPE_DIR || type == TYPE_LINK)
|
if(type == TYPE_DIR || type == TYPE_LINK){
|
||||||
return EINVAL;
|
*error = EINVAL;
|
||||||
|
return -1;
|
||||||
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV)
|
}
|
||||||
return ENOSYS; // TODO change this when the device manager is implemented :)
|
|
||||||
|
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
||||||
|
*error = ENOSYS;
|
||||||
|
return -1; // TODO change this when the device manager is implemented :)
|
||||||
|
}
|
||||||
|
|
||||||
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
||||||
|
|
||||||
@@ -72,6 +76,26 @@ int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vfs_read(int* error, vnode_t* node, void* buff, size_t count, size_t offset){
|
||||||
|
|
||||||
|
int type = GETTYPE(node->st.st_mode);
|
||||||
|
|
||||||
|
if(type == TYPE_DIR || type == TYPE_LINK){
|
||||||
|
*error = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
||||||
|
*error = ENOSYS;
|
||||||
|
return -1; // TODO change this when the device manager is implemented :)
|
||||||
|
}
|
||||||
|
|
||||||
|
int readcount = node->fs->calls->read(error, node, buff, count, offset);
|
||||||
|
|
||||||
|
return readcount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int vfs_close(vnode_t* node){
|
int vfs_close(vnode_t* node){
|
||||||
|
|
||||||
vfs_releasenode(node);
|
vfs_releasenode(node);
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ typedef struct _fscalls_t {
|
|||||||
int (*create)(dirnode_t* parent, char* name, mode_t mode);
|
int (*create)(dirnode_t* parent, char* name, mode_t mode);
|
||||||
// write to a file
|
// write to a file
|
||||||
int (*write)(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
int (*write)(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
||||||
|
// read from a file
|
||||||
|
int (*read)(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
||||||
} fscalls_t;
|
} fscalls_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +66,7 @@ int vfs_close(vnode_t* node);
|
|||||||
int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode);
|
int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode);
|
||||||
int vfs_create(dirnode_t* ref, char* path, mode_t mode);
|
int vfs_create(dirnode_t* ref, char* path, mode_t mode);
|
||||||
int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
||||||
|
int vfs_read(int* error, vnode_t* node, void* buff, size_t count, size_t offset);
|
||||||
|
|
||||||
void vfs_init();
|
void vfs_init();
|
||||||
dirnode_t* vfs_root();
|
dirnode_t* vfs_root();
|
||||||
|
|||||||
Reference in New Issue
Block a user