wasi-filesystem icon indicating copy to clipboard operation
wasi-filesystem copied to clipboard

No st_mode from stat?

Open corwin-of-amber opened this issue 5 years ago • 3 comments

The internal struct used by stat calls does not have a field for the mode of the file (read/write/execute bits), and stat, lstat, fstat, fstatat all return zeros for these bits. The implementer of the API has no control over that.

https://github.com/CraneStation/wasi-libc/blob/12f5832b45c7450f8320db271334081247191d58/libc-bottom-half/headers/public/wasi/api.h#L955

Most of the time it's alright, but some code checks file permissions occasionally (esp. execute permission) and behaves unexpectedly when the permissions set in st_mode are in fact lower than the actual permissions for the file.

E.g. excerpt from kpathsea:

      if (stat (name, &s) == 0 && s.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)
                               /* Do not stop at directories. */
                               && !S_ISDIR(s.st_mode))
        self = name;
      else
        free (name);

corwin-of-amber avatar Jan 26 '20 19:01 corwin-of-amber

WASI recently added a way to set permissions on a file; we should consider adding a simple way to retrieve the permissions on a file too, which would allow us to implement this.

sunfishcode avatar Feb 27 '20 00:02 sunfishcode

I just came across this bug again :D is there any way to do this now?

Looks like stat_impl.h has to be modified to support it: https://github.com/WebAssembly/wasi-libc/blob/659ff414560721b1660a19685110e484a081c3d4/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h

corwin-of-amber avatar Aug 30 '21 16:08 corwin-of-amber

This needs WASI support first, and then we can add libc support for it. WASI has been focused on lower-level areas of the design lately, so we haven't had a chance to add this yet.

One question here is: what should implementations on Windows put in this field?

sunfishcode avatar Aug 30 '21 22:08 sunfishcode