Skip to content

Commit

Permalink
trying something
Browse files Browse the repository at this point in the history
Signed-off-by: Umer Saleem <[email protected]>
  • Loading branch information
usaleem-ix committed Sep 17, 2024
1 parent 28cd4a6 commit 5d46d9a
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions module/os/linux/zfs/zfs_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,36 @@ get_dpath(struct path *path, int len, char *full_path)
return (error);
}

static char *
construct_absolute_path(struct path *path, char *buf, int buflen)
{
char *p;
struct dentry *dentry;
struct vfsmount *mnt;

p = buf + buflen - 1;
*p = '\0';

dentry = *current->dentry->d_parent;
mnt = path->mnt;

// while (!IS_ROOT(dentry)) {
while (!IS_ROOT(dentry)) {
zfs_dbgmsg("inside loop");
int len = dentry->d_name.len;
p -= len;
if (p < buf) {
return ERR_PTR(-ENAMETOOLONG);
}
memcpy(p, dentry->d_name.name, len);
*(--p) = '/';
dentry = dentry->d_parent;
}
zfs_dbgmsg("buf: %s, p: %s", buf, p);
return p;
}


static void
get_global_namespace_path(struct path *path)
{
Expand Down Expand Up @@ -1166,8 +1196,35 @@ get_global_namespace_path(struct path *path)
zfs_dbgmsg("path in global namespace: %s", p);

revert_creds(old_cred);
put_cred(kern_cred);
//put_cred(kern_cred);
kmem_free(p, MAXPATHLEN);

char *init_path_buf;
char *chroot_path_buf;
char *relative_path;
int len;

// Allocate buffers for the paths
init_path_buf = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
chroot_path_buf = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
relative_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);

if (!init_path_buf || !chroot_path_buf || !relative_path) {
goto out;
}

// Construct the absolute paths
construct_absolute_path(&init->fs->root, init_path_buf, MAXPATHLEN);
construct_absolute_path(path, chroot_path_buf, MAXPATHLEN);

// Calculate the relative path
len = snprintf(relative_path, MAXPATHLEN, "%s", chroot_path_buf + strlen(init_path_buf));
zfs_dbgmsg("relative path: %s", relative_path);

out:
kfree(init_path_buf);
kfree(chroot_path_buf);
kfree(relative_path);
}

static int
Expand Down Expand Up @@ -1241,6 +1298,7 @@ zfsctl_snapshot_mount(struct path *path, int flags)
if (is_current_chrooted()) {
zfs_dbgmsg("We are chrooted");
get_global_namespace_path(path);

}

/*
Expand Down Expand Up @@ -1277,7 +1335,7 @@ zfsctl_snapshot_mount(struct path *path, int flags)
zfs_dbgmsg("vfs->vfs_mntpoint: %s, full_path: %s, full_name: %s, dfp: %s", zfsvfs->z_vfs->vfs_mntpoint, full_path, full_name, dfp);

argv[5] = full_name;
argv[6] = dfp;
argv[6] = full_path;
for (int x = 0; x < 8; x++) {
if (argv[x] != NULL)
zfs_dbgmsg("argv[%d]: %s", x, argv[x]);
Expand Down

0 comments on commit 5d46d9a

Please sign in to comment.