Example #1
0
bool zz_vfs_local::get_mtime (const char * file_name, uint64 * t) const
{
    struct __stat64 st;

    if (_stat64(file_name, &st) != 0) {
        return false;
    }
    *t = st.st_mtime;
    return true;
}
Example #2
0
uint64_t fsize(const char *filename)
{
#if __MINGW32__
	struct __stat64 st;
	if (_stat64(filename, &st) == 0) return st.st_size;
#else
	struct stat st;
	if (stat(filename, &st) == 0) return st.st_size;
#endif
	return 0;
}
Example #3
0
int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
{
    int r;
#if defined(_MSC_VER)
    r = _stat64(infilename, statbuf);
    if (r || !(statbuf->st_mode & S_IFREG)) return 0;   /* No good... */
#else
    r = stat(infilename, statbuf);
    if (r || !S_ISREG(statbuf->st_mode)) return 0;   /* No good... */
#endif
    return 1;
}
Example #4
0
//Char IO
bool AssertFile(char *filename)
{
	if(filename == NULL)
		return false;
#ifdef _WIN32
	struct _stat64 st;
	return _stat64(filename, &st) == 0;
#else
	struct stat st;
	return stat(filename, &st) == 0;
#endif
}
Example #5
0
U32 UTIL_isDirectory(const char* infilename)
{
    int r;
    stat_t statbuf;
#if defined(_MSC_VER)
    r = _stat64(infilename, &statbuf);
    if (!r && (statbuf.st_mode & _S_IFDIR)) return 1;
#else
    r = stat(infilename, &statbuf);
    if (!r && S_ISDIR(statbuf.st_mode)) return 1;
#endif
    return 0;
}
Example #6
0
static U64 BMK_GetFileSize(char* infilename)
{
    int r;
#if defined(_MSC_VER)
    struct _stat64 statbuf;
    r = _stat64(infilename, &statbuf);
#else
    struct stat statbuf;
    r = stat(infilename, &statbuf);
#endif
    if (r || !S_ISREG(statbuf.st_mode)) return 0;   // No good...
    return (U64)statbuf.st_size;
}
Example #7
0
long kGUISystemWin::FileTime(const char *fn)
{
   struct __stat64 buf;
   int result;

   result = _stat64( fn, &buf );

   /* Check if statistics are valid: */
   if( result != 0 )
		return(0);
   else
		return((long)buf.st_mtime);
}
Example #8
0
hpatch_BOOL _hpatch_getPathStat_noEndDirSeparator(const char* path_utf8,hpatch_TPathType* out_type,
                                                  hpatch_StreamPos_t* out_fileSize,size_t* out_st_mode){
#if (_IS_USED_WIN32_UTF8_WAPI)
    int            wsize;
    wchar_t        path_w[hpatch_kPathMaxSize];
    struct _stat64 s;
#else
#   ifdef _MSC_VER
    struct _stat64 s;
#   else
    struct stat  s;
#   endif
#endif
    
    int          rt;
    assert(out_type!=0);
    memset(&s,0,sizeof(s));
#if (_IS_USED_WIN32_UTF8_WAPI)
    wsize=_utf8FileName_to_w(path_utf8,path_w,hpatch_kPathMaxSize);
    if (wsize<=0) return hpatch_FALSE;
    rt = _wstat64(path_w,&s);
#else
#   ifdef _MSC_VER
    rt = _stat64(path_utf8,&s);
#   else
    rt = stat(path_utf8,&s);
#   endif
#endif
    
    if(rt!=0){
        if (errno==ENOENT){
            *out_type=kPathType_notExist;
            return hpatch_TRUE;
        }
        return hpatch_FALSE; //error
    }else if ((s.st_mode&S_IFMT)==S_IFREG){
        *out_type=kPathType_file;
        if (out_fileSize) *out_fileSize=s.st_size;
        if (out_st_mode) *out_st_mode=s.st_mode;
        return hpatch_TRUE;
    }else if ((s.st_mode&S_IFMT)==S_IFDIR){
        *out_type=kPathType_dir;
        if (out_fileSize) *out_fileSize=0;
        if (out_st_mode) *out_st_mode=s.st_mode;
        return hpatch_TRUE;
    }else{
        return hpatch_FALSE; //as error; unknow how to dispose
    }
}
Example #9
0
int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer)
{
	if (!utf8_filenames) {
		return _stat64(path, buffer);
	} else {
		wchar_t *wpath;
		int ret;

		if (!(wpath = wchar_from_utf8(path))) return -1;
		ret = _wstat64(wpath, buffer);
		free(wpath);

		return ret;
	}
}
Example #10
0
u64 GetFileSize64(char *filename)
{
#ifdef _WIN32
	struct _stat64 st;
	if( _stat64(filename, &st) != 0)
		return 0;
	else
		return st.st_size;
#else
	struct stat st;
	if( stat(filename, &st) != 0)
		return 0;
	else
		return st.st_size;
#endif
}
Example #11
0
File: path.c Project: pedrox/kmod
TS_EXPORT int stat64(const char *path, struct stat64 *st)
{
	const char *p;
	char buf[PATH_MAX * 2];
	static int (*_stat64)(const char *path, struct stat64 *buf);

	if (!get_rootpath(__func__))
		return -1;

	_stat64 = get_libc_func("stat64");

	p = trap_path(path, buf);
	if (p == NULL)
		return -1;

	return _stat64(p, st);
}
Example #12
0
Response::Response(RequestParser p)
  : parser(p),
    mode(INTERNAL_ERROR),
    fileLength(-1),
    file(0),
    rangeStart(0),
    rangeEnd(0),
    offset(0),
    bytesRemaining(0)
{
  string target = parser.GetTarget();
  if (target == "") {
    mode = DIR_LIST;
    path = ".";
  } else if (target.find("..") != string::npos) {
    mode = ERROR_FILE_NOT_EXIST;
  } else {
    // Determine if the file exists, and if it is a directory.
    struct __stat64 buf;
    int result;
    result = _stat64(target.c_str(), &buf );
    if (result == -1) {
      cerr << "File not found" << std::endl;
      mode = ERROR_FILE_NOT_EXIST;
    } else if (result != 0) {
      mode = INTERNAL_ERROR;
    } else if (S_ISDIR(buf.st_mode)) {
      mode = DIR_LIST;
      path = parser.GetTarget();
    } else if (parser.IsRangeRequest() && !parser.IsLive()) {
      mode = GET_FILE_RANGE;
      path = parser.GetTarget();
      parser.GetRange(rangeStart, rangeEnd);
      if (rangeEnd == -1) {
        rangeEnd = buf.st_size;
      }
      fileLength = buf.st_size;
    } else {
      mode = GET_ENTIRE_FILE;
      path = parser.GetTarget();
      fileLength = buf.st_size;
    }
  }
}
bool ON::IsDirectory( const char* utf8pathname )
{
  bool rc = false;

  if ( 0 != utf8pathname && 0 != utf8pathname[0] )
  {
    ON_String buffer;
    const char* stail = utf8pathname;
    while ( 0 != *stail )
      stail++;
    stail--;
    if ( '\\' == *stail || '/' == *stail ) 
    {
      const char trim[2] = {*stail,0};
      buffer = utf8pathname;
      buffer.TrimRight(trim);
      if ( buffer.Length() > 0 )
        utf8pathname = buffer;
    }
#if defined(ON_COMPILER_MSC)
    // this works on Windows
    struct _stat64 buf;
    memset(&buf,0,sizeof(buf));
    int stat_errno = _stat64( utf8pathname, &buf );
    if ( 0 == stat_errno && 0 != (_S_IFDIR & buf.st_mode) )
    {
      rc = true;
    }
#else
    // this works on Apple and gcc implentations.
    struct stat buf;
    memset(&buf,0,sizeof(buf));
    int stat_errno = stat( utf8pathname, &buf );
    if ( 0 == stat_errno && S_ISDIR(buf.st_mode) )
    {
      rc = true;
    }
#endif
  }

  return rc;
}
Example #14
0
bool getPathInfo(const char * name, fileInfo & info)
{
	// we don't handle symbolic links as destinations
	if (name == NULL)
		return false;

	int result;
#ifdef WINDOWS
	struct __stat64 buf;
	result = _stat64(name, &buf);
#else
	struct stat64 buf;
	result = stat64(name, &buf);
#endif

	info.isDir = (buf.st_mode & S_IFDIR) != 0;
	info.isFile = (buf.st_mode & S_IFREG) != 0;

	return result == 0 ? true : false;
}
Example #15
0
FileInfo::FileInfo( const Path& path, bool followSymbolicLinks )
{
#if defined(__WIN32__)
	if( _stat64(path.absolute().c_str(), &m_Stat) != -1 )
		return;
#else
	if( followSymbolicLinks )
	{
		if( stat(path.absolute().c_str(), &m_Stat) != -1 )
			return;
	}
	else
	{
		if( lstat(path.absolute().c_str(), &m_Stat) != -1 )
			return;
	}
#endif
	
	std::memset(&m_Stat, 0, sizeof(m_Stat));
}
Example #16
0
U64 UTIL_getFileSize(const char* infilename)
{
    if (!UTIL_isRegularFile(infilename)) return UTIL_FILESIZE_UNKNOWN;
    {   int r;
#if defined(_MSC_VER)
        struct __stat64 statbuf;
        r = _stat64(infilename, &statbuf);
        if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
#elif defined(__MINGW32__) && defined (__MSVCRT__)
        struct _stati64 statbuf;
        r = _stati64(infilename, &statbuf);
        if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
#else
        struct stat statbuf;
        r = stat(infilename, &statbuf);
        if (r || !S_ISREG(statbuf.st_mode)) return UTIL_FILESIZE_UNKNOWN;
#endif
        return (U64)statbuf.st_size;
    }
}
Example #17
0
bool MsgLogger::DoDivide() {
    bool logFileExist = false;
    struct _stat64 st;
    if (0 == _stat64(m_logFileName.c_str(), &st))
        logFileExist = (st.st_size > 0);

    if (logFileExist) {
        time_t ttNow = time(NULL);
        tm tmNow;
        localtime_s(&tmNow, &ttNow);

        char historyFileName[256];
        strftime(historyFileName, 256, m_historyFileNamePattern.c_str(), &tmNow);

        rename(m_logFileName.c_str(), historyFileName);
    }

    fopen_s(&m_logFile, m_logFileName.c_str(), "wb");
    m_fileLen = 0;
    return (m_logFile != NULL);
}
Example #18
0
vfspos GetFileSize(const char* fn)
{
#ifdef VFS_LARGEFILE_SUPPORT
# ifdef _MSC_VER
    struct _stat64 st;
    if(_stat64(fn, &st))
        return 0;
    return st.st_size;
# else // _MSC_VER
    struct stat64 st;
    if(stat64(fn, &st))
        return 0;
    return st.st_size;
# endif
#else // VFS_LARGEFILE_SUPPORT
    struct stat st;
    if(stat(fn, &st))
        return 0;
    return st.st_size;
#endif
}
Example #19
0
File: stat.c Project: cosinuz/ponyc
bool os_stat(const char* path, pony_stat_t* p)
{
#if defined(PLATFORM_IS_WINDOWS)
  WIN32_FILE_ATTRIBUTE_DATA fa;

  if(!GetFileAttributesEx(path, GetFileExInfoStandard, &fa))
    return false;

  struct __stat64 st;

  if(_stat64(path, &st) != 0)
  {
    // Report a broken symlink with no other information.
    p->symlink = true;
    p->broken = true;
    return true;
  }

  windows_stat(path, p, &st, fa.dwFileAttributes,
    &fa.ftLastAccessTime, &fa.ftLastWriteTime, &fa.ftCreationTime);

  return true;
#elif defined(PLATFORM_IS_POSIX_BASED)
  struct stat st;

  if(lstat(path, &st) != 0)
    return false;

  unix_stat(p, &st);

  if(p->symlink && (stat(path, &st) != 0))
  {
    // Report a broken symlink with everything set except the size.
    p->broken = true;
    p->size = 0;
  }

  return true;
#endif
}
Example #20
0
void GRaportManager::UpdateTime(GClock & clock)
{
	if(!time_period(clock)) return;

	if(flush_period(clock))
	{
		if(raport_file) 
		{
			fflush(raport_file);
#ifdef LINUX
			struct stat buf;
			int ret= stat( file_name, &buf );
#else
			struct __stat64 buf;
			int ret= _stat64( file_name, &buf );
#endif
			if(ret==-1){fclose(raport_file);raport_file=NULL;wait_for_data=true;}
		}
		overflow_lines=0;
	}
	UpdateName(clock);
}
Example #21
0
int opal_os_dirpath_access(const char *path, const mode_t in_mode ) {
#ifndef __WINDOWS__
    struct stat buf;
#else
#  ifndef _MSC_VER
    struct stat buf;
#  else
    struct __stat64 buf;
#  endif
#endif
    mode_t loc_mode = S_IRWXU;  /* looking for full rights */

    /*
     * If there was no mode specified, use the default mode
     */
    if( 0 != in_mode ) {
        loc_mode = in_mode;
    }

#ifndef __WINDOWS__
    if (0 == stat(path, &buf)) { /* exists - check access */
#else
    if (0 == _stat64(path, &buf)) { /* exist -- check */
#endif
        if ((buf.st_mode & loc_mode) == loc_mode) { /* okay, I can work here */
            return(OPAL_SUCCESS);
        }
        else {
            /* Don't have access rights to the existing path */
            return(OPAL_ERROR);
        }
    }
    else {
        /* We could not find the path */
        return( OPAL_ERR_NOT_FOUND );
    }
}
Example #22
0
int lstat64(const char *path, struct stat64 *statp) {
	return _stat64(path, statp, S_IFLNK);
}
Example #23
0
int stat64(const char *path, struct stat64 *statp) {
	return _stat64(path, statp, 0);
}
Example #24
0
//
// Target can be file name
// Arg[0]: Device number. Optional
//
// From NdasOpReadDIB, LurnRMDRead
//
int CmdViewMeta(char* target, char* arg[])
{
	UINT64 Pos = 10;
	int retval = 0;
	SOCKET				connsock;
	PUCHAR				data = NULL;
	int					iResult;
	unsigned			UserId;
	FILE*	file = NULL;
	NDAS_DIB_V2 DIB_V2;
	NDAS_RAID_META_DATA Rmd;
	NDAS_LAST_WRITTEN_REGION_BLOCK Lwr;
	UINT32 i, j;
	
	BOOL IsTargetFile;
	UINT64 DiskSectorCount;
	char* str;
	PNDAS_UNIT_META_DATA UnitMeta;
	data = (PUCHAR) malloc(MAX_DATA_BUFFER_SIZE);

	if (strcspn(target, ":") >=strlen(target)) {
		IsTargetFile = TRUE;
	} else {
		IsTargetFile = FALSE;
	}
	if (IsTargetFile) {
		struct __stat64 statbuff;

		file = fopen(target, "r");
		if (file ==NULL) {
			fprintf(stderr, "Failed to open file\n");
			retval = GetLastError();
			goto errout; 
		}
		iResult = _stat64(target, &statbuff);
		if (iResult !=0) {
			fprintf(stderr, "Failed to get stat file\n");
			goto errout;
		}
		DiskSectorCount = statbuff.st_size/BLOCK_SIZE;
	} else {
		int dev;
		UserId = MAKE_USER_ID(DEFAULT_USER_NUM, USER_PERMISSION_SW);

		if (arg[0])
			dev = (int) _strtoi64(arg[0], NULL, 0);
		else 
			dev = 0;
		if (dev==0) {
			//
		} else {
			UserId |= 0x100;
		}

		if (ConnectToNdas(&connsock, target, UserId, NULL) !=0)
			goto errout;
		// Need to get disk info before IO
		if((iResult = GetDiskInfo(connsock, iTargetID, TRUE, TRUE)) != 0) {
			fprintf(stderr, "GetDiskInfo Failed...\n");
			retval = iResult;
			goto errout;
		}
		DiskSectorCount = PerTarget[iTargetID].SectorCount;
	}
	fprintf(stderr,"Total sector count = %I64d\n", DiskSectorCount);

	// Read an NDAS_DIB_V2 structure from the NDAS Device at NDAS_BLOCK_LOCATION_DIB_V2
	if (IsTargetFile) {
		iResult = fseek(file, (long)((DiskSectorCount + NDAS_BLOCK_LOCATION_DIB_V2)*BLOCK_SIZE), SEEK_SET);
		if (iResult != 0) {
			fprintf(stderr, "fseek error\n");
			goto errout;
		}
		iResult = (int)fread((void*)&DIB_V2, 512, 1, file);
		if (iResult == 0) {
			fprintf(stderr, "fread error\n");
			goto errout;
		}
	} else {
		iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_DIB_V2, 1, 0, sizeof(DIB_V2), (PCHAR)&DIB_V2, 0, 0);
		if (iResult != 0) {
			fprintf(stderr, "READ Failed.\n");
			goto errout;
		}
	}

	// Check Signature, Version and CRC informations in NDAS_DIB_V2 and accept if all the informations are correct
	if(NDAS_DIB_V2_SIGNATURE != DIB_V2.Signature)
	{
		if (DIB_V2.Signature == 0) {
			fprintf(stderr, "No DIBv2 signature. Single disk or uninitialized disk.\n");
		} else {
			fprintf(stderr, "V2 Signature mismatch\n");
		}
		goto errout;
		//goto process_v1;
	}

	if(!IS_DIB_CRC_VALID(crc32_calc, DIB_V2))
	{
		fprintf(stderr, "CRC mismatch\n");
		goto errout;
//		goto process_v1;
	}

	if(NDAS_BLOCK_SIZE_XAREA != DIB_V2.sizeXArea &&
		NDAS_BLOCK_SIZE_XAREA * SECTOR_SIZE != DIB_V2.sizeXArea)
	{
		fprintf(stderr, "Reserved size mismatch\n");
		goto errout;
//		goto process_v1;
	}

	if(DIB_V2.sizeUserSpace + DIB_V2.sizeXArea > DiskSectorCount)
	{
		fprintf(stderr, "Disk size mistmatch\n");
		goto errout;
//		goto process_v1;
	}

#if 0
	nTotalDiskCount = DIB_V2.nDiskCount + DIB_V2.nSpareCount;
	// check DIB_V2.nDiskCount
	if(!NdasOpVerifyDiskCount(DIB_V2.iMediaType, DIB_V2.nDiskCount))
		goto process_v1;
#endif
	// Dump DIB info
	printf("DIBV2 Major Version = %d, Minor version = %d\n", DIB_V2.MajorVersion, DIB_V2.MinorVersion);
	printf("User Space in sectors=%I64d, X space=%I64d\n", DIB_V2.sizeUserSpace, DIB_V2.sizeXArea);
	printf("Bitmap sector per bit=%d(%fMbyte)\n", DIB_V2.iSectorsPerBit, DIB_V2.iSectorsPerBit / 2.0/1024);
	switch(DIB_V2.iMediaType) {
	case NMT_SINGLE:		str="Single"; break;
	case NMT_MIRROR:		str="Mirror without repair info"; break;
	case NMT_AGGREGATE:		str="Aggregation"; break;
	case NMT_RAID0:			str="RAID0"; break;
	case NMT_RAID1:			str="RAID1(~3.10)"; break;
	case NMT_RAID4:			str="RAID4(~3.10)"; break;
	case NMT_RAID1R2:		str="RAID1(3.11~)"; break;
	case NMT_RAID4R2:		str="RAID4(3.11~)"; break;
	case NMT_RAID1R3:		str="RAID1(3.20~)"; break;
	case NMT_RAID4R3:		str="RAID4(3.20~)"; break;
	case NMT_AOD:			str="Append only disk"; break;
	case NMT_VDVD:			str="Virtual DVD"; break;
	case NMT_CDROM:			str="packet device, CD / DVD"; break;
	case NMT_OPMEM:			str="packet device, Magnetic Optical"; break;
	case NMT_FLASH:			str="flash card"; break;
	default: str="Unknown"; break;
	}
	printf("Media type=%d(%s)\n", DIB_V2.iMediaType, str);

	printf("Diskcount=%d, Sequence=%d, SpareCount=%d\n", 
		DIB_V2.nDiskCount, DIB_V2.iSequence, DIB_V2.nSpareCount);

	for(i=0;i<DIB_V2.nDiskCount+DIB_V2.nSpareCount;i++) {
		printf(" * Unit disk %d: ", i);
		printf("MAC %02x:%02x:%02x:%02x:%02x:%02x, VID: %x, UnitNumber=%d, HwVersion=%d\n",
			DIB_V2.UnitDisks[i].MACAddr[0], DIB_V2.UnitDisks[i].MACAddr[1], DIB_V2.UnitDisks[i].MACAddr[2],
			DIB_V2.UnitDisks[i].MACAddr[3], DIB_V2.UnitDisks[i].MACAddr[4], DIB_V2.UnitDisks[i].MACAddr[5],
			DIB_V2.UnitDisks[i].VID,
			DIB_V2.UnitDisks[i].UnitNumber,
			DIB_V2.UnitDiskInfos[i].HwVersion
			);
	}

	// Show RMD info 

	if (IsTargetFile) {
		iResult = fseek(file, (long)((DiskSectorCount + NDAS_BLOCK_LOCATION_RMD)*BLOCK_SIZE), SEEK_SET);
		if (iResult != 0) {
			fprintf(stderr, "fseek error\n");
			goto errout;
		}
		iResult = (int)fread((void*)&Rmd, 512, 1, file);
		if (iResult == 0) {
			fprintf(stderr, "fread error\n");
			goto errout;
		}
	} else {
		iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_RMD, 1, 0, sizeof(Rmd), (PCHAR)&Rmd, 0, 0);
		if (iResult != 0) {
			fprintf(stderr, "READ Failed.\n");
			goto errout;
		}
	}

	// Check Signature, Version and CRC informations in NDAS_DIB_V2 and accept if all the informations are correct
	if(NDAS_RAID_META_DATA_SIGNATURE != Rmd.Signature)
	{
		fprintf(stderr, "RMD Signature mismatch: %I64x\n", Rmd.Signature);
		goto errout;
		//goto process_v1;
	}

	if(!IS_RMD_CRC_VALID(crc32_calc, Rmd))
	{
		fprintf(stderr, "RMD CRC mismatch\n");
		goto errout;
//		goto process_v1;
	}
	printf("RAID Set ID  = %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n",
		Rmd.guid.Data1, Rmd.guid.Data2, Rmd.guid.Data3,
		Rmd.guid.Data4[0], Rmd.guid.Data4[1], Rmd.guid.Data4[2], Rmd.guid.Data4[3], 
		Rmd.guid.Data4[4], Rmd.guid.Data4[5], Rmd.guid.Data4[6], Rmd.guid.Data4[7]
	);
	printf("Config Set ID= %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n",
		Rmd.ConfigSetId.Data1, Rmd.ConfigSetId.Data2, Rmd.ConfigSetId.Data3,
		Rmd.ConfigSetId.Data4[0], Rmd.ConfigSetId.Data4[1], Rmd.ConfigSetId.Data4[2], Rmd.ConfigSetId.Data4[3], 
		Rmd.ConfigSetId.Data4[4], Rmd.ConfigSetId.Data4[5], Rmd.ConfigSetId.Data4[6], Rmd.ConfigSetId.Data4[7]
	);
	printf("USN: %d\n", Rmd.uiUSN);
	
	switch(Rmd.state & (NDAS_RAID_META_DATA_STATE_MOUNTED | NDAS_RAID_META_DATA_STATE_UNMOUNTED)) {
		case NDAS_RAID_META_DATA_STATE_MOUNTED:	str= "Mounted"; break;
		case NDAS_RAID_META_DATA_STATE_UNMOUNTED:	str= "Unmounted"; break;
		default: str = "Unknown/Never Mounted"; break;
	}
	if (Rmd.state & NDAS_RAID_META_DATA_STATE_USED_IN_DEGRADED) {
		printf("This member is used in degraded mode\n");
	}

	printf("State: %d(%s)\n", Rmd.state, str);
	for(i=0;i<NDAS_DRAID_ARBITER_ADDR_COUNT;i++) {
		if (Rmd.ArbiterInfo[i].Type == 0)
			break;
		printf("DRAID Listen Address: Type %d - %02x:%02x:%02x:%02x:%02x:%02x\n", 
			Rmd.ArbiterInfo[i].Type,
			Rmd.ArbiterInfo[i].Addr[0], Rmd.ArbiterInfo[i].Addr[1], Rmd.ArbiterInfo[i].Addr[2],
			Rmd.ArbiterInfo[i].Addr[3], Rmd.ArbiterInfo[i].Addr[4], Rmd.ArbiterInfo[i].Addr[5]
		);
	}
	for(i=0;i<DIB_V2.nDiskCount+DIB_V2.nSpareCount;i++) {
		char* DefectStr;
		printf(" * Role %d: ", i);
		UnitMeta = &Rmd.UnitMetaData[i];

		printf("Unit index=%d  Status=%d(%s%s%s%s%s%s)\n",
			UnitMeta->iUnitDeviceIdx, UnitMeta->UnitDeviceStatus, 
			(UnitMeta->UnitDeviceStatus==0)?"Normal ":"",
			(UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_NOT_SYNCED)?"Out-of-sync ":"",
			(UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_SPARE)?"Spare ":"",
			(UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_BAD_DISK)?"Bad disk ":"",
			(UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_BAD_SECTOR)?"Bad sector ":"",
			(UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_REPLACED_BY_SPARE)?"Replaced by spare ":""
			);
	}

	//
	// Dump bitmap
	// 
	if (DIB_V2.iMediaType == NMT_RAID1R3) 
	{
		UINT32 BitCount = (UINT32)((DIB_V2.sizeUserSpace + DIB_V2.iSectorsPerBit - 1)/DIB_V2.iSectorsPerBit);
		UINT32 BmpSectorCount = (BitCount + NDAS_BIT_PER_OOS_BITMAP_BLOCK -1)/NDAS_BIT_PER_OOS_BITMAP_BLOCK;
		UINT32 CurBitCount;
		PNDAS_OOS_BITMAP_BLOCK BmpBuffer;
		UCHAR OnBits[] = {1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7};
		UINT32 BitOn, BitOnStart, BitOnEnd;

		printf("\nBitmap sector per bit=0x%x, Bit count =0x%x, BmpSector count=0x%x\n", 
			DIB_V2.iSectorsPerBit, BitCount, BmpSectorCount);
		BmpBuffer = (PNDAS_OOS_BITMAP_BLOCK) malloc(BmpSectorCount* 512);
		iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_BITMAP, (_int16)BmpSectorCount, 0, BmpSectorCount* 512, (PCHAR)BmpBuffer, 0, 0);
		if (iResult != 0) {
			fprintf(stderr, "READ Failed.\n");
			free(BmpBuffer);
			goto errout;
		}
		CurBitCount = 0;
		for(i=0;i<BmpSectorCount;i++) {
			printf("  Bitmap sector %d, Seq head=%I64x, tail=%I64x\n", i, BmpBuffer[i].SequenceNumHead,BmpBuffer[i].SequenceNumTail);
			BitOn = FALSE;
			BitOnStart = BitOnEnd = 0;
			for(j=0;j<NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8;j++) {
				if (BitOn == FALSE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8])) {
					BitOn = TRUE;
					BitOnStart = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j;
					printf("    Bit on from bit %x ~ ", BitOnStart);
				}
				if (BitOn == TRUE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8]) == 0) {
					BitOn = FALSE;
					BitOnEnd = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j;
					printf("%x\n", BitOnEnd-1);
				}
				CurBitCount++;
				if (CurBitCount >= BitCount)
					break;
			}
			if (BitOn == TRUE) {
				printf("%x\n", i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j);
			}
		}
		free(BmpBuffer);
	}
	printf("\n");
	DisconnectFromNdas(connsock, UserId);
