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: missing ST_NOEXEC etc statfs constants #25341

Closed
bradfitz opened this issue May 10, 2018 · 3 comments
Closed

x/sys/unix: missing ST_NOEXEC etc statfs constants #25341

bradfitz opened this issue May 10, 2018 · 3 comments

Comments

@bradfitz
Copy link
Contributor

I needed the ST_NOEXEC constant for statfs, but found it missing in x/sys/unix.

I tried the obvious,

$ git di
diff --git a/unix/linux/types.go b/unix/linux/types.go
index 3bc7035..d4ec87a 100644
--- a/unix/linux/types.go
+++ b/unix/linux/types.go
@@ -46,6 +46,7 @@ package unix
 #include <sys/user.h>
 #include <sys/utsname.h>
 #include <sys/wait.h>
+#include <sys/vfs.h>
 #include <linux/filter.h>
 #include <linux/icmpv6.h>
 #include <linux/keyctl.h>
@@ -337,8 +338,6 @@ type _Gid_t C.gid_t
 
 type Stat_t C.struct_stat
 
-type Statfs_t C.struct_statfs
-
 type StatxTimestamp C.struct_statx_timestamp
 
 type Statx_t C.struct_statx
@@ -972,3 +971,19 @@ type HDDriveCmdHdr C.struct_hd_drive_cmd_hdr
 type HDGeometry C.struct_hd_geometry
        
 type HDDriveID C.struct_hd_driveid
+       
+// Statfs
+       
+type Statfs_t C.struct_statfs
+
+const (
+       ST_MANDLOCK    = C.ST_MANDLOCK
+       ST_NOATIME     = C.ST_NOATIME
+       ST_NODEV       = C.ST_NODEV
+       ST_NODIRATIME  = C.ST_NODIRATIME
+       ST_NOEXEC      = C.ST_NOEXEC
+       ST_NOSUID      = C.ST_NOSUID
+       ST_RDONLY      = C.ST_RDONLY
+       ST_RELATIME    = C.ST_RELATIME
+       ST_SYNCHRONOUS = C.ST_SYNCHRONOUS
+)

but I got:

/build/linux/types.go:980:19: could not determine kind of name for C.ST_MANDLOCK
/build/linux/types.go:981:19: could not determine kind of name for C.ST_NOATIME
/build/linux/types.go:982:19: could not determine kind of name for C.ST_NODEV
/build/linux/types.go:983:19: could not determine kind of name for C.ST_NODIRATIME
/build/linux/types.go:984:19: could not determine kind of name for C.ST_NOEXEC
/build/linux/types.go:985:19: could not determine kind of name for C.ST_NOSUID
/build/linux/types.go:986:19: could not determine kind of name for C.ST_RDONLY
/build/linux/types.go:987:19: could not determine kind of name for C.ST_RELATIME
/build/linux/types.go:988:19: could not determine kind of name for C.ST_SYNCHRONOUS

I then went to search how they were defined and found https://elixir.bootlin.com/linux/latest/source/include/linux/statfs.h#L33

/*
 * Definitions for the flag in f_flag.
 *
 * Generally these flags are equivalent to the MS_ flags used in the mount
 * ABI.  The exception is ST_VALID which has the same value as MS_REMOUNT
 * which doesn't make any sense for statfs.
 */
#define ST_RDONLY	0x0001	/* mount read-only */
#define ST_NOSUID	0x0002	/* ignore suid and sgid bits */
#define ST_NODEV	0x0004	/* disallow access to device special files */
#define ST_NOEXEC	0x0008	/* disallow program execution */
...

And I discovered we do have MS_NOEXEC, so that'll do for now.

But it'd be nice to also have the ST_ names in there, even if they're the same. It would save others this distraction in the future.

/cc @tklauser

@gopherbot gopherbot added this to the Unreleased milestone May 10, 2018
@bradfitz
Copy link
Contributor Author

Also, the *_MAGIC constants on Linux would be nice: http://man7.org/linux/man-pages/man2/statfs.2.html

           TMPFS_MAGIC           0x01021994

@tklauser
Copy link
Member

It seems sys/vfs.h doesn't include bits/statvfs. (or sys/statvfs.h for that matter) where these constants are defined. Replacing #include <sys/vfs.h> with #include <sys/statvfs.h> seems to do the trick. I'll send a CL, also adding the *_MAGIC constants.

@gopherbot
Copy link

Change https://golang.org/cl/112696 mentions this issue: unix: add statfs and filesystem magic constants on Linux

@golang golang locked and limited conversation to collaborators May 11, 2019
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

3 participants