ramdisk

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 0

README

ramdisk 🐏

Convenience wrapper for managing RAM disks across different operating systems with a consistent interface.

Usage

Help screen:

$ ramdisk -h
ramdisk 0.2.1 🐏

Usage:
  ramdisk [options] create [<mount-path>]
  ramdisk destroy <device-path>

Options:
  -h -help      Show this screen.
  -d            Print the resulting device path to stdout.
  -v            Verbose output.
  -size=<mb>    Size in megabytes [default: 32].

Creating a new ram disk with a specified size:

$ device_name=$(ramdisk -size=512 -d create)
512MB ramdisk created as /dev/disk4, mounted at /tmp/ramdisk-325620223
To later remove do: `ramdisk destroy /dev/disk4`
$ echo "${device_name}"
/dev/disk4

Installation

  • 📦 Compile via Go toolchain: go get github.com/carterjones/ramdisk/cmd/ramdisk

Platform Support

macOS ✅

Works great and does not require superuser access.

The basic steps followed are:

  • Create an unmounted but attached device in RAM that consists of the appropriate number of device blocks via hdiutil.
  • Format a new uniquely named HFS+ volume on that device via newfs_hfs.
  • Mounts the volume at a uniquely generated path within the /tmp filesystem, via mount.

This normally requires a sequence of arcane commands on the macOS command line which I can never remember, and thus was the primary reason I created this wrapper.

Linux ✅

Things are quite simple and work great via tmpfs on Linux! (But note that most Linux implementations unfortunately requires sudo access to mount new volumes.)

If you prefer a sudo-less route, most modern Linux on kernel 2.6+ often already has /dev/shm mounted, which is memory backed, so you can also just use that without any initialization at all.

Documentation

Index

Constants

View Source
const (
	DefaultSize = 1 * datasize.MB
)

defaults that are used for any zero value in Options

View Source
const Version = "0.2.1"

Version is the semantic version of this package.

Variables

This section is empty.

Functions

func Destroy

func Destroy(devicePath string) error

Destroy unmounts the ramdisk and removes it from devices.

Types

type LinuxPlatformImplementation

type LinuxPlatformImplementation struct{}

LinuxPlatformImplementation is the implementation for Linux systems.

The Linux implementation likely *requires sudo* to function on most distros. If you want a sudo-less option, you can use /dev/shm instead on most modern Linux platforms.

type Options

type Options struct {
	MountPath string      // optional: fs mount dir  (default: temp directory)
	Size      uint64      // optional: size in bytes (default: DefaultSize)
	Logger    *log.Logger // optional: logger for verbose implementation logs
}

Options are optional values that will override default behavior

type PlatformImplementation

type PlatformImplementation interface {
	// contains filtered or unexported methods
}

PlatformImplementation is the interface that should be implmented on an individual platform (operating system, etc), and hidden behind platform specific build tags.

type RAMDisk

type RAMDisk struct {
	// The system path referring to the RAMDisk. This may or may not be
	// identical to the MountPath, depending on operating system specific
	// implementations.
	DevicePath string
	// The filesystem path where the RAMDisk is mounted and may be viewed.
	MountPath string
}

RAMDisk represents the "results" of a ram disk creation operation

func Create

func Create(opts Options) (*RAMDisk, error)

Create a new ramdisk, using the implementation for the currently active platform.

If you wish to use all default values, supply a zero-value struct.

rd, err := ramdisk.Create(Options{})

May return an error on numerous platform-specific conditions.

Directories

Path Synopsis
cmd
ramdisk command
The ramdisk command line application.
The ramdisk command line application.
Package datasize defines a few useful constants for binary prefix byte sizes.
Package datasize defines a few useful constants for binary prefix byte sizes.

Jump to

Keyboard shortcuts

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