errout:
	closesocket(connsock);
	if (data)
		free(data);
	return retval;
}
Example #25
0
void BLI_builddir(const char *dirname, const char *relname)
{
	struct dirent *fname;
	struct dirlink *dlink;
	int rellen, newnum = 0;
	char buf[256];
	DIR *dir;

	strcpy(buf,relname);
	rellen=strlen(relname);

	if (rellen){
		buf[rellen]='/';
		rellen++;
	}

	if (chdir(dirname) == -1){
		perror(dirname);
		return;
	}

	if ( (dir = (DIR *)opendir(".")) ){
		while ((fname = (struct dirent*) readdir(dir)) != NULL) {
			dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
			if (dlink){
				strcpy(buf+rellen,fname->d_name);
				dlink->name = BLI_strdup(buf);
				BLI_addhead(dirbase,dlink);
				newnum++;
			}
		}
		
		if (newnum){

			if(files) {
				void *tmp= realloc(files, (totnum+newnum) * sizeof(struct direntry));
				if(tmp) {
					files= (struct direntry *)tmp;
				}
				else { /* realloc fail */
					free(files);
					files= NULL;
				}
			}
			
			if(files==NULL)
				files=(struct direntry *)malloc(newnum * sizeof(struct direntry));

			if (files){
				dlink = (struct dirlink *) dirbase->first;
				while(dlink){
					memset(&files[actnum], 0 , sizeof(struct direntry));
					files[actnum].relname = dlink->name;
					files[actnum].path = BLI_strdupcat(dirname, dlink->name);
// use 64 bit file size, only needed for WIN32 and WIN64. 
// Excluding other than current MSVC compiler until able to test.
#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500)
					_stat64(dlink->name,&files[actnum].s);
#elif defined(__MINGW32__)
					_stati64(dlink->name,&files[actnum].s);
#else
					stat(dlink->name,&files[actnum].s);
#endif
					files[actnum].type=files[actnum].s.st_mode;
					files[actnum].flags = 0;
					totnum++;
					actnum++;
					dlink = dlink->next;
				}
			} else{
				printf("Couldn't get memory for dir\n");
				exit(1);
			}

			BLI_freelist(dirbase);
			if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))BLI_compare);
		} else {
			printf("%s empty directory\n",dirname);
		}

		closedir(dir);
	} else {
		printf("%s non-existant directory\n",dirname);
	}
}
Example #26
0
bool RAUX::File :: Exists () const
{
	
#if defined ( __APPLE__ )
	
	struct stat FStatData;
	
#elif defined ( _WIN32 )
	
	struct __stat64 FStatData;
	
#else
	
	struct stat64 FStatData;
	
#endif
	
	int ReturnCode;
	
	if ( Opened )
	{
		
#ifdef _WIN32
		
		int FD = _fileno ( Handle );
		
#else
		
		int FD = fileno ( Handle );
		
#endif
		
		if ( FD == - 1 )
			return false;
		
#if defined ( __APPLE__ )
		
		ReturnCode = fstat ( FD, & FStatData );

#elif defined ( _WIN32 )
		
		ReturnCode = _fstat64 ( FD, & FStatData );

#else
		
		ReturnCode = fstat64 ( FD, & FStatData );
		
#endif
		
	}
	else
	{
		
#if defined ( __APPLE__ )
		
		ReturnCode = stat ( Name.c_str (), & FStatData );
		
#elif defined ( _WIN32 )
		
		ReturnCode = _stat64 ( Name.c_str (), & FStatData );
		
#else
		
		ReturnCode = stat64 ( Name.c_str (), & FStatData );
		
#endif
		
	}
	
	if ( ReturnCode == - 1 )
		return false;
	
	return true;
	
}
Example #27
0
int encode_file(char *file, char *base_dir, FILE *fp, int *s_id) {

	char fullname[MAX_PATH_LENGTH];
	char fullpath[MAX_PATH_LENGTH];

#ifdef _MSC_VER
	struct __stat64 file_stats;
#else
	struct stat64 file_stats;
#endif
	int i;

	uri_t *uri = NULL;
	char *hostname = NULL;
	alc_session_t *s = get_alc_session(*s_id);
	char *user = NULL;
	char *uri_str = NULL;	
	
#ifdef USE_ZLIB
	int retcode;
	char enc_fullpath[MAX_PATH_LENGTH];

#ifdef _MSC_VER
	struct __stat64 enc_file_stats;
#else
	struct stat64 enc_file_stats;
#endif
#endif

#ifdef USE_OPENSSL
	char *md5 = NULL;
#endif

#ifdef FDT_INST_FEC_OTI_FILE
	div_t div_max_n;
	int max_n;

	div_max_n = div((s->def_max_sblen * (100 + s->def_fec_ratio)), 100);
	max_n = div_max_n.quot;
#endif

	unsigned long long padding_length;

#ifdef _MSC_VER
	user = getenv("USERNAME");
#else
	user = getenv("USER");
#endif

	memset(fullpath, 0, MAX_PATH_LENGTH);

	if(!(strcmp(base_dir, "") == 0)) {
		strcpy(fullpath, base_dir);

#ifdef _MSC_VER
		strcat(fullpath, "\\");
#else
		strcat(fullpath, "/");
#endif
	}

	strcat(fullpath, file);

#ifdef _MSC_VER
	if(_stat64(fullpath, &file_stats) == -1) {
#else
	if(stat64(fullpath, &file_stats) == -1) {
#endif
		printf("Error: %s is not valid file name\n", fullpath);
		fflush(stdout);
		return -1;
	}

	if(file_stats.st_size == 0) {
		printf("Error: file %s size = 0\n", fullpath);
		fflush(stdout);
		return -1;
	}

	hostname = getdnsname();	

	memset(fullname, 0, MAX_PATH_LENGTH);
	strcpy(fullname, file);

	for(i = 0; i < (int)strlen(fullname); i++) {
		if(fullname[i] == '\\') {
			fullname[i] = '/';
		}
	}

	uri = alloc_uri_struct();

	set_uri_scheme(uri, "file");

	if(user != NULL) {
		set_uri_user(uri, user);
	}	

#ifdef HOSTNAME_TO_FDT
	if(hostname != NULL) {
		set_uri_host(uri, hostname);
	}
#endif

	set_uri_path(uri, fullname);

#ifdef _MSC_VER
	fprintf(fp, "\t<File TOI=\"%I64u\"", toi);
#else
	fprintf(fp, "\t<File TOI=\"%llu\"", toi);
#endif

	uri_str = uri_string(uri);
	
	fprintf(fp, "\n\t\t");
	fprintf(fp, "Content-Location=\"%s\"", uri_str);
	
	free(uri_str);
	
	fprintf(fp, "\n\t\t");
	fprintf(fp, "Content-Length=\"%llu\"", file_stats.st_size);

	if(s->encode_content == 0 || s->encode_content == ZLIB_FDT) {
		if(is_enough_source_block_numbers(s->def_max_sblen, s->def_eslen, file_stats.st_size,
								   s->def_fec_enc_id, s->def_fec_inst_id) < 0) {
			printf("Maximum source block length %i too small for the file: %s\n", s->def_max_sblen, file);
			fflush(stdout);
			if(hostname != NULL) {
				free(hostname);
			}
			free_uri(uri);
			return -1;
		}
	}

	if(s->encode_content == PAD_FILES) {
		padding_length = compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen);

        if(padding_length) {
        	fprintf(fp, "\n\t\t");
        	fprintf(fp, "Content-Encoding=\"%s\"", "pad");

        	fprintf(fp, "\n\t\t");
            fprintf(fp, "Transfer-Length=\"%llu\"", (file_stats.st_size + padding_length));
        }

		if(is_enough_source_block_numbers(s->def_max_sblen, s->def_eslen, (file_stats.st_size + padding_length),
								   s->def_fec_enc_id, s->def_fec_inst_id) < 0) {
			printf("Maximum source block length %i too small for the file: %s\n", s->def_max_sblen, file);
			fflush(stdout);
			if(hostname != NULL) {
				free(hostname);
			}
			free_uri(uri);
			return -1;
		}
	}

#ifdef USE_ZLIB       	
	else if(s->encode_content == ZLIB_FDT_AND_GZIP_FILES) {
                
		retcode = file_gzip_compress(fullpath, "wb");
                                                                                                                                                              
        	if(retcode == 0) {
                	fprintf(fp, "\n\t\t");
                	fprintf(fp, "Content-Encoding=\"%s\"", "gzip");
                                                                                                                                                              
               		memset(enc_fullpath, 0 , MAX_PATH_LENGTH);
                	strcpy(enc_fullpath, fullpath);
                	strcat(enc_fullpath, GZ_SUFFIX);
#ifdef _MSC_VER                                                                                                                                                      
                	if(_stat64(enc_fullpath, &enc_file_stats) == -1) {
#else
                	if(stat64(enc_fullpath, &enc_file_stats) == -1) {
#endif
                        printf("Error: %s is not valid file name\n", enc_fullpath);
                        fflush(stdout);
						if(hostname != NULL) {
							free(hostname);
						}
						free_uri(uri);
                        return -1;
                }

#ifdef USE_OPENSSL
					if(s->calculate_session_size == FALSE) {
					 md5 = file_md5(enc_fullpath);

					 if(md5 == NULL) {
						if(hostname != NULL) {
							free(hostname);
						}
						free_uri(uri);
						return -1;
					 } 
					
					 fprintf(fp, "\n\t\t");
					 fprintf(fp, "Content-MD5=\"%s\"", md5);
					}
#endif
                                                                                                                                                              
					fprintf(fp, "\n\t\t");
					fprintf(fp, "Transfer-Length=\"%llu\"", enc_file_stats.st_size);

					if(is_enough_source_block_numbers(s->def_max_sblen, s->def_eslen, enc_file_stats.st_size,
								   s->def_fec_enc_id, s->def_fec_inst_id) < 0) {
						printf("Maximum source block length %i too small for the file: %s\n", s->def_max_sblen, file);
						fflush(stdout);
						if(hostname != NULL) {
							free(hostname);
						}
						free_uri(uri);
						return -1;
					}
		}
      	}
#endif
	else {

#ifdef USE_OPENSSL
			if(s->calculate_session_size == FALSE) {
			 md5 = file_md5(fullpath);

			 if(md5 == NULL) {
				if(hostname != NULL) {
					free(hostname);
				}
				free_uri(uri);
				return -1;
			 }

			 fprintf(fp, "\n\t\t");
			 fprintf(fp, "Content-MD5=\"%s\"", md5);
			}
#endif
	}
	
#ifdef FDT_INST_FEC_OTI_FILE
	if(!s->use_fec_oti_ext_hdr) {

		fprintf(fp, "\n\t\t");
		fprintf(fp, "FEC-OTI-FEC-Encoding-ID=\"%u\"", s->def_fec_enc_id);

		if(s->def_fec_enc_id >= 128) {
			fprintf(fp, "\n\t\t");
			fprintf(fp, "FEC-OTI-FEC-Instance-ID=\"%u\"", s->def_fec_inst_id);
		}

		if(s->def_fec_enc_id == RS_FEC_ENC_ID) {
			fprintf(fp, "\n\t");
			fprintf(fp, "FEC-OTI-Finite-Field-Parameter=\"%u\"", GF_BITS);
			fprintf(fp, "\n\t");
			fprintf(fp, "FEC-OTI-Number-of-Encoding-Symbols-per-Group=\"%u\"", 1);
		}

		fprintf(fp, "\n\t\t");
		fprintf(fp, "FEC-OTI-Maximum-Source-Block-Length=\"%u\"", s->def_max_sblen);
		fprintf(fp, "\n\t\t");
		fprintf(fp, "FEC-OTI-Encoding-Symbol-Length=\"%u\"", s->def_eslen);

		if(s->def_fec_enc_id == SB_SYS_FEC_ENC_ID) {
			fprintf(fp, "\n\t\t");
			fprintf(fp, "FEC-OTI-Max-Number-of-Encoding-Symbols=\"%u\"", max_n);	
		}
	}
#endif

	fprintf(fp, "/>\n");
	toi++;
	free_uri(uri);

#ifdef USE_OPENSSL
	if(s->calculate_session_size == FALSE) {
		free(md5);
	}
#endif
	
	if(hostname != NULL) {
		free(hostname);
	}

	return 0;
}

/**
 * This is a private function which parses directory to the FDT.
 *
 * @param directory directory to be parsed
 * @param base_dir base directory for file to be parsed to the FDT
 * @param fp file pointer to the generated FDT
 * @param s_id session identifier
 *
 * @return 0 in success, -1 otherwise
 *
 */

int encode_directory(char *directory, char *base_dir, FILE *fp, int *s_id) {

	int result;
	char fullname[MAX_PATH_LENGTH];
	char fullpath[MAX_PATH_LENGTH];

#ifdef _MSC_VER
	struct __stat64 file_stats;
#else
	struct stat64 file_stats;
#endif

	uri_t *uri = NULL;
	char *hostname = NULL;
	alc_session_t *s = NULL;
	char *user = NULL;

#ifdef USE_ZLIB
	int retcode;
	char enc_fullpath[MAX_PATH_LENGTH];
#ifdef _MSC_VER
	struct __stat64 enc_file_stats;
#else
	struct stat64 enc_file_stats;
#endif
#endif

#ifdef USE_OPENSSL
	char *md5 = NULL;
#endif

#ifdef _MSC_VER
	int i;
	char findfile[MAX_PATH_LENGTH + 3];
	HANDLE dirptr = NULL;
	WIN32_FIND_DATA entry;
#else
	struct dirent *entry;
	DIR *dirptr = NULL;
	char findfile[MAX_PATH_LENGTH];
#endif

#ifdef FDT_INST_FEC_OTI_FILE
	div_t div_max_n;
	int max_n;
#endif

	char *uri_str = NULL;

	hostname = getdnsname();

	s = get_alc_session(*s_id);

#ifdef FDT_INST_FEC_OTI_FILE
	div_max_n = div((s->def_max_sblen * (100 + s->def_fec_ratio)), 100);
	max_n = div_max_n.quot;
#endif

#ifdef _MSC_VER
	user = getenv("USERNAME");

	memset(findfile, 0, (MAX_PATH_LENGTH + 3));

	if(!(strcmp(base_dir, "") == 0)) {
		strcpy(findfile, base_dir);
		strcat(findfile, "\\");
	}

	strcat(findfile, directory);
	strcat(findfile, "\\*");
	
	dirptr = FindFirstFile(findfile, &entry);

	if(dirptr == INVALID_HANDLE_VALUE) {
		printf("Error: %s is not valid directory name\n", directory);
		fflush(stdout);
		free(hostname);
		return -1;
	}

	if(!checkpath(entry.cFileName)) {

		memset(fullname, 0 , MAX_PATH_LENGTH);
		strcpy(fullname, directory);

		if(fullname[strlen(fullname) - 1] != '\\') {
			strcat(fullname, "\\");
		}

		strcat(fullname, entry.cFileName);

		for(i = 0; i < (int)strlen(fullname); i++) {
			if(fullname[i] == '\\') {
				fullname[i] = '/';
			}
		}

		if(entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			result = encode_directory(fullname, base_dir, fp, s_id);

			if(result < 0) {
				free(hostname);
				return -1;
			}
		}
		else {

			memset(fullpath, 0, MAX_PATH_LENGTH);

			if(!(strcmp(base_dir, "") == 0)) {
				strcpy(fullpath, base_dir);
				strcat(fullpath, "\\");
			}

			strcat(fullpath, fullname);

#ifdef _MSC_VER
			if(_stat64(fullpath, &file_stats) == -1) {
#else
			if(stat64(fullpath, &file_stats) == -1) {
#endif
				printf("Error: %s is not valid file name\n", fullpath);
				fflush(stdout);
				free(hostname);
				return -1;
			}		

			if(file_stats.st_size == 0) {
				printf("Error: file %s size = 0\n", fullpath);
				fflush(stdout);
				free(hostname);
				return -1;
			}
			
			uri = alloc_uri_struct();

			set_uri_scheme(uri, "file");

			if(user != NULL) {
				set_uri_user(uri, user);
			}

#ifdef HOSTNAME_TO_FDT
			if(hostname != NULL) {
				set_uri_host(uri, hostname);
			}
#endif

			set_uri_path(uri, fullname);

			fprintf(fp, "\t<File TOI=\"%I64u\"", toi);
			
			uri_str = uri_string(uri);

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Location=\"%s\"", uri_str);

			free(uri_str);
			uri_str = NULL;

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Length=\"%llu\"", file_stats.st_size);

                        if(s->encode_content == PAD_FILES) {

                                if(compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen)) {
                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Content-Encoding=\"%s\"", "pad"); 

                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Transfer-Length=\"%llu\"", compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen) + file_stats.st_size);
								}
