Mercurial > hg > toybox
annotate toys/pending/stat.c @ 811:7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
perror_msg() sets return code already. Truncate long english messages that
don't get translated. Don't return int from a function hardwired to always
return 0. Don't test for that hardwired return value to change and print an
error message that can never happen and would be a duplicate anyway.
More whitespace cleanup. C does not require typecasting void *.
Remove 404 URL to stat.html that isn't in posix.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 05 Mar 2013 03:06:42 -0600 |
parents | 874d2e646f2d |
children | 8aa07b575cd6 |
rev | line source |
---|---|
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
1 /* stat.c : display file or file system status |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
2 * anand.sinha85@gmail.com |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
3 * Copyright 2012 <warior.linux@gmail.com> |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
4 |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 USE_STAT(NEWTOY(stat, "LZfc", TOYFLAG_BIN)) |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
6 |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 config STAT |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
8 bool stat |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 default n |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 help |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 Usage: stat [OPTION] FILE... |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 display file or file system status |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 -Z, --context |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 print the security context information if available |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 -f, --file-system |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 display file system status instead of file status |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 -c --format=FORMAT |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 use the specified FORMAT instead of the default; output a newline after each use of FORMAT |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 --help display this help and exit |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 The valid format sequences for files (without --file-system): |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 %a Access rights in octal |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 %A Access rights in human readable form |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 %b Number of blocks allocated (see |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 %B The size in bytes of each block reported by |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 %d Device number in decimal |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 %D Device number in hex |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 %f Raw mode in hex |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 %F File type |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 %G Group name of owner |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 %h Number of hard links |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 %i Inode number |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 %n File name |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 %N Quoted file name with dereference if symbolic link |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 %o I/O block size |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 %s Total size, in bytes |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 %t Major device type in hex |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 %T Minor device type in hex |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 %u User ID of owner |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 %U User name of owner |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 %x Time of last access |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 %X Time of last access as seconds since Epoch |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 %y Time of last modification |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 %Y Time of last modification as seconds since Epoch |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 %z Time of last change |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 %Z Time of last change as seconds since Epoch |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 */ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 #define FOR_stat |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 #include "toys.h" |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
50 |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 #define SIZE_DATE_TIME_STAT 36 |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 #define access_string(x, s, i) if((x&7) & 1) \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 s[9 - i * 3] = 'x'; \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 else \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 s[9 - i * 3] = '-'; \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 if(((x&7) >> 1) & 1) \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 s[9 - (i * 3 + 1)] = 'w'; \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 else \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 s[9 - (i * 3 + 1)] = '-'; \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 if(((x&7) >> 2) & 1) \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 s[9 - (i * 3 + 2)] = 'r'; \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 else \ |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 s[9 - (i * 3 + 2)] = '-'; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
65 static char *check_type_file(mode_t, size_t); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
66 static char *get_access_str(unsigned long, mode_t); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
67 static char *date_stat_format(time_t ); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 inline void print_stat_format(char *, int); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 GLOBALS( |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
71 char *access_str; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
72 char *file_type; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
73 struct passwd *user_name; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
74 struct group *group_name; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
75 struct tm *time_toy; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
76 struct stat *toystat; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
77 struct statfs *toystatfs; |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 int toy_obj_file_arg; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 ) |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
82 static void do_stat(const char * file_name) |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
83 { |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
84 TT.toystat = xmalloc(sizeof(struct stat)); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
85 if (stat(file_name, TT.toystat) < 0) perror_msg("stat: '%s'", file_name); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
88 static void do_statfs(const char * file_name) |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
89 { |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
90 TT.toystatfs = xmalloc(sizeof(struct statfs)); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
91 if (statfs(file_name, TT.toystatfs) < 0) |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
92 perror_msg("statfs: '%s'", file_name); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
95 static char * check_type_file(mode_t mode, size_t size) |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
96 { |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
97 if (S_ISREG(mode)) { |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
98 if (size) return "regular file"; |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
99 return "regular empty file"; |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 } |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
101 if (S_ISDIR(mode)) return "directory"; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
102 if (S_ISCHR(mode)) return "character device"; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
103 if (S_ISBLK(mode)) return "block device"; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
104 if (S_ISFIFO(mode)) return "FIFO (named pipe)"; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
105 if (S_ISLNK(mode)) return "symbolic link"; |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
106 if (S_ISSOCK(mode)) return "socket"; |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
109 static char * get_access_str(unsigned long pernission, mode_t mode) |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
110 { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 static char access_string[10]; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 int i; |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
113 |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
114 if (S_ISDIR(mode)) access_string[0] = 'd'; |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
115 else access_string[0] = '-'; |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
116 for (i = 0; i < 3; i++) |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 access_string(pernission >> (i * 3) & 7, access_string, i); |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
118 |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 access_string[10] = '\0'; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 return access_string; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
123 static char * date_stat_format(time_t time) |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
124 { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 static char buf[SIZE_DATE_TIME_STAT]; |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
126 |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&time)); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 return buf; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
131 inline void print_stat_format(char *format, int flag) |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
132 { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 format++; |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
134 switch (*format) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 case 'a': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
136 if (flag) xprintf("%lu\n", TT.toystatfs->f_bavail); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
137 else xprintf("%04lo\n",TT.toystat->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 case 'A': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 xprintf("%s\n",TT.access_str); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 case 'b': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
143 if (flag) xprintf("%lu\n", TT.toystatfs->f_blocks); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
144 else xprintf("%llu\n", TT.toystat->st_blocks); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 case 'B': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 xprintf("%lu\n", TT.toystat->st_blksize); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 case 'c': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
150 if (flag) xprintf("%lu\n", TT.toystatfs->f_files); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 case 'C': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 xprintf("Currently feature is not supported\n"); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 case 'd': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
156 if (flag) xprintf("%lu\n", TT.toystatfs->f_ffree); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
157 else xprintf("%ldd\n", TT.toystat->st_dev); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 case 'D': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 xprintf("%llxh\n", TT.toystat->st_dev); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 case 'f': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
163 if (flag) xprintf("%lu\n", TT.toystatfs->f_bfree); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
164 else xprintf("%lx\n", TT.toystat->st_mode); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 case 'F': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 xprintf("%s\n", TT.file_type); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 case 'g': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 xprintf("%lu\n", TT.toystat->st_uid); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 case 'G': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 xprintf("%8s\n", TT.user_name->pw_name); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 case 'h': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 xprintf("%lu\n", TT.toystat->st_nlink); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 case 'i': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
179 if (flag) |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 xprintf("%d%d\n", TT.toystatfs->f_fsid.__val[0], TT.toystatfs->f_fsid.__val[1]); |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
181 else xprintf("%llu\n", TT.toystat->st_ino); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 case 'l': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
184 if (flag) xprintf("need to implement\n"); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 case 'n': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 xprintf("%s\n", toys.optargs[TT.toy_obj_file_arg]); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 case 'N': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 xprintf("`%s\n'", toys.optargs[TT.toy_obj_file_arg]); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
191 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 case 'o': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 xprintf("%lu\n", TT.toystat->st_blksize); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 case 's': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
196 if (flag) xprintf("%d\n", TT.toystatfs->f_frsize); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
197 else xprintf("%llu\n", TT.toystat->st_size); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 case 'S': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
200 if (flag) xprintf("%d\n", TT.toystatfs->f_bsize); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 case 't': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
203 if (flag) xprintf("%lx\n", TT.toystatfs->f_type); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 case 'T': |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
206 if (flag) xprintf("Needs to be implemented\n"); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
207 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
208 case 'u': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 xprintf("%lu\n", TT.toystat->st_uid); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
210 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 case 'U': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 xprintf("%8s\n", TT.user_name->pw_name); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 case 'x': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 xprintf("%s\n", date_stat_format(TT.toystat->st_atime)); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 case 'X': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 xprintf("%llu\n", TT.toystat->st_atime); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
220 case 'y': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 xprintf("%s\n", date_stat_format(TT.toystat->st_mtime)); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 case 'Y': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
224 xprintf("%llu\n", TT.toystat->st_mtime); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 case 'z': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 xprintf("%s\n", date_stat_format(TT.toystat->st_ctime)); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
228 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
229 case 'Z': |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
230 xprintf("%llu\n", TT.toystat->st_ctime); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
231 default: |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
232 xprintf("%c\n", *format); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 break; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 exit(0); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
238 void stat_main(void) |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
239 { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
240 int stat_flag_Z = 0, stat_flag_f = 0, stat_flag_c = 0, stat_format = 0; |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
241 |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
242 if (toys.optargs) { |
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
243 if (toys.optflags & 1) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
244 stat_flag_c = 1; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
245 TT.toy_obj_file_arg = 1; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
246 stat_format = 1; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
247 } |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
248 if (toys.optflags & (1 << 1)) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
249 stat_flag_f = 1; |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
250 do_statfs(toys.optargs[TT.toy_obj_file_arg]); |
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
251 } else do_stat(toys.optargs[TT.toy_obj_file_arg]); |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
252 if (toys.optflags & (1 << 2)) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
253 stat_flag_Z = 1; |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
254 xprintf("SELinux feature has not been implemented so far..\n"); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
255 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
256 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
257 // function to check the type/mode of file |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
258 if (!stat_flag_f) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
259 TT.file_type = check_type_file(TT.toystat->st_mode, TT.toystat->st_size); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
260 // check user and group name |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
261 TT.user_name = getpwuid(TT.toystat->st_uid); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
262 TT.group_name = getgrgid(TT.toystat->st_gid); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
263 // function to get access in human readable format |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
264 TT.access_str = get_access_str((TT.toystat->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)), TT.toystat->st_mode); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
265 TT.time_toy = gmtime(&(TT.toystat->st_atime)); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
266 } |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
267 if (!(stat_flag_f |stat_flag_Z)) { |
811
7a983e09efad
Call stat "stat" instead of "st" in menuconfig. Use xmalloc() instead of malloc.
Rob Landley <rob@landley.net>
parents:
810
diff
changeset
|
268 if (stat_format) print_stat_format(toys.optargs[0], stat_flag_f); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
269 xprintf(" File: `%s'\n", toys.optargs[TT.toy_obj_file_arg]); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
270 xprintf(" Size: %llu\t Blocks: %llu\t IO Blocks: %lu\t", TT.toystat->st_size, TT.toystat->st_blocks, TT.toystat->st_blksize); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
271 xprintf("%s\n", TT.file_type); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
272 xprintf("Device: %llxh\t Inode: %llu\t Links: %lu\n", TT.toystat->st_dev, TT.toystat->st_ino, TT.toystat->st_nlink); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
273 xprintf("Access: (%04lo/%s)\tUid: (%lu/%8s)\tGid: (%lu/%8s)\n", (TT.toystat->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)), TT.access_str, TT.toystat->st_uid, TT.user_name->pw_name, TT.toystat->st_gid, TT.group_name->gr_name); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
274 xprintf("Access: %s\nModify: %s\nChange: %s\n", date_stat_format(TT.toystat->st_atime), date_stat_format(TT.toystat->st_mtime), date_stat_format(TT.toystat->st_ctime)); |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
275 } else if (stat_flag_f) { |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
276 // implementation of statfs -f, file system |
810
874d2e646f2d
Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents:
747
diff
changeset
|
277 if (stat_format) print_stat_format(toys.optargs[0], stat_flag_f); |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
278 xprintf(" File: \"%s\"\n", toys.optargs[TT.toy_obj_file_arg]); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
279 xprintf(" ID: %d%d Namelen: %ld Type: %lx\n", TT.toystatfs->f_fsid.__val[0], TT.toystatfs->f_fsid.__val[1], TT.toystatfs->f_namelen, TT.toystatfs->f_type); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
280 xprintf("Block Size: %d Fundamental block size: %d\n", TT.toystatfs->f_bsize, TT.toystatfs->f_frsize); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
281 xprintf("Blocks: Total: %lu\t", TT.toystatfs->f_blocks); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
282 xprintf("Free: %lu\t", TT.toystatfs->f_bfree); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
283 xprintf("Available: %lu\n", TT.toystatfs->f_bavail); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
284 xprintf("Inodes: Total: %lu\t", TT.toystatfs->f_files); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
285 xprintf("\tFree: %d\n", TT.toystatfs->f_ffree); |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
286 } |
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
287 } |