@@ -17,16 +17,18 @@ package lisafs
1717import (
1818 "fmt"
1919 "math"
20+ "os"
2021 "strings"
2122
2223 "golang.org/x/sys/unix"
2324 "gvisor.dev/gvisor/pkg/abi/linux"
2425 "gvisor.dev/gvisor/pkg/cleanup"
26+ "gvisor.dev/gvisor/pkg/errors"
27+ "gvisor.dev/gvisor/pkg/errors/linuxerr"
2528 "gvisor.dev/gvisor/pkg/flipcall"
2629 "gvisor.dev/gvisor/pkg/fspath"
2730 "gvisor.dev/gvisor/pkg/log"
2831 "gvisor.dev/gvisor/pkg/marshal/primitive"
29- "gvisor.dev/gvisor/pkg/p9"
3032)
3133
3234const (
@@ -266,7 +268,7 @@ func SetStatHandler(c *Connection, comm Communicator, payloadLen uint32) (uint32
266268 failureMask , failureErr := fd .impl .SetStat (req )
267269 resp .FailureMask = failureMask
268270 if failureErr != nil {
269- resp .FailureErrNo = uint32 (p9 . ExtractErrno (failureErr ))
271+ resp .FailureErrNo = uint32 (ExtractErrno (failureErr ))
270272 }
271273 return nil
272274 }); err != nil {
@@ -1529,3 +1531,42 @@ func checkSafeName(name string) error {
15291531 }
15301532 return unix .EINVAL
15311533}
1534+
1535+ // ExtractErrno extracts a unix.Errno from an error, best effort.
1536+ func ExtractErrno (err error ) unix.Errno {
1537+ errno , _ := TryExtractErrno (err )
1538+ return errno
1539+ }
1540+
1541+ // TryExtractErrno extracts a unix.Errno from an error, and reports whether it
1542+ // was successful. If unsuccessful, the returned errno is EIO.
1543+ func TryExtractErrno (err error ) (unix.Errno , bool ) {
1544+ switch err {
1545+ case os .ErrNotExist :
1546+ return unix .ENOENT , true
1547+ case os .ErrExist :
1548+ return unix .EEXIST , true
1549+ case os .ErrPermission :
1550+ return unix .EACCES , true
1551+ case os .ErrInvalid :
1552+ return unix .EINVAL , true
1553+ }
1554+
1555+ // Attempt to unwrap.
1556+ switch e := err .(type ) {
1557+ case * errors.Error :
1558+ return linuxerr .ToUnix (e ), true
1559+ case unix.Errno :
1560+ return e , true
1561+ case * os.PathError :
1562+ return TryExtractErrno (e .Err )
1563+ case * os.SyscallError :
1564+ return TryExtractErrno (e .Err )
1565+ case * os.LinkError :
1566+ return TryExtractErrno (e .Err )
1567+ }
1568+
1569+ // Default case.
1570+ log .Warningf ("unknown error: %v" , err )
1571+ return unix .EIO , false
1572+ }
0 commit comments