group/pintos/src/filesys/directory.c
/* Removes any entry for NAME in DIR.
   Returns true if successful, false on failure,
   which occurs only if there is no file with the given NAME. */
Removes any entry for NAME in DIR.
Returns true if successful, false on failure,
which occurs only if there is no file with the given NAME.
Removes any entry for NAME in DIR . Returns true if successful false on failure which occurs only if there is no file with the given NAME .
bool
dir_remove (struct dir *dir, const char *name)
{
  struct dir_entry e;
  struct inode *inode = NULL;
  bool success = false;
  off_t ofs;
  ASSERT (dir != NULL);
  ASSERT (name != NULL);
  if (!lookup (dir, name, &e, &ofs))
    goto done;
  inode = inode_open (e.inode_sector);
  if (inode == NULL)
    goto done;
  e.in_use = false;
  if (inode_write_at (dir->inode, &e, sizeof e, ofs) != sizeof e)
    goto done;
  if (inode->data.isdir && !dir_isempty(dir_open(inode)))
      goto done;
  inode_remove (inode);
  success = true;
 done:
  inode_close (inode);
  return success;
}
bool dir_remove ( struct dir * dir , const char * name ) { struct dir_entry e ; struct inode * inode = NULL ; bool success = false ; off_t ofs ; ASSERT ( dir != NULL ) ; ASSERT ( name != NULL ) ; if ( ! lookup ( dir , name , & e , & ofs ) ) goto done ; inode = inode_open ( e . inode_sector ) ; if ( inode == NULL ) goto done ; e . in_use = false ; if ( inode_write_at ( dir -> inode , & e , sizeof e , ofs ) != sizeof e ) goto done ; if ( inode -> data . isdir && ! dir_isempty ( dir_open ( inode ) ) ) goto done ; inode_remove ( inode ) ; success = true ; done : inode_close ( inode ) ; return success ; }
Removes any entry for NAME in DIR.
Removes any entry for NAME in DIR .
/* Find directory entry. */ /* Open inode. */ /* Erase directory entry. */ /* Remove inode. */