nfs-ganesha 1.4
|
00001 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=4:tabstop=4: 00003 */ 00004 #ifdef HAVE_CONFIG_H 00005 #include "config.h" 00006 #endif 00007 #include <string.h> 00008 00009 #include "fsal.h" 00010 #include "posixdb_internal.h" 00011 #include "abstract_mem.h" 00012 00028 fsal_posixdb_status_t fsal_posixdb_getChildren(fsal_posixdb_conn * p_conn, /* IN */ 00029 posixfsal_handle_t * p_parent_directory_handle, /* IN */ 00030 unsigned int max_count, fsal_posixdb_child ** p_children, /* OUT */ 00031 unsigned int *p_count /* OUT */ ) 00032 { 00033 unsigned int i; 00034 char query[2048]; 00035 result_handle_t res; 00036 fsal_posixdb_status_t st; 00037 00038 /* sanity check */ 00039 if(!p_conn || !p_parent_directory_handle || !(p_children) || !p_count) 00040 ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); 00041 00042 snprintf(query, 2048, "SELECT Handle.handleid, Handle.handlets, Parent.name, " 00043 "Handle.inode, Handle.deviceid, Handle.nlink, Handle.ctime, Handle.ftype " 00044 "FROM Parent INNER JOIN Handle ON Handle.handleid=Parent.handleid AND Handle.handlets=Parent.handlets " 00045 "WHERE Parent.handleidparent=%llu AND Parent.handletsparent=%u " 00046 "AND NOT (Parent.handleidparent = Parent.handleid AND Parent.handletsparent = Parent.handlets)", 00047 p_parent_directory_handle->data.id, p_parent_directory_handle->data.ts); 00048 00049 st = db_exec_sql(p_conn, query, &res); 00050 if(FSAL_POSIXDB_IS_ERROR(st)) 00051 return st; 00052 00053 *p_count = mysql_num_rows(res); 00054 00055 if(*p_count == 0) 00056 { 00057 *p_children = NULL; 00058 mysql_free_result(res); 00059 ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0); 00060 } 00061 00062 if(max_count && (*p_count > max_count)) 00063 { 00064 *p_children = NULL; 00065 mysql_free_result(res); 00066 LogCrit(COMPONENT_FSAL, "Children count %u exceed max_count %u in fsal_posixdb_getChildren", 00067 *p_count, max_count); 00068 ReturnCodeDB(ERR_FSAL_POSIXDB_TOOMANYPATHS, 0); 00069 } 00070 00071 *p_children = gsh_malloc(sizeof(fsal_posixdb_child) * (*p_count)); 00072 if(*p_children == NULL) 00073 { 00074 mysql_free_result(res); 00075 ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); 00076 } 00077 00078 for(i = 0; i < *p_count; i++) 00079 { 00080 MYSQL_ROW row; 00081 00082 row = mysql_fetch_row(res); 00083 if(!row) 00084 { 00085 /* Error */ 00086 mysql_free_result(res); 00087 ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); 00088 } 00089 00090 FSAL_str2name(row[2], FSAL_MAX_NAME_LEN, &((*p_children)[i].name)); 00091 00092 (*p_children)[i].handle.data.id = atoll(row[0]); 00093 (*p_children)[i].handle.data.ts = atoi(row[1]); 00094 posixdb_internal_fillFileinfoFromStrValues(&((*p_children)[i].handle.data.info), 00095 row[4], row[3], row[5], row[6], row[7]); 00096 } 00097 00098 mysql_free_result(res); 00099 00100 ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0); 00101 }