ls (list), which is the utility commonly found in Unix-like operating
systems, is used to display a list of files and directories in a specified
location, providing options to control the display targets or format. In this
project, you will be tasked with implementing your own simplified version of
ls.
Make sure you check the
general guide for
assignment and the
course policy web page before
doing this assignment or any of the EE309 assignments. In particular, note that
you may consult with the course instructor, TAs, etc. while doing
assignments, as prescribed by that web page.
A. Inputs
- Your program should take the paths to the file or directory from command-line arguments, which is the targets to be displayed. The given path is can be either absolute or relative. For example,
$ ./ls309 /home/user/some_abs_path
$ ./ls309 ./some_rel_path
$ ./ls309 ./file1 ./file2 ./file2
$ ./ls309 ./some_file1 ./some_dir/ ./some_file2
should be properly handled.
- Your program should support an empty argument. In this case, use the current directory as the display target. For example,
$ ./ls309
should give same result with
$ ./ls309 .
- Your program should support three options:
-a
, -l
, and -R
. Any combination of those options such as
$ ./ls309 -a
$ ./ls309 -a -l
$ ./ls309 -aR
$ ./ls309 -alR
should be properly handled.
Note that the option strings can be located in any position of arguments. For example,
$ ./ls309 -alR ./file
$ ./ls309 ./file -alR
$ ./ls309 ./file1 -a ./file2 -lR
also should be properly handled.
For the functionality of each options, refer C. Options.
B. Outputs
C. Options
- The behavior of your program should be altered based on specified options. Note that even if multiple options are specified, the functionalities that each option provides should be properly worked.
-a
option
-l
option
-R
option
- An option to display directories recursively. If
-R
option specified, your program should list not only the contents of the specified directory will be listed, but also the contents of all its subdirectories.
$ ./samplels309
dir
file
samplels309
$ ./samplels309 -R
.:
dir
file
samplels309
./dir:
file1
file2
D. Etc
- Your program should properly handle errors returned from library functions and print corresponding textual error messages such as
"No such file or directory"
.
- Your program should be robust from any kind of input (i.e. should not crash unintendedly). If the program faces unexpected crashes, you will get 0 points on corresponding test cases.
- Your program should not have any kind of memory leak. Your program should
free
every memory which returned from memory-allocating functions such as malloc
, calloc
, or strdup
.
Notes: We provide the sample reference program
samplels309
. Your program should follow the behavior of a
reference program for ambiguous or undocumented specifications. The grading
will be done by comparing the output of this reference program and yours.
Do not try to debug or reverse engineer the given reference program
since it is obfuscated to prevent such tries.
The given skeleton code (Updated on Sep 6, 6124bf773e452d5b739199f15a4fcba2) was mainly designed with four tasks: 1) Option parsing & Entries sorting, 2) Directory listing and Support -a
option, 3) Support -l
option, 4) Support -R
option. You can search // TODO
from the given skeleton code to locate each task's implementation points.
- Option parsing & Entries sorting
- Finish implementation of option parsing routine of
main
function. Properly set the variables based on parsed options.
- Finish implementation of
sort_dnode_entries
function, which sorts to the provided entry list and returns them as a pointer array. You may want to use compare_dnode_name
helper function.
- Directory listing and Support
-a
option
- Implement
parse_dir
function, which parses the directory entries from a given path and returns the entry list and their counts. You may need to use other directory-related library functions (opendir
, readdir
, closedir
) or other helper functions from the skeleton code (concat_path
, strdup
).
- Support
-a
option into your implementation of parse_dir
function.
- Support
-l
option
- Finish implementation of
parse_dnode
function. Parse the information of the file from the given path and properly set it into an entry object. Note that you need to follow or not follow the link based on follow_link
parameter, which should be properly set by the caller based on the situation. You may need to use library functions for file information(stat
, fstat
, lstat
).
- Finish implementation of
display_dnode_long
function. Get the link target for link entries to print it correctly. You may want to use readlink
function to get link target.
- Support
-R
option
- Finish implementation of
print_dir
function. Properly identify the sub-directories of the current display target and display them recursively.
For error handling, check the return values of library functions in your overall implementations and print the proper error message into
stderr
. You may want to use the
errno
variable and
perror
/
strerror
functions.
For the robustness of your program, always be aware of memory-related bugs in your implementation. You may use
Valgrind or
Address Sanitizer to detect whether your program has a memory bugs and leaks.
You can pass all test cases from
test-error
if your program correctly handles errors and is bulletproof from memory error and memory leaks.
A. Platform
- Use KAIST KLMS to submit your project.
- We will not accept submission via email.
B. File structure
- Your submission should be a single gzipped tarball having proper name
<YourStudentID>_assign1.tar.gz
. For example, if your student ID is 20211234
, your submission would be 20211234_assign1.tar.gz
- src directory that satisfy the requirements of the project. You can create additional directories for your convenience. But please make sure that Makefile works correctly.
- Makefile to compile your submission via
make
command. Makefile should support two commands: 1) make
, which compiles your code to create program ls309
, and make clean
, which cleans the build artifacts such as binary, .o files, etc. We provided the sample Makefile for the given skeleton code.
- README.md file to describe 1) any reference, 2) colleague who discuss with, 3) any additional information that staffs have to know.
- Other files (provided reference program, test scripts, ethics document...) are fine unless they make the size of the submission file massive or hinder grading steps.
- The below shows the structure of the directory and the way to create a tarball.
$ ls -R ./20211234_assign1
./20211234_assign1:
Makefile README.md src
./20211234_assign1/src:
dir.c dnode.c include main.c
./20211234_assign1/src/include:
dir.h dnode.h
$ tar -czvf 20211234_assign1.tar.gz 20211234_assign1/
20211234_assign1/
20211234_assign1/README.md
20211234_assign1/Makefile
20211234_assign1/src/
20211234_assign1/src/dir.c
20211234_assign1/src/main.c
20211234_assign1/src/dnode.c
20211234_assign1/src/include/
20211234_assign1/src/include/dnode.h
20211234_assign1/src/include/dir.h
$ ls 20211234_assign1.tar.gz
20211234_assign1.tar.gz
- Your code should be compiled properly with
gcc209
compiler, as the Makefile of skeleton does. gcc209
command is provided defaulty on eelabg12
(Haedong lounge server).
$ which gcc209
/usr/bin/gcc209
$ cat /usr/bin/gcc209
#!/bin/bash
gcc -Wall -Werror -ansi -pedantic -std=c99 "$@"
- Make sure to run
make clean
before submitting.
Notes: 1) We will deduct 5% of the score if your submission fails to grade because you don’t follow the structure above. 2) Don’t include Hangul in any file or directory name when you submit.
- Please use Piazza to post any questions about the assignment.
- If you have any issues in accessing a server for the assignment, please contact the TA’s immediately.
A. Scoring
- We will test your codes with test cases that check the functionality of your program based on the reference program. The test cases consist of the following categories.
test-basic
(20%)
test-a
(10%)
test-l
(15%)
test-R
(15%)
test-advanced
(30%)
test-error
(10%)
- We only provide the subset of full test cases as a sample. You can grade your program with sample test cases by following command.
B. Test environment
- We will test your codes under ubuntu 20.04.6 LTS (same environment with Haedong lounge server).
If your submission file does not contain the expected files, or your code cannot be compiled at eelabg12
(Haedong lounge server) with gcc209
compiler, we cannot give you any points. Please double check before you submit.