/* Not possible to use, because padded file is not in the hard disk in the sender side
#ifdef USE_OPENSSL
                                if(s->calculate_session_size == FALSE) {
								 md5 = file_md5(fullpath);

                                 if(md5 == NULL) {
                                	free(hostname);        
                                        free_uri(uri);           
                                        return -1;
                                 }
                              
                                fprintf(fp, "\n\t\t"); 
                                fprintf(fp, "Content-MD5=\"%s\"", md5);
							   }
#endif
*/
                        }
#ifdef USE_ZLIB
			else if(s->encode_content == ZLIB_FDT_AND_GZIP_FILES) {

				retcode = file_gzip_compress(fullpath, "wb");

				if(retcode == 0) {
					
					memset(enc_fullpath, 0 , MAX_PATH_LENGTH);
					strcpy(enc_fullpath, fullpath);
					strcat(enc_fullpath, GZ_SUFFIX);
#ifdef _MSC_VER
					if(_stat64(enc_fullpath, &enc_file_stats) == -1) {
#else
					if(stat64(enc_fullpath, &enc_file_stats) == -1) {
#endif
						printf("Error: %s is not valid file name\n", enc_fullpath);
						fflush(stdout);
						free(hostname);
						free_uri(uri);
						return -1;
					}
					
					fprintf(fp, "\n\t\t");
					fprintf(fp, "Content-Encoding=\"%s\"", "gzip");
				
#ifdef USE_OPENSSL
					if(s->calculate_session_size == FALSE) {
					 md5 = file_md5(enc_fullpath);

					 if(md5 == NULL) {
						free(hostname);
						free_uri(uri);
						return -1;
					 }

					 fprintf(fp, "\n\t\t");
					 fprintf(fp, "Content-MD5=\"%s\"", md5);
				    }
#endif

					fprintf(fp, "\n\t\t");
					fprintf(fp, "Transfer-Length=\"%llu\"", enc_file_stats.st_size);
				}
			}
#endif
			else {
#ifdef USE_OPENSSL
				if(s->calculate_session_size == FALSE) {
				 md5 = file_md5(fullpath);

				 if(md5 == NULL) {
					free(hostname);
					free_uri(uri);
					return -1;
				 }

				 fprintf(fp, "\n\t\t");
				 fprintf(fp, "Content-MD5=\"%s\"", md5);
				}
#endif
			}

#ifdef FDT_INST_FEC_OTI_FILE
			if(!s->use_fec_oti_ext_hdr) {

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-FEC-Encoding-ID=\"%u\"", s->def_fec_enc_id);

				if(s->def_fec_enc_id >= 128) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-FEC-Instance-ID=\"%u\"", s->def_fec_inst_id);
				}

				if(s->def_fec_enc_id == RS_FEC_ENC_ID) {
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Finite-Field-Parameter=\"%u\"", GF_BITS);
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Number-of-Encoding-Symbols-per-Group=\"%u\"", 1);
				}

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Maximum-Source-Block-Length=\"%u\"", s->def_max_sblen);
				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Encoding-Symbol-Length=\"%u\"", s->def_eslen);

				if(s->def_fec_enc_id == RS_FEC_ENC_ID || s->def_fec_enc_id == SB_SYS_FEC_ENC_ID) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-Max-Number-of-Encoding-Symbols=\"%u\"", max_n);	
				}
			}
