/* mydir.c : msdos - dir-Befehl: */ #include #include #include #include #include int main() { struct stat statbuffer; struct dirent * direntry; /* data structure for dir-entries*/ char * p; char * directory = "."; int inode; unsigned long int size = 0; DIR * dir; /* stream handle for dir */ if (stat(directory, &statbuffer) < 0) { perror("stat error with '.'"); exit(1); } if ( (statbuffer.st_mode & S_IFMT) != S_IFDIR) { perror(". no directory?"); exit(2); } inode = statbuffer.st_ino; printf("Inode of actual directory: %d\n", inode); /* open directory */ dir = opendir(directory); while( (direntry = readdir(dir))!=NULL) { printf("%s\n", direntry->d_name); if (stat(direntry->d_name, &statbuffer) < 0) { perror("stat error occured - "); exit(1); } size += statbuffer.st_size; printf("\tlast access: %s", ctime(&statbuffer.st_atime) ); printf("\tlast modification: %s", ctime(&statbuffer.st_mtime) ); printf("\tlast change: %s", ctime(&statbuffer.st_ctime) ); switch (statbuffer.st_mode & S_IFMT) { case S_IFDIR: p = "directory"; break; case S_IFCHR: p = "char special"; break; case S_IFBLK: p = "block special"; break; case S_IFREG: p = "regular"; break; case S_IFLNK: p = "sym link"; break ; case S_IFSOCK: p = "socket"; break; case S_IFIFO: p = "fifo"; break; default: p = "UNKNOWN"; break; } printf("\ttype: %s\n", p); } printf("Size overall: %ld Bytes\n", size); exit(0); }