libisofs  1.5.4
About: libisofs is a library to create an ISO 9660 filesystem, supports extensions like RockRidge or Joliet, makes bootable ISO 9660, and records file attributes which are of interest for data backups.
  Fossies Dox: libisofs-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

find.c File Reference
#include "libisofs.h"
#include "node.h"
#include <fnmatch.h>
#include <string.h>
Include dependency graph for find.c:

Go to the source code of this file.

Data Structures

struct  iso_find_condition
 
struct  find_iter_data
 
struct  cond_times
 
struct  logical_binary_conditions
 

Functions

static int get_next (struct find_iter_data *iter, IsoNode **n)
 
static void update_next (IsoDirIter *iter)
 
static int find_iter_next (IsoDirIter *iter, IsoNode **node)
 
static int find_iter_has_next (IsoDirIter *iter)
 
static void find_iter_free (IsoDirIter *iter)
 
static int find_iter_take (IsoDirIter *iter)
 
static int find_iter_remove (IsoDirIter *iter)
 
void find_notify_child_taken (IsoDirIter *iter, IsoNode *node)
 
int iso_dir_find_children (IsoDir *dir, IsoFindCondition *cond, IsoDirIter **iter)
 Find all directory children that match the given condition. More...
 
static int cond_name_matches (IsoFindCondition *cond, IsoNode *node)
 
static void cond_name_free (IsoFindCondition *cond)
 
IsoFindConditioniso_new_find_conditions_name (const char *wildcard)
 Create a new condition that checks if the node name matches the given wildcard. More...
 
static int cond_mode_matches (IsoFindCondition *cond, IsoNode *node)
 
static void cond_mode_free (IsoFindCondition *cond)
 
IsoFindConditioniso_new_find_conditions_mode (mode_t mask)
 Create a new condition that checks the node mode against a mode mask. More...
 
static int cond_gid_matches (IsoFindCondition *cond, IsoNode *node)
 
static void cond_gid_free (IsoFindCondition *cond)
 
IsoFindConditioniso_new_find_conditions_gid (gid_t gid)
 Create a new condition that checks the node gid. More...
 
static int cond_uid_matches (IsoFindCondition *cond, IsoNode *node)
 
static void cond_uid_free (IsoFindCondition *cond)
 
IsoFindConditioniso_new_find_conditions_uid (uid_t uid)
 Create a new condition that checks the node uid. More...
 
static int cond_time_matches (IsoFindCondition *cond, IsoNode *node)
 
static void cond_time_free (IsoFindCondition *cond)
 
IsoFindConditioniso_new_find_conditions_atime (time_t time, enum iso_find_comparisons comparison)
 Create a new condition that checks the time of last access. More...
 
IsoFindConditioniso_new_find_conditions_mtime (time_t time, enum iso_find_comparisons comparison)
 Create a new condition that checks the time of last modification. More...
 
IsoFindConditioniso_new_find_conditions_ctime (time_t time, enum iso_find_comparisons comparison)
 Create a new condition that checks the time of last status change. More...
 
static void cond_logical_binary_free (IsoFindCondition *cond)
 
static int cond_logical_and_matches (IsoFindCondition *cond, IsoNode *node)
 
IsoFindConditioniso_new_find_conditions_and (IsoFindCondition *a, IsoFindCondition *b)
 Create a new condition that check if the two given conditions are valid. More...
 
static int cond_logical_or_matches (IsoFindCondition *cond, IsoNode *node)
 
IsoFindConditioniso_new_find_conditions_or (IsoFindCondition *a, IsoFindCondition *b)
 Create a new condition that check if at least one the two given conditions is valid. More...
 
static void cond_not_free (IsoFindCondition *cond)
 
static int cond_not_matches (IsoFindCondition *cond, IsoNode *node)
 
IsoFindConditioniso_new_find_conditions_not (IsoFindCondition *negate)
 Create a new condition that check if the given conditions is false. More...
 

Variables

static struct iso_dir_iter_iface find_iter_class
 

Function Documentation

◆ cond_gid_free()

static void cond_gid_free ( IsoFindCondition cond)
static

Definition at line 396 of file find.c.

397 {
398  free(cond->data);
399 }
void * data
condition specific data
Definition: find.c:40

References find_iter_data::cond, and iso_find_condition::data.

