aboutsummaryrefslogtreecommitdiffstats
path: root/com32/chain/partiter.h
diff options
context:
space:
mode:
authorMichal Soltys <soltys@ziu.info>2013-02-14 16:51:45 +0100
committerMichal Soltys <soltys@ziu.info>2013-02-14 16:53:04 +0100
commit4f46f2e8713dddfc73d4a5e229201302254b988c (patch)
tree575bc9c1ee3292a903f9d1c8ddc9fe8e28f5b107 /com32/chain/partiter.h
parentc5d41b402f31849690a18ff682422ac7e691bebe (diff)
downloadsyslinux-4f46f2e8713dddfc73d4a5e229201302254b988c.tar.gz
syslinux-4f46f2e8713dddfc73d4a5e229201302254b988c.tar.xz
syslinux-4f46f2e8713dddfc73d4a5e229201302254b988c.zip
com32/chain: partiter - simplifications and updates
The code uses more abstractions than it's really worth or necessary, so these patches simplify the code a bit. Partially suggested by Shao as well. Additionally, there're some added comments and more consistent naming used. Signed-off-by: Michal Soltys <soltys@ziu.info>
Diffstat (limited to 'com32/chain/partiter.h')
-rw-r--r--com32/chain/partiter.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h
index ac15de63..821d4481 100644
--- a/com32/chain/partiter.h
+++ b/com32/chain/partiter.h
@@ -40,12 +40,11 @@
#include <stdint.h>
#include <syslinux/disk.h>
-#define PI_ERRLOAD 3
-#define PI_INSANE 2
-#define PI_DONE 1
-#define PI_OK 0
+/* status */
-/* behaviour flags */
+enum {PI_OK, PI_DONE, PI_INSANE, PI_ERRLOAD};
+
+/* flags */
#define PIF_STEPALL 0x01
@@ -53,9 +52,8 @@ struct itertype;
struct part_iter;
struct itertype {
- int (*ctor)(struct part_iter *, va_list *);
void (*dtor)(struct part_iter *);
- struct part_iter *(*next) (struct part_iter *);
+ int (*next)(struct part_iter *);
};
#define PI_GPTLABSIZE ((int)sizeof(((struct disk_gpt_part_entry *)0)->name))
@@ -66,13 +64,12 @@ struct part_iter {
char *record;
uint64_t start_lba;
uint64_t length;
- int index;
- int rawindex;
+ int index0; /* including holes, from -1 (disk, then parts from 0) */
+ int rawindex; /* including holes, from 0 (disk, then parts from 1) */
+ int index; /* excluding holes, from 0 (disk) (-1) means hole, if PIF_STEPALL is set */
+ int flags; /* flags, see #defines above */
+ int status; /* current status, see enums above */
struct disk_info di;
- int flags;
- int status;
- /* internal */
- int index0;
union {
struct {
uint32_t disk_sig;
@@ -103,9 +100,18 @@ extern const struct itertype * const typegpt;
extern const struct itertype * const typeraw;
struct part_iter *pi_begin(const struct disk_info *, int flags);
-struct part_iter *pi_new(const struct itertype *, ...);
void pi_del(struct part_iter **);
-int pi_next(struct part_iter **);
+
+/* inline virtuals */
+static inline int pi_next(struct part_iter *iter)
+{
+ return iter->type->next(iter);
+}
+
+static inline void pi_dtor(struct part_iter *iter)
+{
+ iter->type->dtor(iter);
+}
#endif