1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
"github.com/aenix-io/talm/internal/pkg/encryption/helpers"
11
"github.com/siderolabs/talos/pkg/machinery/config/config"
15
// ReadOnly is a flag for setting the mount point as readonly.
16
ReadOnly Flags = 1 << iota
17
// Shared is a flag for setting the mount point as shared.
19
// Resize indicates that a the partition for a given mount point should be
20
// resized to the maximum allowed.
22
// Overlay indicates that a the partition for a given mount point should be
23
// mounted using overlayfs.
25
// SystemOverlay indicates that overlay directory should be created under tmpfs.
27
// SystemOverlay should be combined with Overlay option.
29
// ReadonlyOverlay indicates that a the partition for a given mount point should be
30
// mounted using multi-layer readonly overlay from multiple partitions given as sources.
32
// SkipIfMounted is a flag for skipping mount if the mountpoint is already mounted.
34
// SkipIfNoFilesystem is a flag for skipping formatting and mounting if the mountpoint has not filesystem.
36
// SkipIfNoDevice is a flag for skipping errors when the device is not found.
40
// Flags is the mount flags.
43
// Options is the functional options struct.
49
PostUnmountHooks []Hook
50
Encryption config.Encryption
51
SystemInformationGetter helpers.SystemInformationGetter
56
// Option is the functional option func.
57
type Option func(*Options)
59
// Check checks if all provided flags are set.
60
func (f Flags) Check(flags Flags) bool {
61
return (f & flags) == flags
64
// Intersects checks if at least one flag is set.
65
func (f Flags) Intersects(flags Flags) bool {
66
return (f & flags) != 0
69
// WithPrefix is a functional option for setting the mount point prefix.
70
func WithPrefix(o string) Option {
71
return func(args *Options) {
76
// WithFlags is a functional option to set up mount flags.
77
func WithFlags(flags Flags) Option {
78
return func(args *Options) {
79
args.MountFlags |= flags
83
// WithPreMountHooks adds functions to be called before mounting the partition.
84
func WithPreMountHooks(hooks ...Hook) Option {
85
return func(args *Options) {
86
args.PreMountHooks = append(args.PreMountHooks, hooks...)
90
// WithPostUnmountHooks adds functions to be called after unmounting the partition.
91
func WithPostUnmountHooks(hooks ...Hook) Option {
92
return func(args *Options) {
93
args.PostUnmountHooks = append(args.PostUnmountHooks, hooks...)
97
// WithEncryptionConfig partition encryption configuration.
98
func WithEncryptionConfig(cfg config.Encryption) Option {
99
return func(args *Options) {
100
args.Encryption = cfg
104
// WithLogger sets the logger.
105
func WithLogger(logger *log.Logger) Option {
106
return func(args *Options) {
111
// WithProjectQuota enables project quota mount option.
112
func WithProjectQuota(enable bool) Option {
113
return func(args *Options) {
114
args.ProjectQuota = enable
118
// WithSystemInformationGetter the function to get system information on the node.
119
func WithSystemInformationGetter(getter helpers.SystemInformationGetter) Option {
120
return func(args *Options) {
121
args.SystemInformationGetter = getter
125
// Hook represents pre/post mount hook.
126
type Hook func(p *Point) error
128
// NewDefaultOptions initializes a Options struct with default values.
129
func NewDefaultOptions(setters ...Option) *Options {
134
PreMountHooks: []Hook{},
135
PostUnmountHooks: []Hook{},
138
for _, setter := range setters {