]> git.tuebingen.mpg.de Git - adu.git/blobdiff - adu.h
--base-dir must not be a required option.
[adu.git] / adu.h
diff --git a/adu.h b/adu.h
index 1e6519bc91c12fb6a03307042de9c56f97c1c92b..ea660dd7188e35e6f37c6a0ee812e08bf7d46c89 100644 (file)
--- a/adu.h
+++ b/adu.h
@@ -4,7 +4,7 @@
  * 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 <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))
-
 /** debug loglevel, gets really noisy */
 #define DEBUG 1
 /** still noisy, but won't fill your disk */
@@ -94,7 +87,6 @@
 #define EMERG_LOG(...)
 #endif
 /** \endcond */
-__printf_2_3 void __log(int, const char*, ...);
 
 /**
  * Write a log message to a dynamically allocated string.
@@ -107,7 +99,7 @@ __printf_2_3 void __log(int, const char*, ...);
 { \
        int n; \
        size_t size = 100; \
-       p = para_malloc(size); \
+       p = adu_malloc(size); \
        while (1) { \
                va_list ap; \
                /* Try to print in the allocated space. */ \
@@ -122,6 +114,100 @@ __printf_2_3 void __log(int, const char*, ...);
                        size = n + 1; /* precisely what is needed */ \
                else /* glibc 2.0 */ \
                        size *= 2; /* twice the old size */ \
-               p = para_realloc(p, size); \
+               p = adu_realloc(p, size); \
        } \
 }
+
+#define FOR_EACH_USER(ui) for (ui = uid_hash_table; ui && ui < uid_hash_table \
+               + uid_hash_table_size; ui++)
+
+/** 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,
+};
+
+extern uint32_t num_uids;
+extern uint32_t uid_hash_table_size;
+extern struct osl_table *dir_table;
+extern struct user_info *uid_hash_table;
+extern uint64_t num_dirs;
+extern uint64_t num_files;
+extern uint64_t num_bytes;
+extern struct gengetopt_args_info 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(void);
+int search_uid(uint32_t uid, enum search_uid_flags flags,
+               struct user_info **ui_ptr);
+
+/* select.c */
+int com_select(void);
+
+/* create.h */
+int com_create(void);
+
+static inline int ui_used(struct user_info *ui)
+{
+       return ui->flags & UI_FL_SLOT_USED;
+}
+
+static inline int ui_admissible(struct user_info *ui)
+{
+       return ui->flags & UI_FL_ADMISSIBLE;
+}