2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file adu.h Global definitions. */
14 #include <time.h> /* time(), localtime() */
23 #include "gcc-compat.h"
24 #include "select.cmdline.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(...)
89 * Write a log message to a dynamically allocated string.
91 * \param fmt Usual format string.
92 * \param p Result pointer.
95 #define VSPRINTF(fmt, p) \
99 p = adu_malloc(size); \
102 /* Try to print in the allocated space. */ \
104 n = vsnprintf(p, size, fmt, ap); \
106 /* If that worked, return the string. */ \
107 if (n > -1 && n < size) \
109 /* Else try again with more space. */ \
110 if (n > -1) /* glibc 2.1 */ \
111 size = n + 1; /* precisely what is needed */ \
112 else /* glibc 2.0 */ \
113 size *= 2; /* twice the old size */ \
114 p = adu_realloc(p, size); \
118 /** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
119 #define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
121 /** The columns of the directory table. */
122 enum dir_table_columns {
123 /** The name of the directory. */
125 /** The dir count number. */
127 /** The number of the parent directory. */
129 /** The number of bytes of all regular files. */
131 /** The number of all regular files. */
133 /** Number of columns in this table. */
137 /** The columns of the id table. */
138 enum user_table_columns {
139 /** The numer of the directory. */
141 /** The number of bytes of all regular files in this dir owned by this id. */
143 /** The number of files in this dir owned by this id. */
145 /** Number of columns in this table. */
149 enum uid_info_flags {
150 /** Whether this slot of the hash table is used. */
152 /** Whether this uid should be taken into account. */
153 UI_FL_ADMISSIBLE = 2,
160 struct osl_table *table;
164 struct osl_table_description *desc;
172 enum search_uid_flags {
174 CREATE_USER_TABLE = 2,
177 #define FOR_EACH_UID_RANGE(ur, urs) for (ur = urs; ur->low <= ur->high; ur++)
179 extern uint32_t num_uids;
180 extern struct osl_table *dir_table;
181 extern struct gengetopt_args_info conf;
182 extern struct select_args_info select_conf;
185 __printf_2_3 void __log(int, const char*, ...);
186 int open_dir_table(int create);
187 void check_signals(void);
188 void close_all_tables(void);
189 char *get_uid_list_name(void);
190 void create_hash_table(unsigned bits);
191 int search_uid(uint32_t uid, struct uid_range *urs,
192 enum search_uid_flags flags, struct user_info **ui_ptr);
193 int for_each_admissible_user(int (*func)(struct user_info *, void *),
195 void sort_hash_table(int (*comp)(const void *, const void *));
198 struct select_format_info {
199 struct format_info *global_list_fi;
200 struct format_info *global_summary_fi;
201 struct format_info *user_summary_fi;
202 struct format_info *user_list_fi;
204 int parse_select_options(char *string, struct select_cmdline_parser_params *params,
205 struct uid_range **admissible_uids, struct select_format_info *sfi);
206 int run_select_query(struct uid_range *admissible_uids, struct select_format_info *sfi);
207 int com_select(void);
210 int com_create(void);
211 int com_interactive(void);