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

x/sys/unix: O_PATH & O_TMPFILE aren't defined on Linux #7830

Closed
gopherbot opened this issue Apr 21, 2014 · 4 comments
Closed

x/sys/unix: O_PATH & O_TMPFILE aren't defined on Linux #7830

gopherbot opened this issue Apr 21, 2014 · 4 comments

Comments

@gopherbot
Copy link

by joejob357:

go version devel +7da10a02f6dd Sun Apr 20 11:02:01 2014 +0200 linux/amd64

Linux defines the constants O_PATH (as of v2.6.39) and O_TMPFILE (as of v3.11), but
neither are exposed by the syscall package. Running src/pkg/syscall/mkerrors.sh
correctly picks up O_PATH, but not O_TMPFILE. Perhaps this is because of how it is
defined:

  #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)

(in /usr/src/linux-headers-3.13-1-common/include/uapi/asm-generic/fcntl.h)
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.4.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 18, 2014

Comment 2:

package syscall is frozen so these constants will never appear there. Perhaps they
should appear in go.sys/unix.

Labels changed: added repo-sys, release-none, removed repo-main, release-go1.4.

@mikioh mikioh changed the title go.sys/unix: O_PATH & O_TMPFILE aren't defined on Linux unix: O_PATH & O_TMPFILE aren't defined on Linux Jan 7, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title unix: O_PATH & O_TMPFILE aren't defined on Linux x/sys/unix: O_PATH & O_TMPFILE aren't defined on Linux Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-sys label Apr 14, 2015
wking added a commit to ipfs/kubo that referenced this issue Jun 24, 2015
On Linux, open() will follow symlinks unless you use the O_NOFOLLOW
flag (added in Linux 2.1.126).  Then it will error out with ELOOP
unless you've set O_PATH.  Unfortunately, Go doesn't define O_PATH and
has no plans to do so [1].

The other tricky bit here is extracting the errno [2] from the
*PathError [3] returned by os.Open [4].  The new files.Errno tries to
cast the error instance to an *os.PathError.  If that succeeds, it
looks at the *os.PathError's Err attribute and tries to cast that to
an Errno.  If that succeeds it returns the extracted errno.

With this commit, we now have File object for the symlinks with the
correct filename and mode.  I've also created a string-based reader to
pass along the link target, so the adder will have it available when
it gains support for these types of files.

[1]: golang/go#7830
[2]: https://golang.org/pkg/syscall/#Errno
[3]: https://golang.org/pkg/os/#PathError
[4]: https://golang.org/pkg/os/#Open

License: MIT
Signed-off-by: W. Trevor King <wking@tremily.us>
@cmarcelo
Copy link
Contributor

O_PATH is already exported.

I've made a CL for O_TMPFILE: https://go-review.googlesource.com/#/c/21003/

@gopherbot
Copy link
Author

CL https://golang.org/cl/21003 mentions this issue.

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

No branches or pull requests

4 participants