/****************************************************************************** NAME vc_hostfs_freespace SYNOPSIS int vc_hostfs_freespace(const char *path) FUNCTION Returns the amount of free space on the physical file system that contains path. RETURNS Successful completion: free space Otherwise: -1 ******************************************************************************/ int64_t vc_hostfs_freespace64(const char *inPath) { char *path = strdup( inPath ); int64_t ret; STRUCT_STATFS fsStat; // Replace all '\' with '/' backslash_to_slash( path ); ret = (int64_t) STATFS( path, &fsStat ); if (ret == 0) { ret = fsStat.f_bsize * fsStat.f_bavail; } else { ret = -1; } DEBUG_MINOR( "vc_hostfs_freespace64 for '%s' returning %" PRId64 "", path, ret ); free( path ); return ret; }
int vc_hostfs_remove(const char *path) { char *pathbuf = strdup(path); int ret = -1; DEBUG_MINOR( "vc_hostfs_remove: '%s'", path ); if (pathbuf) { backslash_to_slash(pathbuf); if ( unlink( pathbuf ) == 0 ) ret = 0; } return ret; }
void *vc_hostfs_opendir(const char *dirname) { struct fs_dir *fsdir = NULL; DEBUG_MINOR( "vc_hostfs_opendir: '%s'", dirname ); if (dirname && dirname[0]) { fsdir = (struct fs_dir *)malloc(sizeof(struct fs_dir)); if (fsdir) { DIR *dhandle; int len = strlen(dirname); memcpy(fsdir->pathbuf, dirname, len); backslash_to_slash(fsdir->pathbuf); /* Remove any trailing slashes */ while (fsdir->pathbuf[len - 1] == '/') len--; fsdir->pathbuf[len] = '\0'; dhandle = opendir(fsdir->pathbuf); DEBUG_MINOR( "opendir: '%s' = %p", fsdir->pathbuf, dhandle ); if (dhandle) { fsdir->pathlen = len; fsdir->dhandle = dhandle; } else { free(fsdir); fsdir = NULL; } } } return fsdir; }
HRESULT CSkeletalsMgr::GetSkeInPool( const TCHAR* szName , CSkeletalFrame** pSkeletalFrame ) { if ( szName == 0 || szName[0] == 0 ) { *pSkeletalFrame = NULL; return GERROR; } string result = szName; backslash_to_slash(result); tolower(result); int pos = result.rfind("/"); result = result.substr(pos+1,result.size()-pos); *pSkeletalFrame = GetSkeFromContainer( result ); if(*pSkeletalFrame) return 0; //CSkeletalFrame* Temp = new CSkeletalFrame( result ); //if ( !Temp ) // return GERROR; //CPkgFile::EnableAsyncRead(false); //int filesize = Temp->BinLoad(); //CPkgFile::EnableAsyncRead(true); //if ( SUCCEEDED( filesize ) ) //{ // *pSkeletalFrame = Temp; // AddSkeToContainer(result,Temp); // ChangePoolSize(filesize); // return 0; //} //delete Temp; if(!m_bInit) { string fileName = st_SkePathConfig + result; CSkeletalFrame* pSkeFrame = CDataSources::GetInst()->NewSkeletalFrame( fileName.c_str(),PATH_ALIAS_RES ); if ( pSkeFrame ) { bool bAsyn = CPkgFile::IsEnableAsyncRead(); CPkgFile::EnableAsyncRead(false); int filesize = pSkeFrame->BinLoad(); CPkgFile::EnableAsyncRead(bAsyn); if ( SUCCEEDED( filesize ) ) { AddSkeToContainer(result.c_str(),pSkeFrame); ChangePoolSize(filesize); *pSkeletalFrame = pSkeFrame; return 0; } delete pSkeFrame; } } ArtErr("¹Ç¼ÜÎļþȱʧ",result); return GERROR; }
int vc_hostfs_open(const char *inPath, int vc_oflag) { char *path = strdup( inPath ); //char *s; int flags = 0, ret=errno; struct stat fileStat; // Replace all '\' with '/' backslash_to_slash( path ); #if 0 s = path + strlen( path ); if (( s - path ) >= 4 ) { if ( strcasecmp( &s[ -4 ], ".vll" ) == 0 ) { // The Videocore is asking for a .vll file. Since it isn't consistent with // the case, we convert .vll files to all lowercase. "vc_hostfs_open: '%s'", path ; s--; // backup to the last character (*s is on the '\0') while (( s >= path ) && ( *s != '/' )) { *s = tolower( *s ); s--; } } } #endif DEBUG_MINOR("vc_hostfs_open: '%s'", path); flags = O_RDONLY; if (vc_oflag & VC_O_WRONLY) flags = O_WRONLY; if (vc_oflag & VC_O_RDWR) flags = O_RDWR; if (vc_oflag & VC_O_APPEND) flags |= O_APPEND; if (vc_oflag & VC_O_CREAT) flags |= O_CREAT; if (vc_oflag & VC_O_TRUNC) flags |= O_TRUNC; if (vc_oflag & VC_O_EXCL) flags |= O_EXCL; //while (*path == '\\') path++; // do not want initial '\' if (flags & O_CREAT) ret = open(path, flags, S_IRUSR | S_IWUSR ); else ret = open(path, flags ); if (ret < 0 ) { DEBUG_MINOR("vc_hostfs_open(%s,%d) = %d", path, vc_oflag, ret); } else { DEBUG_MINOR("vc_hostfs_open(%s,%d) = %d", path, vc_oflag, ret); } // If the file was successfully open then initialize its entry in // the file info table. If necessary, we expand the size of the table if (ret >= 0) { // File was successfully opened if (ret >= file_info_table_len) { file_info_t *p_new_file_info_table = p_file_info_table; int new_file_info_table_len = file_info_table_len; // try and allocate a bigger buffer for the file info table new_file_info_table_len += FILE_INFO_TABLE_CHUNK_LEN; p_new_file_info_table = calloc( (size_t)new_file_info_table_len, sizeof( file_info_t ) ); if (p_new_file_info_table == NULL) { // calloc failed DEBUG_MAJOR("vc_hostfs_open: file_info_table calloc failed"); assert( 0 ); } else { // calloc successful, so copy data from previous buffer to new buffer, // free previous buffer and update ptr and len info memcpy( p_new_file_info_table, p_file_info_table, sizeof( file_info_t ) * file_info_table_len ); free( p_file_info_table ); p_file_info_table = p_new_file_info_table; file_info_table_len = new_file_info_table_len; } } assert( ret < file_info_table_len ); { // initialize this file's entry in the file info table p_file_info_table[ret].is_fifo = 0; p_file_info_table[ret].read_offset = 0; } // Check whether the file is a FIFO. A FIFO does not support seeking // but we will fake, to the extent supported by the buffered file system // on the Videocore, limited FIFO seek functionality. This is for the benefit // of certain Videocore "streaming" file handlers. if (fstat( ret, &fileStat ) != 0) { DEBUG_MINOR("vc_hostfs_open: fstat failed: %s", strerror(errno)); } else if (S_ISFIFO( fileStat.st_mode )) { // file is a FIFO, so note its fildes for future reference p_file_info_table[ret].is_fifo = 1; DEBUG_MINOR("vc_hostfs_open: file with fildes %d is a FIFO", ret); } } free( path ); return ret; }