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

Trailing slash is removed by proot-rs #41

Closed
Tracked by #45
imlk0 opened this issue Jul 22, 2021 · 2 comments
Closed
Tracked by #45

Trailing slash is removed by proot-rs #41

imlk0 opened this issue Jul 22, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@imlk0
Copy link
Collaborator

imlk0 commented Jul 22, 2021

proot-rs is currently not aware of the / at the end of the path during path translation. This causes the behavior of ls to be inconsistent with that on host.

inside guestfs:

image
in hostfs:

image

This issue and #40 are both related to handling trailing slash

@imlk0
Copy link
Collaborator Author

imlk0 commented Jul 22, 2021

Document the steps to solve this problem:

  • The expected behavior:

    image

    image

    image

    image

  • Causes of this issue:

    The reason is similar to the one of the previous issue.

    When translating a path, proot-rs needs to create a new path by iterating over the components in the path (with Path::components() ). However, the trailing slash is not shown in the results of Path::components(), with is a flaw in the implementation of the rust standard library.
    stdlib Path has inconsistent normalisation behaviour rust-lang/rust#29008 (comment)

  • According to POSIX

    A pathname that contains at least one non- character and that ends with one or more trailing characters shall not be resolved successfully unless the last pathname component before the trailing characters names an existing directory or a directory entry that is to be created for a directory immediately after the pathname is resolved. Interfaces using pathname resolution may specify additional constraints1 when a pathname that does not name an existing directory contains at least one non- character and contains one or more trailing characters.
    If a symbolic link is encountered during pathname resolution, the behavior shall depend on whether the pathname component is at the end of the pathname and on the function being performed. If all of the following are true, then pathname resolution is complete:
    - This is the last pathname component of the pathname.
    - The pathname has no trailing .
    - The function is required to act on the symbolic link itself, or certain arguments direct that the function act on the symbolic link itself.

  • Something maybe helpful: https://elixir.bootlin.com/linux/latest/source/fs/namei.c#L97

      ```rust
      /* [Feb-Apr 2000 AV] Complete rewrite. Rules for symlinks:
       *	inside the path - always follow.
       *	in the last component in creation/removal/renaming - never follow.
       *	if LOOKUP_FOLLOW passed - follow.
       *	if the pathname has trailing slashes - follow.
       *	otherwise - don't follow.
       * (applied in that order).
      */
      ```
    
  • Way to fix:

    • Extend PathBuf to add two functions:
      • fn with_trailing_slash(&self) -> bool;: Check if this path contains trailing slash.
      • try_add_trailing_slash(&mut self);: Add a trailing slash ("/") to PathBuf.
    • In path translation function translate_absolute_path():
      • Add a appropriate slash to the end of translated path, so that trailing slash will not be eaten by proot-rs.
    • In enter() function of each path related syscalls:
      • Add trailing slash as a consideration for whether to follow the last component

    image

@imlk0 imlk0 self-assigned this Jul 22, 2021
@imlk0 imlk0 added the bug label Jul 22, 2021
@imlk0 imlk0 added this to the v0.0.1 milestone Jul 22, 2021
@imlk0
Copy link
Collaborator Author

imlk0 commented Jul 27, 2021

Fixed in commit 6db9b17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant