Home | History | Annotate | Download | only in chain
      1 /* ----------------------------------------------------------------------- *
      2  *
      3  *   Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
      4  *   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
      5  *   Copyright 2010 Shao Miller
      6  *   Copyright 2010-2012 Michal Soltys
      7  *
      8  *   Permission is hereby granted, free of charge, to any person
      9  *   obtaining a copy of this software and associated documentation
     10  *   files (the "Software"), to deal in the Software without
     11  *   restriction, including without limitation the rights to use,
     12  *   copy, modify, merge, publish, distribute, sublicense, and/or
     13  *   sell copies of the Software, and to permit persons to whom
     14  *   the Software is furnished to do so, subject to the following
     15  *   conditions:
     16  *
     17  *   The above copyright notice and this permission notice shall
     18  *   be included in all copies or substantial portions of the Software.
     19  *
     20  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     21  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
     22  *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     23  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
     24  *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     25  *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     26  *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     27  *   OTHER DEALINGS IN THE SOFTWARE.
     28  *
     29  * ----------------------------------------------------------------------- */
     30 
     31 /*
     32  * partiter.h
     33  *
     34  * Provides disk / partition iteration.
     35  */
     36 
     37 #ifndef COM32_CHAIN_PARTITER_H
     38 #define COM32_CHAIN_PARTITER_H
     39 
     40 #include <stdint.h>
     41 #include <syslinux/disk.h>
     42 
     43 /* status */
     44 
     45 enum {PI_ERRLOAD = -31, PI_INSANE, PI_OK = 0, PI_DONE};
     46 
     47 /* flags */
     48 
     49 enum {PIF_STEPALL = 1, PIF_PREFMBR = 2, PIF_STRICT = 4, PIF_STRICTER = 8};
     50 
     51 struct itertype;
     52 struct part_iter;
     53 
     54 struct itertype {
     55 	void (*dtor)(struct part_iter *);
     56 	int  (*next)(struct part_iter *);
     57 };
     58 
     59 #define PI_GPTLABSIZE ((int)sizeof(((struct disk_gpt_part_entry *)0)->name))
     60 
     61 struct part_iter {
     62     const struct itertype *type;
     63     char *data;
     64     char *record;
     65     uint64_t abs_lba;
     66     uint64_t length;
     67     int index0;	    /* including holes, from -1 (disk, then parts from 0) */
     68     int index;	    /* excluding holes, from  0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */
     69     int flags;	    /* flags, see #defines above */
     70     int status;	    /* current status, see enums above */
     71     struct disk_info di;
     72     union {
     73 	struct {
     74 	    uint32_t disk_sig;	  /* 32bit disk signature as stored in MBR */
     75 
     76 	    uint32_t bebr_lba;	  /* absolute lba of base extended partition */
     77 	    uint32_t bebr_siz;	  /* size of base extended partition */
     78 
     79 	    uint32_t cebr_lba;	  /* absolute lba of curr ext. partition */
     80 	    uint32_t cebr_siz;	  /* size of curr ext. partition */
     81 	    uint32_t nebr_lba;	  /* absolute lba of next ext. partition */
     82 	    uint32_t nebr_siz;	  /* size of next ext. partition */
     83 
     84 	    int bebr_index0;	  /* index of (0-3) of base ext. part., -1 if not present in MBR */
     85 	    int logskipcnt;	  /* how many logical holes were skipped */
     86 	} dos;
     87 	struct {
     88 	    struct guid disk_guid;
     89 	    struct guid part_guid;
     90 	    char part_label[PI_GPTLABSIZE/2+1];
     91 	    int pe_count;
     92 	    int pe_size;
     93 	    uint64_t ufirst;
     94 	    uint64_t ulast;
     95 	} gpt;
     96     };
     97 };
     98 
     99 extern const struct itertype * const typedos;
    100 extern const struct itertype * const typegpt;
    101 extern const struct itertype * const typeraw;
    102 
    103 struct part_iter *pi_begin(const struct disk_info *, int flags);
    104 void pi_del(struct part_iter **);
    105 
    106 /* inline virtuals */
    107 static inline int pi_next(struct part_iter *iter)
    108 {
    109     return iter->type->next(iter);
    110 }
    111 
    112 static inline void pi_dtor(struct part_iter *iter)
    113 {
    114     iter->type->dtor(iter);
    115 }
    116 
    117 #endif
    118 
    119 /* vim: set ts=8 sts=4 sw=4 noet: */
    120