Skip to content

Commit

Permalink
sys/vfs/hammer: Define and use HAMMER_ENCODE() on blockmap formatting
Browse files Browse the repository at this point in the history
- Add HAMMER_ENCODE() which is a generic version of existing
  macros HAMMER_ENCODE_{RAW_VOLUME|RAW_BUFFER|FREEMAP}().

- Use HAMMER_ENCODE() in format_blockmap() in userspace when newfs
  initializes blockmap offsets. This is better in the sense that
  the macro hides internal of hammer's storage address space format,
  and gets rid of bitwise operations that make assumption on format.
  • Loading branch information
kusumi committed Jul 6, 2015
1 parent 3f08a1b commit cbf2551
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions sbin/hammer/ondisk.c
Expand Up @@ -817,8 +817,7 @@ void
format_blockmap(hammer_blockmap_t blockmap, hammer_off_t zone_base)
{
blockmap->phys_offset = 0;
blockmap->alloc_offset = zone_base | HAMMER_VOL_ENCODE(255) |
HAMMER_SHORT_OFF_ENCODE(-1);
blockmap->alloc_offset = HAMMER_ENCODE(zone_base, 255, -1);
blockmap->first_offset = zone_base;
blockmap->next_offset = zone_base;
blockmap->entry_crc = crc32(blockmap, HAMMER_BLOCKMAP_CRCSIZE);
Expand Down
5 changes: 5 additions & 0 deletions sys/vfs/hammer/hammer_disk.h
Expand Up @@ -189,6 +189,11 @@ typedef u_int32_t hammer_crc_t;
#define HAMMER_LONG_OFF_ENCODE(offset) \
((hammer_off_t)(offset) & HAMMER_OFF_LONG_MASK)

#define HAMMER_ENCODE(zone_base, vol_no, offset) \
((zone_base) | \
HAMMER_VOL_ENCODE(vol_no) | \
HAMMER_SHORT_OFF_ENCODE(offset))

#define HAMMER_ENCODE_RAW_VOLUME(vol_no, offset) \
(HAMMER_ZONE_RAW_VOLUME | \
HAMMER_VOL_ENCODE(vol_no) | \
Expand Down

0 comments on commit cbf2551

Please sign in to comment.