FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/fs_fs.c
/* Read the format number and maximum number of files per directory
   from PATH and return them in *PFORMAT, *MAX_FILES_PER_DIR and
   USE_LOG_ADDRESSIONG respectively.

   *MAX_FILES_PER_DIR is obtained from the 'layout' format option, and
   will be set to zero if a linear scheme should be used.
   *USE_LOG_ADDRESSIONG is obtained from the 'addressing' format option,
   and will be set to FALSE for physical addressing.

   Use POOL for temporary allocation. */
Read the format number and maximum number of files per directory
from PATH and return them in *PFORMAT, *MAX_FILES_PER_DIR and
USE_LOG_ADDRESSIONG respectively.

MAX_FILES_PER_DIR is obtained from the 'layout' format option, and
will be set to zero if a linear scheme should be used.
USE_LOG_ADDRESSIONG is obtained from the 'addressing' format option,
and will be set to FALSE for physical addressing.

Use POOL for temporary allocation.
Read the format number and maximum number of files per directory from PATH and return them in * PFORMAT * MAX_FILES_PER_DIR and USE_LOG_ADDRESSIONG respectively . MAX_FILES_PER_DIR is obtained from the ' layout ' format option and will be set to zero if a linear scheme should be used . USE_LOG_ADDRESSIONG is obtained from the ' addressing ' format option and will be set to FALSE for physical addressing . Use POOL for temporary allocation .
static svn_error_t *
read_format(int *pformat,
            int *max_files_per_dir,
            svn_boolean_t *use_log_addressing,
            const char *path,
            apr_pool_t *pool)
{
  svn_error_t *err;
  svn_stream_t *stream;
  svn_stringbuf_t *content;
  svn_stringbuf_t *buf;
  svn_boolean_t eos = FALSE;
  err = svn_stringbuf_from_file2(&content, path, pool);
  if (err && APR_STATUS_IS_ENOENT(err->apr_err))
    {
      svn_error_clear(err);
      *pformat = 1;
      *max_files_per_dir = 0;
      return SVN_NO_ERROR;
    }
  SVN_ERR(err);
  stream = svn_stream_from_stringbuf(content, pool);
  SVN_ERR(svn_stream_readline(stream, &buf, "\n", &eos, pool));
  if (buf->len == 0 && eos)
    {
      return svn_error_createf(SVN_ERR_BAD_VERSION_FILE_FORMAT, NULL,
                               _("Can't read first line of format file '%s'"),
                               svn_dirent_local_style(path, pool));
    }
  SVN_ERR(check_format_file_buffer_numeric(buf->data, 0, path, pool));
  SVN_ERR(svn_cstring_atoi(pformat, buf->data));
  SVN_ERR(check_format(*pformat));
  *max_files_per_dir = 0;
  *use_log_addressing = FALSE;
  while (!eos)
    {
      SVN_ERR(svn_stream_readline(stream, &buf, "\n", &eos, pool));
      if (buf->len == 0)
        break;
      if (*pformat >= SVN_FS_FS__MIN_LAYOUT_FORMAT_OPTION_FORMAT &&
          strncmp(buf->data, "layout ", 7) == 0)
        {
          if (strcmp(buf->data + 7, "linear") == 0)
            {
              *max_files_per_dir = 0;
              continue;
            }
          if (strncmp(buf->data + 7, "sharded ", 8) == 0)
            {
              SVN_ERR(check_format_file_buffer_numeric(buf->data, 15, path, pool));
              SVN_ERR(svn_cstring_atoi(max_files_per_dir, buf->data + 15));
              continue;
            }
        }
      if (*pformat >= SVN_FS_FS__MIN_LOG_ADDRESSING_FORMAT &&
          strncmp(buf->data, "addressing ", 11) == 0)
        {
          if (strcmp(buf->data + 11, "physical") == 0)
            {
              *use_log_addressing = FALSE;
              continue;
            }
          if (strcmp(buf->data + 11, "logical") == 0)
            {
              *use_log_addressing = TRUE;
              continue;
            }
        }
      return svn_error_createf(SVN_ERR_BAD_VERSION_FILE_FORMAT, NULL,
         _("'%s' contains invalid filesystem format option '%s'"),
         svn_dirent_local_style(path, pool), buf->data);
    }
  if (*use_log_addressing && !*max_files_per_dir)
    return svn_error_createf(SVN_ERR_BAD_VERSION_FILE_FORMAT, NULL,
       _("'%s' specifies logical addressing for a non-sharded repository"),
       svn_dirent_local_style(path, pool));
  return SVN_NO_ERROR;
}
static svn_error_t * read_format ( int * pformat , int * max_files_per_dir , svn_boolean_t * use_log_addressing , const char * path , apr_pool_t * pool ) { svn_error_t * err ; svn_stream_t * stream ; svn_stringbuf_t * content ; svn_stringbuf_t * buf ; svn_boolean_t eos = FALSE ; err = svn_stringbuf_from_file2 ( & content , path , pool ) ; if ( err && APR_STATUS_IS_ENOENT ( err -> apr_err ) ) { svn_error_clear ( err ) ; * pformat = 1 ; * max_files_per_dir = 0 ; return SVN_NO_ERROR ; } SVN_ERR ( err ) ; stream = svn_stream_from_stringbuf ( content , pool ) ; SVN_ERR ( svn_stream_readline ( stream , & buf , " \n " , & eos , pool ) ) ; if ( buf -> len == 0 && eos ) { return svn_error_createf ( SVN_ERR_BAD_VERSION_FILE_FORMAT , NULL , _ ( " " ) , svn_dirent_local_style ( path , pool ) ) ; } SVN_ERR ( check_format_file_buffer_numeric ( buf -> data , 0 , path , pool ) ) ; SVN_ERR ( svn_cstring_atoi ( pformat , buf -> data ) ) ; SVN_ERR ( check_format ( * pformat ) ) ; * max_files_per_dir = 0 ; * use_log_addressing = FALSE ; while ( ! eos ) { SVN_ERR ( svn_stream_readline ( stream , & buf , " \n " , & eos , pool ) ) ; if ( buf -> len == 0 ) break ; if ( * pformat >= SVN_FS_FS__MIN_LAYOUT_FORMAT_OPTION_FORMAT && strncmp ( buf -> data , " " , 7 ) == 0 ) { if ( strcmp ( buf -> data + 7 , " " ) == 0 ) { * max_files_per_dir = 0 ; continue ; } if ( strncmp ( buf -> data + 7 , " " , 8 ) == 0 ) { SVN_ERR ( check_format_file_buffer_numeric ( buf -> data , 15 , path , pool ) ) ; SVN_ERR ( svn_cstring_atoi ( max_files_per_dir , buf -> data + 15 ) ) ; continue ; } } if ( * pformat >= SVN_FS_FS__MIN_LOG_ADDRESSING_FORMAT && strncmp ( buf -> data , " " , 11 ) == 0 ) { if ( strcmp ( buf -> data + 11 , " " ) == 0 ) { * use_log_addressing = FALSE ; continue ; } if ( strcmp ( buf -> data + 11 , " " ) == 0 ) { * use_log_addressing = TRUE ; continue ; } } return svn_error_createf ( SVN_ERR_BAD_VERSION_FILE_FORMAT , NULL , _ ( " " ) , svn_dirent_local_style ( path , pool ) , buf -> data ) ; } if ( * use_log_addressing && ! * max_files_per_dir ) return svn_error_createf ( SVN_ERR_BAD_VERSION_FILE_FORMAT , NULL , _ ( " " ) , svn_dirent_local_style ( path , pool ) ) ; return SVN_NO_ERROR ; }
Read the format number and maximum number of files per directory
from PATH and return them in *PFORMAT, *MAX_FILES_PER_DIR and
USE_LOG_ADDRESSIONG respectively.
Read the format number and maximum number of files per directory from PATH and return them in * PFORMAT * MAX_FILES_PER_DIR and USE_LOG_ADDRESSIONG respectively .
/* Treat an absent format file as format 1.  Do not try to
         create the format file on the fly, because the repository
         might be read-only for us, or this might be a read-only
         operation, and the spirit of FSFS is to make no changes
         whatseover in read-only operations.  See thread starting at
         http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=97600
         for more. */ /* Return a more useful error message. */ /* Check that the first line contains only digits. */ /* Check that we support this format at all */ /* Set the default values for anything that can be set via an option. */ /* Read any options. */ /* Check that the argument is numeric. */ /* Non-sharded repositories never use logical addressing.
   * If the format file is inconsistent in that respect, something
   * probably went wrong.
   */