Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!udel!mmdf From: XBR2D78V%DDATHD21.BITNET@cunyvm.cuny.edu (MATHIAS GAERTNER) Newsgroups: comp.os.minix Subject: help wanted Message-ID: <17736@louie.udel.EDU> Date: 15 Jun 89 16:42:30 GMT Sender: mmdf@udel.EDU Lines: 113 Hi folks, I have a problem with MINIX-ST, recently with the file-system (as i guess). In an old UNIX-book I found a little program to list the directory-structure of an UNIX-system. Well, typing in was easy and compiling too but... It brings out the wanted but with many errors inbetween. And my guess, besides logical errors in the program, is that the fs is not properly implemented to UNIX-style. The program: It gets a filename and checks this file with stat(). If it is a directory it will list it, otherwises it just prints the filename. So should it be. In real it prints the directory (as wanted) and then an amount of '/'es, than the error 'Directory not to open' and than all the files in it. So anything with the S_IFDIR-mode went wrong... I have no idea, what it could be, so if someone can help me? PS.: There may be better ways to get the file-structure of UNIX but I want this. The source-code: ------------------------------cut here----------------------------------- #include #include #include #include #define P_GR 128 /* just a buffer-size */ extern char *strcpy(); void traverse(); void report(fileordir) char * fileordir; { struct stat stbuf; if (stat(fileordir,&stbuf) != 0) { printf("Directory defekt\n"); exit(); } if ((stbuf.st_mode & S_IFMT) != S_IFDIR) { printf("%s;\n",fileordir); return; } else { printf("%s;<<<=== DIRECTORY\n",fileordir); traverse(fileordir,report); } } void traverse(name, func) char *name; int (*func)(); { struct direct dirbuf; char *nbp; char *nep; int i,fd; nbp=name + strlen(name); *nbp++ = '/'; *nbp++ = '\0'; if ((fd=open(name,0)) ==-1) { fprintf(stdout,"FEHLER/traverse(), Dir nicht lesbar%s\n",name); return; } while (read(fd,(char *)&dirbuf,sizeof(dirbuf))>0) { if (dirbuf.d_ino == 0) continue; if (strcmp(dirbuf.d_name,".") == 0 || strcmp(dirbuf.d_name,"..") == 0) continue; if (nbp + strlen(dirbuf.d_name) +2 >= name + P_GR) { printf("Puffer-ueberlauf\n"); exit(); } for (i=0,nep=nbp;i