コード例 #1
0
ファイル: fsal_compat.c プロジェクト: chandra2/nfs-ganesha
fsal_status_t WRAP_FUSEFSAL_getattrs(fsal_handle_t * p_filehandle,      /* IN */
                                     fsal_op_context_t * p_context,     /* IN */
                                     fsal_attrib_list_t *
                                     p_object_attributes /* IN/OUT */ )
{
  return FUSEFSAL_getattrs((fusefsal_handle_t *) p_filehandle,
                           (fusefsal_op_context_t *) p_context, p_object_attributes);
}
コード例 #2
0
ファイル: fsal_truncate.c プロジェクト: MeghanaM/nfs-ganesha
fsal_status_t FUSEFSAL_truncate(fsal_handle_t *handle, /* IN */
                                fsal_op_context_t * p_context,      /* IN */
                                fsal_size_t length,     /* IN */
                                fsal_file_t * file_descriptor,      /* Unused in this FSAL */
                                fsal_attrib_list_t * object_attributes  /* [ IN/OUT ] */
    )
{

  int rc;
  char object_path[FSAL_MAX_PATH_LEN];
  fusefsal_handle_t * filehandle = (fusefsal_handle_t *)handle;

  /* sanity checks.
   * note : object_attributes is optional.
   */
  if(!filehandle || !p_context)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_truncate);

  if(!p_fs_ops->truncate)
    Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_truncate);

  /* get the full path for the object */
  rc = NamespacePath(filehandle->data.inode, filehandle->data.device, filehandle->data.validator,
                     object_path);
  if(rc)
    Return(ERR_FSAL_STALE, rc, INDEX_FSAL_truncate);

  /* set context for the next operation, so it can be retrieved by FS thread */
  fsal_set_thread_context(p_context);

  TakeTokenFSCall();
  rc = p_fs_ops->truncate(object_path, (off_t) length);
  ReleaseTokenFSCall();

  if(rc)
    Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_truncate);

  if(object_attributes)
    {

      fsal_status_t st;

      st = FUSEFSAL_getattrs(handle, p_context, object_attributes);

      if(FSAL_IS_ERROR(st))
        {
          FSAL_CLEAR_MASK(object_attributes->asked_attributes);
          FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
        }

    }

  /* No error occured */
  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_truncate);

}
コード例 #3
0
/**
 * FSAL_open:
 * Open a regular file for reading/writing its data content.
 *
 * \param filehandle (input):
 *        Handle of the file to be read/modified.
 * \param cred (input):
 *        Authentication context for the operation (user,...).
 * \param openflags (input):
 *        Flags that indicates behavior for file opening and access.
 *        This is an inclusive OR of the following values
 *        ( such of them are not compatible) :
 *        - FSAL_O_RDONLY: opening file for reading only.
 *        - FSAL_O_RDWR: opening file for reading and writing.
 *        - FSAL_O_WRONLY: opening file for writting only.
 *        - FSAL_O_APPEND: always write at the end of the file.
 *        - FSAL_O_TRUNC: truncate the file to 0 on opening.
 * \param file_descriptor (output):
 *        The file descriptor to be used for FSAL_read/write operations.
 * \param file_attributes (optionnal input/output):
 *        Post operation attributes.
 *        As input, it defines the attributes that the caller
 *        wants to retrieve (by positioning flags into this structure)
 *        and the output is built considering this input
 *        (it fills the structure according to the flags it contains).
 *
 * \return Major error codes:
 *      - ERR_FSAL_NO_ERROR     (no error)
 *      - ERR_FSAL_ACCESS       (user doesn't have the permissions for opening the file)
 *      - ERR_FSAL_STALE        (filehandle does not address an existing object)
 *      - ERR_FSAL_INVAL        (filehandle does not address a regular file,
 *                               or open flags are conflicting)
 *      - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument)
 *      - Other error codes can be returned :
 *        ERR_FSAL_IO, ...
 */
