lib/fatfs_glue.c
/*
 * mount_fs - creates the FATFS structure and scan for files and folders
 *
 * @mount - the mount structure
 *
 *  This function scans for files and folders and creates entries in the
 *  Virtual file system for them. It attaches the corresponding operation
 *  pointers (file_ops).
 */
creates the FATFS structure and scan for files and folders
@mount - the mount structure

This function scans for files and folders and creates entries in the
Virtual file system for them. It attaches the corresponding operation
pointers (file_ops).
creates the FATFS structure and scan for files and folders @mount - the mount structure This function scans for files and folders and creates entries in the Virtual file system for them . It attaches the corresponding operation pointers ( file_ops ) .
static int mount_fs(struct vfs_mount_filesystem_s *mount)
{
  int ret = OK;
  if (g_fatfs != NULL) {
    return -EINVAL;
  }
  g_fatfs = malloc(sizeof(FATFS));
  if (g_fatfs == NULL) {
    return -ENOMEM;
  }
  g_mtd_ops = mount->mtd_ops;
  FRESULT retfs = f_mount(g_fatfs, "", 1);
  if (retfs != FR_OK) {
    ret = -ENOSYS;
    goto free_with_mem;
  }
  char *mnt_path = (char *)mount->mount_path;
  struct vfs_node_s *node = vfs_get_matching_node(mnt_path, strlen(mnt_path));
  if (node == NULL) {
    ret = -ENOSYS;
    goto free_with_mem;
  }
  char *scan_path = calloc(FATFS_MAX_PATH, sizeof(char));
  if (scan_path == NULL) {
    ret = -ENOMEM;
    goto free_with_mem;
  }
  strncpy(scan_path, VFS_PATH_DELIM, 1);
  g_mounted_fs = mount;
  scan_files(scan_path);
  free(scan_path);
  return OK;
free_with_mem:
  free(g_fatfs);
  g_mounted_fs = NULL;
  g_fatfs = NULL;
  return ret;
}
static int mount_fs ( struct vfs_mount_filesystem_s * mount ) { int ret = OK ; if ( g_fatfs != NULL ) { return - EINVAL ; } g_fatfs = malloc ( sizeof ( FATFS ) ) ; if ( g_fatfs == NULL ) { return - ENOMEM ; } g_mtd_ops = mount -> mtd_ops ; FRESULT retfs = f_mount ( g_fatfs , " " , 1 ) ; if ( retfs != FR_OK ) { ret = - ENOSYS ; goto free_with_mem ; } char * mnt_path = ( char * ) mount -> mount_path ; struct vfs_node_s * node = vfs_get_matching_node ( mnt_path , strlen ( mnt_path ) ) ; if ( node == NULL ) { ret = - ENOSYS ; goto free_with_mem ; } char * scan_path = calloc ( FATFS_MAX_PATH , sizeof ( char ) ) ; if ( scan_path == NULL ) { ret = - ENOMEM ; goto free_with_mem ; } strncpy ( scan_path , VFS_PATH_DELIM , 1 ) ; g_mounted_fs = mount ; scan_files ( scan_path ) ; free ( scan_path ) ; return OK ; free_with_mem : free ( g_fatfs ) ; g_mounted_fs = NULL ; g_fatfs = NULL ; return ret ; }
mount_fs - creates the FATFS structure and scan for files and folders
 @mount - the mount structure
mount_fs - creates the FATFS structure and scan for files and folders @mount - the mount structure
/* Check for already in use */