• Home
  • Raw
  • Download

Lines Matching refs:fd

98 static void fuse_reply(const fuse_data* fd, uint64_t unique, const void* data, size_t len) {  in fuse_reply()  argument
110 int res = writev(fd->ffd, vec, 2); in fuse_reply()
116 static int handle_init(void* data, fuse_data* fd, const fuse_in_header* hdr) { in handle_init() argument
147 fuse_reply(fd, hdr->unique, &out, fuse_struct_size); in handle_init()
152 static void fill_attr(fuse_attr* attr, const fuse_data* fd, uint64_t nodeid, uint64_t size, in fill_attr() argument
156 attr->uid = fd->uid; in fill_attr()
157 attr->gid = fd->gid; in fill_attr()
166 static int handle_getattr(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) { in handle_getattr() argument
171 fill_attr(&(out.attr), fd, hdr->nodeid, 4096, S_IFDIR | 0555); in handle_getattr()
173 fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444); in handle_getattr()
175 fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0); in handle_getattr()
180 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_getattr()
184 static int handle_lookup(void* data, const fuse_data* fd, const fuse_in_header* hdr) { in handle_lookup() argument
195 fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444); in handle_lookup()
199 fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0); in handle_lookup()
204 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_lookup()
208 static int handle_open(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) { in handle_open() argument
214 fuse_reply(fd, hdr->unique, &out, sizeof(out)); in handle_open()
228 static int fetch_block(fuse_data* fd, uint32_t block) { in fetch_block() argument
229 if (block == fd->curr_block) { in fetch_block()
233 if (block >= fd->file_blocks) { in fetch_block()
234 memset(fd->block_data, 0, fd->block_size); in fetch_block()
235 fd->curr_block = block; in fetch_block()
239 uint32_t fetch_size = fd->block_size; in fetch_block()
240 if (block * fd->block_size + fetch_size > fd->file_size) { in fetch_block()
243 fetch_size = fd->file_size - (block * fd->block_size); in fetch_block()
244 memset(fd->block_data + fetch_size, 0, fd->block_size - fetch_size); in fetch_block()
247 if (!fd->provider->ReadBlockAlignedData(fd->block_data, fetch_size, block)) { in fetch_block()
251 fd->curr_block = block; in fetch_block()
261 SHA256(fd->block_data, fd->block_size, hash.data()); in fetch_block()
263 const SHA256Digest& blockhash = fd->hashes[block]; in fetch_block()
270 fd->curr_block = -1; in fetch_block()
275 fd->hashes[block] = hash; in fetch_block()
279 static int handle_read(void* data, fuse_data* fd, const fuse_in_header* hdr) { in handle_read() argument
303 uint32_t block = offset / fd->block_size; in handle_read()
304 int result = fetch_block(fd, block); in handle_read()
315 uint32_t block_offset = offset - (block * fd->block_size); in handle_read()
318 if (size + block_offset <= fd->block_size) { in handle_read()
321 vec[1].iov_base = fd->block_data + block_offset; in handle_read()
327 memcpy(fd->extra_block, fd->block_data + block_offset, fd->block_size - block_offset); in handle_read()
328 vec[1].iov_base = fd->extra_block; in handle_read()
329 vec[1].iov_len = fd->block_size - block_offset; in handle_read()
331 result = fetch_block(fd, block + 1); in handle_read()
333 vec[2].iov_base = fd->block_data; in handle_read()
338 if (writev(fd->ffd, vec, vec_used) == -1) { in handle_read()
362 fuse_data fd = {}; in run_fuse_sideload() local
363 fd.provider = provider.get(); in run_fuse_sideload()
364 fd.file_size = file_size; in run_fuse_sideload()
365 fd.block_size = block_size; in run_fuse_sideload()
366 fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1); in run_fuse_sideload()
369 if (fd.file_blocks > (1 << 18)) { in run_fuse_sideload()
370 fprintf(stderr, "file has too many blocks (%u)\n", fd.file_blocks); in run_fuse_sideload()
376 fd.hashes.resize(fd.file_blocks); in run_fuse_sideload()
377 fd.uid = getuid(); in run_fuse_sideload()
378 fd.gid = getgid(); in run_fuse_sideload()
380 fd.curr_block = -1; in run_fuse_sideload()
381 fd.block_data = static_cast<uint8_t*>(malloc(block_size)); in run_fuse_sideload()
382 if (fd.block_data == nullptr) { in run_fuse_sideload()
387 fd.extra_block = static_cast<uint8_t*>(malloc(block_size)); in run_fuse_sideload()
388 if (fd.extra_block == nullptr) { in run_fuse_sideload()
394 fd.ffd.reset(open("/dev/fuse", O_RDWR)); in run_fuse_sideload()
395 if (fd.ffd == -1) { in run_fuse_sideload()
403 "fd=%d,user_id=%d,group_id=%d,max_read=%u,allow_other,rootmode=040000", fd.ffd.get(), in run_fuse_sideload()
404 fd.uid, fd.gid, block_size); in run_fuse_sideload()
416 ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer))); in run_fuse_sideload()
438 result = handle_init(data, &fd, hdr); in run_fuse_sideload()
442 result = handle_lookup(data, &fd, hdr); in run_fuse_sideload()
446 result = handle_getattr(data, &fd, hdr); in run_fuse_sideload()
450 result = handle_open(data, &fd, hdr); in run_fuse_sideload()
454 result = handle_read(data, &fd, hdr); in run_fuse_sideload()
458 result = handle_flush(data, &fd, hdr); in run_fuse_sideload()
462 result = handle_release(data, &fd, hdr); in run_fuse_sideload()
480 TEMP_FAILURE_RETRY(write(fd.ffd, &outhdr, sizeof(outhdr))); in run_fuse_sideload()
491 free(fd.block_data); in run_fuse_sideload()
492 free(fd.extra_block); in run_fuse_sideload()