Lines Matching refs:fd
97 static void fuse_reply(struct fuse_data* fd, __u64 unique, const void *data, size_t len) in fuse_reply() argument
112 res = writev(fd->ffd, vec, 2); in fuse_reply()
118 static int handle_init(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_init() argument
154 fuse_reply(fd, hdr->unique, &out, fuse_struct_size); in handle_init()
159 static void fill_attr(struct fuse_attr* attr, struct fuse_data* fd, in fill_attr() argument
163 attr->uid = fd->uid; in fill_attr()
164 attr->gid = fd->gid; in fill_attr()
173 static int handle_getattr(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_getattr() argument
180 fill_attr(&(out.attr), fd, hdr->nodeid, 4096, S_IFDIR | 0555); in handle_getattr()
182 fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444); in handle_getattr()
184 fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0); in handle_getattr()
189 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_getattr()
193 static int handle_lookup(void* data, struct fuse_data* fd, in handle_lookup() argument
204 fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444); in handle_lookup()
209 fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0); in handle_lookup()
214 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_lookup()
218 static int handle_open(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_open() argument
227 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_open()
231 static int handle_flush(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_flush() argument
235 static int handle_release(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_release() argument
241 static int fetch_block(struct fuse_data* fd, uint32_t block) { in fetch_block() argument
242 if (block == fd->curr_block) { in fetch_block()
246 if (block >= fd->file_blocks) { in fetch_block()
247 memset(fd->block_data, 0, fd->block_size); in fetch_block()
248 fd->curr_block = block; in fetch_block()
252 size_t fetch_size = fd->block_size; in fetch_block()
253 if (block * fd->block_size + fetch_size > fd->file_size) { in fetch_block()
257 fetch_size = fd->file_size - (block * fd->block_size); in fetch_block()
258 memset(fd->block_data + fetch_size, 0, fd->block_size - fetch_size); in fetch_block()
261 int result = fd->vtab->read_block(fd->cookie, block, fd->block_data, fetch_size); in fetch_block()
264 fd->curr_block = block; in fetch_block()
276 SHA256_hash(fd->block_data, fd->block_size, hash); in fetch_block()
277 uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_SIZE; in fetch_block()
285 fd->curr_block = -1; in fetch_block()
294 static int handle_read(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) { in handle_read() argument
323 uint32_t block = offset / fd->block_size; in handle_read()
324 result = fetch_block(fd, block); in handle_read()
338 uint32_t block_offset = offset - (block * fd->block_size); in handle_read()
340 if (size + block_offset <= fd->block_size) { in handle_read()
343 vec[1].iov_base = fd->block_data + block_offset; in handle_read()
349 memcpy(fd->extra_block, fd->block_data + block_offset, in handle_read()
350 fd->block_size - block_offset); in handle_read()
351 vec[1].iov_base = fd->extra_block; in handle_read()
352 vec[1].iov_len = fd->block_size - block_offset; in handle_read()
354 result = fetch_block(fd, block+1); in handle_read()
356 vec[2].iov_base = fd->block_data; in handle_read()
361 if (writev(fd->ffd, vec, vec_used) < 0) { in handle_read()
385 struct fuse_data fd; in run_fuse_sideload() local
386 memset(&fd, 0, sizeof(fd)); in run_fuse_sideload()
387 fd.vtab = vtab; in run_fuse_sideload()
388 fd.cookie = cookie; in run_fuse_sideload()
389 fd.file_size = file_size; in run_fuse_sideload()
390 fd.block_size = block_size; in run_fuse_sideload()
391 fd.file_blocks = (file_size == 0) ? 0 : (((file_size-1) / block_size) + 1); in run_fuse_sideload()
393 if (fd.file_blocks > (1<<18)) { in run_fuse_sideload()
394 fprintf(stderr, "file has too many blocks (%u)\n", fd.file_blocks); in run_fuse_sideload()
399 fd.hashes = (uint8_t*)calloc(fd.file_blocks, SHA256_DIGEST_SIZE); in run_fuse_sideload()
400 if (fd.hashes == NULL) { in run_fuse_sideload()
402 fd.file_blocks * SHA256_DIGEST_SIZE); in run_fuse_sideload()
407 fd.uid = getuid(); in run_fuse_sideload()
408 fd.gid = getgid(); in run_fuse_sideload()
410 fd.curr_block = -1; in run_fuse_sideload()
411 fd.block_data = (uint8_t*)malloc(block_size); in run_fuse_sideload()
412 if (fd.block_data == NULL) { in run_fuse_sideload()
417 fd.extra_block = (uint8_t*)malloc(block_size); in run_fuse_sideload()
418 if (fd.extra_block == NULL) { in run_fuse_sideload()
424 fd.ffd = open("/dev/fuse", O_RDWR); in run_fuse_sideload()
425 if (fd.ffd < 0) { in run_fuse_sideload()
435 fd.ffd, fd.uid, fd.gid, block_size); in run_fuse_sideload()
445 ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer))); in run_fuse_sideload()
467 result = handle_init(data, &fd, hdr); in run_fuse_sideload()
471 result = handle_lookup(data, &fd, hdr); in run_fuse_sideload()
475 result = handle_getattr(data, &fd, hdr); in run_fuse_sideload()
479 result = handle_open(data, &fd, hdr); in run_fuse_sideload()
483 result = handle_read(data, &fd, hdr); in run_fuse_sideload()
487 result = handle_flush(data, &fd, hdr); in run_fuse_sideload()
491 result = handle_release(data, &fd, hdr); in run_fuse_sideload()
509 TEMP_FAILURE_RETRY(write(fd.ffd, &outhdr, sizeof(outhdr))); in run_fuse_sideload()
514 fd.vtab->close(fd.cookie); in run_fuse_sideload()
521 if (fd.ffd) close(fd.ffd); in run_fuse_sideload()
522 free(fd.hashes); in run_fuse_sideload()
523 free(fd.block_data); in run_fuse_sideload()
524 free(fd.extra_block); in run_fuse_sideload()