UPB-FILS-SdE2 / questions

0 stars 1 forks source link

[filesystem] `chmod` Related Question #115

Closed popescuatopg closed 7 months ago

popescuatopg commented 7 months ago

Question

Is the permissions_mode method from the FileDescriptorInfo trait for checking the File Descriptor permissions over a file (the permissions that the file was opened with) OR for checking the File permissions (the permissions that the file has at any given time)?

Problem

This issue refers to unmerged tests in the upstream for filesystem, more specifically 3

Per documentation for chmod:

This function changes the permissions on a certain file/directory specified by the path

Which is to be understood.

What I can not figure out is if the method permissions_mode belonging to the FileDescriptorInfo trait wants to replicate the fstat function from sys/stat.h (fstat) and return the permissions of the underlying file that the FD points to OR replicate the fcntl function from fcntl.h (fcntl) and retrieve the permissions of the FD (with which the file was opened --- fcntl(fd, F_GETFL))?

If it is wanted for permissions_mode to replicate the fstat function, wouldn't that mean that the FDInfo structure and the FileDescriptorInfo trait's implementation for it both have to be modified? If that's the case, I'd have no problem with modifying them myself, but just want to make sure I'm not modifying things I should not be and want to double check this is the way you intend us to do it.


Example

I will exemplify this by making use of the chmod_simple test's code:

#[test]
pub fn chmod_simple() {
    let mut fs = mount(1000);
    assert_eq!(fs.create("./file_chmod.txt", PermissionsMode::Write), Ok(0));
    let fd = fs
    .open("./file_chmod.txt", PermissionsMode::Write)
    .unwrap();
    assert_eq!(
        fs.file_descriptor_info(fd).unwrap().permissions_mode(),
        PermissionsMode::Write
    );
    assert_eq!(fs.chmod("./file_chmod.txt", PermissionsMode::Read), Ok(()));
    assert_eq!(
        fs.file_descriptor_info(fd).unwrap().permissions_mode(),
        PermissionsMode::Read
    );
}

Here the file_chmod.txt is created with Write permissions, after which the FILE'S permissions are modified to Read permissions by making use of chmod. In the end, we are trying to assert that the permissions of the File Descriptor are Read permissions, or so I think, but this is trying to assert that the File's permissions are Read permissions (???), whilst having them grabbed through the permissions_mode method implemented for the FDInfo structure from the FileDescriptorInfo trait.

IF we wanted to check the new permissions of the file, shouldn't we try to open that specific file again but with the newer permissions and having the open function return us OK since the new perms are matching?

Finally, reiterating my question: Is the permissions_mode method from the FileDescriptorInfo trait for checking the File Descriptor permissions over a file (the permissions that the file was opened with) OR for checking the File permissions (the permissions that the file has at any given time)?