summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-03-14 16:35:16 -0400
committerSam Anthony <sam@samanthony.xyz>2026-03-14 16:35:16 -0400
commitb57a199eb44dff5af3bdb7866b818544e1d270ee (patch)
tree0ee7df898e993a5075a04b337e088e08ce582073
parent51c51c16bf4839940124695fbee65c152f6d29c5 (diff)
downloadbuth-b57a199eb44dff5af3bdb7866b818544e1d270ee.zip
authfs: implement Rclunk and Ropen
-rw-r--r--back/cmd/authfs/authfs.go33
-rw-r--r--back/cmd/authfs/err.go1
-rw-r--r--back/cmd/authfs/root.go7
-rw-r--r--back/cmd/authfs/sess.go7
-rw-r--r--back/cmd/authfs/sessdir.go7
-rw-r--r--back/cmd/authfs/userdir.go7
6 files changed, 62 insertions, 0 deletions
diff --git a/back/cmd/authfs/authfs.go b/back/cmd/authfs/authfs.go
index 71e5128..bf6e340 100644
--- a/back/cmd/authfs/authfs.go
+++ b/back/cmd/authfs/authfs.go
@@ -12,6 +12,7 @@ import (
type File interface {
Qid() (p9.QID, error)
+ Open(mode p9.Mode) error
// TODO
}
@@ -121,3 +122,35 @@ func (fs *Authfs) attach(fid p9.FID, f File) error {
fs.files[fid] = f
return nil
}
+
+func (fs *Authfs) Rclunk(fid p9.FID) error {
+ fs.mu.Lock()
+ defer fs.mu.Unlock()
+
+ if _, exists := fs.files[fid]; !exists {
+ return ErrFidNotExist
+ }
+ delete(fs.files, fid)
+ return nil
+}
+
+func (fs *Authfs) Ropen(fid p9.FID, mode p9.Mode) (p9.QID, error) {
+ f, err := fs.getFile(fid)
+ if err != nil {
+ return p9.QID{}, err
+ }
+ if err := f.Open(mode); err != nil {
+ return p9.QID{}, err
+ }
+ return f.Qid()
+}
+
+func (fs *Authfs) getFile(fid p9.FID) (File, error) {
+ fs.mu.Lock()
+ defer fs.mu.Unlock()
+ f, exists := fs.files[fid]
+ if !exists {
+ return nil, ErrFidNotExist
+ }
+ return f, nil
+}
diff --git a/back/cmd/authfs/err.go b/back/cmd/authfs/err.go
index 81da2ba..4f4dbbf 100644
--- a/back/cmd/authfs/err.go
+++ b/back/cmd/authfs/err.go
@@ -7,4 +7,5 @@ var (
ErrFileNotExist = errors.New("file does not exist")
ErrFidExist = errors.New("fid already exists")
ErrFidNotExist = errors.New("fid does not exist")
+ ErrPerm = errors.New("permission denied")
)
diff --git a/back/cmd/authfs/root.go b/back/cmd/authfs/root.go
index 5d56045..7a0fcbd 100644
--- a/back/cmd/authfs/root.go
+++ b/back/cmd/authfs/root.go
@@ -29,3 +29,10 @@ func (r *RootDir) Qid() (p9.QID, error) {
Path: rootQidPath,
}, nil
}
+
+func (r *RootDir) Open(mode p9.Mode) error {
+ if mode != p9.OREAD {
+ return ErrPerm
+ }
+ return nil
+}
diff --git a/back/cmd/authfs/sess.go b/back/cmd/authfs/sess.go
index 3d0cca3..ce45ae4 100644
--- a/back/cmd/authfs/sess.go
+++ b/back/cmd/authfs/sess.go
@@ -52,3 +52,10 @@ func (s *Session) Extend() bool {
}
func (s *Session) Qid() (p9.QID, error) { return s.qid, nil }
+
+func (s *Session) Open(mode p9.Mode) error {
+ if mode != p9.OREAD {
+ return ErrPerm
+ }
+ return nil
+}
diff --git a/back/cmd/authfs/sessdir.go b/back/cmd/authfs/sessdir.go
index eafc92f..22d8202 100644
--- a/back/cmd/authfs/sessdir.go
+++ b/back/cmd/authfs/sessdir.go
@@ -72,3 +72,10 @@ func (dir *SessionsDir) Qid() (p9.QID, error) {
Path: sessionsQidPath,
}, nil
}
+
+func (dir *SessionsDir) Open(mode p9.Mode) error {
+ if mode&(p9.OEXEC|p9.OTRUNC|p9.ORCLOSE) != 0 {
+ return ErrPerm
+ }
+ return nil
+}
diff --git a/back/cmd/authfs/userdir.go b/back/cmd/authfs/userdir.go
index f7ef5a7..d5e1cce 100644
--- a/back/cmd/authfs/userdir.go
+++ b/back/cmd/authfs/userdir.go
@@ -49,3 +49,10 @@ func (dir *UsersDir) Qid() (p9.QID, error) {
Path: usersQidPath,
}, nil
}
+
+func (dir *UsersDir) Open(mode p9.Mode) error {
+ if mode&(p9.OEXEC|p9.OTRUNC|p9.ORCLOSE) != 0 {
+ return ErrPerm
+ }
+ return nil
+}