Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx::filesystem_t Namespace Reference

This module is designed to operate directly on files and directories in enclave. More...

Classes

class  FileStatus
 A class to store file type and permissions. More...
 
class  FileSystemException
 Exception about filesystem. More...
 
class  Path
 A class for storing path. More...
 
class  PlainFileReader
 Read a plaintext file (file size <= 100 KB) More...
 
class  PlainFileWriter
 Write a plaintext file (file size <= 100 KB) More...
 
class  ProtectedFileReader
 A ProtectedFileReader for reading from the Intel SGX Protected File System. More...
 
class  ProtectedFileWriter
 A ProtectedFileWriter for writing to the Intel SGX Protected File System. More...
 

Enumerations

enum class  FileType {
  None = 0 , NotFound , Regular , Directory ,
  Symlink , Block , Character , Fifo ,
  Socket , Unknown
}
 File type enum. More...
 
enum class  Perms : unsigned {
  None = 0 , OwnerRead = 0400 , OwnerWrite = 0200 , OwnerExec = 0100 ,
  OwnerAll = 0700 , GroupRead = 040 , GroupWrite = 020 , GroupExec = 010 ,
  GroupAll = 070 , OthersRead = 04 , OthersWrite = 02 , OthersExec = 01 ,
  OthersAll = 07 , All = 0777 , SetUid = 04000 , SetGid = 02000 ,
  StickyBit = 01000 , Mask = 07777 , Unknown = 0xFFFF
}
 File permissions (Octal) More...
 
enum class  FileMode { CreateNew = 1 , OpenOrCreate = 2 , Append = 3 }
 The mode for file writing operation. More...
 

Functions

bool CreateDirectory (const Path &p)
 Create a directory (attribute default 0755)
 
FileStatus Status (const Path &p)
 Retrieve file type and permissions; If the file is a symbolic link, the retrieved file type and permissions correspond to those of the target file it references.
 
FileStatus SymlinkStatus (const Path &p)
 Retrieve file type and permissions; This function can retrieve the type and permissions of the symbolic link file itself, distinct from its target file.
 
bool Exists (const FileStatus &s) noexcept
 Check if a file exists.
 
bool Exists (const Path &p)
 Check if a file exists.
 
bool Remove (const Path &p)
 Remove a file.
 
bool RemoveProtectedFile (const Path &file_name)
 Remove a protected file.
 
uintmax_t FileSize (const Path &p)
 Check the size of the file.
 
bool IsDirectory (const FileStatus &s) noexcept
 Check if the file is a directory.
 
bool IsDirectory (const Path &p)
 Check if the file is a directory.
 
bool IsEmpty (const Path &p)
 If the path is a directory, check whether it is empty; If the path is a regular file, check whether its size is 0.
 
bool IsRegularFile (const FileStatus &s) noexcept
 Check if the file is a regular file.
 
bool IsRegularFile (const Path &p)
 Check if the file is a regular file.
 

Detailed Description

This module is designed to operate directly on files and directories in enclave.

Enumeration Type Documentation

◆ FileMode

enum class ssgx::filesystem_t::FileMode
strong

The mode for file writing operation.

Enumerator
CreateNew 

Specifies that the operating system should create a new file. If the file already exists, an FileSystemException exception is thrown.

OpenOrCreate 

Specifies that the operating system should open a file if it exists; otherwise, a new file will be created.

Append 

Opens the file if it exists and seeks to the end of the file, or creates a new file.

◆ FileType

enum class ssgx::filesystem_t::FileType
strong

File type enum.

Enumerator
None 

default value

NotFound 

the file is not exist

Regular 

the file is a regular file

Directory 

the file is a directory file

Symlink 

the file is a symlink file

Block 

the file is a block file

Character 

the file is a character file

Fifo 

the file is a fifo file

Socket 

the file is a socket file

Unknown 

the type of file is unknown

◆ Perms

enum class ssgx::filesystem_t::Perms : unsigned
strong

File permissions (Octal)

Enumerator
None 

No permissions.

OwnerRead 

The file owner has read permission.

OwnerWrite 

The file owner has write permission.

OwnerExec 

The file owner has execute permission.

OwnerAll 

The file owner has read, write and execute permission.

GroupRead 

The file owner's user group has read permissions.

GroupWrite 

The file owner's user group has write permissions.

GroupExec 

The file owner's user group has execute permissions.

GroupAll 

The file owner's user group has read, write and execute permission

OthersRead 

Others have read permission.

OthersWrite 

Others have write permission.

OthersExec 

Others have execute permission.

OthersAll 

Others have read, write and execute permission.

All 

All users have read, write and execute permission.

SetUid 

When this bit is set, the file has the file owner's permissions during execution

SetGid 

When this bit is set, files created in this directory belong to the same group as the directory.

StickyBit 

When this bit is set, only the owner of the file in the directory or root can delete or move the file.

Mask 

The file permissions represent the bits.

Unknown 

Invalid permission.

Function Documentation

◆ CreateDirectory()

bool ssgx::filesystem_t::CreateDirectory ( const Path & p)

Create a directory (attribute default 0755)

Parameters
[in]pDir path
Returns
Return true if created successfully; return false if the directory already exists
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
bool result = CreateDirectory(file_path);
} catch (FileSystemException& e) {
...
}
A class for storing path.
Definition ssgx_filesystem_t.h:100
bool CreateDirectory(const Path &p)
Create a directory (attribute default 0755)

◆ Exists() [1/2]

