Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction In this assignment, you will practice using system calls to access the filesystem, navigate the directory structure, and parse file stats. Learning Outcomes Describe

Introduction
In this assignment, you will practice using system calls to access the filesystem, navigate the directory structure, and parse file stats.
Learning Outcomes
Describe the API for different operations related to files (Module 3 MLO 3)
Describe the API for different operations related to directories (Module 3 MLO 6)
How to define and use structures in C?(Module 2 MLO 3)
Specifications
NAME
tree - recursively list files and directories
SYNOPSIS
tree [OPTION]...[DIRECTORY]...
DESCRIPTION
Recursively list all files found in DIRECTORYs. If no DIRECTORY is provided, the current directory is used.
By default, output is sorted alphabetically.
LISTING OPTIONS
-a Print hidden files. By default, tree does not print hidden files beginning with a dot ('.') character.
The filesystem constructs `.' and `..' are never printed even with the -a option.
-d Print only directories, no files.
FILE OPTIONS
-p Print permissions according to the mode string format specified for `ls' according to POSIX.
-u Print the username, or UID # if no username is available, of the file.
-g Print the group name, or GID # if no group name is available, of the file.
-s Print the size of each file in bytes.
SORTING OPTIONS (default: alphabetic sorting)
-r Sort the output in reverse alphabetic order.
-t Sort the output by last modification time instead of alphabetically.
-U Do not sort. List files according to directory order.
-h Print this message
AUTHOR
You, again!
NOTES
Source code must compile without errors againt the c99 standard on os1 to receive ANY credit. Example:
gcc -std=c99...
Source code must compile without errors for FULL credit, with the following flags:
gcc -std=c99-Wall -Wextra -Wpedantic -Werror ...
Detailed instructions
In this assignment, you will write a small library that parses files and directory structures to list files and directory contents recursively in a tree format, where each subdirectory is indented from the last. You will implement basic sorting and print the file permissions, username, group, and file size.
Example output
$./tree -pugs /usr/share/man/en
[drwxr-xr-x root root 66]/usr/share/man/en
[drwxr-xr-x root root 148] man2
[-rw-r--r-- root root 2407] close.2.gz
[-rw-r--r-- root root 1808] getdomainname.2.gz
[-rw-r--r-- root root 7736] getrlimit.2.gz
[-rw-r--r-- root root 4852] madvise.2.gz
[-rw-r--r-- root root 5949] mount.2.gz
[-rw-r--r-- root root 1445] sysinfo.2.gz
[-rw-r--r-- root root 1962] umask.2.gz
[drwxr-xr-x root root 158] man3
[-rw-r--r-- root root 2141] encrypt.3.gz
[-rw-r--r-- root root 2004] fclose.3.gz
[-rw-r--r-- root root 2143] fflush.3.gz
[-rw-r--r-- root root 2214] lockf.3.gz
[-rw-r--r-- root root 2700] rand.3.gz
[-rw-r--r-- root root 3157] strtok.3.gz
[-rw-r--r-- root root 1359] toupper.3.gz
[-rw-r--r-- root root 1502] updwtmp.3.gz
[drwxr-xr-x root root 21] man4
[-rw-r--r-- root root 10229] st.4.gz
[drwxr-xr-x root root 23] man5
[-rw-r--r-- root root 4761] utmp.5.gz
[drwxr-xr-x root root 64] man7
[-rw-r--r-- root root 3165] environ.7.gz
[-rw-r--r-- root root 4731] hier.7.gz
[-rw-r--r-- root root 4278] suffixes.7.gz
Guidance
In this assignment, you will be working with two source files, one of which will produce a library (shared object) and the other which acts as a test-bench to model a third party using your library.
What is a shared library? It's just a collection of symbol definitions (functions, objects) that are packaged into a shared object (.so) file format. If your program is linked against a shared library, any symbols that you use, which are part of that library, will have undefined values when your program starts. A program called the loader comes along during the initialization process (before main() is called), and it loads the shared library into memory, and the linker updates the table of symbols to point to the appropriate locations in that library. This is actually how all of the functions and symbols you use from the standard C library work. If your program calls printf, the libc.so file is loaded into your program's virtual memory space, and the printf symbol is resolved at runtime by the linker.
Shared libraries are really useful. For one, since they contain mostly read-only information (function instructions, constants), shared libraries can be, well, shared. There is one copy of the shared library in memory, and every program that is using it simply has it mapped into each of their private virtual memory address spaces. From the perspective of the program, it's the only one using that library. From the perspective of the kernel, it just save a bunch of memory! It also means your program is a lot smaller, since the instructions and data for common things are actually stored already in the system, separate f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions