Skip to content

Commit

Permalink
fs: share code between rawBridge.{ReadDirPlus,ReadDir}
Browse files Browse the repository at this point in the history
Change-Id: I00e7e45e9024085601702bcb918594248f8c3852
  • Loading branch information
hanwen committed Sep 9, 2024
1 parent d27836c commit 1a89ec9
Showing 1 changed file with 15 additions and 48 deletions.
63 changes: 15 additions & 48 deletions fs/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,57 +1081,15 @@ func (b *rawBridge) getStream(ctx context.Context, inode *Inode) (DirStream, sys
return NewListDirStream(r), 0
}

func (b *rawBridge) ReadDir(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status {
n, f := b.inode(input.NodeId, input.Fh)

f.mu.Lock()
defer f.mu.Unlock()

defer func() { f.dirOffset = out.Offset }()

errno, eof := b.setStream(cancel, input, n, f)
if errno != 0 {
return errnoToStatus(errno)
} else if eof {
return fuse.OK
}

if f.hasOverflow {
if f.overflowErrno != 0 {
return errnoToStatus(f.overflowErrno)
}

f.hasOverflow = false
// always succeeds.
out.AddDirEntry(f.overflow)
}

first := true
for f.dirStream.HasNext() {
e, errno := f.dirStream.Next()

if errno != 0 {
if first {
return errnoToStatus(errno)
} else {
f.hasOverflow = true
f.overflowErrno = errno
return fuse.OK
}
}

first = false
if !out.AddDirEntry(e) {
f.overflow = e
f.hasOverflow = true
return errnoToStatus(errno)
}
}
func (b *rawBridge) ReadDirPlus(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status {
return b.readDirMaybeLookup(cancel, input, out, true)
}

return fuse.OK
func (b *rawBridge) ReadDir(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status {
return b.readDirMaybeLookup(cancel, input, out, false)
}

func (b *rawBridge) ReadDirPlus(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status {
func (b *rawBridge) readDirMaybeLookup(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList, lookup bool) fuse.Status {
n, f := b.inode(input.NodeId, input.Fh)

f.mu.Lock()
Expand Down Expand Up @@ -1172,6 +1130,15 @@ func (b *rawBridge) ReadDirPlus(cancel <-chan struct{}, input *fuse.ReadIn, out
}
first = false

if !lookup {
if !out.AddDirEntry(e) {
f.overflow = e
f.hasOverflow = true
return fuse.OK
}
continue
}

entryOut := out.AddDirLookupEntry(e)
if entryOut == nil {
f.overflow = e
Expand Down

0 comments on commit 1a89ec9

Please sign in to comment.