FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/transaction.c
/* Allocate an item index for the given MY_OFFSET in the transaction TXN_ID
 * of file system FS and return it in *ITEM_INDEX.  For old formats, it
 * will simply return the offset as item index; in new formats, it will
 * increment the txn's item index counter file and store the mapping in
 * the proto index file.  Use POOL for allocations.
 */
Allocate an item index for the given MY_OFFSET in the transaction TXN_ID
of file system FS and return it in *ITEM_INDEX.  For old formats, it
will simply return the offset as item index; in new formats, it will
increment the txn's item index counter file and store the mapping in
the proto index file.  Use POOL for allocations.
Allocate an item index for the given MY_OFFSET in the transaction TXN_ID of file system FS and return it in * ITEM_INDEX . For old formats it will simply return the offset as item index ; in new formats it will increment the txn ' s item index counter file and store the mapping in the proto index file . Use POOL for allocations .
static svn_error_t *
allocate_item_index(apr_uint64_t *item_index,
                    svn_fs_t *fs,
                    const svn_fs_fs__id_part_t *txn_id,
                    apr_off_t my_offset,
                    apr_pool_t *pool)
{
  if (svn_fs_fs__use_log_addressing(fs))
    {
      apr_file_t *file;
      char buffer[SVN_INT64_BUFFER_SIZE] = { 0 };
      svn_boolean_t eof = FALSE;
      apr_size_t to_write;
      apr_size_t read;
      apr_off_t offset = 0;
      SVN_ERR(svn_io_file_open(&file,
                         svn_fs_fs__path_txn_item_index(fs, txn_id, pool),
                         APR_READ | APR_WRITE | APR_CREATE | APR_BUFFERED,
                         APR_OS_DEFAULT, pool));
      SVN_ERR(svn_io_file_read_full2(file, buffer, sizeof(buffer)-1,
                                     &read, &eof, pool));
      if (read)
        SVN_ERR(svn_cstring_atoui64(item_index, buffer));
      else
        *item_index = SVN_FS_FS__ITEM_INDEX_FIRST_USER;
      to_write = svn__ui64toa(buffer, *item_index + 1);
      SVN_ERR(svn_io_file_seek(file, APR_SET, &offset, pool));
      SVN_ERR(svn_io_file_write_full(file, buffer, to_write, NULL, pool));
      SVN_ERR(svn_io_file_close(file, pool));
      SVN_ERR(store_l2p_index_entry(fs, txn_id, my_offset, *item_index, pool));
    }
  else
    {
      *item_index = (apr_uint64_t)my_offset;
    }
  return SVN_NO_ERROR;
}
static svn_error_t * allocate_item_index ( apr_uint64_t * item_index , svn_fs_t * fs , const svn_fs_fs__id_part_t * txn_id , apr_off_t my_offset , apr_pool_t * pool ) { if ( svn_fs_fs__use_log_addressing ( fs ) ) { apr_file_t * file ; char buffer [ SVN_INT64_BUFFER_SIZE ] = { 0 } ; svn_boolean_t eof = FALSE ; apr_size_t to_write ; apr_size_t read ; apr_off_t offset = 0 ; SVN_ERR ( svn_io_file_open ( & file , svn_fs_fs__path_txn_item_index ( fs , txn_id , pool ) , APR_READ | APR_WRITE | APR_CREATE | APR_BUFFERED , APR_OS_DEFAULT , pool ) ) ; SVN_ERR ( svn_io_file_read_full2 ( file , buffer , sizeof ( buffer ) - 1 , & read , & eof , pool ) ) ; if ( read ) SVN_ERR ( svn_cstring_atoui64 ( item_index , buffer ) ) ; else * item_index = SVN_FS_FS__ITEM_INDEX_FIRST_USER ; to_write = svn__ui64toa ( buffer , * item_index + 1 ) ; SVN_ERR ( svn_io_file_seek ( file , APR_SET , & offset , pool ) ) ; SVN_ERR ( svn_io_file_write_full ( file , buffer , to_write , NULL , pool ) ) ; SVN_ERR ( svn_io_file_close ( file , pool ) ) ; SVN_ERR ( store_l2p_index_entry ( fs , txn_id , my_offset , * item_index , pool ) ) ; } else { * item_index = ( apr_uint64_t ) my_offset ; } return SVN_NO_ERROR ; }
Allocate an item index for the given MY_OFFSET in the transaction TXN_ID
 of file system FS and return it in *ITEM_INDEX.
Allocate an item index for the given MY_OFFSET in the transaction TXN_ID of file system FS and return it in * ITEM_INDEX .
/* read number, increment it and write it back to disk */ /* write log-to-phys index */