Referenced by iso_new_find_conditions_gid().

◆ cond_gid_matches()

static int cond_gid_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 389 of file find.c.

390 {
391  gid_t *gid = (gid_t*) cond->data;
392  return node->gid == *gid ? 1 : 0;
393 }
gid_t gid
group ID of owner
Definition: node.h:117

References find_iter_data::cond, iso_find_condition::data, and Iso_Node::gid.

Referenced by iso_new_find_conditions_gid().

◆ cond_logical_and_matches()

static int cond_logical_and_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 650 of file find.c.

651 {
652  struct logical_binary_conditions *data = cond->data;
653  return data->a->matches(data->a, node) && data->b->matches(data->b, node);
654 }
int(* matches)(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:32
IsoFindCondition * a
Definition: find.c:633
IsoFindCondition * b
Definition: find.c:634

References logical_binary_conditions::a, logical_binary_conditions::b, iso_find_condition::data, and iso_find_condition::matches.

Referenced by iso_new_find_conditions_and().

◆ cond_logical_binary_free()

static void cond_logical_binary_free ( IsoFindCondition cond)
static

Definition at line 638 of file find.c.

639 {
640  struct logical_binary_conditions *data;
641  data = cond->data;
642  data->a->free(data->a);
643  free(data->a);
644  data->b->free(data->b);
645  free(data->b);
646  free(cond->data);
647 }
void(* free)(IsoFindCondition *)
Free condition specific data.
Definition: find.c:37

References logical_binary_conditions::a, logical_binary_conditions::b, iso_find_condition::data, and iso_find_condition::free.

Referenced by iso_new_find_conditions_and(), and iso_new_find_conditions_or().

◆ cond_logical_or_matches()

static int cond_logical_or_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 691 of file find.c.

692 {
693  struct logical_binary_conditions *data = cond->data;
694  return data->a->matches(data->a, node) || data->b->matches(data->b, node);
695 }

References logical_binary_conditions::a, logical_binary_conditions::b, iso_find_condition::data, and iso_find_condition::matches.

Referenced by iso_new_find_conditions_or().

◆ cond_mode_free()

static void cond_mode_free ( IsoFindCondition cond)
static

Definition at line 344 of file find.c.

345 {
346  free(cond->data);
347 }

References find_iter_data::cond, and iso_find_condition::data.

Referenced by iso_new_find_conditions_mode().

◆ cond_mode_matches()

static int cond_mode_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 337 of file find.c.

338 {
339  mode_t *mask = (mode_t*) cond->data;
340  return node->mode & *mask ? 1 : 0;
341 }
mode_t mode
protection
Definition: node.h:115

References find_iter_data::cond, iso_find_condition::data, and Iso_Node::mode.

Referenced by iso_new_find_conditions_mode().

◆ cond_name_free()

static void cond_name_free ( IsoFindCondition cond)
static

Definition at line 303 of file find.c.

304 {
305  free(cond->data);
306 }

References find_iter_data::cond, and iso_find_condition::data.

Referenced by iso_new_find_conditions_name().

◆ cond_name_matches()

static int cond_name_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 295 of file find.c.

296 {
297  char *pattern = (char*) cond->data;
298  int ret = fnmatch(pattern, node->name, 0);
299  return ret == 0 ? 1 : 0;
300 }
char * name
Real name, in default charset.
Definition: node.h:113

References find_iter_data::cond, iso_find_condition::data, and Iso_Node::name.

Referenced by iso_new_find_conditions_name().

◆ cond_not_free()

static void cond_not_free ( IsoFindCondition cond)
static

Definition at line 732 of file find.c.

733 {
734  IsoFindCondition *negate = cond->data;
735  negate->free(negate);
736  free(negate);
737 }

References iso_find_condition::data, and iso_find_condition::free.

Referenced by iso_new_find_conditions_not().

◆ cond_not_matches()

static int cond_not_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 740 of file find.c.

741 {
742  IsoFindCondition *negate = cond->data;
743  return !(negate->matches(negate, node));
744 }

References iso_find_condition::data, and iso_find_condition::matches.

Referenced by iso_new_find_conditions_not().

◆ cond_time_free()

static void cond_time_free ( IsoFindCondition cond)
static

Definition at line 514 of file find.c.

515 {
516  free(cond->data);
517 }

References iso_find_condition::data.

Referenced by iso_new_find_conditions_atime(), iso_new_find_conditions_ctime(), and iso_new_find_conditions_mtime().

◆ cond_time_matches()

static int cond_time_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 486 of file find.c.

487 {
488  time_t node_time;
489  struct cond_times *data = cond->data;
490 
491  switch (data->what_time) {
492  case 0: node_time = node->atime; break;
493  case 1: node_time = node->mtime; break;
494  default: node_time = node->ctime; break;
495  }
496 
497  switch (data->comparison) {
499  return node_time > data->time ? 1 : 0;
501  return node_time >= data->time ? 1 : 0;
502  case ISO_FIND_COND_EQUAL:
503  return node_time == data->time ? 1 : 0;
504  case ISO_FIND_COND_LESS:
505  return node_time < data->time ? 1 : 0;
507  return node_time <= data->time ? 1 : 0;
508  }
509  /* should never happen */
510  return 0;
511 }
@ ISO_FIND_COND_LESS
Definition: libisofs.h:5557
@ ISO_FIND_COND_EQUAL
Definition: libisofs.h:5556
@ ISO_FIND_COND_LESS_OR_EQUAL
Definition: libisofs.h:5558
@ ISO_FIND_COND_GREATER_OR_EQUAL
Definition: libisofs.h:5555
@ ISO_FIND_COND_GREATER
Definition: libisofs.h:5554
time_t ctime
time of last status change
Definition: node.h:122
time_t atime
time of last access
Definition: node.h:120
time_t mtime
time of last modification
Definition: node.h:121
int what_time
Definition: find.c:481
enum iso_find_comparisons comparison
Definition: find.c:482
time_t time
Definition: find.c:480

References Iso_Node::atime, cond_times::comparison, Iso_Node::ctime, iso_find_condition::data, ISO_FIND_COND_EQUAL, ISO_FIND_COND_GREATER, ISO_FIND_COND_GREATER_OR_EQUAL, ISO_FIND_COND_LESS, ISO_FIND_COND_LESS_OR_EQUAL, Iso_Node::mtime, cond_times::time, and cond_times::what_time.

Referenced by iso_new_find_conditions_atime(), iso_new_find_conditions_ctime(), and iso_new_find_conditions_mtime().

◆ cond_uid_free()

static void cond_uid_free ( IsoFindCondition cond)
static

Definition at line 441 of file find.c.

442 {
443  free(cond->data);
444 }

References find_iter_data::cond, and iso_find_condition::data.

Referenced by iso_new_find_conditions_uid().

◆ cond_uid_matches()

static int cond_uid_matches ( IsoFindCondition cond,
IsoNode node 
)
static

Definition at line 434 of file find.c.

435 {
436  uid_t *uid = (uid_t*) cond->data;
437  return node->uid == *uid ? 1 : 0;
438 }
uid_t uid
user ID of owner
Definition: node.h:116

References find_iter_data::cond, iso_find_condition::data, and Iso_Node::uid.

Referenced by iso_new_find_conditions_uid().

◆ find_iter_free()

static void find_iter_free ( IsoDirIter iter)
static

Definition at line 168 of file find.c.

169 {
170  struct find_iter_data *data = iter->data;
171  if (data->free_cond) {
172  data->cond->free(data->cond);
173  free(data->cond);
174  }
175 
176  iso_node_unref((IsoNode*)data->dir);
177 
178  /* free refs to nodes */
179  if (data->prev) {
180  iso_node_unref(data->prev);
181  }
182  if (data->current) {
183  iso_node_unref(data->current);
184  }
185 
186  /* free underlying iter */
187  iso_dir_iter_free(data->iter);
188  free(iter->data);
189 }
void iso_node_unref(IsoNode *node)
Decrements the reference counting of the given node.
Definition: node.c:56
void iso_dir_iter_free(IsoDirIter *iter)
Free a dir iterator.
Definition: node.c:1051
void * data
Definition: node.h:228
Definition: node.h:100
IsoDirIter * iter
Definition: find.c:46
IsoNode * prev
last returned node, needed for removal
Definition: find.c:51
IsoFindCondition * cond
Definition: find.c:48
IsoNode * current
node to be returned next
Definition: find.c:50
int free_cond
whether to free cond on iter_free
Definition: find.c:52
IsoDir * dir
original dir of the iterator
Definition: find.c:45

References find_iter_data::cond, find_iter_data::current, Iso_Dir_Iter::data, find_iter_data::dir, iso_find_condition::free, find_iter_data::free_cond, iso_dir_iter_free(), iso_node_unref(), find_iter_data::iter, and find_iter_data::prev.

◆ find_iter_has_next()

static int find_iter_has_next ( IsoDirIter iter)
static

Definition at line 160 of file find.c.

161 {
162  struct find_iter_data *data = iter->data;
163 
164  return (data->current != NULL);
165 }

References find_iter_data::current, Iso_Dir_Iter::data, and find_iter_data::iter.

◆ find_iter_next()

static int find_iter_next ( IsoDirIter iter,
IsoNode **  node 
)
static

Definition at line 142 of file find.c.

143 {
144  struct find_iter_data *data;
145 
146  if (iter == NULL || node == NULL) {
147  return ISO_NULL_POINTER;
148  }
149  data = iter->data;
150 
151  if (data->err < 0) {
152  return data->err;
153  }
154  *node = data->current;
155  update_next(iter);
156  return (*node == NULL) ? 0 : ISO_SUCCESS;
157 }
static void update_next(IsoDirIter *iter)
Definition: find.c:99
#define ISO_SUCCESS
successfully execution
Definition: libisofs.h:8719
#define ISO_NULL_POINTER
NULL pointer as value for an arg.
Definition: libisofs.h:8742
int err
error?
Definition: find.c:49

References find_iter_data::current, Iso_Dir_Iter::data, find_iter_data::err, ISO_NULL_POINTER, ISO_SUCCESS, find_iter_data::iter, and update_next().

◆ find_iter_remove()

static int find_iter_remove ( IsoDirIter iter)
static

Definition at line 203 of file find.c.

204 {
205  struct find_iter_data *data = iter->data;
206 
207  if (data->prev == NULL) {
208  return ISO_ERROR; /* next not called or end of dir */
209  }
210  return iso_node_remove(data->prev);
211 }
#define ISO_ERROR
Unknown or unexpected error (FAILURE,HIGH, -3)
Definition: libisofs.h:8734
int iso_node_remove(IsoNode *node)
Removes a child from a directory and free (unref) it.
Definition: node.c:850

References Iso_Dir_Iter::data, ISO_ERROR, iso_node_remove(), find_iter_data::iter, and find_iter_data::prev.

◆ find_iter_take()

static int find_iter_take ( IsoDirIter iter)
static

Definition at line 192 of file find.c.

193 {
194  struct find_iter_data *data = iter->data;
195 
196  if (data->prev == NULL) {
197  return ISO_ERROR; /* next not called or end of dir */
198  }
199  return iso_node_take(data->prev);
200 }
int iso_node_take(IsoNode *node)
Removes a child from a directory.
Definition: node.c:810

References Iso_Dir_Iter::data, ISO_ERROR, iso_node_take(), find_iter_data::iter, and find_iter_data::prev.

◆ find_notify_child_taken()

void find_notify_child_taken ( IsoDirIter iter,
IsoNode node 
)

Definition at line 213 of file find.c.

214 {
215  struct find_iter_data *data = iter->data;
216 
217  if (data->prev == node) {
218  /* free our ref */
219  iso_node_unref(node);
220  data->prev = NULL;
221  } else if (data->current == node) {
222  iso_node_unref(node);
223  data->current = NULL;
224  update_next(iter);
225  }
226 }

◆ get_next()

static int get_next ( struct find_iter_data iter,
IsoNode **  n 
)
static

Definition at line 56 of file find.c.

57 {
58  int ret;
59 
60  if (iter->itersec != NULL) {
61  ret = iso_dir_iter_next(iter->itersec, n);
62  if (ret <= 0) {
63  /* secondary item no more needed */
65  iter->itersec = NULL;
66  }
67  if (ret != 0) {
68  /* success or error */
69  return ret;
70  }
71  }
72 
73  /*
74  * we reach here if:
75  * - no secondary item is present
76  * - secondary item has no more items
77  */
78 
79  while ((ret = iso_dir_iter_next(iter->iter, n)) == 1) {
80  if (iter->cond->matches(iter->cond, *n)) {
81  return ISO_SUCCESS;
82  } else if (ISO_NODE_IS_DIR(*n)) {
83  /* recurse on child dir */
84  struct find_iter_data *data;
85  ret = iso_dir_find_children((IsoDir*)*n, iter->cond,
86  &iter->itersec);
87  if (ret < 0) {
88  return ret;
89  }
90  data = iter->itersec->data;
91  data->free_cond = 0; /* we don't need sec iter to free cond */
92  return get_next(iter, n);
93  }
94  }
95  return ret;
96 }
int iso_dir_find_children(IsoDir *dir, IsoFindCondition *cond, IsoDirIter **iter)
Find all directory children that match the given condition.
Definition: find.c:238
static int get_next(struct find_iter_data *iter, IsoNode **n)
Definition: find.c:56
#define ISO_NODE_IS_DIR(n)
Definition: libisofs.h:237
int iso_dir_iter_next(IsoDirIter *iter, IsoNode **node)
Get the next child.
Definition: node.c:1035
Definition: node.h:140
IsoDirIter * itersec
iterator to deal with child dirs
Definition: find.c:47

References find_iter_data::cond, Iso_Dir_Iter::data, find_iter_data::free_cond, iso_dir_find_children(), iso_dir_iter_free(), iso_dir_iter_next(), ISO_NODE_IS_DIR, ISO_SUCCESS, find_iter_data::iter, find_iter_data::itersec, and iso_find_condition::matches.

Referenced by update_next().

◆ iso_dir_find_children()

int iso_dir_find_children ( IsoDir dir,
IsoFindCondition cond,
IsoDirIter **  iter 
)

Find all directory children that match the given condition.

Parameters
dirDirectory where we will search children.
condCondition that the children must match in order to be returned. It will be free together with the iterator. Remember to delete it if this function return error.
iterIterator that returns only the children that match condition.
Returns
1 on success, < 0 on error
Since
0.6.4

Definition at line 238 of file find.c.

240 {
241  int ret;
242  IsoDirIter *children;
243  IsoDirIter *it;
244  struct find_iter_data *data;
245 
246  if (dir == NULL || cond == NULL || iter == NULL) {
247  return ISO_NULL_POINTER;
248  }
249  it = malloc(sizeof(IsoDirIter));
250  if (it == NULL) {
251  return ISO_OUT_OF_MEM;
252  }
253  data = malloc(sizeof(struct find_iter_data));
254  if (data == NULL) {
255  free(it);
256  return ISO_OUT_OF_MEM;
257  }
258  ret = iso_dir_get_children(dir, &children);
259  if (ret < 0) {
260  free(it);
261  free(data);
262  return ret;
263  }
264 
265  it->class = &find_iter_class;
266  it->dir = (IsoDir*)dir;
267  data->iter = children;
268  data->itersec = NULL;
269  data->cond = cond;
270  data->free_cond = 1;
271  data->err = 0;
272  data->prev = data->current = NULL;
273  it->data = data;
274 
275  if (iso_dir_iter_register(it) < 0) {
276  free(it);
277  return ISO_OUT_OF_MEM;
278  }
279 
281 
282  /* take another ref to the original dir */
283  data->dir = (IsoDir*)dir;
285 
286  update_next(it);
287 
288  *iter = it;
289  return ISO_SUCCESS;
290 }
static struct iso_dir_iter_iface find_iter_class
Definition: find.c:229
int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter)
Get an iterator for the children of the given dir.
Definition: node.c:1001
#define ISO_OUT_OF_MEM
Memory allocation error (FATAL,HIGH, -6)
Definition: libisofs.h:8745
void iso_node_ref(IsoNode *node)
Increments the reference counting of the given node.
Definition: node.c:46
int iso_dir_iter_register(IsoDirIter *iter)
Add a new iterator to the registry.
Definition: node.c:1418
An iterator for directory children.
Definition: node.h:222
struct iso_dir_iter_iface * class
Definition: node.h:223
IsoDir * dir
Definition: node.h:226

