utils/unistd.c
/**************************************************************************
 * Name:
 *  unlink
 *
 * Description:
 *  Remove the file from the filesystem.
 *
 * Input Parameters:
 *  path - the path of the file that we want to remove
 *
 * Return Value:
 *  Zero on success otherwise a negative value.
 *
 *************************************************************************/
unlink

Remove the file from the filesystem.

Input Parameters:
path - the path of the file that we want to remove

Return Value:
Zero on success otherwise a negative value.
unlink Remove the file from the filesystem . Input Parameters : path - the path of the file that we want to remove Return Value : Zero on success otherwise a negative value .
int unlink(const char *path)
{
  int ret = 0;
  irq_state_t irq_state = cpu_disableint();
  struct vfs_node_s *node = vfs_get_matching_node(path, strlen(path));
  cpu_enableint(irq_state);
  if (node == NULL) {
    return -EINVAL;
  }
  if (!node->ops || !node->ops->unlink) {
    return -ENOSYS;
  }
  sem_wait(&node->lock);
  if (node->open_count > 0) {
    printf("Node %s opened %d times\n", node->name, node->open_count);
    sem_post(&node->lock);
    return -ENFILE;
  }
  sem_post(&node->lock);
  if (node->node_type == VFS_TYPE_FILE) {
    ret = unlink_node(path, node);
  } else if (node->node_type == VFS_TYPE_DIR) {
    if (node->num_children > 0) {
      return -ENOTEMPTY;
    }
    ret = unlink_node(path, node);
  } else {
    return -EOPNOTSUPP;
  }
  return ret;
}
int unlink ( const char * path ) { int ret = 0 ; irq_state_t irq_state = cpu_disableint ( ) ; struct vfs_node_s * node = vfs_get_matching_node ( path , strlen ( path ) ) ; cpu_enableint ( irq_state ) ; if ( node == NULL ) { return - EINVAL ; } if ( ! node -> ops || ! node -> ops -> unlink ) { return - ENOSYS ; } sem_wait ( & node -> lock ) ; if ( node -> open_count > 0 ) { printf ( " \n " , node -> name , node -> open_count ) ; sem_post ( & node -> lock ) ; return - ENFILE ; } sem_post ( & node -> lock ) ; if ( node -> node_type == VFS_TYPE_FILE ) { ret = unlink_node ( path , node ) ; } else if ( node -> node_type == VFS_TYPE_DIR ) { if ( node -> num_children > 0 ) { return - ENOTEMPTY ; } ret = unlink_node ( path , node ) ; } else { return - EOPNOTSUPP ; } return ret ; }
Name:
  unlink
Name : unlink
/* If the directory has entries don't remove it */