Example #1
0
/* msdos_file_rmnod --
 *     Remove node associated with a file - set up first name character to
 *     predefined value(and write it to the disk), and mark fat-file which
 *     correspondes to the file as "removed"
 *
 * PARAMETERS:
 *     pathloc - node description
 *
 * RETURNS:
 *     RC_OK on success, or -1 if error occured (errno set appropriately)
 */
int
msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc,
                 rtems_filesystem_location_info_t *pathloc)
{
    int                rc = RC_OK;
    rtems_status_code  sc = RTEMS_SUCCESSFUL;
    msdos_fs_info_t   *fs_info = pathloc->mt_entry->fs_info;
    fat_file_fd_t     *fat_fd = pathloc->node_access;

    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    if (sc != RTEMS_SUCCESSFUL)
        rtems_set_errno_and_return_minus_one(EIO);

    /* mark file removed */
    rc = msdos_set_first_char4file_name(pathloc->mt_entry,
                                        &fat_fd->dir_pos,
                                        MSDOS_THIS_DIR_ENTRY_EMPTY);
    if (rc != RC_OK)
    {
        rtems_semaphore_release(fs_info->vol_sema);
        return rc;
    }

    fat_file_mark_removed(pathloc->mt_entry, fat_fd);

    rtems_semaphore_release(fs_info->vol_sema);
    return RC_OK;
}
Example #2
0
int
msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
            const rtems_filesystem_location_info_t *pathloc)
{
    int                rc = RC_OK;
    fat_file_fd_t     *fat_fd = pathloc->node_access;

    if (fat_fd->fat_file_type == MSDOS_DIRECTORY)
    {
        bool is_empty = false;

        /*
         * You cannot remove a node that still has children
         */
        rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty);
        if (rc != RC_OK)
        {
            return rc;
        }

        if (!is_empty)
        {
            rtems_set_errno_and_return_minus_one(ENOTEMPTY);
        }

        /*
         * We deny attempts to delete open directory (if directory is current
         * directory we assume it is open one)
         */
        if (fat_fd->links_num > 1)
        {
            rtems_set_errno_and_return_minus_one(EBUSY);
        }

        /*
         * You cannot remove the file system root node.
         */
        if (rtems_filesystem_location_is_root(pathloc))
        {
            rtems_set_errno_and_return_minus_one(EBUSY);
        }

        /*
         * You cannot remove a mountpoint.
         * not used - mount() not implemenetd yet.
         */
    }

    /* mark file removed */
    rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos,
                                        MSDOS_THIS_DIR_ENTRY_EMPTY);
    if (rc != RC_OK)
    {
        return rc;
    }

    fat_file_mark_removed(pathloc->mt_entry, fat_fd);

    return rc;
}