예제 #1
0
static int trunk_client_trunk_do_alloc_space(TrackerServerInfo *pTrunkServer, \
		const int file_size, FDFSTrunkFullInfo *pTrunkInfo)
{
	TrackerHeader *pHeader;
	char *p;
	int result;
	char out_buff[sizeof(TrackerHeader)+FDFS_GROUP_NAME_MAX_LEN+4];
	FDFSTrunkInfoBuff trunkBuff;
	int64_t in_bytes;

	pHeader = (TrackerHeader *)out_buff;
	memset(out_buff, 0, sizeof(out_buff));
	snprintf(out_buff + sizeof(TrackerHeader), sizeof(out_buff) - \
		sizeof(TrackerHeader),  "%s", g_group_name);
	int2buff(file_size, out_buff + sizeof(TrackerHeader) \
		 + FDFS_GROUP_NAME_MAX_LEN);
	long2buff(FDFS_GROUP_NAME_MAX_LEN + 4, pHeader->pkg_len);
	pHeader->cmd = STORAGE_PROTO_CMD_TRUNK_ALLOC_SPACE;

	if ((result=tcpsenddata_nb(pTrunkServer->sock, out_buff, \
			sizeof(out_buff), g_fdfs_network_timeout)) != 0)
	{
		logError("file: "__FILE__", line: %d, " \
			"send data to storage server %s:%d fail, " \
			"errno: %d, error info: %s", __LINE__, \
			pTrunkServer->ip_addr, pTrunkServer->port, \
			result, STRERROR(result));

		return result;
	}

	p = (char *)&trunkBuff;
	if ((result=fdfs_recv_response(pTrunkServer, \
		&p, sizeof(FDFSTrunkInfoBuff), &in_bytes)) != 0)
	{
		return result;
	}

	if (in_bytes != sizeof(FDFSTrunkInfoBuff))
	{
		logError("file: "__FILE__", line: %d, " \
			"storage server %s:%d, recv body length: %d invalid, " \
			"expect body length: %d", __LINE__, \
			pTrunkServer->ip_addr, pTrunkServer->port, \
			(int)in_bytes, (int)sizeof(FDFSTrunkInfoBuff));
		return EINVAL;
	}

	pTrunkInfo->path.store_path_index = trunkBuff.store_path_index;
	pTrunkInfo->path.sub_path_high = trunkBuff.sub_path_high;
	pTrunkInfo->path.sub_path_low = trunkBuff.sub_path_low;
	pTrunkInfo->file.id = buff2int(trunkBuff.id);
	pTrunkInfo->file.offset = buff2int(trunkBuff.offset);
	pTrunkInfo->file.size = buff2int(trunkBuff.size);
	pTrunkInfo->status = FDFS_TRUNK_STATUS_HOLD;

	return 0;
}
예제 #2
0
void trunk_file_info_decode(const char *str, FDFSTrunkFileInfo *pTrunkFile)
{
    char buff[FDFS_TRUNK_FILE_INFO_LEN];
    int len;

    base64_decode_auto(&g_fdfs_base64_context, str, FDFS_TRUNK_FILE_INFO_LEN, \
                       buff, &len);

    pTrunkFile->id = buff2int(buff);
    pTrunkFile->offset = buff2int(buff + sizeof(int));
    pTrunkFile->size = buff2int(buff + sizeof(int) * 2);
}
예제 #3
0
void trunk_unpack_header(const char *buff, FDFSTrunkHeader *pTrunkHeader)
{
    pTrunkHeader->file_type = *(buff + FDFS_TRUNK_FILE_FILE_TYPE_OFFSET);
    pTrunkHeader->alloc_size = buff2int(
                                   buff + FDFS_TRUNK_FILE_ALLOC_SIZE_OFFSET);
    pTrunkHeader->file_size = buff2int(
                                  buff + FDFS_TRUNK_FILE_FILE_SIZE_OFFSET);
    pTrunkHeader->crc32 = buff2int(
                              buff + FDFS_TRUNK_FILE_FILE_CRC32_OFFSET);
    pTrunkHeader->mtime = buff2int(
                              buff + FDFS_TRUNK_FILE_FILE_MTIME_OFFSET);
    memcpy(pTrunkHeader->formatted_ext_name, buff + \
           FDFS_TRUNK_FILE_FILE_EXT_NAME_OFFSET, \
           FDFS_FILE_EXT_NAME_MAX_LEN + 1);
    *(pTrunkHeader->formatted_ext_name+FDFS_FILE_EXT_NAME_MAX_LEN+1)='\0';
}
예제 #4
0
EmqTypeBlockRequest *emqTypeBlockRequestReStreamLize(char *buff)
{
    EmqTypeBlockRequest *tbReq;

    if(buff == NULL) {
        return NULL;
    }

    if((tbReq = emqTypeBlockRequestNew()) == NULL)
        return NULL;

    tbReq->oper_no = buff2int(buff);
    tbReq->priority = buff2int(buff+4);
    tbReq->send_index = buff2int(buff+8);
    tbReq->flag = buff2int(buff+12);
    tbReq->body_len = buff2int(buff+16);

    return tbReq;
}
예제 #5
0
/* receive type block request */
EmqTypeBlockResponse * emqTypeBlockResponseReceive(EmqNioConn *the_conn)
{
    char buff[1024];
    int func_no, ret;
    int err_len;
    EmqTypeBlockResponse *tpRep;

    tpRep = emqTypeBlockResponseNew();
    if(tpRep == NULL) {
        applog(EMERG, "func emqTypeBlockResponseNew error");
        return NULL;
    }

    memset(buff, 0x00, sizeof(buff));
    ret = socketRecvDataFromConn(the_conn, buff, 28);
    if(ret != 28 ) {
        applog(EMERG, "func socketRecvDataFromConn error!");
        emqTypeBlockResponseFree(&tpRep);
        return NULL;
    }
    tpRep->oper_no = buff2int(buff); 
    tpRep->priority = buff2int(buff+4); 
    tpRep->send_index = buff2int(buff+8); 
    tpRep->flag = buff2int(buff+12); 
    tpRep->body_len = buff2int(buff+16); 
    tpRep->err_type = buff2int(buff+20); 
    tpRep->err_no = buff2int(buff+24); 
    if(!(tpRep->err_type == 0 && tpRep->err_no == 0)) {
        memset(buff, 0x00, sizeof(buff));
        ret = socketRecvDataFromConn(the_conn, buff, 4);
        if(ret != 4 ) {
            applog(EMERG, "func socketSendDataToConn error!");
            emqTypeBlockResponseFree(&tpRep);
            return NULL;
        }
        err_len= buff2int(buff);
        if(err_len > 0 && err_len <= MAX_STR_LEN) {
            memset(buff, 0x00, sizeof(buff));
            ret = socketRecvDataFromConn(the_conn, buff, err_len);
            if(ret != err_len ) {
                applog(EMERG, "func socketRecvDataFromConn error!");
                emqTypeBlockResponseFree(&tpRep);
                return NULL;
            }
            memcpy(tpRep->err_msg, buff, err_len);
            tpRep->err_msg[MAX_STR_LEN] = '\0';
        }
    }

    return tpRep;
}
예제 #6
0
EmqTypeBlockResponse *emqTypeBlockResponseReStreamLize(char *buff)
{
    EmqTypeBlockResponse *tbRes;
    int len = 0;

    if((tbRes = emqTypeBlockResponseNew()) == NULL)
        return NULL;

    len += 4;
    tbRes->err_type = buff2int(buff+len);
    len += 4;
    tbRes->err_no = buff2int(buff+len);
    len += 4;
    if(!(tbRes->err_type == 0 && tbRes->err_no == 0)) {
        len += buff2string(buff+len, tbRes->err_msg);
    }
    tbRes->flag = buff2int(buff+len);
    len += 4;
    tbRes->body_len = buff2int(buff+len);

    return tbRes;
}
예제 #7
0
MsgExample1Rep *MsgExample1RepReStreamlize(char *buff, int len)
{
    MsgExample1Rep *rep;
    int len1;
    
    rep = (MsgExample1Rep *)malloc(sizeof(MsgExample1Rep));
    if(rep == NULL) {
        applog(EMERG, "malloc memory error");
        return NULL;
    }

    rep->allow = buff2int(buff); 

    return rep; 
}
예제 #8
0
int fdht_recv_header(FDHTServerInfo *pServer, fdht_pkg_size_t *in_bytes)
{
	FDHTProtoHeader resp;
	int result;

	if ((result=tcprecvdata_nb(pServer->sock, &resp, \
		sizeof(resp), g_fdht_network_timeout)) != 0)
	{
		logError("file: "__FILE__", line: %d, " \
			"server: %s:%d, recv data fail, " \
			"errno: %d, error info: %s", \
			__LINE__, pServer->ip_addr, \
			pServer->port, \
			result, STRERROR(result));
		*in_bytes = 0;
		return result;
	}

	if (resp.status != 0)
	{
		*in_bytes = 0;
		return resp.status;
	}

	*in_bytes = buff2int(resp.pkg_len);
	if (*in_bytes < 0)
	{
		logError("file: "__FILE__", line: %d, " \
			"server: %s:%d, recv package size %d " \
			"is not correct", \
			__LINE__, pServer->ip_addr, \
			pServer->port, *in_bytes);
		*in_bytes = 0;
		return EINVAL;
	}

	return resp.status;
}
예제 #9
0
int fdfs_get_storage_ids_from_tracker_server(ConnectionInfo *pTrackerServer)
{
#define MAX_REQUEST_LOOP   32
	TrackerHeader *pHeader;
	ConnectionInfo *conn;
	char out_buff[sizeof(TrackerHeader) + sizeof(int)];
	char *p;
	char *response;
	struct data_info {
		char *buffer;  //for free
		char *content;
		int length;
	} data_list[MAX_REQUEST_LOOP];
	int list_count;
	int total_count;
	int current_count;
	int result;
	int i;
	int start_index;
	int64_t in_bytes;

	if ((conn=tracker_connect_server(pTrackerServer, &result)) == NULL)
	{
		return result;
	}

	memset(data_list, 0, sizeof(data_list));
	memset(out_buff, 0, sizeof(out_buff));
	pHeader = (TrackerHeader *)out_buff;
	p = out_buff + sizeof(TrackerHeader);
	pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_FETCH_STORAGE_IDS;
	long2buff(sizeof(int), pHeader->pkg_len);

	start_index = 0;
	list_count = 0;
	result = 0;
	while (1)
	{
		int2buff(start_index, p);
		if ((result=tcpsenddata_nb(conn->sock, out_buff, \
			sizeof(out_buff), g_fdfs_network_timeout)) != 0)
		{
			logError("file: "__FILE__", line: %d, " \
				"send data to tracker server %s:%d fail, " \
				"errno: %d, error info: %s", __LINE__, \
				pTrackerServer->ip_addr, \
				pTrackerServer->port, \
				result, STRERROR(result));
		}
		else
		{
			response = NULL;
			result = fdfs_recv_response(conn, \
				&response, 0, &in_bytes);
            if (result != 0)
            {
                logError("file: "__FILE__", line: %d, "
                        "fdfs_recv_response fail, result: %d",
                        __LINE__, result);
            }
		}

		if (result != 0)
		{
			break;
		}

		if (in_bytes < 2 * sizeof(int))
		{
			logError("file: "__FILE__", line: %d, " \
				"tracker server %s:%d, recv data length: %d "\
				"is invalid", __LINE__, 
				pTrackerServer->ip_addr, \
				pTrackerServer->port, (int)in_bytes);
			result = EINVAL;
			break;
		}

		total_count = buff2int(response);
		current_count = buff2int(response + sizeof(int));
		if (total_count <= start_index)
		{
			logError("file: "__FILE__", line: %d, " \
				"tracker server %s:%d, total storage " \
				"count: %d is invalid, which <= start " \
				"index: %d", __LINE__, pTrackerServer->ip_addr,\
				pTrackerServer->port, total_count, start_index);
			result = EINVAL;
			break;
		}

		if (current_count <= 0)
		{
			logError("file: "__FILE__", line: %d, " \
				"tracker server %s:%d, current storage " \
				"count: %d is invalid, which <= 0", \
				__LINE__, pTrackerServer->ip_addr,\
				pTrackerServer->port, current_count);
			result = EINVAL;
			break;
		}

		data_list[list_count].buffer = response;
		data_list[list_count].content = response + 2 * sizeof(int);
		data_list[list_count].length = in_bytes - 2 * sizeof(int);
		list_count++;

		/*
		//logInfo("list_count: %d, total_count: %d, current_count: %d", 
			list_count, total_count, current_count);
		*/

		start_index += current_count;
		if (start_index >= total_count)
		{
			break;
		}

		if (list_count == MAX_REQUEST_LOOP)
		{
			logError("file: "__FILE__", line: %d, " \
				"response data from tracker " \
				"server %s:%d is too large", \
				__LINE__, pTrackerServer->ip_addr,\
				pTrackerServer->port);
			result = ENOSPC;
			break;
		}
	}

	tracker_disconnect_server_ex(conn, result != 0);

	if (result == 0)
	{
		do
		{
			int total_length;
			char *content;

			total_length = 0;
			for (i=0; i<list_count; i++)
			{
				total_length += data_list[i].length;
			}

			content = (char *)malloc(total_length + 1);
			if (content == NULL)
			{
				result = errno != 0 ? errno : ENOMEM;
				logError("file: "__FILE__", line: %d, " \
					"malloc %d bytes fail, " \
					"errno: %d, error info: %s", \
					__LINE__, total_length + 1, \
					result, STRERROR(result));
				break;
			}

			p = content;
			for (i=0; i<list_count; i++)
			{
				memcpy(p, data_list[i].content, data_list[i].length);
				p += data_list[i].length;
			}
			*p = '\0';

			//logInfo("list_count: %d, storage ids:\n%s", list_count, content);

			result = fdfs_load_storage_ids(content, \
					"storage-ids-from-tracker");
			free(content);
		} while (0);
	}

	for (i=0; i<list_count; i++)
	{
		free(data_list[i].buffer);
	}

	return result;
}
예제 #10
0
int trunk_file_do_lstat_func_ex(const FDFSStorePaths *pStorePaths, \
                                const int store_path_index, const char *true_filename, \
                                const int filename_len, const int stat_func, \
                                struct stat *pStat, FDFSTrunkFullInfo *pTrunkInfo, \
                                FDFSTrunkHeader *pTrunkHeader, int *pfd)
{
    char full_filename[MAX_PATH_SIZE];
    char buff[128];
    char pack_buff[FDFS_TRUNK_FILE_HEADER_SIZE];
    int64_t file_size;
    int buff_len;
    int fd;
    int read_bytes;
    int result;

    pTrunkInfo->file.id = 0;
    if (filename_len != FDFS_TRUNK_FILENAME_LENGTH) //not trunk file
    {
        snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
                 pStorePaths->paths[store_path_index], true_filename);

        if (stat_func == FDFS_STAT_FUNC_STAT)
        {
            result = stat(full_filename, pStat);
        }
        else
        {
            result = lstat(full_filename, pStat);
        }
        if (result == 0)
        {
            return 0;
        }
        else
        {
            return errno != 0 ? errno : ENOENT;
        }
    }

    memset(buff, 0, sizeof(buff));
    base64_decode_auto(&g_fdfs_base64_context, (char *)true_filename + \
                       FDFS_TRUE_FILE_PATH_LEN, FDFS_FILENAME_BASE64_LENGTH, \
                       buff, &buff_len);

    file_size = buff2long(buff + sizeof(int) * 2);
    if (!IS_TRUNK_FILE(file_size))  //slave file
    {
        snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
                 pStorePaths->paths[store_path_index], true_filename);

        if (stat_func == FDFS_STAT_FUNC_STAT)
        {
            result = stat(full_filename, pStat);
        }
        else
        {
            result = lstat(full_filename, pStat);
        }
        if (result == 0)
        {
            return 0;
        }
        else
        {
            return errno != 0 ? errno : ENOENT;
        }
    }

    trunk_file_info_decode(true_filename + FDFS_TRUE_FILE_PATH_LEN + \
                           FDFS_FILENAME_BASE64_LENGTH, &pTrunkInfo->file);

    pTrunkHeader->file_size = FDFS_TRUNK_FILE_TRUE_SIZE(file_size);
    pTrunkHeader->mtime = buff2int(buff + sizeof(int));
    pTrunkHeader->crc32 = buff2int(buff + sizeof(int) * 4);
    memcpy(pTrunkHeader->formatted_ext_name, true_filename + \
           (filename_len - (FDFS_FILE_EXT_NAME_MAX_LEN + 1)), \
           FDFS_FILE_EXT_NAME_MAX_LEN + 2); //include tailing '\0'
    pTrunkHeader->alloc_size = pTrunkInfo->file.size;

    pTrunkInfo->path.store_path_index = store_path_index;
    pTrunkInfo->path.sub_path_high = strtol(true_filename, NULL, 16);
    pTrunkInfo->path.sub_path_low = strtol(true_filename + 3, NULL, 16);

    trunk_get_full_filename_ex(pStorePaths, pTrunkInfo, full_filename, \
                               sizeof(full_filename));
    fd = open(full_filename, O_RDONLY);
    if (fd < 0)
    {
        return errno != 0 ? errno : EIO;
    }

    if (lseek(fd, pTrunkInfo->file.offset, SEEK_SET) < 0)
    {
        result = errno != 0 ? errno : EIO;
        close(fd);
        return result;
    }

    read_bytes = read(fd, buff, FDFS_TRUNK_FILE_HEADER_SIZE);
    if (read_bytes == FDFS_TRUNK_FILE_HEADER_SIZE)
    {
        result = 0;
    }
    else
    {
        result = errno;
        close(fd);
        return result != 0 ? result : EINVAL;
    }

    memset(pStat, 0, sizeof(struct stat));
    pTrunkHeader->file_type = *(buff + FDFS_TRUNK_FILE_FILE_TYPE_OFFSET);
    if (pTrunkHeader->file_type == FDFS_TRUNK_FILE_TYPE_REGULAR)
    {
        pStat->st_mode = S_IFREG;
    }
    else if (pTrunkHeader->file_type == FDFS_TRUNK_FILE_TYPE_LINK)
    {
        pStat->st_mode = S_IFLNK;
    }
    else if (pTrunkHeader->file_type == FDFS_TRUNK_FILE_TYPE_NONE)
    {
        close(fd);
        return ENOENT;
    }
    else
    {
        close(fd);
        logError("file: "__FILE__", line: %d, " \
                 "Invalid file type: %d", __LINE__, \
                 pTrunkHeader->file_type);
        return ENOENT;
    }

    trunk_pack_header(pTrunkHeader, pack_buff);

    /*
    {
    char temp[265];
    char szHexBuff[2 * FDFS_TRUNK_FILE_HEADER_SIZE + 1];
    FDFSTrunkHeader trueTrunkHeader;

    fprintf(stderr, "file: "__FILE__", line: %d, true buff=%s\n", __LINE__, \
    	bin2hex(buff+1, FDFS_TRUNK_FILE_HEADER_SIZE - 1, szHexBuff));
    trunk_unpack_header(buff, &trueTrunkHeader);
    fprintf(stderr, "file: "__FILE__", line: %d, true fields=%s\n", __LINE__, \
    	trunk_header_dump(&trueTrunkHeader, full_filename, sizeof(full_filename)));

    fprintf(stderr, "file: "__FILE__", line: %d, my buff=%s\n", __LINE__, \
    	bin2hex(pack_buff+1, FDFS_TRUNK_FILE_HEADER_SIZE - 1, szHexBuff));
    fprintf(stderr, "file: "__FILE__", line: %d, my trunk=%s, my fields=%s\n", __LINE__, \
    	trunk_info_dump(pTrunkInfo, temp, sizeof(temp)), \
    	trunk_header_dump(pTrunkHeader, full_filename, sizeof(full_filename)));
    }
    */

    if (memcmp(pack_buff, buff, FDFS_TRUNK_FILE_HEADER_SIZE) != 0)
    {
        close(fd);
        return ENOENT;
    }

    pStat->st_size = pTrunkHeader->file_size;
    pStat->st_mtime = pTrunkHeader->mtime;

    if (pfd != NULL)
    {
        *pfd = fd;
    }
    else
    {
        close(fd);
    }

    return 0;
}
예제 #11
0
UINT32 TrackerMgr::GetStorageStat(ConnectionInfo *pTrackerServer,
	TCHAR *pszGroupName, FDFSStorageStat *pStat, UINT32 nLen,
	UINT32 *pnStatCount)
{
	UINT32 nRet;
	UINT64 nInBytes;
	StorageStat rawStat[FDFS_MAX_GROUPS];
	BYTE byOut[sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN];
	memset(byOut, 0, sizeof(byOut));
	memset(pStat, 0, sizeof(FDFSStorageStat) * nLen);
	UINT32 nNameLen = strlen(pszGroupName);
	if (nNameLen > FDFS_GROUP_NAME_MAX_LEN)
	{
		nNameLen = FDFS_GROUP_NAME_MAX_LEN;
	}

	TrackerHeader *pHeader = (TrackerHeader*)byOut;
	pHeader->byCmd = TRACKER_PROTO_CMD_SERVER_LIST_STORAGE;
	memcpy(byOut + sizeof(TrackerHeader), pszGroupName, nNameLen);
	long642buff(FDFS_GROUP_NAME_MAX_LEN, (char*)pHeader->byPkgLen);

	EnterCriticalSection(&pTrackerServer->csSend);
	if ((nRet = tcpsenddata_nb(pTrackerServer->sock, byOut, sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN, DEFAULT_NETWORK_TIMEOUT)) != 0)
	{
		closesocket(pTrackerServer->sock);
		pTrackerServer->sock = INVALID_SOCKET;
		LeaveCriticalSection(&pTrackerServer->csSend);
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat tcpsenddata_nb Header Failed, Error Code:%d"), nRet);
		return enumNetworkError_FDFS;
	}

	TrackerHeader resp;
	int nCount = 0;
	EnterCriticalSection(&pTrackerServer->csRecv);
	if ((nRet = tcprecvdata_nb(pTrackerServer->sock, &resp, sizeof(resp), DEFAULT_NETWORK_TIMEOUT, &nCount)) != 0)
	{
		closesocket(pTrackerServer->sock);
		pTrackerServer->sock = INVALID_SOCKET;
		LeaveCriticalSection(&pTrackerServer->csRecv);
		LeaveCriticalSection(&pTrackerServer->csSend);
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat tcprecvdata_nb Header Failed, Error Code:%d"), nRet);
		return enumNetworkError_FDFS;
	}

	if (resp.byStatus != 0)
	{
		closesocket(pTrackerServer->sock);
		pTrackerServer->sock = INVALID_SOCKET;
		LeaveCriticalSection(&pTrackerServer->csRecv);
		LeaveCriticalSection(&pTrackerServer->csSend);
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat Status Error, %d"), resp.byStatus);
		return enumFailure_FDFS;
	}

	nInBytes = buff2long64((const char*)(resp.byPkgLen));
	if (nInBytes < 0 || (nInBytes % sizeof(StorageStat)) != 0 || (nInBytes / sizeof(StorageStat)) > FDFS_MAX_SERVERS_EACH_GROUP)
	{
		closesocket(pTrackerServer->sock);
		pTrackerServer->sock = INVALID_SOCKET;
		LeaveCriticalSection(&pTrackerServer->csRecv);
		LeaveCriticalSection(&pTrackerServer->csSend);
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat Packet Len Error"));
		return enumFailure_FDFS;
	}
	*pnStatCount = nInBytes / sizeof(StorageStat);

	//包头接收完毕,接收Body
	if ((nRet = tcprecvdata_nb(pTrackerServer->sock, rawStat, nInBytes, DEFAULT_NETWORK_TIMEOUT, &nCount)) != 0)
	{
		closesocket(pTrackerServer->sock);
		pTrackerServer->sock = INVALID_SOCKET;
		LeaveCriticalSection(&pTrackerServer->csRecv);
		LeaveCriticalSection(&pTrackerServer->csSend);
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat tcprecvdata_nb Body Failed, Error Code:%d"), nRet);
		return enumNetworkError_FDFS;
	}
	LeaveCriticalSection(&pTrackerServer->csRecv);
	LeaveCriticalSection(&pTrackerServer->csSend);

	//数据接收完毕,开始处理
	if(nLen < *pnStatCount)
	{
		WriteLogInfo(LogFileName, FDFSC_ERROR_MODE, _T("TrackerMgr::GetStorageStat Storages Is Too Many"));
		return enumFailure_FDFS;
	}
	
	StorageStatBuff *pStatBuff = NULL;
	StorageStat *pSrc = NULL;
	FDFSStorageInfo *pStorageInfo = NULL;
	FDFSStorageStat *pDest = NULL;

	for(int i = 0; i < *pnStatCount; i++)
	{
		pDest = &pStat[i];
		pSrc = &rawStat[i];
		pStatBuff = &(pSrc->statBuff);
		pStorageInfo = &(pDest->stat);

		pDest->byStatus = pSrc->byStatus;
		//保留最后一个\0
		memcpy(pDest->szID, pSrc->byID, FDFS_STORAGE_ID_MAX_SIZE - 1);
		memcpy(pDest->szIpAddr, pSrc->byIP, IP_ADDRESS_SIZE - 1);
		memcpy(pDest->szSrcId, pSrc->bySrcID, FDFS_STORAGE_ID_MAX_SIZE - 1);
		strcpy(pDest->szDomainName, (const char*)pSrc->byDomainName);
		strcpy(pDest->szVersion, (const char*)pSrc->byVersion);
		pDest->joinTime = buff2long64((const char*)pSrc->byJoinTime);
		pDest->upTime = buff2long64((const char*)pSrc->byUpTime);
		pDest->nTotalMb = buff2long64((const char*)pSrc->byTotalMB);
		pDest->nFreeMb = buff2long64((const char*)pSrc->byFreeMB);
		pDest->nUploadPriority = buff2long64((const char*)pSrc->byUploadPriority);
		pDest->nStorePathCount = buff2long64((const char*)pSrc->byStorePathCount);
		pDest->nSubdirCountPerPath = buff2long64((const char*)pSrc->bySubdirCountPerPath);
		pDest->nStoragePort = buff2long64((const char*)pSrc->byStoragePort);
		pDest->nStorageHttpPort = buff2long64((const char*)pSrc->byStorageHttpPort);
		pDest->nCurrentWritePath = buff2long64((const char*)pSrc->byCurrentWritePath);

		pStorageInfo->connection.nAllocCount = buff2int((const char*)pStatBuff->connection.byAllocCount);
		pStorageInfo->connection.nCurrentCount = buff2int((const char*)pStatBuff->connection.byCurrentCount);
		pStorageInfo->connection.nMaxCount = buff2int((const char*)pStatBuff->connection.byMaxCount);

		pStorageInfo->nTotalUploadCount = buff2long64((const char*)pStatBuff->byTotalUploadCount);
		pStorageInfo->nSuccessUploadCount = buff2long64((const char*)pStatBuff->bySuccessUploadCount);
		pStorageInfo->nTotalAppendCount = buff2long64((const char*)pStatBuff->byTotalAppendCount);
		pStorageInfo->nSuccessAppendCount = buff2long64((const char*)pStatBuff->bySuccessAppendCount);
		pStorageInfo->nTotalModifyCount = buff2long64((const char*)pStatBuff->byTotalModifyCount);
		pStorageInfo->nSuccessModifyCount = buff2long64((const char*)pStatBuff->bySuccessModifyCount);
		pStorageInfo->nTotalTruncateCount = buff2long64((const char*)pStatBuff->byTotalTruncateCount);
		pStorageInfo->nSuccessTruncateCount = buff2long64((const char*)pStatBuff->bySuccessTruncateCount);
		pStorageInfo->nTotalSetMetaCount = buff2long64((const char*)pStatBuff->byTotalSetMetaCount);
		pStorageInfo->nSuccessSetMetaCount = buff2long64((const char*)pStatBuff->bySuccessSetMetaCount);

		pStorageInfo->nTotalDeleteCount = buff2long64((const char*)pStatBuff->byTotalDeleteCount);
		pStorageInfo->nSuccessDeleteCount = buff2long64((const char*)pStatBuff->bySuccessDeleteCount);
		pStorageInfo->nTotalDownloadCount = buff2long64((const char*)pStatBuff->byTotalDownloadCount);
		pStorageInfo->nSuccessDownloadCount = buff2long64((const char*)pStatBuff->bySuccessDownloadCount);
		pStorageInfo->nTotalGetMetaCount = buff2long64((const char*)pStatBuff->byTotalGetMetaCount);
		pStorageInfo->nSuccessGetMetaCount = buff2long64((const char*)pStatBuff->bySuccessGetMetaCount);
		pStorageInfo->lastSourceUpdate = buff2long64((const char*)pStatBuff->byLastSourceUpdate);
		pStorageInfo->lastSyncUpdate = buff2long64((const char*)pStatBuff->byLastSyncUpdate);
		pStorageInfo->lastSyncedTimestamp = buff2long64((const char*)pStatBuff->byLastSyncedTimestamp);
		pStorageInfo->nTotalCreateLinkCount = buff2long64((const char*)pStatBuff->byTotalCreateLinkCount);
		pStorageInfo->nSuccessCreateLinkCount = buff2long64((const char*)pStatBuff->bySuccessCreateLinkCount);
		pStorageInfo->nTotalDeleteLinkCount = buff2long64((const char*)pStatBuff->byTotalDeleteLinkCount);
		pStorageInfo->nSuccessDeleteLinkCount = buff2long64((const char*)pStatBuff->bySuccessDeleteLinkCount);
		pStorageInfo->nTotalUploadBytes = buff2long64((const char*)pStatBuff->byTotalUploadBytes);
		pStorageInfo->nSuccessUploadBytes = buff2long64((const char*)pStatBuff->bySuccessUploadBytes);
		pStorageInfo->nTotalAppendBytes = buff2long64((const char*)pStatBuff->byTotalAppendBytes);
		pStorageInfo->nSuccessAppendBytes = buff2long64((const char*)pStatBuff->bySuccessAppendBytes);
		pStorageInfo->nTotalModifyBytes = buff2long64((const char*)pStatBuff->byTotalModifyBytes);
		pStorageInfo->nSuccessModifyBytes = buff2long64((const char*)pStatBuff->bySuccessModifyBytes);
		pStorageInfo->nTotalDownloadBytes = buff2long64((const char*)pStatBuff->byTotalDownloadBytes);
		pStorageInfo->nSuccessDownloadBytes = buff2long64((const char*)pStatBuff->bySuccessDownloadBytes);
		pStorageInfo->nTotalSyncInBytes = buff2long64((const char*)pStatBuff->byTotalSyncInBytes);
		pStorageInfo->nSuccessSyncInBytes = buff2long64((const char*)pStatBuff->bySuccessSyncInBytes);
		pStorageInfo->nTotalSyncOutBytes = buff2long64((const char*)pStatBuff->byTotalSyncOutBytes);
		pStorageInfo->nSuccessSyncOutBytes = buff2long64((const char*)pStatBuff->bySuccessSyncOutBytes);
		pStorageInfo->nTotalFileOpenCount = buff2long64((const char*)pStatBuff->byTotalFileOpenCount);
		pStorageInfo->nSuccessFileOpenCount = buff2long64((const char*)pStatBuff->bySuccessFileOpenCount);
		pStorageInfo->nTotalFileReadCount = buff2long64((const char*)pStatBuff->byTotalFileReadCount);
		pStorageInfo->nSuccessFileReadCount = buff2long64((const char*)pStatBuff->bySuccessFileReadCount);
		pStorageInfo->nTotalFileWriteCount = buff2long64((const char*)pStatBuff->byTotalFileWriteCount);
		pStorageInfo->nSuccessFileWriteCount = buff2long64((const char*)pStatBuff->bySuccessFileWriteCount);
		pStorageInfo->lastHeartBeatTime = buff2long64((const char*)pStatBuff->byLastHeartBeatTime);
		pDest->bIfTrunkServer = pSrc->byIfTrunkServer;
	}
	return enumSuccess_FDFS;
}