nfs-ganesha 1.4

fsal_truncate.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include "fsal.h"
00019 #include "fsal_internal.h"
00020 #include "fsal_convert.h"
00021 #include "namespace.h"
00022 
00050 fsal_status_t FUSEFSAL_truncate(fsal_handle_t *handle, /* IN */
00051                                 fsal_op_context_t * p_context,      /* IN */
00052                                 fsal_size_t length,     /* IN */
00053                                 fsal_file_t * file_descriptor,      /* Unused in this FSAL */
00054                                 fsal_attrib_list_t * object_attributes  /* [ IN/OUT ] */
00055     )
00056 {
00057 
00058   int rc;
00059   char object_path[FSAL_MAX_PATH_LEN];
00060   fusefsal_handle_t * filehandle = (fusefsal_handle_t *)handle;
00061 
00062   /* sanity checks.
00063    * note : object_attributes is optional.
00064    */
00065   if(!filehandle || !p_context)
00066     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_truncate);
00067 
00068   if(!p_fs_ops->truncate)
00069     Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_truncate);
00070 
00071   /* get the full path for the object */
00072   rc = NamespacePath(filehandle->data.inode, filehandle->data.device, filehandle->data.validator,
00073                      object_path);
00074   if(rc)
00075     Return(ERR_FSAL_STALE, rc, INDEX_FSAL_truncate);
00076 
00077   /* set context for the next operation, so it can be retrieved by FS thread */
00078   fsal_set_thread_context(p_context);
00079 
00080   TakeTokenFSCall();
00081   rc = p_fs_ops->truncate(object_path, (off_t) length);
00082   ReleaseTokenFSCall();
00083 
00084   if(rc)
00085     Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_truncate);
00086 
00087   if(object_attributes)
00088     {
00089 
00090       fsal_status_t st;
00091 
00092       st = FUSEFSAL_getattrs(handle, p_context, object_attributes);
00093 
00094       if(FSAL_IS_ERROR(st))
00095         {
00096           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00097           FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00098         }
00099 
00100     }
00101 
00102   /* No error occured */
00103   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_truncate);
00104 
00105 }