View Source edifa (edifa v1.0.0)

Summary

Functions

Closes the previously created image.
Creates an image of give size in bytes with given options. The file must not already exists. If the image file is 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.

Extracts a range of partition that may include the reserved space before the first partition into the given file. Both paritions are included in the extracted data, so to extract a single one, the same must be specified from the 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.

Formats a partition in a previously created image. Only supports FAT for now.

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.

Mounts a partition from given image. Returns the path to the directory where the parition is mounted.

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.

Creates the partition table on a previously created image. Only supports MBR partitions for now. Support for active/bootable partition flag is not implemented yet.

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.

Unmounts a previously mounted partition.

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.

Writes data into a previously created image from gien input file.

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}.
Link to this type

partition_filesystem/0

View Source
-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

-spec close(image()) -> ok | {error, Reason :: term()}.

Equivalent to edifa:close(Image, #{}).

-spec close(image(), close_options()) ->
               ok |
               {ok, LogState :: term()} |
               {error, Reason :: term()} |
               {error, Reason :: term(), LogState :: term()}.
Closes the previously created image.
-spec create(Filename :: file:filename(), Size :: pos_integer()) ->
                {ok, image()} | {error, Reason :: term()}.

Equivalent to edifa:create(Filename, Size, #{}).

Link to this function

create(Filename, Size, Options)

View Source
-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()}.
Creates an image of give size in bytes with given options. The file must not already exists. If the image file is 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.

Link to this function

extract(Img, PartId, Filename)

View Source
-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.\
Link to this function

extract(Img, From, To, OutputFile)

View Source
-spec extract(image(),
              From :: reserved | partition_id(),
              To :: reserved | partition_id(),
              file:filename()) ->
                 ok.

Equivalent to edifa:extract(Image, From, To, OutputFile, #{}).

Link to this function

extract(Image, From, To, OutputFile, Opts)

View Source
-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()}.
Extracts a range of partition that may include the reserved space before the first partition into the given file. Both paritions are included in the extracted data, so to extract a single one, the same must be specified from the 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.

Link to this function

format(Image, PartId, FileSystem, Opts)

View Source
-spec format(image(), partition_id(), partition_filesystem(), format_options()) ->
                ok |
                {ok, LogState :: term()} |
                {error, Reason :: term()} |
                {error, Reason :: term(), LogState :: term()}.
Formats a partition in a previously created image. Only supports FAT for now.

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, #{}).

Link to this function

mount(Image, PartId, Opts)

View Source
-spec mount(image(), partition_id(), mount_options()) ->
               {ok, MountPoint :: binary()} |
               {ok, MountPoint :: binary(), LogState :: term()} |
               {error, Reason :: term()} |
               {error, Reason :: term(), LogState :: term()}.
Mounts a partition from given image. Returns the path to the directory where the parition is mounted.

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.

Link to this function

partition(Img, PartTable, PartitionSpecs)

View Source
-spec partition(image(), partition_table(), partition_specs()) ->
                   {ok, [partition_id()]} | {error, Reason :: term()}.

Equivalent to edifa:partition(Image, PartitionTableType, PartitionSpec, #{}).

Link to this function

partition(Image, PartTable, PartitionSpecs, Opts)

View Source
-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()}.
Creates the partition table on a previously created image. Only supports MBR partitions for now. Support for active/bootable partition flag is not implemented yet.

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, #{}).

Link to this function

unmount(Image, PartId, Opts)

View Source
-spec unmount(image(), partition_id(), unmount_options()) ->
                 ok |
                 {ok, LogState :: term()} |
                 {error, Reason :: term()} |
                 {error, Reason :: term(), LogState :: term()}.
Unmounts a previously mounted partition.

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.

Link to this function

write(Image, Filename, Opts)

View Source
-spec write(image(), file:filename(), write_options()) ->
               ok |
               {ok, LogState :: term()} |
               {error, Reason :: term()} |
               {error, Reason :: term(), LogState :: term()}.
Writes data into a previously created image from gien input file.

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.