Filesystem: Change rtems_filesystem_chown()

Implement POSIX requirements in the high-level file system layer.  Use
common implementation for all change owner variants.
This commit is contained in:
Sebastian Huber
2013-09-12 15:31:23 +02:00
parent b6657c3957
commit d2da61aa0c
4 changed files with 67 additions and 48 deletions
+2 -3
View File
@@ -572,10 +572,9 @@ int rtems_filesystem_chmod(
);
int rtems_filesystem_chown(
const char *path,
const rtems_filesystem_location_info_t *loc,
uid_t owner,
gid_t group,
int eval_follow_link
gid_t group
);
static inline bool rtems_filesystem_is_ready_for_unmount(
+11 -22
View File
@@ -25,31 +25,20 @@
#include <rtems/libio_.h>
int rtems_filesystem_chown(
const char *path,
uid_t owner,
gid_t group,
int eval_follow_link
)
{
int rv = 0;
rtems_filesystem_eval_path_context_t ctx;
int eval_flags = eval_follow_link;
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
rv = (*ops->chown_h)( currentloc, owner, group );
rtems_filesystem_eval_path_cleanup( &ctx );
return rv;
}
/**
* POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
*/
int chown( const char *path, uid_t owner, gid_t group )
{
return rtems_filesystem_chown( path, owner, group, RTEMS_FS_FOLLOW_LINK );
int rv;
rtems_filesystem_eval_path_context_t ctx;
int eval_flags = RTEMS_FS_FOLLOW_LINK;
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
rv = rtems_filesystem_chown( currentloc, owner, group );
rtems_filesystem_eval_path_cleanup( &ctx );
return rv;
}
+43 -17
View File
@@ -22,26 +22,31 @@
#include <rtems/libio_.h>
/**
* POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
*/
int fchown( int fd, uid_t owner, gid_t group )
int rtems_filesystem_chown(
const rtems_filesystem_location_info_t *loc,
uid_t owner,
gid_t group
)
{
int rv = 0;
rtems_libio_t *iop;
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
int rv;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_is_open(iop);
if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
struct stat st;
if (iop->pathinfo.mt_entry->writeable) {
rtems_filesystem_instance_lock( &iop->pathinfo );
rv = (*iop->pathinfo.mt_entry->ops->chown_h)(
&iop->pathinfo,
owner,
group
);
rtems_filesystem_instance_unlock( &iop->pathinfo );
memset( &st, 0, sizeof(st) );
rv = (*loc->handlers->fstat_h)( loc, &st );
if ( rv == 0 ) {
uid_t uid = geteuid();
if ( uid == 0 || st.st_uid == uid ) {
rv = (*mt_entry->ops->chown_h)( loc, owner, group );
} else {
errno = EPERM;
rv = -1;
}
}
} else {
errno = EROFS;
rv = -1;
@@ -49,3 +54,24 @@ int fchown( int fd, uid_t owner, gid_t group )
return rv;
}
/**
* POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
*/
int fchown( int fd, uid_t owner, gid_t group )
{
int rv;
rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_is_open(iop);
rtems_filesystem_instance_lock( &iop->pathinfo );
rv = rtems_filesystem_chown( &iop->pathinfo, owner, group );
rtems_filesystem_instance_unlock( &iop->pathinfo );
return rv;
}
+11 -6
View File
@@ -19,10 +19,15 @@
int lchown( const char *path, uid_t owner, gid_t group )
{
return rtems_filesystem_chown(
path,
owner,
group,
RTEMS_FS_FOLLOW_HARD_LINK
);
int rv;
rtems_filesystem_eval_path_context_t ctx;
int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK;
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
rv = rtems_filesystem_chown( currentloc, owner, group );
rtems_filesystem_eval_path_cleanup( &ctx );
return rv;
}