summaryrefslogtreecommitdiff
path: root/cpukit/libfs/src/rfs/rtems-rfs-link.c
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2010-03-04 06:36:51 +0000
committerChris Johns <chrisj@rtems.org>2010-03-04 06:36:51 +0000
commit8ec7abb551a23bdf47509189145885a364810006 (patch)
tree7b5fa486b93583479b97f05a51c7370dd0c2d69f /cpukit/libfs/src/rfs/rtems-rfs-link.c
parent3fc1c8db5ecc2658fa06a9b2fe1f43c045450907 (diff)
010-03-04 Chris Johns <chrisj@rtems.org>
* libcsupport/include/rtems/libio.h, libcsupport/src/_rename_r.c: Add a rename file op and have rename use it. * libfs/Makefile.am, libfs/src/dosfs/msdos_rename.c, libfs/src/imfs/imfs_rename.c: New files to support the rename file op. * libfs/src/imfs/imfs.h: Add rename interface. * libfs/src/imfs/imfs_init.c: Add rename handler. * libfs/src/imfs/miniimfs_init.c: Fix up ops struct. * libfs/src/dosfs/msdos.h: Add msdos_rename and remove msdos_file_link. * libfs/src/dosfs/msdos_create.c: Remove the link call. * libfs/src/dosfs/msdos_eval.c: Fix a path parsing bug. * libfs/src/dosfs/msdos_init.c: Add rename handler and clean up the struct naming. * libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-link.h: Change the link call to allow linking of directories if told to and change the unlink to handle unlink directories that are not empty so rename can be supported. * libfs/src/rfs/rtems-rfs-rtems-dir.c: Fix the link/unlink calls. * libfs/src/rfs/rtems-rfs-rtems.c: Add a rename handler. Fix the link/unlink calls. * libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_format.c, libfs/src/dosfs/msdos_misc.c, httpd/asp.c, libfs/src/nfsclient/src/nfs.c: Work around a newlib warning when using the is*() family of calls.
Diffstat (limited to 'cpukit/libfs/src/rfs/rtems-rfs-link.c')
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-link.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-link.c b/cpukit/libfs/src/rfs/rtems-rfs-link.c
index bfbcae66e7..5346eabae3 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-link.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-link.c
@@ -24,13 +24,15 @@
#include <rtems/rfs/rtems-rfs-trace.h>
#include <rtems/rfs/rtems-rfs-dir.h>
#include <rtems/rfs/rtems-rfs-dir-hash.h>
+#include <rtems/rfs/rtems-rfs-link.h>
int
rtems_rfs_link (rtems_rfs_file_system* fs,
const char* name,
int length,
rtems_rfs_ino parent,
- rtems_rfs_ino target)
+ rtems_rfs_ino target,
+ bool link_dir)
{
rtems_rfs_inode_handle parent_inode;
rtems_rfs_inode_handle target_inode;
@@ -50,7 +52,11 @@ rtems_rfs_link (rtems_rfs_file_system* fs,
if (rc)
return rc;
- if (S_ISDIR (rtems_rfs_inode_get_mode (&target_inode)))
+ /*
+ * If the target inode is a directory and we cannot link directories
+ * return a not supported error code.
+ */
+ if (!link_dir && S_ISDIR (rtems_rfs_inode_get_mode (&target_inode)))
{
rtems_rfs_inode_close (fs, &target_inode);
return ENOTSUP;
@@ -99,11 +105,12 @@ rtems_rfs_unlink (rtems_rfs_file_system* fs,
rtems_rfs_ino parent,
rtems_rfs_ino target,
uint32_t doff,
- bool dir)
+ rtems_rfs_unlink_dir dir_mode)
{
rtems_rfs_inode_handle parent_inode;
rtems_rfs_inode_handle target_inode;
uint16_t links;
+ bool dir;
int rc;
if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
@@ -112,29 +119,35 @@ rtems_rfs_unlink (rtems_rfs_file_system* fs,
rc = rtems_rfs_inode_open (fs, target, &target_inode, true);
if (rc)
return rc;
-
+
+ /*
+ * If a directory process the unlink mode.
+ */
+
+ dir = RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&target_inode));
if (dir)
{
- rc = rtems_rfs_dir_empty (fs, &target_inode);
- if (rc > 0)
- {
- if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
- printf ("rtems-rfs: dir-empty: %d: %s\n", rc, strerror (rc));
- rtems_rfs_inode_close (fs, &target_inode);
- return rc;
- }
- }
- else
- {
- /*
- * Directories not allowed and the target is a directory.
- */
- if (RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&target_inode)))
+ switch (dir_mode)
{
- if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
- printf ("rtems-rfs: link is a directory\n");
- rtems_rfs_inode_close (fs, &target_inode);
- return EISDIR;
+ case rtems_rfs_unlink_dir_denied:
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link is a directory\n");
+ rtems_rfs_inode_close (fs, &target_inode);
+ return EISDIR;
+
+ case rtems_rfs_unlink_dir_if_empty:
+ rc = rtems_rfs_dir_empty (fs, &target_inode);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: dir-empty: %d: %s\n", rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+ break;
+
+ default:
+ break;
}
}