ext4

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

ext4

A Go wrapper for working with ext4 filesystems (e2fsprogs).

Usage

For detailed examples see the ext4_test.go file.

package main

import (
    "context"
    "log"

    "github.com/dpeckett/ext4"
)

func main() {
    c := ext4.NewClient()

    ctx := context.Background()

    err := c.CreateFilesystem(ctx, ext4.CreateOptions{
        Device: "/dev/loop0",
    })
    if err != nil {
        log.Fatal("Failed to create filesystem: ", err)
    }

    // Shrink the filesystem to its minimum size.
    err = c.ResizeFilesystem(ctx, ext4.ResizeOptions{
        Device: "/dev/loop0",
        Shrink: true,
    })
    if err != nil {
        log.Fatal("Failed to resize filesystem: ", err)
    }
}

Commands

This is a work in progress. The following commands are implemented:

  • e2fsck
  • e2image
  • e2label
  • e2mmpstatus
  • e2scrub
  • e2undo
  • mke2fs
  • resize2fs
  • tune2fs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckOptions added in v0.2.0

type CheckOptions struct {
	Device              string `arg:"0"` // Device containing the filesystem to check.
	Preen               bool   `arg:"p"` // Automatically repair the filesystem.
	NoFix               bool   `arg:"n"` // Perform a read-only check.
	CheckForBadBlocks   bool   `arg:"c"` // Check for bad blocks.
	AppendBadBlocks     bool   `arg:"k"` // Append to existing bad blocks list.
	AppendBadBlocksFile string `arg:"l"` // Append bad blocks from file to existing bad blocks list.
	BadBlocksFile       string `arg:"L"` // Use bad blocks list from file.
	Force               bool   `arg:"f"` // Force checking even if the filesystem seems clean.
	OptimizeDirectories bool   `arg:"D"` // Optimize directories.
	Flush               bool   `arg:"F"` // Flush the device's buffer cache.
	Superblock          *int   `arg:"b"` // Use alternative superblock.
	Blocksize           *int   `arg:"B"` // Block size in bytes (supported: 1024, 2048 and 4096 bytes).
	ExternalJournal     string `arg:"j"` // External journal for the filesystem.
	ExtendedOptions     string `arg:"E"` // Extended options, comma separated list.
	UndoFile            string `arg:"z"` // Before overwriting blocks, backup the contents.
}

CheckOptions provides options for checking an ext4 filesystem.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...ClientOption) *Client

Construct a new e2fsprogs client.

func (*Client) CheckFilesystem added in v0.1.1

func (c *Client) CheckFilesystem(ctx context.Context, opts CheckOptions) error

Check an ext4 filesystem.

func (*Client) CreateFilesystem

func (c *Client) CreateFilesystem(ctx context.Context, opts CreateOptions) error

Create an ext4 filesystem.

func (*Client) ResizeFilesystem

func (c *Client) ResizeFilesystem(ctx context.Context, opts ResizeOptions) error

Resize an ext4 filesystem.

type ClientOption

type ClientOption func(*Client)

func WithPath

func WithPath(path string) ClientOption

WithPath sets the path of the directory containing the e2fsprogs binaries.

type CreateOptions added in v0.2.0

type CreateOptions struct {
	Device                   string `arg:"0"` // Device where the filesystem will be created.
	Size                     string `arg:"1"` // Optional size of the filesystem.
	CheckForBadBlocks        bool   `arg:"c"` // Check for bad blocks before creating the filesystem.
	BlockSize                *int   `arg:"b"` // Block size in bytes (supported: 1024, 2048 and 4096 bytes).
	ClusterSize              *int   `arg:"C"` // Cluster size in bytes for filesystems using the bigalloc feature (supported: [2048, 256M]).
	BytesPerInode            *int   `arg:"i"` // Bytes/inode ratio, generally shouldn't be smaller than the block size.
	InodeSize                *int   `arg:"I"` // The size of each inode in bytes.
	JournalOptions           string `arg:"J"` // Journal options, comma separated list.
	NumberOfGroups           *int   `arg:"G"` // The number of block groups packed into a flex_bg group.
	NumberOfInodes           *int   `arg:"N"` // Override the default number of reserved inodes.
	RootDirectory            string `arg:"d"` // Copy directory contents into the filesystem.
	ReservedBlocksPercentage *int   `arg:"m"` // Percentage of blocks reserved for the super-user.
	CreatorOS                string `arg:"o"` // Override creator os.
	BlocksPerGroup           *int   `arg:"g"` // The number of blocks in each block group.
	Label                    string `arg:"L"` // Volume label (max length 16 bytes).
	LastMountedDirectory     string `arg:"M"` // Directory where the filesystem was last mounted.
	Features                 string `arg:"O"` // Filesystem features/options, comma separated list.
	FilesystemRevision       *int   `arg:"r"` // Revision level for the filesystem.
	ExtendedOptions          string `arg:"E"` // Extended options, comma separated list.
	UsageType                string `arg:"T"` // Filesystem usage type (supported: floppy, small, default).
	UUID                     string `arg:"U"` // UUID for the filesystem.
	ErrorBehavior            string `arg:"e"` // Kernel behavior when errors are detected (supported: continue, remount-ro, panic).
	UndoFile                 string `arg:"z"` // Before overwriting blocks, backup the contents.
	Journal                  bool   `arg:"j"` // Create an ext3 journal.
	DryRun                   bool   `arg:"n"` // Dry run (don't actually create the filesystem).
	DirectIO                 bool   `arg:"D"` // Use direct I/O when writing to the disk.
	Force                    bool   `arg:"F"` // Force filesystem creation on any device.
	WriteSuperblocks         bool   `arg:"S"` // Write superblock and group descriptors only.
}

CreateOptions provides options for creating an ext4 filesystem.

type ResizeOptions added in v0.2.0

type ResizeOptions struct {
	Device       string `arg:"0"` // Device containing the filesystem to resize.
	Size         string `arg:"1"` // Optional size of the filesystem.
	Force        bool   `arg:"f"` // Skip safety checks.
	Flush        bool   `arg:"F"` // Flush the device's buffer cache.
	Shrink       bool   `arg:"M"` // Shrink the filesystem to the minimum size.
	Enable64Bit  bool   `arg:"b"` // Enable 64-bit feature.
	Disable64Bit bool   `arg:"s"` // Disable 64-bit feature.
	RAIDStride   *int   `arg:"S"` // RAID stride size in filesystem blocks.
	UndoFile     string `arg:"z"` // Before overwriting blocks, backup the contents.
}

ResizeOptions provides options for resizing an ext4 filesystem.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL