Clarifications of exercise
Directory entries: you are required to use the first and second files
to work on. Note that these files are the 3rd and 4rth directory entries,
respectively. That is because "." and ".." are the first 2 directory
entries.
Useful information for exercise
Getting directory information
You can use the documentation on the "getdents" system call.
However, some of the documentation is a bit confusing, and there are
several versions depending on the system version, so below is some clarification
of the confusing part. You still need to refer to the docs.
The arguments to the system call are:
- fd of directory (which you get by using the "open" system call).
- address of a buffer to which the system call should transfer the data.
- size of buffer (how many bytes of directory information will be provided,
at most).
Returned value is how many bytes of information were transfered - less or
equal to the 3rd argument. It will be less if the total directory information
is less than the buffer size.
The data transfered to the buffer
is a "list" (i.e. a sequence of bytes containing one
structure followed by the next, etc.)
of directory entry structures, where each structure is as follows:
- dword: inode number (which you don't need in this exercise, but is there)
- dword: index of next valid
entry in directory, where the first is 0 (you will probably
have no need for this one). Note - previous version of this was incorrect,
and also the relevant Linux man page is incorrect (which is why I was
also confused) - good thing you don't need this item anyway.
- word: Size of this entry, including the file name,
this item, and the
above two. This item is important for the exercise.
- variable sized data: null terminated string - the file name. Note that
the space USED for this entry is always a multiple of 4, so in some cases
there will be "junk" characters after the null character.