#include "adu.h"
#include <dirent.h> /* readdir() */
+#include <pwd.h>
#include "gcc-compat.h"
#include "cmdline.h"
struct user_info {
uint32_t uid;
uint32_t flags;
+ char *pw_name;
struct osl_table *table;
uint64_t files;
uint64_t bytes;
static int open_user_table(struct user_info *ui, int create)
{
int ret;
+ struct passwd *pw;
ui->desc = adu_malloc(sizeof(*ui->desc));
ui->desc->num_columns = NUM_UT_COLUMNS;
ui->desc->column_descriptions = user_table_cols;
ui->desc->dir = adu_strdup(conf.database_dir_arg);
ui->desc->name = make_message("%u", (unsigned)ui->uid);
+ pw = getpwuid(ui->uid);
+ if (pw && pw->pw_name)
+ ui->pw_name = adu_strdup(pw->pw_name);
+
INFO_LOG(".............................uid #%u: %u\n",
(unsigned)num_uids, (unsigned)ui->uid);
if (create) {
err:
free((char *)ui->desc->name);
free((char *)ui->desc->dir);
+ free(ui->pw_name);
free(ui->desc);
ui->desc->name = NULL;
ui->desc->dir = NULL;
ui->desc->name = NULL;
free((char *)ui->desc->dir);
ui->desc->dir = NULL;
+ free(ui->pw_name);
+ ui->pw_name = NULL;
free(ui->desc);
ui->desc = NULL;
ui->table = NULL;
struct user_info *ui;
printf("User summary "
- "(uid/dirs%s/files%s/size%s):\n",
+ "(pw_name/uid/dirs%s/files%s/size%s):\n",
count_unit_buf, count_unit_buf, size_unit_buf);
FOR_EACH_USER(ui) {
char formated_dir_count[FORMATED_VALUE_SIZE],
format_size_value(conf.size_unit_arg, ui->bytes,
conf.size_unit_arg == size_unit_arg_h,
formated_bytes);
- printf("\t%u\t%s\t%s\t%s\n", (unsigned)ui->uid,
+ printf("\t%s\t%u\t%s\t%s\t%s\n",
+ ui->pw_name? ui->pw_name : "?",
+ (unsigned)ui->uid,
formated_dir_count,
formated_file_count,
formated_bytes
if (!ui_used(ui) || !ui_admissible(ui))
continue;
usi.flags = USF_PRINT_DIRNAME | USF_PRINT_BYTES | USF_COMPUTE_SUMMARY;
- printf("uid %u, by size%s:\n",
- (unsigned) ui->uid, size_unit_buf);
+ printf("%s (uid %u), by size%s:\n",
+ ui->pw_name? ui->pw_name : "?", (unsigned)ui->uid,
+ size_unit_buf);
ret = adu_loop_reverse(ui->table, UT_BYTES, &usi, user_stats_loop_function,
&usi.ret, &usi.osl_errno);
if (ret < 0)
return ret;
- printf("\nuid %u, by file count%s:\n",
- (unsigned) ui->uid, count_unit_buf);
+ printf("\n%s (uid %u), by file count%s:\n",
+ ui->pw_name? ui->pw_name : "?", (unsigned)ui->uid,
+ count_unit_buf);
usi.count = conf.limit_arg,
usi.flags = USF_PRINT_DIRNAME | USF_PRINT_FILES;
ret = adu_loop_reverse(ui->table, UT_FILES, &usi, user_stats_loop_function,