mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
file: fd_clone
This commit is contained in:
@@ -131,3 +131,29 @@ int fd_close(int fd) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fd_clone(proc_t *targproc) {
|
||||||
|
proc_t *proc = _cpu()->thread->proc;
|
||||||
|
int error = 0;
|
||||||
|
spinlock_acquire(&proc->fdlock);
|
||||||
|
|
||||||
|
targproc->fdcount = proc->fdcount;
|
||||||
|
targproc->fdfirst = proc->fdfirst;
|
||||||
|
targproc->fd = alloc(proc->fdcount * sizeof(fd_t));
|
||||||
|
if (targproc->fd == NULL) {
|
||||||
|
error = ENOMEM;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < targproc->fdcount; ++i) {
|
||||||
|
if (proc->fd[i].file == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
targproc->fd[i] = proc->fd[i];
|
||||||
|
FILE_HOLD(targproc->fd[i].file);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
spinlock_release(&proc->fdlock);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ void fd_release(file_t *file);
|
|||||||
int fd_new(int flags, file_t **file, int *fd);
|
int fd_new(int flags, file_t **file, int *fd);
|
||||||
int fd_close(int fd);
|
int fd_close(int fd);
|
||||||
int fd_dup(int oldfd, int newfd, bool exact, int flags, int *ret);
|
int fd_dup(int oldfd, int newfd, bool exact, int flags, int *ret);
|
||||||
|
int fd_clone(proc_t *proc);
|
||||||
|
|
||||||
#define FILE_READ 1
|
#define FILE_READ 1
|
||||||
#define FILE_WRITE 2
|
#define FILE_WRITE 2
|
||||||
|
|||||||
Reference in New Issue
Block a user