Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support substitution #1716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions fs/adhoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ struct fd *adhoc_fd_create(const struct fd_ops *ops) {
return fd;
}

static struct fd *adhoc_open(struct mount *UNUSED(mount), const char *path, int UNUSED(flags), int UNUSED(mode)) {
if (*path != '/') {
return ERR_PTR(_EBADF);
}
char fdstr[MAX_NAME];
strcpy(fdstr, path+1);
fd_t nfd = atol(fdstr);
if (nfd < 0) {
return ERR_PTR(_EBADF);
}

return fd_retain(f_get(nfd));
}

static int adhoc_stat(struct mount *UNUSED(mount), const char *path, struct statbuf *stat) {
if (*path != '/') {
return _EBADF;
}
char fdstr[MAX_NAME];
strcpy(fdstr, path+1);
fd_t nfd = atol(fdstr);
if (nfd < 0) {
return _EBADF;
}
struct fd* fd = f_get(nfd);
return fd->mount->fs->fstat(fd, stat);
}

static int adhoc_fstat(struct fd *fd, struct statbuf *stat) {
*stat = fd->stat;
return 0;
Expand Down Expand Up @@ -57,6 +85,8 @@ static const struct fs_ops adhoc_fs = {
.fstat = adhoc_fstat,
.fsetattr = adhoc_fsetattr,
.getpath = adhoc_getpath,
.open = adhoc_open,
.stat = adhoc_stat,
};

static struct mount adhoc_mount = {
Expand Down
32 changes: 32 additions & 0 deletions fs/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@

struct mount *find_mount_and_trim_path(char *path) {
struct mount *mount = mount_find(path);
// trying to be clever here ...
// if we're opening something like:
// /proc/self/fd/xxx
// - or -
// /proc/<current pid>/fd/xxx
// we should check whether it's a adhoc_fd, like pipes etc.
// do not let proc hanle their io, working around issue #164
if (mount->fs == &procfs) {
char fdstr[MAX_NAME];
*fdstr = '\0';
if (strncmp(path, "/proc/self/fd/", 14) == 0) {
strcpy(fdstr, path + 13);
} else {
char s[MAX_PATH];
sprintf(s, "/proc/%d/fd/", current->pid);
if (strncmp(path, s, strlen(s)) == 0) {
strcpy(fdstr, path + strlen(s) - 1);
}
}
if (*fdstr != '\0') {
// parse fd and check whether it's adhoc_fd
fd_t nfd = atol(fdstr);
if (nfd >= 0) {
struct fd* fd = f_get(nfd);
if (!IS_ERR(fd) && is_adhoc_fd(fd)) {
strcpy(path, fdstr);
return fd->mount;
}
}
}
}
// should not be opening any adhoc_fd, continue normally
char *dst = path;
const char *src = path + strlen(mount->point);
while (*src != '\0')
Expand Down