Lfs ---> LfsClientLocalImp

#ifndef LFS_CLIENT_LOCAL_IMP_H
#define  LFS_CLIENT_LOCAL_IMPH
#include "CommonDefine.h"
namespace lfs {
class LfsClientLocalImp
{
public:
	int Initialize(const char* nsAddr = NULL);
	int Close(const int fd);
	int Open(const char* fileName, const int flags);
	int Write(const int fd, const void* data, int64_t count);
	int Read(const int fd, void* buf, const int64_t count);
	int Unlink(const char* fileName);
	int Fstat(const int fd, common::FileInfo& buf);
	int64_t SaveFile(char* fileName, const char* localFile, const int32_t flag, const char* nsAddr = NULL);
	int FetchFile(const char* localFile, const char* fileName, const char* nsAddr = NULL);
};
} // Namespace lfs
#endif
 

#include "LfsClientLocalImp.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include  "Log.h"
namespace lfs{
int LfsClientLocalImp::Initialize(const char* nsAddr)
{
	LOG_INFO("Initialized");
	// Global Namespace Init --> Maybe read from Config file
	return 0;
}
int LfsClientLocalImp::Close(const int fd)
{
	if(fd < 0)
	{
		LOG_ERROR("fd error!");
		return -1;
	}
	return ::close(fd);
}
int LfsClientLocalImp::Open(const char* fileName, const int flags)
{
	if(fileName == NULL)
	{
		LOG_ERROR("file Name NULL");
		return -1;
	}
	return ::open(fileName, flags);
}
int LfsClientLocalImp::Write(const int fd, const void* data, int64_t count)
{
	if(fd < 0 || data == NULL || count < 0)
	{
		LOG_ERROR("fd error or data NULL or count < 0!");
		return -1;
	}
	return ::write(fd, data, count);
}
int LfsClientLocalImp::Read(const int fd, void* buf, const int64_t count)
{
	if(fd < 0 || buf == NULL || count < 0)
	{
		LOG_ERROR("fd error or data NULL or count < 0!");
		return -1;
	}
	return ::read(fd, buf, count);
}
int LfsClientLocalImp::Unlink(const char* fileName)
{
	if(fileName == NULL)
	{
		LOG_ERROR("fileName NULL");
		return -1;
	}
	return unlink(fileName);
}
int LfsClientLocalImp::Fstat(const int fd, common::FileInfo& buf)
{
	struct stat fst;
	int ret = ::fstat(fd, &fst);
	if(ret != 0 )
	{
		LOG_ERROR("get the file info error from OS!");	
		return -1;
	}
	buf.ID = fst.st_ino;
	buf.Size = fst.st_size;
    buf.UsedSize = fst.st_blksize * fst.st_blocks;
    buf.ModifyTime = fst.st_mtime;
    buf.CreateTime = fst.st_ctime;
	return 0;
}
int64_t LfsClientLocalImp::SaveFile(char* fileName, const char* localFile, const int32_t flag, const char* nsAddr)
{
	LOG_INFO("Not Support, save file....");
	return 0;
}
int LfsClientLocalImp::FetchFile(const char* localFile, const char* fileName, const char* nsAddr)
{
	LOG_INFO("Not Support, fetch file....");
	return 0;
}
}/* end namespace lfs */
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值