/***************************************************************************
                Inode.cpp
                -----------------------------------------
    begin      : 2011/10/06
    copyright  : (C) 2005 SolutionBox Inc.
    author     : Service 1 Team
    email      : svc1@solbox.com

    CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
    Redistribution and use in source and binary forms, with or with out
    modification, are not permitted in outside of SolutionBox Inc.
***************************************************************************/
#include "Inode.h"
#include <errno.h>
#include <string.h>

using namespace std;

CInode::CInode()
{
	m_szFilename	= "";
	m_nDeviceId		= 0;
	m_nInum			= 0;
	m_nMode			= 0;
	m_nSize			= 0;
	m_nATime		= 0;
	m_nMTime		= 0;
	m_nCTime		= 0;
}

CInode::~CInode()
{
}

void CInode::Print( int logLevel )
{
	_LOG_( logLevel, "Print info of %s.", m_szFilename.c_str() );
	_LOG_( logLevel, "     filename   = %s", m_szFilename.c_str() );
	_LOG_( logLevel, "     device id  = %lu", m_nDeviceId );
	_LOG_( logLevel, "     inode num  = %lld", m_nInum );
	_LOG_( logLevel, "     mode       = %d", m_nMode );
	_LOG_( logLevel, "     size       = %lld", m_nSize );
	_LOG_( logLevel, "     ATime      = %jd", m_nATime );
	_LOG_( logLevel, "     MTime      = %jd", m_nMTime );
	_LOG_( logLevel, "     CTime      = %jd", m_nCTime );
}

bool CInode::LoadInfo( std::string path )
{
    if( path.length() == 0 )
    {   
        LOG( LWAR, "can't get inode because input parameter filename is empty." );
		return false;
    }
    
    struct stat statbuf;
    
    if( stat( path.c_str(), &statbuf ) == -1 )
    {   
        LOG( LWAR, "can't get inode because stat(%s) was failed. errno:%d, errmsg:%s", path.c_str(), errno, strerror(errno) );
		return false;
    }
 
	SetFilename( path );
	SetDeviceId( statbuf.st_dev );
	SetInum( statbuf.st_ino ); 
	SetFileMode( statbuf.st_mode ); 
	SetSize( statbuf.st_size ); 
	SetATime( statbuf.st_atime ); 
	SetMTime( statbuf.st_mtime ); 
	SetCTime( statbuf.st_ctime );

	Print(LDEV);



	return true;
}

