2 * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file adu.h \brief Global definitions. */
14 #include <time.h> /* time(), localtime() */
23 #include "gcc-compat.h"
24 #include "portable_io.h"
26 /** debug loglevel, gets really noisy */
28 /** still noisy, but won't fill your disk */
30 /** normal, but significant event */
32 /** unexpected event that can be handled */
34 /** unhandled error condition */
36 /** system might be unreliable */
38 /** last message before exit */
41 /** Log messages with lower priority than that will not be compiled in. */
42 #define COMPILE_TIME_LOGLEVEL 0
45 #if DEBUG > COMPILE_TIME_LOGLEVEL
46 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
48 #define DEBUG_LOG(...) do {;} while (0)
51 #if INFO > COMPILE_TIME_LOGLEVEL
52 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
54 #define INFO_LOG(...) do {;} while (0)
57 #if NOTICE > COMPILE_TIME_LOGLEVEL
58 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
60 #define NOTICE_LOG(...) do {;} while (0)
63 #if WARNING > COMPILE_TIME_LOGLEVEL
64 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
66 #define WARNING_LOG(...) do {;} while (0)
69 #if ERROR > COMPILE_TIME_LOGLEVEL
70 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
72 #define ERROR_LOG(...) do {;} while (0)
75 #if CRIT > COMPILE_TIME_LOGLEVEL
76 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
78 #define CRIT_LOG(...) do {;} while (0)
81 #if EMERG > COMPILE_TIME_LOGLEVEL
82 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
84 #define EMERG_LOG(...)
88 /** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
89 #define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
91 /** The columns of the directory table. */
92 enum dir_table_columns {
93 /** The name of the directory. */
95 /** The dir count number. */
97 /** The number of the parent directory. */
99 /** The number of bytes of all regular files. */
101 /** The number of all regular files. */
103 /** Number of columns in this table. */
107 extern struct osl_table *dir_table;
109 /** The adu command line options. */
110 extern struct gengetopt_args_info conf;
112 /** Computed database dir. */
113 extern char *database_dir;
116 * The select command line options.
118 * Either given at the command line, or via the \a set command
119 * in interactive mode.
121 extern struct select_args_info select_conf;
124 * Compare two osl objects pointing to unsigned integers of 64 bit size.
126 * \param obj1 Pointer to the first integer.
127 * \param obj2 Pointer to the second integer.
129 * \return The values required for an osl compare function.
131 * \sa osl_compare_func, osl_hash_compare().
133 _static_inline_ int uint64_compare(const struct osl_object *obj1,
134 const struct osl_object *obj2)
136 uint64_t d1 = read_u64((const char *)obj1->data);
137 uint64_t d2 = read_u64((const char *)obj2->data);
147 * Compare the size of two directories
149 * \param obj1 Pointer to the first object.
150 * \param obj2 Pointer to the second object.
152 * This function first compares the size values as usual integers. If they compare as
153 * equal, the address of \a obj1 and \a obj2 are compared. So this compare function
154 * returns zero if and only if \a obj1 and \a obj2 point to the same memory area.
156 _static_inline_ int size_compare(const struct osl_object *obj1, const struct osl_object *obj2)
158 uint64_t d1 = *(uint64_t *)obj1->data;
159 uint64_t d2 = *(uint64_t *)obj2->data;
160 int ret = NUM_COMPARE(d2, d1);
164 //INFO_LOG("addresses: %p, %p\n", obj1->data, obj2->data);
165 return NUM_COMPARE(obj2->data, obj1->data);
169 __printf_2_3 void __log(int, const char*, ...);
170 int open_dir_table(int create);
171 void check_signals(void);
173 int com_create(void);
176 void print_interactive_help(void);
177 int com_interactive(void);