Title | COMP2521 21T3 Assignment 1 |
---|---|
Course | Data Structure & Algorithms |
Institution | University of New South Wales |
Pages | 16 |
File Size | 3.8 MB |
File Type | |
Total Downloads | 108 |
Total Views | 138 |
COMP2521 21T3 Assignment 1,an assignment on File systems in linux...
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
[08/10 10:00] [09/10 16:30]
FsMkfile
/(root)
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
/home cd
/ .
-
_ .
..
. ls
ls . .
.
..
/
/ /tmp
tmp
/tmp/tmp.123 /tmp//tmp.123
tmp.123 tmp.123
tmp tmp
tmp /(root)
bin
ls
etc
mv
passwd
home
ssh
jas
init
tmp
tmp.123
tmp.456
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
.
..
passwd
/home/jas/cs2521/lecs ../cs2521/labs
/etc/
/ /home /home/jas /home/jas/cs2521 .. ../cs2521
/home/jas/cs2521/lecs
/home/jas
../cs2521/labs
/ /home /home/jas
/home/jas/cs2521
$ unzip /web/cs2521/21T3/ass/ass1/downloads/files.zip
files.zip
unz
Makefile Fs.h Fs.c utility.h utility.c FileType.h listFile.c
listFile
testFs.c make testFsColored
listFile
testFs Fs.c utility.c
utility.h Fs.c utility.c
testFs.c
utilit
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
FsGetCwd void FsGetCwd(Fs fs, char cwd[PATH_MAX + 1]);
cw PATH_MAX
FsFree void FsFree(Fs fs);
Fs
FsMkdir void FsMkdir(Fs fs, char *path);
FsMk mkdir
mkdir: cannot create directory 'path': Fi mkdir: cannot create directory 'path': No mkdir: cannot create directory 'path': No
path labs/lab01
labs/lab01
mkdir: cannot create directory 'labs/lab01': File exists
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
int main(void) { Fs fs = FsNew(); // this is equivalent to FsMkdir(fs, "tmp"); because initially, // the current working directory is the root directory FsMkdir(fs, "/tmp"); FsMkdir(fs, "/tmp/tmp.123"); FsMkdir(fs, "/usr"); FsMkdir(fs, "/bin"); // see the section for FsTree for details FsTree(fs, NULL); }
/ bin tmp tmp.123 usr
FsMkfile void FsMkfile(Fs fs, char *path);
touch
mkfile: cannot create file 'path': File mkfile: cannot create file 'path': Not a mkfile: cannot create file 'path': No su
int main(void) {
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
/ bin mkdir mkfile hello.c world.c
FsCd void FsCd(Fs fs, char *path);
NULL NULL NULL cd
cd: 'path': Not a directory cd: 'path': No such file or direc
int main(void) { Fs fs = FsNew(); FsMkdir(fs, "/home"); FsCd(fs, "home"); FsMkdir(fs, "jas"); FsCd(fs, "jas"); FsMkdir(fs, "cs2521"); FsCd(fs, "cs2521"); FsMkdir(fs, "lectures"); FsMkdir(fs, "tutes"); FsMkdir(fs, "labs"); FsTree(fs, NULL); }
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
NULL ls
ls: cannot access 'path': Not a dire ls: cannot access 'path': No such fi
int main(void) { Fs fs = FsNew(); printf("---\n"); // marker to separate output FsLs(fs, "/"); printf("---\n"); FsMkfile(fs, "hello.txt"); FsMkdir(fs, "tmp"); FsLs(fs, "/"); }
----hello.txt tmp
FsPwd void FsPwd(Fs fs);
pwd
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
FsTree void FsTree(Fs fs, char *path);
NULL NULL NULL tree
tree: 'path': Not a directory tree: 'path': No such file or dire
int main(void) { Fs fs = FsNew(); FsMkfile(fs, "hello.txt"); FsMkfile(fs, "world.txt"); FsMkdir(fs, "bin"); FsMkfile(fs, "bin/ls"); FsMkfile(fs, "bin/pwd"); FsMkdir(fs, "home"); FsMkdir(fs, "home/jas"); FsMkfile(fs, "home/jas/todo.txt"); FsMkfile(fs, "home/jas/mail.txt"); FsTree(fs, "/home/jas"); printf("---\n"); // marker to separate output FsTree(fs, NULL); }
/home/jas il t t
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
FsPut void FsPut(Fs fs, char *path, char *content);
put: 'path': Is a directory put: 'path': Not a directory put: 'path': No such file or
int main(void) { Fs fs = FsNew(); FsMkfile(fs, "hello.txt"); FsPut(fs, "hello.txt", "hello\n"); FsPut(fs, "./hello.txt", "world\n"); // overwrites existing content }
FsCat void FsCat(Fs fs, char *path);
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
int main(void) { Fs fs = FsNew(); FsMkfile(fs, "hello.txt"); FsPut(fs, "hello.txt", "hello\n"); FsCat(fs, "hello.txt"); FsPut(fs, "./hello.txt", "world\n"); // overwrites existing content FsCat(fs, "/hello.txt"); }
hello world
FsDldir void FsDldir(Fs fs, char *path);
rmdir
dldir: failed to remove 'path': Directo dldir: failed to remove 'path': Not a d dldir: failed to remove 'path': No such
int main(void) { Fs fs = FsNew(); FsMkdir(fs, "hello"); FsMkdir(fs, "hello/world"); FsTree(fs, NULL); printf("---\n"); // marker to separate output FsDldir(fs, "hello/world"); FsDldir(fs, "hello");
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
rm
rm mktemp -d cd
recursive
dl: cannot remove 'path': Is a dl: cannot remove 'path': Not dl: cannot remove 'path': No s
int main(void) { Fs fs = FsNew(); FsMkdir(fs, "hello"); FsMkfile(fs, "hello/world.txt"); FsMkfile(fs, "abc.txt"); FsTree(fs, NULL); printf("---\n"); // marker to separate output FsDl(fs, true, "abc.txt"); FsTree(fs, NULL); printf("---\n"); // marker to separate output FsDl(fs, true, "hello"); FsTree(fs, NULL); }
/ abc.txt hello world.txt --/ hello
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
NULL src
src
dest
src src
dest
src dest dest
recursive cp
cp
cp
src
int main(void) { Fs fs = FsNew(); FsMkfile(fs, "hello.txt"); FsPut(fs, "hello.txt", "hello\n"); FsMkfile(fs, "world.txt"); FsPut(fs, "world.txt", "world\n"); FsCat(fs, "world.txt"); printf("---\n"); char *src[] = { "hello.txt", NULL }; FsCp(fs, false, src, "world.txt"); FsCat(fs, "world.txt"); printf("---\n"); FsTree(fs, NULL); }
world --hello --/ hello.txt world.txt
src dest
dest
src
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
FsMv void FsMv(Fs fs, char *src[], char *dest);
NULL
src
dest
dest mv bin
/(root)
etc
passwd
ssh
...
tmp
init
home
bin
jas
tmp.123
tmp.456
...
... ls
mv
testFs.c char *src[] = { "/bin", NULL }; FsMv(fs, src, "/tmp");
mv
src src
mv
int main(void) { Fs fs = FsNew(); (
)
tmpdir
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
dest
src
dest
path
FsMkdir
NULL
testFs.c
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1
Fs
valgrind $ valgrind -q --leak-check=full ./testFs > /dev/null
12/10/2021, 10:39
COMP2521 21T3 - Assignment 1...