MCPcopy
hub / github.com/google/gvisor / getXattr

Method getXattr

pkg/sentry/fsimpl/gofer/directfs_inode.go:561–585  ·  view source on GitHub ↗
(ctx context.Context, name string, size uint64, d *dentry)

Source from the content-addressed store, hash-verified

559}
560
561func (i *directfsInode) getXattr(ctx context.Context, name string, size uint64, d *dentry) (string, error) {
562 if ftype := d.inode.fileType(); ftype == linux.S_IFSOCK || ftype == linux.S_IFLNK {
563 // Sockets and symlinks use O_PATH control FDs. However, fgetxattr(2) fails
564 // with EBADF for O_PATH FDs. Fallback to lisafs.
565 if err := i.ensureLisafsControlFD(ctx, d); err != nil {
566 return "", err
567 }
568 return i.controlFDLisa.GetXattr(ctx, name, size)
569 }
570
571 // getxattr(2) called with size 0 should return the attribute size. As a
572 // result, we need to return the entire attribute here so that the sentry
573 // can return the correct value.
574 if size > linux.XATTR_SIZE_MAX || size == 0 {
575 size = linux.XATTR_SIZE_MAX
576 }
577 bPtr := xattrBufPool.Get().(*[]byte)
578 defer xattrBufPool.Put(bPtr)
579 data := (*bPtr)[:size]
580 sz, err := unix.Fgetxattr(i.controlFD, name, data)
581 if err != nil {
582 return "", err
583 }
584 return string(data[:sz]), nil
585}
586
587func (i *directfsInode) setXattr(ctx context.Context, opts *vfs.SetXattrOptions, d *dentry) error {
588 if ftype := d.inode.fileType(); ftype == linux.S_IFSOCK || ftype == linux.S_IFLNK {

Callers

nothing calls this directly

Calls 5

ensureLisafsControlFDMethod · 0.95
GetXattrMethod · 0.65
GetMethod · 0.65
fileTypeMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected