Introduce --global-summary-format.
[adu.git] / adu.h
diff --git a/adu.h b/adu.h
index 775af7faef3c85bfc3890e87426b044f161a552b..012fddeea9a2bb5d146bd3de787aea3bf47543b6 100644 (file)
--- a/adu.h
+++ b/adu.h
@@ -4,11 +4,11 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file para.h global paraslash definitions */
+/** \file adu.h Global definitions. */
 
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/wait.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h> /* time(), localtime() */
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <ctype.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/un.h> /* needed by create_pf_socket */
+#include <inttypes.h>
 #include <string.h>
 #include <assert.h>
 #include <osl.h>
 #include "gcc-compat.h"
-
-/** compute the minimum of \a a and \a b */
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-/** compute the maximum of \a a and \a b */
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/** compute the absolute value of \a a */
-#define ABS(a) ((a) > 0 ? (a) : -(a))
+#include "select.cmdline.h"
 
 /** debug loglevel, gets really noisy */
 #define DEBUG 1
@@ -94,7 +84,6 @@
 #define EMERG_LOG(...)
 #endif
 /** \endcond */
-__printf_2_3 void __log(int, const char*, ...);
 
 /**
  * Write a log message to a dynamically allocated string.
@@ -125,3 +114,96 @@ __printf_2_3 void __log(int, const char*, ...);
                p = adu_realloc(p, size); \
        } \
 }
+
+/** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
+#define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
+
+/** The columns of the directory table. */
+enum dir_table_columns {
+       /** The name of the directory. */
+       DT_NAME,
+       /** The dir count number. */
+       DT_NUM,
+       /** The number of the parent directory. */
+       DT_PARENT_NUM,
+       /** The number of bytes of all regular files. */
+       DT_BYTES,
+       /** The number of all regular files. */
+       DT_FILES,
+       /** Number of columns in this table. */
+       NUM_DT_COLUMNS
+};
+
+/** The columns of the id table. */
+enum user_table_columns {
+       /** The numer of the directory. */
+       UT_DIR_NUM,
+       /** The number of bytes of all regular files in this dir owned by this id. */
+       UT_BYTES,
+       /** The number of files in this dir owned by this id. */
+       UT_FILES,
+       /** Number of columns in this table. */
+       NUM_UT_COLUMNS
+};
+
+enum uid_info_flags {
+       /** Whether this slot of the hash table is used. */
+       UI_FL_SLOT_USED = 1,
+       /** Whether this uid should be taken into account. */
+       UI_FL_ADMISSIBLE = 2,
+};
+
+struct user_info {
+       uint32_t uid;
+       uint32_t flags;
+       char *pw_name;
+       struct osl_table *table;
+       uint64_t files;
+       uint64_t bytes;
+       uint64_t dirs;
+       struct osl_table_description *desc;
+};
+
+struct uid_range {
+       uint32_t low;
+       uint32_t high;
+};
+
+enum search_uid_flags {
+       OPEN_USER_TABLE = 1,
+       CREATE_USER_TABLE = 2,
+};
+
+#define FOR_EACH_UID_RANGE(ur, urs) for (ur = urs; ur->low <= ur->high; ur++)
+
+extern uint32_t num_uids;
+extern struct osl_table *dir_table;
+extern struct gengetopt_args_info conf;
+extern struct select_args_info select_conf;
+
+/* adu.c */
+__printf_2_3 void __log(int, const char*, ...);
+int open_dir_table(int create);
+void check_signals(void);
+void close_all_tables(void);
+char *get_uid_list_name(void);
+void create_hash_table(unsigned bits);
+int search_uid(uint32_t uid, struct uid_range *urs,
+               enum search_uid_flags flags, struct user_info **ui_ptr);
+int for_each_admissible_user(int (*func)(struct user_info *, void *),
+               void *data);
+void sort_hash_table(int (*comp)(const void *, const void *));
+
+/* select.c */
+struct select_format_info {
+       struct format_info *global_summary_fi;
+       struct format_info *user_summary_fi;
+};
+int parse_select_options(char *string, struct select_cmdline_parser_params *params,
+               struct uid_range **admissible_uids, struct select_format_info *sfi);
+int run_select_query(struct uid_range *admissible_uids, struct select_format_info *sfi);
+int com_select(void);
+
+/* create.h */
+int com_create(void);
+int com_interactive(void);