Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update systemio.h #291

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/syscall/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ class OpenSyscall : public BaseSyscall {

public:
OpenSyscall()
: BaseSyscall("Open", "Opens a file from a path",
: BaseSyscall("Open", "The open system call is used to open files in the file system. It allows you to create new files or open existing ones for reading, writing, or both. The call returns a file descriptor that represents the opened file, which is later used for performing various operations on the file.",
{{0, "Pointer to null terminated string for the path"},
{1, "flags"}},
{{0, "the file decriptor or -1 if an error occurred"}}) {}
{{0, "the file decriptor or -1 if an error occurred"}}) {
// flag descriptions
addFlagDescription("O_RDONLY", "Open the file for reading data only. You cannot modify the file's content.");
addFlagDescription("O_WRONLY", "Open the file for writing data only. You cannot read from the file.");
addFlagDescription("O_RDWR", "Open the file for both reading and writing. You can read from and write to the file.");
addFlagDescription("O_APPEND", "When writing to the file, add the data to the end of the file instead of overwriting it. This flag is useful when you want to keep existing data in the file and append new data at the end.");
addFlagDescription("O_CREAT", "Create a new file if it does not exist. You can also specify additional file permissions using this flag.");
addFlagDescription("O_TRUNC", "If the file already exists and it's opened for writing, clear its content before writing new data. This flag is useful when you want to start writing from the beginning of the file, overwriting any existing data.");
addFlagDescription("O_EXCL", "Used together with O_CREAT. If the file already exists, the open operation will fail. This flag is useful when you want to ensure that the file is created exclusively and does not overwrite an existing file.");
}
void execute() {
const AInt arg0 = BaseSyscall::getArg(RegisterFileType::GPR, 0);
const AInt arg1 = BaseSyscall::getArg(RegisterFileType::GPR, 1);
Expand Down
18 changes: 18 additions & 0 deletions src/syscall/systemio.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,31 @@ class SystemIO : public QObject {
static constexpr int SYSCALL_BUFSIZE = 128;
// Maximum number of files that can be open
static constexpr int SYSCALL_MAXFILES = 32;
// Flags for open system call (following Unix conventions):

// Opens the file for reading data only. File's content can't be modified.
static constexpr int O_RDONLY = 0x00000000;

// Opens the file for writing data only. File's content can't be read.
static constexpr int O_WRONLY = 0x00000001;

// Opens the file for both reading and writing.
static constexpr int O_RDWR = 0x00000002;

// Append
// Adds the data to the end of the file instead of overwriting it.
static constexpr int O_APPEND = 0x00000008;

// Creates a new file if it doesn't exist.
// Read and write permissions can be specified
static constexpr int O_CREAT = 0x00000200; // 512

// Truncate
// Clears the file content before writing.
static constexpr int O_TRUNC = 0x00000400; // 1024

// Exclusive
// Used with O_CREAT to ensure file creation fails if the file already exists
static constexpr int O_EXCL = 0x00000800; // 2048

// //////////////////////////////////////////////////////////////////////////////
Expand Down