Resolving data_offset and data_len

Simon 'corecode' Schubert corecode at
Thu Jun 4 11:14:55 PDT 2009

Daniel Lorch wrote:
cursor.leaf->base.key is the logical *end* (in bytes) of the extent
cursor.leaf->data_len is the length of the extent in bytes
cursor.leaf->data_offset is the HAMMER internal offset (see below)
I am not sure I understand extents in HAMMER. Let me try:

Suppose we had a file of 24K. This file would be broken up into two
parts of 16K and 8K respectively. In HAMMER, these parts are called
``data records''. Contiguous data records are called ``extents''
(contiguous relative to what? to the underlying block device?).
Yes.  They are contiguous on the block device, and also in the file.

Each data record is stored as a leaf node in the B-tree. To obtain all
leaf nodes belonging to a file, a ``cursor'' is initalized with the
following values:
  cursor.key_beg.obj_id     <-- the i-number
  cursor.key_beg.key        <-- is that a byte offset? relative to what?
that's the offset in the file.

  cursor.asof               <-- what's that for? history/version?

  cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA <-- we want a file

hammer_ip_first() and hammer_ip_next() are used to iterate through all
leaf nodes.
Is that right? (reference:
Yes, however there are more details to it, because extents may overlap 
(history!), or not exit (sparse files) or be too long (truncations), so 
special care must be taken.

1. Does cursor.leaf->base.key indicate the end of the current data
record or the *entire file*?
the end of (i.e. first offset after) this extent

2. For a given file of 12 bytes, cursor.leaf->data_len gives me 16. What
am I missing?
extents might be padded or files might be truncated.  you always have to 
keep an eye on the inode length.

  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |      Against  HTML   \
Dude 2c 2 the max   !       Mail + News   / \

More information about the Hammer mailing list