Skip to content

Commit

Permalink
Merge pull request #7 from frobnitzem/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
frobnitzem committed Apr 27, 2023
2 parents 6edd128 + 2d417d9 commit 029e3fa
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
3 changes: 1 addition & 2 deletions cfilesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ func (fs *fsState) newEnt() cEnt {
}
}

func (_ cEnt) SetInfo(_ *SFid) {}

// Note: This always returns returns a file with a nonzero IOUnit.
func (ent cEnt) Open(ctx context.Context, mode Flag) (File, error) {
_, iounit, err := ent.fs.session.Open(ctx, ent.fid, mode)
Expand Down Expand Up @@ -279,6 +277,7 @@ func (ent cEnt) Walk(ctx context.Context,
// drop part of ent.path
//steps = steps[:len(qids)]
//remain := len(ent.path) - bsp
// Note: potentially dangerous use of append [may modify ent.path]
//next.path = append(ent.path[:remain], steps[bsp:]...)
if len(qids) > 0 {
next.qid = qids[len(qids)-1]
Expand Down
6 changes: 5 additions & 1 deletion cmd/9pr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ func main() {
}

completer := readline.NewPrefixCompleter(
readline.PcItem("ls"),
readline.PcItem("cat"),
readline.PcItem("cd"),
readline.PcItem("exit"),
readline.PcItem("ls"),
readline.PcItem("mkdir"),
readline.PcItem("pwd"),
readline.PcItem("rm"),
Expand Down Expand Up @@ -122,6 +123,9 @@ func main() {
var cmd func(ctx context.Context, args ...string) error

switch name {
case "exit":
csession.Stop(nil)
return
case "ls":
cmd = commander.cmdls
case "cd":
Expand Down
6 changes: 0 additions & 6 deletions filesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ type Dirent interface {

Stat(ctx context.Context) (Dir, error)
WStat(ctx context.Context, stat Dir) error

// This is automatically called by the server
// on new Dirent-s (i.e. returned from Attach/Walk/Create).
// It informs the server of the internal data structure
// used to track this file's interfaces, Path, and Open mode (if opened).
SetInfo(info *SFid)
}

// Helper function to check Dirent.Qid().Type for QTDIR bit.
Expand Down
25 changes: 18 additions & 7 deletions ramfs/dirent.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ func (h FileHandle) OpenDir(ctx context.Context) (p9p.ReadNext, error) {
return h.ent.OpenDir(ctx)
}

func (_ FileHandle) SetInfo(sfid *p9p.SFid) { }

func (h FileHandle) Clunk(ctx context.Context) error {
h.ent.decref()
for i := range(h.parents) {
for i := range h.parents {
h.parents[len(h.parents)-i-1].decref()
}
return nil
Expand Down Expand Up @@ -165,12 +163,25 @@ func (h FileHandle) Walk(ctx context.Context, names ...string) ([]p9p.Qid, p9p.D
// ref = /
// rh.ent = /
// rh.parents = []
rh.parents = append(append(
rh.parents = make([]*FileEnt, len(h.parents)-ndel + 1 + len(ans)-ndel)

// would use append, but append mutates its input
/*rh.parents = append(append(
h.parents[:len(h.parents)-ndel],
ref),
ans[ndel:]...)
for _, p := range(rh.parents) {
ans[ndel:]...)*/
i0 := len(h.parents)-ndel + 1
for i := range rh.parents {
var p *FileEnt
if i < len(h.parents)-ndel {
p = h.parents[i]
} else if i >= i0 {
p = ans[ndel+i-i0]
} else {
p = ref
}
p.incref()
rh.parents[i] = p
}
rh.ent = rh.parents[len(rh.parents)-1]
rh.parents = rh.parents[:len(rh.parents)-1]
Expand All @@ -179,7 +190,7 @@ func (h FileHandle) Walk(ctx context.Context, names ...string) ([]p9p.Qid, p9p.D
}

qids = make([]p9p.Qid, len(ans))
for i, a := range(ans) {
for i, a := range ans {
qids[i] = a.Info.Qid
}

Expand Down
3 changes: 1 addition & 2 deletions sfilesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ func (sess *session) getRef(fid Fid) (*SFid, error) {
return ref, nil
}

// Sets ref.Ent and informs the ent of ref.
// Sets ref.Ent (could also informs the ent of ref.)
func (ref *SFid) link(ent Dirent) {
ref.Ent = ent
ent.SetInfo(ref)
}

// Add a new reference to the refs table.
Expand Down
2 changes: 0 additions & 2 deletions sleepfs/dirent.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func (s sleepTime) OpenDir(ctx context.Context) (p9p.ReadNext, error) {
return (&dirList{s, 0, 1000}).Next, nil
}

func (s sleepTime) SetInfo(_ *p9p.SFid) { }

func (s sleepTime) Clunk(ctx context.Context) error {
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions ufs/dirent.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ func (ref *FileRef) OpenDir(ctx context.Context) (p9p.ReadNext, error) {
return (&dirList{dirs, false}).Next, nil
}

func (ref *FileRef) SetInfo(sfid *p9p.SFid) {
ref.SFid = sfid
}

func (ref *FileRef) Clunk(ctx context.Context) error {
if ref.file != nil {
return ref.file.Close()
Expand Down
1 change: 0 additions & 1 deletion ufs/filesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type fServer struct {
type FileRef struct {
fs *fServer
file *os.File
SFid *p9p.SFid
Path string
Info p9p.Dir
}
Expand Down

0 comments on commit 029e3fa

Please sign in to comment.