diff --git a/week10/_ex1.txt b/week10/_ex1.txt new file mode 100644 index 0000000..72867bc --- /dev/null +++ b/week10/_ex1.txt @@ -0,0 +1 @@ +RinRi diff --git a/week10/_ex1_1.txt b/week10/_ex1_1.txt new file mode 100644 index 0000000..72867bc --- /dev/null +++ b/week10/_ex1_1.txt @@ -0,0 +1 @@ +RinRi diff --git a/week10/_ex1_2.txt b/week10/_ex1_2.txt new file mode 100644 index 0000000..72867bc --- /dev/null +++ b/week10/_ex1_2.txt @@ -0,0 +1 @@ +RinRi diff --git a/week10/_ex3.txt b/week10/_ex3.txt new file mode 100755 index 0000000..039727e --- /dev/null +++ b/week10/_ex3.txt @@ -0,0 +1 @@ +lol diff --git a/week10/ex1.sh b/week10/ex1.sh new file mode 100755 index 0000000..1ab7087 --- /dev/null +++ b/week10/ex1.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rm -f _ex1* +echo "RinRi" > _ex1.txt +ln -f _ex1.txt _ex1_1.txt +ln -f _ex1.txt _ex1_2.txt +ls -i _ex1.txt > ex1.txt +ls -i _ex1_1.txt >> ex1.txt +ls -i _ex1_2.txt >> ex1.txt diff --git a/week10/ex1.txt b/week10/ex1.txt new file mode 100644 index 0000000..063fde8 --- /dev/null +++ b/week10/ex1.txt @@ -0,0 +1,3 @@ +6817598 _ex1.txt +6817598 _ex1_1.txt +6817598 _ex1_2.txt diff --git a/week10/ex2.sh b/week10/ex2.sh new file mode 100755 index 0000000..ede974a --- /dev/null +++ b/week10/ex2.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +rm -f ../week01/file.txt _ex2.txt +echo "file" > ../week01/file.txt +ln -f ../week01/file.txt _ex2.txt +inode=$(find _ex2.txt -printf '%i') +find .. -inum "$inode" > ex2.txt +find .. -inum "$inode" -exec rm {} \; >> ex2.txt diff --git a/week10/ex2.txt b/week10/ex2.txt new file mode 100644 index 0000000..62b56a6 --- /dev/null +++ b/week10/ex2.txt @@ -0,0 +1,2 @@ +../week10/_ex2.txt +../week01/file.txt diff --git a/week10/ex3.sh b/week10/ex3.sh new file mode 100755 index 0000000..6eefe1e --- /dev/null +++ b/week10/ex3.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +rm -f _ex3.txt +echo "lol" > _ex3.txt +chmod a-x _ex3.txt +ls -l _ex3.txt > ex3.txt +chmod 707 _ex3.txt +ls -l _ex3.txt >> ex3.txt +chmod a=u _ex3.txt +ls -l _ex3.txt >> ex3.txt +echo "660 means read and write permissions (6) for user and the group" >> ex3.txt +echo "775 means read, write, and execute permissions (7) for user and the group, and read and execute permissions (5) for others" >> ex3.txt +echo "777 means read, write, and execute permissions (7) for everyone" >> ex3.txt diff --git a/week10/ex3.txt b/week10/ex3.txt new file mode 100644 index 0000000..f3b5c03 --- /dev/null +++ b/week10/ex3.txt @@ -0,0 +1,6 @@ +-rw-r--r-- 1 rinri users 4 Nov 15 21:08 _ex3.txt +-rwx---rwx 1 rinri users 4 Nov 15 21:08 _ex3.txt +-rwxrwxrwx 1 rinri users 4 Nov 15 21:08 _ex3.txt +660 means read and write permissions (6) for user and the group +775 means read, write, and execute permissions (7) for user and the group, and read and execute permissions (5) for others +777 means read, write, and execute permissions (7) for everyone diff --git a/week10/ex4.c b/week10/ex4.c new file mode 100644 index 0000000..54ddf02 --- /dev/null +++ b/week10/ex4.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include + +struct file { + ino_t inode; + char names[64][256]; + int sz; +}; + +int putToFiles(char name[256], ino_t inode, struct file *files, int sz) { + // if found the same inode + for (int i = 0; i < sz; ++i) { + if (files[i].inode == inode) { + memcpy(files[i].names[files[i].sz++], name, 256); + return sz; + } + } + + // if not found + files[sz].inode = inode; + memcpy(files[sz].names[0], name, 256); + files[sz].sz = 1; + sz++; + + return sz; +} + +int main() { + DIR *d = opendir("./tmp"); + if (d == NULL) { + perror("opendir"); + exit(1); + } + + struct file files[64]; + int sz = 0; + + struct dirent *entry; + while ((entry = readdir(d))!= NULL) { + if (entry->d_name[0] == '.') + continue; + + //printf("%s ", entry->d_name); + struct stat s; + char buf[256] = "./tmp/"; + strncpy(buf + strlen(buf), entry->d_name, 200); + + if (stat(buf, &s) == -1) { + perror("stat"); + exit(1); + } + + sz = putToFiles(entry->d_name, s.st_ino, files, sz); + } + + printf("File --- Hard links\n"); + for (int i = 0; i < sz; ++i) { + if (files[i].sz > 1) { + for (int j = 0; j < files[i].sz; ++j) { + printf("%s --- ", files[i].names[j]); + for (int k = 0; k < files[i].sz; ++k) { + printf("%s ", files[i].names[k]); + } + printf("\n"); + } + } + } +} diff --git a/week10/ex4.out b/week10/ex4.out new file mode 100755 index 0000000..ce4b8fc Binary files /dev/null and b/week10/ex4.out differ diff --git a/week10/ex4.sh b/week10/ex4.sh new file mode 100755 index 0000000..5ec3c6e --- /dev/null +++ b/week10/ex4.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rm -rf tmp +mkdir tmp +touch tmp/file1 tmp/file2 +ln tmp/file1 tmp/link1 + +gcc ex4.c -o ex4.out +./ex4.out diff --git a/week10/tmp/file1 b/week10/tmp/file1 new file mode 100644 index 0000000..e69de29 diff --git a/week10/tmp/file2 b/week10/tmp/file2 new file mode 100644 index 0000000..e69de29 diff --git a/week10/tmp/link1 b/week10/tmp/link1 new file mode 100644 index 0000000..e69de29