Notes:
1. Failure to follow the instructions and rules may lead to failed test cases and/or a final grade of 0. 2. You can do this assignment individually or in a team of two. If you are doing it in a group, only one submission per group is required. For example: If Person A and B are in one group, only one person has to accept the assignment link and do the submission. Person A: upload all files (.txt, .c), group.txt. Person B: no submission required. For group assignment, submit a ” group.txt ” indicating the Github ids of each member. For example: if I am working with John in a group then group.txt will be as below: hazra.imran Johndoe 3. You may submit multiple times until the deadline. Grade penalties will be imposed for late submissions (see the course outline for the details). 4. Always plan before coding. 5. All the codes in this lab must be done using C language only. No other languages should be used. 6. Use function-level and inline comments throughout your code. We will not be specifically grading documentation. However, remember that you will not be able to comment on your code unless sufficiently documented. Take the time to document your code as you develop it properly. 7. We will carefully analyze the code submitted to look for plagiarism signs, so please do not do it! If you are unsure about what is allowed, please talk to an instructor or a TA.
Coding Rules
You have to follow the file name as specified in the instructions.
Makefile : Makefile provides the following functionality:
all : compiles your program (this is the default behavior), producing an
executable file named the same as the C file.
clean : deletes the executable file and any intermediate files (.o, specifically)
You will receive 0 if your makefile fails.
Check your build to ensure that there are no errors.
Visit TA's programming office hours to get help.
Background The Unix/Linux ls command is used to list files and directories in the file system. For this assignment you will be implementing a version of ls which supports only a limited set of options. Note : The format of the output od myls [options] [file list] should be EXACTLTY same as ls [options] [file lists] Note: Mac-OS’s ls is different; must develop under Linux. By completing this assignment, you will:
- Understand what an inode is, and understand its role in the Unix file system.
- Know how to use system calls to navigate the Unix file system from a user-level program.
- Understand how files and directories are organized and stored in Unix. Assignment requirements In this assignment, you will be creating a program named myls (short for MY List ). Your program should support below mentioned functionalities.
When calling the program, it will take the form:
./myls [options] [file list] [options] : Optional options from the list below. May be specified in any order or grouping, such as (none) , -i , -i -l -R , -iRl -R -li , -lR … [file list] : Optional space separated list of paths to files or directories to display. Options: Implement the following options (you need not support any other options, and you need not support the long version of the option names):
-i : Print the index number of each file
-l : Use a long listing format
-R : List subdirectories recursively. (Make sure that recursion must not cause any
infinite loop) The format of the output of myls [options] [file list] should be EXACTLTY same as ls [options] [file lists]
Sort : Sort the files and directories lexicographically. When printing directories recursively
(-R option), do a depth-first traversal of the directories, entering sibling directories in lexicographical order. Hint : Use ls -R to check your myls output. Both should be same.
Date Format : When using the -l option you must print out date information in the
following format: mmm dd yyyy hh:mm
For example:
Oct 2 2021 14:
Sep 30 2021 0 0 :
Specifically :
mmm Initial three characters of month name; first letter capitalized. dd Two digit day of month; pad with space ( ) for single digit day. yyyy Four digit year number; pad with spaces ( ) if less than 4 digits. hh Two digit hour (24 hour clock); pad with zero (0) if less than 2 digits. mm Two digit minute; pad with zero (0) if less than 2 digits. Special Paths You must support the following paths with special meaning (x and y are arbitrary names): / Root directory (when at the front of path of the path such as /usr) /x/y Absolute path to a file or directory /xy/ Absolute path to a directory x/y Relative path to a file or directory x/y/ Relative path to a directory ~ Users home folder (can be used such as ~ or ~/test/this/out )
. Current directory .. Up one directory (can be used such as ../ or ../../ oh / my /../ really/.. )
- Wildcard (such as *.c); most of this work will be done by the shell! Simplifications vs built-in ls command Do not print the Total 123456 line at the top of the output when using the -l option. All options (if any) must be specified before any files/directories (if any). You do not need to support quoted strings as arguments: $ myls “thank goodness we dont/have to support this/” $ myls ‘it is like a “gift” not to do this!.txt’ $ myls ‘seemed like a good idea.c’ Error Handling You must display a meaningful error and exit when: User specified an unsupported option such as -a. It is undefined behavior if the user specifies an argument such as –version. You should display a message Error : Unsupported Option User specified a nonexistent file/directory.
The message should be Error : Nonexistent files or directories
Testing
Test all permutations of the possible options, including no options at all.
Test listing edge cases:
on a file; on an empty directory; on a very large directory
ls on different file types (normal, symbolic). Print the relevant data of what it is
pointing to or the link itself. Check stat() and lstat().
Many Linux/Unix systems create an automatic alias for ls so that it automatically uses
some options.
To see your current alias (if any) run:
$ alias ls
To temporarily clear your alias for the current terminal, run:
$ unalias ls
Example commands ( for easy reference)
Hints
Initially concentrate on getting the listing for a directory correct; later worry about
recursion.
Focus on extracting the proper information and just printing it. Once you have that all
done work on making the format match the ls command.
Consult the provided file infodemo.c and secret_hearder.h to see what calls to use to
get actual group and user names.
Don't forget to test your code on directories with symbolic links in them.
Restrictions
You may not use 3 rd^ party libraries. For example, you must write the path processing,
file listing, and directory recursion code yourself. Standard c libraries are allowed.
You may not copy other people's code. If you are copying and adapting the code from
external sources, credit the source.
Your code should make use of a modular design; try breaking your code into
meaningful modules and reasonable functions!
You must implement sorting yourself (any O(n 2 ) or better Algorithm OK).
You may not copy-and-paste sorting code from online; you may use any built-in
routines in either C or Linux which will sort. You can use alphasort().
Test Cases
- Run the executable with all the combinations of iRl (-i, -l, -R, -lR, -iR, -il, -iRl) including without passing an of the options
- Run the executable by passing a file or directory along with the (iRl) options
- Place a subdirectory (with a few files) inside your original directory and test if the iRl options are working fine for the files inside the subdirectory.
Submission Instructions:
For A4, the concrete required deliverables are:
- group.txt
- myls.c file
- Makefile
Grading Criteria
Correct make files + 10 Prints entries for a single file argument + Prints entries for a single directory argument + Prints entries for a multiple file argument + Prints entries for a multiple directory argument + Prints entries for mixed files and directories + Handles case when no file or directory given, and no options + Option -R with sort + Option -i + Option -l + Option combinations: -Ri, -Rl, -il, -Ril + Handles symbolic links properly. + Special paths + Error handling +