示例#1
0
static int
rtems_rfs_rtems_chown (const rtems_filesystem_location_info_t *pathloc,
                       uid_t                                   owner,
                       gid_t                                   group)
{
  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;
#if defined (RTEMS_POSIX_API)
  uid_t                  uid;
#endif
  int                    rc;

  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_CHOWN))
    printf ("rtems-rfs-rtems: chown: in: ino:%" PRId32 " uid:%d gid:%d\n",
            ino, owner, group);

  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
  if (rc > 0)
  {
    return rtems_rfs_rtems_error ("chown: opening inode", rc);
  }

  /*
   *  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))
  {
    rtems_rfs_inode_close (fs, &inode);
    return rtems_rfs_rtems_error ("chown: not able", EPERM);
  }
#endif

  rtems_rfs_inode_set_uid_gid (&inode, owner, group);

  rc = rtems_rfs_inode_close (fs, &inode);
  if (rc)
  {
    return rtems_rfs_rtems_error ("chown: closing inode", rc);
  }

  return 0;
}
示例#2
0
int
rtems_rfs_inode_initialise (rtems_rfs_inode_handle* handle,
                            uint16_t                links,
                            uint16_t                mode,
                            uid_t                   uid,
                            gid_t                   gid)
{
  int b;
  rtems_rfs_inode_set_links (handle, links);
  rtems_rfs_inode_set_flags (handle, 0);
  rtems_rfs_inode_set_mode (handle,  mode);
  rtems_rfs_inode_set_uid_gid (handle, uid, gid);
  rtems_rfs_inode_set_block_offset (handle, 0);
  rtems_rfs_inode_set_block_count (handle, 0);
  for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
    rtems_rfs_inode_set_block (handle, b, 0);
  rtems_rfs_inode_set_last_map_block (handle, 0);
  rtems_rfs_inode_set_last_data_block (handle, 0);
  return rtems_rfs_inode_time_stamp_now (handle, true, true);
}