nfs-ganesha 1.4

posixdb_getChildren.c

Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 #include <string.h>
00005 
00006 #include "fsal.h"
00007 #include "posixdb_internal.h"
00008 #include "abstract_mem.h"
00009 
00025 fsal_posixdb_status_t fsal_posixdb_getChildren(fsal_posixdb_conn * p_conn,      /* IN */
00026                                                posixfsal_handle_t * p_parent_directory_handle,  /* IN */
00027                                                unsigned int max_count, fsal_posixdb_child ** p_children,        /* OUT */
00028                                                unsigned int *p_count /* OUT */ )
00029 {
00030   PGresult *p_res;
00031   char handleid_str[MAX_HANDLEIDSTR_SIZE], handlets_str[MAX_HANDLETSSTR_SIZE];
00032   const char *paramValues[2] = { NULL, NULL };
00033   unsigned int i;
00034 
00035   /* sanity check */
00036   if(!p_conn || !p_parent_directory_handle || !(p_children) || !p_count)
00037     ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0);
00038 
00039   snprintf(handleid_str, MAX_HANDLEIDSTR_SIZE, "%lli", p_parent_directory_handle->data.id);
00040   snprintf(handlets_str, MAX_HANDLETSSTR_SIZE, "%i", p_parent_directory_handle->data.ts);
00041   paramValues[0] = handleid_str;
00042   paramValues[1] = handlets_str;
00043   p_res = PQexecPrepared(p_conn, "countChildren", 2, paramValues, NULL, NULL, 0);
00044   CheckResult(p_res);
00045 
00046   *p_count = atoi(PQgetvalue(p_res, 0, 0));
00047   PQclear(p_res);
00048 
00049   if(*p_count == 0)
00050     {
00051       *p_children = NULL;
00052       ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0);
00053     }
00054 
00055   if(max_count && (*p_count > max_count))
00056     {
00057       *p_children = NULL;
00058       LogCrit(COMPONENT_FSAL, "Children count %u exceed max_count %u in fsal_posixdb_getChildren",
00059                  *p_count, max_count);
00060       ReturnCodeDB(ERR_FSAL_POSIXDB_TOOMANYPATHS, 0);
00061     }
00062 
00063   p_res = PQexecPrepared(p_conn, "lookupChildren", 2, paramValues, NULL, NULL, 0);
00064   CheckResult(p_res);
00065 
00066   *p_count = PQntuples(p_res);
00067   *p_children = gsh_malloc(sizeof(fsal_posixdb_child) * (*p_count));
00068   if(*p_children == NULL)
00069     {
00070       PQclear(p_res);
00071       ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0);
00072     }
00073 
00074   for(i = 0; i < *p_count; i++)
00075     {
00076 
00077       char *pq_id = PQgetvalue(p_res, i, 0);
00078       char *pq_ts = PQgetvalue(p_res, i, 1);
00079 
00080       FSAL_str2name(PQgetvalue(p_res, i, 2), FSAL_MAX_NAME_LEN, &((*p_children)[i].name));
00081 
00082       (*p_children)[i].handle.data.id = atoll(pq_id);
00083       (*p_children)[i].handle.data.ts = atoi(pq_ts);
00084       posixdb_internal_fillFileinfoFromStrValues(&((*p_children)[i].handle.data.info),
00085                                                  PQgetvalue(p_res, i, 4),
00086                                                  PQgetvalue(p_res, i, 3),
00087                                                  PQgetvalue(p_res, i, 5),
00088                                                  PQgetvalue(p_res, i, 6),
00089                                                  PQgetvalue(p_res, i, 7));
00090     }
00091   PQclear(p_res);
00092 
00093   ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0);
00094 }