References Iso_Dir_Iter::class, find_iter_data::cond, find_iter_data::current, Iso_Dir_Iter::data, find_iter_data::dir, Iso_Dir_Iter::dir, find_iter_data::err, find_iter_class, find_iter_data::free_cond, iso_dir_get_children(), iso_dir_iter_register(), iso_node_ref(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, find_iter_data::iter, find_iter_data::itersec, find_iter_data::prev, and update_next().

Referenced by get_next(), and update_next().

◆ iso_new_find_conditions_and()

IsoFindCondition* iso_new_find_conditions_and ( IsoFindCondition a,
IsoFindCondition b 
)

Create a new condition that check if the two given conditions are valid.

Parameters
a
bIsoFindCondition to compare
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 668 of file find.c.

670 {
671  IsoFindCondition *cond;
672  struct logical_binary_conditions *data;
673  cond = malloc(sizeof(IsoFindCondition));
674  if (cond == NULL) {
675  return NULL;
676  }
677  data = malloc(sizeof(struct logical_binary_conditions));
678  if (data == NULL) {
679  free(cond);
680  return NULL;
681  }
682  data->a = a;
683  data->b = b;
684  cond->data = data;
687  return cond;
688 }
static void cond_logical_binary_free(IsoFindCondition *cond)
Definition: find.c:638
static int cond_logical_and_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:650

References logical_binary_conditions::a, logical_binary_conditions::b, cond_logical_and_matches(), cond_logical_binary_free(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_atime()

IsoFindCondition* iso_new_find_conditions_atime ( time_t  time,
enum iso_find_comparisons  comparison 
)

Create a new condition that checks the time of last access.

Parameters
timeTime to compare against IsoNode atime.
comparisonComparison to be done between IsoNode atime and submitted time. Note that ISO_FIND_COND_GREATER, for example, is true if the node time is greater than the submitted time.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 533 of file find.c.

535 {
536  IsoFindCondition *cond;
537  struct cond_times *data;
538  cond = malloc(sizeof(IsoFindCondition));
539  if (cond == NULL) {
540  return NULL;
541  }
542  data = malloc(sizeof(struct cond_times));
543  if (data == NULL) {
544  free(cond);
545  return NULL;
546  }
547  data->time = time;
548  data->comparison = comparison;
549  data->what_time = 0; /* atime */
550  cond->data = data;
551  cond->free = cond_time_free;
552  cond->matches = cond_time_matches;
553  return cond;
554 }
static void cond_time_free(IsoFindCondition *cond)
Definition: find.c:514
static int cond_time_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:486

References cond_times::comparison, cond_time_free(), cond_time_matches(), iso_find_condition::data, iso_find_condition::free, iso_find_condition::matches, cond_times::time, and cond_times::what_time.

◆ iso_new_find_conditions_ctime()

IsoFindCondition* iso_new_find_conditions_ctime ( time_t  time,
enum iso_find_comparisons  comparison 
)

Create a new condition that checks the time of last status change.

Parameters
timeTime to compare against IsoNode ctime.
comparisonComparison to be done between IsoNode ctime and submitted time. Note that ISO_FIND_COND_GREATER, for example, is true if the node time is greater than the submitted time.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 607 of file find.c.

609 {
610  IsoFindCondition *cond;
611  struct cond_times *data;
612  cond = malloc(sizeof(IsoFindCondition));
613  if (cond == NULL) {
614  return NULL;
615  }
616  data = malloc(sizeof(struct cond_times));
617  if (data == NULL) {
618  free(cond);
619  return NULL;
620  }
621  data->time = time;
622  data->comparison = comparison;
623  data->what_time = 2; /* ctime */
624  cond->data = data;
625  cond->free = cond_time_free;
626  cond->matches = cond_time_matches;
627  return cond;
628 }

References cond_times::comparison, cond_time_free(), cond_time_matches(), iso_find_condition::data, iso_find_condition::free, iso_find_condition::matches, cond_times::time, and cond_times::what_time.

◆ iso_new_find_conditions_gid()

IsoFindCondition* iso_new_find_conditions_gid ( gid_t  gid)

Create a new condition that checks the node gid.

Parameters
gidDesired Group Id.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 411 of file find.c.

412 {
413  IsoFindCondition *cond;
414  gid_t *data;
415  cond = malloc(sizeof(IsoFindCondition));
416  if (cond == NULL) {
417  return NULL;
418  }
419  data = malloc(sizeof(gid_t));
420  if (data == NULL) {
421  free(cond);
422  return NULL;
423  }
424  *data = gid;
425  cond->data = data;
426  cond->free = cond_gid_free;
427  cond->matches = cond_gid_matches;
428  return cond;
429 }
static int cond_gid_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:389
static void cond_gid_free(IsoFindCondition *cond)
Definition: find.c:396

References find_iter_data::cond, cond_gid_free(), cond_gid_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_mode()

IsoFindCondition* iso_new_find_conditions_mode ( mode_t  mask)

Create a new condition that checks the node mode against a mode mask.

It can be used to check both file type and permissions.

For example:

iso_new_find_conditions_mode(S_IFREG) : search for regular files iso_new_find_conditions_mode(S_IFCHR | S_IWUSR) : search for character devices where owner has write permissions.

Parameters
maskMode mask to AND against node mode.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 366 of file find.c.

367 {
368  IsoFindCondition *cond;
369  mode_t *data;
370  cond = malloc(sizeof(IsoFindCondition));
371  if (cond == NULL) {
372  return NULL;
373  }
374  data = malloc(sizeof(mode_t));
375  if (data == NULL) {
376  free(cond);
377  return NULL;
378  }
379  *data = mask;
380  cond->data = data;
381  cond->free = cond_mode_free;
382  cond->matches = cond_mode_matches;
383  return cond;
384 }
static int cond_mode_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:337
static void cond_mode_free(IsoFindCondition *cond)
Definition: find.c:344

References find_iter_data::cond, cond_mode_free(), cond_mode_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_mtime()

IsoFindCondition* iso_new_find_conditions_mtime ( time_t  time,
enum iso_find_comparisons  comparison 
)

Create a new condition that checks the time of last modification.

Parameters
timeTime to compare against IsoNode mtime.
comparisonComparison to be done between IsoNode mtime and submitted time. Note that ISO_FIND_COND_GREATER, for example, is true if the node time is greater than the submitted time.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 570 of file find.c.

572 {
573  IsoFindCondition *cond;
574  struct cond_times *data;
575  cond = malloc(sizeof(IsoFindCondition));
576  if (cond == NULL) {
577  return NULL;
578  }
579  data = malloc(sizeof(struct cond_times));
580  if (data == NULL) {
581  free(cond);
582  return NULL;
583  }
584  data->time = time;
585  data->comparison = comparison;
586  data->what_time = 1; /* mtime */
587  cond->data = data;
588  cond->free = cond_time_free;
589  cond->matches = cond_time_matches;
590  return cond;
591 }

References cond_times::comparison, cond_time_free(), cond_time_matches(), iso_find_condition::data, iso_find_condition::free, iso_find_condition::matches, cond_times::time, and cond_times::what_time.

◆ iso_new_find_conditions_name()

IsoFindCondition* iso_new_find_conditions_name ( const char *  wildcard)

Create a new condition that checks if the node name matches the given wildcard.

Parameters
wildcard
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 318 of file find.c.

319 {
320  IsoFindCondition *cond;
321  if (wildcard == NULL) {
322  return NULL;
323  }
324  cond = malloc(sizeof(IsoFindCondition));
325  if (cond == NULL) {
326  return NULL;
327  }
328  cond->data = strdup(wildcard);
329  cond->free = cond_name_free;
330  cond->matches = cond_name_matches;
331  return cond;
332 }
static int cond_name_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:295
static void cond_name_free(IsoFindCondition *cond)
Definition: find.c:303

References find_iter_data::cond, cond_name_free(), cond_name_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_not()

IsoFindCondition* iso_new_find_conditions_not ( IsoFindCondition negate)

Create a new condition that check if the given conditions is false.

Parameters
negate
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 755 of file find.c.

756 {
757  IsoFindCondition *cond;
758  cond = malloc(sizeof(IsoFindCondition));
759  if (cond == NULL) {
760  return NULL;
761  }
762  cond->data = negate;
763  cond->free = cond_not_free;
764  cond->matches = cond_not_matches;
765  return cond;
766 }
static void cond_not_free(IsoFindCondition *cond)
Definition: find.c:732
static int cond_not_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:740

References cond_not_free(), cond_not_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_or()

IsoFindCondition* iso_new_find_conditions_or ( IsoFindCondition a,
IsoFindCondition b 
)

Create a new condition that check if at least one the two given conditions is valid.

Parameters
a
bIsoFindCondition to compare
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 709 of file find.c.

711 {
712  IsoFindCondition *cond;
713  struct logical_binary_conditions *data;
714  cond = malloc(sizeof(IsoFindCondition));
715  if (cond == NULL) {
716  return NULL;
717  }
718  data = malloc(sizeof(struct logical_binary_conditions));
719  if (data == NULL) {
720  free(cond);
721  return NULL;
722  }
723  data->a = a;
724  data->b = b;
725  cond->data = data;
728  return cond;
729 }
static int cond_logical_or_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:691

References logical_binary_conditions::a, logical_binary_conditions::b, cond_logical_binary_free(), cond_logical_or_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ iso_new_find_conditions_uid()

IsoFindCondition* iso_new_find_conditions_uid ( uid_t  uid)

Create a new condition that checks the node uid.

Parameters
uidDesired User Id.
Returns
The created IsoFindCondition, NULL on error.
Since
0.6.4

Definition at line 456 of file find.c.

457 {
458  IsoFindCondition *cond;
459  uid_t *data;
460  cond = malloc(sizeof(IsoFindCondition));
461  if (cond == NULL) {
462  return NULL;
463  }
464  data = malloc(sizeof(uid_t));
465  if (data == NULL) {
466  free(cond);
467  return NULL;
468  }
469  *data = uid;
470  cond->data = data;
471  cond->free = cond_uid_free;
472  cond->matches = cond_uid_matches;
473  return cond;
474 }
static int cond_uid_matches(IsoFindCondition *cond, IsoNode *node)
Definition: find.c:434
static void cond_uid_free(IsoFindCondition *cond)
Definition: find.c:441

References find_iter_data::cond, cond_uid_free(), cond_uid_matches(), iso_find_condition::data, iso_find_condition::free, and iso_find_condition::matches.

◆ update_next()

static void update_next ( IsoDirIter iter)
static

Definition at line 99 of file find.c.

100 {
101  int ret;
102  IsoNode *n;
103  struct find_iter_data *data = iter->data;
104 
105  if (data->prev) {
106  iso_node_unref(data->prev);
107  }
108  data->prev = data->current;
109 
110  if (data->itersec == NULL && data->current != NULL
111  && ISO_NODE_IS_DIR(data->current)) {
112 
113  /* we need to recurse on child dir */
114  struct find_iter_data *data2;
115  ret = iso_dir_find_children((IsoDir*)data->current, data->cond,
116  &data->itersec);
117  if (ret < 0) {
118  data->current = NULL;
119  data->err = ret;
120  return;
121  }
122  data2 = data->itersec->data;
123  data2->free_cond = 0; /* we don't need sec iter to free cond */
124  }
125 
126  ret = get_next(data, &n);
128  if (ret == 1) {
129  data->current = n;
130  iso_node_ref(n);
131  data->err = 0;
132  iter->dir = n->parent;
133  } else {
134  data->current = NULL;
135  data->err = ret;
136  iter->dir = data->dir;
137  }
139 }
IsoDir * parent
parent node, NULL for root
Definition: node.h:126

References find_iter_data::cond, find_iter_data::current, Iso_Dir_Iter::data, find_iter_data::dir, Iso_Dir_Iter::dir, find_iter_data::err, find_iter_data::free_cond, get_next(), iso_dir_find_children(), ISO_NODE_IS_DIR, iso_node_ref(), iso_node_unref(), find_iter_data::iter, find_iter_data::itersec, Iso_Node::parent, and find_iter_data::prev.

Referenced by find_iter_next(), and iso_dir_find_children().

Variable Documentation

◆ find_iter_class

struct iso_dir_iter_iface find_iter_class
static
Initial value:
= {
}
static void find_iter_free(IsoDirIter *iter)
Definition: find.c:168
static int find_iter_has_next(IsoDirIter *iter)
Definition: find.c:160
static int find_iter_next(IsoDirIter *iter, IsoNode **node)
Definition: find.c:142
static int find_iter_remove(IsoDirIter *iter)
Definition: find.c:203
static int find_iter_take(IsoDirIter *iter)
Definition: find.c:192
void find_notify_child_taken(IsoDirIter *iter, IsoNode *node)
Definition: find.c:213

Definition at line 213 of file find.c.

Referenced by iso_dir_find_children().