podman

Форк
0
38 строк · 1.4 Кб
1
package mkcw
2

3
import (
4
	"fmt"
5
	"os/exec"
6
	"strings"
7

8
	"github.com/sirupsen/logrus"
9
)
10

11
// MakeFS formats the imageFile as a filesystem of the specified type,
12
// populating it with the contents of the directory at sourcePath.
13
// Recognized filesystem types are "ext2", "ext3", "ext4", and "btrfs".
14
// Note that krun's init is currently hard-wired to assume "ext4".
15
// Returns the stdout, stderr, and any error returned by the mkfs command.
16
func MakeFS(sourcePath, imageFile, filesystem string) (string, string, error) {
17
	var stdout, stderr strings.Builder
18
	// N.B. mkfs.xfs can accept a protofile via its -p option, but the
19
	// protofile format doesn't allow us to supply timestamp information or
20
	// specify that files are hard linked
21
	switch filesystem {
22
	case "ext2", "ext3", "ext4":
23
		logrus.Debugf("mkfs -t %s --rootdir %q %q", filesystem, sourcePath, imageFile)
24
		cmd := exec.Command("mkfs", "-t", filesystem, "-d", sourcePath, imageFile)
25
		cmd.Stdout = &stdout
26
		cmd.Stderr = &stderr
27
		err := cmd.Run()
28
		return stdout.String(), stderr.String(), err
29
	case "btrfs":
30
		logrus.Debugf("mkfs -t %s --rootdir %q %q", filesystem, sourcePath, imageFile)
31
		cmd := exec.Command("mkfs", "-t", filesystem, "--rootdir", sourcePath, imageFile)
32
		cmd.Stdout = &stdout
33
		cmd.Stderr = &stderr
34
		err := cmd.Run()
35
		return stdout.String(), stderr.String(), err
36
	}
37
	return "", "", fmt.Errorf("don't know how to make a %q filesystem with contents", filesystem)
38
}
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.