fat32

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 14 Imported by: 11

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 DiskRange added in v1.5.0

type DiskRange struct {
	Offset uint64
	Length uint64
}

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) GetClusterChain added in v1.5.0

func (fl *File) GetClusterChain() ([]uint32, error)

Get the full cluster chain of the File. Getting this file system internal info can be beneficial for some low-level operations, such as: - Performing secure erase. - Detecting file fragmentation. - Passing Disk locations to a different tool that can work with it.

func (*File) GetDiskRanges added in v1.5.0

func (fl *File) GetDiskRanges() ([]DiskRange, error)

Get the disk ranges occupied by the File. Returns an array of disk ranges, where each entry is a contiguous area on disk. This information is similar to that returned by GetClusterChain, just in a different format, directly returning disk ranges instead of FAT clusters.

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(b backend.Storage, size, start, blocksize int64, volumeLabel string) (*FileSystem, error)

Create creates a FAT32 filesystem in a given file or device

requires the backend.Storage 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 backend.Storage 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(b backend.Storage, size, start, blocksize int64) (*FileSystem, error)

Read reads a filesystem from a given disk.

requires the backend.Storage 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 backend.Storage 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) Chmod added in v1.5.0

func (fs *FileSystem) Chmod(_ string, _ os.FileMode) error

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target.

func (*FileSystem) Chown added in v1.5.0

func (fs *FileSystem) Chown(_ string, _, _ int) error

Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value

func (*FileSystem) Close added in v1.5.2

func (fs *FileSystem) Close() error

Do cleaning job for fat32. Note that fat32 does not have side-effects so we do not do anything.

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 (fs *FileSystem) Link(_, _ string) error

creates a new link (also known as a hard link) to an existing file.

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) Mknod added in v1.5.0

func (fs *FileSystem) Mknod(_ string, _ uint32, _ int) error

creates a filesystem node (file, device special file, or named pipe) named pathname, with attributes specified by mode and dev

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) Remove added in v1.5.0

func (fs *FileSystem) Remove(pathname string) error

removes the named file or (empty) directory.

func (*FileSystem) Rename added in v1.5.0

func (fs *FileSystem) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it.

func (*FileSystem) SetLabel added in v1.3.0

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

SetLabel changes the filesystem label

func (fs *FileSystem) Symlink(_, _ string) error

creates a symbolic link named linkpath which contains the string target.

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