#endif

			fprintf(fp, "/>\n");
			
			toi++;
			free_uri(uri);

#ifdef USE_OPENSSL
			free(md5);
			md5 = NULL;
#endif
		}
	}

	while(FindNextFile(dirptr, &entry)) {

		if(checkpath(entry.cFileName)) {
			continue;
		}

		memset(fullname, 0 , MAX_PATH_LENGTH);
		strcpy(fullname, directory);

		if(fullname[strlen(fullname) - 1] != '\\') {
			strcat(fullname, "\\");
		}

		strcat(fullname, entry.cFileName);

		for(i = 0; i < (int)strlen(fullname); i++) {
			if(fullname[i] == '\\') {
				fullname[i] = '/';
			}
		}

		if(entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			result = encode_directory(fullname, base_dir, fp, s_id);

			if(result < 0) {
				continue;
			}
		}
		else {
	
			memset(fullpath, 0, MAX_PATH_LENGTH);

			if(!(strcmp(base_dir, "") == 0)) {
				strcpy(fullpath, base_dir);
				strcat(fullpath, "\\");
			}

			strcat(fullpath, fullname);

#ifdef _MSC_VER
			if(_stat64(fullpath, &file_stats) == -1) {
#else
			if(stat64(fullpath, &file_stats) == -1) {
#endif
				printf("Error: %s is not valid file name\n", fullpath);
				fflush(stdout);
				continue;
			}

			if(file_stats.st_size == 0) {
				printf("Error: file %s size = 0\n", fullpath);
				fflush(stdout);
				continue;
			}

			uri = alloc_uri_struct();

			set_uri_scheme(uri, "file");

			if(user != NULL) {
				set_uri_user(uri, user);
			}

#ifdef HOSTNAME_TO_FDT
			if(hostname != NULL) {
				set_uri_host(uri, hostname);
			}
#endif

			set_uri_path(uri, fullname);

            fprintf(fp, "\t<File TOI=\"%I64u\"", toi);

			uri_str = uri_string(uri);

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Location=\"%s\"", uri_str);

			free(uri_str);
			uri_str = NULL;

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Length=\"%llu\"", file_stats.st_size);

                        if(s->encode_content == PAD_FILES) {

                                if(compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen)) {           
                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Content-Encoding=\"%s\"", "pad");

                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Transfer-Length=\"%llu\"", compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen) + file_stats.st_size);
                                }
                        }
