Example #1
0
int File::fstat(file_stat_t *fs)
{
	if(!is_multipart)
		return fstat_file(fd, fs);

	int64_t size = 0;
	file_stat_t statbuf;

	for(int i = 0; i < is_multipart; i++)
	{
		fstat_file(fp[i], &statbuf);
		size += statbuf.file_size;
	}

	int ret = fstat_file(fd, fs); statbuf.file_size = size; *fs = statbuf;
	return ret;
}
Example #2
0
int File::open(const char *path, int flags)
{
	if (FD_OK(fd))
		this->close();

	fd = open_file(path, flags);
	if (!FD_OK(fd))
		return -1;

	// multi part
	int flen = strlen(path)-6;
	if(flen < 0)
		is_multipart = 0;
	else
		is_multipart = (strstr(path + flen, ".iso.0") != NULL || strstr(path + flen, ".ISO.0") != NULL);

	if(!is_multipart) return 0;

	char *filepath = (char *)malloc(strlen(path)+2); strcpy(filepath, path);

	file_stat_t st;
	fstat_file(fd, &st); part_size = st.file_size;

	is_multipart = 1; // count parts

	for(int i = 1; i < 64; i++)
	{
		filepath[flen+4] = 0; sprintf(filepath, "%s.%i", filepath, i);

		fp[i] = open_file(filepath, flags);
		if (!FD_OK(fp[i])) break;

		is_multipart++;
	}

	fp[0] = fd; free(filepath);

	return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
	int ret;
	struct stat st;
	struct file_context *src;
	struct file_context *dst;
	uint64_t off;
	int64_t count;
	
#ifdef WIN32
	if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
		printf("Failed to start Winsock2\n");
		return 10;
	}
#endif

#ifdef AROS
	aros_init_socket();
#endif

	if (argc != 3) {
		usage();
	}

	src = open_file(argv[1], O_RDONLY);
	if (src == NULL) {
		fprintf(stderr, "Failed to open %s\n", argv[1]);
		return 10;
	}

	dst = open_file(argv[2], O_WRONLY|O_CREAT|O_TRUNC);
	if (dst == NULL) {
		fprintf(stderr, "Failed to open %s\n", argv[2]);
		free_file_context(src);
		return 10;
	}

	if (fstat_file(src, &st) != 0) {
		fprintf(stderr, "Failed to fstat source file\n");
		free_file_context(src);
		free_file_context(dst);
		return 10;
	}

	off = 0;
	while (off < st.st_size) {
		count = st.st_size - off;
		if (count > BUFSIZE) {
			count = BUFSIZE;
		}
		count = file_pread(src, buf, count, off);
		if (count < 0) {
			fprintf(stderr, "Failed to read from source file\n");
			free_file_context(src);
			free_file_context(dst);
			return 10;
		}
		count = file_pwrite(dst, buf, count, off);
		if (count < 0) {
			fprintf(stderr, "Failed to write to dest file\n");
			free_file_context(src);
			free_file_context(dst);
			return 10;
		}

		off += count;
	}
	printf("copied %d bytes\n", (int)off);

	free_file_context(src);
	free_file_context(dst);

	return 0;
}
void runFstatTests(){
	fstat_file();
	fstat_largeFile();
	fstat_dir();
	fstat_ebadf();
}