30 #include <sys/types.h> 31 #include "posixstat.h" 64 #define OPT_UID 0x00001 65 #define OPT_GID 0x00002 66 #define OPT_DEV 0x00004 67 #define OPT_INO 0x00008 68 #define OPT_PERM 0x00010 69 #define OPT_LNKNAM 0x00020 70 #define OPT_FID 0x00040 71 #define OPT_NLINK 0x00080 72 #define OPT_RDEV 0x00100 73 #define OPT_SIZE 0x00200 74 #define OPT_ATIME 0x00400 75 #define OPT_MTIME 0x00800 76 #define OPT_CTIME 0x01000 77 #define OPT_BLKSIZE 0x02000 78 #define OPT_BLKS 0x04000 79 #define OPT_FTYPE 0x08000 80 #define OPT_PMASK 0x10000 81 #define OPT_OPERM 0x20000 83 #define OPT_ASCII 0x1000000 85 #define OPTIONS "acdgiflmnopsuACGMP:U" 94 while (*++s >=
'0' && *s <=
'7')
95 r = (r * 8) + (*s -
'0');
105 int mode,
flags, opt;
120 case 'd': flags |=
OPT_DEV;
break;
121 case 'i': flags |=
OPT_INO;
break;
122 case 'f': flags |=
OPT_FID;
break;
123 case 'g': flags |=
OPT_GID;
break;
133 case 'u': flags |=
OPT_UID;
break;
147 for (i = 0; i <
argc; i++)
157 static struct stat st;
161 if (strncmp(f,
"/dev/fd/", 8) == 0) {
162 if ((
legal_number(f + 8, &lfd) == 0) || (
int)lfd != lfd) {
164 return ((
struct stat *)0);
176 return ((
struct stat *)0);
202 char ubits[4], gbits[4], obits[4];
233 ubits[2] = (m &
S_IXUSR) ?
's' :
'S';
235 gbits[2] = (m &
S_IXGRP) ?
's' :
'S';
237 obits[2] = (m &
S_IXOTH) ?
't' :
'T';
239 printf (
"u=%s,g=%s,o=%s", ubits, gbits, obits);
277 ma = major (st->st_rdev);
278 mi = minor (st->st_rdev);
279 #if defined (makedev) 280 d = makedev (ma, mi);
282 d = st->st_rdev & 0xFF;
284 printf(
"Device (major/minor): %d (%d/%d)\n", d, ma, mi);
286 printf(
"Inode: %d\n", (
int) st->st_ino);
287 printf(
"Mode: (%o) ", (
int) st->st_mode);
289 printf(
"Link count: %d\n", (
int) st->st_nlink);
291 owner = pw ? pw->pw_name :
"unknown";
292 printf(
"Uid of owner: %d (%s)\n", (
int) st->st_uid, owner);
294 owner = gr ? gr->gr_name :
"unknown";
295 printf(
"Gid of owner: %d (%s)\n", (
int) st->st_gid, owner);
296 printf(
"Device type: %d\n", (
int) st->st_rdev);
297 printf(
"File size: %ld\n", (
long) st->st_size);
298 printf(
"File last access time: %s", ctime (&st->st_atime));
299 printf(
"File last modify time: %s", ctime (&st->st_mtime));
300 printf(
"File last status change time: %s", ctime (&st->st_ctime));
323 printf(
"%s", ctime(&st->st_atime));
325 printf(
"%ld\n", st->st_atime);
328 printf(
"%s", ctime(&st->st_mtime));
330 printf(
"%ld\n", st->st_mtime);
333 printf(
"%s", ctime(&st->st_ctime));
335 printf(
"%ld\n", st->st_ctime);
337 printf(
"%d\n", st->st_dev);
339 printf(
"%d\n", st->st_ino);
341 printf(
"%d:%ld\n", st->st_dev, st->st_ino);
343 printf(
"%d\n", st->st_nlink);
347 p = readlink(f, b, 4096);
348 if (p >= 0 && p < 4096)
365 printf(
"%o\n",
getperm(st->st_mode));
371 printf(
"%s\n", pw ? pw->pw_name :
"unknown");
373 printf(
"%d\n", st->st_uid);
377 printf(
"%s\n", gr ? gr->gr_name :
"unknown");
379 printf(
"%d\n", st->st_gid);
381 printf(
"%ld\n", (
long) st->st_size);
403 "Display information about file attributes.",
405 "Display information about each FILE. Only single operators should",
406 "be supplied. If no options are supplied, a summary of the info",
407 "available about each FILE is printed. If FILE is of the form",
408 "/dev/fd/XX, file descriptor XX is described. Operators, if supplied,",
409 "have the following meanings:",
411 " -a last file access time",
412 " -A last file access time in ctime format",
413 " -c last file status change time",
414 " -C last file status change time in ctime format",
415 " -m last file modification time",
416 " -M last file modification time in ctime format",
419 " -f composite file identifier (device:inode)",
421 " -G group name of owner",
422 " -l name of file pointed to by symlink",
424 " -o permissions in octal",
425 " -p permissions in ascii",
426 " -P mask permissions ANDed with MASK (like with umask)",
427 " -s file size in bytes",
429 " -U user name of owner",
438 "finfo [-acdgiflmnopsuACGMPU] file [file...]",
444 #if defined (PREFER_STDARG) 447 # if defined (PREFER_VARARGS) 448 # include <varargs.h> 465 fprintf(stderr,
"%s: usage: %s [-%s] [file ...]\n",
prog,
prog,
OPTIONS);
468 #ifndef HAVE_STRERROR 473 static char ebuf[40];
475 extern char *sys_errlist[];
477 if (e < 0 || e > sys_nerr) {
478 sprintf(ebuf,
"Unknown error code %d", e);
481 return (sys_errlist[e]);
495 fprintf(stderr,
"%s: cannot malloc %d bytes\n",
prog, s);
532 if (*
string ==
'-' || *
string ==
'+')
534 if (!digit (
string[1]))
543 while (digit (*
string))
546 value = (value * 10) + digit_value (*
string);
559 *result = value * sign;
584 #if defined (USE_VARARGS) 586 #if defined (PREFER_STDARG) 599 #if defined (PREFER_STDARG) 600 va_start (args, format);
605 vfprintf (stderr, format, args);
607 fprintf (stderr,
"\n");
612 char *format, *arg1, *arg2, *arg3, *arg4, *arg5;
617 fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
618 fprintf (stderr,
"\n");
struct passwd * getpwuid()
struct group * getgrgid()
int finfo_builtin(WORD_LIST *list)
static struct stat * getstat(char *f)
static nls_uint32 nls_uint32 i
void builtin_error(char *format, va_alist) const
int sh_getopt(int argc, char *const *argv, const char *optstring)
static int getperm(int m)
char ** make_builtin_argv()
struct builtin finfo_struct
static char * finfo_doc[]
int main(int argc, char **argv)
static int octal(char *s)
char * base_pathname(char *string)
int legal_number(char *string, intmax_t *result) const