lab1programy.docx

(575 KB) Pobierz

Laboratorium z systemów operacyjnych

 

Lab 1 Funkcje z systemowe LINUX – podsystem plików

 

 

 


Zadanie B

Program, który wypisze informacje o utworzonym uprzednio pliku ( plik należy utworzyć w bieżącym katalogu programu). Informacje: ilość dowiązań do pliku, czasy ostatniego dostępu i modyfikacji pliku, identyfikatory grupy i użytkownika, rozmiar i atrybuty dostępu. W programie należy stworzyć i usunąć dodatkowe dowiązania do pliku (link, unink) pokazując jednocześnie zmianę odpowiedniego elementu informacyjnego

Zadanie C

Program, który bierze jako parametr (linia komend) nazwę pliku lub katalogu i jeżeli jest to katalog to wypisuje ilość zawartych w nim plików wraz z ich nazwami.

Zadanie D

Program – odpowiednik narzędzia ls (użycie funkcji readdir i stat)

Zadanie E

Program – odpowiednik copy (funkcje read, write, open, close), powinien przyjmować parametry plik źródłowy, plik docelowy, obsługa błędów.

Zadanie F

Program, który z pliku podanego w linii komend utworzy kopię pozbawiona pierwszych n i ostatnich m linii ( funkcje lseek, open, read, write, close)

 

 

 

 

 

 

 

 

 

 

Zadanie B

C:\Users\Fonev\Desktop\zadb.jpg

Zadanie C

#include <stdio.h>

#include <sys/file.h>

#include <dirent.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <sys/fcntl.h>

#include <stdlib.h>

#include <string.h>

main(argc, argv)

int argc;

char *argv[];

{

int result;

DIR *d;

struct dirent *dir;

struct stat statbuf;

mode_t mode;

result = stat(argv[1], &statbuf);

//sprawdzanie czy jest plikiem

if (S_ISREG(statbuf.st_mode)) printf("%s is a file.\n", argv[1]);

//sprawdzanie czy jest katalogiem

if (S_ISDIR(statbuf.st_mode))

{    

printf("%s is directory.\n", argv[1]);

d = opendir(argv[1]);

if (d)

{

while ((dir = readdir(d)) != NULL)

        {

         printf("%s\n", dir -> d_name);

}

closedir(d);

}}

if (stat(argv[1], &statbuf) == -1)

{

perror("stat");

exit(EXIT_FAILURE);

}

return 0;

}

Zadanie D

#include <stdio.h>

  #include <sys/file.h>

  #include <dirent.h>

  #include <sys/stat.h>

  #include <sys/types.h>

  #include <sys/fcntl.h>

  #include <stdlib.h>

  #include <string.h>

  main(argc, argv)

  int argc;

  char *argv[];

{

int result;

  DIR *d;

  struct dirent *dir;

  struct stat statbuf;

result = stat(argv[1], &statbuf);

if (S_ISREG(statbuf.st_mode)) {

printf("%s jest plikiem z prawami\n -", argv[1]);

printf((statbuf.st_mode & S_IRUSR) ? "r" : "-");

printf((statbuf.st_mode & S_IWUSR) ? "w" : "-");

printf((statbuf.st_mode & S_IXUSR) ? "x" : "-");

printf((statbuf.st_mode & S_IRGRP) ? "r" : "-");

printf((statbuf.st_mode & S_IWGRP) ? "w" : "-");

printf((statbuf.st_mode & S_IXGRP) ? "x" : "-");

printf((statbuf.st_mode & S_IROTH) ? "r" : "-");

printf((statbuf.st_mode & S_IWOTH) ? "w" : "-");

printf((statbuf.st_mode & S_IXOTH) ? "x" : "-");

printf("\n");

return 0;

}

if (S_ISDIR(statbuf.st_mode)) {

printf("%s jest katalogiem z prawami\n d", argv[1]);

d = opendir(argv[1]);

while ((dir = readdir(d)) != NULL){

printf((statbuf.st_mode & S_IRUSR) ? "r" : "-");

printf((statbuf.st_mode & S_IRUSR) ? "r" : "-");

printf((statbuf.st_mode & S_IWUSR) ? "w" : "-");

printf((statbuf.st_mode & S_IXUSR) ? "x" : "-");

printf((statbuf.st_mode & S_IRGRP) ? "r" : "-");

printf((statbuf.st_mode & S_IWGRP) ? "w" : "-");

printf((statbuf.st_mode & S_IXGRP) ? "x" : "-");

printf((statbuf.st_mode & S_IROTH) ? "r" : "-");

printf((statbuf.st_mode & S_IWOTH) ? "w" : "-");

printf((statbuf.st_mode & S_IXOTH) ? "x" : "-");

printf("\n");

break;

} }

  closedir(d);

printf("\n");

}

 

 

Zadanie E

#include <stdio.h>

   #include <sys/file.h>

   #include <dirent.h>

   #include <sys/stat.h>

   #include <sys/types.h>

   #include <sys/fcntl.h>

   #include <stdlib.h>

   #include <string.h>

  main(argc, argv)

   int argc;

   char *argv[];

{

int p_zrodlowy, p_docelowy, czyt, pisz;

char buff[512];

p_zrodlowy =  open(...

Zgłoś jeśli naruszono regulamin