group/pintos/src/filesys/filesys.c
/* Deletes the file named NAME.
   Returns true if successful, false on failure.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
Deletes the file named NAME.
Returns true if successful, false on failure.
Fails if no file named NAME exists,
or if an internal memory allocation fails.
Deletes the file named NAME . Returns true if successful false on failure . Fails if no file named NAME exists or if an internal memory allocation fails .
bool
filesys_remove (const char *path)
{
    char fname[NAME_MAX];
    char *buff = malloc(sizeof(char) * PATH_MAX);
    char *dir_path = malloc(sizeof(char) * PATH_MAX);
    struct dir *dir = NULL;
    bool success = false;
    memset(buff, 0, sizeof(char) * PATH_MAX);
    memset(dir_path, 0, sizeof(char) * PATH_MAX);
    memset(fname, 0, NAME_MAX);
    memcpy(buff, path, strlen(path));
    to_abs(buff);
    if (simplify_path(buff))
    {
        memcpy(dir_path, buff, strlen(buff));
        if (to_dir_path(dir_path)
                && (dir = get_dir_by_path(dir_path)) != NULL) {
            path_basename(buff, fname);
            success = dir_remove(dir, fname);
        }
    }
    dir_close(dir);
    free(dir_path);
    free(buff);
    return success;
}
bool filesys_remove ( const char * path ) { char fname [ NAME_MAX ] ; char * buff = malloc ( sizeof ( char ) * PATH_MAX ) ; char * dir_path = malloc ( sizeof ( char ) * PATH_MAX ) ; struct dir * dir = NULL ; bool success = false ; memset ( buff , 0 , sizeof ( char ) * PATH_MAX ) ; memset ( dir_path , 0 , sizeof ( char ) * PATH_MAX ) ; memset ( fname , 0 , NAME_MAX ) ; memcpy ( buff , path , strlen ( path ) ) ; to_abs ( buff ) ; if ( simplify_path ( buff ) ) { memcpy ( dir_path , buff , strlen ( buff ) ) ; if ( to_dir_path ( dir_path ) && ( dir = get_dir_by_path ( dir_path ) ) != NULL ) { path_basename ( buff , fname ) ; success = dir_remove ( dir , fname ) ; } } dir_close ( dir ) ; free ( dir_path ) ; free ( buff ) ; return success ; }
Deletes the file named NAME.
Deletes the file named NAME .
// struct dir *dir = dir_open_root (); // bool success = dir != NULL && dir_remove (dir, name); // dir_close (dir); // return success;