#ifdef USE_ZLIB
			else if(s->encode_content == ZLIB_FDT_AND_GZIP_FILES) {

				retcode = file_gzip_compress(fullpath, "wb");
			
				if(retcode == 0) {

					memset(enc_fullpath, 0 , MAX_PATH_LENGTH);
					strcpy(enc_fullpath, fullpath);
					strcat(enc_fullpath, GZ_SUFFIX);

#ifdef _MSC_VER
					if(_stat64(enc_fullpath, &enc_file_stats) == -1) {
#else
					if(stat64(enc_fullpath, &enc_file_stats) == -1) {
#endif
						printf("Error: %s is not valid file name\n", enc_fullpath);
						fflush(stdout);
						free_uri(uri);
						continue;
					}
					
					fprintf(fp, "\n\t\t");
					fprintf(fp, "Content-Encoding=\"%s\"", "gzip");

#ifdef USE_OPENSSL
					if(s->calculate_session_size == FALSE) {
					 md5 = file_md5(enc_fullpath);

					 if(md5 == NULL) {
						free(hostname);
						free_uri(uri);
						continue;
					 }

					 fprintf(fp, "\n\t\t");
					 fprintf(fp, "Content-MD5=\"%s\"", md5);
					}
#endif

					fprintf(fp, "\n\t\t");
					fprintf(fp, "Transfer-Length=\"%llu\"", enc_file_stats.st_size);
				}
			}
#endif
			else {
#ifdef USE_OPENSSL
				if(s->calculate_session_size == FALSE) {
				 md5 = file_md5(fullpath);

				 if(md5 == NULL) {
					free(hostname);
					free_uri(uri);
					continue;
				 }

				 fprintf(fp, "\n\t\t");
				 fprintf(fp, "Content-MD5=\"%s\"", md5);
				}
#endif
			}
			
#ifdef FDT_INST_FEC_OTI_FILE
			if(!s->use_fec_oti_ext_hdr) {

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-FEC-Encoding-ID=\"%u\"", s->def_fec_enc_id);

				if(s->def_fec_enc_id >= 128) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-FEC-Instance-ID=\"%u\"", s->def_fec_inst_id);
				}

				if(s->def_fec_enc_id == RS_FEC_ENC_ID) {
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Finite-Field-Parameter=\"%u\"", GF_BITS);	
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Number-of-Encoding-Symbols-per-Group=\"%u\"", 1);
				}

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Maximum-Source-Block-Length=\"%u\"", s->def_max_sblen);
				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Encoding-Symbol-Length=\"%u\"", s->def_eslen);
				
				if(s->def_fec_enc_id == RS_FEC_ENC_ID || s->def_fec_enc_id == SB_SYS_FEC_ENC_ID) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-Max-Number-of-Encoding-Symbols=\"%u\"", max_n);	
				}
			}
