-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor mountFd code #3512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor mountFd code #3512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,9 @@ import ( | |
| type mountError struct { | ||
| op string | ||
| source string | ||
| srcFD string | ||
| target string | ||
| procfd string | ||
| dstFD string | ||
| flags uintptr | ||
| data string | ||
| err error | ||
|
|
@@ -22,19 +23,21 @@ func (e *mountError) Error() string { | |
| out := e.op + " " | ||
|
|
||
| if e.source != "" { | ||
| out += e.source + ":" + e.target | ||
| } else { | ||
| out += e.target | ||
| out += "src=" + e.source + ", " | ||
| if e.srcFD != "" { | ||
| out += "srcFD=" + e.srcFD + ", " | ||
| } | ||
| } | ||
| if e.procfd != "" { | ||
| out += " (via " + e.procfd + ")" | ||
| out += "dst=" + e.target | ||
| if e.dstFD != "" { | ||
| out += ", dstFD=" + e.dstFD | ||
| } | ||
|
|
||
| if e.flags != uintptr(0) { | ||
| out += ", flags: 0x" + strconv.FormatUint(uint64(e.flags), 16) | ||
| out += ", flags=0x" + strconv.FormatUint(uint64(e.flags), 16) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (unrelated and out of scope, sharing my thoughts :D) I really wish there was a pretty print for the flags
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, thought about it, too, decided to not implement it, since it is only used by developers, and we can cope with numeric values.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap, I ended up doing the same :-D. Some day it will happen :) |
||
| } | ||
| if e.data != "" { | ||
| out += ", data: " + e.data | ||
| out += ", data=" + e.data | ||
| } | ||
|
|
||
| out += ": " + e.err.Error() | ||
|
|
@@ -47,19 +50,36 @@ func (e *mountError) Unwrap() error { | |
| return e.err | ||
| } | ||
|
|
||
| // mount is a simple unix.Mount wrapper. If procfd is not empty, it is used | ||
| // instead of target (and the target is only used to add context to an error). | ||
| func mount(source, target, procfd, fstype string, flags uintptr, data string) error { | ||
| // mount is a simple unix.Mount wrapper, returning an error with more context | ||
| // in case it failed. | ||
| func mount(source, target, fstype string, flags uintptr, data string) error { | ||
| return mountViaFDs(source, "", target, "", fstype, flags, data) | ||
| } | ||
|
|
||
| // mountViaFDs is a unix.Mount wrapper which uses srcFD instead of source, | ||
| // and dstFD instead of target, unless those are empty. The *FD arguments, | ||
| // if non-empty, are expected to be in the form of a path to an opened file | ||
| // descriptor on procfs (i.e. "/proc/self/fd/NN"). | ||
| // | ||
| // If case an FD is used instead of a source or a target path, the | ||
| // corresponding path is only used to add context to an error in case | ||
| // the mount operation has failed. | ||
| func mountViaFDs(source, srcFD, target, dstFD, fstype string, flags uintptr, data string) error { | ||
| src := source | ||
| if srcFD != "" { | ||
| src = srcFD | ||
| } | ||
| dst := target | ||
| if procfd != "" { | ||
| dst = procfd | ||
| if dstFD != "" { | ||
| dst = dstFD | ||
| } | ||
| if err := unix.Mount(source, dst, fstype, flags, data); err != nil { | ||
| if err := unix.Mount(src, dst, fstype, flags, data); err != nil { | ||
| return &mountError{ | ||
| op: "mount", | ||
| source: source, | ||
| srcFD: srcFD, | ||
| target: target, | ||
| procfd: procfd, | ||
| dstFD: dstFD, | ||
| flags: flags, | ||
| data: data, | ||
| err: err, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.