+int osl_errno;
+
+/** Command line and config file options. */
+static struct gengetopt_args_info conf;
+
+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;
+ struct osl_table *table;
+ uint64_t files;
+ uint64_t bytes;
+ uint64_t dirs;
+ struct osl_table_description *desc;
+};
+
+/** The decimal representation of an uint64_t never exceeds that size. */
+#define FORMATED_VALUE_SIZE 25
+
+
+/**
+ * Contains info for each user that owns at least one regular file.
+ *
+ * Even users that are not taken into account because of the --uid
+ * option occupy a slot in this hash table. This allows to find out
+ * quicky whether a uid is admissible. And yes, this has to be fast.
+ */
+static struct user_info *uid_hash_table;
+
+/* these get filled in by the select command. */
+static char count_unit_buf[4] = "( )", size_unit_buf[4] = "( )";
+
+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;
+}
+
+struct uid_range {
+ uint32_t low;
+ uint32_t high;
+};
+
+static struct uid_range *admissible_uids;
+
+static inline int check_uid_arg(const char *arg, uint32_t *uid)
+{
+ const uint32_t max = ~0U;
+ /*
+ * we need an 64-bit int for string -> uid conversion because strtoll()
+ * returns a signed value.
+ */
+ int64_t val;
+ int ret = para_atoi64(arg, &val);
+
+ if (ret < 0)
+ return ret;
+ if (val < 0 || val > max)
+ return -ERRNO_TO_ERROR(EINVAL);
+ *uid = val;
+ return 1;
+}
+
+static int parse_uid_range(const char *orig_arg, struct uid_range *ur)
+{
+ int ret;
+ char *arg = para_strdup(orig_arg), *p = strchr(arg, '-');
+
+ if (!p || p == arg) { /* -42 or 42 */
+ ret = check_uid_arg(p? p + 1 : arg, &ur->high);
+ if (ret < 0)
+ goto out;
+ ur->low = p? 0 : ur->high;
+ ret = 1;
+ goto out;
+ }
+ /* 42- or 42-4711 */
+ *p = '\0';
+ p++;
+ ret = check_uid_arg(arg, &ur->low);
+ if (ret < 0)
+ goto out;
+ ur->high = ~0U;
+ if (*p) { /* 42-4711 */
+ ret = check_uid_arg(p, &ur->high);
+ if (ret < 0)
+ goto out;
+ }
+ if (ur->low > ur->high)
+ ret = -ERRNO_TO_ERROR(EINVAL);
+out:
+ if (ret < 0)
+ ERROR_LOG("bad uid option: %s\n", orig_arg);
+ else
+ INFO_LOG("admissible uid range: %u - %u\n", ur->low,
+ ur->high);
+ free(arg);
+ return ret;
+}
+