lib/fatfs_glue.c
/*
 * emit_vfs_node - creates a new node in the virtual file system for a FS object
 *
 * @mount_path - the readable location where we mount the file system
 * @name       - the file name with the path relative to this file system
 * @node_type  - the type of the VFS object (regular file or dir)
 *
 */
creates a new node in the virtual file system for a FS object
@mount_path - the readable location where we mount the file system
@name       - the file name with the path relative to this file system
@node_type  - the type of the VFS object (regular file or dir)
creates a new node in the virtual file system for a FS object @mount_path - the readable location where we mount the file system @name - the file name with the path relative to this file system @node_type - the type of the VFS object ( regular file or dir )
static int emit_vfs_node(const char *mount_path, const char *name,
                         enum vfs_node_type node_type)
{
  size_t mnt_path_len = strlen(mount_path);
  size_t name_len = strlen(name);
  size_t path_len = strlen(mount_path) + strlen(name) + 2;
  char *path = calloc(1, path_len);
  if (path == NULL) {
    return -ENOMEM;
  }
  int j = 0;
  for (int i = 0; i < mnt_path_len; i++) {
    path[j] = mount_path[i];
    if (mount_path[i] == '/' && j > 0 && path[j - 1] == '/') {
      continue;
    }
    j++;
  }
  if (path[j] == '\0') {
    path[j] = '/';
  } else if (path[j] != '/') {
    path[++j] = '/';
  } 
  for (int i = 0; i < name_len; i++) {
    path[j] = name[i];
    if (name[i] == '/' && j > 0 && path[j - 1] == '/') {
      continue;
    }
    j++;
  }
  int ret = vfs_register_node(path,
                              strlen(path),
                              &g_fs_ops,
                              node_type,
                              path);
  printf("Creating %s: %s status %d\n",
         node_type == VFS_TYPE_DIR ? "DIR" : "FILE", path, ret);
  return ret;
}
static int emit_vfs_node ( const char * mount_path , const char * name , enum vfs_node_type node_type ) { size_t mnt_path_len = strlen ( mount_path ) ; size_t name_len = strlen ( name ) ; size_t path_len = strlen ( mount_path ) + strlen ( name ) + 2 ; char * path = calloc ( 1 , path_len ) ; if ( path == NULL ) { return - ENOMEM ; } int j = 0 ; for ( int i = 0 ; i < mnt_path_len ; i ++ ) { path [ j ] = mount_path [ i ] ; if ( mount_path [ i ] == ' ' && j > 0 && path [ j - 1 ] == ' ' ) { continue ; } j ++ ; } if ( path [ j ] == ' \0 ' ) { path [ j ] = ' ' ; } else if ( path [ j ] != ' ' ) { path [ ++ j ] = ' ' ; } for ( int i = 0 ; i < name_len ; i ++ ) { path [ j ] = name [ i ] ; if ( name [ i ] == ' ' && j > 0 && path [ j - 1 ] == ' ' ) { continue ; } j ++ ; } int ret = vfs_register_node ( path , strlen ( path ) , & g_fs_ops , node_type , path ) ; printf ( " \n " , node_type == VFS_TYPE_DIR ? " " : " " , path , ret ) ; return ret ; }
emit_vfs_node - creates a new node in the virtual file system for a FS object
 @mount_path - the readable location where we mount the file system
 @name       - the file name with the path relative to this file system
 @node_type  - the type of the VFS object (regular file or dir)
emit_vfs_node - creates a new node in the virtual file system for a FS object @mount_path - the readable location where we mount the file system @name - the file name with the path relative to this file system @node_type - the type of the VFS object ( regular file or dir )