mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-08-29 09:41:01 +08:00
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:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user