fat32

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 14 Imported by: 9

Documentation

Overview

Package fat32 provides utilities to interact with, manipulate and create a FAT32 filesystem on a block device or a disk image.

references:

https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system
https://www.cs.fsu.edu/~cop4610t/assignments/project3/spec/fatspec.pdf
https://wiki.osdev.org/FAT

Index

Constants

View Source
const (
	// FirstRemovableDrive is first removable drive
	FirstRemovableDrive uint8 = 0x00
	// FirstFixedDrive is first fixed drive
	FirstFixedDrive uint8 = 0x80
)
View Source
const (
	// KB represents one KB
	KB int64 = 1024
	// MB represents one MB
	MB int64 = 1024 * KB
	// GB represents one GB
	GB int64 = 1024 * MB
	// TB represents one TB
	TB int64 = 1024 * GB
	// Fat32MaxSize is maximum size of a FAT32 filesystem in bytes
	Fat32MaxSize int64 = 2198754099200
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

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

Directory represents a single directory in a FAT32 filesystem

type FSInformationSector

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

FSInformationSector is a structure holding the FAT32 filesystem information sector

type File

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

File represents a single file in a FAT32 filesystem

func (*File) Close added in v1.2.0

func (fl *File) Close() error

Close close the file

func (*File) Read

func (fl *File) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF reads from the last known offset in the file from last read or write and increments the offset by the number of bytes read. Use Seek() to set at a particular point

func (*File) Seek

func (fl *File) Seek(offset int64, whence int) (int64, error)

Seek set the offset to a particular point in the file

func (*File) Write

func (fl *File) Write(p []byte) (int, error)

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. returns a non-nil error when n != len(b) writes to the last known offset in the file from last read or write and increments the offset by the number of bytes read. Use Seek() to set at a particular point

type FileInfo

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

FileInfo represents the information for an individual file it fulfills os.FileInfo interface

func (FileInfo) IsDir

func (fi FileInfo) IsDir() bool

IsDir abbreviation for Mode().IsDir()

func (FileInfo) ModTime

func (fi FileInfo) ModTime() time.Time

ModTime modification time

func (FileInfo) Mode

func (fi FileInfo) Mode() os.FileMode

Mode returns file mode

func (FileInfo) Name

func (fi FileInfo) Name() string

Name base name of the file

will return the long name of the file. If none exists, returns the shortname and extension

func (FileInfo) ShortName

func (fi FileInfo) ShortName() string

ShortName just the 8.3 short name of the file

func (FileInfo) Size

func (fi FileInfo) Size() int64

Size length in bytes for regular files

func (FileInfo) Sys

func (fi FileInfo) Sys() interface{}

Sys underlying data source - not supported yet and so will return nil

type FileSystem

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

FileSystem implememnts the FileSystem interface

func Create

func Create(f util.File, size, start, blocksize int64, volumeLabel string) (*FileSystem, error)

Create creates a FAT32 filesystem in a given file or device

requires the util.File where to create the filesystem, size is the size of the filesystem in bytes, start is how far in bytes from the beginning of the util.File to create the filesystem, and blocksize is is the logical blocksize to use for creating the filesystem

note that you are *not* required to create the filesystem on the entire disk. You could have a disk of size 20GB, and create a small filesystem of size 50MB that begins 2GB into the disk. This is extremely useful for creating filesystems on disk partitions.

Note, however, that it is much easier to do this using the higher-level APIs at github.com/diskfs/go-diskfs which allow you to work directly with partitions, rather than having to calculate (and hopefully not make any errors) where a partition starts and ends.

If the provided blocksize is 0, it will use the default of 512 bytes. If it is any number other than 0 or 512, it will return an error.

func Read

func Read(file util.File, size, start, blocksize int64) (*FileSystem, error)

Read reads a filesystem from a given disk.

requires the util.File where to read the filesystem, size is the size of the filesystem in bytes, start is how far in bytes from the beginning of the util.File the filesystem is expected to begin, and blocksize is is the logical blocksize to use for creating the filesystem

note that you are *not* required to read a filesystem on the entire disk. You could have a disk of size 20GB, and a small filesystem of size 50MB that begins 2GB into the disk. This is extremely useful for working with filesystems on disk partitions.

Note, however, that it is much easier to do this using the higher-level APIs at github.com/diskfs/go-diskfs which allow you to work directly with partitions, rather than having to calculate (and hopefully not make any errors) where a partition starts and ends.

If the provided blocksize is 0, it will use the default of 512 bytes. If it is any number other than 0 or 512, it will return an error.

func (*FileSystem) Equal

func (fs *FileSystem) Equal(a *FileSystem) bool

Equal compare if two filesystems are equal

func (*FileSystem) Label added in v1.1.0

func (fs *FileSystem) Label() string

Label get the label of the filesystem from the secial file in the root directory. The label stored in the boot sector is ignored to mimic Windows behavior which only stores and reads the label from the special file in the root directory.

func (*FileSystem) Mkdir

func (fs *FileSystem) Mkdir(p string) error

Mkdir make a directory at the given path. It is equivalent to `mkdir -p`, i.e. idempotent, in that:

* It will make the entire tree path if it does not exist * It will not return an error if the path already exists

func (*FileSystem) OpenFile

func (fs *FileSystem) OpenFile(p string, flag int) (filesystem.File, error)

OpenFile returns an io.ReadWriter from which you can read the contents of a file or write contents to the file

accepts normal os.OpenFile flags

returns an error if the file does not exist

func (*FileSystem) ReadDir

func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error)

