From: Alasdair Kergon Date: Thu, 22 Sep 2005 12:06:34 +0000 (+0000) Subject: Resync list.h with LVM2. X-Git-Tag: v1_01_05~1 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=c6c58d1c02b1b550a470e4ab406bce38a6582301;p=dm.git Resync list.h with LVM2. --- diff --git a/WHATS_NEW b/WHATS_NEW index 0f1aede..c35bdb5 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 1.01.05 - ============================= + Resync list.h with LVM2. Remember increased buffer size and use for subsequent calls. On 'buffer full' condition, double buffer size and repeat ioctl. Fix termination of getopt_long() option array. diff --git a/include/list.h b/include/list.h index 1ec8c73..11765ec 100644 --- a/include/list.h +++ b/include/list.h @@ -104,6 +104,22 @@ static inline int list_end(struct list *head, struct list *elem) return elem->n == head; } +/* + * Return first element of the list or NULL if empty + */ +static inline struct list *list_first(struct list *head) +{ + return (list_empty(head) ? NULL : head->n); +} + +/* + * Return last element of the list or NULL if empty + */ +static inline struct list *list_last(struct list *head) +{ + return (list_empty(head) ? NULL : head->p); +} + /* * Return the previous element of the list, or NULL if we've reached the start. */ @@ -187,6 +203,25 @@ static inline struct list *list_next(struct list *head, struct list *elem) */ #define list_iterate_items(v, head) list_iterate_items_gen(v, (head), list) +/* + * Walk a list backwards, setting 'v' in turn to the containing structure + * of each item. + * The containing structure should be the same type as 'v'. + * The 'struct list' variable within the containing structure is 'field'. + */ +#define list_iterate_back_items_gen(v, head, field) \ + for (v = list_struct_base((head)->p, typeof(*v), field); \ + &v->field != (head); \ + v = list_struct_base(v->field.p, typeof(*v), field)) + +/* + * Walk a list backwards, setting 'v' in turn to the containing structure + * of each item. + * The containing structure should be the same type as 'v'. + * The list should be 'struct list list' within the containing structure. + */ +#define list_iterate_back_items(v, head) list_iterate_back_items_gen(v, (head), list) + /* * Return the number of elements in a list by walking it. */