Esempio n. 1
0
static void test(const char *rda, const char *mnt, const char *file)
{
  static const msdos_format_request_param_t rqdata = {
    .quick_format = true,
    .sync_device = true
  };

  rtems_status_code sc;
  int disk_fd;
  int rv;

  sc = rtems_disk_io_initialize();
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  disk_fd = open(rda, O_RDWR);
  rtems_test_assert(disk_fd >= 0);

  rv = msdos_format(rda, &rqdata);
  rtems_test_assert(rv == 0);

  rv = mount_and_make_target_path(
    rda,
    mnt,
    RTEMS_FILESYSTEM_TYPE_DOSFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL
  );
  rtems_test_assert(rv == 0);

  create_file(file);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);

  write_to_file(file, false);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);
  check_file_size(file, 0);

  write_to_file(file, true);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);
  check_file_size(file, 1);

  rv = unmount(mnt);
  rtems_test_assert(rv == 0);

  rv = close(disk_fd);
  rtems_test_assert(rv == 0);
}

static void Init(rtems_task_argument arg)
{
  puts("\n\n*** TEST FSDOSFSSYNC 1 ***");

  test("/dev/rda", "/mnt", "/mnt/file");

  puts("*** END OF TEST FSDOSFSSYNC 1 ***");

  rtems_test_exit(0);
}
Esempio n. 2
0
static void initialize_ftpfs(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  int rv = 0;
  struct timeval to = {
    .tv_sec = 10,
    .tv_usec = 0
  };
  const char *target = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;

  rv = mount_and_make_target_path(
    NULL,
    target,
    RTEMS_FILESYSTEM_TYPE_FTPFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL
  );
  rtems_test_assert(rv == 0);

  sc = rtems_ftpfs_set_verbose(target, true);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_ftpfs_set_timeout(target, &to);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}

