nfs-ganesha 1.4

fsal_truncate.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00007  *
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 3 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  * ------------- 
00024  */
00025 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include "fsal_convert.h"
00042 
00043 #include <unistd.h>
00044 #include <sys/types.h>
00045 #include <sys/fsuid.h>
00046 
00070 fsal_status_t GPFSFSAL_truncate(fsal_handle_t * p_filehandle,       /* IN */
00071                             fsal_op_context_t * p_context,      /* IN */
00072                             fsal_size_t length, /* IN */
00073                             fsal_file_t * file_descriptor,      /* NOT USED */
00074                             fsal_attrib_list_t * p_object_attributes) /* [ IN/OUT ] */
00075 {
00076   int fsuid, fsgid;
00077   fsal_status_t st;
00078 
00079   /* sanity checks.
00080    * note : object_attributes is optional.
00081    */
00082   if(!p_filehandle || !p_context)
00083     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_truncate);
00084 
00085   fsuid = setfsuid(p_context->credential.user);
00086   fsgid = setfsgid(p_context->credential.group);
00087 
00088   TakeTokenFSCall();
00089   st = fsal_trucate_by_handle(p_context, p_filehandle, length);
00090   ReleaseTokenFSCall();
00091   if (FSAL_IS_ERROR(st)) {
00092     setfsuid(fsuid);
00093     setfsgid(fsgid);
00094     ReturnStatus(st, INDEX_FSAL_truncate);
00095   }
00096   /* Optionally retrieve attributes */
00097   if(p_object_attributes)
00098     {
00099       fsal_status_t st;
00100 
00101       st = GPFSFSAL_getattrs(p_filehandle, p_context, p_object_attributes);
00102 
00103       if(FSAL_IS_ERROR(st))
00104         {
00105           FSAL_CLEAR_MASK(p_object_attributes->asked_attributes);
00106           FSAL_SET_MASK(p_object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00107         }
00108     }
00109 
00110   fsuid =setfsuid(fsuid);
00111   fsgid =setfsgid(fsgid);
00112   /* No error occurred */
00113   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_truncate);
00114 
00115 }