{"modulePath":"github.com/ejfkdev/udf","version":"v0.7.9","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package disk\n\nPackage disk provides utilities for working directly with a disk\n\nMost of the provided functions are intelligent wrappers around implementations of github.com/ejfkdev/udf/diskkit/partition and github.com/ejfkdev/udf/diskkit/filesystem\n\n## Variables\n\n```go\nvar ErrReReadDeferred = errors.New(\"partition table written to disk but kernel re-read deferred (device busy); reboot to apply\")\n```\nErrReReadDeferred is returned (wrapped) by ReReadPartitionTable when the on-disk partition table was written successfully but the kernel could not be made to re-read it because the disk is busy (a partition is mounted/held — the common case when repartitioning the disk you are booted from). The new table is committed on disk; a reboot makes the kernel pick it up. Callers can detect this with errors.Is and reboot-to-apply instead of treating it as a failure.\n\n## Types\n\n```go\ntype DeviceType int\n```\n\n```go\nconst (\n\tDeviceTypeUnknown DeviceType = iota\n\tDeviceTypeFile\n\tDeviceTypeBlockDevice\n)\n```\n\n```go\nfunc DetermineDeviceType(f iofs.File) (DeviceType, error)\n```\n\n```go\ntype Disk struct {\n\tBackend           backend.Storage\n\tSize              int64\n\tLogicalBlocksize  int64\n\tPhysicalBlocksize int64\n\tTable             partition.Table\n\tDefaultBlocks     bool\n}\n```\nDisk is a reference to a single disk block device or image that has been Create() or Open()\n\n```go\nfunc (d *Disk) Close() error\n```\nClose the disk. Once successfully closed, it can no longer be used.\n\n```go\nfunc (d *Disk) CreateFilesystem(spec FilesystemSpec) (filesystem.FileSystem, error)\n```\nCreateFilesystem creates a filesystem on a disk image, the equivalent of mkfs.\n\nRequired:\n\n  - desired partition number, or 0 to create the filesystem on the entire block device or disk image,\n  - the filesystem type from github.com/ejfkdev/udf/diskkit/filesystem\n\nOptional:\n\n  - volume label for those filesystems that support it; under Linux this shows in '/dev/disks/by-label/\\\u003clabel\u003e'\n\nif successful, returns a filesystem-implementing structure for the given filesystem type\n\nreturns error if there was an error creating the filesystem, or the partition table is invalid and did not request the entire disk.\n\n```go\nfunc (d *Disk) GetFilesystem(partIndex int) (filesystem.FileSystem, error)\n```\nGetFilesystem gets the filesystem that already exists on a disk image\n\npass the desired partition number, or 0 to create the filesystem on the entire block device / disk image,\n\nif successful, returns a filesystem-implementing structure for the given filesystem type\n\nreturns error if there was an error reading the filesystem, or the partition table is invalid and did not request the entire disk.\n\n```go\nfunc (d *Disk) GetPartition(partIndex int) (part.Partition, error)\n```\n\n```go\nfunc (d *Disk) GetPartitionTable() (partition.Table, error)\n```\nGetPartitionTable retrieves a PartitionTable for a Disk\n\nIf the table is able to be retrieved from the disk, it is saved in the instance.\n\nreturns an error if the Disk is invalid or does not exist, or the partition table is unknown\n\n```go\nfunc (d *Disk) Partition(table partition.Table) error\n```\nPartition applies a partition.Table implementation to a Disk\n\nThe Table can have zero, one or more Partitions, each of which is unique to its implementation. E.g. MBR partitions in mbr.Table look different from GPT partitions in gpt.Table\n\nActual writing of the table is delegated to the individual implementation\n\n```go\nfunc (d *Disk) ReReadPartitionTable() error\n```\nReReadPartitionTable makes the kernel pick up the on-disk partition table.\n\nIt first tries a whole-disk re-read via the BLKRRPART ioctl. That is all-or-nothing and fails with EBUSY whenever the kernel or udev is transiently holding any partition -- which is common immediately after a partition-table write, because the write triggers a udev re-probe -- or when a partition is mounted. When BLKRRPART fails, it falls back to per-partition BLKPG reconciliation (the same mechanism partx/parted use): it adds, removes, and re-creates only the entries whose geometry changed, via BLKPG ioctls that do not require a whole-disk exclusive re-read. This keeps the library free of any dependency on external tools such as partx. The fallback is Linux-only; on other platforms it reports that the re-read could not be completed.\n\n```go\nfunc (d *Disk) ReadPartitionContents(partIndex int, writer io.Writer) (int64, error)\n```\nReadPartitionContents reads the contents of a partition to an io.Writer\n\nif successful, returns the number of bytes read\n\nreturns an error if there was an error reading from the disk, writing to the writer, the table is invalid, or the partition is invalid\n\n```go\nfunc (d *Disk) WritePartitionContents(partIndex int, reader io.Reader) (int64, error)\n```\nWritePartitionContents writes the contents of an io.Reader to a given partition\n\nif successful, returns the number of bytes written\n\nreturns an error if there was an error writing to the disk, reading from the reader, the table is invalid, or the partition is invalid\n\n```go\ntype FilesystemSpec struct {\n\tPartition   int\n\tFSType      filesystem.Type\n\tVolumeLabel string\n\tWorkDir     string\n\t// The filesystem will be created in a reproducible manner following SOURCE_DATE_EPOCH guidelines.\n\tReproducible bool\n}\n```\nFilesystemSpec represents the specification of a filesystem to be created\n\n```go\ntype InvalidPartitionError struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewInvalidPartitionError(requested int) *InvalidPartitionError\n```\n\n```go\nfunc (e *InvalidPartitionError) Error() string\n```\n\n```go\ntype MaxPartitionsExceededError struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewMaxPartitionsExceededError(requested, maxPart int) *MaxPartitionsExceededError\n```\n\n```go\nfunc (e *MaxPartitionsExceededError) Error() string\n```\n\n```go\ntype NoPartitionTableError struct{}\n```\n\n```go\nfunc (e *NoPartitionTableError) Error() string\n```\n\n```go\ntype Type int\n```\nType represents the type of disk this is\n\n```go\nconst (\n\t// File is a file-based disk image\n\tFile Type = iota\n\t// Device is an OS-managed block device\n\tDevice\n)\n```\n\n```go\ntype UnknownFilesystemError struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewUnknownFilesystemError(partition int) *UnknownFilesystemError\n```\n\n```go\nfunc (e *UnknownFilesystemError) Error() string\n```\n\n","path":"github.com/ejfkdev/udf/diskkit/disk","name":"disk","synopsis":"Package disk provides utilities for working directly with a disk","isRedistributable":true}
