nfs-ganesha 1.4
|
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 00045 fsal_status_t POSIXFSAL_truncate(fsal_handle_t * filehandle, /* IN */ 00046 fsal_op_context_t * context, /* IN */ 00047 fsal_size_t length, /* IN */ 00048 fsal_file_t * file_descriptor, /* Unused in this FSAL */ 00049 fsal_attrib_list_t * p_object_attributes /* [ IN/OUT ] */ 00050 ) 00051 { 00052 posixfsal_handle_t * p_filehandle = (posixfsal_handle_t *) filehandle; 00053 posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context; 00054 int rc, errsv; 00055 struct stat buffstat; 00056 fsal_path_t fsalpath; 00057 fsal_status_t st; 00058 00059 /* sanity checks. 00060 * note : object_attributes is optional. 00061 */ 00062 if(!p_filehandle || !p_context) 00063 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_truncate); 00064 00065 /* get the path of the file and its POSIX information */ 00066 st = fsal_internal_getPathFromHandle(p_context, p_filehandle, 0, &fsalpath, &buffstat); 00067 if(FSAL_IS_ERROR(st)) 00068 Return(st.major, st.minor, INDEX_FSAL_truncate); 00069 00070 /* check if it is a file */ 00071 if(!S_ISREG(buffstat.st_mode)) 00072 { 00073 Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_truncate); 00074 } 00075 00076 /* Executes the POSIX truncate operation */ 00077 00078 TakeTokenFSCall(); 00079 rc = truncate(fsalpath.path, length); 00080 errsv = errno; 00081 ReleaseTokenFSCall(); 00082 00083 /* convert return code */ 00084 if(rc) 00085 Return(posix2fsal_error(errsv), -errsv, INDEX_FSAL_truncate); 00086 00087 /* Optionally retrieve attributes */ 00088 if(p_object_attributes) 00089 { 00090 00091 fsal_status_t st; 00092 00093 st = POSIXFSAL_getattrs(p_filehandle, p_context, p_object_attributes); 00094 00095 if(FSAL_IS_ERROR(st)) 00096 { 00097 FSAL_CLEAR_MASK(p_object_attributes->asked_attributes); 00098 FSAL_SET_MASK(p_object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00099 } 00100 00101 } 00102 00103 /* No error occurred */ 00104 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_truncate); 00105 00106 }