nfs-ganesha 1.4

fsal_rename.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 "fsal_common.h"
00022 
00064 fsal_status_t FSAL_rename(fsal_handle_t * old_parentdir_handle, /* IN */
00065                           fsal_name_t * p_old_name,     /* IN */
00066                           fsal_handle_t * new_parentdir_handle, /* IN */
00067                           fsal_name_t * p_new_name,     /* IN */
00068                           fsal_op_context_t * p_context,        /* IN */
00069                           fsal_attrib_list_t * src_dir_attributes,      /* [ IN/OUT ] */
00070                           fsal_attrib_list_t * tgt_dir_attributes       /* [ IN/OUT ] */
00071     )
00072 {
00073 
00074   int rc;
00075 
00076   /* sanity checks.
00077    * note : src/tgt_dir_attributes are optional.
00078    */
00079   if(!old_parentdir_handle ||
00080      !new_parentdir_handle || !p_old_name || !p_new_name || !p_context)
00081     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rename);
00082 
00083   TakeTokenFSCall();
00084 
00085   /* >> call your filesystem rename function << */
00086 
00087   ReleaseTokenFSCall();
00088 
00089   /* >> interpret the returned error << */
00090 
00091   /* >> get last parent post op attributes if asked
00092    * For example : << */
00093 
00094   if(src_dir_attributes)
00095     {
00096       fsal_status_t st;
00097 
00098       st = FSAL_getattrs(old_parentdir_handle, p_context, src_dir_attributes);
00099 
00100       if(FSAL_IS_ERROR(st))
00101         {
00102           FSAL_CLEAR_MASK(src_dir_attributes->asked_attributes);
00103           FSAL_SET_MASK(src_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00104         }
00105 
00106     }
00107 
00108   /* >> get new parent post op attributes if asked
00109    * For example : << */
00110 
00111   if(tgt_dir_attributes)
00112     {
00113       fsal_status_t st;
00114 
00115       /* optimization when src=tgt : */
00116 
00117       if(!FSAL_handlecmp(old_parentdir_handle, new_parentdir_handle, &st)
00118          && src_dir_attributes)
00119         {
00120 
00121           /* If source dir = target dir, we just copy the attributes.
00122            * to avoid doing another getattr.
00123            */
00124 
00125           (*tgt_dir_attributes) = (*src_dir_attributes);
00126 
00127         }
00128       else
00129         {
00130 
00131           /* get attributes */
00132           st = FSAL_getattrs(new_parentdir_handle, p_context, tgt_dir_attributes);
00133 
00134           if(FSAL_IS_ERROR(st))
00135             {
00136               FSAL_CLEAR_MASK(tgt_dir_attributes->asked_attributes);
00137               FSAL_SET_MASK(tgt_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00138             }
00139 
00140         }
00141 
00142     }
00143 
00144   /* OK */
00145   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_rename);
00146 
00147 }