/* Read from the file NODE for user CRED starting at OFFSET and continuing for up to *LEN bytes. Put the data at DATA. Set *LEN to the amount successfully read upon return. */ error_t netfs_attempt_read (struct iouser *cred, struct node *node, off_t offset, size_t *len, void *data) { error_t err = 0; if (! node->nn->contents) err = ccache_create (node, &node->nn->contents); if (! err) { if (*len > node->nn_stat.st_size - offset) *len = node->nn_stat.st_size - offset; if (*len > 0) err = ccache_read (node->nn->contents, offset, *len, data); } return err; }
void tarsnap_mode_c(struct bsdtar *bsdtar) { struct archive *a; size_t i; if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) bsdtar_errc(bsdtar, 1, 0, "no files or directories specified"); for (i = 0; bsdtar->argv[i] != NULL; i++) { if (bsdtar->argv[i][0] == '-' && bsdtar->argv[i][1] == '-') { bsdtar_warnc(bsdtar, 0, "List of objects to archive includes '%s'." " This might not be what you intended.", bsdtar->argv[i]); break; } } a = archive_write_new(); /* We only support the pax restricted format. */ archive_write_set_format_pax_restricted(a); /* Set the block size to zero -- we don't want buffering. */ archive_write_set_bytes_per_block(a, 0); /* Open the archive, keeping a cookie for talking to the tape layer. */ bsdtar->write_cookie = archive_write_open_multitape(a, bsdtar->machinenum, bsdtar->cachedir, bsdtar->tapenames[0], bsdtar->argc_orig, bsdtar->argv_orig, bsdtar->option_print_stats, bsdtar->option_dryrun, bsdtar->creationtime); if (bsdtar->write_cookie == NULL) bsdtar_errc(bsdtar, 1, 0, "%s", archive_error_string(a)); /* * Remember the device and inode numbers of the cache directory, so * that we can skip is in write_hierarchy(). */ if (getdevino(a, bsdtar->cachedir, &bsdtar->cachedir_dev, &bsdtar->cachedir_ino)) bsdtar_errc(bsdtar, 1, 0, "%s", archive_error_string(a)); /* If the chunkification cache is enabled, read it. */ if ((bsdtar->cachecrunch < 2) && (bsdtar->cachedir != NULL)) { bsdtar->chunk_cache = ccache_read(bsdtar->cachedir); if (bsdtar->chunk_cache == NULL) bsdtar_errc(bsdtar, 1, errno, "Error reading cache"); } write_archive(a, bsdtar); /* * If this isn't a dry run and we're running with the chunkification * cache enabled, write the cache back to disk. */ if ((bsdtar->option_dryrun == 0) && (bsdtar->cachecrunch < 2)) { if (ccache_write(bsdtar->chunk_cache, bsdtar->cachedir)) bsdtar_errc(bsdtar, 1, errno, "Error writing cache"); } /* Free the chunkification cache. */ if (bsdtar->cachecrunch < 2) ccache_free(bsdtar->chunk_cache); }