mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Change vfs.Dirent.Off to NextOff.
"d_off is the distance from the start of the directory to the start of the next linux_dirent." - getdents(2). PiperOrigin-RevId: 270349685
This commit is contained in:
@@ -190,10 +190,10 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
}
|
||||
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
Name: child.diskDirent.FileName(),
|
||||
Type: fs.ToDirentType(childType),
|
||||
Ino: uint64(child.diskDirent.Inode()),
|
||||
Off: fd.off,
|
||||
Name: child.diskDirent.FileName(),
|
||||
Type: fs.ToDirentType(childType),
|
||||
Ino: uint64(child.diskDirent.Inode()),
|
||||
NextOff: fd.off + 1,
|
||||
}) {
|
||||
dir.childList.InsertBefore(child, fd.iter)
|
||||
return nil
|
||||
|
||||
@@ -584,7 +584,7 @@ func TestIterDirents(t *testing.T) {
|
||||
// Ignore the inode number and offset of dirents because those are likely to
|
||||
// change as the underlying image changes.
|
||||
cmpIgnoreFields := cmp.FilterPath(func(p cmp.Path) bool {
|
||||
return p.String() == "Ino" || p.String() == "Off"
|
||||
return p.String() == "Ino" || p.String() == "NextOff"
|
||||
}, cmp.Ignore())
|
||||
if diff := cmp.Diff(cb.dirents, test.want, cmpIgnoreFields); diff != "" {
|
||||
t.Errorf("dirents mismatch (-want +got):\n%s", diff)
|
||||
|
||||
@@ -75,10 +75,10 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
|
||||
if fd.off == 0 {
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
Name: ".",
|
||||
Type: linux.DT_DIR,
|
||||
Ino: vfsd.Impl().(*dentry).inode.ino,
|
||||
Off: 0,
|
||||
Name: ".",
|
||||
Type: linux.DT_DIR,
|
||||
Ino: vfsd.Impl().(*dentry).inode.ino,
|
||||
NextOff: 1,
|
||||
}) {
|
||||
return nil
|
||||
}
|
||||
@@ -87,10 +87,10 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
if fd.off == 1 {
|
||||
parentInode := vfsd.ParentOrSelf().Impl().(*dentry).inode
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
Name: "..",
|
||||
Type: parentInode.direntType(),
|
||||
Ino: parentInode.ino,
|
||||
Off: 1,
|
||||
Name: "..",
|
||||
Type: parentInode.direntType(),
|
||||
Ino: parentInode.ino,
|
||||
NextOff: 2,
|
||||
}) {
|
||||
return nil
|
||||
}
|
||||
@@ -112,10 +112,10 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
// Skip other directoryFD iterators.
|
||||
if child.inode != nil {
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
Name: child.vfsd.Name(),
|
||||
Type: child.inode.direntType(),
|
||||
Ino: child.inode.ino,
|
||||
Off: fd.off,
|
||||
Name: child.vfsd.Name(),
|
||||
Type: child.inode.direntType(),
|
||||
Ino: child.inode.ino,
|
||||
NextOff: fd.off + 1,
|
||||
}) {
|
||||
dir.childList.InsertBefore(child, fd.iter)
|
||||
return nil
|
||||
|
||||
@@ -199,8 +199,11 @@ type Dirent struct {
|
||||
// Ino is the inode number.
|
||||
Ino uint64
|
||||
|
||||
// Off is this Dirent's offset.
|
||||
Off int64
|
||||
// NextOff is the offset of the *next* Dirent in the directory; that is,
|
||||
// FileDescription.Seek(NextOff, SEEK_SET) (as called by seekdir(3)) will
|
||||
// cause the next call to FileDescription.IterDirents() to yield the next
|
||||
// Dirent. (The offset of the first Dirent in a directory is always 0.)
|
||||
NextOff int64
|
||||
}
|
||||
|
||||
// IterDirentsCallback receives Dirents from FileDescriptionImpl.IterDirents.
|
||||
|
||||
Reference in New Issue
Block a user