Example #1
0
int file_dup(int fd1, int fd2)
{
	int ret;
	struct file *file1, *file2;
	if ((ret = fd2file(fd1, &file1)) != 0) {
		return ret;
	}
	if ((ret = filemap_alloc(fd2, &file2)) != 0) {
		return ret;
	}
	filemap_dup(file2, file1);
	return file2->fd;
}
Example #2
0
int
dup_fs(struct fs_struct *to, struct fs_struct *from) {
    assert(to != NULL && from != NULL);
    assert(fs_count(to) == 0 && fs_count(from) > 0);
    if ((to->pwd = from->pwd) != NULL) {
        vop_ref_inc(to->pwd);
    }
    int i;
    struct file *to_file = to->filemap, *from_file = from->filemap;
    for (i = 0; i < FS_STRUCT_NENTRY; i ++, to_file ++, from_file ++) {
        if (from_file->status == FD_OPENED) {
            /* alloc_fd first */
            to_file->status = FD_INIT;
            filemap_dup(to_file, from_file);
        }
    }
    return 0;
}