ReadDir return the contents of a given directory in a given filesystem.

Returns a slice of os.FileInfo with all of the entries in the directory.

Will return an error if the directory does not exist or is a regular file and not a directory

func (*FileSystem) SetLabel added in v1.3.0

func (fs *FileSystem) SetLabel(volumeLabel string) error

SetLabel changes the filesystem label

func (*FileSystem) Type

func (fs *FileSystem) Type() filesystem.Type

Type returns the type code for the filesystem. Always returns filesystem.TypeFat32

type MsdosMediaType

type MsdosMediaType uint8

MsdosMediaType is the (mostly unused) media type. However, we provide and export the known constants for it.

const (
	// Media8InchDrDos for single-sided 250KB DR-DOS disks
	Media8InchDrDos MsdosMediaType = 0xe5
	// Media525InchTandy for 5.25 inch floppy disks for Tandy
	Media525InchTandy MsdosMediaType = 0xed
	// MediaCustomPartitionsDrDos for non-standard custom DR-DOS partitions utilizing non-standard BPB formats
	MediaCustomPartitionsDrDos MsdosMediaType = 0xee
	// MediaCustomSuperFloppyDrDos for non-standard custom superfloppy disks for DR-DOS
	MediaCustomSuperFloppyDrDos MsdosMediaType = 0xef
	// Media35Inch for standard 1.44MB and 2.88MB 3.5 inch floppy disks
	Media35Inch MsdosMediaType = 0xf0
	// MediaDoubleDensityAltos for double-density floppy disks for Altos only
	MediaDoubleDensityAltos MsdosMediaType = 0xf4
	// MediaFixedDiskAltos for fixed disk 1.95MB for Altos only
	MediaFixedDiskAltos MsdosMediaType = 0xf5
	// MediaFixedDisk for standard fixed disks - can be used for any partitioned fixed or removable media where the geometry is defined in the BPB
	MediaFixedDisk MsdosMediaType = 0xf8
)

type SectorSize

type SectorSize uint16

SectorSize indicates what the sector size in bytes is

const (
	// SectorSize512 is a sector size of 512 bytes, used as the logical size for all FAT filesystems
	SectorSize512 SectorSize = 512
)

Jump to

Keyboard shortcuts

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