Exemple #1
0
/* remove currently selected file */
uint16 as_remove(asgard_handle * handle) {
	fs_file * file = as_get_current_file(handle);
	fs_rmfile(file, handle->mode);
	file = as_get_current_directory(handle);						//get current directory
	as_set_current_file(handle, file);								//automatically select parent directory
	return APDU_SUCCESS;
}
Exemple #2
0
static int wrap_fs_unlink(struct _reent *r, char *path)
{
    if (!fs_rmfile(fs, (euint8*)path)) {
	return 0;
    }
    r->_errno = EACCES;

    return -1;
}
Exemple #3
0
bool test_fs_manip()
{
	char *str;

	printf("testing simple read/write... ");

	fs_writestr("testfile", "str-TEST");
	str = fs_readstr("testfile");
	if(!str_isequal(str, "str-TEST"))
		return printf("failed\n"), false;

	mem_free(str);

	printf("okay\n");

	printf("testing file copy... ");

	fs_copy("copyfile", "testfile");
	str = fs_readstr("copyfile");
	if(!str_isequal(str, "str-TEST"))
		return printf("failed\n"), false;

	mem_free(str);

	printf("okay\n");

	printf("testing file deletion... ");

	fs_rmfile("testfile");
	fs_rmfile("copyfile");
	if(fs_exists("testfile") || fs_exists("copyfile"))
		return printf("failed\n"), false;

	printf("okay\n");

	return true;
}
Exemple #4
0
static int wrap_fs_open(struct _reent *r, const char *pathname, int flags, int mode)
{
    wrap_fs_check_is_inited();
    mode = mode;
    int fd = wrap_fs_get_fd();
    if (fd >= 0) {
	euint8 m = 0;
	flags &= 0xffff;
	if (flags == O_RDONLY)
	    m = MODE_READ;
	else if (flags & O_APPEND)
	    m = MODE_APPEND;
	else if (flags & O_WRONLY) {
	    if ((flags & O_CREAT) || (flags & O_TRUNC))
		fs_rmfile(fs, (euint8*)pathname);
	    m = MODE_WRITE;
	}

	fprintf(stderr, "open(%s) flag: %08X mode: %c\n", pathname, flags, m);
	if (!m) {
	    fprintf(stderr, "unknown mode\n");
	    r->_errno = EACCES;
	    return -1;
	}

	fd_list[fd].file = (File *)malloc(sizeof(File));
	if (!fd_list[fd].file) {
	    fprintf(stderr, "No memory!\n");
	    r->_errno = ENOMEM;
	    return -1;
	}
	if ( (file_fopen(fd_list[fd].file, fs, (esint8*)pathname, m)) != 0) {
	    fprintf(stderr, "Unable to open the file\n");
	    r->_errno = EACCES;
	    return(-1);
	}
	fd_list[fd].used = 1;
	return fd;
    }
    r->_errno = ENFILE;
    return -1;
}