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
- type Directory
- type FSInformationSector
- type File
- type FileInfo
- type FileSystem
- func (fs *FileSystem) Equal(a *FileSystem) bool
- func (fs *FileSystem) Label() string
- func (fs *FileSystem) Mkdir(p string) error
- func (fs *FileSystem) OpenFile(p string, flag int) (filesystem.File, error)
- func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error)
- func (fs *FileSystem) SetLabel(volumeLabel string) error
- func (fs *FileSystem) Type() filesystem.Type
- type MsdosMediaType
- type SectorSize
Constants ¶
const ( // FirstRemovableDrive is first removable drive FirstRemovableDrive uint8 = 0x00 // FirstFixedDrive is first fixed drive FirstFixedDrive uint8 = 0x80 )
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) Read ¶
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) Write ¶
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) Name ¶
Name base name of the file
will return the long name of the file. If none exists, returns the shortname and extension
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem implememnts the FileSystem interface
func Create ¶
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 )