1 /* list.h - header for grub list */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef GRUB_LIST_HEADER
21 #define GRUB_LIST_HEADER 1
23 #include <grub/symbol.h>
24 #include <grub/types.h>
28 struct grub_list
*next
;
30 typedef struct grub_list
*grub_list_t
;
32 typedef int (*grub_list_hook_t
) (grub_list_t item
);
33 typedef int (*grub_list_test_t
) (grub_list_t new_item
, grub_list_t item
);
35 void EXPORT_FUNC(grub_list_push
) (grub_list_t
*head
, grub_list_t item
);
36 void * EXPORT_FUNC(grub_list_pop
) (grub_list_t
*head
);
37 void EXPORT_FUNC(grub_list_remove
) (grub_list_t
*head
, grub_list_t item
);
38 int EXPORT_FUNC(grub_list_iterate
) (grub_list_t head
, grub_list_hook_t hook
);
39 void EXPORT_FUNC(grub_list_insert
) (grub_list_t
*head
, grub_list_t item
,
40 grub_list_test_t test
);
42 /* This function doesn't exist, so if assertion is false for some reason, the
45 /* This approach fails with Apple's gcc. Use grub_abort. */
46 #include <grub/misc.h>
48 grub_assert_fail (void)
54 extern void* grub_assert_fail (void);
57 #define GRUB_FIELD_MATCH(ptr, type, field) \
58 ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
60 #define GRUB_AS_LIST(ptr) \
61 (GRUB_FIELD_MATCH (ptr, grub_list_t, next) ? \
62 (grub_list_t) ptr : grub_assert_fail ())
64 #define GRUB_AS_LIST_P(pptr) \
65 (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) ? \
66 (grub_list_t *) (void *) pptr : grub_assert_fail ())
68 struct grub_named_list
70 struct grub_named_list
*next
;
73 typedef struct grub_named_list
*grub_named_list_t
;
75 void * EXPORT_FUNC(grub_named_list_find
) (grub_named_list_t head
,
78 #define GRUB_AS_NAMED_LIST(ptr) \
79 ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) && \
80 GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
81 (grub_named_list_t) ptr : grub_assert_fail ())
83 #define GRUB_AS_NAMED_LIST_P(pptr) \
84 ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) && \
85 GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
86 (grub_named_list_t *) (void *) pptr : grub_assert_fail ())
88 #define GRUB_PRIO_LIST_PRIO_MASK 0xff
89 #define GRUB_PRIO_LIST_FLAG_ACTIVE 0x100
93 struct grub_prio_list
*next
;
97 typedef struct grub_prio_list
*grub_prio_list_t
;
99 void EXPORT_FUNC(grub_prio_list_insert
) (grub_prio_list_t
*head
,
100 grub_prio_list_t item
);
103 grub_prio_list_remove (grub_prio_list_t
*head
, grub_prio_list_t item
)
105 if ((item
->prio
& GRUB_PRIO_LIST_FLAG_ACTIVE
) && (item
->next
))
106 item
->next
->prio
|= GRUB_PRIO_LIST_FLAG_ACTIVE
;
107 grub_list_remove (GRUB_AS_LIST_P (head
), GRUB_AS_LIST (item
));
110 #define GRUB_AS_PRIO_LIST(ptr) \
111 ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \
112 GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \
113 GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \
114 (grub_prio_list_t) ptr : grub_assert_fail ())
116 #define GRUB_AS_PRIO_LIST_P(pptr) \
117 ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \
118 GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \
119 GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio))? \
120 (grub_prio_list_t *) (void *) pptr : grub_assert_fail ())
122 #endif /* ! GRUB_LIST_HEADER */