示例#1
0
文件: dfs_raw.c 项目: samkrew/nxp-lpc
/*
+------------------------------------------------------------------------------
| Function    : dfile_raw_rename
+------------------------------------------------------------------------------
| Description : 
|
| Parameters  : 
| Returns     : 
|
+------------------------------------------------------------------------------
*/
int dfile_raw_rename(const char* oldpath, const char* newpath)
{
	struct dfs_filesystem *oldfs, *newfs;
	char *oldfullpath, *newfullpath;
#ifdef DFS_USING_WORKDIR
	/* Change DFS_PATH_MAX to DFS_PATH_MAX + 1, [email protected]*/
	char old_realpath[DFS_PATH_MAX + 1], new_realpath[DFS_PATH_MAX + 1];
#endif

	oldfullpath = (char*)oldpath;
	newfullpath = (char*)newpath;

	if ( oldfullpath[0] != '/' )
	{
#ifdef DFS_USING_WORKDIR
		/* build full path */
		oldfullpath = old_realpath;
		dfs_lock();
		build_fullpath(working_directory, oldpath, oldfullpath);
		dfs_unlock();
#else
		rt_kprintf("bad filename\n");
		return -1;
#endif
	}

	if ( newfullpath[0] != '/' )
	{
#ifdef DFS_USING_WORKDIR
		/* build full path */
		newfullpath = new_realpath;
		dfs_lock();
		build_fullpath(working_directory, newpath, newfullpath);
		dfs_unlock();
#else
		rt_kprintf("bad filename");
		return -1;
#endif
	}

	if ( (oldfs = dfs_filesystem_lookup(oldfullpath)) == RT_NULL )
	{
		return -DFS_STATUS_ENOENT;
	}

	if ( (newfs = dfs_filesystem_lookup(newfullpath)) == RT_NULL )
	{
		return -DFS_STATUS_ENOENT;
	}

	if ( oldfs == newfs )
	{
		if ( oldfs->ops->rename == RT_NULL ) return -DFS_STATUS_ENOSYS;
		
		return oldfs->ops->rename(oldfs, oldfullpath, newfullpath);
	}

	/* not at same file system, return EXDEV */
	return -DFS_STATUS_EXDEV;
}
示例#2
0
文件: dfs_raw.c 项目: samkrew/nxp-lpc
/*
+------------------------------------------------------------------------------
| Function    : dfile_raw_unlink
+------------------------------------------------------------------------------
| Description : 
|
| Parameters  : 
| Returns     : 
|
+------------------------------------------------------------------------------
*/
int dfile_raw_unlink(const char *path)
{
	struct dfs_filesystem* fs;
	char *fullpath, *real_path, search_path[DFS_PATH_MAX + 1];
#ifdef DFS_USING_WORKDIR
	char full_path[DFS_PATH_MAX+1];
#endif
	struct dfs_fd* fd;
	int index, fspathlen;

	/* Make sure we have an absolute path */
	fullpath = (char*)path;
	if ( fullpath[0] != '/')
	{
#ifdef DFS_USING_WORKDIR
		/* build full path */
		fullpath = full_path;
		dfs_lock();
		build_fullpath(working_directory, path, fullpath);
		dfs_unlock();
#else
#ifdef RT_USING_FINSH
		rt_kprintf("bad filename");
#endif
		return -1;
#endif
	}

	if ( (fs = dfs_filesystem_lookup(fullpath)) == RT_NULL) return -DFS_STATUS_ENOENT;

	/* Check whether file is already open */
	dfs_lock();
	for (index = 0; index < DFS_FD_MAX; index++)
	{
		fd = &(fd_table[index]);
		if (fd->fs == RT_NULL) continue;

		build_fullpath(fd->fs->path, fd->path, search_path);
		if (strcmp(fullpath, search_path) == 0)
		{
			dfs_unlock();
			return -DFS_STATUS_EEXIST;
		}
	}
	dfs_unlock();

	fspathlen = strlen(fs->path);
	real_path = search_path;
	rt_memset( real_path, 0, sizeof( real_path ) );
	if (*(fullpath + fspathlen) != '/') strcpy(real_path, "/");
	strcat(real_path, fullpath + fspathlen);

	if (fs->ops->unlink != RT_NULL) return fs->ops->unlink(fs, real_path);

	return -DFS_STATUS_ENOSYS;
}
示例#3
0
文件: xmemtest.c 项目: bradomyn/coht
static int check_file_exists(const char *confpath, const char *filename)
{
	FILE *file;
	char *fullpath;

	fullpath = build_fullpath(confpath, filename);
	file = fopen(fullpath, "r");
	if (!file)
		return -1;
	fclose(file);

	return 0;
}
示例#4
0
文件: dfs_raw.c 项目: samkrew/nxp-lpc
/*
+------------------------------------------------------------------------------
| Function    : dfile_raw_stat
+------------------------------------------------------------------------------
| Description : get the file or directory stat description
|
| Parameters  : path, the file or directory path
|               buf,  the stat description will be saved in it
| Returns     : 
|
+------------------------------------------------------------------------------
*/
int dfile_raw_stat(const char *path, struct dfs_stat *buf)
{
	struct dfs_filesystem* fs;
	char* fullpath, real_path[DFS_PATH_MAX + 1];
#ifdef DFS_USING_WORKDIR
	char full_path[DFS_PATH_MAX + 1];
#endif
	int fspathlen;

	fullpath = (char*)path;
	if ( fullpath[0] != '/' )
	{
#ifdef DFS_USING_WORKDIR
		/* build full path */
		fullpath = full_path;
		dfs_lock();
		build_fullpath(working_directory, path, fullpath);
		dfs_unlock();
#else
#ifdef RT_USING_FINSH
		rt_kprintf("not support working directory, bad filename\n");
#endif
		return -1;
#endif
	}

	if ( (fs = dfs_filesystem_lookup(fullpath)) == RT_NULL )
	{
		dfs_log(DFS_DEBUG_ERROR, ("can't find mounted filesystem on this path:%s", fullpath));
		return -DFS_STATUS_ENOENT;
	}

	fspathlen = strlen(fs->path);
	rt_memset(real_path, 0, sizeof(real_path));
	if (*(fullpath + fspathlen) != '/') strcpy(real_path, "/");
	strcat(real_path, fullpath + fspathlen);

	if (fs->ops->stat == RT_NULL)
	{
		dfs_log(DFS_DEBUG_ERROR, ("the filesystem didn't implement this function"));
		return -DFS_STATUS_ENOSYS;
	}

	return fs->ops->stat(fs, real_path, buf);
}
示例#5
0
// Load Track into Deck
void do_load( const char* filepath )
{
	if (verbose) printf("-> do_load(%s)\n", filepath);
	
	// Can only load if Deck is empty
	if (get_state() != MADJACK_STATE_EMPTY )
	{
		do_eject();
	}
	
	
	// Check it really is empty
	if (get_state() == MADJACK_STATE_EMPTY )
	{
		char* fullpath;
	
		set_state( MADJACK_STATE_LOADING );
		
		// Pre-pend the root directory path
		fullpath = build_fullpath( root_directory, filepath );
		if (!quiet) printf("Loading: %s\n", fullpath);
		
		// Open the new file
		input_file->file = fopen( fullpath, "r" );
		if (input_file->file==NULL) {
			error_handler( "%s: %s", strerror( errno ), fullpath);
			free( fullpath );
			return;
		}
		
		// Copy string
		input_file->filepath = strdup( filepath );
		free( fullpath );

		// Cue up the new file	
		do_cue(0.0f);
	}
	else if (get_state() != MADJACK_STATE_EMPTY)
	{
		fprintf(stderr, "Warning: Can't change from %s to state LOADING.\n", get_state_name(get_state()) );
	}
	
}
示例#6
0
文件: dfs_raw.c 项目: samkrew/nxp-lpc
/*
+------------------------------------------------------------------------------
| Function    : dfile_raw_open
+------------------------------------------------------------------------------
| Description : 
|
| Parameters  : 
| Returns     : 
|
+------------------------------------------------------------------------------
*/
int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags)
{
	struct dfs_filesystem* fs;
	char *fullpath;
#ifdef DFS_USING_WORKDIR
	char full_path[DFS_PATH_MAX + 1];
#endif
	int fspathlen, result;

	/* parameter check */
	if ( fd == RT_NULL ) return -DFS_STATUS_EINVAL;

	/* make sure we have an absolute path */
	fullpath = (char*)path;
	if ( fullpath[0] != '/')
	{
#ifdef DFS_USING_WORKDIR
		/* build full path */
		fullpath = &full_path[0];
		dfs_lock();
		build_fullpath(working_directory, path, fullpath);
		dfs_unlock();
#else
#ifdef RT_USING_FINSH
		rt_kprintf("bad filename");
#endif
		return -1;
#endif
	}

	dfs_log(DFS_DEBUG_INFO, ("open file:%s", fullpath));

	/* find filesystem */
	fs = dfs_filesystem_lookup(fullpath);
	if ( fs == RT_NULL ) return -DFS_STATUS_ENOENT;

	dfs_log(DFS_DEBUG_INFO, ("open in filesystem:%s", fs->ops->name));
	fd->fs = fs;

	/* initilize the fd item */
	fd->type = FT_REGULAR;
	//fd->ref_count = 1;
	fd->flags = flags;
	fd->size = 0;
	fd->pos = 0;

	fspathlen = strlen(fs->path);
	rt_memset(fd->path, 0, DFS_PATH_MAX + 1);
	if (*(fullpath + fspathlen) != '/') strcpy(fd->path, "/");
	strcat(fd->path, fullpath + fspathlen);

	/* specific file system open routine */
	if (fs->ops->open == RT_NULL)
	{
		/* clear fd */
		rt_memset(fd->path, 0, DFS_PATH_MAX + 1);

		fd->type = FT_REGULAR;
		fd->ref_count = 0;
		fd->fs = RT_NULL;
		fd->flags = 0;
		fd->size = 0;
		fd->pos = 0;
		fd->data = RT_NULL;

		return -DFS_STATUS_ENOSYS;
	}

	if ((result = fs->ops->open(fd)) < 0)
	{
		/* clear fd */
		fd->fs = RT_NULL;
		fd->flags = 0;
		fd->data = RT_NULL;

		dfs_log(DFS_DEBUG_INFO, ("open failed"));

		return result;
	}

	fd->flags |= DFS_F_OPEN;
	if ( flags & DFS_O_DIRECTORY )
	{
		fd->type = FT_DIRECTORY;
		fd->flags |= DFS_F_DIRECTORY;
	}

	dfs_log(DFS_DEBUG_INFO, ("open successful"));
	return 0;
}