fs/vfs/fs_unlink.c
int do_unlink(int dirfd, const char *pathname)
{
  struct Vnode *vnode = NULL;
  int ret;
  char *name = NULL;
  char *fullpath = NULL;
  char *relativepath = NULL;

  /* Get relative path by dirfd*/
  ret = get_path_from_fd(dirfd, &relativepath);
  if (ret < 0)
    {
      goto errout;
    }

  ret = vfs_normalize_path((const char *)relativepath, pathname, &fullpath);
  if (relativepath)
    {
      free(relativepath);
    }

  if (ret < 0)
    {
      goto errout;
    }

  VnodeHold();
  ret = VnodeLookup(fullpath, &vnode, 0);
  if (ret < 0)
    {
      goto errout_with_lock;
    }

  ret = check_target(vnode);
  if (ret < 0)
    {
      goto errout_with_lock;
    }
  name = strrchr(fullpath, '/') + 1;

  if (vnode && vnode->vop && vnode->vop->Unlink)
    {
      ret = vnode->vop->Unlink(vnode->parent, vnode, name);
    }
  else if (vnode && vnode->fop && vnode->fop->unlink)
    {
      ret = vnode->fop->unlink(vnode);
      if (ret == OK) {
        goto done;
      }
    }
  else
    {
      ret = -ENOSYS;
    }

  if (ret != OK)
    {
      goto errout_with_lock;
    }

  VnodeFree(vnode);

done:
  VnodeDrop();
#ifdef LOSCFG_KERNEL_VM
  (void)remove_mapping(fullpath);
#endif
  /* Successfully unlinked */

  free(fullpath);
  return OK;

errout_with_lock:
  VnodeDrop();

errout:
  if (fullpath)
    {
      free(fullpath);
    }
  set_errno(-ret);

  return VFS_ERROR;
}
/****************************************************************************
 * Name: do_unlink
 *
 * Description:  Remove a file managed a mountpoint
 *
 ****************************************************************************/
do_unlink
Description:  Remove a file managed a mountpoint
do_unlink Description : Remove a file managed a mountpoint
int do_unlink(int dirfd, const char *pathname)
{
  struct Vnode *vnode = NULL;
  int ret;
  char *name = NULL;
  char *fullpath = NULL;
  char *relativepath = NULL;
  ret = get_path_from_fd(dirfd, &relativepath);
  if (ret < 0)
    {
      goto errout;
    }
  ret = vfs_normalize_path((const char *)relativepath, pathname, &fullpath);
  if (relativepath)
    {
      free(relativepath);
    }
  if (ret < 0)
    {
      goto errout;
    }
  VnodeHold();
  ret = VnodeLookup(fullpath, &vnode, 0);
  if (ret < 0)
    {
      goto errout_with_lock;
    }
  ret = check_target(vnode);
  if (ret < 0)
    {
      goto errout_with_lock;
    }
  name = strrchr(fullpath, '/') + 1;
  if (vnode && vnode->vop && vnode->vop->Unlink)
    {
      ret = vnode->vop->Unlink(vnode->parent, vnode, name);
    }
  else if (vnode && vnode->fop && vnode->fop->unlink)
    {
      ret = vnode->fop->unlink(vnode);
      if (ret == OK) {
        goto done;
      }
    }
  else
    {
      ret = -ENOSYS;
    }
  if (ret != OK)
    {
      goto errout_with_lock;
    }
  VnodeFree(vnode);
done:
  VnodeDrop();
#ifdef LOSCFG_KERNEL_VM
  (void)remove_mapping(fullpath);
#endif
  free(fullpath);
  return OK;
errout_with_lock:
  VnodeDrop();
errout:
  if (fullpath)
    {
      free(fullpath);
    }
  set_errno(-ret);
  return VFS_ERROR;
}
int do_unlink ( int dirfd , const char * pathname ) { struct Vnode * vnode = NULL ; int ret ; char * name = NULL ; char * fullpath = NULL ; char * relativepath = NULL ; ret = get_path_from_fd ( dirfd , & relativepath ) ; if ( ret < 0 ) { goto errout ; } ret = vfs_normalize_path ( ( const char * ) relativepath , pathname , & fullpath ) ; if ( relativepath ) { free ( relativepath ) ; } if ( ret < 0 ) { goto errout ; } VnodeHold ( ) ; ret = VnodeLookup ( fullpath , & vnode , 0 ) ; if ( ret < 0 ) { goto errout_with_lock ; } ret = check_target ( vnode ) ; if ( ret < 0 ) { goto errout_with_lock ; } name = strrchr ( fullpath , ' ' ) + 1 ; if ( vnode && vnode -> vop && vnode -> vop -> Unlink ) { ret = vnode -> vop -> Unlink ( vnode -> parent , vnode , name ) ; } else if ( vnode && vnode -> fop && vnode -> fop -> unlink ) { ret = vnode -> fop -> unlink ( vnode ) ; if ( ret == OK ) { goto done ; } } else { ret = - ENOSYS ; } if ( ret != OK ) { goto errout_with_lock ; } VnodeFree ( vnode ) ; done : VnodeDrop ( ) ; #ifdef LOSCFG_KERNEL_VM ( void ) remove_mapping ( fullpath ) ; #endif free ( fullpath ) ; return OK ; errout_with_lock : VnodeDrop ( ) ; errout : if ( fullpath ) { free ( fullpath ) ; } set_errno ( - ret ) ; return VFS_ERROR ; }
Name: do_unlink
 Description:  Remove a file managed a mountpoint
Name : do_unlink Description : Remove a file managed a mountpoint
/* Get relative path by dirfd*/ /* Successfully unlinked */