3 // authors, in order of contribution:
4 // jonas.sundstrom@kirilla.com
6 // axeld@pinc-software.de
9 #include <TypeConstants.h>
22 "Usage: lsindex [--help | -v | --verbose | --mkindex | -l | --long] [volume path]\n"
23 " -l --long\t outputs long listing\n"
24 " -v --verbose\t gives index type, dates and owner\n"
25 " --mkindex\t outputs mkindex commands to recreate all the indices\n"
26 " --help\t prints out this text\n\n"
27 " If no volume is specified, the volume of the current directory is assumed.\n");
32 print_index_type(const index_info
&info
, bool mkindexOutput
)
34 static char buffer
[30];
38 return mkindexOutput
? "int" : "Int-32";
40 return mkindexOutput
? "llong" : "Int-64";
42 return mkindexOutput
? "string" : "Text";
44 return mkindexOutput
? "float" : "Float";
46 return mkindexOutput
? "double" : "Double";
49 sprintf(buffer
, mkindexOutput
? "0x%08lx" : "Unknown type (0x%lx)", info
.type
);
56 type_string(type_code type
)
58 // all types from <TypeConstants.h> listed for completeness,
59 // even though they don't all apply to attribute indices
61 #define RETURN_TYPE(x) case x: return #x
64 RETURN_TYPE(B_ANY_TYPE
);
65 RETURN_TYPE(B_BOOL_TYPE
);
66 RETURN_TYPE(B_CHAR_TYPE
);
67 RETURN_TYPE(B_COLOR_8_BIT_TYPE
);
68 RETURN_TYPE(B_DOUBLE_TYPE
);
69 RETURN_TYPE(B_FLOAT_TYPE
);
70 RETURN_TYPE(B_GRAYSCALE_8_BIT_TYPE
);
71 RETURN_TYPE(B_INT64_TYPE
);
72 RETURN_TYPE(B_INT32_TYPE
);
73 RETURN_TYPE(B_INT16_TYPE
);
74 RETURN_TYPE(B_INT8_TYPE
);
75 RETURN_TYPE(B_MESSAGE_TYPE
);
76 RETURN_TYPE(B_MESSENGER_TYPE
);
77 RETURN_TYPE(B_MIME_TYPE
);
78 RETURN_TYPE(B_MONOCHROME_1_BIT_TYPE
);
79 RETURN_TYPE(B_OBJECT_TYPE
);
80 RETURN_TYPE(B_OFF_T_TYPE
);
81 RETURN_TYPE(B_PATTERN_TYPE
);
82 RETURN_TYPE(B_POINTER_TYPE
);
83 RETURN_TYPE(B_POINT_TYPE
);
84 RETURN_TYPE(B_RAW_TYPE
);
85 RETURN_TYPE(B_RECT_TYPE
);
86 RETURN_TYPE(B_REF_TYPE
);
87 RETURN_TYPE(B_RGB_32_BIT_TYPE
);
88 RETURN_TYPE(B_RGB_COLOR_TYPE
);
89 RETURN_TYPE(B_SIZE_T_TYPE
);
90 RETURN_TYPE(B_SSIZE_T_TYPE
);
91 RETURN_TYPE(B_STRING_TYPE
);
92 RETURN_TYPE(B_TIME_TYPE
);
93 RETURN_TYPE(B_UINT64_TYPE
);
94 RETURN_TYPE(B_UINT32_TYPE
);
95 RETURN_TYPE(B_UINT16_TYPE
);
96 RETURN_TYPE(B_UINT8_TYPE
);
97 RETURN_TYPE(B_MEDIA_PARAMETER_TYPE
);
98 RETURN_TYPE(B_MEDIA_PARAMETER_WEB_TYPE
);
99 RETURN_TYPE(B_MEDIA_PARAMETER_GROUP_TYPE
);
100 RETURN_TYPE(B_ASCII_TYPE
);
110 print_index_long_stat(const index_info
&info
, char *name
)
113 strftime(modified
, 30, "%m/%d/%Y %I:%M %p", localtime(&info
.modification_time
));
114 printf("%16s %s %8Ld %s\n", print_index_type(info
, false), modified
, info
.size
, name
);
119 print_index_verbose_stat(const index_info
&info
, char *name
)
121 printf("%-18s\t", name
);
124 const char *typeString
= type_string(info
.type
);
125 if (typeString
!= NULL
)
126 printf("%-10s\t", typeString
);
128 printf("%ld\t", info
.type
);
131 printf("%10Ld ", info
.size
);
135 strftime(string
, sizeof(string
), "%Y-%m-%d %H:%M", localtime(&info
.creation_time
));
136 printf("%s ", string
);
139 strftime(string
, sizeof(string
), "%Y-%m-%d %H:%M", localtime(&info
.modification_time
));
140 printf("%s", string
);
143 printf("%5d", info
.uid
);
146 printf("%5d\n", info
.gid
);
151 main(int argc
, char **argv
)
153 dev_t device
= dev_for_path(".");
155 bool verbose
= false;
156 bool longListing
= false;
157 bool mkindexOutput
= false; /* mkindex-ready output */
159 for (int i
= 1; i
< argc
; i
++) {
160 if (argv
[i
][0] == '-') {
161 if (!strcmp(argv
[i
], "--help")) {
164 } else if (!strcmp(argv
[i
], "--verbose") || !strcmp(argv
[i
], "-v"))
166 else if (!strcmp(argv
[i
], "--long") || !strcmp(argv
[i
], "-l"))
168 else if (!strcmp(argv
[i
], "--mkindex"))
169 mkindexOutput
= true;
171 fprintf(stderr
, "%s: option %s is not understood (use --help for help)\n", argv
[0], argv
[i
]);
175 device
= dev_for_path(argv
[i
]);
177 fprintf(stderr
, "%s: can't get information about volume: %s\n", argv
[0], argv
[i
]);
183 indices
= fs_open_index_dir(device
);
184 if (indices
== NULL
) {
185 fprintf(stderr
, "%s: can't open index dir of device %ld\n", argv
[0], device
);
190 printf(" Name Type Size Created Modified User Group\n");
191 printf("********************************************************\n");
195 dirent
*index
= fs_read_index_dir(indices
);
197 if (errno
!= B_ENTRY_NOT_FOUND
&& errno
!= B_OK
) {
198 printf("%s: fs_read_index_dir: (%d) %s\n", argv
[0], errno
, strerror(errno
));
204 if (verbose
|| longListing
|| mkindexOutput
) {
207 if (fs_stat_index(device
, index
->d_name
, &info
) != B_OK
) {
208 printf("%s: fs_stat_index(): (%d) %s\n", argv
[0], errno
, strerror(errno
));
213 print_index_verbose_stat(info
, index
->d_name
);
214 else if (longListing
)
215 print_index_long_stat(info
, index
->d_name
);
216 else /* mkindexOutput */
217 printf("mkindex -t %s '%s'\n", print_index_type(info
, true), index
->d_name
);
219 printf("%s\n", index
->d_name
);
222 fs_close_index_dir(indices
);