nfs-ganesha 1.4

fsal_fsinfo.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 <sys/statvfs.h>
00022 
00041 fsal_status_t POSIXFSAL_dynamic_fsinfo(fsal_handle_t * filehandle,       /* IN */
00042                                        fsal_op_context_t * context,      /* IN */
00043                                        fsal_dynamicfsinfo_t * p_dynamicinfo     /* OUT */
00044     )
00045 {
00046   posixfsal_handle_t * p_filehandle = (posixfsal_handle_t *) filehandle;
00047   posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
00048   fsal_path_t pathfsal;
00049   fsal_status_t status;
00050   struct statvfs buffstatvfs;
00051   int rc, errsv;
00052 
00053   /* sanity checks. */
00054   if(!p_filehandle || !p_dynamicinfo || !p_context)
00055     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_dynamic_fsinfo);
00056 
00057   status = fsal_internal_getPathFromHandle(p_context, p_filehandle, 1, &pathfsal, NULL);
00058   if(FSAL_IS_ERROR(status))
00059     Return(status.major, status.minor, INDEX_FSAL_dynamic_fsinfo);
00060 
00061   TakeTokenFSCall();
00062   rc = statvfs(pathfsal.path, &buffstatvfs);
00063   errsv = errno;
00064   ReleaseTokenFSCall();
00065   if(rc)
00066     Return(posix2fsal_error(errsv), errsv, INDEX_FSAL_dynamic_fsinfo);
00067 
00068   p_dynamicinfo->total_bytes = buffstatvfs.f_frsize * buffstatvfs.f_blocks;
00069   p_dynamicinfo->free_bytes = buffstatvfs.f_frsize * buffstatvfs.f_bfree;
00070   p_dynamicinfo->avail_bytes = buffstatvfs.f_frsize * buffstatvfs.f_bavail;
00071 
00072   p_dynamicinfo->total_files = buffstatvfs.f_files;
00073   p_dynamicinfo->free_files = buffstatvfs.f_ffree;
00074   p_dynamicinfo->avail_files = buffstatvfs.f_favail;
00075 
00076   p_dynamicinfo->time_delta.seconds = 1;
00077   p_dynamicinfo->time_delta.nseconds = 0;
00078 
00079   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_dynamic_fsinfo);
00080 
00081 }