From 1e1d07d546651718cc93166e0a5e15d9f13ca4e9 Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Mon, 27 Jul 2020 17:57:22 +0100 Subject: [PATCH] Remove vcfiled and vcfilesys. Both these libraries/apps were related to the VPU accessing the host file system over VCHI. This has never been used on the Pi, and is creating build warnings with the latest versions of gcc. Remove them from the source tree. --- .../linux/libs/bcm_host/CMakeLists.txt | 4 +- interface/vmcs_host/CMakeLists.txt | 4 +- .../vmcs_host/linux/vcfiled/vcfiled_check.c | 169 -- .../vmcs_host/linux/vcfiled/vcfiled_check.h | 48 - interface/vmcs_host/linux/vcfilesys.c | 1131 -------- interface/vmcs_host/vc_fileservice_defs.h | 119 - interface/vmcs_host/vc_vchi_filesys.c | 2509 ----------------- interface/vmcs_host/vc_vchi_filesys.h | 184 -- interface/vmcs_host/vcfilesys.h | 166 -- interface/vmcs_host/vchost.h | 70 - 10 files changed, 3 insertions(+), 4401 deletions(-) delete mode 100644 interface/vmcs_host/linux/vcfiled/vcfiled_check.c delete mode 100644 interface/vmcs_host/linux/vcfiled/vcfiled_check.h delete mode 100644 interface/vmcs_host/linux/vcfilesys.c delete mode 100644 interface/vmcs_host/vc_fileservice_defs.h delete mode 100644 interface/vmcs_host/vc_vchi_filesys.c delete mode 100644 interface/vmcs_host/vc_vchi_filesys.h delete mode 100644 interface/vmcs_host/vcfilesys.h diff --git a/host_applications/linux/libs/bcm_host/CMakeLists.txt b/host_applications/linux/libs/bcm_host/CMakeLists.txt index a863cb6d2..2f4beb932 100644 --- a/host_applications/linux/libs/bcm_host/CMakeLists.txt +++ b/host_applications/linux/libs/bcm_host/CMakeLists.txt @@ -15,9 +15,7 @@ include_directories( ../../../.. ../../../../host_applications/vmcs/test_apps/iltest ../../../../host_applications/framework/common ) -add_library(bcm_host ${SHARED} bcm_host.c - ../../../../interface/vmcs_host/linux/vcfilesys.c - ../../../../interface/vmcs_host/linux/vcfiled/vcfiled_check.c) +add_library(bcm_host ${SHARED} bcm_host.c) target_link_libraries(bcm_host vcos vchostif) diff --git a/interface/vmcs_host/CMakeLists.txt b/interface/vmcs_host/CMakeLists.txt index 4a914a7e3..cbef80c57 100755 --- a/interface/vmcs_host/CMakeLists.txt +++ b/interface/vmcs_host/CMakeLists.txt @@ -8,8 +8,8 @@ add_definitions(-fno-strict-aliasing) add_library(vchostif - ${VMCS_TARGET}/vcfilesys.c ${VMCS_TARGET}/vcmisc.c - vc_vchi_gencmd.c vc_vchi_filesys.c vc_vchi_gpuserv.c + ${VMCS_TARGET}/vcmisc.c + vc_vchi_gencmd.c vc_vchi_gpuserv.c vc_vchi_tvservice.c vc_vchi_cecservice.c vc_vchi_dispmanx.c vc_service_common.c) # ${VMCS_TARGET}/vmcs_main.c diff --git a/interface/vmcs_host/linux/vcfiled/vcfiled_check.c b/interface/vmcs_host/linux/vcfiled/vcfiled_check.c deleted file mode 100644 index 35e089931..000000000 --- a/interface/vmcs_host/linux/vcfiled/vcfiled_check.c +++ /dev/null @@ -1,169 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "vcfiled_check.h" -#include -#include -#include -#include -#include -#include -#include -#include - -int vcfiled_lock(const char *lockfile, VCFILED_LOGMSG_T logmsg) -{ - int rc, fd; - char pidbuf[32]; - char *lockdir = strdup(lockfile); - char *sep = strrchr(lockdir, '/'); - int ret = -1; - if (!sep) - { - free(lockdir); - return -1; - } - *sep = '\0'; - - if (mkdir(lockdir, S_IRWXU | S_IRGRP|S_IXGRP) < 0) - { - if (errno != EEXIST) - { - logmsg(LOG_CRIT, "could not create %s:%s\n", lockdir,strerror(errno)); - goto finish; - } - } - fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0640); - if (fd<0) - { - if (errno != EEXIST) - { - logmsg(LOG_CRIT, "could not create lockfile %s:%s\n", lockfile, strerror(errno)); - goto finish; - } - else - { - // it already exists - reopen it and try to lock it - fd = open(lockfile, O_RDWR); - if (fd<0) - { - logmsg(LOG_CRIT, "could not re-open lockfile %s:%s\n", lockfile, strerror(errno)); - goto finish; - } - } - } - // at this point, we have opened the file, and can use discretionary locking, - // which should work even over NFS - - struct flock flock; - memset(&flock, 0, sizeof(flock)); - flock.l_type = F_WRLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 1; - if (fcntl(fd, F_SETLK, &flock) < 0) - { - // if we failed to lock, then it might mean we're already running, or - // something else bad. - if (errno == EACCES || errno == EAGAIN) - { - // already running - int pid = 0, rc = read(fd, pidbuf, sizeof(pidbuf)); - if (rc) - pid = atoi(pidbuf); - logmsg(LOG_CRIT, "already running at pid %d\n", pid); - close(fd); - goto finish; - } - else - { - logmsg(LOG_CRIT, "could not lock %s:%s\n", lockfile, strerror(errno)); - close(fd); - goto finish; - } - } - snprintf(pidbuf,sizeof(pidbuf),"%d", getpid()); - rc = write(fd, pidbuf, strlen(pidbuf)+1); - if (rc<0) - { - logmsg(LOG_CRIT, "could not write pid:%s\n", strerror(errno)); - goto finish; - } - /* do not close the file, as that will release the lock - it will - * will close automatically when the program exits. - */ - ret = 0; -finish: - free(lockdir); - /* coverity[leaked_handle] - fd left open on purpose */ - return ret; -} - -int vcfiled_is_running(const char *filename) -{ - int ret; - - int fd = open(filename, O_RDONLY); - if (fd < 0) - { - // file not there, so filed not running - ret = 0; - } - - else - { - struct flock flock; - memset(&flock, 0, sizeof(flock)); - flock.l_type = F_WRLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 1; - int rc = fcntl(fd, F_GETLK, &flock); - if (rc != 0) - { - /* could not access lock info */ - printf("%s: Could not access lockfile %s: %s\n", - "vmcs_main", filename, strerror(errno)); - ret = 0; - } - else if (flock.l_pid == 0) - { - /* file is unlocked, so filed not running */ - ret = 0; - } - else - { - /* file is locked, so filed is running */ - ret = 1; - } - } - /* coverity[leaked_handle] - fd left open on purpose */ - return ret; -} - - - diff --git a/interface/vmcs_host/linux/vcfiled/vcfiled_check.h b/interface/vmcs_host/linux/vcfiled/vcfiled_check.h deleted file mode 100644 index 360f50a90..000000000 --- a/interface/vmcs_host/linux/vcfiled/vcfiled_check.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef VCFILED_CHECK_H -#define VCFILED_CHECK_H - -#ifdef ANDROID -#define VCFILED_LOCKDIR "/tmp/vcfiled/vcfiled.pid" -#define VCFILED_LOCKFILE "/tmp/vcfiled" -#endif - -#ifndef VCFILED_LOCKFILE -#define VCFILED_LOCKDIR "/var/run/vcfiled" -#define VCFILED_LOCKFILE VCFILED_LOCKDIR "/vcfiled" -#endif - -typedef void (*VCFILED_LOGMSG_T)(int level, const char *fmt, ...); -int vcfiled_lock(const char *filename, VCFILED_LOGMSG_T logmsg); -extern int vcfiled_is_running(const char *lockfile); - - -#endif - - diff --git a/interface/vmcs_host/linux/vcfilesys.c b/interface/vmcs_host/linux/vcfilesys.c deleted file mode 100644 index 9f3ebf159..000000000 --- a/interface/vmcs_host/linux/vcfilesys.c +++ /dev/null @@ -1,1131 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define VCOS_LOG_CATEGORY (&hostfs_log_cat) - -#ifndef _LARGEFILE_SOURCE -#define _LARGEFILE_SOURCE -#endif -#ifndef _LARGEFILE64_SOURCE -#define _LARGEFILE64_SOURCE -#endif -#define _FILE_OFFSET_BITS 64 /* So we get lseek and lseek64 */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(__GLIBC__) && !defined( __USE_FILE_OFFSET64 ) -#error "__USE_FILE_OFFSET64 isn't defined" -#endif - -#include "interface/vcos/vcos.h" - -/* Some hackery to prevent a clash with the Linux type of the same name */ -#define dirent fs_dirent -#include "vcfilesys_defs.h" -#include "vchost.h" -#undef dirent - -#include - -#include "vc_fileservice_defs.h" - -VCOS_LOG_CAT_T hostfs_log_cat; - -/****************************************************************************** -Global data. -******************************************************************************/ - -/****************************************************************************** -Local types and defines. -******************************************************************************/ - -//#define DEBUG_LEVEL 1 -#define DEBUG_MINOR(...) vcos_log_info(__VA_ARGS__) -#define DEBUG_MAJOR(...) vcos_log_warn(__VA_ARGS__) - -/* Define a wrapper for the native directory handle which includes the path - * to that directory (needed to retrieve size and attributes via stat()). - */ - -struct fs_dir -{ - DIR *dhandle; - int pathlen; - char pathbuf[PATH_MAX]; -}; - -/* - * The media player on the Videocore may be asked to open a file on the Host that - * is in fact a FIFO. We need to note when a FIFO has been opened so that we - * can fake out some FIFO seeks that the Videocore may perform, hence the following - * types and variables. - */ - -typedef struct -{ - int is_fifo; // non-zero if file is a FIFO - uint64_t read_offset; // read offset into file -} file_info_t; - -#define FILE_INFO_TABLE_CHUNK_LEN 20 - -/****************************************************************************** -Static data. -******************************************************************************/ - -static file_info_t *p_file_info_table = NULL; -static int file_info_table_len = 0; - -/****************************************************************************** -Static functions. -******************************************************************************/ - -static void backslash_to_slash( char *s ); - -/****************************************************************************** -Global functions. -******************************************************************************/ - -/****************************************************************************** -NAME - vc_hostfs_init - -SYNOPSIS - void vc_hostfs_init(void) - -FUNCTION - Initialises the host to accept requests from Videocore - -RETURNS - void -******************************************************************************/ - -void vc_hostfs_init(void) -{ - // This hostfs module is not thread safe - it allocaes a block - // of memory and uses it without any kind of locking. - // - // It offers no advantage of stdio, and so most clients should - // not use it. Arguably FILESYS should use it in order to get - // the FIFO support. - - const char *thread_name = vcos_thread_get_name(vcos_thread_current()); - if (strcmp(thread_name, "FILESYS") != 0 && strcmp(thread_name, "HFilesys") != 0) - { - fprintf(stderr,"%s: vc_hostfs is deprecated. Please use stdio\n", - vcos_thread_get_name(vcos_thread_current())); - } - - vcos_log_register("hostfs", &hostfs_log_cat); - DEBUG_MINOR("init"); - // Allocate memory for the file info table - p_file_info_table = (file_info_t *)calloc( FILE_INFO_TABLE_CHUNK_LEN, sizeof( file_info_t ) ); - assert( p_file_info_table != NULL ); - if (p_file_info_table) - { - file_info_table_len = FILE_INFO_TABLE_CHUNK_LEN; - } -} - -/** Terminate this library. Clean up resources. - */ - -void vc_hostfs_exit(void) -{ - vcos_log_unregister(&hostfs_log_cat); - if (p_file_info_table) - { - free(p_file_info_table); - p_file_info_table = NULL; - } -} - -/****************************************************************************** -NAME - vc_hostfs_close - -SYNOPSIS - int vc_hostfs_close(int fildes) - -FUNCTION - Deallocates the file descriptor to a file. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_close(int fildes) -{ - DEBUG_MINOR("vc_hostfs_close(%d)", fildes); - return close(fildes); -} - -/****************************************************************************** -NAME - vc_hostfs_lseek - -SYNOPSIS - long vc_hostfs_lseek(int fildes, long offset, int whence) - -FUNCTION - Sets the file pointer associated with the open file specified by fildes. If - the file is a FIFO (Linux does not support seeking on a FIFO) then, for the - benefit of the Videocore streaming file handlers which do a number of null seeks, - that is, seeks to the current position, the return value is faked without an - actual seek being done. - -RETURNS - Successful completion: offset - Otherwise: -1 -******************************************************************************/ - -long vc_hostfs_lseek(int fildes, long offset, int whence) -{ - return (long) vc_hostfs_lseek64( fildes, (int64_t) offset, whence); -} - - -/****************************************************************************** -NAME - vc_hostfs_lseek64 - -SYNOPSIS - int64_t vc_hostfs_lseek64(int fildes, int64_t offset, int whence) - -FUNCTION - Sets the file pointer associated with the open file specified by fildes. If - the file is a FIFO (Linux does not support seeking on a FIFO) then, for the - benefit of the Videocore streaming file handlers which do a number of null seeks, - that is, seeks to the current position, the return value is faked without an - actual seek being done. - -RETURNS - Successful completion: offset - Otherwise: -1 -******************************************************************************/ - -int64_t vc_hostfs_lseek64(int fildes, int64_t offset, int whence) -{ - DEBUG_MINOR("vc_hostfs_lseek(%d,%" PRId64 ",%d)", fildes, offset, whence); - if (fildes >= file_info_table_len) - { - // File descriptor not in table, so this is an error - DEBUG_MAJOR("vc_hostfs_lseek: invalid fildes %d", fildes); - return -1; - } - else - { - // There is entry in the file info table for this file descriptor, so go - // ahead and handle the seek - int64_t read_offset = p_file_info_table[fildes].read_offset; - - if (p_file_info_table[fildes].is_fifo) - { - // The Videocore is attempting to seek on a FIFO. FIFOs don't support seeking - // but, for the benefit of certain Videocore "streaming" file handlers, we - // will fake limited FIFO seek functionality by computing where a seek - // would take us to - if (whence == SEEK_SET) - { - read_offset = offset; - } - else if (whence == SEEK_CUR) - { - read_offset += offset; - } - else - { - // seeking to the end of FIFO makes no sense, so this is an error - DEBUG_MAJOR("vc_hostfs_lseek(%d,%lld,%d): SEEK_END not supported on FIFO", fildes, (long long)offset, whence); - return -1; - } - } - else - { - // File is not a FIFO, so do the seek - read_offset = lseek64(fildes, offset, whence); - } - p_file_info_table[fildes].read_offset = read_offset; - DEBUG_MINOR("vc_hostfs_lseek returning %" PRId64 ")", read_offset); - return read_offset; - } -} - - - - -/****************************************************************************** -NAME - vc_hostfs_open - -SYNOPSIS - int vc_hostfs_open(const char *path, int vc_oflag) - -FUNCTION - Establishes a connection between a file and a file descriptor. For the benefit - of faking out seeks on a FIFO, we will need to keep track of the read offset for - all reads, and to facilitate this each opened file is given an entry in a local - file info table. - -RETURNS - Successful completion: file descriptor - Otherwise: -1 -******************************************************************************/ - -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; -} - -/****************************************************************************** -NAME - vc_hostfs_read - -SYNOPSIS - int vc_hostfs_read(int fildes, void *buf, unsigned int nbyte) - -FUNCTION - Attempts to read nbyte bytes from the file associated with the file - descriptor, fildes, into the buffer pointed to by buf. For the benefit - of faking out seeks on a FIFO, we keep track of the read offset for all - reads. - -RETURNS - Successful completion: number of bytes read - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_read(int fildes, void *buf, unsigned int nbyte) -{ - if (fildes >= file_info_table_len) - { - // File descriptor not in table, so this is an error - DEBUG_MAJOR("vc_hostfs_read(%d,%p,%u): invalid fildes", fildes, buf, nbyte); - return -1; - } - else - { - // There is entry in the file info table for this file descriptor, so go - // ahead and handle the read - int ret = (int) read(fildes, buf, nbyte); - DEBUG_MINOR("vc_hostfs_read(%d,%p,%u) = %d", fildes, buf, nbyte, ret); - if (ret > 0) - { - p_file_info_table[fildes].read_offset += (long) ret; - } - return ret; - } -} - -/****************************************************************************** -NAME - vc_hostfs_write - -SYNOPSIS - int vc_hostfs_write(int fildes, const void *buf, unsigned int nbyte) - -FUNCTION - Attempts to write nbyte bytes from the buffer pointed to by buf to file - associated with the file descriptor, fildes. - -RETURNS - Successful completion: number of bytes written - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_write(int fildes, const void *buf, unsigned int nbyte) -{ - int ret = (int) write(fildes, buf, nbyte); - DEBUG_MINOR("vc_hostfs_write(%d,%p,%u) = %d", fildes, buf, nbyte, ret); - return ret; -} - -/****************************************************************************** -NAME - vc_hostfs_closedir - -SYNOPSIS - int vc_hostfs_closedir(void *dhandle) - -FUNCTION - Ends a directory list iteration. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_closedir(void *dhandle) -{ - struct fs_dir *fsdir = (struct fs_dir *)dhandle; - int ret = -1; - - DEBUG_MINOR( "vc_hostfs_closedir(%p)", dhandle ); - - if (dhandle && fsdir->dhandle) - { - (void)closedir(fsdir->dhandle); - fsdir->dhandle = NULL; - free(fsdir); - ret = 0; - } - - return ret; -} - -/****************************************************************************** -NAME - vc_hostfs_format - -SYNOPSIS - int vc_hostfs_format(const char *path) - -FUNCTION - Formats the physical file system that contains path. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_format(const char *path) -{ - DEBUG_MINOR("vc_hostfs_format: '%s' not implemented", path); - return -1; -} - -/****************************************************************************** -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 -******************************************************************************/ - -int vc_hostfs_freespace(const char *inPath) -{ - int ret; - - int64_t freeSpace = vc_hostfs_freespace64( inPath ); - - // Saturate return value (need this in case we have a large file system) - if (freeSpace > (int64_t) INT_MAX) - { - ret = INT_MAX; - } - else - { - ret = (int) freeSpace; - } - - return ret; -} - - - - - -/****************************************************************************** -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; -} - - -/****************************************************************************** -NAME - vc_hostfs_get_attr - -SYNOPSIS - int vc_hostfs_get_attr(const char *path, fattributes_t *attr) - -FUNCTION - Gets the file/directory attributes. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_get_attr(const char *path, fattributes_t *attr) -{ - struct stat sb; - - DEBUG_MINOR("vc_hostfs_get_attr: '%s'", path ); - - - *attr = 0; - - if ( stat( path, &sb ) == 0 ) - { - if ( S_ISDIR( sb.st_mode )) - { - *attr |= ATTR_DIRENT; - } - - if (( sb.st_mode & S_IWUSR ) == 0 ) - { - *attr |= ATTR_RDONLY; - } - - return 0; - } - return -1; -} - -/****************************************************************************** -NAME - vc_hostfs_mkdir - -SYNOPSIS - int vc_hostfs_mkdir(const char *path) - -FUNCTION - Creates a new directory named by the pathname pointed to by path. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_mkdir(const char *path) -{ - DEBUG_MINOR( "vc_hostfs_mkdir: '%s'", path ); - if ( mkdir( path, 0777 ) == 0 ) - { - return 0; - } - return -1; -} - -/****************************************************************************** -NAME - vc_hostfs_opendir - -SYNOPSIS - void *vc_hostfs_opendir(const char *dirname) - -FUNCTION - Starts a directory list iteration of sub-directories. - -RETURNS - Successful completion: dhandle (pointer) - Otherwise: NULL -******************************************************************************/ - -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; -} - -/****************************************************************************** -NAME - vc_hostfs_readdir_r - -SYNOPSIS - struct dirent *vc_hostfs_readdir_r(void *dhandle, struct dirent *result) - -FUNCTION - Fills in the passed result structure with details of the directory entry - at the current psition in the directory stream specified by the argument - dhandle, and positions the directory stream at the next entry. If the last - sub-directory has been reached it ends the iteration and begins a new one - for files in the directory. - -RETURNS - Successful completion: result - End of directory stream: NULL -******************************************************************************/ - -struct fs_dirent *vc_hostfs_readdir_r(void *dhandle, struct fs_dirent *result) -{ - struct fs_dir *fsdir = (struct fs_dir *)dhandle; - - DEBUG_MINOR( "vc_hostfs_readdir_r(%p)", fsdir ); - - if (fsdir && result) - { - struct dirent *dent; - - while ((dent = readdir(fsdir->dhandle)) != NULL) - { - struct stat statbuf; - int ret; - - /* Append the filename, and stat the resulting path */ - fsdir->pathbuf[fsdir->pathlen] = '/'; - vcos_safe_strcpy(fsdir->pathbuf, dent->d_name, sizeof(fsdir->pathbuf), fsdir->pathlen + 1); - ret = stat(fsdir->pathbuf, &statbuf); - fsdir->pathbuf[fsdir->pathlen] = '\0'; - - if (ret == 0) - { - vcos_safe_strcpy(result->d_name, dent->d_name, sizeof(result->d_name), 0); - result->d_size = (statbuf.st_size <= 0xffffffff) ? (unsigned int)statbuf.st_size : 0xffffffff; - result->d_attrib = ATTR_NORMAL; - if ((statbuf.st_mode & S_IWUSR) == 0) - result->d_attrib |= ATTR_RDONLY; - if (statbuf.st_mode & S_IFDIR) - result->d_attrib |= ATTR_DIRENT; - result->d_creatime = statbuf.st_ctime; - result->d_modtime = statbuf.st_mtime; - DEBUG_MINOR( "vc_hostfs_readdir_r() = '%s', %x, %x", result->d_name, result->d_size, result->d_attrib ); - break; - } - } - - if (!dent) - { - DEBUG_MINOR( "vc_hostfs_readdir_r() = NULL" ); - rewinddir(fsdir->dhandle); - result = NULL; - } - } - else - { - result = NULL; - } - - return result; -} - -/****************************************************************************** -NAME - vc_hostfs_remove - -SYNOPSIS - int vc_hostfs_remove(const char *path) - -FUNCTION - Removes a file or a directory. A directory must be empty before it can be - deleted. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -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; - } - - free(pathbuf); - - return ret; -} - -/****************************************************************************** -NAME - vc_hostfs_rename - -SYNOPSIS - int vc_hostfs_rename(const char *old, const char *new) - -FUNCTION - Changes the name of a file. The old and new pathnames must be on the same - physical file system. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_rename(const char *old, const char *new) -{ - char *oldbuf = strdup(old); - char *newbuf = strdup(new); - int ret = -1; - - DEBUG_MINOR( "vc_hostfs_rename: '%s' to '%s'", old, new ); - - if (oldbuf && newbuf) - { - backslash_to_slash(oldbuf); - backslash_to_slash(newbuf); - - if ( rename( oldbuf, newbuf ) == 0 ) - ret = 0; - } - - if (oldbuf) - free(oldbuf); - - if (newbuf) - free(newbuf); - - return ret; -} - -/****************************************************************************** -NAME - vc_hostfs_set_attr - -SYNOPSIS - int vc_hostfs_set_attr(const char *path, fattributes_t attr) - -FUNCTION - Sets file/directory attributes. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_set_attr(const char *path, fattributes_t attr) -{ - char *pathbuf = strdup(path); - int ret = -1; - - DEBUG_MINOR( "vc_hostfs_set_attr: '%s', %x", path, attr ); - - if (pathbuf) - { - mode_t mode = 0; - struct stat sb; - - backslash_to_slash(pathbuf); - - if ( stat( path, &sb ) == 0 ) - { - mode = sb.st_mode; - - if ( attr & ATTR_RDONLY ) - { - mode &= ~S_IWUSR; - } - else - { - mode |= S_IWUSR; - } - - /* coverity[toctou] Not doing anything security-relevant here, - * so the race condition is harmless */ - if ( chmod( path, mode ) == 0 ) - ret = 0; - } - } - - if (pathbuf) - free(pathbuf); - - return ret; -} - -/****************************************************************************** -NAME - vc_hostfs_setend - -SYNOPSIS - int vc_hostfs_setend(int fildes) - -FUNCTION - Truncates file at current position. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_setend(int filedes) -{ - off_t currPosn; - - if (( currPosn = lseek( filedes, 0, SEEK_CUR )) != (off_t)-1 ) - { - if ( ftruncate( filedes, currPosn ) == 0 ) - { - return 0; - } - } - return -1; -} - - -/****************************************************************************** -NAME - vc_hostfs_totalspace64 - -SYNOPSIS - int64_t vc_hostfs_totalspace64(const char *path) - -FUNCTION - Returns the total amount of space on the physical file system that contains - path. - -RETURNS - Successful completion: total space - Otherwise: -1 -******************************************************************************/ - -int64_t vc_hostfs_totalspace64(const char *inPath) -{ - char *path = strdup( inPath ); - int64_t ret = -1; - struct statfs fsStat; - - // Replace all '\' with '/' - if (path) - { - backslash_to_slash( path ); - - ret = statfs( path, &fsStat ); - - if (ret == 0) - { - ret = fsStat.f_bsize * fsStat.f_blocks; - } - else - { - ret = -1; - } - } - - DEBUG_MINOR( "vc_hostfs_totalspace for '%s' returning %" PRId64 "", path, ret ); - - if (path) - free( path ); - return ret; -} - - -/****************************************************************************** -NAME - vc_hostfs_totalspace - -SYNOPSIS - int vc_hostfs_totalspace(const char *path) - -FUNCTION - Returns the total amount of space on the physical file system that contains - path. - -RETURNS - Successful completion: total space - Otherwise: -1 -******************************************************************************/ - -int vc_hostfs_totalspace(const char *inPath) -{ - int ret; - int64_t totalSpace = vc_hostfs_totalspace64(inPath); - - // Saturate return value (need this in case we have a large file system) - if (totalSpace > (int64_t) INT_MAX) - { - ret = INT_MAX; - } - else - { - ret = (int) totalSpace; - } - return ret; -} - -/****************************************************************************** -NAME - backslash_to_slash - -SYNOPSIS - void backslash_to_slash( char *s ) - -FUNCTION - Convert all '\' in a string to '/'. - -RETURNS - None. -******************************************************************************/ - -static void backslash_to_slash( char *s ) -{ - while ( *s != '\0' ) - { - if ( *s == '\\' ) - { - *s = '/'; - } - s++; - } -} - -/****************************************************************************** -NAME - vc_hostfs_scandisk - -SYNOPSIS - void vc_hostfs_scandisk(const char *path) - -FUNCTION - Invalidates any cluster chains in the FAT that are not referenced - in any directory structures - -RETURNS - Void -******************************************************************************/ - -void vc_hostfs_scandisk(const char *path) -{ - (void)path; - - // not yet implemented -} - - -/****************************************************************************** -NAME - vc_hostfs_chkdsk - -SYNOPSIS - int vc_hostfs_chkdsk(const char *path, int fix_errors) - -FUNCTION - Checks whether or not a FAT filesystem is corrupt or not. If fix_errors - is TRUE behaves exactly as vc_filesys_scandisk. - -RETURNS - Successful completion: 0 - Otherwise: indicates failure -******************************************************************************/ - -int vc_hostfs_chkdsk(const char *path, int fix_errors) -{ - (void)path; - (void)fix_errors; - return 0; -} - diff --git a/interface/vmcs_host/vc_fileservice_defs.h b/interface/vmcs_host/vc_fileservice_defs.h deleted file mode 100644 index cfcb738ce..000000000 --- a/interface/vmcs_host/vc_fileservice_defs.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -// File service command enumeration. - -#ifndef VC_FILESERVICE_DEFS_H -#define VC_FILESERVICE_DEFS_H - -#define VC_FILESERV_VER 1 -/* Definitions (not used by API) */ -#define FS_MAX_DATA 8192 //4096 - -/* Protocol (not used by API) version 1.2 */ - -enum { - /* Over-the-wire file open flags */ - VC_O_RDONLY = 0x01, - VC_O_WRONLY = 0x02, - VC_O_RDWR = 0x04, - VC_O_APPEND = 0x08, - VC_O_CREAT = 0x10, - VC_O_TRUNC = 0x20, - VC_O_EXCL = 0x40, - - /* Request Commands (VC->Host->VC) */ - - /* These commands don't require a pathname */ - VC_FILESYS_RESET = 64, - VC_FILESYS_CLOSE = 65, - VC_FILESYS_CLOSEDIR = 66, - VC_FILESYS_LSEEK = 67, - VC_FILESYS_READ = 68, - VC_FILESYS_READDIR = 69, - VC_FILESYS_SETEND = 70, - VC_FILESYS_WRITE = 71, - - /* These commands require a pathname */ - VC_FILESYS_FORMAT = 72, - VC_FILESYS_FREESPACE = 73, - VC_FILESYS_GET_ATTR = 74, - VC_FILESYS_MKDIR = 75, - VC_FILESYS_OPEN = 76, - VC_FILESYS_OPENDIR = 77, - VC_FILESYS_REMOVE = 78, - VC_FILESYS_RENAME = 79, - VC_FILESYS_SET_ATTR = 80, - VC_FILESYS_SCANDISK = 81, - VC_FILESYS_TOTALSPACE = 82, - VC_FILESYS_DISKWRITABLE=83, - VC_FILESYS_OPEN_DISK_RAW = 84, - VC_FILESYS_CLOSE_DISK_RAW = 85, - VC_FILESYS_NUMSECTORS = 86, - VC_FILESYS_READ_SECTORS = 87, - VC_FILESYS_WRITE_SECTORS = 88, - - VC_FILESYS_MOUNT = 89, - VC_FILESYS_UMOUNT = 90, - VC_FILESYS_FSTYPE = 91, - - VC_FILESYS_READ_DIRECT = 92, - - VC_FILESYS_LSEEK64 = 93, - VC_FILESYS_FREESPACE64 = 94, - VC_FILESYS_TOTALSPACE64= 95, - VC_FILESYS_OPEN_DISK = 96, - VC_FILESYS_CLOSE_DISK = 97, - - /* extra simple functions for mass storage testing */ - VC_FILESYS_READ_SECTOR = 98, //1sect - VC_FILESYS_STREAM_SECTOR_BEGIN = 99, - VC_FILESYS_STREAM_SECTOR_END = 100, - VC_FILESYS_WRITE_SECTOR = 101, - VC_FILESYS_FSTAT = 102, - VC_FILESYS_DIRSIZE = 103, - VC_FILESYS_LIST_DIRS = 104, - VC_FILESYS_LIST_FILES = 105, - VC_FILESYS_NUM_DIRS = 106, - VC_FILESYS_NUM_FILES = 107, - VC_FILESYS_MAX_FILESIZE = 108, - VC_FILESYS_CHKDSK = 109, -}; - -/* Parameters for lseek */ - -#define VC_FILESYS_SEEK_SET 0 /* Set file pointer to "offset" */ -#define VC_FILESYS_SEEK_CUR 1 /* Set file pointer to current plus "offset" */ -#define VC_FILESYS_SEEK_END 2 /* Set file pointer to EOF plus "offset" */ - -/* Return values of vc_filesys_type */ -#define VC_FILESYS_FS_UNKNOWN 0 -#define VC_FILESYS_FS_FAT12 1 -#define VC_FILESYS_FS_FAT16 2 -#define VC_FILESYS_FS_FAT32 3 - -#endif diff --git a/interface/vmcs_host/vc_vchi_filesys.c b/interface/vmcs_host/vc_vchi_filesys.c deleted file mode 100644 index 26a34b959..000000000 --- a/interface/vmcs_host/vc_vchi_filesys.c +++ /dev/null @@ -1,2509 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#include -#include -#include -#include -#include - -#include "vchost.h" - -#include "interface/vcos/vcos.h" -#include "interface/vchi/vchi.h" -#include "interface/vchi/common/endian.h" - -#include "vc_vchi_filesys.h" -#include "interface/vmcs_host/vc_vchi_fileservice_defs.h" - -/****************************************************************************** -Global data. -******************************************************************************/ - -/****************************************************************************** -Local types and defines. -******************************************************************************/ -typedef enum { - VC_SECTOR_IO_NONE, - VC_SECTOR_IO_READING, - VC_SECTOR_IO_WRITING -} VC_SECTOR_IO_T; - -typedef struct { - - VCHI_SERVICE_HANDLE_T open_handle; - - int32_t num_connections; - - //Host->2727 - FILESERV_MSG_T fileserv_msg; - - //2727->Host XXX - FILESERV_MSG_T vc_msg; - - VCOS_THREAD_T filesys_thread; - - // used to signal response has arrived - VCOS_EVENT_T response_event; - - //we lock each vc_filesys function call - VCOS_MUTEX_T filesys_lock; - - //used to signal msg arrivals - VCOS_EVENT_T filesys_msg_avail; - - // Outstanding transaction's ID - volatile uint32_t cur_xid; - - // Copy of the header code from responses - int32_t resp_code; - int32_t err_no; - - char *bulk_buffer; - int32_t initialised; - -} FILESYS_SERVICE_T; - -static FILESYS_SERVICE_T vc_filesys_client; - - -/****************************************************************************** -Static functions. -******************************************************************************/ - -//Lock the host state -static __inline int32_t lock_obtain (void) { - int ret = -1; - if(vc_filesys_client.initialised && vcos_mutex_lock(&vc_filesys_client.filesys_lock) == VCOS_SUCCESS) { - vchi_service_use(vc_filesys_client.open_handle); - ret = 0; - } - return ret; -} - -//Unlock the host state -static __inline void lock_release (void) { - vcos_assert(vc_filesys_client.initialised); - vchi_service_release(vc_filesys_client.open_handle); - vcos_mutex_unlock(&vc_filesys_client.filesys_lock); -} - -// File Service VCHI functions - -static int vchi_msg_stub(FILESERV_MSG_T* msg, uint16_t cmd_id, int msg_len ); - -static int vchi_msg_stub_noblock(FILESERV_MSG_T* msg, uint16_t cmd_id, int msg_len); - -static int vc_fs_message_handler( FILESERV_MSG_T* msg, uint32_t nbytes ); - -static void *filesys_task_func(void *arg); - -static void filesys_callback( void *callback_param, VCHI_CALLBACK_REASON_T reason, void *msg_handle ); - - - -#ifdef PRINTF -#ifdef WIN32 -#define printf tprintf -#endif -static void showmsg(VC_MSGFIFO_CMD_HEADER_T const * head, - struct file_service_msg_body const * body); -#endif -static int fs_host_direntbytestream_create(struct dirent *d, void *buffer); -static void fs_host_direntbytestream_interp(struct dirent *d, void *buffer); - -/*---------------------------------------------------------------------------*/ - -/****************************************************************************** -NAME - vc_filesys_init - -SYNOPSIS - vc_filesys_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) { - -FUNCTION - Initialise the file system for use. A negative return value - indicates failure (which may mean it has not been started on VideoCore). - -RETURNS - int -******************************************************************************/ -int vc_vchi_filesys_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) -{ - int32_t success = 0; - SERVICE_CREATION_T filesys_parameters; - VCOS_THREAD_ATTR_T attrs; - VCOS_STATUS_T status; - - // record the number of connections - memset( &vc_filesys_client, 0, sizeof(FILESYS_SERVICE_T) ); - vc_filesys_client.num_connections = num_connections; - - if(!vcos_verify(vc_filesys_client.num_connections < 2)) - return -1; - - status = vcos_mutex_create(&vc_filesys_client.filesys_lock, "HFilesys"); - vcos_assert(status == VCOS_SUCCESS); - - status = vcos_event_create(&vc_filesys_client.filesys_msg_avail, "HFilesys"); - vcos_assert(status == VCOS_SUCCESS); - - //create sema used to signal cmd response has arrived - status = vcos_event_create(&vc_filesys_client.response_event, "HFilesys"); - vcos_assert(status == VCOS_SUCCESS); - - vc_filesys_client.bulk_buffer = vcos_malloc_aligned(FILESERV_MAX_BULK, 16, "HFilesys bulk_recv"); - vc_filesys_client.cur_xid = 0; - - memset(&filesys_parameters, 0, sizeof(filesys_parameters)); - filesys_parameters.service_id = FILESERV_4CC; // 4cc service code - filesys_parameters.connection = connections[0]; // passed in fn ptrs - filesys_parameters.rx_fifo_size = 0; // rx fifo size (unused) - filesys_parameters.tx_fifo_size = 0; // tx fifo size (unused) - filesys_parameters.callback = &filesys_callback; - filesys_parameters.callback_param = &vc_filesys_client.filesys_msg_avail; - filesys_parameters.want_unaligned_bulk_rx = 0; - filesys_parameters.want_unaligned_bulk_tx = 0; - filesys_parameters.want_crc = 0; - filesys_parameters.version.version = VC_FILESERV_VER; - filesys_parameters.version.version_min = VC_FILESERV_VER; - - success = vchi_service_open( initialise_instance, &filesys_parameters, &vc_filesys_client.open_handle ); - vcos_assert( success == 0 ); - - vcos_thread_attr_init(&attrs); - vcos_thread_attr_setstacksize(&attrs, 4000); - vcos_thread_attr_settimeslice(&attrs, 1); - - vc_filesys_client.initialised = 1; - - status = vcos_thread_create(&vc_filesys_client.filesys_thread, "HFilesys", &attrs, filesys_task_func, NULL); - vcos_assert(status == VCOS_SUCCESS); - - /* Not using service immediately - release videocore */ - vchi_service_release(vc_filesys_client.open_handle); - - return (int)success; -} - -static void *filesys_task_func(void *arg) -{ - int32_t success; - uint32_t msg_len; - - (void)arg; - - vc_hostfs_init(); - - while(1) { - // wait for the semaphore to say that there is a message - if (vcos_event_wait(&vc_filesys_client.filesys_msg_avail) != VCOS_SUCCESS || vc_filesys_client.initialised == 0) - break; - - vchi_service_use(vc_filesys_client.open_handle); - // read the message - should we really "peek" this - while (1) { - success = vchi_msg_dequeue(vc_filesys_client.open_handle, &vc_filesys_client.vc_msg, - sizeof(vc_filesys_client.vc_msg), &msg_len, VCHI_FLAGS_NONE); - if (!success) - break; - - /* coverity[tainted_string_argument] */ - success = (int32_t) vc_fs_message_handler(&vc_filesys_client.vc_msg, msg_len); - (void)success; - } - vchi_service_release(vc_filesys_client.open_handle); - } - - return 0; -} - - -/****************************************************************************** -NAME - filesys_callback - -SYNOPSIS - void filesys_callback( void *callback_param, - const VCHI_CALLBACK_REASON_T reason, - const void *msg_handle ) - -FUNCTION - VCHI callback - -RETURNS - int -******************************************************************************/ -static void filesys_callback( void *callback_param, - const VCHI_CALLBACK_REASON_T reason, - void *msg_handle ) -{ - (void)msg_handle; - - switch( reason ) { - - case VCHI_CALLBACK_MSG_AVAILABLE: - { - VCOS_EVENT_T *event = (VCOS_EVENT_T *) callback_param; - if(event) - vcos_event_signal(event); - } - break; - - case VCHI_CALLBACK_BULK_RECEIVED: - break; - case VCHI_CALLBACK_BULK_SENT: - break; - - default: - return; - } -} - -/****************************************************************************** -NAME - vc_filesys_stop - -SYNOPSIS - void vc_filesys_stop() - -FUNCTION - This tells us that the file system service has stopped, thereby preventing - any of the functions from doing anything. - -RETURNS - void -******************************************************************************/ - -void vc_filesys_stop () -{ - int32_t result; - void *dummy; - - if(lock_obtain() != 0) - return; - - result = vchi_service_close(vc_filesys_client.open_handle); - vcos_assert(result == 0); - - vc_filesys_client.initialised = 0; - - vcos_event_signal(&vc_filesys_client.filesys_msg_avail); - vcos_thread_join(&vc_filesys_client.filesys_thread, &dummy); - - vcos_event_delete(&vc_filesys_client.filesys_msg_avail); - vcos_event_delete(&vc_filesys_client.response_event); - vcos_mutex_delete(&vc_filesys_client.filesys_lock); - - if(vc_filesys_client.bulk_buffer) - vcos_free(vc_filesys_client.bulk_buffer); -} - -/****************************************************************************** -NAME - vc_filesys_single_param - -SYNOPSIS - int vc_filesys_single_param(uint32_t param, uint32_t fn) - -FUNCTION - Utility function for implementing filesys methods - -RETURNS - void -******************************************************************************/ -static int vc_filesys_single_param(uint32_t param, uint32_t fn) -{ - int success = -1; - - if(lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = param; - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, fn, 4) == FILESERV_RESP_OK) - success = 0; - - lock_release(); - } - - return success; -} - -/****************************************************************************** -NAME - vc_filesys_single_string - -SYNOPSIS - int vc_filesys_single_string(uint32_t param, const char *str, uint32_t fn, int return_param) - -FUNCTION - Utility function for implementing filesys methods - -RETURNS - void -******************************************************************************/ -static int vc_filesys_single_string(uint32_t param, const char *str, uint32_t fn, int return_param) -{ - int ret = -1; - int len = strlen(str); - - if(len < FILESERV_MAX_DATA && lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = param; - /* coverity[buffer_size_warning] - the length of str has already been checked */ - strncpy((char*)vc_filesys_client.fileserv_msg.data, str, FILESERV_MAX_DATA); - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, fn, len+1+16) == FILESERV_RESP_OK) - { - if(return_param) - ret = (int) vc_filesys_client.fileserv_msg.params[0]; - else - ret = 0; - } - - lock_release(); - } - - return ret; -} - -/* Standard UNIX low-level library functions (declared in unistd.h) */ -/****************************************************************************** -NAME - vc_filesys_close - -SYNOPSIS - int vc_filesys_close(int fildes) - -FUNCTION - Deallocates the file descriptor to a file. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_close(int fildes) -{ - return vc_filesys_single_param((uint32_t) fildes, VC_FILESYS_CLOSE); -} - - -/****************************************************************************** -NAME - vc_filesys_lseek - -SYNOPSIS - long vc_filesys_lseek(int fildes, long offset, int whence) - -FUNCTION - Sets the file pointer associated with the open file specified by fildes. - -RETURNS - Successful completion: offset - Otherwise: -1 -******************************************************************************/ - -long vc_filesys_lseek(int fildes, long offset, int whence) -{ - long set = -1; - - if(lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = (uint32_t) fildes; - vc_filesys_client.fileserv_msg.params[1] = (uint32_t) offset; - vc_filesys_client.fileserv_msg.params[2] = (uint32_t) whence; - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_LSEEK, 12) == FILESERV_RESP_OK) - set = (long) vc_filesys_client.fileserv_msg.params[0]; - - lock_release(); - } - - return set; -} - -/****************************************************************************** -NAME - vc_filesys_lseek64 - -SYNOPSIS - int64_t vc_filesys_lseek64(int fildes, int64_t offset, int whence) - -FUNCTION - Sets the file pointer associated with the open file specified by fildes. - -RETURNS - Successful completion: file pointer value - Otherwise: -1 -******************************************************************************/ - -int64_t vc_filesys_lseek64(int fildes, int64_t offset, int whence) -{ - int64_t set = -1; - - if(lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = (uint32_t) fildes; - vc_filesys_client.fileserv_msg.params[1] = (uint32_t) offset; // LSB - vc_filesys_client.fileserv_msg.params[2] = (uint32_t)(offset >> 32); // MSB - vc_filesys_client.fileserv_msg.params[3] = (uint32_t) whence; - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_LSEEK64, 16) == FILESERV_RESP_OK) - { - set = vc_filesys_client.fileserv_msg.params[0]; - set += (int64_t)vc_filesys_client.fileserv_msg.params[1] << 32; - } - - lock_release(); - } - - return set; -} - -/****************************************************************************** -NAME - vc_filesys_mount - -SYNOPSIS - int vc_filesys_mount(const char *device, const char *mountpoint, const char *options) - -FUNCTION - Mounts a filesystem at a given location - -RETURNS - Successful completion: 0 -******************************************************************************/ - -int vc_filesys_mount(const char *device, const char *mountpoint, const char *options) -{ - int set = -1, len; - int a = strlen(device); - int b = strlen(mountpoint); - int c = strlen(options); - - if(a + b + c + 3 < FILESERV_MAX_DATA && lock_obtain() == 0) - { - char *str = (char *) vc_filesys_client.fileserv_msg.data; - - memcpy(str, device, a); - str[a] = 0; - memcpy(str+a+1, mountpoint, b); - str[a+1+b] = 0; - memcpy(str+a+b+2, options, c); - str[a+b+c+2] = 0; - len = a + b + c + 3 + (int)(((FILESERV_MSG_T *)0)->data); - len = ((len + (VCHI_BULK_GRANULARITY-1)) & ~(VCHI_BULK_GRANULARITY-1)) + VCHI_BULK_GRANULARITY; - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_MOUNT, len) == FILESERV_RESP_OK) - set = (int) vc_filesys_client.fileserv_msg.params[0]; - - lock_release(); - } - - return set; -} - -/****************************************************************************** -NAME - vc_filesys_umount - -SYNOPSIS - int vc_filesys_mount(const char *mountpoint) - -FUNCTION - Un-mounts a removable device from the location that it has been mounted - to earlier in the session - -RETURNS - Successful completion: 0 -******************************************************************************/ - -int vc_filesys_umount(const char *mountpoint) -{ - return vc_filesys_single_string(0, mountpoint, VC_FILESYS_UMOUNT, 1); -} - -/****************************************************************************** -NAME - vc_filesys_open - -SYNOPSIS - int vc_filesys_open(const char *path, int vc_oflag) - -FUNCTION - Establishes a connection between a file and a file descriptor. - -RETURNS - Successful completion: file descriptor - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_open(const char *path, int vc_oflag) -{ - return vc_filesys_single_string((uint32_t) vc_oflag, path, VC_FILESYS_OPEN, 1); -} - - -/****************************************************************************** -NAME - vc_filesys_read - -SYNOPSIS - int vc_filesys_read(int fildes, void *buf, unsigned int nbyte) - -FUNCTION - Attempts to read nbyte bytes from the file associated with the file - descriptor, fildes, into the buffer pointed to by buf. - -RETURNS - Successful completion: number of bytes read - Otherwise: -1 -******************************************************************************/ - -/****************************************************************************** - -FUNCTION - - -RETURNS - Successful completion: the number of bytes received - Otherwise negative error code -******************************************************************************/ -static int vc_vchi_msg_bulk_read(FILESERV_MSG_T* msg, uint16_t cmd_id, uint32_t transfer_len, uint8_t* recv_addr ) -{ - uint32_t i; - int msg_len; - uint32_t host_align_bytes; - uint32_t num_bytes_read; - int32_t success; - - //this is current file_io_buffer size so assuming never more than this - //otherwise we will split the read into chunks - if(!vcos_verify(transfer_len <= FILESERV_MAX_BULK)) - return -1; - - //number of bytes required to align recv_addr - host_align_bytes = VCHI_BULK_ALIGN_NBYTES(recv_addr); - - i = vc_filesys_client.cur_xid + 1; - i &= 0x7fffffffUL; - vc_filesys_client.cur_xid = i; - - msg->xid = vc_filesys_client.cur_xid; - - //fill in cmd id: VC_FILESYS_READ etc - msg->cmd_code = cmd_id; - - msg->params[2] = transfer_len; - - msg->params[3] = host_align_bytes; - - //24 comes from the static size of FILESERV_MSG_T - msg_len = 24; - - if(vchi_msg_queue( vc_filesys_client.open_handle, msg, (uint32_t)msg_len, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL ) != 0) - return -1; - - //wait to receive response - if(vcos_event_wait(&vc_filesys_client.response_event) != VCOS_SUCCESS || msg->cmd_code == FILESERV_RESP_ERROR) - return -1; - - //total bytes read - num_bytes_read = msg->params[0]; - - if(!vcos_verify(num_bytes_read <= FILESERV_MAX_BULK)) - return -1; - - //everything is in msg->data - if(msg->cmd_code == FILESERV_RESP_OK) { - if(!vcos_verify(num_bytes_read <= FILESERV_MAX_DATA)) - return -1; - - memcpy(recv_addr, msg->data, num_bytes_read); - return (int) num_bytes_read; - } - -// Make this code conditional to stop Coverity complaining about dead code -#if VCHI_BULK_ALIGN > 1 - //copy host_align_bytes bytes to recv_addr, now ready for bulk - if(host_align_bytes) { - memcpy(recv_addr, msg->data, host_align_bytes); - recv_addr += host_align_bytes; - transfer_len -= host_align_bytes; - } -#endif - - //receive bulk from host - if(msg->cmd_code == FILESERV_BULK_WRITE){ - //number of end bytes - uint32_t end_bytes = msg->params[1]; - //calculate what portion of read transfer by bulk - uint32_t bulk_bytes = (num_bytes_read-host_align_bytes-end_bytes); - - success = vchi_bulk_queue_receive(vc_filesys_client.open_handle, - recv_addr, - bulk_bytes, - VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE, - NULL ); - if(!vcos_verify(success == 0)) - return -1; - - recv_addr+=bulk_bytes; - - //copy any left over end bytes from original msg - if(end_bytes) - memcpy(recv_addr, &msg->data[host_align_bytes], end_bytes); - } - else { - return -1; - } - - return (int) num_bytes_read; -} - - -int vc_filesys_read(int fildes, void *buf, unsigned int nbyte) -{ - int bulk_bytes = 0; - int actual_read = 0; - int total_byte = 0; - uint8_t* ptr = (uint8_t*)buf; - - if (nbyte == 0) { - return 0; - } - - if(lock_obtain() == 0) - { - do { - bulk_bytes = nbyte > FILESERV_MAX_BULK ? FILESERV_MAX_BULK : nbyte; - - //we overwrite the response here so fill in data again - vc_filesys_client.fileserv_msg.params[0] = (uint32_t)fildes; - vc_filesys_client.fileserv_msg.params[1] = 0xffffffffU; // offset: use -1 to indicate no offset - - actual_read = vc_vchi_msg_bulk_read(&vc_filesys_client.fileserv_msg , VC_FILESYS_READ, (uint32_t)bulk_bytes, (uint8_t*)ptr); - - if(bulk_bytes != actual_read) { - if(actual_read < 0) - total_byte = -1; - else - total_byte += actual_read; - //exit loop - break; - } - - ptr+=bulk_bytes; - nbyte -= actual_read; - total_byte += actual_read; - }while(nbyte > 0); - - lock_release(); - } - - return total_byte; -} - -/****************************************************************************** -NAME - vc_filesys_write - -SYNOPSIS - int vc_filesys_write(int fildes, const void *buf, unsigned int nbyte) - -FUNCTION - Attempts to write nbyte bytes from the buffer pointed to by buf to file - associated with the file descriptor, fildes. - -RETURNS - Successful completion: number of bytes written - Otherwise: -1 -******************************************************************************/ - -/****************************************************************************** - -FUNCTION - - -RETURNS - Successful completion: the number of bytes received - Otherwise negative error code -******************************************************************************/ -static int vc_vchi_msg_bulk_write(FILESERV_MSG_T* msg, uint16_t cmd_id, uint32_t transfer_len, uint8_t* send_addr ) -{ - uint32_t i; - int msg_len; - uint32_t align_bytes = 0; - uint32_t bulk_end_bytes = 0; - uint32_t bulk_bytes = 0; - int num_bytes_written = -1; - - //this is current file_io_buffer size so assuming never more than this - //otherwise we will split the read into chunks - if(!vcos_verify(transfer_len <= FILESERV_MAX_BULK)) - return -1; - - i = vc_filesys_client.cur_xid + 1; - i &= 0x7fffffffUL; - vc_filesys_client.cur_xid = i; - - msg->xid = vc_filesys_client.cur_xid; - - //fill in cmd id VC_FILESYS_OPEN etc - msg->cmd_code = cmd_id; - - msg->params[2] = transfer_len; - - //24 comes from the static size of FILESERV_MSG_T - msg_len = 24; - - //put it all in one msg - if(transfer_len <= FILESERV_MAX_DATA) { - memcpy(msg->data, send_addr, transfer_len); - msg->params[3] = 0; - msg_len += transfer_len; - //send request to write to host - if(vchi_msg_queue( vc_filesys_client.open_handle, msg, (uint32_t)msg_len, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL ) != 0) - return -1; - - // wait to receive response - if(vcos_event_wait(&vc_filesys_client.response_event) == VCOS_SUCCESS && - msg->cmd_code != FILESERV_RESP_ERROR && msg->params[0] == transfer_len) - { - //vc_fs_message_handler copies resp into outgoing msg struct - num_bytes_written = (int)msg->params[0]; - } - } - else { - //required to make send_addr for bulk - align_bytes = VCHI_BULK_ALIGN_NBYTES(send_addr); - -// Make this code conditional to stop Coverity complaining about dead code -#if VCHI_BULK_ALIGN > 1 - //copy vc_align bytes to msg->data, send_addr ready for bulk - if(align_bytes) { - msg->params[3] = align_bytes; - memcpy(msg->data, send_addr, align_bytes); - transfer_len -= align_bytes; - send_addr += align_bytes; - msg_len += align_bytes; - } - else -#endif - msg->params[3] = 0; - - // need to ensure we have the appropriate alignment - bulk_bytes = (transfer_len)&(~(VCHI_BULK_GRANULARITY-1)); - - bulk_end_bytes = transfer_len-bulk_bytes; - - if(bulk_end_bytes) { - memcpy(msg->data+align_bytes, send_addr+bulk_bytes, bulk_end_bytes); - msg_len += bulk_end_bytes; - } - - //send request to write to host - if(vchi_msg_queue( vc_filesys_client.open_handle, msg, (uint32_t)msg_len, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL ) != 0) - return -1; - - //send bulk VCHI_FLAGS_BLOCK_UNTIL_QUEUED is ok because we wait for response msg with actual length written - if(vchi_bulk_queue_transmit( vc_filesys_client.open_handle, - send_addr, - bulk_bytes, - VCHI_FLAGS_BLOCK_UNTIL_QUEUED, - NULL ) != 0) - return -1; - - // wait to receive response sent by filsys_task_func - if(vcos_event_wait(&vc_filesys_client.response_event) == VCOS_SUCCESS && msg->cmd_code == FILESERV_BULK_READ) - num_bytes_written = (int)msg->params[0]; - } - - return num_bytes_written; -} - - -int vc_filesys_write(int fildes, const void *buf, unsigned int nbyte) -{ - int num_wrt = 0; - int bulk_bytes = 0; - int actual_written = 0; - uint8_t *ptr = (uint8_t*) buf; - - if (nbyte == 0) { - return 0; - } - - if(lock_obtain() == 0) - { - //will split the read into 4K chunks based on vc fwrite buffer size array size - //we will make this more dynamic later - do { - bulk_bytes = nbyte > FILESERV_MAX_BULK ? FILESERV_MAX_BULK : nbyte; - - //we overwrite the response here so fill in data again - vc_filesys_client.fileserv_msg.params[0] = (uint32_t)fildes; - vc_filesys_client.fileserv_msg.params[1] = 0xffffffffU; // offset: use -1 to indicate no offset - - actual_written = vc_vchi_msg_bulk_write(&vc_filesys_client.fileserv_msg , VC_FILESYS_WRITE, (uint32_t)bulk_bytes, (uint8_t*)ptr); - - if(bulk_bytes != actual_written) { - if(actual_written < 0) - num_wrt = -1; - else - num_wrt += actual_written; - break; - } - - ptr+=bulk_bytes; - nbyte -= actual_written; - num_wrt += actual_written; - }while(nbyte > 0); - - lock_release(); - } - - return num_wrt; -} - - -/* Directory management functions */ - -/****************************************************************************** -NAME - vc_filesys_closedir - -SYNOPSIS - int vc_filesys_closedir(void *dhandle) - -FUNCTION - Ends a directory list iteration. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_closedir(void *dhandle) -{ - return vc_filesys_single_param((uint32_t)dhandle, VC_FILESYS_CLOSEDIR); -} - - -/****************************************************************************** -NAME - vc_filesys_format - -SYNOPSIS - int vc_filesys_format(const char *path) - -FUNCTION - Formats the physical file system that contains path. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_format(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_FORMAT, 0); -} - - -/****************************************************************************** -NAME - vc_filesys_freespace - -SYNOPSIS - int vc_filesys_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 -******************************************************************************/ - -int vc_filesys_freespace(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_FREESPACE, 1); -} - - -/****************************************************************************** -NAME - vc_filesys_freespace64 - -SYNOPSIS - int64_t vc_filesys_freespace64(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_filesys_freespace64(const char *path) -{ - int64_t freespace = -1LL; - - if(lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, path, FS_MAX_PATH); - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_FREESPACE64, - (int)(16+strlen((char *)vc_filesys_client.fileserv_msg.data)+1)) == FILESERV_RESP_OK) - { - freespace = vc_filesys_client.fileserv_msg.params[0]; - freespace += (int64_t)vc_filesys_client.fileserv_msg.params[1] << 32; - } - - lock_release(); - } - - return freespace; -} - - -/****************************************************************************** -NAME - vc_filesys_get_attr - -SYNOPSIS - int vc_filesys_get_attr(const char *path, fattributes_t *attr) - -FUNCTION - Gets the file/directory attributes. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_get_attr(const char *path, fattributes_t *attr) -{ - int success = -1; - - if(lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, path, FS_MAX_PATH); - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_GET_ATTR, - (int)(16+strlen((char *)vc_filesys_client.fileserv_msg.data)+1)) == FILESERV_RESP_OK) - { - success = 0; - *attr = (fattributes_t) vc_filesys_client.fileserv_msg.params[0]; - } - - lock_release(); - } - - return success; -} - - -/****************************************************************************** -NAME - vc_filesys_fstat - -SYNOPSIS - int64_t vc_filesys_fstat(int fildes, FSTAT_T *buf) - -FUNCTION - Returns the file stat info structure for the specified file. - This structure includes date and size info. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_fstat(int fildes, FSTAT_T *buf) -{ - int success = -1; - - if (buf != NULL && lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = (uint32_t) fildes; - if ( vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_FSTAT, 4) == FILESERV_RESP_OK ) - { - buf->st_size = (int64_t)vc_filesys_client.fileserv_msg.params[0]; // LSB - buf->st_size |= (int64_t)vc_filesys_client.fileserv_msg.params[1] << 32; // MSB - buf->st_modtime = (uint32_t)vc_filesys_client.fileserv_msg.params[2]; - // there's room for expansion here to pass across more elements of the structure if required... - success = 0; - } - - lock_release(); - } - - return success; -} - - -/****************************************************************************** -NAME - vc_filesys_mkdir - -SYNOPSIS - int vc_filesys_mkdir(const char *path) - -FUNCTION - Creates a new directory named by the pathname pointed to by path. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_mkdir(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_MKDIR, 0); -} - - -/****************************************************************************** -NAME - vc_filesys_opendir - -SYNOPSIS - void *vc_filesys_opendir(const char *dirname) - -FUNCTION - Starts a directory list iteration. - -RETURNS - Successful completion: dhandle (pointer) - Otherwise: NULL -******************************************************************************/ - -void *vc_filesys_opendir(const char *dirname) -{ - return (void *) vc_filesys_single_string(0, dirname, VC_FILESYS_OPENDIR, 1); -} - - -/****************************************************************************** -NAME - vc_filesys_dirsize - -SYNOPSIS - int vc_filesys_dirsize(const char *path) - -FUNCTION - Look through the specified directory tree and sum the file sizes. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int64_t vc_filesys_dirsize(const char *path, uint32_t *num_files, uint32_t *num_dirs) -{ - int64_t ret = -1; - - if(lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, path, FS_MAX_PATH); - - // FIXME: Should probably use a non-blocking call here since it may take a - // long time to do the operation... - if ( vchi_msg_stub(&vc_filesys_client.fileserv_msg, - VC_FILESYS_DIRSIZE, - (int)(16+strlen((char *)vc_filesys_client.fileserv_msg.data)+1)) == FILESERV_RESP_OK ) - { - ret = vc_filesys_client.fileserv_msg.params[0]; - ret += (int64_t)vc_filesys_client.fileserv_msg.params[1] << 32; - if (num_files) - *num_files = vc_filesys_client.fileserv_msg.params[2]; - if (num_dirs) - *num_dirs = vc_filesys_client.fileserv_msg.params[3]; - } - - lock_release(); - } - - return ret; -} - - -/****************************************************************************** -NAME - vc_filesys_readdir_r - -SYNOPSIS - struct dirent *vc_filesys_readdir_r(void *dhandle, struct dirent *result) - -FUNCTION - Fills in the passed result structure with details of the directory entry - at the current psition in the directory stream specified by the argument - dhandle, and positions the directory stream at the next entry. - -RETURNS - Successful completion: result - End of directory stream: NULL -******************************************************************************/ - -struct dirent *vc_filesys_readdir_r(void *dhandle, struct dirent *result) -{ - struct dirent *ret = NULL; - - if(lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = (uint32_t)dhandle; - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_READDIR, 4) == FILESERV_RESP_OK) - { - fs_host_direntbytestream_interp(result, (void *)vc_filesys_client.fileserv_msg.data); - ret = result; - } - - lock_release(); - } - - return ret; -} - - -/****************************************************************************** -NAME - vc_filesys_remove - -SYNOPSIS - int vc_filesys_remove(const char *path) - -FUNCTION - Removes a file or a directory. A directory must be empty before it can be - deleted. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_remove(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_REMOVE, 0); -} - - -/****************************************************************************** -NAME - vc_filesys_rename - -SYNOPSIS - int vc_filesys_rename(const char *oldfile, const char *newfile) - -FUNCTION - Changes the name of a file. The old and new pathnames must be on the same - physical file system. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_rename(const char *oldfile, const char *newfile) -{ - int a, b, success = -1; - - // Ensure the pathnames aren't too long - if ((a = strlen(oldfile)) < FS_MAX_PATH && (b = strlen(newfile)) < FS_MAX_PATH && lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, oldfile, FS_MAX_PATH); - strncpy((char *)&vc_filesys_client.fileserv_msg.data[a+1], newfile, FS_MAX_PATH); - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_RENAME, 16+a+1+b+1) == FILESERV_RESP_OK) - success = 0; - - lock_release(); - } - - return success; -} - - -/****************************************************************************** -NAME - vc_filesys_reset - -SYNOPSIS - int vc_filesys_reset() - -FUNCTION - Send a vc_FILESYS_RESET command. This will return immediately. - -RETURNS - Successful completion: FILESERV_RESP_OK - Otherwise: - -******************************************************************************/ - -int vc_filesys_reset() -{ - return vc_filesys_single_param(0, VC_FILESYS_RESET); -} - - -/****************************************************************************** -NAME - vc_filesys_set_attr - -SYNOPSIS - int vc_filesys_set_attr(const char *path, fattributes_t attr) - -FUNCTION - Sets file/directory attributes. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_set_attr(const char *path, fattributes_t attr) -{ - return vc_filesys_single_string((uint32_t) attr, path, VC_FILESYS_SET_ATTR, 0); -} - - -/****************************************************************************** -NAME - vc_filesys_setend - -SYNOPSIS - int vc_filesys_setend(int fildes) - -FUNCTION - Truncates file at current position. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_setend(int fildes) -{ - return vc_filesys_single_param((uint32_t) fildes, VC_FILESYS_SETEND); -} - - - -/****************************************************************************** -NAME - vc_filesys_scandisk - -SYNOPSIS - void vc_filesys_scandisk(const char *path) - -FUNCTION - Truncates file at current position. - -RETURNS - - -******************************************************************************/ - -void vc_filesys_scandisk(const char *path) -{ - vc_filesys_single_string(0, path, VC_FILESYS_SCANDISK, 0); - return; -} - -/****************************************************************************** -NAME - vc_filesys_chkdsk - -SYNOPSIS - int vc_filesys_chkdsk(const char *path, int fix_errors) - -FUNCTION - Truncates file at current position. - -RETURNS - - -******************************************************************************/ - -int vc_filesys_chkdsk(const char *path, int fix_errors) -{ - return vc_filesys_single_string(fix_errors, path, VC_FILESYS_CHKDSK, 1); -} - -/****************************************************************************** -NAME - vc_filesys_size - -SYNOPSIS - int vc_filesys_size(const char *path) - -FUNCTION - return size of file - -RETURNS - - -******************************************************************************/ - -int vc_filesys_size(const char *path) -{ - int fd; - int end_pos = 0; - int success = -1; - if((fd = vc_filesys_open(path, VC_O_RDONLY)) == 0) - { - end_pos = vc_filesys_lseek(fd, 0, SEEK_END); - success = vc_filesys_close(fd); - (void)success; - } - - return end_pos; -} -/****************************************************************************** -NAME - vc_filesys_totalspace - -SYNOPSIS - int vc_filesys_totalspace(const char *path) - -FUNCTION - Returns the total amount of space on the physical file system that contains - path. - -RETURNS - Successful completion: total space - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_totalspace(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_TOTALSPACE, 1); -} - - -/****************************************************************************** -NAME - vc_filesys_totalspace64 - -SYNOPSIS - int64_t vc_filesys_totalspace64(const char *path) - -FUNCTION - Returns the total amount of space on the physical file system that contains - path. - -RETURNS - Successful completion: total space - Otherwise: -1 -******************************************************************************/ - -int64_t vc_filesys_totalspace64(const char *path) -{ - int64_t totalspace = -1LL; - - if(lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, path, FS_MAX_PATH); - - if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, VC_FILESYS_TOTALSPACE64, - (int)(16+strlen((char *)vc_filesys_client.fileserv_msg.data)+1)) == FILESERV_RESP_OK) - { - totalspace = vc_filesys_client.fileserv_msg.params[0]; - totalspace += (int64_t)vc_filesys_client.fileserv_msg.params[1] << 32; - } - - lock_release(); - } - - return totalspace; -} - - -/****************************************************************************** -NAME - vc_filesys_diskwritable - -SYNOPSIS - int vc_filesys_diskwritable(const char *path) - -FUNCTION - Return whether the named disk is writable. - -RETURNS - Successful completion: 1 (disk writable) or 0 (disk not writable) - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_diskwritable(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_DISKWRITABLE, 1); -} - -/****************************************************************************** -NAME - vc_filesys_fstype - -SYNOPSIS - int vc_filesys_fstype(const char *path) - -FUNCTION - Return the filesystem type of the named disk. - -RETURNS - Successful completion: disk type (see vc_fileservice_defs.h) - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_fstype(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_FSTYPE, 1); -} - -/****************************************************************************** -NAME - vc_filesys_open_disk_raw - -SYNOPSIS - int vc_filesys_open_disk_raw(const char *path) - -FUNCTION - Open disk for access in raw mode. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_open_disk_raw(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_OPEN_DISK_RAW, 1); -} - -/****************************************************************************** -NAME - vc_filesys_close_disk_raw - -SYNOPSIS - int vc_filesys_close_disk_raw(const char *path) - -FUNCTION - Close disk from access in raw mode. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_close_disk_raw(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_CLOSE_DISK_RAW, 1); -} - - -/****************************************************************************** -NAME - vc_filesys_open_disk - -SYNOPSIS - int vc_filesys_open_disk(const char *path) - -FUNCTION - Open disk for normal access. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_open_disk(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_OPEN_DISK, 1); -} - -/****************************************************************************** -NAME - vc_filesys_close_disk - -SYNOPSIS - int vc_filesys_close_disk(const char *path) - -FUNCTION - Close disk from normal access. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_close_disk(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_CLOSE_DISK, 1); -} - -/****************************************************************************** -NAME - vc_filesys_numsectors - -SYNOPSIS - int vc_filesys_numsectors(const char *path) - -FUNCTION - Return number of sectors on disk - -RETURNS - Successful completion: greater than 0 - Otherwise: -1 -******************************************************************************/ - -int vc_filesys_numsectors(const char *path) -{ - return vc_filesys_single_string(0, path, VC_FILESYS_NUMSECTORS, 1); -} - -/****************************************************************************** -NAME - vc_filesys_read_sectors - -SYNOPSIS - int vc_filesys_read_sectors(const char *path, uint32_t sector_num, char *buffer, uint32_t num_sectors) - -FUNCTION - Start streaming sectors from 2727 - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ -int vc_filesys_read_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_read) -{ -#if VCHI_BULK_ALIGN > 1 - uint32_t align_bytes = 0; -#endif - char* bulk_addr = sectors; - int len; - int ret = -1; - - if((len = (int)strlen(path)) < FS_MAX_PATH && lock_obtain() == 0) - { - strncpy((char *)vc_filesys_client.fileserv_msg.data, path, FS_MAX_PATH); - vc_filesys_client.fileserv_msg.params[0] = sector_num; - vc_filesys_client.fileserv_msg.params[1] = num_sectors; - -#if VCHI_BULK_ALIGN > 1 - //required to make buffer aligned for bulk - align_bytes = VCHI_BULK_ALIGN_NBYTES(sectors); -#endif - //note for read we are currently doing memcpy on host to tell 2727 align is 0 - vc_filesys_client.fileserv_msg.params[2] = 0; - - //we send read request - if (vchi_msg_stub_noblock(&vc_filesys_client.fileserv_msg, VC_FILESYS_READ_SECTORS, 16+len+1) == 0) - { - while(num_sectors) - { - uint32_t bulk_sectors = (num_sectors > FILESERV_MAX_BULK_SECTOR) ? (uint32_t)FILESERV_MAX_BULK_SECTOR : num_sectors; - if(vchi_bulk_queue_receive( vc_filesys_client.open_handle, -#if VCHI_BULK_ALIGN > 1 - align_bytes ? vc_filesys_client.bulk_buffer : bulk_addr, -#else - bulk_addr, -#endif - (bulk_sectors*FILESERV_SECTOR_LENGTH), VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE, NULL) != 0) - break; - -#if VCHI_BULK_ALIGN > 1 - if(align_bytes) { - //this is bad but will do for now.. - memcpy( bulk_addr, vc_filesys_client.bulk_buffer, (bulk_sectors*FILESERV_SECTOR_LENGTH)); - } -#endif - bulk_addr += (bulk_sectors*FILESERV_SECTOR_LENGTH); - num_sectors -= bulk_sectors; - } - - // now wait to receive resp from original msg... - if(vcos_event_wait(&vc_filesys_client.response_event) == VCOS_SUCCESS && vc_filesys_client.fileserv_msg.cmd_code == FILESERV_RESP_OK) - { - *sectors_read = vc_filesys_client.fileserv_msg.params[0]; - ret = 0; - } - else - { - //error code in [0] - *sectors_read = vc_filesys_client.fileserv_msg.params[1]; - ret = vc_filesys_client.fileserv_msg.params[0]; - } - } - - lock_release(); - } - - return ret; -} - -/****************************************************************************** -NAME - vc_filesys_write_sectors - -SYNOPSIS - int vc_filesys_write_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_written) - -FUNCTION - Start streaming sectors to 2727 - -RETURNS - Successful completion: 0 - Otherwise: -error code -******************************************************************************/ -int vc_filesys_write_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_written) -{ - uint32_t align_bytes = 0; - char* bulk_addr = sectors; - int len; - int ret = -1; - - len = (int) strlen(path); - if((len = (int) strlen(path)) < FS_MAX_PATH && lock_obtain() == 0) - { - vc_filesys_client.fileserv_msg.params[0] = sector_num; - vc_filesys_client.fileserv_msg.params[1] = num_sectors; - - //required to make buffer aligned for bulk - align_bytes = ((unsigned long)sectors & (VCHI_BULK_ALIGN-1)); - vc_filesys_client.fileserv_msg.params[2] = align_bytes; - - //copy path at end of any alignbytes - strncpy(((char *)vc_filesys_client.fileserv_msg.data), path, FS_MAX_PATH); - - //we send write request - if (vchi_msg_stub_noblock(&vc_filesys_client.fileserv_msg, VC_FILESYS_WRITE_SECTORS, 16+len+1) == 0) - { - if(align_bytes) { - //note we are cheating and going backward to make addr aligned and sending more data... - bulk_addr -= align_bytes; - } - - while(num_sectors) { - uint32_t bulk_sectors = (num_sectors > FILESERV_MAX_BULK_SECTOR) ? (uint32_t)FILESERV_MAX_BULK_SECTOR : num_sectors; - //we send some extra data at the start - if(vchi_bulk_queue_transmit( vc_filesys_client.open_handle, bulk_addr, - VCHI_BULK_ROUND_UP((bulk_sectors*FILESERV_SECTOR_LENGTH)+align_bytes), - VCHI_FLAGS_BLOCK_UNTIL_DATA_READ, NULL) != 0) - break; - - //go to next ALIGNED address - bulk_addr += FILESERV_MAX_BULK; - num_sectors -= bulk_sectors; - } - - // now wait to receive resp from original msg... - if(vcos_event_wait(&vc_filesys_client.response_event) == VCOS_SUCCESS && vc_filesys_client.fileserv_msg.cmd_code == FILESERV_RESP_OK) - { - *sectors_written = vc_filesys_client.fileserv_msg.params[0]; - ret = 0; - } - else - { - //error code in [0] - *sectors_written = vc_filesys_client.fileserv_msg.params[1]; - ret = vc_filesys_client.fileserv_msg.params[0]; - } - } - - lock_release(); - } - - return ret; -} - -/****************************************************************************** -NAME - vc_filesys_errno - -SYNOPSIS - int vc_filesys_errno(void) - -FUNCTION - Returns the error code of the last file system error that occurred. - -RETURNS - Error code -******************************************************************************/ - -int vc_filesys_errno(void) -{ - return (int) vc_filesys_client.err_no; -} - - -/* File Service Message FIFO functions */ - -/****************************************************************************** -NAME - vchi_msg_stub - -SYNOPSIS - static int vc_fs_stub(int verb, int ext_len) - -FUNCTION - Generates a request and sends it to the co-processor. It then suspends - until it receives a reply from the host. The calling task must hold - the filesys_lock. - -RETURNS - Successful completion: Response code of reply - Otherwise: - -******************************************************************************/ -static int vchi_msg_stub(FILESERV_MSG_T* msg, uint16_t cmd_id, int msg_len ) -{ - int ret = -1; - vchi_msg_stub_noblock(msg, cmd_id, msg_len); - - // wait to receive response - if(vcos_event_wait(&vc_filesys_client.response_event) == VCOS_SUCCESS) - ret = (int) msg->cmd_code; - - return ret; -} - -static int vchi_msg_stub_noblock(FILESERV_MSG_T* msg, uint16_t cmd_id, int msg_len) -{ - uint32_t i; - - if(!vcos_verify(msg_len <= VCHI_MAX_MSG_SIZE)) - return -1; - - //will get changed by response from command - vc_filesys_client.resp_code = FILESERV_RESP_ERROR; - - //the top bit is used for host/vc - i = vc_filesys_client.cur_xid + 1; - i &= 0x7fffffffUL; - vc_filesys_client.cur_xid = i; - - //fill in transaction id, used for response identification - vchi_writebuf_uint32( &(msg->xid), vc_filesys_client.cur_xid ); - - //fill in cmd id VC_FILESYS_OPEN etc - vchi_writebuf_uint32( &(msg->cmd_code), cmd_id ); - - //we always have cmd_id, xid - msg_len += 8; - - //return response code - return (int) vchi_msg_queue( vc_filesys_client.open_handle, msg, (uint32_t)msg_len, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL ); -} - -static int vc_send_response( FILESERV_MSG_T* msg, uint32_t retval, uint32_t nbytes ) -{ - int success = -1; - //convert all to over the wire values - vchi_writebuf_uint32(&msg->cmd_code, retval); - vchi_writebuf_uint32(&msg->xid, msg->xid); - vchi_writebuf_uint32(&msg->params[0], msg->params[0]); - vchi_writebuf_uint32(&msg->params[1], msg->params[1]); - vchi_writebuf_uint32(&msg->params[2], msg->params[2]); - vchi_writebuf_uint32(&msg->params[3], msg->params[3]); - - //start with 8 because always xid and retval - nbytes += 8; - - if(vcos_verify(nbytes <= VCHI_MAX_MSG_SIZE)) - success = (int) vchi_msg_queue( vc_filesys_client.open_handle, msg, nbytes, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL ); - - return success; -} - -/****************************************************************************** -NAME - vc_fs_message_handler - -SYNOPSIS - static int vc_fs_message_handler() - -FUNCTION - Handle messages from the co-processor. - -RETURNS - 0 - No message found. - 1 - Request received and actioned. - 2 - Reply received. -******************************************************************************/ - -static int vc_fs_message_handler( FILESERV_MSG_T* msg, uint32_t nbytes ) -{ - int rr = 0; - uint32_t xid = vchi_readbuf_uint32(&msg->xid); - - if (xid == vc_filesys_client.cur_xid) { - - //memcpy reply to msg should really peek before - vc_filesys_client.fileserv_msg.xid = xid; - vc_filesys_client.fileserv_msg.cmd_code = vchi_readbuf_uint32(&msg->cmd_code); - vc_filesys_client.fileserv_msg.params[0] = vchi_readbuf_uint32(&msg->params[0]); - vc_filesys_client.fileserv_msg.params[1] = vchi_readbuf_uint32(&msg->params[1]); - vc_filesys_client.fileserv_msg.params[2] = vchi_readbuf_uint32(&msg->params[2]); - vc_filesys_client.fileserv_msg.params[3] = vchi_readbuf_uint32(&msg->params[3]); - - //copy any data, 24 is size of header - if(nbytes >24) - memcpy(&vc_filesys_client.fileserv_msg.data, msg->data, (nbytes-24)); - - vc_filesys_client.resp_code = (int32_t)vc_filesys_client.fileserv_msg.cmd_code; - - if (vc_filesys_client.resp_code == FILESERV_RESP_ERROR) { - vc_filesys_client.err_no = (int32_t)vc_filesys_client.fileserv_msg.params[0]; - } - - // signal vchi_msg_stub which will be waiting for response - vcos_event_signal(&vc_filesys_client.response_event); - - rr = 2; - } - else if ((xid & 0x80000000UL) == 0x80000000UL) { - /* Process new requests from the co-processor */ - - uint32_t retval = FILESERV_RESP_OK; - - //this is the number of uint32_t param[] + data that we send back to VC in bytes - - uint32_t rlen = 0; - int i; - - switch (msg->cmd_code) { - - case VC_FILESYS_CLOSE: - - i = vc_hostfs_close((int)msg->params[0]); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_CLOSEDIR: - - i = vc_hostfs_closedir((void *)msg->params[0]); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_FORMAT: - - i = vc_hostfs_format((const char *)msg->data); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_FREESPACE: - - i = vc_hostfs_freespace((const char *)msg->data); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t)i; - rlen = 4; - } - break; - - case VC_FILESYS_FREESPACE64: - { - int64_t freespace; - freespace = vc_hostfs_freespace64((const char *)msg->data); - if (freespace < (int64_t)0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t)freespace; - msg->params[1] = (uint32_t)(freespace>>32); - rlen = 8; - } - } - break; - - case VC_FILESYS_GET_ATTR: - { - fattributes_t attr; - - i = vc_hostfs_get_attr((const char *)msg->data, - &attr); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t) attr; - rlen = 4; - } - } - break; - case VC_FILESYS_LSEEK: - - i = vc_hostfs_lseek( (int)msg->params[0], - (int)msg->params[1], - (int)msg->params[2]); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t) i; - rlen = 4; - } - break; - - case VC_FILESYS_LSEEK64: - { - int64_t offset; - offset = (((int64_t) msg->params[2]) << 32) + msg->params[1]; - - offset = vc_hostfs_lseek64( (int)msg->params[0], offset, (int)msg->params[3]); - if (offset < (int64_t)0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t)offset; - msg->params[1] = (uint32_t)(offset>>32); - rlen = 8; - } - } - break; - - case VC_FILESYS_MKDIR: - - i = vc_hostfs_mkdir((const char *)msg->data); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_OPEN: - - i = vc_hostfs_open((const char *)msg->data, - (int) msg->params[0]); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - } else { - msg->params[0] = (uint32_t) i; - } - rlen = 4; - break; - - case VC_FILESYS_OPENDIR: - - msg->params[0] = (uint32_t)vc_hostfs_opendir( - (const char *)msg->data); - if ((void *)msg->params[0] == NULL) { - retval = FILESERV_RESP_ERROR; - } - rlen = 4; - break; - - case VC_FILESYS_READ: - { - uint32_t fd = msg->params[0]; - uint32_t offset = msg->params[1]; - int total_bytes = (int)msg->params[2]; - uint32_t nalign_bytes = msg->params[3]; - - i = 0; - - if(!vcos_verify(((int)vc_filesys_client.bulk_buffer & (VCHI_BULK_ALIGN-1)) == 0 && - total_bytes <= FILESERV_MAX_BULK)) - { - retval = FILESERV_RESP_ERROR; - rlen = 4; - break; - } - - rlen = 0; - - //perform any seeking - if ( (uint32_t)0xffffffffUL != offset) - { - i = vc_hostfs_lseek( (int)fd, - (long int) offset, - VC_FILESYS_SEEK_SET); - if ( 0 > i) - { - retval = FILESERV_RESP_ERROR; - rlen = 4; - break; - } - } - - - //put it all in one msg - if(total_bytes <= FILESERV_MAX_DATA) { - i = vc_hostfs_read( (int)fd, - msg->data, - (unsigned int) total_bytes); - - if(i < 0) { - retval = FILESERV_RESP_ERROR; - msg->params[0] = 0; - } - else { - retval = FILESERV_RESP_OK; - //send back length of read - msg->params[0] = (uint32_t) i; - } - - msg->params[1] = 0; - rlen = 16 + (uint32_t) i; - } - //bulk transfer required - else { - uint32_t end_bytes = 0; - retval = FILESERV_BULK_WRITE; - - //we send the bytes required for HOST buffer align - if(nalign_bytes) { - i = vc_hostfs_read( (int)fd, - msg->data, - (unsigned int)nalign_bytes); - if(i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 16; - break; - } - else if(i != (int)nalign_bytes) { - //all data will be in one msg - retval = FILESERV_RESP_OK; - msg->params[0] = (uint32_t) i; - msg->params[1] = 0; - rlen = 16 + (uint32_t) i; - //send response - break; - } - - total_bytes -= i; - rlen += (uint32_t) i; - } - - //bulk bytes - i = vc_hostfs_read((int)fd, vc_filesys_client.bulk_buffer, (unsigned int)total_bytes); - - if(i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 16; - break; - } - else if((i+nalign_bytes) <= FILESERV_MAX_DATA) { - retval = FILESERV_RESP_OK; - memcpy(&msg->data[nalign_bytes], &vc_filesys_client.bulk_buffer[0], (size_t) i); - //read size - msg->params[0] = (i + nalign_bytes); - msg->params[1] = 0; - rlen = i + nalign_bytes + 16; - break; - } - - //copy end unaligned length bytes into msg->data - end_bytes = (uint32_t) (i & (VCHI_BULK_GRANULARITY-1)); - if(end_bytes) { - int end_index = i - (int) end_bytes; - memcpy(&msg->data[nalign_bytes], &vc_filesys_client.bulk_buffer[end_index], end_bytes); - rlen += end_bytes; - } - - //send back total bytes - msg->params[0] = (uint32_t)(i + nalign_bytes); - //number of end bytes - msg->params[1] = end_bytes; - //number of bulk bytes - msg->params[2] = (uint32_t)(i - end_bytes); - //16 for param len - rlen += 16; - - //queue bulk to be sent - if(vchi_bulk_queue_transmit( vc_filesys_client.open_handle, - vc_filesys_client.bulk_buffer, - msg->params[2], - VCHI_FLAGS_BLOCK_UNTIL_QUEUED, - NULL ) != 0) - { - retval = FILESERV_RESP_ERROR; - rlen = 4; - break; - } - } - } - //send response - break; - - case VC_FILESYS_READDIR: - { - struct dirent result; - if (vc_hostfs_readdir_r((void *)msg->params[0], - &result) == NULL) { - retval = FILESERV_RESP_ERROR; - rlen = 4; - } else { - rlen = (uint32_t) (16+fs_host_direntbytestream_create(&result, - (void *)msg->data)); - } - } - break; - - case VC_FILESYS_REMOVE: - - i = vc_hostfs_remove((const char *)msg->data); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_RENAME: - - i = (int) strlen((char *)msg->data); - if (vc_hostfs_rename((const char *)msg->data, - (const char *)&msg->data[i+1]) - != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_SETEND: - - i = vc_hostfs_setend( (int)msg->params[0] ); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_SET_ATTR: - - i = vc_hostfs_set_attr((const char *)msg->data, - (fattributes_t)msg->params[0]); - if (i != 0) { - retval = FILESERV_RESP_ERROR; - } - rlen = 0; - break; - - case VC_FILESYS_TOTALSPACE: - - i = vc_hostfs_totalspace((const char *)msg->data); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t) i; - rlen = 4; - } - break; - - case VC_FILESYS_TOTALSPACE64: - { - int64_t totalspace; - totalspace = vc_hostfs_totalspace64((const char *)msg->data); - if (totalspace < (int64_t)0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t)totalspace; - msg->params[1] = (uint32_t)(totalspace>>32); - rlen = 8; - } - } - break; -#if 0 // I don't think host systems are ready for these yet - case VC_FILESYS_SCANDISK: - - vc_hostfs_scandisk((const char *)msg->data); - rlen = 0; - break; - - case VC_FILESYS_CHKDSK: - - i = vc_hostfs_chkdsk((const char *)msg->data, msg->params[0]); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - rlen = 0; - } else { - msg->params[0] = (uint32_t)i; - rlen = 4; - } - break; -#endif - case VC_FILESYS_WRITE: - { - uint32_t fd = msg->params[0]; - // uint32_t offset = msg->params[1]; - int total_bytes = (int)msg->params[2]; - uint32_t nalign_bytes = msg->params[3]; - retval = FILESERV_RESP_OK; - i = 0; - - //everything in one msg - if(total_bytes <= FILESERV_MAX_DATA) - { - i = vc_hostfs_write( (int)fd, - msg->data, - (unsigned int) total_bytes); - if (i < 0) { - retval = FILESERV_RESP_ERROR; - } else { - msg->params[0] = (uint32_t) i; - } - rlen = 4; - //send response - break; - } - else - { - uint32_t end_bytes; - uint32_t bulk_bytes; - uint32_t total_bytes_written = 0; - i = 0; - //one return param - rlen = 4; - retval = FILESERV_BULK_READ; - - //write bytes required for VC buffer align - if(nalign_bytes) { - i = vc_hostfs_write( (int)fd, - msg->data, - (unsigned int)nalign_bytes); - if(i < 0) { - retval = FILESERV_RESP_ERROR; - msg->params[0] = 0; - //break from switch and send reply - break; - } - total_bytes_written += i; - total_bytes -= nalign_bytes; - } - - //calculate bytes that wil lbe sent by bulk - bulk_bytes = (uint32_t)((total_bytes)&(~(VCHI_BULK_ALIGN-1))); - - end_bytes = total_bytes-bulk_bytes; - - - - if(vchi_bulk_queue_receive(vc_filesys_client.open_handle, - vc_filesys_client.bulk_buffer, - bulk_bytes, - VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE, - NULL) != 0 || - (i = vc_hostfs_write( (int)fd, - vc_filesys_client.bulk_buffer, - (unsigned int) bulk_bytes)) < 0) - { - retval = FILESERV_RESP_ERROR; - msg->params[0] = 0; - break; - } - - total_bytes_written += i; - - if(end_bytes) { - i = vc_hostfs_write( (int)fd, - msg->data+nalign_bytes, - (unsigned int)end_bytes); - - total_bytes_written += i; - } - - if(i < 0) { - retval = FILESERV_RESP_ERROR; - msg->params[0] = 0; - break; - } - - msg->params[0] = total_bytes_written; - - } - } - break; - - default: - rlen = 4; - retval = FILESERV_RESP_ERROR; - break; - } - - //convert all to over the wire values and send - vc_send_response( msg, retval, rlen ); - - rr = 1; - - } else { - /* A message has been left in the fifo and the host side has been reset. - The message needs to be flushed. It would be better to do this by resetting - the fifos. */ - } - - return rr; -} - - -/****************************************************************************** -NAME - showmsg - -SYNOPSIS - static void showmsg(VC_MSGFIFO_CMD_HEADER_T const * head, - struct file_service_msg_body const * body) - -FUNCTION - De-bug tool: prints out fifo message. - -RETURNS - void -******************************************************************************/ - -#ifdef PRINTF -static void showmsg(VC_MSGFIFO_CMD_HEADER_T const * head, - struct file_service_msg_body const * body) -{ - unsigned int ael = (head->ext_length + 15) & ~15; - printf("Sync=%08x XID=%08x Code=%08x Extlen=%08x (%d bytes follow)\n", - head->sync, head->xid, head->cmd_code, head->ext_length, ael); - if (ael) { - unsigned int i; - printf("Content:"); - for (i = 0; i < 4 && i*4 < head->ext_length; ++i) printf(" %08x", body->params[i]); - //for(i = 0; i+16 < head->ext_length; ++i) printf(" %02x", body->data[i]); - if (head->ext_length > 16) printf(" plus %d bytes\n", head->ext_length); - } - printf("\n"); -} -#endif - - -/****************************************************************************** -NAME - fs_host_direntbytestream_create - -SYNOPSIS - static int fs_host_direntbytestream_create(struct dirent *d, void *buffer) - -FUNCTION - Turns a variable of type struct dirent into a compiler independent byte - stream, which is stored in buffer. - -RETURNS - Successful completion: The length of the byte stream - Otherwise: -1 -******************************************************************************/ -static void write_bytestream(void *a, char *b, int n) -{ - int i; - for (i=0;id_name, D_NAME_MAX_SIZE); - buf += D_NAME_MAX_SIZE; - - // Write d_size (unsigned int) - write_bytestream((void *)&d->d_size, buf, (int)sizeof(d->d_size)); - buf += 4; - - // Write d_attrib (int) - write_bytestream((void *)&d->d_attrib, buf, (int)sizeof(d->d_attrib)); - buf += 4; - - // Write d_modtime (time_t) - write_bytestream((void *)&d->d_modtime, buf, (int)sizeof(d->d_modtime)); - buf += 4; - - return (int)(buf-(char *)buffer); -} - - -/****************************************************************************** -NAME - fs_host_direntbytestream_interp - -SYNOPSIS - static void fs_host_direntbytestream_interp(struct dirent *d, void *buffer) - -FUNCTION - Turns a compiler independent byte stream back into a struct of type dirent. - -RETURNS - Successful completion: 0 - Otherwise: -1 -******************************************************************************/ -static void read_bytestream(void *a, char *b, int n) -{ - int i; - for (i=0;id_name, buf, D_NAME_MAX_SIZE); - buf += D_NAME_MAX_SIZE; - - // Read d_size (unsigned int) - read_bytestream((void *)&d->d_size, buf, (int)sizeof(d->d_size)); - d->d_size = VC_VTOH32(d->d_size); - buf += 4; - - // Read d_attrib (int) - read_bytestream((void *)&d->d_attrib, buf, (int)sizeof(d->d_attrib)); - d->d_attrib = VC_VTOH32(d->d_attrib); - buf += 4; - - // Read d_modtime (time_t) - read_bytestream((void *)&d->d_modtime, buf, (int)sizeof(d->d_modtime)); - d->d_modtime = VC_VTOH32(d->d_modtime); - - return; -} - - - -void vc_filesys_sendreset(void) -{ - //TODO -} diff --git a/interface/vmcs_host/vc_vchi_filesys.h b/interface/vmcs_host/vc_vchi_filesys.h deleted file mode 100644 index 393a3eb85..000000000 --- a/interface/vmcs_host/vc_vchi_filesys.h +++ /dev/null @@ -1,184 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef VC_VCHI_VCFILESYS_H_ -#define VC_VCHI_VCFILESYS_H_ - -#include "vchost_platform_config.h" -#include "vcfilesys_defs.h" -#include "vc_fileservice_defs.h" -#include "interface/vchi/vchi.h" - -#ifndef _DIRENT_H // This should really be in a dirent.h header to avoid conflicts -typedef struct DIR_tag DIR; -#endif // ifndef _DIRENT_H - -typedef struct { - int64_t st_size; /* total size, in bytes (off_t)*/ - uint32_t st_modtime; /* time of last modification (time_t)*/ -} FSTAT_T; - - -VCHPRE_ int VCHPOST_ vc_vchi_filesys_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ); - -// Stop it to prevent the functions from trying to use it. -VCHPRE_ void VCHPOST_ vc_filesys_stop(void); - -// Return the service number (-1 if not running). -VCHPRE_ int VCHPOST_ vc_filesys_inum(void); - -// Low level file system functions equivalent to close(), lseek(), open(), read() and write() -VCHPRE_ int VCHPOST_ vc_filesys_close(int fildes); - -VCHPRE_ long VCHPOST_ vc_filesys_lseek(int fildes, long offset, int whence); - -VCHPRE_ int64_t VCHPOST_ vc_filesys_lseek64(int fildes, int64_t offset, int whence); - -VCHPRE_ int VCHPOST_ vc_filesys_open(const char *path, int vc_oflag); - -VCHPRE_ int VCHPOST_ vc_filesys_read(int fildes, void *buf, unsigned int nbyte); - -VCHPRE_ int VCHPOST_ vc_filesys_write(int fildes, const void *buf, unsigned int nbyte); - -VCHPRE_ int VCHPOST_ vc_filesys_mount(const char *device, const char *mountpoint, const char *options); -VCHPRE_ int VCHPOST_ vc_filesys_umount(const char *mountpoint); - - -// Ends a directory listing iteration -VCHPRE_ int VCHPOST_ vc_filesys_closedir(void *dhandle); - -// Formats the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_format(const char *path); - -// Returns the amount of free space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_freespace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_freespace64(const char *path); - -// Gets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_filesys_get_attr(const char *path, fattributes_t *attr); - -// Get the file stat info struct for the specified file. -VCHPRE_ int VCHPOST_ vc_filesys_fstat(int filedes, FSTAT_T *buf); - -// Creates a new directory -VCHPRE_ int VCHPOST_ vc_filesys_mkdir(const char *path); - -// Starts a directory listing iteration -VCHPRE_ void * VCHPOST_ vc_filesys_opendir(const char *dirname); - -// Directory listing iterator -VCHPRE_ struct dirent * VCHPOST_ vc_filesys_readdir_r(void *dhandle, struct dirent *result); - -// Get the sum of the filesizes, and the number of files under the specified directory path. -VCHPRE_ int64_t VCHPOST_ vc_filesys_dirsize(const char *path, uint32_t *num_files, uint32_t *num_dirs); - -// Deletes a file or (empty) directory -VCHPRE_ int VCHPOST_ vc_filesys_remove(const char *path); - -// Renames a file, provided the new name is on the same file system as the old -VCHPRE_ int VCHPOST_ vc_filesys_rename(const char *oldfile, const char *newfile); - -// Resets the co-processor side file system -VCHPRE_ int VCHPOST_ vc_filesys_reset(void); - -// Sets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_filesys_set_attr(const char *path, fattributes_t attr); - -// Truncates a file at its current position -VCHPRE_ int VCHPOST_ vc_filesys_setend(int fildes); - -// Returns the size of a file in bytes. -VCHPRE_ int VCHPOST_ vc_filesys_size(const char *path); - -// Checks whether there are any messages in the incoming message fifo and responds to any such messages -VCHPRE_ int VCHPOST_ vc_filesys_poll_message_fifo(void); - -// Return the event used to wait for reads. -VCHPRE_ void * VCHPOST_ vc_filesys_read_event(void); - -// Sends a command for VC01 to reset the file system -VCHPRE_ void VCHPOST_ vc_filesys_sendreset(void); - -// Return the error code of the last file system error -VCHPRE_ int VCHPOST_ vc_filesys_errno(void); - -// Invalidates any cluster chains in the FAT that are not referenced in any directory structures -VCHPRE_ void VCHPOST_ vc_filesys_scandisk(const char *path); - -// Checks whether or not a FAT filesystem is corrupt or not. If fix_errors is TRUE behaves exactly as vc_filesys_scandisk. -VCHPRE_ int VCHPOST_ vc_filesys_chkdsk(const char *path, int fix_errors); - -// Return whether a disk is writeable or not. -VCHPRE_ int VCHPOST_ vc_filesys_diskwritable(const char *path); - -// Return file system type of a disk. -VCHPRE_ int VCHPOST_ vc_filesys_fstype(const char *path); - -// Returns the toatl amount of space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_totalspace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_totalspace64(const char *path); - -// Open disk for block level access -VCHPRE_ int VCHPOST_ vc_filesys_open_disk_raw(const char *path); - -// Close disk from block level access mode -VCHPRE_ int VCHPOST_ vc_filesys_close_disk_raw(const char *path); - -// Open disk for normal access -VCHPRE_ int VCHPOST_ vc_filesys_open_disk(const char *path); - -// Close disk for normal access -VCHPRE_ int VCHPOST_ vc_filesys_close_disk(const char *path); - -// Return number of sectors. -VCHPRE_ int VCHPOST_ vc_filesys_numsectors(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_numsectors64(const char *path); - -// Read/Write sectors -VCHPRE_ int VCHPOST_ vc_filesys_read_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_read); -VCHPRE_ int VCHPOST_ vc_filesys_write_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_written); - -// Begin reading sectors from VideoCore. -VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_begin(const char *path, uint32_t sector, uint32_t count); - -// Read the next sector. -VCHPRE_ int VCHPOST_ vc_filesys_read_sector(char *buf); - -// End streaming sectors. -VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_end(uint32_t *sectors_read); - -// Begin writing sectors from VideoCore. -VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_begin(const char *path, uint32_t sector, uint32_t count); - -// Write the next sector. -VCHPRE_ int VCHPOST_ vc_filesys_write_sector(const char *buf); - -// End streaming sectors. -VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_end(uint32_t *sectors_written); - -#endif //VCFILESYS_H_ - diff --git a/interface/vmcs_host/vcfilesys.h b/interface/vmcs_host/vcfilesys.h deleted file mode 100644 index c8617cfa9..000000000 --- a/interface/vmcs_host/vcfilesys.h +++ /dev/null @@ -1,166 +0,0 @@ -/* -Copyright (c) 2012, Broadcom Europe Ltd -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "vchost_platform_config.h" -#include "vcfilesys_defs.h" -#include "vc_fileservice_defs.h" - -#ifndef VCFILESYS_H_ -#define VCFILESYS_H_ - -#ifndef FILESYS_DIR_DEFINED -#define FILESYS_DIR_DEFINED -typedef struct DIR_tag DIR; -#endif - -// Initialises the file system for use -VCHPRE_ int VCHPOST_ vc_filesys_init (void); - -// Stop it to prevent the functions from trying to use it. -VCHPRE_ void VCHPOST_ vc_filesys_stop(void); - -// Return the service number (-1 if not running). -VCHPRE_ int VCHPOST_ vc_filesys_inum(void); - -// Low level file system functions equivalent to close(), lseek(), open(), read() and write() -VCHPRE_ int VCHPOST_ vc_filesys_close(int fildes); - -VCHPRE_ long VCHPOST_ vc_filesys_lseek(int fildes, long offset, int whence); - -VCHPRE_ int64_t VCHPOST_ vc_filesys_lseek64(int fildes, int64_t offset, int whence); - -VCHPRE_ int VCHPOST_ vc_filesys_open(const char *path, int vc_oflag); - -VCHPRE_ int VCHPOST_ vc_filesys_read(int fildes, void *buf, unsigned int nbyte); - -VCHPRE_ int VCHPOST_ vc_filesys_write(int fildes, const void *buf, unsigned int nbyte); - -VCHPRE_ int VCHPOST_ vc_filesys_mount(const char *device, const char *mountpoint, const char *options); -VCHPRE_ int VCHPOST_ vc_filesys_umount(const char *mountpoint); - - -// Ends a directory listing iteration -VCHPRE_ int VCHPOST_ vc_filesys_closedir(void *dhandle); - -// Formats the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_format(const char *path); - -// Returns the amount of free space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_freespace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_freespace64(const char *path); - -// Gets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_filesys_get_attr(const char *path, fattributes_t *attr); - -// Creates a new directory -VCHPRE_ int VCHPOST_ vc_filesys_mkdir(const char *path); - -// Starts a directory listing iteration -VCHPRE_ void * VCHPOST_ vc_filesys_opendir(const char *dirname); - -// Directory listing iterator -VCHPRE_ struct dirent * VCHPOST_ vc_filesys_readdir_r(void *dhandle, struct dirent *result); - -// Deletes a file or (empty) directory -VCHPRE_ int VCHPOST_ vc_filesys_remove(const char *path); - -// Renames a file, provided the new name is on the same file system as the old -VCHPRE_ int VCHPOST_ vc_filesys_rename(const char *oldfile, const char *newfile); - -// Resets the co-processor side file system -VCHPRE_ int VCHPOST_ vc_filesys_reset(void); - -// Sets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_filesys_set_attr(const char *path, fattributes_t attr); - -// Truncates a file at its current position -VCHPRE_ int VCHPOST_ vc_filesys_setend(int fildes); - -// Checks whether there are any messages in the incoming message fifo and responds to any such messages -VCHPRE_ int VCHPOST_ vc_filesys_poll_message_fifo(void); - -// Return the event used to wait for reads. -VCHPRE_ void * VCHPOST_ vc_filesys_read_event(void); - -// Sends a command for VC01 to reset the file system -VCHPRE_ void VCHPOST_ vc_filesys_sendreset(void); - -// Return the error code of the last file system error -VCHPRE_ int VCHPOST_ vc_filesys_errno(void); - -// Invalidates any cluster chains in the FAT that are not referenced in any directory structures -VCHPRE_ void VCHPOST_ vc_filesys_scandisk(const char *path); - -// Checks whether or not a FAT filesystem is corrupt or not. If fix_errors is TRUE behaves exactly as vc_filesys_scandisk. -VCHPRE_ int VCHPOST_ vc_filesys_chkdsk(const char *path, int fix_errors); - -// Return whether a disk is writeable or not. -VCHPRE_ int VCHPOST_ vc_filesys_diskwritable(const char *path); - -// Return file system type of a disk. -VCHPRE_ int VCHPOST_ vc_filesys_fstype(const char *path); - -// Returns the toatl amount of space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_filesys_totalspace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_totalspace64(const char *path); - -// Open disk for block level access -VCHPRE_ int VCHPOST_ vc_filesys_open_disk_raw(const char *path); - -// Close disk from block level access mode -VCHPRE_ int VCHPOST_ vc_filesys_close_disk_raw(const char *path); - -// Open disk for normal access -VCHPRE_ int VCHPOST_ vc_filesys_open_disk(const char *path); - -// Close disk for normal access -VCHPRE_ int VCHPOST_ vc_filesys_close_disk(const char *path); - -// Return number of sectors. -VCHPRE_ int VCHPOST_ vc_filesys_numsectors(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_filesys_numsectors64(const char *path); - -// Begin reading sectors from VideoCore. -VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_begin(const char *path, uint32_t sector, uint32_t count); - -// Read the next sector. -VCHPRE_ int VCHPOST_ vc_filesys_read_sector(char *buf); - -// End streaming sectors. -VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_end(uint32_t *sectors_read); - -// Begin writing sectors from VideoCore. -VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_begin(const char *path, uint32_t sector, uint32_t count); - -// Write the next sector. -VCHPRE_ int VCHPOST_ vc_filesys_write_sector(const char *buf); - -// End streaming sectors. -VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_end(uint32_t *sectors_written); - -#endif //VCFILESYS_H_ - diff --git a/interface/vmcs_host/vchost.h b/interface/vmcs_host/vchost.h index 23ffa6353..e4a379880 100644 --- a/interface/vmcs_host/vchost.h +++ b/interface/vmcs_host/vchost.h @@ -29,9 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define VCHOST_H #include "vchost_platform_config.h" -#include "vcfilesys_defs.h" #include "interface/vcos/vcos.h" //for VCHPRE_ abd VCHPOST_ macro's for func declaration -#include "interface/vmcs_host/vc_fileservice_defs.h" // for VC_O_XXX file definitions #include "interface/vchi/vchi.h" #define UNUSED_PARAMETER(x) ((void)(x))/* macro to suppress not use warning */ @@ -159,74 +157,6 @@ VCHPRE_ void VCHPOST_ vc_lock_obtain(void *lock); VCHPRE_ void VCHPOST_ vc_lock_release(void *lock); -/*---------------------------------------------------------------------------*/ -/* File system related functions */ -/*---------------------------------------------------------------------------*/ - -// Initialises the host dependent file system functions for use -VCHPRE_ void VCHPOST_ vc_hostfs_init(void); -VCHPRE_ void VCHPOST_ vc_hostfs_exit(void); - -// Low level file system functions equivalent to close(), lseek(), open(), read() and write() -VCHPRE_ int VCHPOST_ vc_hostfs_close(int fildes); - -VCHPRE_ long VCHPOST_ vc_hostfs_lseek(int fildes, long offset, int whence); - -VCHPRE_ int64_t VCHPOST_ vc_hostfs_lseek64(int fildes, int64_t offset, int whence); - -VCHPRE_ int VCHPOST_ vc_hostfs_open(const char *path, int vc_oflag); - -VCHPRE_ int VCHPOST_ vc_hostfs_read(int fildes, void *buf, unsigned int nbyte); - -VCHPRE_ int VCHPOST_ vc_hostfs_write(int fildes, const void *buf, unsigned int nbyte); - -// Ends a directory listing iteration -VCHPRE_ int VCHPOST_ vc_hostfs_closedir(void *dhandle); - -// Formats the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_hostfs_format(const char *path); - -// Returns the amount of free space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_hostfs_freespace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_hostfs_freespace64(const char *path); - -// Gets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_hostfs_get_attr(const char *path, fattributes_t *attr); - -// Creates a new directory -VCHPRE_ int VCHPOST_ vc_hostfs_mkdir(const char *path); - -// Starts a directory listing iteration -VCHPRE_ void * VCHPOST_ vc_hostfs_opendir(const char *dirname); - -// Directory listing iterator -VCHPRE_ struct dirent * VCHPOST_ vc_hostfs_readdir_r(void *dhandle, struct dirent *result); - -// Deletes a file or (empty) directory -VCHPRE_ int VCHPOST_ vc_hostfs_remove(const char *path); - -// Renames a file, provided the new name is on the same file system as the old -VCHPRE_ int VCHPOST_ vc_hostfs_rename(const char *oldfile, const char *newfile); - -// Sets the attributes of the named file -VCHPRE_ int VCHPOST_ vc_hostfs_set_attr(const char *path, fattributes_t attr); - -// Truncates a file at its current position -VCHPRE_ int VCHPOST_ vc_hostfs_setend(int fildes); - -// Returns the total amount of space on the drive that contains the given path -VCHPRE_ int VCHPOST_ vc_hostfs_totalspace(const char *path); -VCHPRE_ int64_t VCHPOST_ vc_hostfs_totalspace64(const char *path); - -// Return millisecond resolution system time, only used for differences -VCHPRE_ int VCHPOST_ vc_millitime(void); - -// Invalidates any cluster chains in the FAT that are not referenced in any directory structures -VCHPRE_ void VCHPOST_ vc_hostfs_scandisk(const char *path); - -// Checks whether or not a FAT filesystem is corrupt or not. If fix_errors is TRUE behaves exactly as vc_filesys_scandisk. -VCHPRE_ int VCHPOST_ vc_hostfs_chkdsk(const char *path, int fix_errors); - /*---------------------------------------------------------------------------*/ /* These functions only need to be implemented for the test system. */ /*---------------------------------------------------------------------------*/