#endif

			fprintf(fp, "/>\n");
			
			toi++;
			free_uri(uri);

#ifdef USE_OPENSSL
			if(s->calculate_session_size == FALSE) {
			  free(md5);
			  md5 = NULL;
			}
#endif
		}
	}
	FindClose(dirptr);

#else
	user = getenv("USER");	

	memset(findfile, 0, MAX_PATH_LENGTH);

	if(!(strcmp(base_dir, "") == 0)) {
		strcpy(findfile, base_dir);
		strcat(findfile, "/");
	}

	strcat(findfile, directory);

	dirptr = opendir(findfile);

	if(dirptr == NULL) {
		printf("%s is not valid directory name\n", findfile);
		fflush(stdout);
		free(hostname);
		return -1;
	}

	entry = readdir(dirptr);

	while(entry != NULL) {
		
		if(checkpath(entry->d_name)) {
			entry = readdir(dirptr);
			continue;
		}

		memset(fullname, 0 , MAX_PATH_LENGTH);
		strcpy(fullname, directory);
		
		if(fullname[strlen(fullname) - 1] != '/') {
			strcat(fullname, "/");
		}

		strcat(fullname, entry->d_name);

		memset(fullpath, 0, MAX_PATH_LENGTH);

		if(!(strcmp(base_dir, "") == 0)) {
			strcpy(fullpath, base_dir);
			strcat(fullpath, "/");
		}

		strcat(fullpath, fullname);

		if(stat64(fullpath, &file_stats) == -1) {
			printf("Error: %s is not valid file name\n", fullpath);
			fflush(stdout);
			entry = readdir(dirptr);
			continue;
		}

		if(S_ISDIR(file_stats.st_mode)) {
			result = encode_directory(fullname, base_dir, fp, s_id);

			if(result < 0) {
				entry = readdir(dirptr);
				continue;
			}
		}
		else {	
			if(file_stats.st_size == 0) {
				printf("Error: file %s size = 0\n", fullpath);
				fflush(stdout);
				entry = readdir(dirptr);
				continue;
			}

			uri = alloc_uri_struct();

			set_uri_scheme(uri, "file");

			if(user != NULL) {
				set_uri_user(uri, user);
			}
			
#ifdef HOSTNAME_TO_FDT
			if(hostname != NULL) {
				set_uri_host(uri, hostname);
			}
#endif

			set_uri_path(uri, fullname);

			fprintf(fp, "\t<File TOI=\"%llu\"", toi);

			uri_str = uri_string(uri);

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Location=\"%s\"", uri_str);

			free(uri_str);
			uri_str = NULL;

			fprintf(fp, "\n\t\t");
			fprintf(fp, "Content-Length=\"%llu\"", file_stats.st_size);

                        if(s->encode_content == PAD_FILES) {

                                if(compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen)) {           
                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Content-Encoding=\"%s\"", "pad");

                                        fprintf(fp, "\n\t\t");
                                        fprintf(fp, "Transfer-Length=\"%llu\"", compute_padding_length(file_stats.st_size, s->def_max_sblen, s->def_eslen) + file_stats.st_size);
                                }
                        }
