cfs/src/FsProc_JournalBasic.cc
// assumes that .calcSize() has been called and buf has that much space
assumes that .calcSize() has been called and buf has that much space
assumes that . calcSize () has been called and buf has that much space
size_t InodeLogEntry::serialize(uint8_t *buf) {
  uint64_t *uint64_header_fields = (uint64_t *)buf;
  uint64_header_fields[1] = inode;
  uint64_header_fields[2] = syncID;
  uint32_t *uint32_fields = (uint32_t *)(&(uint64_header_fields[3]));
  off_t i = 0;
  uint32_fields[i++] = optfield_bitarr;
  uint32_fields[i++] = mode;
  uint32_fields[i++] = uid;
  uint32_fields[i++] = gid;
  uint32_fields[i++] = block_count;
  uint32_fields[i++] = bitmap_op;
  struct timeval *timeval_fields = (struct timeval *)(&uint32_fields[i]);
  i = 0;
  timeval_fields[i++] = atime;
  timeval_fields[i++] = mtime;
  timeval_fields[i++] = ctime;
  uint8_t *ptr = (uint8_t *)(&timeval_fields[i]);
  *((uint16_t *)ptr) = dentry_count;
  ptr += 2;
  *((uint8_t *)ptr) = nlink;
  ptr += 1;
  *((uint64_t *)ptr) = size;
  ptr += 8;
  size_t n_ext_add = ext_add.size();
  uint8_t *ext_iter = ptr;
  *((uint64_t *)ext_iter) = (uint64_t)n_ext_add;
  ext_iter += 8;
  for (const auto &[block_no, val] : ext_add) {
    *((uint64_t *)ext_iter) = block_no;
    ext_iter += 8;
    *((struct ExtMapVal *)ext_iter) = val;
    ext_iter += sizeof(struct ExtMapVal);
  }
  size_t n_ext_del = ext_del.size();
  *((uint64_t *)ext_iter) = (uint64_t)n_ext_del;
  ext_iter += 8;
  for (const auto &[block_no, val] : ext_del) {
    *((uint64_t *)ext_iter) = block_no;
    ext_iter += 8;
    *((struct ExtMapVal *)ext_iter) = val;
    ext_iter += sizeof(struct ExtMapVal);
  }
  size_t n_depends_on = depends_on.size();
  uint64_t *depends_on_map = (uint64_t *)ext_iter;
  depends_on_map[0] = (uint64_t)n_depends_on;
  i = 1;
  for (auto const &iter : depends_on) {
    depends_on_map[i++] = (uint64_t)iter.first;
    depends_on_map[i++] = (uint64_t)iter.second;
  }
  size_t entry_size = ((uint8_t *)(&(depends_on_map[i]))) - buf;
  uint64_header_fields[0] = (uint64_t)entry_size;
  return entry_size;
}
size_t InodeLogEntry :: serialize ( uint8_t * buf ) { uint64_t * uint64_header_fields = ( uint64_t * ) buf ; uint64_header_fields [ 1 ] = inode ; uint64_header_fields [ 2 ] = syncID ; uint32_t * uint32_fields = ( uint32_t * ) ( & ( uint64_header_fields [ 3 ] ) ) ; off_t i = 0 ; uint32_fields [ i ++ ] = optfield_bitarr ; uint32_fields [ i ++ ] = mode ; uint32_fields [ i ++ ] = uid ; uint32_fields [ i ++ ] = gid ; uint32_fields [ i ++ ] = block_count ; uint32_fields [ i ++ ] = bitmap_op ; struct timeval * timeval_fields = ( struct timeval * ) ( & uint32_fields [ i ] ) ; i = 0 ; timeval_fields [ i ++ ] = atime ; timeval_fields [ i ++ ] = mtime ; timeval_fields [ i ++ ] = ctime ; uint8_t * ptr = ( uint8_t * ) ( & timeval_fields [ i ] ) ; * ( ( uint16_t * ) ptr ) = dentry_count ; ptr += 2 ; * ( ( uint8_t * ) ptr ) = nlink ; ptr += 1 ; * ( ( uint64_t * ) ptr ) = size ; ptr += 8 ; size_t n_ext_add = ext_add . size ( ) ; uint8_t * ext_iter = ptr ; * ( ( uint64_t * ) ext_iter ) = ( uint64_t ) n_ext_add ; ext_iter += 8 ; for ( const auto & [ block_no , val ] : ext_add ) { * ( ( uint64_t * ) ext_iter ) = block_no ; ext_iter += 8 ; * ( ( struct ExtMapVal * ) ext_iter ) = val ; ext_iter += sizeof ( struct ExtMapVal ) ; } size_t n_ext_del = ext_del . size ( ) ; * ( ( uint64_t * ) ext_iter ) = ( uint64_t ) n_ext_del ; ext_iter += 8 ; for ( const auto & [ block_no , val ] : ext_del ) { * ( ( uint64_t * ) ext_iter ) = block_no ; ext_iter += 8 ; * ( ( struct ExtMapVal * ) ext_iter ) = val ; ext_iter += sizeof ( struct ExtMapVal ) ; } size_t n_depends_on = depends_on . size ( ) ; uint64_t * depends_on_map = ( uint64_t * ) ext_iter ; depends_on_map [ 0 ] = ( uint64_t ) n_depends_on ; i = 1 ; for ( auto const & iter : depends_on ) { depends_on_map [ i ++ ] = ( uint64_t ) iter . first ; depends_on_map [ i ++ ] = ( uint64_t ) iter . second ; } size_t entry_size = ( ( uint8_t * ) ( & ( depends_on_map [ i ] ) ) ) - buf ; uint64_header_fields [ 0 ] = ( uint64_t ) entry_size ; return entry_size ; }
assumes that .calcSize() has been called and buf has that much space
assumes that . calcSize () has been called and buf has that much space
// TODO create a struct for the private members and memcpy the entire thing // TODO disassemble and see if the optimized code avoids the increment and // uses hard coded literals // returns total number of bytes used