1 | /* |
---|
2 | * Routine to rename a MSDOS filesystem node |
---|
3 | * |
---|
4 | * Copyright (C) 2010 Chris Johns <chrisj@rtems.org> |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | * |
---|
10 | * @(#) $Id$ |
---|
11 | * |
---|
12 | */ |
---|
13 | #if HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <errno.h> |
---|
18 | #include <stdio.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <string.h> |
---|
21 | #include <rtems/libio_.h> |
---|
22 | #include <time.h> |
---|
23 | |
---|
24 | #include "fat.h" |
---|
25 | #include "fat_fat_operations.h" |
---|
26 | #include "fat_file.h" |
---|
27 | |
---|
28 | #include "msdos.h" |
---|
29 | |
---|
30 | /* msdos_rename -- |
---|
31 | * Rename the node by removing the exitsing directory entry and creating a |
---|
32 | * new one. |
---|
33 | * |
---|
34 | * PARAMETERS: |
---|
35 | * old_parent_loc - node description for the "old parent" node |
---|
36 | * old_loc - node description for the "old" node |
---|
37 | * new_parent_loc - node description for the "parent" node |
---|
38 | * name - name of new node |
---|
39 | * |
---|
40 | * RETURNS: |
---|
41 | * RC_OK on success, or -1 if error occured (errno set appropriately) |
---|
42 | */ |
---|
43 | int |
---|
44 | msdos_rename(rtems_filesystem_location_info_t *old_parent_loc, |
---|
45 | rtems_filesystem_location_info_t *old_loc, |
---|
46 | rtems_filesystem_location_info_t *new_parent_loc, |
---|
47 | const char *new_name) |
---|
48 | { |
---|
49 | int rc = RC_OK; |
---|
50 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
51 | msdos_fs_info_t *fs_info = new_parent_loc->mt_entry->fs_info; |
---|
52 | fat_file_fd_t *old_fat_fd = old_loc->node_access; |
---|
53 | const char *token; |
---|
54 | int len; |
---|
55 | |
---|
56 | /* |
---|
57 | * check spelling and format new node name |
---|
58 | */ |
---|
59 | if (MSDOS_NAME != msdos_get_token(new_name, strlen(new_name), &token, &len)) { |
---|
60 | rtems_set_errno_and_return_minus_one(ENAMETOOLONG); |
---|
61 | } |
---|
62 | /* |
---|
63 | * lock volume |
---|
64 | */ |
---|
65 | sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, |
---|
66 | MSDOS_VOLUME_SEMAPHORE_TIMEOUT); |
---|
67 | if (sc != RTEMS_SUCCESSFUL) |
---|
68 | rtems_set_errno_and_return_minus_one(EIO); |
---|
69 | |
---|
70 | /* |
---|
71 | * create new directory entry as "hard link", copying relevant info from |
---|
72 | * existing file |
---|
73 | */ |
---|
74 | rc = msdos_creat_node(new_parent_loc, |
---|
75 | MSDOS_HARD_LINK,new_name,len,S_IFREG, |
---|
76 | old_fat_fd); |
---|
77 | if (rc != RC_OK) |
---|
78 | { |
---|
79 | rtems_semaphore_release(fs_info->vol_sema); |
---|
80 | return rc; |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * mark file removed |
---|
85 | */ |
---|
86 | rc = msdos_set_first_char4file_name(old_loc->mt_entry, |
---|
87 | &old_fat_fd->dir_pos, |
---|
88 | MSDOS_THIS_DIR_ENTRY_EMPTY); |
---|
89 | |
---|
90 | rtems_semaphore_release(fs_info->vol_sema); |
---|
91 | return rc; |
---|
92 | } |
---|