annotate toys/pending/stat.c @ 810:874d2e646f2d

Fix whitespace in submitted stat command.
author Rob Landley <rob@landley.net>
date Tue, 05 Mar 2013 02:48:12 -0600
parents 68d6c1ce7bba
children 7a983e09efad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 *
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/stat.html
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 USE_STAT(NEWTOY(stat, "LZfc", TOYFLAG_BIN))
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
8
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config STAT
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 bool st
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 default n
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 help
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 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
14 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
15 -Z, --context
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 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
17 -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
18 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
19 -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
20 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
21 --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
22 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
23 %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
24 %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
25 %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
26 %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
27 %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
28 %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
29 %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
30 %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
31 %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
32 %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
33 %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
34 %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
35 %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
36 %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
37 %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
38 %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
39 %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
40 %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
41 %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
42 %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
43 %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
44 %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
45 %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
46 %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
47 %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
48 */
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
49
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 #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
51 #include "toys.h"
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
52
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 #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
54 #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
55 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
56 else \
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] = '-'; \
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 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
59 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
60 else \
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 + 1)] = '-'; \
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 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
63 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
64 else \
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 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
66
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 static char * check_type_file(mode_t, size_t);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 static char * get_access_str(unsigned long, mode_t);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 static char * date_stat_format(time_t );
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 static int do_stat(const char *);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 static int do_statfs(const char *);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 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
73
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 GLOBALS(
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 char * access_str;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 char * file_type;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
77 struct passwd * user_name; struct group * group_name; struct tm *time_toy;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 struct stat * toystat;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 struct statfs * toystatfs;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
80 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
81 )
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
82
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
83
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
84 static int do_stat(const char * file_name)
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
85 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
86 TT.toystat = (struct stat*)malloc(sizeof(struct stat));
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
87 if(stat(file_name, TT.toystat) < 0){
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 perror_msg("Error: unable to get information about the file, stat\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
89 toys.exitval = EXIT_FAILURE;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
91 return 0;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
93
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
94 static int do_statfs(const char * file_name)
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
95 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
96 TT.toystatfs = (struct statfs *)malloc(sizeof(struct statfs));
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
97 if (statfs(file_name, TT.toystatfs) < 0) {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 perror_msg("Error: unable to get information about the file, statfs\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
99 toys.exitval = EXIT_FAILURE;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
100 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
101 return 0;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
103
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
104 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
105 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
106 if(S_ISREG(mode)){
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
107 if (size) return "regular file";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
108 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
109 }
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
110 if(S_ISDIR(mode)) return "directory";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
111 if(S_ISCHR(mode)) return "character device";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
112 if(S_ISBLK(mode)) return "block device";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
113 if(S_ISFIFO(mode)) return "FIFO (named pipe)";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
114 if(S_ISLNK(mode)) return "symbolic link";
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
115 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
116 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
117
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
118 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
119 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
120 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
121 int i;
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
122
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
123 if (S_ISDIR(mode)) access_string[0] = 'd';
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
124 else access_string[0] = '-';
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
125 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
126 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
127
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
128 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
129 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
130 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
131
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
132 static char * date_stat_format(time_t time)
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
133 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 static char buf[SIZE_DATE_TIME_STAT];
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 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
136 return buf;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
138
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
139 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
140 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 format++;
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
142 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
143 case 'a':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
144 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 xprintf("%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
146 else
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 xprintf("%04lo\n",TT.toystat->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO));
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 'A':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
150 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
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 'b':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
153 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
154 xprintf("%lu\n", 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
155 else
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
156 xprintf("%llu\n", TT.toystat->st_blocks);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
157 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
158 case 'B':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
159 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
160 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 case 'c':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
162 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
163 xprintf("%lu\n", 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
164 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
165 case 'C':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
166 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
167 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
168 case 'd':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
169 if(flag)
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.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
171 else
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
172 xprintf("%ldd\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
173 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
174 case 'D':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
175 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
176 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
177 case 'f':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
178 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
179 xprintf("%lu\n", 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
180 else
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
181 xprintf("%lx\n", 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
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 'F':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
184 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
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 'g':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
187 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
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 'G':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
190 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
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 'h':
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_nlink);
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 'i':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
196 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
197 xprintf("%d%d\n", TT.toystatfs->f_fsid.__val[0], TT.toystatfs->f_fsid.__val[1]);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
198 else
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
199 xprintf("%llu\n", TT.toystat->st_ino);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
200 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
201 case 'l':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
202 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
203 xprintf("need to implement\n");
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 'n':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
206 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
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 'N':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
209 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
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 'o':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
212 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
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 's':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
215 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
216 xprintf("%d\n", 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
217 else
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_size);
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 'S':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
221 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
222 xprintf("%d\n", TT.toystatfs->f_bsize);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
223 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
224 case 't':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
225 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
226 xprintf("%lx\n", 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
227 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 case 'T':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
229 if(flag)
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
230 xprintf("Needs to be implemented\n");
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
231 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
232 case 'u':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
233 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
234 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
235 case 'U':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
236 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
237 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
238 case 'x':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
239 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
240 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
241 case 'X':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
242 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
243 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
244 case 'y':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
245 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
246 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
247 case 'Y':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
248 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
249 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
250 case 'z':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
251 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
252 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
253 case 'Z':
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
254 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
255 default:
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
256 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
257 break;
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
258 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
259 exit(0);
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
260 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
261
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
262 void stat_main(void)
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
263 {
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
264 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
265
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
266 if (toys.optargs) {
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
267 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
268 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
269 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
270 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
271 }
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
272 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
273 stat_flag_f = 1;
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
274 if (do_statfs(toys.optargs[TT.toy_obj_file_arg]) != 0)
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
275 xprintf("Error STATFS\n");
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
276 } else if (do_stat(toys.optargs[TT.toy_obj_file_arg]) != 0)
747
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
277 xprintf("Error STAT\n");
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
278 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
279 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
280 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
281 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
282 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
283 // function to check the type/mode of file
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
284 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
285 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
286 // 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
287 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
288 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
289 // 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
290 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
291 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
292 }
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
293 if (!(stat_flag_f |stat_flag_Z)) {
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 } 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
302 // implementation of statfs -f, file system
810
874d2e646f2d Fix whitespace in submitted stat command.
Rob Landley <rob@landley.net>
parents: 747
diff changeset
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
313 }
68d6c1ce7bba Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
diff changeset
314