myls Project
COP-3402
Table of Contents
Overview
In this project, you will develop a simple version of an ls
-style command that lists the contents of a given directory.
Input
USAGE: ./myls [dir]
The program should be called myls
. It only takes a single argument, which is optional. The argument is the path to a directory, either relative or absolute. If a directory is not provided, use the current working directory, i.e., ".", the dot directory.
Output
Error handling
- If the input directory is not accessible (due to non-existence, permissions, etc.), then exit with error code
EXIT_FAILURE
(stdlib.h).- How can you tell that the directory failed to open?
Output contents
For each entry in the directory (including hidden files, .
, and ..
), print the following information
- The name of the file in the directory (not including its full path, just the from the directory entry)
- The number of hard links to the file (from stat)
- The type of file (from stat), which is one of the following, corresponding the
S_IFMT
names without theS_IF
prefix:- REG
- DIR
- SOCK
- LNK
- BLK
- CHR
- FIFO
- The size of the file, which is either
- The number of directory entries if the file itself is a directory (S_IFDIR). Put "unknown" if the directory is inaccessible.
- The total size (from stat), in bytes, of the file for all other types
- If the file is a regular file (S_IFREG), then a preview of the file, consisting of the first 16 characters of the file (or the whole file if it is less than 16 characters), with spaces replacing any non-printable or non-ASCII characters.
Output format
Column | Contents | Format string |
---|---|---|
1 | name | "%16.16s\t" |
2 | # hard links | "%" PRIdMAX "\t" |
3 | type | String literals |
4 | size | "%" PRIdMAX "\t" |
5 | preview | "%s" |
Notes:
- PRIdMAX is a macro containing the format string for the maxmimum integer size and can be included with
#include <inttypes.h>
- For type, use the literal strings as given in Output contents, following by a "\t".
Example output
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402fall24/files/myls_example.tar tar -xvf myls_example.tar
We can inspect the contents of the directory:
ls -a myls_example/contents/
Output:
. .. lorem.txt message.png message.txt subdir
We can run our myls
program on the directory :
./myls myls_example/contents/
Output:
. 3 DIR 6 .. 3 DIR 3 message.txt 1 REG 6 hello lorem.txt 1 REG 738 Lorem ipsum dolo subdir 2 DIR 3 message.png 1 REG 865 PNG IHDR
Try also testing on /dev/
to see more file types:
./myls /dev
System call and library references
Do not use helper libraries or other simplified calls to achieve similar results as functions below. Just use the syscalls below for these aspects of the project.
Symbol | Reference | Reading |
---|---|---|
opendir() | man 3 opendir |
LPI 18.8 |
readdir() | man 3 readdir |
|
closedir() | man 3 closedir |
|
stat() | man 2 stat |
LPI 15.1 |
struct stat | man 2 stat |
|
st_mode | man 7 inode |
|
open() | man 2 open |
LPI 4.1 |
read() | man 2 read |
|
close() | man 2 close |
|
perror() | man 3 perror |
LPI 3.4 |
exit(EXIT_FAILURE) | man 3 exit |
man
is the command-line manual.- LPI is The Linux Program Interface book.
- Knowledge of memory management and string processing is assumed.
Submitting your project
Setup the repo
ssh into eustis, replacing
NID
with your UCF NID.ssh NID@eustis.eecs.ucf.edu
Create a new git repo
cd ~ mkdir myls cd myls/ git init echo "myls" > README git add README git commit -m "initial commit" README
Add the URL of your personal remote repository, replacing
NID
with your UCF NID.git remote add submission gitolite3@eustis3.eecs.ucf.edu:cop3402/NID/myls
Synchronize your local repo with the remote eustis3 repo.
git push --set-upstream submission master
Keeping your repository up to date
Use git commit
and git push
regularly to keep the remote repo up to date.
Building and running the tool
Your project should be buildable with make
and runnable with ./myls
, both from the root of your repo, i.e.,
make ./myls
Create a Makefile that will build your project and give the resulting program the name myls
.
Self-check
cd ~ git clone gitolite3@eustis3.eecs.ucf.edu:cop3402/NID/myls myls_new cd myls_new make wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402fall24/files/myls_example.tar tar -xvf myls_example.tar ./myls myls_example/contents/
Self-grading
cd ~/ git clone https://www.cs.ucf.edu/~gazzillo/teaching/cop3402fall24/repos/myls-grading.git cd myls-grading wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402fall24/files/myls-tests.tar tar -xvf myls-tests.tar
Look at README.md
for usage instructions.
Troubleshooting
If you make a mistake in typing the URL, you can remove the submission remote and try the add step again:
This will show what the current remote URL is:
git remote -v
This will remove the remote:
git remote rm submission
Then try re-adding the remote:
git remote add submission gitolite3@eustis3.eecs.ucf.edu:cop3402/NID/myls
And see if push will work now:
git push --set-upstream submission master
- Do not try creating a new repo if you make a mistake. You will not be able to push the new repo to gitolite3, since there already is one there. You can always make new changes and commit them to fix mistakes.
Grading schema
Criterion | Points |
---|---|
The git repo exists | 1 |
The program is written, builds, and runs as described here | 1 |
Prorated lines correct for public test cases | 2 |
Prorated lines correct for private test cases | 2 |
TOTAL | 6 |