source: rtems/cpukit/libfs/src/dosfs/msdos_rmnod.c @ c17d0b3

4.11
Last change on this file since c17d0b3 was c17d0b3, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 2, 2012 at 1:44:59 PM

Filesystem: Reject removal of root nodes

Reject the removal of file system instance root nodes in rmdir() and
unlink() and return the EBUSY error status. File system instances can
be removed with unmount(). Remove root node special cases in IMFS,
DOSFS, and RFS.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 *  MSDOS directory handlers implementation
3 *
4 *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
5 *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13  #include "config.h"
14#endif
15
16#include "msdos.h"
17
18int
19msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
20            const rtems_filesystem_location_info_t *pathloc)
21{
22    int                rc = RC_OK;
23    msdos_fs_info_t   *fs_info = pathloc->mt_entry->fs_info;
24    fat_file_fd_t     *fat_fd = pathloc->node_access;
25
26    if (fat_fd->fat_file_type == MSDOS_DIRECTORY)
27    {
28        bool is_empty = false;
29
30        /*
31         * You cannot remove a node that still has children
32         */
33        rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty);
34        if (rc != RC_OK)
35        {
36            return rc;
37        }
38
39        if (!is_empty)
40        {
41            rtems_set_errno_and_return_minus_one(ENOTEMPTY);
42        }
43
44        /*
45         * We deny attempts to delete open directory (if directory is current
46         * directory we assume it is open one)
47         */
48        if (fat_fd->links_num > 1)
49        {
50            rtems_set_errno_and_return_minus_one(EBUSY);
51        }
52
53        /*
54         * You cannot remove a mountpoint.
55         * not used - mount() not implemenetd yet.
56         */
57    }
58
59    /* mark file removed */
60    rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos,
61                                        MSDOS_THIS_DIR_ENTRY_EMPTY);
62    if (rc != RC_OK)
63    {
64        return rc;
65    }
66
67    fat_file_mark_removed(&fs_info->fat, fat_fd);
68
69    return rc;
70}
Note: See TracBrowser for help on using the repository browser.