summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/dosfs/msdos_rmnod.c
blob: 56431b2133d71a9f825c6275abd58d51cf69cc2c (plain) (blame)
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
77
78
79
/*
 *  MSDOS directory handlers implementation
 *
 *  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.com/license/LICENSE.
 *
 *  @(#) $Id$
 */

#if 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;
    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;
}