#ifdef USE_ZLIB
			else if(s->encode_content == ZLIB_FDT_AND_GZIP_FILES) {
                                                                                                                                              
				retcode = file_gzip_compress(fullpath, "wb");
                                                                                                                                          
				if(retcode == 0) {
					
					memset(enc_fullpath, 0 , MAX_PATH_LENGTH);
					strcpy(enc_fullpath, fullpath);
					strcat(enc_fullpath, GZ_SUFFIX);
                                                                                                                                      
					if(stat64(enc_fullpath, &enc_file_stats) == -1) {
						printf("Error: %s is not valid file name\n", enc_fullpath);
						fflush(stdout);
						entry = readdir(dirptr);
						free_uri(uri);
						continue;
					}

					fprintf(fp, "\n\t\t");
					fprintf(fp, "Content-Encoding=\"%s\"", "gzip");					
#ifdef USE_OPENSSL
					if(s->calculate_session_size == FALSE) {
					 md5 = file_md5(enc_fullpath);

					 if(md5 == NULL) {
						free_uri(uri);
						continue;
					 }
					
					 fprintf(fp, "\n\t\t");
					 fprintf(fp, "Content-MD5=\"%s\"", md5);
					}
#endif
                
					fprintf(fp, "\n\t\t");
					fprintf(fp, "Transfer-Length=\"%llu\"", enc_file_stats.st_size);
				}
			}
#endif
			else {

#ifdef USE_OPENSSL
				if(s->calculate_session_size == FALSE) {
				 md5 = file_md5(fullpath);

				 if(md5 == NULL) {
					free_uri(uri);
					continue;
				 }

				 fprintf(fp, "\n\t\t");
				 fprintf(fp, "Content-MD5=\"%s\"", md5);
				}
#endif
			}
			
