- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
#include "uni.h"
#include "xreadlink.h"
int process(char *dir);
char *cd;
char *scd;
struct stat st1;
ino_t cino;
dev_t cdev;
int main(){
cd = (char *)malloc(160+1);
if(cd==NULL){
perror("Not enough memory");
return -1;
}
scd = (char *)malloc(1600+1);
if(scd==NULL){
perror("Not enough memory");
return -1;
}
memset(cd,'\0',1601);
memset(scd,'\0',1601);
strcat(scd,".");
if(lstat(scd,&st1)==-1){
perror("stat");
exit(EXIT_FAILURE);
};
cino = st1.st_ino;
cdev = st1.st_rdev;
//printf("inode %lu cdev %llu\n",cino,cdev);
process(scd);
return 0;
};
int process(char *dir){
DIR *dp;
struct dirent *ent;
ino_t lino;
dev_t ldev;
ino_t lino2;
dev_t ldev2;
int cnt=0;
char *mydir=(char*)malloc(1600);
char *mydir2=(char*)malloc(1600);
char **fpwd=(char**)malloc(160);
for(int i=0;i<=160;i++){
*(fpwd+i)=(char*)malloc(1600);
if(*(fpwd+i)==NULL){perror("Not sufficient memory");
return -1;
}
}
if(mydir==NULL)return -1;
if(*fpwd==NULL)return -1;
strcpy(mydir,dir);
strcpy(mydir2,dir);
struct stat lstt;
struct stat lstt2;
struct stat stt;
while(lino!=lino2 || ldev!=ldev2){
if(lstat(mydir,&lstt)==-1){
perror("not sufficient memory");
return -1;
}
strcat(mydir2,"/..");
if(lstat(mydir2,&lstt2)==-1){
perror("not sufficient memory");
return -1;
}
//printf("yes\n");
lino=lstt.st_ino;
ldev=lstt.st_rdev;
lino2=lstt2.st_ino;
ldev2=lstt2.st_rdev;
if ((dp = opendir(mydir2)) == NULL) {
fprintf(stderr, "%s: cannot open for reading: %s\n", dir, strerror(errno));
return 1;
}
if(lstat(mydir2,&stt)==-1){
perror("not sufficient memory");
return -1;
}
//if(chdir("/")<0){perror("chdir");return -1;};
while ((ent = readdir(dp)) != NULL){
if(ent->d_ino==lino && strcmp(ent->d_name,".")!=0 && strcmp(ent->d_name,"..")!=0 && stt.st_rdev==ldev){
//printf("%8ld %s\n", ent->d_ino, ent->d_name);
strcat(fpwd[cnt++],ent->d_name);
}
}
if (closedir(dp) != 0) {
fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
return 1;
}
//printf("mydir %s inode %lu cdev %llu inode %lu cdev %llu\n",mydir,lino,ldev,lino2,ldev2);
strcat(mydir,"/..");
strcpy(mydir2,mydir);
}
Комментарии (0) RSS
Добавить комментарий