summaryrefslogtreecommitdiff
path: root/cpukit/libfs/src/dosfs/msdos_rmnod.c
blob: 77e280af074819471794758f2c18a8612ad0c0de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * @file
 *
 * @ingroup libfs_msdos MSDOS FileSystem
 *
 * @brief Remove Node from MSDOS Directory
 */

/*
 *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
 *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "msdos.h"

int
msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
            const rtems_filesystem_location_info_t *pathloc)
{
    int                rc = RC_OK;
    msdos_fs_info_t   *fs_info = pathloc->mt_entry->fs_info;
    fat_file_fd_t     *fat_fd = pathloc->node_access;

    if (fat_fd->fat_file_type == FAT_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 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(&fs_info->fat, fat_fd);

    return rc;
}