View Source edifa (edifa v1.0.0)
Summary
Functions
Equivalent to edifa:close(Image, #{}).
Equivalent to edifa:create(Filename, Size, #{}).
undefined
, a temporary file will be created and deleted at the end.Options:
- max_block_size: Maximum block size used when doing file operations.
- temp_dir: The directory to use when creating temporary files and directories.
- log_handler: A function to call with log events.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Equivalent to edifa:extract(Image, ParetId, PartId, OutputFile, #{}).
From
and To
arguments. The output file must not already exists. All the paritions involved MUST NOT be mounted, otherwise the extracted data mya not be up-to-date.Options:
- compressed: If the output file should be compressed with gzip. If
true
, the.gz` extension will be append at the end of the file name. Default: `false
. - log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Options for FAT file system:
- identifier: The parition identifier as a positive integer.
- label: The parition label as a binary or a string.
- type: The type of FAT, could be either 12, 16 or 32.
- cluster_size: The number of sector per cluster, must be a power of 2 from 1 to 128 included. Default is 8.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Equivalent to edifa:mount(Image, PartId, #{}).
Options:
- mount_point: An explicit directory path to mount the file system into.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Specification of MBR partitions:
- type: Required partition type as the 'fat32' atom or a positive integer.
- start: Optional partition start offset in bytes. It MUST be a multiple of the sector size (512). If not specified, it will be 0 for the first partition, and the ending of the last partition for the following ones.
- size: Required size of the partition. It MUST be a multiple of the sector size (512).
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Equivalent to edifa:unmount(Image, PartId, #{}).
Options:
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Options:
- max_block_size: Maximum block size used when doing file operations.
- count: The number of bytes to write.
- skip: The number of bytes to skip in the input file.
- seek: The offset in the output file where to start writing.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
Types
-type close_options() :: #{log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type create_options() :: #{max_block_size => undefined | pos_integer(), temp_dir => undefined | file:filename(), log_handler => undefined | edifa_exec:log_handler(), log_state => term()}.
-type extract_options() :: #{compressed => boolean(), log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type format_options() :: #{identifier => undefined | non_neg_integer(), label => undefined | iodata(), type => undefined | 12 | 16 | 32, cluster_size => undefined | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type image() :: #image{pid :: term()}.
-type mbr_partition_specs() :: [#{type := partition_type() | pos_integer(), start => non_neg_integer(), size := non_neg_integer(), active => boolean()}].
-type mount_options() :: #{mount_point => undefined | file:filename(), log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type partition_filesystem() :: fat.
-type partition_id() :: atom().
-type partition_options() :: #{log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type partition_specs() :: mbr_partition_specs().
-type partition_table() :: mbr.
-type partition_type() :: fat32.
-type unmount_options() :: #{log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
-type write_options() :: #{max_block_size => pos_integer(), count => pos_integer(), skip => pos_integer(), seek => pos_integer(), log_handler => undefined | edifa_exec:log_handler(), log_state => term(), timeout => pos_integer() | infinity}.
Functions
Equivalent to edifa:close(Image, #{}).
-spec create(Filename :: file:filename(), Size :: pos_integer()) -> {ok, image()} | {error, Reason :: term()}.
Equivalent to edifa:create(Filename, Size, #{}).
-spec create(Filename :: file:filename() | undefined, Size :: pos_integer(), Options :: create_options()) -> {ok, image()} | {ok, image(), LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
undefined
, a temporary file will be created and deleted at the end.Options:
- max_block_size: Maximum block size used when doing file operations.
- temp_dir: The directory to use when creating temporary files and directories.
- log_handler: A function to call with log events.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec extract(image(), reserved | partition_id(), Filename :: file:filename()) -> ok | {error, Reason :: term()}.
Equivalent to edifa:extract(Image, ParetId, PartId, OutputFile, #{}).
Extracts a partition or the reserved space before the first partition into the given file. The output file must not already exists.\-spec extract(image(), From :: reserved | partition_id(), To :: reserved | partition_id(), file:filename()) -> ok.
Equivalent to edifa:extract(Image, From, To, OutputFile, #{}).
-spec extract(image(), From :: reserved | partition_id(), To :: reserved | partition_id(), file:filename(), extract_options()) -> ok | {ok, LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
From
and To
arguments. The output file must not already exists. All the paritions involved MUST NOT be mounted, otherwise the extracted data mya not be up-to-date.Options:
- compressed: If the output file should be compressed with gzip. If
true
, the.gz` extension will be append at the end of the file name. Default: `false
. - log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec format(image(), partition_id(), partition_filesystem(), format_options()) -> ok | {ok, LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
Options for FAT file system:
- identifier: The parition identifier as a positive integer.
- label: The parition label as a binary or a string.
- type: The type of FAT, could be either 12, 16 or 32.
- cluster_size: The number of sector per cluster, must be a power of 2 from 1 to 128 included. Default is 8.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec mount(image(), partition_id()) -> {ok, MountPoint :: binary()} | {error, Reason :: term()}.
Equivalent to edifa:mount(Image, PartId, #{}).
-spec mount(image(), partition_id(), mount_options()) -> {ok, MountPoint :: binary()} | {ok, MountPoint :: binary(), LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
Options:
- mount_point: An explicit directory path to mount the file system into.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec partition(image(), partition_table(), partition_specs()) -> {ok, [partition_id()]} | {error, Reason :: term()}.
Equivalent to edifa:partition(Image, PartitionTableType, PartitionSpec, #{}).
-spec partition(image(), partition_table(), partition_specs(), partition_options()) -> {ok, [partition_id()]} | {ok, [partition_id()], LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
Specification of MBR partitions:
- type: Required partition type as the 'fat32' atom or a positive integer.
- start: Optional partition start offset in bytes. It MUST be a multiple of the sector size (512). If not specified, it will be 0 for the first partition, and the ending of the last partition for the following ones.
- size: Required size of the partition. It MUST be a multiple of the sector size (512).
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec unmount(image(), partition_id()) -> ok | {error, Reason :: term()}.
Equivalent to edifa:unmount(Image, PartId, #{}).
-spec unmount(image(), partition_id(), unmount_options()) -> ok | {ok, LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
Options:
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.
-spec write(image(), file:filename(), write_options()) -> ok | {ok, LogState :: term()} | {error, Reason :: term()} | {error, Reason :: term(), LogState :: term()}.
Options:
- max_block_size: Maximum block size used when doing file operations.
- count: The number of bytes to write.
- skip: The number of bytes to skip in the input file.
- seek: The offset in the output file where to start writing.
- log_handler: Either a stateless or stateful anonymous function that will be called with all the events happening during the operation. If a stateful handler is specified, the function will return the state as an extra last tuple element.
- log_state: The state data to use if the log handler is stateful.
- timeout: The maximum time the command is allowed to run without any IO.