github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/filesystem/util/api.go (about)

     1  package util
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"os"
     7  
     8  	"github.com/Cloud-Foundations/Dominator/lib/filesystem"
     9  	"github.com/Cloud-Foundations/Dominator/lib/filter"
    10  	"github.com/Cloud-Foundations/Dominator/lib/log"
    11  	"github.com/Cloud-Foundations/Dominator/lib/mbr"
    12  	"github.com/Cloud-Foundations/Dominator/lib/objectserver"
    13  )
    14  
    15  type BootInfoType struct {
    16  	BootDirectory     *filesystem.DirectoryInode
    17  	InitrdImageDirent *filesystem.DirectoryEntry
    18  	InitrdImageFile   string
    19  	KernelImageDirent *filesystem.DirectoryEntry
    20  	KernelImageFile   string
    21  	KernelOptions     string
    22  }
    23  
    24  type ComputedFile struct {
    25  	Filename string
    26  	Source   string
    27  }
    28  
    29  type ComputedFilesData struct {
    30  	FileData      map[string][]byte // Key: filename.
    31  	RootDirectory string
    32  }
    33  
    34  // CopyMtimes will copy modification times for files from the source to the
    35  // destination if the file data and metadata (other than mtime) are identical.
    36  // Directory entry inode pointers are invalidated by this operation, so this
    37  // should be followed by a call to dest.RebuildInodePointers().
    38  func CopyMtimes(source, dest *filesystem.FileSystem) {
    39  	copyMtimes(source, dest)
    40  }
    41  
    42  func DeletedFilteredFiles(rootDir string, filt *filter.Filter) error {
    43  	return deletedFilteredFiles(rootDir, filt)
    44  }
    45  
    46  func GetBootInfo(fs *filesystem.FileSystem, rootLabel string,
    47  	extraKernelOptions string) (*BootInfoType, error) {
    48  	return getBootInfo(fs, rootLabel, extraKernelOptions)
    49  }
    50  
    51  func GetUnsupportedExt4fsOptions(fs *filesystem.FileSystem,
    52  	objectsGetter objectserver.ObjectsGetter) ([]string, error) {
    53  	return getUnsupportedOptions(fs, objectsGetter)
    54  }
    55  
    56  func LoadComputedFiles(filename string) ([]ComputedFile, error) {
    57  	return loadComputedFiles(filename)
    58  }
    59  
    60  func MakeBootable(fs *filesystem.FileSystem,
    61  	deviceName, rootLabel, rootDir, kernelOptions string,
    62  	doChroot bool, logger log.DebugLogger) error {
    63  	return makeBootable(fs, deviceName, rootLabel, rootDir, kernelOptions,
    64  		doChroot, logger)
    65  }
    66  
    67  func MakeExt4fs(deviceName, label string, unsupportedOptions []string,
    68  	bytesPerInode uint64, logger log.Logger) error {
    69  	return makeExt4fs(deviceName, label, unsupportedOptions, bytesPerInode,
    70  		logger)
    71  }
    72  
    73  func MakeKernelOptions(rootDevice, extraOptions string) string {
    74  	return fmt.Sprintf("root=%s ro console=tty0 console=ttyS0,115200n8 %s",
    75  		rootDevice, extraOptions)
    76  }
    77  
    78  func MergeComputedFiles(base, overlay []ComputedFile) []ComputedFile {
    79  	return mergeComputedFiles(base, overlay)
    80  }
    81  
    82  func ReplaceComputedFiles(fs *filesystem.FileSystem,
    83  	computedFilesData *ComputedFilesData,
    84  	objectsGetter objectserver.ObjectsGetter) (
    85  	objectserver.ObjectsGetter, error) {
    86  	return replaceComputedFiles(fs, computedFilesData, objectsGetter)
    87  }
    88  
    89  func SpliceComputedFiles(fs *filesystem.FileSystem,
    90  	computedFileList []ComputedFile) error {
    91  	return spliceComputedFiles(fs, computedFileList)
    92  }
    93  
    94  func Unpack(fs *filesystem.FileSystem, objectsGetter objectserver.ObjectsGetter,
    95  	rootDir string, logger log.Logger) error {
    96  	return unpack(fs, objectsGetter, rootDir, logger)
    97  }
    98  
    99  func (bootInfo *BootInfoType) WriteBootloaderConfig(rootDir string,
   100  	logger log.Logger) error {
   101  	return bootInfo.writeBootloaderConfig(rootDir, logger)
   102  }
   103  
   104  func WriteFstabEntry(writer io.Writer,
   105  	source, mountPoint, fileSystemType, flags string,
   106  	dumpFrequency, checkOrder uint) error {
   107  	return writeFstabEntry(writer, source, mountPoint, fileSystemType, flags,
   108  		dumpFrequency, checkOrder)
   109  }
   110  
   111  func WriteImageName(mountPoint, imageName string) error {
   112  	return writeImageName(mountPoint, imageName)
   113  }
   114  
   115  type WriteRawOptions struct {
   116  	AllocateBlocks    bool
   117  	DoChroot          bool
   118  	InitialImageName  string
   119  	InstallBootloader bool
   120  	MinimumFreeBytes  uint64
   121  	RootLabel         string
   122  	RoundupPower      uint64
   123  	WriteFstab        bool
   124  }
   125  
   126  func WriteRaw(fs *filesystem.FileSystem,
   127  	objectsGetter objectserver.ObjectsGetter, rawFilename string,
   128  	perm os.FileMode, tableType mbr.TableType,
   129  	minFreeSpace uint64, roundupPower uint64, makeBootable, allocateBlocks bool,
   130  	logger log.DebugLogger) error {
   131  	return writeRaw(fs, objectsGetter, rawFilename, perm, tableType,
   132  		WriteRawOptions{
   133  			AllocateBlocks:    allocateBlocks,
   134  			InstallBootloader: makeBootable,
   135  			MinimumFreeBytes:  minFreeSpace,
   136  			WriteFstab:        makeBootable,
   137  			RoundupPower:      roundupPower,
   138  		},
   139  		logger)
   140  }
   141  
   142  func WriteRawWithOptions(fs *filesystem.FileSystem,
   143  	objectsGetter objectserver.ObjectsGetter, rawFilename string,
   144  	perm os.FileMode, tableType mbr.TableType, options WriteRawOptions,
   145  	logger log.DebugLogger) error {
   146  	return writeRaw(fs, objectsGetter, rawFilename, perm, tableType, options,
   147  		logger)
   148  }