bool ssgx::filesystem_t::Exists ( const FileStatus & s)
noexcept

Check if a file exists.

Parameters
[in]sFile status
Returns
Return true if it exists; return false if it does not exist
See also
ssgx::filesystem::Status(const Path& p)
Example
Path file_path("/root/main.cpp");
try {
FileStatus file_status = Status(file_path);
} catch (FileSystemException& e) {
...
}
bool result = Exists(file_status);
A class to store file type and permissions.
Definition ssgx_filesystem_t.h:18
FileStatus Status(const Path &p)
Retrieve file type and permissions; If the file is a symbolic link, the retrieved file type and permi...
bool Exists(const FileStatus &s) noexcept
Check if a file exists.

◆ Exists() [2/2]

bool ssgx::filesystem_t::Exists ( const Path & p)

Check if a file exists.

Parameters
[in]pFile path
Returns
Return true if it exists; return false if it does not exist
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
bool result = Exists(file_path);
} catch (FileSystemException& e) {
...
}

◆ FileSize()

uintmax_t ssgx::filesystem_t::FileSize ( const Path & p)

Check the size of the file.

Parameters
[in]pFile path
Returns
File size
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
uint64_t result = FileSize(file_path);
} catch (FileSystemException& e) {
...
}
uintmax_t FileSize(const Path &p)
Check the size of the file.

◆ IsDirectory() [1/2]

bool ssgx::filesystem_t::IsDirectory ( const FileStatus & s)
noexcept

Check if the file is a directory.

Parameters
[in]sFile status
Returns
Return true if the file type is a directory; otherwise return false
See also
Status(const Path& p)
Example
Path file_path("/root/main.cpp");
try {
FileStatus file_status = Status(file_path);
} catch (FileSystemException& e) {
...
}
bool result = IsDirectory(file_status);
bool IsDirectory(const FileStatus &s) noexcept
Check if the file is a directory.

◆ IsDirectory() [2/2]

bool ssgx::filesystem_t::IsDirectory ( const Path & p)

Check if the file is a directory.

Parameters
[in]pFile path
Returns
Return true if the file type is a directory; otherwise return false
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
bool result = IsDirectory(file_path);
} catch (FileSystemException& e) {
...
}

◆ IsEmpty()

bool ssgx::filesystem_t::IsEmpty ( const Path & p)

If the path is a directory, check whether it is empty; If the path is a regular file, check whether its size is 0.

Parameters
[in]pPath
Returns
If the path is a directory: return true if the directory is empty; otherwise return false;
If the path is a regular file: returns true if its size is 0; otherwise return false
Exceptions
FileSystemException
Example
Path file_path("/root");
try {
bool result = IsEmpty(file_path);
} catch (FileSystemException& e) {
...
}
bool IsEmpty(const Path &p)
If the path is a directory, check whether it is empty; If the path is a regular file,...

◆ IsRegularFile() [1/2]

bool ssgx::filesystem_t::IsRegularFile ( const FileStatus & s)
noexcept

Check if the file is a regular file.

Parameters
[in]sFile status
Returns
Return true if the file type is a regular file; otherwise return false
See also
Status(const Path& p)
Example
Path file_path("/root/main.cpp");
try {
FileStatus file_status = Status(file_path);
} catch (FileSystemException& e) {
...
}
bool result = IsRegularFile(file_status);
bool IsRegularFile(const FileStatus &s) noexcept
Check if the file is a regular file.

◆ IsRegularFile() [2/2]

bool ssgx::filesystem_t::IsRegularFile ( const Path & p)

Check if the file is a regular file.

Parameters
[in]pFile path
Returns
Return true if the file type is a regular file; otherwise return false
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
bool result = IsRegularFile(file_path);
} catch (FileSystemException& e) {
...
}

◆ Remove()

bool ssgx::filesystem_t::Remove ( const Path & p)

Remove a file.

Parameters
[in]pFile path
Returns
Return true if removed successfully; return false if the file does not exist
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
bool result = Remove(file_path);
} catch (FileSystemException& e) {
...
}
bool Remove(const Path &p)
Remove a file.

◆ RemoveProtectedFile()

bool ssgx::filesystem_t::RemoveProtectedFile ( const Path & file_name)

Remove a protected file.

Parameters
[in]Theprotected file name
Returns
Return true if removed successfully; return false if the file does not exist
Exceptions
FileSystemException
Example
Path file_path("/root/sealed_file");
try {
bool result = RemoveProtectedFile(file_path);
} catch (FileSystemException& e) {
...
}
bool RemoveProtectedFile(const Path &file_name)
Remove a protected file.

◆ Status()

FileStatus ssgx::filesystem_t::Status ( const Path & p)

Retrieve file type and permissions; If the file is a symbolic link, the retrieved file type and permissions correspond to those of the target file it references.

Parameters
[in]pFile path
Returns
File status
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
FileStatus file_status = Status(file_path);
} catch (FileSystemException& e) {
...
}

◆ SymlinkStatus()

FileStatus ssgx::filesystem_t::SymlinkStatus ( const Path & p)

Retrieve file type and permissions; This function can retrieve the type and permissions of the symbolic link file itself, distinct from its target file.

Parameters
[in]pFile path
Returns
File status
Exceptions
FileSystemException
Example
Path file_path("/root/main.cpp");
try {
FileStatus file_status = SymlinkStatus(file_path);
} catch (FileSystemException& e) {
...
}
FileStatus SymlinkStatus(const Path &p)
Retrieve file type and permissions; This function can retrieve the type and permissions of the symbol...