Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:17

0001 /**
0002  * @file
0003  *
0004  * @ingroup libfs_msdos MSDOS FileSystem
0005  *
0006  * @brief Remove Node from MSDOS Directory
0007  */
0008 
0009 /*
0010  *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
0011  *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
0012  *
0013  *  The license and distribution terms for this file may be
0014  *  found in the file LICENSE in this distribution or at
0015  *  http://www.rtems.org/license/LICENSE.
0016  */
0017 
0018 #ifdef HAVE_CONFIG_H
0019 #include "config.h"
0020 #endif
0021 
0022 #include "msdos.h"
0023 
0024 int
0025 msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
0026             const rtems_filesystem_location_info_t *pathloc)
0027 {
0028     int                rc = RC_OK;
0029     msdos_fs_info_t   *fs_info = pathloc->mt_entry->fs_info;
0030     fat_file_fd_t     *fat_fd = pathloc->node_access;
0031 
0032     if (fat_fd->fat_file_type == FAT_DIRECTORY)
0033     {
0034         bool is_empty = false;
0035 
0036         /*
0037          * You cannot remove a node that still has children
0038          */
0039         rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty);
0040         if (rc != RC_OK)
0041         {
0042             return rc;
0043         }
0044 
0045         if (!is_empty)
0046         {
0047             rtems_set_errno_and_return_minus_one(ENOTEMPTY);
0048         }
0049 
0050         /*
0051          * We deny attempts to delete open directory (if directory is current
0052          * directory we assume it is open one)
0053          */
0054         if (fat_fd->links_num > 1)
0055         {
0056             rtems_set_errno_and_return_minus_one(EBUSY);
0057         }
0058 
0059         /*
0060          * You cannot remove a mountpoint.
0061          * not used - mount() not implemenetd yet.
0062          */
0063     }
0064 
0065     /* mark file removed */
0066     rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos,
0067                                         MSDOS_THIS_DIR_ENTRY_EMPTY);
0068     if (rc != RC_OK)
0069     {
0070         return rc;
0071     }
0072 
0073     fat_file_mark_removed(&fs_info->fat, fat_fd);
0074 
0075     return rc;
0076 }