fsal_status_t FUSEFSAL_open(fsal_handle_t * file_hdl,     /* IN */
                            fsal_op_context_t * p_context,  /* IN */
                            fsal_openflags_t openflags, /* IN */
                            fsal_file_t * file_desc,  /* OUT */
                            fsal_attrib_list_t * file_attributes        /* [ IN/OUT ] */
    )
{

  int rc = 0;
  char object_path[FSAL_MAX_PATH_LEN];
  int file_info_provided = FALSE;
  fusefsal_handle_t * filehandle = (fusefsal_handle_t *)file_hdl;
  fusefsal_file_t * file_descriptor = (fusefsal_file_t *)file_desc;

  /* sanity checks.
   * note : file_attributes is optional.
   */
  if(!filehandle || !p_context || !file_descriptor)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open);

  /* get the full path for this file */
  rc = NamespacePath(filehandle->data.inode, filehandle->data.device, filehandle->data.validator,
                     object_path);
  if(rc)
    Return(ERR_FSAL_STALE, rc, INDEX_FSAL_open);

  memset(file_descriptor, 0, sizeof(fusefsal_file_t));

  /* set access mode flags */

  file_descriptor->file_info.flags = 0;

  if(openflags & FSAL_O_RDONLY)
    file_descriptor->file_info.flags |= O_RDONLY;
  if(openflags & FSAL_O_WRONLY)
    file_descriptor->file_info.flags |= O_WRONLY;
  if(openflags & FSAL_O_RDWR)
    file_descriptor->file_info.flags |= O_RDWR;

  /* set context for the next operation, so it can be retrieved by FS thread */
  fsal_set_thread_context(p_context);

  /* check open call */

  if(p_fs_ops->open)
    {
      LogFullDebug(COMPONENT_FSAL, "Call to open( %s, %#X )", object_path, file_descriptor->file_info.flags);

      TakeTokenFSCall();
      rc = p_fs_ops->open(object_path, &(file_descriptor->file_info));
      ReleaseTokenFSCall();

      if(rc)
        Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_open);

      file_info_provided = TRUE;

    }
  else
    {
      LogFullDebug(COMPONENT_FSAL, "no open command provided");

      /* ignoring open */
      memset(&(file_descriptor->file_info), 0, sizeof(struct ganefuse_file_info));
    }

  /* check open flags (only FSAL_O_TRUNC and FSAL_O_APPEND are used for FUSE filesystems) */

  if(openflags & FSAL_O_TRUNC)
    {
      if(file_info_provided && p_fs_ops->ftruncate)
        {
          LogFullDebug(COMPONENT_FSAL, "call to ftruncate on file since FSAL_O_TRUNC was set");

          /* ftruncate the file */
          TakeTokenFSCall();
          rc = p_fs_ops->ftruncate(object_path, 0, &(file_descriptor->file_info));
          ReleaseTokenFSCall();

          if(rc)
            Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_open);
        }
      else if(p_fs_ops->truncate)
        {
          LogFullDebug(COMPONENT_FSAL, "call to truncate on file since FSAL_O_TRUNC was set");

          /* truncate the file */
          TakeTokenFSCall();
          rc = p_fs_ops->truncate(object_path, 0);
          ReleaseTokenFSCall();

          if(rc)
            Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_open);
        }
      /* else: ignoring flag */
    }

  if(openflags & FSAL_O_APPEND)
    {
      struct stat stbuf;

      /* In this case, this only solution is to get file attributes */

      if(file_info_provided && p_fs_ops->fgetattr)
        {
          rc = p_fs_ops->fgetattr(object_path, &stbuf, &(file_descriptor->file_info));
        }
      else
        {
          rc = p_fs_ops->getattr(object_path, &stbuf);
        }

      if(rc)
        Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_open);

      file_descriptor->current_offset = stbuf.st_size;
    }
  else
    {
      file_descriptor->current_offset = 0;
    }

  /* fill the file descriptor structure */
  file_descriptor->file_handle = *filehandle;

  /* backup context */
  file_descriptor->context = *(fusefsal_op_context_t *)p_context;

  if(file_info_provided)
    LogFullDebug(COMPONENT_FSAL, "FSAL_open: FH=%"PRId64, file_descriptor->file_info.fh);

  if(file_attributes)
    {
      fsal_status_t status;

      status = FUSEFSAL_getattrs((fsal_handle_t *)filehandle, p_context, file_attributes);

      /* on error, we set a special bit in the mask. */
      if(FSAL_IS_ERROR(status))
        {
          FSAL_CLEAR_MASK(file_attributes->asked_attributes);
          FSAL_SET_MASK(file_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
        }
    }

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_open);

}
コード例 #4
0
ファイル: fsal_dirs.c プロジェクト: MeghanaM/nfs-ganesha
/**
 * FSAL_opendir :
 *     Opens a directory for reading its content.
 *
 * \param dir_handle (input)
 *         the handle of the directory to be opened.
 * \param p_context (input)
 *         Permission context for the operation (user, export context...).
 * \param dir_descriptor (output)
 *         pointer to an allocated structure that will receive
 *         directory stream informations, on successfull completion.
 * \param dir_attributes (optional output)
 *         On successfull completion,the structure pointed
 *         by dir_attributes receives the new directory attributes.
 *         Can be NULL.
 *
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - ERR_FSAL_ACCESS       (user does not have read permission on directory)
 *        - ERR_FSAL_STALE        (dir_handle does not address an existing object)
 *        - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument)
 *        - Other error codes can be returned :
 *          ERR_FSAL_IO, ...
 */
