[syslinux] PATCH/RFC chain.c: update iterator code, yank from chain.c, move both to separate directory

Michal Soltys soltys at ziu.info
Sat Aug 7 17:10:04 PDT 2010


1) code split and move

Iterator related functionality is yanked from chain.c and moved to
iterator.{c,h}. Both are moved to com32/chain and this way chain.c is ready
for further splitting.

Alternatively, partiter could be moved to com32/lib at any time in the future.
It's potentially useful for other modules (e.g. if someone wanted to code
partition dumper or editor).

2) Iterator updates

This part is actually pretty large:

2a) sanity checks

- potential add/mul overflows are detected
- partition related checks handled by notsane_{primary,logical,extended,gpt}()
  family of functions. They can be easily extended in the future.
- additional checks in main pi_{gpt,dos}_next() functions and subfunctions

2b) EBR+MBR iterator merge

They function now simply as 'dos' iterator (to keep naming consistent with
disklib). Code is split into smaller functions, everything should look pretty
logical.

2c) GPT iterator

Core remained similar to previous version. Additional functionality includes:

- extra small sanity check
- empty partition is characterized by type guid == 0, not lba_first == 0
- automatic label rewrite from UCS2-LE to asciiz (to separate buffer)
- export of partition guid (also to separate buffer)

2d) iterators *include* disk during iteration

Right after creation, pi_begin() (previously get_first_partition()) does not
iterate to first partition.

2e) available data at any time

- disk guid or disk signature (sub.gpt.disk_guid or sub.dos_disk_sig)
- parition guid (sub.gpt.part_guid)
- parition label, asciiz (sub.gpt.part_label)
- pointer to record holding unaltered partition entry (record)
- iterator type (type)
- lba beginning of partition (start_lba)
- disk (0) / partition (1+) index (index)

See partiter.h for details.

2f) pi_begin()

It does sanity checks - including gpt's primary+backup+array crc checks - and
allocates proper iterator. Some additional checks (mbr protective id, gpt
revision, general sanity) are also performed.

2g) other stuff

As previously, iterators self-destroy after finishing. They can be explicitly
allocated through pi_new() (although this was exported mostly thinking about
com32/lib) and removed through pi_del(); pi_next() moves iterator further.
Partiter compiles cleanly with -Wextra -Wconversion -pedantic

2h) chain.c changes

- find_by_guid() had small bug (took address of address of struct holding disk
  guid to compare)
- find_by_{guid,label,disk} greately simplified due to extra data available
  from iterators
- in main() - lba_fs takes clear precedence over regular partition number
- changes necessary to include new iterator code
- mbr/sect/hand/file's areas proper deallocation (from earlier patches)


Code has been tested a lot with both gpt and legacy partitions, including holes
(also logical ones) and partitions "not in disk" order (compared to the sample
I sent offlist, it got one small bug fixed - the rest of changes are usually
cosmetics/shuffling). Numbering is consistent with what linux kernel does.

Michal Soltys (1):
  [RFC/PATCH] split chain into chain+iterator, expand iterators' code

 Makefile                         |    2 +-
 com32/Makefile                   |    2 +-
 com32/chain/Makefile             |   39 ++
 com32/{modules => chain}/chain.c |  568 +++++++-----------------------
 com32/chain/partiter.c           |  714 ++++++++++++++++++++++++++++++++++++++
 com32/chain/partiter.h           |   94 +++++
 com32/modules/Makefile           |    2 +-
 7 files changed, 985 insertions(+), 436 deletions(-)
 create mode 100644 com32/chain/Makefile
 rename com32/{modules => chain}/chain.c (68%)
 create mode 100644 com32/chain/partiter.c
 create mode 100644 com32/chain/partiter.h

-- 
1.7.2.1




More information about the Syslinux mailing list