#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"
+#include "portable_io.h"
/** debug loglevel, gets really noisy */
#define DEBUG 1
} \
}
+/** 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. */
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,
-};
+extern struct osl_table *dir_table;
-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;
-};
+/** The adu command line options. */
+extern struct gengetopt_args_info conf;
-struct uid_range {
- uint32_t low;
- uint32_t high;
-};
+/**
+ * The select command line options.
+ *
+ * Either given at the command line, or via the \a set command
+ * in interactive mode.
+ */
+extern struct select_args_info select_conf;
-enum search_uid_flags {
- OPEN_USER_TABLE = 1,
- CREATE_USER_TABLE = 2,
-};
+/**
+ * Compare two osl objects pointing to unsigned integers of 64 bit size.
+ *
+ * \param obj1 Pointer to the first integer.
+ * \param obj2 Pointer to the second integer.
+ *
+ * \return The values required for an osl compare function.
+ *
+ * \sa osl_compare_func, osl_hash_compare().
+ */
+static inline int uint64_compare(const struct osl_object *obj1,
+ const struct osl_object *obj2)
+{
+ uint64_t d1 = read_u64((const char *)obj1->data);
+ uint64_t d2 = read_u64((const char *)obj2->data);
+
+ if (d1 < d2)
+ return 1;
+ if (d1 > d2)
+ return -1;
+ return 0;
+}
-extern uint32_t num_uids;
-extern struct osl_table *dir_table;
-extern uint64_t num_dirs;
-extern uint64_t num_files;
-extern uint64_t num_bytes;
-extern struct gengetopt_args_info conf;
+/**
+ * Compare the size of two directories
+ *
+ * \param obj1 Pointer to the first object.
+ * \param obj2 Pointer to the second object.
+ *
+ * This function first compares the size values as usual integers. If they compare as
+ * equal, the address of \a obj1 and \a obj2 are compared. So this compare function
+ * returns zero if and only if \a obj1 and \a obj2 point to the same memory area.
+ */
+static inline int size_compare(const struct osl_object *obj1, const struct osl_object *obj2)
+{
+ uint64_t d1 = *(uint64_t *)obj1->data;
+ uint64_t d2 = *(uint64_t *)obj2->data;
+ int ret = NUM_COMPARE(d2, d1);
+
+ if (ret)
+ return ret;
+ //INFO_LOG("addresses: %p, %p\n", obj1->data, obj2->data);
+ return NUM_COMPARE(obj2->data, obj1->data);
+}
/* 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, enum search_uid_flags flags,
- struct user_info **ui_ptr);
-int for_each_admissible_user(int (*func)(struct user_info *, void *),
- void *data);
-
-/* select.c */
-int com_select(void);
-
-/* create.h */
+/* create.c */
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;
-}
+/* interactive.c */
+void print_interactive_help(void);
+int com_interactive(void);