GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_dir_cache.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2022 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
18#ifndef GP_DIR_CACHE_H
19#define GP_DIR_CACHE_H
20
21#include <utils/gp_poll.h>
22#include <time.h>
23
25typedef struct gp_dir_entry {
27 size_t size;
29 time_t mtime;
31 unsigned int name_len;
33 int is_dir:1;
35 int filtered:1;
37 char name[];
39
53
69
82gp_dir_cache *gp_dir_cache_new(const char *path);
83
92
107 const char *name, mode_t mode, time_t mtime);
108
119int gp_dir_cache_rem_entry_by_name(gp_dir_cache *self, const char *name);
120
130
139int gp_dir_cache_entry_name_contains(gp_dir_cache *self, const char *needle);
140
149
157
167 unsigned int pos)
168{
169 if (self->used <= pos)
170 return NULL;
171
172 return self->entries[pos];
173}
174
185static inline void gp_dir_cache_set_filter(gp_dir_cache *self, unsigned int pos,
186 int filter)
187{
188 if (self->entries[pos]->filtered == !!filter)
189 return;
190
191 self->entries[pos]->filtered = !!filter;
192 self->filtered += filter ? 1 : -1;
193}
194
202static inline size_t gp_dir_cache_entries(gp_dir_cache *self)
203{
204 return self->used;
205}
206
214static inline size_t gp_dir_cache_entries_filter(gp_dir_cache *self)
215{
216 return self->used - self->filtered;
217}
218
228
240
249
258int gp_dir_cache_mkdir(gp_dir_cache *self, const char *dirname);
259
272unsigned int gp_dir_cache_pos_by_name_filtered(gp_dir_cache *self, const char *name);
273
283
294
295#endif /* GP_DIR_CACHE_H */
int gp_dir_cache_entry_name_contains(gp_dir_cache *self, const char *needle)
Returns true if there is at least one entry with needle in the name.
gp_dir_cache_type
A cache entry lookup type.
@ GP_DIR_CACHE_DIR
A directory type element found.
@ GP_DIR_CACHE_NONE
No element found.
@ GP_DIR_CACHE_FILE
File type element found.
static size_t gp_dir_cache_entries(gp_dir_cache *self)
Returns number of entries.
static void gp_dir_cache_set_filter(gp_dir_cache *self, unsigned int pos, int filter)
Sets dir cache entry filter flag.
int gp_dir_cache_notify(gp_dir_cache *self)
A change notify handler.
gp_dir_entry * gp_dir_cache_entry_lookup(gp_dir_cache *self, const char *name)
Looks up an entry based on a file name.
void gp_dir_cache_sort(gp_dir_cache *self, gp_dir_cache_sort_type sort_type)
Sorts the directory cache entries.
gp_dir_entry * gp_dir_cache_add_entry(gp_dir_cache *self, size_t size, const char *name, mode_t mode, time_t mtime)
Adds an entry to the directory cache.
gp_dir_cache * gp_dir_cache_new(const char *path)
Creates and populates a new directory cache.
int gp_dir_cache_rem_entry_by_name(gp_dir_cache *self, const char *name)
Removes an entry from directory cache.
int gp_dir_cache_mkdir(gp_dir_cache *self, const char *dirname)
Creates a directory and updates the cache.
void gp_dir_cache_destroy(gp_dir_cache *self)
Destroys a directory cache.
static size_t gp_dir_cache_entries_filter(gp_dir_cache *self)
Returns number of not-filtered entries.
gp_fd * gp_dir_cache_notify_fd(gp_dir_cache *self)
Returns inotify fd if available.
void gp_dir_cache_free_entries(gp_dir_cache *self)
Frees all entries from directory cache.
gp_dir_entry * gp_dir_cache_get_filtered(gp_dir_cache *self, unsigned int pos)
Returns entry on position pos ignoring filtered out elements.
enum gp_dir_cache_type gp_dir_cache_lookup(gp_dir_cache *self, const char *name)
Looks for a file in the directory the cache operates in.
unsigned int gp_dir_cache_pos_by_name_filtered(gp_dir_cache *self, const char *name)
Looks up a entry position by name.
static gp_dir_entry * gp_dir_cache_get(gp_dir_cache *self, unsigned int pos)
Returns an entry given a position.
gp_dir_cache_sort_type
How should be the listing sorted.
@ GP_DIR_SORT_BY_MTIME
Sort by modification time.
@ GP_DIR_SORT_BY_SIZE
Sort by size.
@ GP_DIR_SORT_DESC
Sort in a descending order.
@ GP_DIR_SORT_BY_NAME
Sort by name.
@ GP_DIR_SORT_ASC
Sort in an ascending order.
A simple epoll wrapper.
A block allocator block header.
A directory cache.
size_t used
Number of used entries.
gp_dir_entry ** entries
An array of dir cache entres sorted accordingly to sort_type.
enum gp_dir_cache_sort_type sort_type
An order the listing is sorted in.
struct gp_balloc_pool * allocator
A block allocator for the cache entries.
size_t size
The size of the cache.
size_t filtered
Number of filtered items.
A dir cache entry, represents a file or a directory.
int filtered
If set the entry is hidden from listing.
size_t size
Entry size in bytes.
char name[]
Entry name.
unsigned int name_len
Length of the entry name.
time_t mtime
Entry modification time.
int is_dir
Set if entry is a directory.
An epoll file descriptor.
Definition gp_poll.h:70