Back to home page

LXR

 
 

    


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

0001 /**
0002  * @file
0003  *
0004  * @ingroup libfs_msdos MSDOS FileSystem
0005  *
0006  * @brief Rename a MSDOS FileSystem Node
0007  */
0008 
0009 /*
0010  * Copyright (C) 2010 Chris Johns <chrisj@rtems.org>
0011  *
0012  * The license and distribution terms for this file may be
0013  * found in the file LICENSE in this distribution or at
0014  * http://www.rtems.org/license/LICENSE.
0015  *
0016  */
0017 #ifdef HAVE_CONFIG_H
0018 #include "config.h"
0019 #endif
0020 
0021 #include <errno.h>
0022 #include <stdio.h>
0023 #include <stdlib.h>
0024 #include <string.h>
0025 #include <rtems/libio_.h>
0026 #include <time.h>
0027 
0028 #include "fat.h"
0029 #include "fat_fat_operations.h"
0030 #include "fat_file.h"
0031 
0032 #include "msdos.h"
0033 
0034 /* msdos_rename --
0035  *     Rename the node by removing the exitsing directory entry and creating a
0036  *     new one.
0037  */
0038 int
0039 msdos_rename(
0040     const rtems_filesystem_location_info_t *old_parent_loc,
0041     const rtems_filesystem_location_info_t *old_loc,
0042     const rtems_filesystem_location_info_t *new_parent_loc,
0043     const char *new_name,
0044     size_t new_namelen
0045 )
0046 {
0047     int                rc = RC_OK;
0048     fat_file_fd_t     *old_fat_fd  = old_loc->node_access;
0049     fat_dir_pos_t      old_pos = old_fat_fd->dir_pos;
0050 
0051     /*
0052      * create new directory entry as "hard link", copying relevant info from
0053      * existing file
0054      */
0055     rc = msdos_creat_node(new_parent_loc,
0056                           FAT_HARD_LINK,new_name,new_namelen,S_IFREG,
0057                           old_fat_fd);
0058     if (rc != RC_OK)
0059     {
0060         return rc;
0061     }
0062 
0063     /*
0064      * mark file removed
0065      */
0066     rc = msdos_set_first_char4file_name(old_loc->mt_entry,
0067                                         &old_pos,
0068                                         MSDOS_THIS_DIR_ENTRY_EMPTY);
0069 
0070     return rc;
0071 }