simgrid::fsmod::FileSystem

class FileSystem

A class that implements a file system abstraction.

Public Functions

void create_directory(const std::string &full_dir_path) const

Create a directory.

Parameters:

full_dir_path – the directory’s absolute path

void create_file(const std::string &full_path, const std::string &size) const

Create a new file on the file system in zero time.

Parameters:
  • full_path – the file’s absolute path

  • size – the file size

bool directory_exists(const std::string &full_dir_path) const

Check that a directory exists at a given path.

Parameters:

full_path – the directory’s absolute path

Returns:

true if the directory exists, false otherwise

bool file_exists(const std::string &full_path) const

Check that a file exists at a given path.

Parameters:

full_path – the file’s absolute path

Returns:

true if the file exists, false otherwise

sg_size_t file_size(const std::string &full_path) const
Parameters:

full_path – the file’s absolute path

Returns:

the file size in bytes

const char *get_cname() const

Retrieve the file system’s name as a C-style string.

Returns:

a name

sg_size_t get_free_space_at_path(const std::string &full_path) const

Returns the free space on the path’s partition.

Parameters:

full_path – an absolute path

Returns:

a number of bytes

const std::string &get_name() const

Retrieve the file system’s name.

Returns:

a name

std::shared_ptr<Partition> get_partition_for_path_or_null(const std::string &full_path) const

Retrieve the Partition that corresponds to an absolute full path.

Parameters:

full_path – an absolute path

Returns:

A Partition instance or nullptr if the (invalid) path matches no known partition

std::vector<std::shared_ptr<Partition>> get_partitions() const

Retrieve all partitions in the file systems.

Returns:

A list of Partition instances

std::set<std::string, std::less<>> list_files_in_directory(const std::string &full_dir_path) const

Retrieve the names of files in a directory.

Parameters:

full_dir_path – the directory’s absolute path

Returns:

a set of of file names

void make_file_evictable(const std::string &full_path, bool evictable) const

Set the evictable status of a file so that it can or cannot be evicted if stored on a partition that implements caching.

Parameters:
  • full_path – the file’s absolute path

  • evictable – true if the file should be evictable, false if not

void mount_partition(const std::string &mount_point, std::shared_ptr<Storage> storage, const std::string &size, Partition::CachingScheme caching_scheme = Partition::CachingScheme::NONE)

A method to add a partition to the file system.

Parameters:
  • mount_point – the partition’s mount point

  • storage – the storage

  • size – the partition size as a unit string (e.g., “100MB”)

  • caching_scheme – the caching scheme (default: Partition::CachingScheme::NONE)

void mount_partition(const std::string &mount_point, std::shared_ptr<Storage> storage, sg_size_t size, Partition::CachingScheme caching_scheme = Partition::CachingScheme::NONE)

A method to add a partition to the file system.

Parameters:
  • mount_point – the partition’s mount point (e.g., “/dev/a/”)

  • storage – the storage

  • size – the partition size in bytes

  • caching_scheme – the caching scheme (default: Partition::CachingScheme::NONE)

void move_file(const std::string &src_full_path, const std::string &dst_full_path) const

Move a file.

Parameters:
  • src_full_path – the source’s absolute path

  • dst_full_path – the destination’s absolute path

std::shared_ptr<File> open(const std::string &full_path, const std::string &access_mode)

Open a file. If no file corresponds to the given full path, a new file of size 0 is created.

Parameters:
  • full_path – the files’ absolute path

  • access_mode – access mode (“r”, “w”, or “a”)

Returns:

an opened file handle

std::shared_ptr<Partition> partition_by_name(const std::string &name) const

Retrieve a partition by name (i.e., mount point), and throw an exception if no such partition exists.

Parameters:

name – A name (i.e., mount point)

Returns:

A Partition instance

std::shared_ptr<Partition> partition_by_name_or_null(const std::string &name) const

Retrieve a partition by name (i.e., mou t point)

Parameters:

name – A name (i.e., mount point)

Returns:

A Partition instance or nullptr if no such partition exists

void truncate_file(const std::string &full_path, sg_size_t size) const

Truncate a file.

Parameters:
  • full_path – the file’s absolute path

  • size – the number of bytes to truncate (if >= than the file size, the file will have size zero)

Remove a directory and the files it contains.

Parameters:

full_dir_path – the directory’s absolute path

Unlink a file.

Parameters:

full_path – the file’s absolute path

Public Static Functions

static std::shared_ptr<FileSystem> create(const std::string &name, int max_num_open_files = 1024)

Create a FileSystem instance.

Parameters:
  • name – the file system’s name (can be any string)

  • max_num_open_files – the file system’s bound on the number of simultaneous opened files

Returns:

A shared pointer to a FileSystem instance

static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>> &get_file_systems_by_actor(const s4u::ActorPtr &actor)

Get all the file systems an actor has access to.

This corresponds to the file systems in the NetZone wherein the Host on which the Actor runs is.

Parameters:

actor – The actor asking for all the file systems it can access

Returns:

A file system map, using names as keys

static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>> &get_file_systems_by_netzone(const s4u::NetZone *netzone)

Get all the file systems in a netzone.

Parameters:

netzone – A netzone

Returns:

A file system map, using names as keys

static void register_file_system(const s4u::NetZone *netzone, const std::shared_ptr<FileSystem> &fs)

Register a file system in the NetZone it belongs.

Parameters:
  • netzone – The SimGrid NetZone

  • fs – The FSMOD file system