Skip to content

Commit 360f961

Browse files
IlyaHanovgopherbot
authored andcommitted
unix: add API for fsconfig system call
Fixes golang/go#59537 Change-Id: I8d806ace3adad423c633813455d8f758706cee1d Reviewed-on: https://go-review.googlesource.com/c/sys/+/484995 Reviewed-by: Than McIntosh <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 7ff74af commit 360f961

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

unix/linux/types.go

+9
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,15 @@ const (
989989
FSPICK_EMPTY_PATH = C.FSPICK_EMPTY_PATH
990990

991991
FSMOUNT_CLOEXEC = C.FSMOUNT_CLOEXEC
992+
993+
FSCONFIG_SET_FLAG = C.FSCONFIG_SET_FLAG
994+
FSCONFIG_SET_STRING = C.FSCONFIG_SET_STRING
995+
FSCONFIG_SET_BINARY = C.FSCONFIG_SET_BINARY
996+
FSCONFIG_SET_PATH = C.FSCONFIG_SET_PATH
997+
FSCONFIG_SET_PATH_EMPTY = C.FSCONFIG_SET_PATH_EMPTY
998+
FSCONFIG_SET_FD = C.FSCONFIG_SET_FD
999+
FSCONFIG_CMD_CREATE = C.FSCONFIG_CMD_CREATE
1000+
FSCONFIG_CMD_RECONFIGURE = C.FSCONFIG_CMD_RECONFIGURE
9921001
)
9931002

9941003
type OpenHow C.struct_open_how

unix/syscall_linux.go

+99
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,105 @@ func Dup2(oldfd, newfd int) error {
18491849
//sys Fsmount(fd int, flags int, mountAttrs int) (fsfd int, err error)
18501850
//sys Fsopen(fsName string, flags int) (fd int, err error)
18511851
//sys Fspick(dirfd int, pathName string, flags int) (fd int, err error)
1852+
1853+
//sys fsconfig(fd int, cmd uint, key *byte, value *byte, aux int) (err error)
1854+
1855+
func fsconfigCommon(fd int, cmd uint, key string, value *byte, aux int) (err error) {
1856+
var keyp *byte
1857+
if keyp, err = BytePtrFromString(key); err != nil {
1858+
return
1859+
}
1860+
return fsconfig(fd, cmd, keyp, value, aux)
1861+
}
1862+
1863+
// FsconfigSetFlag is equivalent to fsconfig(2) called
1864+
// with cmd == FSCONFIG_SET_FLAG.
1865+
//
1866+
// fd is the filesystem context to act upon.
1867+
// key the parameter key to set.
1868+
func FsconfigSetFlag(fd int, key string) (err error) {
1869+
return fsconfigCommon(fd, FSCONFIG_SET_FLAG, key, nil, 0)
1870+
}
1871+
1872+
// FsconfigSetString is equivalent to fsconfig(2) called
1873+
// with cmd == FSCONFIG_SET_STRING.
1874+
//
1875+
// fd is the filesystem context to act upon.
1876+
// key the parameter key to set.
1877+
// value is the parameter value to set.
1878+
func FsconfigSetString(fd int, key string, value string) (err error) {
1879+
var valuep *byte
1880+
if valuep, err = BytePtrFromString(value); err != nil {
1881+
return
1882+
}
1883+
return fsconfigCommon(fd, FSCONFIG_SET_STRING, key, valuep, 0)
1884+
}
1885+
1886+
// FsconfigSetBinary is equivalent to fsconfig(2) called
1887+
// with cmd == FSCONFIG_SET_BINARY.
1888+
//
1889+
// fd is the filesystem context to act upon.
1890+
// key the parameter key to set.
1891+
// value is the parameter value to set.
1892+
func FsconfigSetBinary(fd int, key string, value []byte) (err error) {
1893+
if len(value) == 0 {
1894+
return EINVAL
1895+
}
1896+
return fsconfigCommon(fd, FSCONFIG_SET_BINARY, key, &value[0], len(value))
1897+
}
1898+
1899+
// FsconfigSetPath is equivalent to fsconfig(2) called
1900+
// with cmd == FSCONFIG_SET_PATH.
1901+
//
1902+
// fd is the filesystem context to act upon.
1903+
// key the parameter key to set.
1904+
// path is a non-empty path for specified key.
1905+
// atfd is a file descriptor at which to start lookup from or AT_FDCWD.
1906+
func FsconfigSetPath(fd int, key string, path string, atfd int) (err error) {
1907+
var valuep *byte
1908+
if valuep, err = BytePtrFromString(path); err != nil {
1909+
return
1910+
}
1911+
return fsconfigCommon(fd, FSCONFIG_SET_PATH, key, valuep, atfd)
1912+
}
1913+
1914+
// FsconfigSetPathEmpty is equivalent to fsconfig(2) called
1915+
// with cmd == FSCONFIG_SET_PATH_EMPTY. The same as
1916+
// FconfigSetPath but with AT_PATH_EMPTY implied.
1917+
func FsconfigSetPathEmpty(fd int, key string, path string, atfd int) (err error) {
1918+
var valuep *byte
1919+
if valuep, err = BytePtrFromString(path); err != nil {
1920+
return
1921+
}
1922+
return fsconfigCommon(fd, FSCONFIG_SET_PATH_EMPTY, key, valuep, atfd)
1923+
}
1924+
1925+
// FsconfigSetFd is equivalent to fsconfig(2) called
1926+
// with cmd == FSCONFIG_SET_FD.
1927+
//
1928+
// fd is the filesystem context to act upon.
1929+
// key the parameter key to set.
1930+
// value is a file descriptor to be assigned to specified key.
1931+
func FsconfigSetFd(fd int, key string, value int) (err error) {
1932+
return fsconfigCommon(fd, FSCONFIG_SET_FD, key, nil, value)
1933+
}
1934+
1935+
// FsconfigCreate is equivalent to fsconfig(2) called
1936+
// with cmd == FSCONFIG_CMD_CREATE.
1937+
//
1938+
// fd is the filesystem context to act upon.
1939+
func FsconfigCreate(fd int) (err error) {
1940+
return fsconfig(fd, FSCONFIG_CMD_CREATE, nil, nil, 0)
1941+
}
1942+
1943+
// FsconfigReconfigure is equivalent to fsconfig(2) called
1944+
// with cmd == FSCONFIG_CMD_RECONFIGURE.
1945+
//
1946+
// fd is the filesystem context to act upon.
1947+
func FsconfigReconfigure(fd int) (err error) {
1948+
return fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, nil, nil, 0)
1949+
}
1950+
18521951
//sys Getdents(fd int, buf []byte) (n int, err error) = SYS_GETDENTS64
18531952
//sysnb Getpgid(pid int) (pgid int, err error)
18541953

unix/zsyscall_linux.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)