Skip to content

Commit 0a5406a

Browse files
kolyshkintklauser
authored andcommitted
unix: add mount_setattr support for linux
This brings in mount_setattr(2) support, added to Linux 5.12 kernel and documented at https://man7.org/linux/man-pages/man2/mount_setattr.2.html Change-Id: I5609980c18aef80f9429a8c8cec8c1e129f74ab7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/363444 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]>
1 parent 0c823b9 commit 0a5406a

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

unix/linux/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ const (
877877
AT_STATX_FORCE_SYNC = C.AT_STATX_FORCE_SYNC
878878
AT_STATX_DONT_SYNC = C.AT_STATX_DONT_SYNC
879879

880+
AT_RECURSIVE = C.AT_RECURSIVE
881+
880882
AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
881883
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
882884

@@ -3865,3 +3867,7 @@ const (
38653867
SHM_RDONLY = C.SHM_RDONLY
38663868
SHM_RND = C.SHM_RND
38673869
)
3870+
3871+
// mount_setattr
3872+
3873+
type MountAttr C.struct_mount_attr

unix/mkerrors.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ struct ltchars {
239239
#include <linux/magic.h>
240240
#include <linux/memfd.h>
241241
#include <linux/module.h>
242+
#include <linux/mount.h>
242243
#include <linux/netfilter/nfnetlink.h>
243244
#include <linux/netlink.h>
244245
#include <linux/net_namespace.h>
@@ -520,7 +521,7 @@ ccflags="$@"
520521
$2 ~ /^HW_MACHINE$/ ||
521522
$2 ~ /^SYSCTL_VERS/ ||
522523
$2 !~ "MNT_BITS" &&
523-
$2 ~ /^(MS|MNT|UMOUNT)_/ ||
524+
$2 ~ /^(MS|MNT|MOUNT|UMOUNT)_/ ||
524525
$2 ~ /^NS_GET_/ ||
525526
$2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
526527
$2 ~ /^(O|F|[ES]?FD|NAME|S|PTRACE|PT|TFD)_/ ||

unix/syscall_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,16 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
17751775
return mount(source, target, fstype, flags, datap)
17761776
}
17771777

1778+
//sys mountSetattr(dirfd int, pathname string, flags uint, attr *MountAttr, size uintptr) (err error) = SYS_MOUNT_SETATTR
1779+
1780+
// MountSetattr is a wrapper for mount_setattr(2).
1781+
// https://man7.org/linux/man-pages/man2/mount_setattr.2.html
1782+
//
1783+
// Requires kernel >= 5.12.
1784+
func MountSetattr(dirfd int, pathname string, flags uint, attr *MountAttr) error {
1785+
return mountSetattr(dirfd, pathname, flags, attr, unsafe.Sizeof(*attr))
1786+
}
1787+
17781788
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
17791789
if raceenabled {
17801790
raceReleaseMerge(unsafe.Pointer(&ioSync))

unix/zerrors_linux.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_linux.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)