Salut a tous,
je dois ecrire un petit programme qui parcours recursivement un repertoire et ecrit dans un fichier appele data le chemin des fichiers ayant plusieurs lien et dans un autre fichier appele data2 les numeros d'inodes des fichiers rencontres. Si le fichier rencontre est un dossier, alors je retourne la fonction.

Il semblerait que je sois dans l'impossibilite d'ecrire dans mon fichier inodes et je n'arrive pas a comprendre pourquoi....

Quelqu'un aurait il des suggestion svp

Merci d'avance

voici mon code.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
 
#include <stdio.h>
#include <stdlib.h>     
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>                      
#include <dirent.h>
 
int checkAllFilesInDir(char * directory){
 
        DIR * dir;
        struct dirent * file;
 
        if ((dir = opendir(directory))==NULL){
                return EXIT_FAILURE;
        }
 
        while ((file = readdir(dir))!=NULL){
                if (strcmp(file->d_name,".")!=0 && strcmp(file->d_name,"..")!= 0){
                        struct stat file_info;
                        char file_path[0x100];
                        strncpy(file_path, directory, sizeof(file_path));
                        strncat(file_path, "/", sizeof(file_path));
                        strncat(file_path, file->d_name, sizeof(file_path));
 
                        if (lstat(file_path, &file_info)!=-1){
                                if (S_ISDIR(file_info.st_mode)){
                                        closedir(dir);
                                        checkAllFilesInDir(file_path);
                                }
                                if (file_info.st_nlink > 1){
                                        int fh;
                                        if ((fh = open("./data", O_CREAT|O_APPEND|O_RDWR,0777))==-1){
                                                perror("Unable to open data");
                                                return EXIT_FAILURE;
                                        }
                                        if ((fh = write(fh, file_path, strlen(file_path)))==-1){
                                                perror("Unable to write to data");
                                                return EXIT_FAILURE;
                                        }
                                        if (close(fh)==-1){
                                                perror("Close error");
                                                return EXIT_FAILURE;
                                        }
                                }
 
                                int fh2;
                                ino_t inode;
 
                                if ((fh2 = open("data2", O_CREAT|O_APPEND|O_RDWR,0777))==-1){
                                                perror("Unable to open inos");
                                                return EXIT_FAILURE;
                                }
                                inode = file_info.st_ino;
                                if (fh2 = write(fh2, inode, sizeof(ino_t))==-1){
                                        perror("Unable to write to inos");
                                        return EXIT_FAILURE;
                                }
 
                                if (close(fh2)==-1){
                                        perror("Close error");
                                        return EXIT_FAILURE;
                                }
                       }
                }
        }
        closedir(dir);
        return EXIT_SUCCESS;
}
voici le header
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
#define MULTIPLE_LINKED_FILE_CREATOR
#ifndef MULTIPLE_LINKED_FILE_CREATOR
 
int checkAllFilesInDir(char * directory);
 
#endif
voici le main
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
#include "MultipleLinkedFileCreator.h"
 
int main( int argc, char * argv[]){
        char directory[0x100];
        char file_name[0x100];
 
        checkAllFilesInDir("/Users");// un repertoire quelconque
        return 0;
}


Bon ok j'ai plus ou moins reussi a cibler mon probleme
il se situe au niveau de mon ecriture de fichier
il semblerait que le numero de fichier soit incorrect.
je n'y comprends rien