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

Implement simplefs_file_open #56

Merged
merged 1 commit into from
Jun 17, 2024
Merged

Implement simplefs_file_open #56

merged 1 commit into from
Jun 17, 2024

Conversation

HotMercury
Copy link
Collaborator

@HotMercury HotMercury commented Jun 17, 2024

In the registration of simplefs_file_ops callbacks, there is no open operation, which may lead to creating unexpected space. This commit adds an open operation to handle file truncation when opening files with O_WRONLY, O_RDWR, and O_TRUNC flags. This prevents unintended space allocation by ensuring proper truncation of files.

The implementation checks the flags associated with the file opening mode and performs truncation if the file is being opened for write or read/write and the O_TRUNC flag is set. Truncation is achieved by reading the file's index block from disk, iterating over the data block pointers, releasing the associated data blocks, and updating the inode metadata (size and block count).

Close #55

In the registration of simplefs_file_ops callbacks, there is no open
operation, which may lead to creating unexpected space. This commit
adds an open operation to handle file truncation when opening files
with O_WRONLY, O_RDWR, and O_TRUNC flags. This prevents unintended
space allocation by ensuring proper truncation of files.

The implementation checks the flags associated with the file opening
mode and performs truncation if the file is being opened for write or
read/write and the O_TRUNC flag is set. Truncation is achieved by
reading the file's index block from disk, iterating over the data block
pointers, releasing the associated data blocks, and updating the
inode metadata (size and block count).

Close #issue55
@jserv jserv merged commit 79a2831 into sysprog21:master Jun 17, 2024
2 checks passed
@jserv
Copy link
Collaborator

jserv commented Jun 17, 2024

Thank @HotMercury for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Register 'open' operation in simplefs_file_ops
2 participants