]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoycli/fat_io_lib/include/fat_list.h
12 //-----------------------------------------------------------------
14 //-----------------------------------------------------------------
19 struct fat_node
*previous
;
20 struct fat_node
*next
;
25 struct fat_node
*head
;
26 struct fat_node
*tail
;
29 //-----------------------------------------------------------------
31 //-----------------------------------------------------------------
32 #define fat_list_entry(p, t, m) p ? ((t *)((char *)(p)-(char*)(&((t *)0)->m))) : 0
33 #define fat_list_next(l, p) (p)->next
34 #define fat_list_prev(l, p) (p)->previous
35 #define fat_list_first(l) (l)->head
36 #define fat_list_last(l) (l)->tail
37 #define fat_list_for_each(l, p) for ((p) = (l)->head; (p); (p) = (p)->next)
39 //-----------------------------------------------------------------
41 //-----------------------------------------------------------------
43 //-----------------------------------------------------------------
45 //-----------------------------------------------------------------
46 static FAT_INLINE
void fat_list_init(struct fat_list
*list
)
50 list
->head
= list
->tail
= 0;
52 //-----------------------------------------------------------------
54 //-----------------------------------------------------------------
55 static FAT_INLINE
void fat_list_remove(struct fat_list
*list
, struct fat_node
*node
)
61 list
->head
= node
->next
;
63 node
->previous
->next
= node
->next
;
66 list
->tail
= node
->previous
;
68 node
->next
->previous
= node
->previous
;
70 //-----------------------------------------------------------------
71 // fat_list_insert_after:
72 //-----------------------------------------------------------------
73 static FAT_INLINE
void fat_list_insert_after(struct fat_list
*list
, struct fat_node
*node
, struct fat_node
*new_node
)
79 new_node
->previous
= node
;
80 new_node
->next
= node
->next
;
82 list
->tail
= new_node
;
84 node
->next
->previous
= new_node
;
85 node
->next
= new_node
;
87 //-----------------------------------------------------------------
88 // fat_list_insert_before:
89 //-----------------------------------------------------------------
90 static FAT_INLINE
void fat_list_insert_before(struct fat_list
*list
, struct fat_node
*node
, struct fat_node
*new_node
)
96 new_node
->previous
= node
->previous
;
97 new_node
->next
= node
;
99 list
->head
= new_node
;
101 node
->previous
->next
= new_node
;
102 node
->previous
= new_node
;
104 //-----------------------------------------------------------------
105 // fat_list_insert_first:
106 //-----------------------------------------------------------------
107 static FAT_INLINE
void fat_list_insert_first(struct fat_list
*list
, struct fat_node
*node
)
120 fat_list_insert_before(list
, list
->head
, node
);
122 //-----------------------------------------------------------------
123 // fat_list_insert_last:
124 //-----------------------------------------------------------------
125 static FAT_INLINE
void fat_list_insert_last(struct fat_list
*list
, struct fat_node
*node
)
131 fat_list_insert_first(list
, node
);
133 fat_list_insert_after(list
, list
->tail
, node
);
135 //-----------------------------------------------------------------
136 // fat_list_is_empty:
137 //-----------------------------------------------------------------
138 static FAT_INLINE
int fat_list_is_empty(struct fat_list
*list
)
144 //-----------------------------------------------------------------
145 // fat_list_pop_head:
146 //-----------------------------------------------------------------
147 static FAT_INLINE
struct fat_node
* fat_list_pop_head(struct fat_list
*list
)
149 struct fat_node
* node
;
153 node
= fat_list_first(list
);
155 fat_list_remove(list
, node
);