-
Notifications
You must be signed in to change notification settings - Fork 11
feat: capture filesystems #74
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package ephem | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/moby/sys/mountinfo" | ||
| ) | ||
|
|
||
| var specialFsRegex = regexp.MustCompile(`^(/proc|/dev|/sys|/run|/var/lib/docker|/var/lib/nfs/rpc_pipefs).*`) | ||
|
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. It's not entirely clear for me what's a "special" filesystem here. Makes sense to filter
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. "Special" means not managed by NixOS i would say. |
||
|
|
||
| // MountInfo represents the information about a mount point. | ||
| // It is just a type alias for mountinfo.Info to allow us to add JSON marshalling. | ||
| type MountInfo struct { | ||
| mountinfo.Info | ||
| } | ||
|
|
||
| func (i MountInfo) MarshalJSON() ([]byte, error) { | ||
| return json.Marshal(map[string]string{ | ||
| "id": strconv.Itoa(i.ID), | ||
| "parent_id": strconv.Itoa(i.Parent), | ||
| "major": strconv.Itoa(i.Major), | ||
| "minor": strconv.Itoa(i.Minor), | ||
| "root": i.Root, | ||
| "mount_point": i.Mountpoint, | ||
| "mount_options": i.Options, | ||
| "optional": i.Optional, | ||
| "filesystem_type": i.FSType, | ||
| "mount_source": i.Source, | ||
| "super_options": i.VFSOptions, | ||
| }) | ||
| } | ||
|
|
||
| func Mounts() ([]*MountInfo, error) { | ||
| info, err := mountinfo.GetMounts(mountFilter) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var result []*MountInfo | ||
| for idx := range info { | ||
| result = append(result, &MountInfo{Info: *info[idx]}) | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| func mountFilter(info *mountinfo.Info) (skip, stop bool) { | ||
| if skip = specialFsRegex.MatchString(info.Mountpoint); skip { | ||
| return true, false | ||
| } | ||
|
|
||
| // skip the read-only bind-mount on /nix/store | ||
| // https://github.com/NixOS/nixpkgs/blob/dac9cdf8c930c0af98a63cbfe8005546ba0125fb/nixos/modules/installer/tools/nixos-generate-config.pl#L395 | ||
| if info.Mountpoint == "/nix/store" && strings.Contains(info.VFSOptions, "rw") && strings.Contains(info.Options, "ro") { | ||
| return true, false | ||
| } | ||
|
|
||
| return false, false | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ephemeralseems to contains only SwapEntries, no "mounts and so on"? Or am I misreading?