void drawactive(int);
void drawcmap(void);
void dumpstack(void);
-struct fgrp *dupfgrp(struct fgrp *);
+struct fgrp *dupfgrp(struct proc *, struct fgrp *);
void egrpcpy(struct egrp *, struct egrp *);
int emptystr(char *unused_char_p_t);
int eqchan(struct chan *, struct chan *, int);
int put_fd(struct files_struct *open_files, int file_desc);
int get_fd(struct files_struct *open_files, int low_fd);
+int claim_fd(struct files_struct *open_files, int file_desc);
#endif /* ROS_KERN_VFS_H */
return new;
}
-struct fgrp *dupfgrp(struct fgrp *f)
+struct fgrp *dupfgrp(struct proc *new_proc, struct fgrp *f)
{
int i;
struct chan *c;
for (i = 0; i <= f->maxfd; i++) {
if ((c = f->fd[i])) {
kref_get(&c->ref, 1);
+ claim_fd(&new_proc->open_files, i);
new->fd[i] = c;
}
}
cclose(c[1]);
if (fd[0] >= 0) {
/* VFS hack */
- put_fd(¤t->open_files, fd[0]);
f->fd[fd[0]] = 0;
+ put_fd(¤t->open_files, fd[0]);
}
if (fd[1] >= 0) {
/* VFS hack */
- put_fd(¤t->open_files, fd[1]);
f->fd[fd[1]] = 0;
+ put_fd(¤t->open_files, fd[1]);
}
poperror();
return -1;
}
/* Copy semantics: do not change this without revisiting proc_destroy,
* close_9ns_files, and closefgrp. */
- new_proc->fgrp = dupfgrp(parent->fgrp);
+ new_proc->fgrp = dupfgrp(new_proc, parent->fgrp);
/* Shared semantics */
kref_get(&parent->pgrp->ref, 1);
new_proc->pgrp = parent->pgrp;
return slot;
}
+/* Claims a specific FD when duping FDs. used by 9ns. < 0 == error. */
+int claim_fd(struct files_struct *open_files, int file_desc)
+{
+ if ((file_desc < 0) || (file_desc > NR_FILE_DESC_MAX))
+ return -EINVAL;
+ if (open_files->closed)
+ return -EINVAL; /* won't matter, they are dying */
+ if (GET_BITMASK_BIT(open_files->open_fds->fds_bits, file_desc))
+ return -ENFILE; /* Should never really happen. Here to catch bugs. */
+
+ SET_BITMASK_BIT(open_files->open_fds->fds_bits, file_desc);
+ assert(file_desc < open_files->max_files && open_files->fd[0].fd_file == 0);
+ if (file_desc >= open_files->next_fd)
+ open_files->next_fd = file_desc + 1;
+ return 0;
+}
+
/* Inserts the file in the files_struct, returning the corresponding new file
* descriptor, or an error code. We start looking for open fds from low_fd. */
int insert_file(struct files_struct *open_files, struct file *file, int low_fd)