LCOV - code coverage report
Current view: top level - app/firedancer/commands/configure - vinyl.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 44 0.0 %
Date: 2025-12-07 04:58:33 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #include "../../../shared/commands/configure/configure.h"
       2             : #include "../../../platform/fd_file_util.h"
       3             : 
       4             : #include <errno.h>
       5             : #include <fcntl.h>    /* open */
       6             : #include <unistd.h>   /* fchown, close */
       7             : #include <sys/stat.h> /* fchmod */
       8             : 
       9             : static int
      10           0 : enabled( config_t const * config ) {
      11           0 :   return !!config->firedancer.vinyl.enabled;
      12           0 : }
      13             : 
      14             : static void
      15           0 : init( config_t const * config ) {
      16           0 :   if( FD_UNLIKELY( -1==fd_file_util_mkdir_all( config->paths.accounts, config->uid, config->gid, 0 ) ) ) {
      17           0 :     FD_LOG_ERR(( "fd_file_util_mkdir_all(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
      18           0 :   }
      19             : 
      20           0 :   int vinyl_fd = open( config->paths.accounts, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, S_IRUSR|S_IWUSR );
      21           0 :   if( FD_UNLIKELY( vinyl_fd<0 ) ) {
      22           0 :     FD_LOG_ERR(( "open(`%s`,O_RDWR|O_CREAT|O_CLOEXEC,S_IRUSR|S_IWUSR) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
      23           0 :   }
      24             : 
      25           0 :   if( FD_UNLIKELY( fchown( vinyl_fd, config->uid, config->gid )<0 ) ) {
      26           0 :     FD_LOG_ERR(( "chown(`%s`,%u:%u) failed (%i-%s)", config->paths.accounts, config->uid, config->gid, errno, fd_io_strerror( errno ) ));
      27           0 :   }
      28             : 
      29           0 :   if( FD_UNLIKELY( fchmod( vinyl_fd, S_IRUSR|S_IWUSR )<0 ) ) {
      30           0 :     FD_LOG_ERR(( "chmod(`%s`,S_IRUSR|S_IWUSR) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
      31           0 :   }
      32             : 
      33           0 :   ulong bstream_sz = config->firedancer.vinyl.file_size_gib<<30;
      34           0 :   if( FD_UNLIKELY( 0!=ftruncate( vinyl_fd, (long)bstream_sz ) ) ) {
      35           0 :     FD_LOG_ERR(( "ftruncate(`%s`,%lu bytes) failed (%i-%s)", config->paths.accounts, bstream_sz, errno, fd_io_strerror( errno ) ));
      36           0 :   }
      37             : 
      38           0 :   if( FD_UNLIKELY( close( vinyl_fd )<0 ) ) {
      39           0 :     FD_LOG_ERR(( "close(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
      40           0 :   }
      41           0 : }
      42             : 
      43             : static int
      44             : fini( config_t const * config,
      45           0 :       int              pre_init ) {
      46           0 :   (void)pre_init;
      47           0 :   if( FD_UNLIKELY( unlink( config->paths.accounts )<0 ) ) {
      48           0 :     FD_LOG_ERR(( "unlink(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
      49           0 :   }
      50           0 :   return 1;
      51           0 : }
      52             : 
      53             : static configure_result_t
      54             : check( config_t const * config,
      55           0 :        int              check_type FD_PARAM_UNUSED ) {
      56           0 :   struct stat st;
      57           0 :   if( FD_UNLIKELY( 0!=stat( config->paths.accounts, &st ) ) ) {
      58           0 :     if( errno==ENOENT ) NOT_CONFIGURED( "`%s` does not exist", config->paths.accounts );
      59           0 :     else                NOT_CONFIGURED( "stat(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) );
      60           0 :   }
      61             : 
      62           0 :   ulong bstream_sz = config->firedancer.vinyl.file_size_gib<<30;
      63           0 :   if( FD_UNLIKELY( (ulong)st.st_size!=bstream_sz ) )
      64           0 :     NOT_CONFIGURED( "`%s` needs to be resized (have %lu bytes, want %lu bytes)", config->paths.accounts, (ulong)st.st_size, bstream_sz );
      65             : 
      66           0 :   CHECK( check_file( config->paths.accounts, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
      67           0 :   CONFIGURE_OK();
      68           0 : }
      69             : 
      70             : configure_stage_t fd_cfg_stage_vinyl = {
      71             :   .name    = "vinyl",
      72             :   .enabled = enabled,
      73             :   .init    = init,
      74             :   .fini    = fini,
      75             :   .check   = check,
      76             : };

Generated by: LCOV version 1.14