SNU-ARC / 2024_spring_sysprog_Lab2

6 stars 3 forks source link

Question regarding error handling example #7

Open ZzeongB opened 5 months ago

ZzeongB commented 5 months ago

Hello, I have a question regarding error handling.

This is the example shown in README.md.

$ dirtree -v -s demo3
Name                                                        User:Group           Size     Perms Type 
----------------------------------------------------------------------------------------------------
demo3
  dir1                                                   sysprog:sysprog         4096 --x------  d
    ERROR: Permission denied
  dir2                                                   sysprog:sysprog         4096 r--------  d
    file1                                               Permission denied
    file2                                               Permission denied
    file3                                               Permission denied
  dir3                                                   sysprog:sysprog         4096 rwx------  d
    file4                                                sysprog:sysprog            0 -----x---   
    file5                                                sysprog:sysprog            0 ----w----   
    file6                                                sysprog:sysprog            0 ---r-----   
----------------------------------------------------------------------------------------------------
6 files, 3 directories, 0 links, 0 pipes, and 0 sockets                         12288

The summary on the bottom line says there are 6 files, 3 directories, 0 links and so on. The example says Permission denied for file 1, 2, and 3.

I supposed that 6 files counts files 1 to 6. However, I was curious how should we count files that we do not have permission for metadata. Since we do not have permission to open metadata for those files, we do not know the actual type of those files. In this case, should I just treat them as regular file, as shown in this example?

Thank you.

yunjayh commented 5 months ago

TL;DR

The case will not used for the test cases. (please refer https://github.com/SNU-ARC/2024_spring_sysprog_Lab2/issues/5#issue-2204778093) You can check your output and the reference's one without the -s option. This means that Permission denied should be printed for each file items, but the aggregated total for types and size wouldn't matter.


Here is the reason why there could be several ways to implement it.

As you mentioned, the process wouldn't know their types for the files which cannot be accessed for their metadata (e.g. file 1, 2, 3). That's because dir2 doesn't have x permission for any users. Permission on UNIX-like systems explains this.

However, as you can see in man page of readdir for some filesystems (including ext4), struct dirent supports d_type. This helps the user to gain knowledge about types of each entry. Since the given VM system is using ext4 filesystem, it's technically possible to access the entry's file type.

In conclusion, you can get the types of files even though you don't have permission to access the metadata. However, we'll not evaluate it as a test cases. So, you can implement your own code, ignoring to aggregate summary of files like file 1, 2, 3.

ZzeongB commented 5 months ago

Thank you very much!

m-joon-ixix commented 5 months ago

@yunjayh 관련 이슈에서 한가지 더 궁금한 것이 있습니다. no permission to open file metadata 인 경우가 있을 때 summary mode로는 테스트하지 않겠다고 공지해주셨는데, directory-only mode도 마찬가지일까요?

특정 entry가 directory인지 판별하려면 entry의 metadata에 접근을 해야 할텐데, permission이 없다면 directory인지 알 방법이 없을 것 같아서 문의드립니다.

물론 dirent.d_type 으로 알아올 수 있긴 할텐데, 위에 설명해주신걸 보니 이게 권장하는 방식은 아닌 것 같아서 여쭤봅니다.

yunjayh commented 5 months ago

https://github.com/SNU-ARC/2024_spring_sysprog_Lab2/issues/5 에서 언급했듯, Metadata에 대해 Permission이 없는 directory에 대해서는 subdirectory가 없을 예정입니다. 따라서 수강생분들은 그런 상황에서 dirent.d_type을 이용해 디렉토리를 출력하게 구현하여도 괜찮고, 혹은 metadata에 대한 permission이 없기 때문에 디렉토리가 있는지 없는지 몰라 출력을 하지 않아도 괜찮습니다. (채점에는 영향이 없을 것입니다) +) dirent.d_type을 이용하는 점이 권장되지 않는 것은 아닙니다.