Operating systems 1 -- 2009-2010 -- info.uvt.ro/Laboratory 2
Quick links:
- front;
- laboratories: agenda, 1, 2, 3, 4, evaluation, tools, references, repository;
- projects: 1, 2, repository;
Source code management
editQuick startup
edit# create a folder to hold all projects
mkdir ./workbench
# and go there
cd ./workbench
# checkout the example source code
svn checkout svn://hephaistos.info.uvt.ro/info/2009-2010/operating-systems-1/examples/laboratory-1/example-1
## the username is `guest` and the password `guest`
# modify the source code
nano ./main.c
# commit the modified files to the server
svn commit
## the `guest` user cannot commit changes
# synchronize the source code with the one on the server
svn update
References
editPlease consult the dedicated page.
Single-file C program
editPlease consult the contents of examples/laboratory-1/example-1 on SVN.
Manual building
editgcc -o ./calc ./main.c
Automated building (with a Bash script)
edit- the script content:
#!/bin/bash
gcc -o ./calc ./main.c
- invoking the script:
chmod +x ./build.sh
./build.sh
Automated building (with a Make script)
edit- the makefile content:
default : ./calc
./calc : ./main.c
gcc -o ./calc ./main.c
- invoking make:
make
Multi-file C program
editPlease consult the contents of examples/laboratory-1/example-2 on SVN.
Automated building
edit- the makefile content:
default : ./calc
./calc : ./main.o ./add.o ./substract.o ./usage.o ./parsing.o
gcc -o ./calc ./main.o ./add.o ./substract.o ./usage.o ./parsing.o
./main.o : ./add.h ./substract.h ./usage.h
./add.o : ./add.h ./parsing.h ./usage.h
./substract.o : ./substract.h ./parsing.h ./usage.h
./parsing.o : ./parsing.h ./usage.h
./usage.o : ./usage.h
%.o : %.c
gcc -c -o $@ $<
Assignment
editSynopsis
edit./fsq access <path> f|r|w|x
./fsq link <source> <target>
./fsq unlink <path>
./fsq mkdir <path>
./fsq rmdir <path>
./fsq rename <old> <new>
./fsq stat <path>
./fsq ls <path>
Description
editImplement a simple file system query utility that wraps some basic POSIX system calls:
- queryies:
- file creation and destruction:
- folder creation and destruction:
- renaming:
- folder listing:
Notes
edit- you should have a makefile, that builds an executable named fsq in the current directory (as the default target);
- each command (like the ones below) should be in it's own .c file;
- include at least three different test-cases for each command in the makefile (except for stat and ls);
- each command should either have the exit code 0 in case of success, or the errno value of the last executed system call;
- each command should thoroughly check the arguments and system call usage; for example:
- if the source or destination file exist or not (using access system call);
- in case of link and unlink, if the source is truly a file (using stat system call);
- (the same in the case of rmdir);
Output
editOutput for ./fsq stat /tmp: for each file display:
- entity type: file, folder, or other;
- UID and GID;
- entity permissions (mode);
- size (in bytes);
type: folder
uid: 0
gid: 0
mode: 1777
size: 180
Output for ./fsq ls /etc (each entity name on a separate line):
fstab
inittab
...
Skeleton
editFor this you could start from the contents of examples/laboratory-1/example-4 on SVN.
References
editPlease consult the dedicated page -- Linux/UNIX programming (C/C++).