static void change_self_priority(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_task_priority cur = 0;

  sc = rtems_task_set_priority(RTEMS_SUCCESSFUL, 110, &cur);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Esempio n. 3
0
static void compare_image(
  const char                      *mount_dir,
  const char                      *dev,
  const rtems_dosfs_mount_options *mount_opts )
{
  #define MOUNT_DIR2 "/mnt2"
  int                       rc;

  rc = mount_and_make_target_path(
    dev,
    MOUNT_DIR2,
    RTEMS_FILESYSTEM_TYPE_DOSFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    mount_opts );
  rtems_test_assert( rc == 0 );

  compare_directories(mount_dir, MOUNT_DIR2);

  rc = unmount( MOUNT_DIR2 );
  rtems_test_assert( rc == 0 );

  rc = rmdir( MOUNT_DIR2 );
  rtems_test_assert( rc == 0 );

}
Esempio n. 4
0
static int test_rfs_mount_handler(
  const char *disk_path,
  const char *mount_path,
  void *arg
)
{
  return mount_and_make_target_path(
    disk_path,
    mount_path,
    RTEMS_FILESYSTEM_TYPE_RFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL
  );
}
Esempio n. 5
0
/*
 * Test the compatibility with a genuine MS Windows FAT file system.
 */
static void test_compatibility( void )
{
  int                       rc;
  rtems_status_code         sc;
  dev_t                     dev;
  char                      diskpath[] = "/dev/ramdisk1";
  rtems_dosfs_mount_options mount_opts;
  rtems_device_major_number major;
  FILE                     *fp;
  int                       buffer;
  unsigned int              index_file = 0;
  unsigned int              index_char;
  unsigned int              offset;
  char                      content_buf[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
                                        + 1];
  char                      file_path[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
                                      + 1];
  DIR                      *dir_stream;
  struct dirent            *dp;


  mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" );
  rtems_test_assert( mount_opts.converter != NULL );

  sc = rtems_io_register_driver( 0, &ramdisk_ops, &major );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  dev = rtems_filesystem_make_dev_t( major, 1 );

  sc  = rtems_disk_create_phys(
    dev,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    &disk_image,
    diskpath );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  rc = mount_and_make_target_path(
    diskpath,
    MOUNT_DIR,
    RTEMS_FILESYSTEM_TYPE_DOSFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    &mount_opts );
  rtems_test_assert( rc == 0 );

  dir_stream = opendir( MOUNT_DIR );
  rtems_test_assert( dir_stream != NULL );

  dp = readdir( dir_stream );
  rtems_test_assert( dp != NULL );

  while ( dp != NULL ) {
    index_char = 0;

    size_t len = strlen( filenames[index_file] );

    if ( filenames[index_file][len - 1] == '.' )
      rtems_test_assert( ( len - 1 ) == dp->d_namlen );
    else
      rtems_test_assert( len == dp->d_namlen );

    rtems_test_assert( 0
                       == memcmp( &filenames[index_file][0], &dp->d_name[0],
                                  dp->d_namlen ) );

    snprintf( file_path, sizeof( file_path ), "%s/%s", MOUNT_DIR,
              filenames[index_file] );
    fp = fopen( file_path, "r" );
    rtems_test_assert( fp != NULL );

    /* These files should contain their own file names. */
    while ( ( buffer = fgetc( fp ) ) != EOF ) {
      content_buf[index_char] = buffer;
      ++index_char;
    }

    if ( 0 == strncmp( content_buf, UTF8_BOM, UTF8_BOM_SIZE ) )
      offset = UTF8_BOM_SIZE;
    else
      offset = 0;

    rtems_test_assert( 0
                       == memcmp( filenames[index_file],
                                  &content_buf[offset],
                                  index_char - offset ) );

    rc = fclose( fp );
    rtems_test_assert( rc == 0 );

    ++index_file;
    dp = readdir( dir_stream );
  }

  rtems_test_assert( index_file == FILES_FILENAMES_NUMBER_OF );

  rc = closedir( dir_stream );
  rtems_test_assert( rc == 0 );

  rc = unmount( MOUNT_DIR );
  rtems_test_assert( rc == 0 );
}
Esempio n. 6
0
static void
initialize_remote_filesystem(char **argv, int hasLocalFilesystem)
{
#ifdef OMIT_NFS_SUPPORT
    printf ("***** Initializing TFTP *****\n");
#if __RTEMS_MAJOR__>4 || \
   (__RTEMS_MAJOR__==4 && __RTEMS_MINOR__>9) || \
   (__RTEMS_MAJOR__==4 && __RTEMS_MINOR__==9 && __RTEMS_REVISION__==99)
    mount_and_make_target_path(NULL,
                               "/TFTP",
                               RTEMS_FILESYSTEM_TYPE_TFTPFS,
                               RTEMS_FILESYSTEM_READ_WRITE,
                               NULL);
#else
    rtems_bsdnet_initialize_tftp_filesystem ();
#endif
    if (!hasLocalFilesystem) {
        char *path;
        int pathsize = 200;
        int l;

        path = mustMalloc(pathsize, "Command path name ");
        strcpy (path, "/TFTP/BOOTP_HOST/epics/");
        l = strlen (path);
        if (gethostname (&path[l], pathsize - l - 10) || (path[l] == '\0'))
        {
            LogFatal ("Can't get host name");
        }
        strcat (path, "/st.cmd");
        argv[1] = path;
    }
#else
    char *server_name;
    char *server_path;
    char *mount_point;
    char *cp;
    int l = 0;

    printf ("***** Initializing NFS *****\n");
    NFS_INIT
    if (env_nfsServer && env_nfsPath && env_nfsMountPoint) {
        server_name = env_nfsServer;
        server_path = env_nfsPath;
        mount_point = env_nfsMountPoint;
        cp = mount_point;
        while ((cp = strchr(cp+1, '/')) != NULL) {
            *cp = '\0';
            if ((mkdir (mount_point, 0755) != 0)
             && (errno != EEXIST))
                LogFatal("Can't create directory \"%s\": %s.\n",
                                                mount_point, strerror(errno));
            *cp = '/';
        }
        argv[1] = rtems_bsdnet_bootp_cmdline;
    }
    else if (hasLocalFilesystem) {
        return;
    }
    else {
        /*
         * Use first component of nvram/bootp command line pathname
         * to set up initial NFS mount.  A "/tftpboot/" is prepended
         * if the pathname does not begin with a '/'.  This allows
         * NFS and TFTP to have a similar view of the remote system.
         */
        if (rtems_bsdnet_bootp_cmdline[0] == '/')
            cp = rtems_bsdnet_bootp_cmdline + 1;
        else
            cp = rtems_bsdnet_bootp_cmdline;
        cp = strchr(cp, '/');
        if ((cp == NULL)
         || ((l = cp - rtems_bsdnet_bootp_cmdline) == 0))
            LogFatal("\"%s\" is not a valid command pathname.\n", rtems_bsdnet_bootp_cmdline);
        cp = mustMalloc(l + 20, "NFS mount paths");
        server_path = cp;
        server_name = rtems_bsdnet_bootp_server_name;
        if (rtems_bsdnet_bootp_cmdline[0] == '/') {
            mount_point = server_path;
            strncpy(mount_point, rtems_bsdnet_bootp_cmdline, l);
            mount_point[l] = '\0';
            argv[1] = rtems_bsdnet_bootp_cmdline;
            /*
             * Its probably common to embed the mount point in the server 
             * name so, when this is occurring, dont clobber the mount point
             * by appending the first node from the command path. This allows
             * the mount point to be a different path then the server's mount 
             * path.
             *
             * This allows for example a line similar to as follows the DHCP 
             * configuration file.
             *
             * server-name "[email protected]:/vol/vol0/bootRTEMS";
             */
            if ( server_name ) {
                const size_t allocSize = strlen ( server_name ) + 2;
                char * const pServerName = mustMalloc( allocSize, 
                                                        "NFS mount paths");
                char * const pServerPath = mustMalloc ( allocSize, 
                                                        "NFS mount paths");
                const int scanfStatus = sscanf ( 
                                          server_name, 
                                          "%[^:] : / %s",  
                                          pServerName, 
                                          pServerPath + 1u );
                if ( scanfStatus ==  2 ) {
                    pServerPath[0u]= '/';
                    server_name = pServerName;
                    server_path = pServerPath;
                }
                else {
                    free ( pServerName );
                    free ( pServerPath );
                }
            }
        }
        else {
            char *abspath = mustMalloc(strlen(rtems_bsdnet_bootp_cmdline)+2,"Absolute command path");
            strcpy(server_path, "/tftpboot/");
            mount_point = server_path + strlen(server_path);
            strncpy(mount_point, rtems_bsdnet_bootp_cmdline, l);
            mount_point[l] = '\0';
            mount_point--;
            strcpy(abspath, "/");
            strcat(abspath, rtems_bsdnet_bootp_cmdline);
            argv[1] = abspath;
        }
    }
    nfsMount(server_name, server_path, mount_point);
#endif
}