capacitycheck

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 7 Imported by: 0

README

Capacity Check

A simple library and CLI to help verify the advertised capacity of storage media.

This program will write a single file of pseudo-random data to the requested directory. A checksum of the data is calculated while creating the file. Once the file has been fully written and synched to disk, the file is read, and the checksum of the read file is compared to the expected checksum. The file is then deleted.

If the checksums do not agree, the media may be lying about its advertised capacity.

To build

go build cmd/capacitycheck/capacitycheck.go

Usage

# write a 63GB file to /media/foo/bar with a read/write buffer of 1MB
./capacitycheck -d /media/foo/bar -s 63GB -b 1MB

Documentation

Index

Constants

View Source
const (
	ChecksumFailed checkError = "Checksum Failed: Capacity may not be truthful"
)

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, bytes uint64, dir string) error

Check will write at least `bytes` bytes to a file within `dir`, read the file, and verify that the written checksum matches the read checksum.

func CheckWithOptions

func CheckWithOptions(ctx context.Context, bytes uint64, dir string, options CheckOptions) error

CheckWithOptions does the same as Check, but provides options that can be set to get hooks into the in-progress check.

Types

type CheckOptions

type CheckOptions struct {
	//BufferSize will override the default read/write buffer size, in bytes
	BufferSize uint64
	//OnWrite will be called after each write to the file with the total number of bytes
	//written and the expected maximum number of bytes that will be written in total
	OnWrite func(written uint64, max uint64)
	//OnRead will be called after each read from the file with the total number of bytes
	//read and the expected maximum number of bytes that will be read in total
	OnRead func(read uint64, max uint64)
	//DebugF will write debug information without newline termination
	DebugF func(format string, args ...interface{})
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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