#include #include #include #include #include #include #define IS(t,c) ((t & S_IFMT) == c) char *name; void istat(char *file) { struct stat s; register int t; void *p; char *str; char c; if (lstat(file, &s)) { fprintf(stderr, "%s ", name); perror(file); return; } t = s.st_dev; /* printf(" Device M/m: %x,%d,%3d\n", t,((t >> 16) & 0x7c) -1, t & 0xffff); */ printf(" Inode: %d\n", s.st_ino); t = s.st_mode; if (IS(t, S_IFBLK) || IS(t, S_IFCHR)) printf("Special M,m: %d,%3d\n", ((s.st_rdev >> 16) & 0x7f) -1, s.st_rdev & 0xffff); printf(" Mode: %04o(%c%c%c%c%c%c%c%c%c%c)\n", t & 0xfff , IS(t, S_IFREG) ? '-' : (IS(t, S_IFDIR) ? 'd' : (IS(t, S_IFLNK) ? 'l' : (IS(t, S_IFCHR) ? 'c' : (IS(t, S_IFBLK) ? 'b' : (IS(t, S_IFIFO) ? 'f' : (IS(t, S_IFSOCK) ? 's' : '-')))))) , (t & S_IRUSR) ? 'r' : '-' , (t & S_IWUSR) ? 'w' : '-' , (t & S_IXUSR) ? ((t & S_ISUID) ? 's' : 'x') : ((t & S_ISUID) ? 'S' : '-') , (t & S_IRGRP) ? 'r' : '-' , (t & S_IWGRP) ? 'w' : '-' , (t & S_IXGRP) ? ((t & S_ISGID) ? 's' : 'x') : (((t & S_ISGID) || (t & S_ENFMT)) ? 'S' : '-') , (t & S_IROTH) ? 'r' : '-' , (t & S_IWOTH) ? 'w' : '-' , (t & S_ISVTX) ? 't' : ((t & S_IXOTH) ? 'x' : '-')); if (IS(t, S_IFLNK)) { char lname[513]; int len; if ((len = readlink(file, lname, 512)) > 0) { lname[len] = '\0'; printf(" Link to: %s\n", lname); } } printf(" Hard Links: %d\n", s.st_nlink); t = s.st_uid; p = (void *) getpwuid(t); if (p) str = ((struct passwd *) p)->pw_name; else str = ""; printf(" Uid: %d/%s", t, str); t = s.st_gid; p = (void *) getgrgid(t); if (p) str = ((struct group *) p)->gr_name; else str = ""; printf(" Gid: %d/%s\n", t, str); t = s.st_size; c = 0; while ((t/1024) > 1) { t /= 1024; ++c; } switch (c) { case 0: c = 'b'; break; case 1: c = 'k'; break; case 2: c = 'm'; break; case 3: c = 'g'; break; default: c = 't'; } printf(" Size: %d(%d%c)\n", s.st_size, t, c); printf("Block count: %d\n", s.st_blocks); printf("Data Blk sz: %d\n", s.st_blksize); printf(" Fs type: %s\n", s.st_fstype); printf("Last Access: %s", ctime(&s.st_atime)); printf("Last Modif.: %s", ctime(&s.st_mtime)); printf("Last Ichang: %s", ctime(&s.st_ctime)); } int main(int argc, char *argv[]) { name = argv[0]; while (*++argv) istat(*argv); exit(0); }