Parcourir la source

week10

master
RinRi il y a 1 an
Parent
révision
a48d5eede3
16 fichiers modifiés avec 125 ajouts et 0 suppressions
  1. +1
    -0
      week10/_ex1.txt
  2. +1
    -0
      week10/_ex1_1.txt
  3. +1
    -0
      week10/_ex1_2.txt
  4. +1
    -0
      week10/_ex3.txt
  5. +9
    -0
      week10/ex1.sh
  6. +3
    -0
      week10/ex1.txt
  7. +8
    -0
      week10/ex2.sh
  8. +2
    -0
      week10/ex2.txt
  9. +13
    -0
      week10/ex3.sh
  10. +6
    -0
      week10/ex3.txt
  11. +71
    -0
      week10/ex4.c
  12. BIN
      week10/ex4.out
  13. +9
    -0
      week10/ex4.sh
  14. +0
    -0
      week10/tmp/file1
  15. +0
    -0
      week10/tmp/file2
  16. +0
    -0
      week10/tmp/link1

+ 1
- 0
week10/_ex1.txt Voir le fichier

@@ -0,0 +1 @@
RinRi

+ 1
- 0
week10/_ex1_1.txt Voir le fichier

@@ -0,0 +1 @@
RinRi

+ 1
- 0
week10/_ex1_2.txt Voir le fichier

@@ -0,0 +1 @@
RinRi

+ 1
- 0
week10/_ex3.txt Voir le fichier

@@ -0,0 +1 @@
lol

+ 9
- 0
week10/ex1.sh Voir le fichier

@@ -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

+ 3
- 0
week10/ex1.txt Voir le fichier

@@ -0,0 +1,3 @@
6817598 _ex1.txt
6817598 _ex1_1.txt
6817598 _ex1_2.txt

+ 8
- 0
week10/ex2.sh Voir le fichier

@@ -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

+ 2
- 0
week10/ex2.txt Voir le fichier

@@ -0,0 +1,2 @@
../week10/_ex2.txt
../week01/file.txt

+ 13
- 0
week10/ex3.sh Voir le fichier

@@ -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

+ 6
- 0
week10/ex3.txt Voir le fichier

@@ -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

+ 71
- 0
week10/ex4.c Voir le fichier

@@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>

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");
}
}
}
}

BIN
week10/ex4.out Voir le fichier


+ 9
- 0
week10/ex4.sh Voir le fichier

@@ -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

+ 0
- 0
week10/tmp/file1 Voir le fichier


+ 0
- 0
week10/tmp/file2 Voir le fichier


+ 0
- 0
week10/tmp/link1 Voir le fichier


Chargement…
Annuler
Enregistrer