Compare commits

...
Author SHA1 Message Date
maxjivi05 073e2c47f8 Skip the link walk for mounts on file systems that cannot hold links
A mount whose source is on vfat or exFAT, or on a FUSE volume backed by
one (Android's SD card), cannot hold symbolic links, so every path in it
is plain. Each mount checks the mount table once, then its paths skip
the link walk and the follow readlink. On the SD card this removes about
two FUSE lookups per file operation.
2026-11-25 19:03:11 -05:00
maxjivi05 b10d0ad521 Check missing paths in binds from their deepest existing folder
A path below folders that do not exist fell back to a readlink of every component, one full lookup each; on a FUSE card that cost up to 8 ms per probe. The check now climbs to the deepest folder that exists and verifies that one, so links before it are still followed and nothing below it can be a link.
2026-11-25 19:03:11 -05:00
maxjivi05 b791fd997a Test link handling and plain paths inside native binds 2026-11-25 19:03:11 -05:00
maxjivi05 a1df1b7a8f Skip per-component link walk for plain paths in binds
Open the translated host path with O_PATH and compare /proc/self/fd
against it; when no link was crossed, return it without walking each
component. follow_guest_link reuses the result instead of rewriting the
path a second time. Cuts stat/open on deep SD-card files from about
5.7 ms to 1.4 ms.
2026-11-25 19:03:11 -05:00
3 changed files with 364 additions and 10 deletions

No files matched your search

+239 -8
View File
@@ -44,6 +44,7 @@ struct ddnatv_bind {
char *src, *dst;
size_t src_len, dst_len;
int identity;
int links;
int order; // position in DDNATV_BINDS: the earlier of two mounts of one folder is its guest path
};
// as many as the session has: a fixed table dropped what came after its 128th entry
@@ -56,6 +57,7 @@ static char g_hostname[65];
// link targets as paths in it, as the kernel follows them there; in the sandbox they are guest paths
static char g_link_root[PATH_MAX];
static size_t g_link_root_len = 0;
static char g_mount_table[PATH_MAX] = "/proc/self/mountinfo";
static int ddnatv_bind_longer_first(const void *a, const void *b) {
const struct ddnatv_bind *x = a, *y = b;
@@ -297,10 +299,220 @@ static int relative_link_into_bind(const char *link, const char *target, const c
// /sys/devices/droiddeck/...): proot follows them inside the guest, the kernel on Android's own /sys.
// A link met on the way to a deeper path is replaced by its target, mapped again; the last component is
// left as it is (lstat() and readlink() must see the link).
static const char *resolve_bind_links(const char *host, size_t src_len, char *buffer, size_t bufsize) {
#if defined(__aarch64__)
static long raw_open_path(const char *path, long flags) {
register long x8 __asm__("x8") = 56;
register long x0 __asm__("x0") = AT_FDCWD;
register long x1 __asm__("x1") = (long)path;
register long x2 __asm__("x2") = flags | O_PATH | O_CLOEXEC;
register long x3 __asm__("x3") = 0;
__asm__ volatile("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2), "r"(x3) : "memory");
return x0;
}
static void raw_close_fd(long fd) {
register long x8 __asm__("x8") = 57;
register long x0 __asm__("x0") = fd;
__asm__ volatile("svc #0" : "+r"(x0) : "r"(x8) : "memory");
}
static __thread const char *t_plain_host = NULL;
static __thread size_t t_plain_len = 0;
static int fd_is_at(long fd, const char *path, size_t len) {
char link[32] = "/proc/self/fd/";
char digits[24];
int nd = 0;
for (long v = fd; nd == 0 || v > 0; v /= 10) digits[nd++] = (char)('0' + v % 10);
size_t at = 14;
while (nd > 0) link[at++] = digits[--nd];
link[at] = '\0';
char real[PATH_MAX];
long n = raw_readlinkat(AT_FDCWD, link, real, sizeof(real));
return n == (long)len && memcmp(real, path, len) == 0;
}
static int prefix_has_no_links(const char *host, size_t dir_len, size_t src_len) {
char dir[PATH_MAX];
if (dir_len <= src_len || dir_len >= sizeof(dir)) return 0;
memcpy(dir, host, dir_len);
dir[dir_len] = '\0';
size_t at = dir_len;
for (;;) {
long fd = raw_open_path(dir, O_NOFOLLOW);
if (fd >= 0) {
char target[2];
int plain = fd_is_at(fd, dir, at) && raw_readlinkat((int)fd, "", target, sizeof(target)) < 0;
raw_close_fd(fd);
return plain;
}
if (fd != -ENOENT && fd != -ENOTDIR) return 0;
while (at > src_len && dir[at] != '/') at--;
if (at <= src_len) return 0;
dir[at] = '\0';
}
}
static int path_has_no_links(const char *host, size_t len, size_t dir_len, size_t src_len) {
t_plain_host = NULL;
long fd = raw_open_path(host, O_NOFOLLOW);
if (fd >= 0) {
char target[2];
int plain = fd_is_at(fd, host, len) && raw_readlinkat((int)fd, "", target, sizeof(target)) < 0;
raw_close_fd(fd);
if (plain) {
t_plain_host = host;
t_plain_len = len;
return 1;
}
return prefix_has_no_links(host, dir_len, src_len);
}
if (!prefix_has_no_links(host, dir_len, src_len)) return 0;
if (fd == -ENOENT) {
t_plain_host = host;
t_plain_len = len;
}
return 1;
}
static int known_plain(const char *host) {
int plain = t_plain_host == host && strlen(host) == t_plain_len;
t_plain_host = NULL;
return plain;
}
static int fs_type_holds_no_links(const char *type) {
return strcmp(type, "vfat") == 0 || strcmp(type, "exfat") == 0 || strcmp(type, "msdos") == 0 ||
strcmp(type, "sdfat") == 0;
}
struct mount_scan {
const char *src;
size_t src_len;
size_t best_len;
int best_plain;
int best_fuse;
char best_name[256];
int nested_links;
int lower_count;
char lower[16][256];
};
static void mount_scan_line(struct mount_scan *scan, char *line) {
char *field[5];
char *p = line;
for (int i = 0; i < 5; i++) {
while (*p == ' ') p++;
field[i] = p;
while (*p && *p != ' ') p++;
if (!*p) return;
*p++ = '\0';
}
char *sep = strstr(p, " - ");
if (!sep) return;
char *type = sep + 3;
char *source = strchr(type, ' ');
if (!source) return;
*source++ = '\0';
char *end = strchr(source, ' ');
if (end) *end = '\0';
const char *point = field[4];
size_t point_len = strlen(point);
int plain = fs_type_holds_no_links(type);
const char *name = strrchr(point, '/');
name = name ? name + 1 : point;
if (plain && strncmp(point, "/mnt/media_rw/", 14) == 0 && !strchr(point + 14, '/') && name[0] &&
strlen(name) < sizeof(scan->lower[0]) && scan->lower_count < 16)
ddnatv_copy_cstr(scan->lower[scan->lower_count++], sizeof(scan->lower[0]), name);
if (point_len > scan->src_len && is_path_prefix(point, scan->src, scan->src_len)) {
if (!plain) scan->nested_links = 1;
return;
}
int covers = point_len == 1 ? point[0] == '/' : is_path_prefix(scan->src, point, point_len);
if (!covers || (point_len < scan->best_len && scan->best_len != 0)) return;
scan->best_len = point_len;
scan->best_plain = plain;
scan->best_fuse = strcmp(type, "fuse") == 0 && strcmp(source, "/dev/fuse") == 0;
ddnatv_copy_cstr(scan->best_name, sizeof(scan->best_name), strlen(name) < sizeof(scan->best_name) ? name : "");
}
static long raw_open_read(const char *path) {
register long x8 __asm__("x8") = 56;
register long x0 __asm__("x0") = AT_FDCWD;
register long x1 __asm__("x1") = (long)path;
register long x2 __asm__("x2") = O_RDONLY | O_CLOEXEC;
register long x3 __asm__("x3") = 0;
__asm__ volatile("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2), "r"(x3) : "memory");
return x0;
}
static long raw_read_fd(long fd, char *buf, size_t size) {
register long x8 __asm__("x8") = 63;
register long x0 __asm__("x0") = fd;
register long x1 __asm__("x1") = (long)buf;
register long x2 __asm__("x2") = (long)size;
__asm__ volatile("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2) : "memory");
return x0;
}
static int mount_holds_no_links(const char *src, size_t src_len) {
if (src_len == 0 || src_len >= PATH_MAX || strpbrk(src, " \t\n\\")) return 0;
long fd = raw_open_read(g_mount_table);
if (fd < 0) return 0;
struct mount_scan *scan = calloc(1, sizeof(*scan));
if (!scan) { raw_close_fd(fd); return 0; }
scan->src = src;
scan->src_len = src_len;
char line[4096];
size_t used = 0;
int skipping = 0;
char chunk[4096];
long n;
while ((n = raw_read_fd(fd, chunk, sizeof(chunk))) > 0 || n == -EINTR) {
for (long i = 0; i < n; i++) {
char c = chunk[i];
if (c == '\n') {
if (!skipping) {
line[used] = '\0';
mount_scan_line(scan, line);
}
used = 0;
skipping = 0;
} else if (used + 1 < sizeof(line)) {
line[used++] = c;
} else {
skipping = 1;
}
}
}
raw_close_fd(fd);
int none = 0;
if (n == 0 && scan->best_len && !scan->nested_links) {
if (scan->best_plain) none = 1;
else if (scan->best_fuse && scan->best_name[0])
for (int i = 0; i < scan->lower_count && !none; i++) none = strcmp(scan->lower[i], scan->best_name) == 0;
}
free(scan);
return none;
}
static int bind_holds_no_links(struct ddnatv_bind *b) {
int state = __atomic_load_n(&b->links, __ATOMIC_RELAXED);
if (state == 0) {
state = mount_holds_no_links(b->src, b->src_len) ? 2 : 1;
__atomic_store_n(&b->links, state, __ATOMIC_RELAXED);
}
return state == 2;
}
#endif
static const char *resolve_links_after(const char *host, size_t src_len, char *buffer, size_t bufsize, int check_plain) {
#if defined(__aarch64__)
size_t len = strlen(host);
if (len >= PATH_MAX || t_bind_link_depth >= 8) return host;
const char *last = strrchr(host, '/');
size_t dir_len = last ? (size_t)(last - host) : 0;
if (check_plain && dir_len > src_len && path_has_no_links(host, len, dir_len, src_len)) return host == buffer ? buffer : host;
for (size_t i = src_len + 1; i < len; i++) {
if (host[i] != '/') continue;
char prefix[PATH_MAX];
@@ -324,18 +536,22 @@ static const char *resolve_bind_links(const char *host, size_t src_len, char *bu
return buffer;
}
#else
(void)src_len; (void)bufsize;
(void)src_len; (void)bufsize; (void)check_plain;
#endif
return host == buffer ? buffer : host;
}
static const char *resolve_bind_links(const char *host, size_t src_len, char *buffer, size_t bufsize) {
return resolve_links_after(host, src_len, buffer, bufsize, 1);
}
// Wine opens every file through its prefix's drive link (dosdevices/z: -> /), so the link must be
// followed in the guest's view even where the prefix is plain rootfs: the kernel would look for the
// rest of the path on Android's own tree. Only that component is checked, not each one of every path.
static const char *resolve_drive_links(const char *host, char *buffer, size_t bufsize) {
const char *devices = strstr(host, "/dosdevices/");
if (!devices) return host;
return resolve_bind_links(host, (size_t)(devices - host) + 11, buffer, bufsize);
return resolve_links_after(host, (size_t)(devices - host) + 11, buffer, bufsize, 0);
}
// Maps an absolute Ubuntu path into the rootfs. Returns `path` (possibly advanced past
@@ -390,7 +606,14 @@ static const char *rewrite_path_in_root(const char *path, char *buffer, size_t b
if (strstr(path + b->dst_len, "/..") && climbs_past_root("", path + b->dst_len))
return rewrite_normalized_in_root(path, buffer, bufsize);
size_t n = ddnatv_append(buffer, bufsize, 0, b->src, b->src_len);
ddnatv_append(buffer, bufsize, n, path + b->dst_len, strlen(path + b->dst_len));
n = ddnatv_append(buffer, bufsize, n, path + b->dst_len, strlen(path + b->dst_len));
#if defined(__aarch64__)
if (bind_holds_no_links(&g_binds[i])) {
t_plain_host = buffer;
t_plain_len = n;
return buffer;
}
#endif
return resolve_bind_links(buffer, b->src_len, buffer, bufsize);
}
}
@@ -455,17 +678,21 @@ static size_t link_root_guest_target(char *target, size_t len) {
// view: the kernel resolves a relative target next to the link's real place, and in a mount that is
// elsewhere (Flatpak's /run/user/0/wayland-0 -> ../../flatpak/wayland-0, where /run/flatpak/wayland-0
// is another mount). Returns `path` when it is no link.
static const char *follow_guest_link(const char *path, char *out, size_t outsz) {
static const char *follow_guest_link_host(const char *path, char *out, size_t outsz, char *host_out, size_t host_outsz) {
#if defined(__aarch64__)
const char *cur = path;
for (int depth = 0; depth < 8; depth++) {
char host_buf[PATH_MAX];
t_plain_host = NULL;
const char *host = rewrite_path_in_root(cur, host_buf, sizeof(host_buf));
// /dev/stdin and /dev/fd are mounts of /proc/self/fd, whose links ("pipe:[123]") only the kernel opens
if (strncmp(host, "/proc/", 6) == 0) return cur;
char target[PATH_MAX];
long n = raw_readlinkat(AT_FDCWD, host, target, sizeof(target) - 1);
if (n <= 0) return cur;
long n = known_plain(host) ? -EINVAL : raw_readlinkat(AT_FDCWD, host, target, sizeof(target) - 1);
if (n <= 0) {
if (host_out && cur == path) ddnatv_copy_cstr(host_out, host_outsz, host);
return cur;
}
target[n] = '\0';
n = (long)link_root_guest_target(target, (size_t)n);
char joined[PATH_MAX];
@@ -504,11 +731,15 @@ static const char *follow_guest_link(const char *path, char *out, size_t outsz)
}
return cur;
#else
(void)out; (void)outsz;
(void)out; (void)outsz; (void)host_out; (void)host_outsz;
return path;
#endif
}
static const char *follow_guest_link(const char *path, char *out, size_t outsz) {
return follow_guest_link_host(path, out, outsz, NULL, 0);
}
// On ENOENT, stat()/lstat()/readlink() retry /usr/bin <-> /bin and /usr/sbin <-> /sbin, for
// rootfs trees where bin and sbin are real directories. Returns 1 for the bin pair, 2 for the
// sbin pair (with the other spelling in `alt`), 0 when `sub` is in neither.
+6 -1
View File
@@ -37,6 +37,9 @@ static void init_ddnatv_hook(void) {
}
}
ddnatv_load_binds(getenv("DDNATV_BINDS"));
const char *mount_table = getenv("DDNATV_MOUNTINFO");
if (mount_table && mount_table[0] == '/' && strlen(mount_table) < sizeof(g_mount_table))
ddnatv_copy_cstr(g_mount_table, sizeof(g_mount_table), mount_table);
const char *exec_loader = getenv("DDNATV_EXEC");
if (exec_loader && exec_loader[0] == '/' && strlen(exec_loader) < sizeof(g_exec_loader))
ddnatv_copy_cstr(g_exec_loader, sizeof(g_exec_loader), exec_loader);
@@ -805,7 +808,9 @@ static const char *rewrite_path_follow(const char *path, char *buffer, size_t bu
path = from_source;
}
char guest[PATH_MAX];
const char *followed = follow_guest_link(path, guest, sizeof(guest));
buffer[0] = '\0';
const char *followed = follow_guest_link_host(path, guest, sizeof(guest), buffer, bufsize);
if (followed == path && buffer[0]) return buffer;
char mapped[PATH_MAX];
const char *host = rewrite_path_in_root(followed, mapped, sizeof(mapped));
// the result may be `followed` or `path` itself, which can live here
+119 -1
View File
@@ -65,6 +65,11 @@ int main(int argc, char **argv) {
printf("%s\t%s\n", argv[i], ok ? cwd : "-");
continue;
}
if (strncmp(argv[i], "lstat:", 6) == 0) {
int ok = lstat(argv[i] + 6, &st) == 0;
printf("%s\t%d\t%d\n", argv[i], ok, ok && S_ISLNK(st.st_mode));
continue;
}
if (strncmp(argv[i], "at:", 3) == 0) {
int dfd = open(argv[i] + 3, O_RDONLY | O_DIRECTORY);
printf("%s\t%d\t%d\n", argv[i], fstatat(AT_FDCWD, argv[i] + 3, &st, 0) == 0, dfd >= 0);
@@ -149,6 +154,16 @@ class NativeHookMountTest(unittest.TestCase):
private_copy = cls.private / "456/pfx/dosdevices"
private_copy.mkdir(parents=True)
os.symlink("../" * 12 + "..", private_copy / "z:")
cls.links = tmp / "links"
(cls.links / "real/sub").mkdir(parents=True)
(cls.links / "real/sub/file.txt").write_text("deep")
(cls.links / "real/sub/deeper/more").mkdir(parents=True)
(cls.links / "real/sub/deeper/more/leaf.txt").write_text("leaf")
os.symlink("real", cls.links / "dir")
os.symlink(str(cls.links / "real"), cls.links / "hostdir")
os.symlink("/etc/hostname", cls.links / "guest")
os.symlink("real/sub/file.txt", cls.links / "file")
os.symlink("/mnt/links/real", cls.links / "real/up")
cls.eqlen_src = tmp / "eqsrcdir"
cls.eqlen_dst = "/" + "d" * (len(str(cls.eqlen_src)) - 1)
eqlen_pfx = cls.eqlen_src / "123/pfx/dosdevices"
@@ -159,10 +174,15 @@ class NativeHookMountTest(unittest.TestCase):
def tearDownClass(cls):
cls.tmp.cleanup()
def run_probe(self, *args, binds=None):
def run_probe(self, *args, binds=None, mounts=None):
if binds is None:
binds = f"{self.library}:/mnt/library|{self.private}:/mnt/private|{self.eqlen_src}:{self.eqlen_dst}"
hook_env = {"DDNATV_ROOT": str(self.root), "DDNATV_BINDS": binds, "LD_PRELOAD": str(self.hook)}
if mounts is not None:
table = Path(self.tmp.name) / f"mountinfo-{len(list(Path(self.tmp.name).glob('mountinfo-*')))}"
table.write_text("".join(f"{i + 20} 1 0:{i + 40} / {point} rw - {kind} {source} rw\n"
for i, (point, kind, source) in enumerate(mounts)))
hook_env["DDNATV_MOUNTINFO"] = str(table)
env = {k: v for k, v in os.environ.items() if k not in ("LD_PRELOAD", "LOCPATH", "GCONV_PATH")}
if self.prefix:
cmd = list(self.prefix) + [arg for key, value in hook_env.items() for arg in ("-E", f"{key}={value}")]
@@ -310,6 +330,104 @@ class NativeHookMountTest(unittest.TestCase):
self.assertEqual(result[path], ["1", "library"])
self.assertEqual(result[cd], [GAME])
def test_plain_paths_in_a_mount_reach_their_files(self):
binds = f"{self.links}:/mnt/links"
paths = ["/mnt/links/real/sub/file.txt", "/mnt/links/real/sub/../sub/file.txt", "/mnt/links//real/sub/file.txt"]
result = self.run_probe(*paths, binds=binds)
for path in paths:
self.assertEqual(result[path], ["1", "deep"], path)
def test_links_inside_a_mount_are_followed_in_the_guest_view(self):
binds = f"{self.links}:/mnt/links"
paths = {"/mnt/links/dir/sub/file.txt": ["1", "deep"], "/mnt/links/hostdir/sub/file.txt": ["1", "deep"],
"/mnt/links/file": ["1", "deep"], "/mnt/links/guest": ["1", "rootfs"],
"/mnt/links/real/up/sub/file.txt": ["1", "deep"], "/mnt/links/dir/up/up/sub/file.txt": ["1", "deep"]}
result = self.run_probe(*paths, binds=binds)
for path, want in paths.items():
self.assertEqual(result[path], want, path)
def test_last_link_in_a_mount_is_seen_by_lstat(self):
binds = f"{self.links}:/mnt/links"
cases = {"lstat:/mnt/links/guest": ["1", "1"], "lstat:/mnt/links/dir": ["1", "1"],
"lstat:/mnt/links/dir/sub/file.txt": ["1", "0"], "lstat:/mnt/links/real/sub": ["1", "0"],
"lstat:/mnt/links/dir/missing": ["0", "0"]}
result = self.run_probe(*cases, binds=binds)
for case, want in cases.items():
self.assertEqual(result[case], want, case)
def test_links_above_missing_folders_in_a_mount_are_still_followed(self):
binds = f"{self.links}:/mnt/links"
paths = {"/mnt/links/real/up/sub/deeper/more/leaf.txt": ["1", "leaf"],
"/mnt/links/dir/up/sub/deeper/more/leaf.txt": ["1", "leaf"],
"/mnt/links/real/up/no/such/folder/file.txt": ["0", "-"],
"/mnt/links/dir/up/sub/no/such/file.txt": ["0", "-"]}
result = self.run_probe(*paths, binds=binds)
for path, want in paths.items():
self.assertEqual(result[path], want, path)
def test_paths_below_missing_folders_in_a_mount_stay_missing(self):
binds = f"{self.links}:/mnt/links"
paths = ["/mnt/links/real/sub/no/such/folder/file.txt", "/mnt/links/real/sub/deeper/no/file.txt",
"/mnt/links/no/such/folder", "/mnt/links/real/sub/file.txt/more/deeper",
"/mnt/links/real/sub/deeper/more/leaf.txt/x/y"]
result = self.run_probe(*paths, binds=binds)
for path in paths:
self.assertEqual(result[path], ["0", "-"], path)
self.assertEqual(self.run_probe("/mnt/links/real/sub/deeper/more/leaf.txt", binds=binds)["/mnt/links/real/sub/deeper/more/leaf.txt"], ["1", "leaf"])
def test_missing_paths_in_a_mount_stay_missing(self):
binds = f"{self.links}:/mnt/links"
paths = ["/mnt/links/real/missing", "/mnt/links/dir/missing", "/mnt/links/missing/file.txt",
"/mnt/links/real/sub/file.txt/more"]
result = self.run_probe(*paths, binds=binds)
for path in paths:
self.assertEqual(result[path], ["0", "-"], path)
def links_volume(self):
real = os.path.realpath(self.links)
return real, os.path.dirname(real), os.path.basename(real)
def test_links_in_a_mount_on_a_link_capable_filesystem_are_followed(self):
real, parent, _ = self.links_volume()
binds = f"{self.links}:/mnt/links"
paths = {"/mnt/links/guest": ["1", "rootfs"], "/mnt/links/real/up/sub/file.txt": ["1", "deep"],
"/mnt/links/dir/sub/file.txt": ["1", "deep"]}
tables = [[("/", "ext4", "/dev/root")],
[("/", "ext4", "/dev/root"), (parent, "vfat", "/dev/sdb1"), (real, "f2fs", "/dev/sda2")],
[("/", "ext4", "/dev/root"), (real, "exfat", "/dev/sdb1"), (f"{real}/real", "ext4", "/dev/sda3")],
[("/", "ext4", "/dev/root"), (real, "fuse", "/dev/fuse")],
[("/", "ext4", "/dev/root"), ("/mnt/media_rw/other", "exfat", "/dev/sdb1"), (real, "fuse", "/dev/fuse")],
[("/", "ext4", "/dev/root"), ("/mnt/media_rw/" + os.path.basename(real), "exfat", "/dev/sdb1"),
(real, "fuse", "/dev/sdb9")]]
for table in tables:
result = self.run_probe(*paths, binds=binds, mounts=table)
for path, want in paths.items():
self.assertEqual(result[path], want, (path, table))
def test_mounts_on_filesystems_without_links_skip_the_link_walk(self):
real, parent, name = self.links_volume()
binds = f"{self.links}:/mnt/links"
tables = [[("/", "ext4", "/dev/root"), (real, "exfat", "/dev/sdb1")],
[("/", "ext4", "/dev/root"), (parent, "vfat", "/dev/sdb1")],
[("/", "ext4", "/dev/root"), (real, "vfat", "/dev/sdb1"), (f"{real}/real", "exfat", "/dev/sdc1")],
[("/", "ext4", "/dev/root"), (f"/mnt/media_rw/{name}", "exfat", "/dev/sdb1"), (real, "fuse", "/dev/fuse")]]
for table in tables:
result = self.run_probe("/mnt/links/guest", "/mnt/links/real/up/sub/file.txt",
"/mnt/links/real/sub/file.txt", "/mnt/links/real/missing",
"lstat:/mnt/links/real/sub", binds=binds, mounts=table)
self.assertNotEqual(result["/mnt/links/guest"], ["1", "rootfs"], table)
self.assertEqual(result["/mnt/links/real/up/sub/file.txt"], ["0", "-"], table)
self.assertEqual(result["/mnt/links/real/sub/file.txt"], ["1", "deep"], table)
self.assertEqual(result["/mnt/links/real/missing"], ["0", "-"], table)
self.assertEqual(result["lstat:/mnt/links/real/sub"], ["1", "0"], table)
def test_a_mount_table_without_the_mount_keeps_the_link_walk(self):
binds = f"{self.links}:/mnt/links"
paths = {"/mnt/links/guest": ["1", "rootfs"], "/mnt/links/real/up/sub/file.txt": ["1", "deep"]}
result = self.run_probe(*paths, binds=binds, mounts=[])
for path, want in paths.items():
self.assertEqual(result[path], want, path)
if __name__ == "__main__":
unittest.main()