Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. static int my_getattr(const char *path, struct stat *stbuf)
  2.  
  3. {
  4.  
  5. int res = 0;
  6.  
  7. int ok=0; //ok permet de controler si @para path fait partie des fichiers du répétoire intéressé ou pas
  8.  
  9. int i=0;
  10.  
  11.  
  12.  
  13. memset(stbuf, 0, sizeof(struct stat));
  14.  
  15.  
  16.  
  17. //Vérifier quel type de fichier qu'on devra retourner: répétoire ou fichier régulier
  18.  
  19. if(strcmp(path, "/") == 0) { // path est un répétoire
  20.  
  21. stbuf->st_mode = S_IFDIR | 0755;
  22.  
  23. stbuf->st_nlink = 2;
  24.  
  25. ok=1;
  26.  
  27. }
  28.  
  29. else{
  30.  
  31. for(i=0;i<MAX_FICHIER;i++){
  32.  
  33. if(strcmp(atoi(path),matrice[i][0]) == 0) { //path est un fichier existe dans le répertoire
  34.  
  35. stbuf->st_mode = S_IFREG | 0444; //0444: O_RDONLY
  36.  
  37. stbuf->st_nlink = 1;
  38.  
  39. if(strcmp(my_path,path) == 0)
  40.  
  41. stbuf->st_size = strlen(path); //taille du fichier est la taille de la chaine "Je connais FUSE\n" si @path est le fichier lire
  42.  
  43. else
  44.  
  45. stbuf->st_size = 0; //sinon la taille du fichier est 0
  46.  
  47. ok=1;
  48.  
  49. break;
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57. if(ok==0) //path n'existe pas dans le répétoire
  58.  
  59. res = -ENOENT;
  60.  
  61. return res;
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement