X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=adu.h;h=5e99709c3679571b70ccaf5db5bc70c62957eb83;hp=b9e6ee9f67812764c8b65b7baf41bc9d31ef5978;hb=7231c544e2ee3f53f5b2c8bc393b7fd1e0b8d0a7;hpb=9e41a10fbee567866d78903b11646d341cfd9882 diff --git a/adu.h b/adu.h index b9e6ee9..5e99709 100644 --- a/adu.h +++ b/adu.h @@ -4,7 +4,7 @@ * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file adu.h Global definitions. */ +/** \file adu.h \brief Global definitions. */ #include #include @@ -21,7 +21,7 @@ #include #include #include "gcc-compat.h" -#include "select.cmdline.h" +#include "portable_io.h" /** debug loglevel, gets really noisy */ #define DEBUG 1 @@ -134,67 +134,6 @@ enum dir_table_columns { 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 -}; - -/** Flags for the user hash table. */ -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, -}; - -/** Information about one admissible user. */ -struct user_info { - /** User ID. */ - uint32_t uid; - /** \sa enum uid_info_flags. */ - uint32_t flags; - /** The user name. */ - char *pw_name; - /** The user table of this user.*/ - struct osl_table *table; - /** Total number of files owned by this user. */ - uint64_t files; - /** Total number of bytes owned by this user. */ - uint64_t bytes; - /** Total number of directories that contain at least one file */ - uint64_t dirs; - /** The description of the user table. */ - struct osl_table_description *desc; -}; - -/** - * Describes one range of admissible user IDs. - * - * adu converts the admissible user ids given at the command line - * into an array of such structs. - */ -struct uid_range { - /** Lowest admissible user ID. */ - uint32_t low; - /** Greatest admissible user ID. */ - 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; /** The adu command line options. */ @@ -208,19 +147,55 @@ extern struct gengetopt_args_info conf; */ extern struct select_args_info select_conf; +/** + * 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; +} + +/** + * 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, 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 *)); - /* create.c */ int com_create(void);