fsal_status_t FUSEFSAL_opendir(fsal_handle_t * dir_hdl,  /* IN */
                               fsal_op_context_t * p_context,       /* IN */
                               fsal_dir_t * dir_desc,     /* OUT */
                               fsal_attrib_list_t * dir_attributes      /* [ IN/OUT ] */
    )
{
  int rc;
  char object_path[FSAL_MAX_PATH_LEN];
  fusefsal_dir_t * dir_descriptor = (fusefsal_dir_t *)dir_desc;
  fusefsal_handle_t * dir_handle = (fusefsal_handle_t *)dir_hdl;

  /* sanity checks
   * note : dir_attributes is optionnal.
   */
  if(!dir_handle || !p_context || !dir_descriptor)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_opendir);

  /* get the full path for this directory */
  rc = NamespacePath(dir_handle->data.inode, dir_handle->data.device, dir_handle->data.validator,
                     object_path);
  if(rc)
    Return(ERR_FSAL_STALE, rc, INDEX_FSAL_opendir);

  memset(dir_descriptor, 0, sizeof(fsal_dir_t));

  /* set context for the next operation, so it can be retrieved by FS thread */
  fsal_set_thread_context(p_context);

  /* check opendir call */

  if(p_fs_ops->opendir)
    {
      TakeTokenFSCall();
      rc = p_fs_ops->opendir(object_path, &(dir_descriptor->dir_info));
      ReleaseTokenFSCall();

      if(rc)
        Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_opendir);
    }
  else
    {
      /* ignoring opendir */
      memset(&(dir_descriptor->dir_info), 0, sizeof(struct ganefuse_file_info));
    }

  /* fill the dir descriptor structure */
  dir_descriptor->dir_handle = *dir_handle;

  /* backup context */
  dir_descriptor->context = *(fusefsal_op_context_t *)p_context;

  /* optionaly get attributes */
  if(dir_attributes)
    {
      fsal_status_t status;

      status = FUSEFSAL_getattrs(dir_hdl, p_context, dir_attributes);

      /* on error, we set a special bit in the mask. */
      if(FSAL_IS_ERROR(status))
        {
          FSAL_CLEAR_MASK(dir_attributes->asked_attributes);
          FSAL_SET_MASK(dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
        }
    }

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_opendir);

}
コード例 #5
0
ファイル: fsal_rename.c プロジェクト: alangenfeld/cloud-nfs
fsal_status_t FUSEFSAL_rename(fusefsal_handle_t * old_parentdir_handle, /* IN */
                              fsal_name_t * p_old_name, /* IN */
                              fusefsal_handle_t * new_parentdir_handle, /* IN */
                              fsal_name_t * p_new_name, /* IN */
                              fusefsal_op_context_t * p_context,        /* IN */
                              fsal_attrib_list_t * src_dir_attributes,  /* [ IN/OUT ] */
                              fsal_attrib_list_t * tgt_dir_attributes   /* [ IN/OUT ] */
    )
{

  int rc = 0;
  char src_dir_path[FSAL_MAX_PATH_LEN];
  char tgt_dir_path[FSAL_MAX_PATH_LEN];
  char src_obj_path[FSAL_MAX_PATH_LEN];
  char tgt_obj_path[FSAL_MAX_PATH_LEN];

  /* sanity checks.
   * note : src/tgt_dir_attributes are optional.
   */
  if(!old_parentdir_handle ||
     !new_parentdir_handle || !p_old_name || !p_new_name || !p_context)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rename);

  if(!p_fs_ops->rename)
    Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_rename);

  /* get full path for parent source handle */
  rc = NamespacePath(old_parentdir_handle->data.inode, old_parentdir_handle->data.device,
                     old_parentdir_handle->data.validator, src_dir_path);
  if(rc)
    Return(ERR_FSAL_STALE, rc, INDEX_FSAL_rename);

  /* get full path for parent target handle */
  rc = NamespacePath(new_parentdir_handle->data.inode, new_parentdir_handle->data.device,
                     new_parentdir_handle->data.validator, tgt_dir_path);
  if(rc)
    Return(ERR_FSAL_STALE, rc, INDEX_FSAL_rename);

  /* build full path for source entry */
  FSAL_internal_append_path(src_obj_path, src_dir_path, p_old_name->name);

  /* build full path for target entry */
  FSAL_internal_append_path(tgt_obj_path, tgt_dir_path, p_new_name->name);

  /* set context for the next operation, so it can be retrieved by FS thread */
  fsal_set_thread_context(p_context);

  TakeTokenFSCall();

  rc = p_fs_ops->rename(src_obj_path, tgt_obj_path);

  ReleaseTokenFSCall();

  /* Regarding FALSE parameter of function fuse2fsal_error:
   * here, if error is ENOENT, we don't know weither the father handle is STALE
   * or if the source entry does not exist.
   * We choose returning ENOENT since the parent exists in the namespace,
   * so it it more likely to exist than the children.
   */
  if(rc)
    Return(fuse2fsal_error(rc, FALSE), rc, INDEX_FSAL_rename);

  /* If operation succeeded, impact the namespace */
  NamespaceRename(old_parentdir_handle->data.inode, old_parentdir_handle->data.device,
                  old_parentdir_handle->data.validator, p_old_name->name,
                  new_parentdir_handle->data.inode, new_parentdir_handle->data.device,
                  new_parentdir_handle->data.validator, p_new_name->name);

  /* Last parent post op attributes if asked */

  if(src_dir_attributes)
    {
      fsal_status_t st;

      st = FUSEFSAL_getattrs(old_parentdir_handle, p_context, src_dir_attributes);

      if(FSAL_IS_ERROR(st))
        {
          FSAL_CLEAR_MASK(src_dir_attributes->asked_attributes);
          FSAL_SET_MASK(src_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
        }

    }

  /* New parent post op attributes if asked */

  if(tgt_dir_attributes)
    {
      fsal_status_t st;

      /* optimization when src=tgt : */

      if(!FUSEFSAL_handlecmp(old_parentdir_handle, new_parentdir_handle, &st)
         && src_dir_attributes)
        {

          /* If source dir = target dir, we just copy the attributes.
           * to avoid doing another getattr.
           */

          (*tgt_dir_attributes) = (*src_dir_attributes);

        }
      else
        {

          /* get attributes */
          st = FUSEFSAL_getattrs(new_parentdir_handle, p_context, tgt_dir_attributes);

          if(FSAL_IS_ERROR(st))
            {
              FSAL_CLEAR_MASK(tgt_dir_attributes->asked_attributes);
              FSAL_SET_MASK(tgt_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
            }

        }

    }

  /* OK */
  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_rename);

}