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

Function newFileFD

pkg/sentry/fsimpl/tmpfs/tmpfs_test.go:59–83  ·  view source on GitHub ↗

newFileFD creates a new file in a new tmpfs mount, and returns the FD. If the returned err is not nil, then cleanup should be called when the FD is no longer needed.

(ctx context.Context, mode linux.FileMode)

Source from the content-addressed store, hash-verified

57// the returned err is not nil, then cleanup should be called when the FD is no
58// longer needed.
59func newFileFD(ctx context.Context, mode linux.FileMode) (*vfs.FileDescription, func(), error) {
60 creds := auth.CredentialsFromContext(ctx)
61 vfsObj, root, cleanup, err := newTmpfsRoot(ctx)
62 if err != nil {
63 return nil, nil, err
64 }
65
66 filename := fmt.Sprintf("tmpfs-test-file-%d", nextFileID.Add(1))
67
68 // Create the file that will be write/read.
69 fd, err := vfsObj.OpenAt(ctx, creds, &vfs.PathOperation{
70 Root: root,
71 Start: root,
72 Path: fspath.Parse(filename),
73 }, &vfs.OpenOptions{
74 Flags: linux.O_RDWR | linux.O_CREAT | linux.O_EXCL,
75 Mode: linux.ModeRegular | mode,
76 })
77 if err != nil {
78 cleanup()
79 return nil, nil, fmt.Errorf("failed to create file %q: %v", filename, err)
80 }
81
82 return fd, cleanup, nil
83}
84
85// newDirFD is like newFileFD, but for directories.
86func newDirFD(ctx context.Context, mode linux.FileMode) (*vfs.FileDescription, func(), error) {

Callers 8

TestStatAfterCreateFunction · 0.85
TestSetStatAtimeFunction · 0.85
TestSetStatFunction · 0.85
TestSimpleWriteReadFunction · 0.85
TestPWriteFunction · 0.85
TestLocksFunction · 0.85
TestPReadFunction · 0.85
TestTruncateFunction · 0.85

Calls 6

CredentialsFromContextFunction · 0.92
ParseFunction · 0.92
newTmpfsRootFunction · 0.85
AddMethod · 0.65
OpenAtMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…