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 | |
---|
18 | int |
---|
19 | msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc, |
---|
20 | const rtems_filesystem_location_info_t *pathloc) |
---|
21 | { |
---|
22 | int rc = RC_OK; |
---|
23 | fat_file_fd_t *fat_fd = pathloc->node_access; |
---|
24 | |
---|
25 | if (fat_fd->fat_file_type == MSDOS_DIRECTORY) |
---|
26 | { |
---|
27 | bool is_empty = false; |
---|
28 | |
---|
29 | /* |
---|
30 | * You cannot remove a node that still has children |
---|
31 | */ |
---|
32 | rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty); |
---|
33 | if (rc != RC_OK) |
---|
34 | { |
---|
35 | return rc; |
---|
36 | } |
---|
37 | |
---|
38 | if (!is_empty) |
---|
39 | { |
---|
40 | rtems_set_errno_and_return_minus_one(ENOTEMPTY); |
---|
41 | } |
---|
42 | |
---|
43 | /* |
---|
44 | * We deny attempts to delete open directory (if directory is current |
---|
45 | * directory we assume it is open one) |
---|
46 | */ |
---|
47 | if (fat_fd->links_num > 1) |
---|
48 | { |
---|
49 | rtems_set_errno_and_return_minus_one(EBUSY); |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | * You cannot remove the file system root node. |
---|
54 | */ |
---|
55 | if (rtems_filesystem_location_is_root(pathloc)) |
---|
56 | { |
---|
57 | rtems_set_errno_and_return_minus_one(EBUSY); |
---|
58 | } |
---|
59 | |
---|
60 | /* |
---|
61 | * You cannot remove a mountpoint. |
---|
62 | * not used - mount() not implemenetd yet. |
---|
63 | */ |
---|
64 | } |
---|
65 | |
---|
66 | /* mark file removed */ |
---|
67 | rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos, |
---|
68 | MSDOS_THIS_DIR_ENTRY_EMPTY); |
---|
69 | if (rc != RC_OK) |
---|
70 | { |
---|
71 | return rc; |
---|
72 | } |
---|
73 | |
---|
74 | fat_file_mark_removed(pathloc->mt_entry, fat_fd); |
---|
75 | |
---|
76 | return rc; |
---|
77 | } |
---|