summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libfs/src/rfs/rtems-rfs-rtems.c')
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems.c180
1 files changed, 101 insertions, 79 deletions
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
index 969f1951a9..f136c15f6f 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
@@ -65,7 +65,7 @@
* @param flags
* @param pathloc
*/
-int
+static int
rtems_rfs_rtems_eval_path (const char* path,
size_t pathlen,
int flags,
@@ -246,7 +246,7 @@ rtems_rfs_rtems_eval_path (const char* path,
* @param name
* @return int
*/
-int
+static int
rtems_rfs_rtems_eval_for_make (const char* path,
rtems_filesystem_location_info_t* pathloc,
const char** name)
@@ -481,7 +481,7 @@ rtems_rfs_rtems_eval_for_make (const char* path,
* @param name
* @return int
*/
-int
+static int
rtems_rfs_rtems_link (rtems_filesystem_location_info_t* to_loc,
rtems_filesystem_location_info_t* parent_loc,
const char* name)
@@ -517,7 +517,7 @@ rtems_rfs_rtems_link (rtems_filesystem_location_info_t* to_loc,
* @return int
*/
-int
+static int
rtems_rfs_rtems_unlink (rtems_filesystem_location_info_t* parent_loc,
rtems_filesystem_location_info_t* loc)
{
@@ -553,7 +553,7 @@ rtems_rfs_rtems_unlink (rtems_filesystem_location_info_t* parent_loc,
* @return rtems_filesystem_node_types_t
*/
-rtems_filesystem_node_types_t
+static rtems_filesystem_node_types_t
rtems_rfs_rtems_node_type (rtems_filesystem_location_info_t* pathloc)
{
rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
@@ -677,7 +677,7 @@ rtems_rfs_rtems_chown (rtems_filesystem_location_info_t *pathloc,
* return int
*/
-int
+static int
rtems_rfs_rtems_utime(rtems_filesystem_location_info_t* pathloc,
time_t atime,
time_t mtime)
@@ -721,7 +721,7 @@ rtems_rfs_rtems_utime(rtems_filesystem_location_info_t* pathloc,
* return int
*/
-int
+static int
rtems_rfs_rtems_symlink (rtems_filesystem_location_info_t* parent_loc,
const char* link_name,
const char* node_name)
@@ -765,7 +765,7 @@ rtems_rfs_rtems_symlink (rtems_filesystem_location_info_t* parent_loc,
* @return int
*/
-ssize_t
+static ssize_t
rtems_rfs_rtems_readlink (rtems_filesystem_location_info_t* pathloc,
char* buf,
size_t bufsize)
@@ -792,13 +792,40 @@ rtems_rfs_rtems_readlink (rtems_filesystem_location_info_t* pathloc,
return (int) length;
}
-/**
- * File change mode routine.
- *
- * @param pathloc
- * @param mode
- * @return int
- */
+int
+rtems_rfs_rtems_fchmod_inode (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ mode_t mode)
+{
+ uint16_t imode;
+#if defined (RTEMS_POSIX_API)
+ uid_t uid;
+#endif
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FCHMOD))
+ printf ("rtems-rfs-rtems: fchmod indo: in: ino:%" PRId32 " mode:%06" PRIomode_t "\n",
+ rtems_rfs_inode_ino (inode), mode);
+
+ imode = rtems_rfs_inode_get_mode (inode);
+
+ /*
+ * Verify I am the owner of the node or the super user.
+ */
+#if defined (RTEMS_POSIX_API)
+ uid = geteuid();
+
+ if ((uid != rtems_rfs_inode_get_uid (inode)) && (uid != 0))
+ return EPERM;
+#endif
+
+ imode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+ imode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+
+ rtems_rfs_inode_set_mode (inode, imode);
+
+ return 0;
+}
+
int
rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
mode_t mode)
@@ -806,10 +833,6 @@ rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
rtems_rfs_inode_handle inode;
- uint16_t imode;
-#if defined (RTEMS_POSIX_API)
- uid_t uid;
-#endif
int rc;
if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FCHMOD))
@@ -825,26 +848,13 @@ rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
return rtems_rfs_rtems_error ("fchmod: opening inode", rc);
}
- imode = rtems_rfs_inode_get_mode (&inode);
-
- /*
- * Verify I am the owner of the node or the super user.
- */
-#if defined (RTEMS_POSIX_API)
- uid = geteuid();
-
- if ((uid != rtems_rfs_inode_get_uid (&inode)) && (uid != 0))
+ rc = rtems_rfs_rtems_fchmod_inode (fs, &inode, mode);
+ if (rc > 0)
{
rtems_rfs_inode_close (fs, &inode);
rtems_rfs_rtems_unlock (fs);
- return rtems_rfs_rtems_error ("fchmod: not owner", EPERM);
+ return rtems_rfs_rtems_error ("fchmod: fchmod inode", EPERM);
}
-#endif
-
- imode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
- imode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
-
- rtems_rfs_inode_set_mode (&inode, imode);
rc = rtems_rfs_inode_close (fs, &inode);
if (rc > 0)
@@ -858,58 +868,39 @@ rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
return 0;
}
-/**
- * The following routine does a stat on a node.
- *
- * @param pathloc
- * @param buf
- * @return int
- */
-
int
-rtems_rfs_rtems_stat (rtems_filesystem_location_info_t* pathloc,
- struct stat* buf)
+rtems_rfs_rtems_stat_inode (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ struct stat* buf)
{
- rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
- rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
- rtems_rfs_inode_handle inode;
- rtems_rfs_file_shared* shared;
- uint16_t mode;
- int rc;
+ rtems_rfs_file_shared* shared;
+ uint16_t mode;
if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_STAT))
- printf ("rtems-rfs-rtems: stat: in: ino:%" PRId32 "\n", ino);
-
- rtems_rfs_rtems_lock (fs);
-
- rc = rtems_rfs_inode_open (fs, ino, &inode, true);
- if (rc)
- {
- rtems_rfs_rtems_unlock (fs);
- return rtems_rfs_rtems_error ("stat: opening inode", rc);
- }
+ printf ("rtems-rfs-rtems: stat-inode: in: ino:%" PRId32 "\n",
+ rtems_rfs_inode_ino (inode));
- mode = rtems_rfs_inode_get_mode (&inode);
+ mode = rtems_rfs_inode_get_mode (inode);
if (RTEMS_RFS_S_ISCHR (mode) || RTEMS_RFS_S_ISBLK (mode))
{
buf->st_rdev =
- rtems_filesystem_make_dev_t (rtems_rfs_inode_get_block (&inode, 0),
- rtems_rfs_inode_get_block (&inode, 1));
+ rtems_filesystem_make_dev_t (rtems_rfs_inode_get_block (inode, 0),
+ rtems_rfs_inode_get_block (inode, 1));
}
buf->st_dev = rtems_rfs_fs_device (fs);
- buf->st_ino = ino;
+ buf->st_ino = rtems_rfs_inode_ino (inode);
buf->st_mode = rtems_rfs_rtems_mode (mode);
- buf->st_nlink = rtems_rfs_inode_get_links (&inode);
- buf->st_uid = rtems_rfs_inode_get_uid (&inode);
- buf->st_gid = rtems_rfs_inode_get_gid (&inode);
+ buf->st_nlink = rtems_rfs_inode_get_links (inode);
+ buf->st_uid = rtems_rfs_inode_get_uid (inode);
+ buf->st_gid = rtems_rfs_inode_get_gid (inode);
/*
* Need to check is the ino is an open file. If so we take the values from
* the open file rather than the inode.
*/
- shared = rtems_rfs_file_get_shared (fs, ino);
+ shared = rtems_rfs_file_get_shared (fs, rtems_rfs_inode_ino (inode));
if (shared)
{
@@ -925,19 +916,50 @@ rtems_rfs_rtems_stat (rtems_filesystem_location_info_t* pathloc,
}
else
{
- buf->st_atime = rtems_rfs_inode_get_atime (&inode);
- buf->st_mtime = rtems_rfs_inode_get_mtime (&inode);
- buf->st_ctime = rtems_rfs_inode_get_ctime (&inode);
- buf->st_blocks = rtems_rfs_inode_get_block_count (&inode);
+ buf->st_atime = rtems_rfs_inode_get_atime (inode);
+ buf->st_mtime = rtems_rfs_inode_get_mtime (inode);
+ buf->st_ctime = rtems_rfs_inode_get_ctime (inode);
+ buf->st_blocks = rtems_rfs_inode_get_block_count (inode);
if (S_ISLNK (buf->st_mode))
- buf->st_size = rtems_rfs_inode_get_block_offset (&inode);
+ buf->st_size = rtems_rfs_inode_get_block_offset (inode);
else
- buf->st_size = rtems_rfs_inode_get_size (fs, &inode);
+ buf->st_size = rtems_rfs_inode_get_size (fs, inode);
}
buf->st_blksize = rtems_rfs_fs_block_size (fs);
+ return 0;
+}
+
+int
+rtems_rfs_rtems_fstat (rtems_filesystem_location_info_t* pathloc,
+ struct stat* buf)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_inode_handle inode;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_STAT))
+ printf ("rtems-rfs-rtems: stat: in: ino:%" PRId32 "\n", ino);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("stat: opening inode", rc);
+ }
+
+ rc = rtems_rfs_rtems_stat_inode (fs, &inode, buf);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("stat: stat'ing the inode", rc);
+ }
+
rc = rtems_rfs_inode_close (fs, &inode);
if (rc > 0)
{
@@ -959,7 +981,7 @@ rtems_rfs_rtems_stat (rtems_filesystem_location_info_t* pathloc,
* @return int
*/
-int
+static int
rtems_rfs_rtems_mknod (const char *name,
mode_t mode,
dev_t dev,
@@ -1090,7 +1112,7 @@ rtems_rfs_rtems_fdatasync (rtems_libio_t* iop)
* @param new_name The new name.
* @return int
*/
-int
+static int
rtems_rfs_rtems_rename(rtems_filesystem_location_info_t* old_parent_loc,
rtems_filesystem_location_info_t* old_loc,
rtems_filesystem_location_info_t* new_parent_loc,
@@ -1150,7 +1172,7 @@ rtems_rfs_rtems_rename(rtems_filesystem_location_info_t* old_parent_loc,
* @param sb
* @return int
*/
-int
+static int
rtems_rfs_rtems_statvfs (rtems_filesystem_location_info_t* pathloc,
struct statvfs* sb)
{
@@ -1186,7 +1208,7 @@ const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers =
.write_h = rtems_filesystem_default_write,
.ioctl_h = rtems_filesystem_default_ioctl,
.lseek_h = rtems_filesystem_default_lseek,
- .fstat_h = rtems_rfs_rtems_stat,
+ .fstat_h = rtems_rfs_rtems_fstat,
.fchmod_h = rtems_filesystem_default_fchmod,
.ftruncate_h = rtems_filesystem_default_ftruncate,
.fpathconf_h = rtems_filesystem_default_fpathconf,