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