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