/* * AUFS support to compensate for the kernel bug * exposing branch pathnames in map_files. * * If the link points inside a branch, save the * relative pathname from the root of the mount * namespace as well as the full pathname from * globl root (/) for later use in dump_filemap() * and parse_smaps(). */ int fixup_aufs_vma_fd(struct vma_area *vma) { char path[PATH_MAX]; int len; path[0] = '.'; len = read_fd_link(vma->vm_file_fd, &path[1], sizeof path - 1); if (len < 0) return -1; len = fixup_aufs_path(&path[1], sizeof path - 1); if (len < 0) return -1; if (len > 0) { vma->aufs_rpath = xmalloc(len + 2); if (!vma->aufs_rpath) return -1; strcpy(vma->aufs_rpath, path); if (opts.root) { vma->aufs_fpath = xmalloc(strlen(opts.root) + 1 + len + 1); if (!vma->aufs_fpath) return -1; /* skip ./ in path */ sprintf(vma->aufs_fpath, "%s/%s", opts.root, &path[2]); } pr_debug("Saved AUFS paths %s and %s\n", vma->aufs_rpath, vma->aufs_fpath); } return 0; }
static char *image_name(int fd) { static char image_path[PATH_MAX]; if (read_fd_link(fd, image_path, sizeof(image_path)) > 0) return image_path; return NULL; }
int main(int argc, char *argv[]) { char path_orig[64], path_new[64]; int fd_self, fd_new; test_init(argc, argv); memset(path_orig, 0, sizeof(path_orig)); memset(path_new, 0, sizeof(path_new)); fd_self = open(nspath, O_RDONLY); if (fd_self < 0) { err("Can't open %s", nspath); return -1; } test_daemon(); test_waitsig(); if (read_fd_link(fd_self, path_orig, sizeof(path_orig))) { err("Can't fill original path"); return -1; } fd_new = open(nspath, O_RDONLY); if (fd_new < 0) { err("Can't open %s", nspath); return -1; } if (read_fd_link(fd_new, path_new, sizeof(path_new))) { err("Can't fill new path"); return -1; } if (memcmp(path_orig, path_new, sizeof(path_orig))) { fail("Paths mismatch %s %s\n", path_orig, path_new); return -1; } pass(); return 0; }
/* * AUFS support to compensate for the kernel bug * exposing branch pathnames in map_files and providing * a wrong mnt_id value in /proc/<pid>/fdinfo/<fd>. * * If the link points inside a branch, save the * relative pathname from the root of the mount * namespace as well as the full pathname from * globl root (/) for later use in dump_filemap() * and parse_smaps(). */ int fixup_aufs_vma_fd(struct vma_area *vma) { char path[PATH_MAX]; int len; path[0] = '.'; len = read_fd_link(vma->vm_file_fd, &path[1], sizeof path - 1); if (len < 0) return -1; len = fixup_aufs_path(&path[1], sizeof path - 1); if (len <= 0) return len; vma->aufs_rpath = xmalloc(len + 2); if (!vma->aufs_rpath) return -1; strcpy(vma->aufs_rpath, path); if (opts.root) { /* skip ./ in path */ vma->aufs_fpath = xsprintf("%s/%s", opts.root, &path[2]); if (!vma->aufs_fpath) return -1; } pr_debug("Saved AUFS paths %s and %s\n", vma->aufs_rpath, vma->aufs_fpath); if (stat(vma->aufs_fpath, vma->vmst) < 0) { pr_perror("Failed stat on map %"PRIx64" (%s)", vma->e->start, vma->aufs_fpath); return -1; } /* tell parse_smap() not to call get_fd_mntid() */ vma->mnt_id = -1; return len; }