#ifdef FDT_INST_FEC_OTI_FILE
			if(!s->use_fec_oti_ext_hdr) {

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-FEC-Encoding-ID=\"%u\"", s->def_fec_enc_id);

				if(s->def_fec_enc_id >= 128) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-FEC-Instance-ID=\"%u\"", s->def_fec_inst_id);
				}

				if(s->def_fec_enc_id == RS_FEC_ENC_ID) {
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Finite-Field-Parameter=\"%u\"", GF_BITS);	
					fprintf(fp, "\n\t");
					fprintf(fp, "FEC-OTI-Number-of-Encoding-Symbols-per-Group=\"%u\"", 1);
				}

				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Maximum-Source-Block-Length=\"%u\"", s->def_max_sblen);
				fprintf(fp, "\n\t\t");
				fprintf(fp, "FEC-OTI-Encoding-Symbol-Length=\"%u\"", s->def_eslen);

				if(s->def_fec_enc_id == RS_FEC_ENC_ID || s->def_fec_enc_id == SB_SYS_FEC_ENC_ID) {
					fprintf(fp, "\n\t\t");
					fprintf(fp, "FEC-OTI-Max-Number-of-Encoding-Symbols=\"%u\"", max_n);	
				}
			}
#endif

			fprintf(fp, "/>\n");
			
			toi++;
			free_uri(uri);

#ifdef USE_OPENSSL
			if(s->calculate_session_size == FALSE) {
			 free(md5);
			 md5 = NULL;
			}
#endif
		}
		entry = readdir(dirptr);
	}
	closedir(dirptr);

#endif
	
	if(hostname != NULL) {
		free(hostname);
	}

	if(toi == 1) {
		return -1;
	}

	return 0;
}

int generate_fdt(char *file_token, char *base_dir, int *s_id, char *fdt_file_name,
				 int complete_fdt, int verbosity) {
  int result;
  FILE *fp;
  
#ifdef _MSC_VER
  struct __stat64 file_stats;
#else
  struct stat64 file_stats;
#endif
  alc_session_t *s = NULL;
  char fullpath[MAX_PATH_LENGTH];
  
#ifdef FDT_INST_FEC_OTI_COMMON
  div_t div_max_n;
  int max_n;
#endif

  char *token;
  
  if((fp = fopen(fdt_file_name, "wb")) == NULL) {
    printf("Error: unable to create fdtfile %s\n", fdt_file_name);
    fflush(stdout);
    return -1;
  }
  
  s = get_alc_session(*s_id);
  
#ifdef FDT_INST_FEC_OTI_COMMON
  div_max_n = div((s->def_max_sblen * (100 + s->def_fec_ratio)), 100);
  max_n = div_max_n.quot;
#endif
  
  toi = 1;
  
  fprintf(fp, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
  fprintf(fp, "<FDT-Instance ");
  
#ifdef _MSC_VER
  if(s->stoptime == 0) {
    /* session is not bounded, set 64bits max value */
    fprintf(fp, "Expires=\"%I64u\"", (unsigned long long)0xFFFFFFFFFFFFFFFF);
  }
  else {
    fprintf(fp, "Expires=\"%I64u\"", s->stoptime);
  }
#else
  if(s->stoptime == 0) {
    /* session is not bounded, set 64bits max value */
    fprintf(fp, "Expires=\"%llu\"", 0xFFFFFFFFFFFFFFFFULL);
  }
  else {
    fprintf(fp, "Expires=\"%llu\"", s->stoptime);
  }
#endif
  
  if(complete_fdt > 0) {
    fprintf(fp, "\n\t");
    fprintf(fp, "Complete=\"true\"");
  }
  
#ifdef FDT_INST_FEC_OTI_COMMON
  if(!s->use_fec_oti_ext_hdr) {
    
    fprintf(fp, "\n\t");
    fprintf(fp, "FEC-OTI-FEC-Encoding-ID=\"%u\"", s->def_fec_enc_id);
    
    if(s->def_fec_enc_id >= 128) {
      fprintf(fp, "\n\t");
      fprintf(fp, "FEC-OTI-FEC-Instance-ID=\"%u\"", s->def_fec_inst_id);
    }
    
    if(s->def_fec_enc_id == RS_FEC_ENC_ID) {
      fprintf(fp, "\n\t");
      fprintf(fp, "FEC-OTI-Finite-Field-Parameter=\"%u\"", GF_BITS);
      fprintf(fp, "\n\t");
      fprintf(fp, "FEC-OTI-Number-of-Encoding-Symbols-per-Group=\"%u\"", 1);
    }
    
    fprintf(fp, "\n\t");
    fprintf(fp, "FEC-OTI-Maximum-Source-Block-Length=\"%u\"", s->def_max_sblen);
    fprintf(fp, "\n\t");
    fprintf(fp, "FEC-OTI-Encoding-Symbol-Length=\"%u\"", s->def_eslen);
    
    if(s->def_fec_enc_id == RS_FEC_ENC_ID || s->def_fec_enc_id == SB_SYS_FEC_ENC_ID) {
      fprintf(fp, "\n\t");
      fprintf(fp, "FEC-OTI-Max-Number-of-Encoding-Symbols=\"%u\"", max_n);
    }
  }
#endif
  
  fprintf(fp, ">\n");

  token = strtok(file_token, ",");

  while(token != NULL) {

    memset(fullpath, 0, (MAX_PATH_LENGTH));
    
    if(!(strcmp(base_dir, "") == 0)) {
      strcpy(fullpath, base_dir);
      
#ifdef _MSC_VER
      strcat(fullpath, "\\");
#else
      strcat(fullpath, "/");
#endif
    }
    
    strcat(fullpath, token);
#ifdef _MSC_VER
    if(_stat64(fullpath, &file_stats) == -1) {
#else
    if(stat64(fullpath, &file_stats) == -1) {
#endif
      printf("Error: %s is not valid file name\n", fullpath);
      fflush(stdout);
      return -1;
    }

    if(file_stats.st_mode & S_IFDIR) {
      result = encode_directory(token, base_dir, fp, s_id);
    }
    else {
      result = encode_file(token, base_dir, fp, s_id);
    }

    if(result < 0) {
      fclose(fp);
      remove(fdt_file_name);
      return -1;
    }

    token = strtok(NULL, ",");
  }
    
  fprintf(fp, "</FDT-Instance>\n");
    
  if(verbosity == 4) {
    printf("File: %s created\n", fdt_file_name);
  }
  
  fclose(fp);
  
  return 0;
}
/*----------------------------------------------------------------------
|   NPT_stat_utf8
+---------------------------------------------------------------------*/
int
NPT_stat_utf8(const char* path, struct __stat64* info)
{
    return _stat64(path, info);
}
Example #29
0
int64_t RAUX::File :: GetLength ( uint32_t * Status ) const
{
	
	* Status = kStatus_Success;
	
	#if defined ( __APPLE__ )
	
	struct stat FStatData;
	
#elif defined ( _WIN32 )
	
	struct __stat64 FStatData;
	
#else
	
	struct stat64 FStatData;
	
#endif
	
	int ReturnCode;
	
	if ( Opened )
	{
		
#ifdef _WIN32
		
		int FD = _fileno ( Handle );
		
#else
		
		int FD = fileno ( Handle );
		
#endif
		
		if ( FD == - 1 )
		{
			
			* Status = kStatus_Failure_FileNotOpen;
			
			return - 1;
			
		}
		
#if defined ( __APPLE__ )
		
		ReturnCode = fstat ( FD, & FStatData );

#elif defined ( _WIN32 )
		
		ReturnCode = _fstat64 ( FD, & FStatData );

#else
		
		ReturnCode = fstat64 ( FD, & FStatData );
		
#endif
		
	}
	else
	{
		
#if defined ( __APPLE__ )
		
		ReturnCode = stat ( Name.c_str (), & FStatData );
		
#elif defined ( _WIN32 )
		
		ReturnCode = _stat64 ( Name.c_str (), & FStatData );
		
#else
		
		ReturnCode = stat64 ( Name.c_str (), & FStatData );
		
#endif
		
	}
	
	if ( ReturnCode == - 1 )
		* Status = kStatus_Failure_Unknown;
	
	return FStatData.st_size;
	
}
Example #30
0
int iRODSNt_stat(const char *filename,struct irodsntstat *stat_p)
{
        char ntfp[2048];
        iRODSPathToNtPath(ntfp,filename);
        return _stat64(ntfp,stat_p);    /* _stat */
}