コード例 #1
0
ファイル: stat.cpp プロジェクト: fireshock199/syndicate
// access
int fs_entry_access( struct fs_core* core, char const* path, int mode, uint64_t user, uint64_t volume ) {
   // make sure this path exists
   int err = 0;
   struct fs_entry* fent = fs_entry_resolve_path( core, path, user, volume, false, &err );
   if( !fent || err ) {
      if( !err )
         err = -ENOMEM;

      return err;
   }

   // F_OK implicitly satisfied

   if( (mode & R_OK) && !IS_READABLE( fent->mode, fent->owner, fent->volume, user, volume ) ) {
      err = -EACCES;
   }
   else if( (mode & W_OK) && !IS_WRITEABLE( fent->mode, fent->owner, fent->volume, user, volume ) ) {
      err = -EACCES;
   }
   else if( (mode & X_OK) && !IS_EXECUTABLE( fent->mode, fent->owner, fent->volume, user, volume ) ) {
      err = -EACCES;
   }

   fs_entry_unlock( fent );
   return err;
}
コード例 #2
0
ファイル: fs_romfs.c プロジェクト: nodesign/nuttx-kernel
static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
                      FAR struct stat *buf)
{
  FAR struct romfs_mountpt_s *rm;
  FAR struct romfs_dirinfo_s dirinfo;
  int ret;

  fvdbg("Entry\n");

  /* Sanity checks */

  DEBUGASSERT(mountpt && mountpt->i_private);

  /* Get the mountpoint private data from the inode structure */

  rm = mountpt->i_private;

  /* Check if the mount is still healthy */

  romfs_semtake(rm);
  ret = romfs_checkmount(rm);
  if (ret != OK)
    {
      fdbg("romfs_checkmount failed: %d\n", ret);
      goto errout_with_semaphore;
    }

  /* Find the directory entry corresponding to relpath. */

  ret = romfs_finddirentry(rm, &dirinfo, relpath);

  /* If nothing was found, then we fail with EEXIST */

  if (ret < 0)
    {
      fvdbg("Failed to find directory: %d\n", ret);
      goto errout_with_semaphore;
    }

  memset(buf, 0, sizeof(struct stat));
  if (IS_DIRECTORY(dirinfo.rd_next))
    {
      /* It's a read-only directory name */

      buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR;
      if (IS_EXECUTABLE(dirinfo.rd_next))
        {
          buf->st_mode |= S_IXOTH|S_IXGRP|S_IXUSR;
        }
    }
  else if (IS_FILE(dirinfo.rd_next))
    {
      /* It's a read-only file name */

      buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR;
      if (IS_EXECUTABLE(dirinfo.rd_next))
        {
          buf->st_mode |= S_IXOTH|S_IXGRP|S_IXUSR;
        }
    }
  else
    {
      /* Otherwise, pretend like the unsupported node does not exist */

      fvdbg("Unsupported inode: %d\n", dirinfo.rd_next);
      ret = -ENOENT;
      goto errout_with_semaphore;
    }

  /* File/directory size, access block size */

  buf->st_size      = dirinfo.rd_size;
  buf->st_blksize   = rm->rm_hwsectorsize;
  buf->st_blocks    = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;

  ret = OK;

errout_with_semaphore:
  romfs_semgive(rm);
  return ret;
}