mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
filesystem seek
This commit is contained in:
parent
dee0e4b0ab
commit
03c5cb09b5
@ -396,12 +396,13 @@ void nn_fs_seek(nn_filesystem *fs, void *_, nn_component *component, nn_computer
|
||||
// size_t capacity = fs->spaceTotal(component, fs->userdata);
|
||||
int moved = 0;
|
||||
|
||||
/* size_t pos = */ fs->seek(component, fs->userdata, fd, whence, off, &moved);
|
||||
size_t pos = fs->seek(component, fs->userdata, fd, whence, off, &moved);
|
||||
if(moved < 0) moved = -moved;
|
||||
|
||||
// do not ask where it comes from, balance is hard
|
||||
nn_fs_readCost(fs, 1, component, computer);
|
||||
nn_fs_seekCost(fs, nn_fs_countChunks(fs, moved, component), component, computer);
|
||||
nn_return_integer(computer, pos);
|
||||
}
|
||||
|
||||
void nn_loadFilesystemTable(nn_universe *universe) {
|
||||
|
@ -181,6 +181,20 @@ size_t ne_fs_read(nn_component *component, ne_fs *fs, int fd, char *buf, size_t
|
||||
return fread(buf, sizeof(char), required, f);
|
||||
}
|
||||
|
||||
size_t ne_fs_seek(nn_component *component, ne_fs *fs, int fd, const char *whence, int off, int *moved) {
|
||||
FILE *f = fs->files[fd];
|
||||
*moved = 0;
|
||||
int w = SEEK_SET;
|
||||
if(strcmp(whence, "cur") == 0) {
|
||||
w = SEEK_CUR;
|
||||
}
|
||||
if(strcmp(whence, "end") == 0) {
|
||||
w = SEEK_END;
|
||||
}
|
||||
fseek(f, w, off);
|
||||
return ftell(f);
|
||||
}
|
||||
|
||||
char **ne_fs_list(nn_Alloc *alloc, nn_component *component, ne_fs *fs, const char *path, size_t *len) {
|
||||
const char *p = ne_fs_diskPath(component, path);
|
||||
if(p[0] == '/') p++;
|
||||
@ -628,7 +642,7 @@ int main() {
|
||||
.close = (void *)ne_fs_close,
|
||||
.write = (void *)ne_fs_write,
|
||||
.read = (void *)ne_fs_read,
|
||||
.seek = NULL,
|
||||
.seek = (void *)ne_fs_seek,
|
||||
};
|
||||
nn_addFileSystem(computer, "OpenOS", 1, &genericFS);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user