summaryrefslogtreecommitdiff
path: root/src/librsync.h
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2017-07-17 13:25:40 +1000
committerDonovan Baarda <abo@minkirri.apana.org.au>2017-07-17 13:25:40 +1000
commit156a31674080ca1549ea312f380935eb18d43b53 (patch)
treef860badc1f53648c87be0c95d642614fbfd73505 /src/librsync.h
parent65f3ed206818e6cd2d53b033d536697e6f13a01a (diff)
downloadlibrsync-156a31674080ca1549ea312f380935eb18d43b53.tar.gz
Add public rs_sig_args() function for reccommended sig args from filesize.
In librsync.h add RS_DEFAULT_STRONG_LEN for default strong_len when no filesize is provided. Add rs_sig_args() for getting recommended args for rs_sig_begin() from the old filesize. Update comments to explain these. In sumset.[ch] add rs_sig_args_check() macro for checking rs_sig_begin() arguments are valid, and use it inside the rs_signature_check() macro. Add implementation of rs_sig_args() function and use it inside rs_signature_init(). Update rs_signature_init() arguments to the same types used by rs_sig_begin() and thus rs_sig_args(). In whole.c make rs_sig_file() get the old filesize and use it with rs_sig_args() to get the recommended sig_magic, block_len and strong_len. In rdiff.c make the default block_len=0 so that rs_sig_file() uses the recommended block_len based on the filesize from rs_sig_args(). Remove the default of block_len=8 for hash=md4 which is not really required for backwards compatibility at all, so it uses the rs_sig_args() recommendation instead. Note this change means strong_len=0 no-longer means "max size for given hash", but instead means "recommended size based on filesize". Update tests/signature.input expected output files to reflect new default strong_len and block_len values.
Diffstat (limited to 'src/librsync.h')
-rw-r--r--src/librsync.h40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/librsync.h b/src/librsync.h
index e379920..fe4f228 100644
--- a/src/librsync.h
+++ b/src/librsync.h
@@ -402,9 +402,17 @@ struct rs_buffers_s {
*/
typedef struct rs_buffers_s rs_buffers_t;
-/** Default block length, if not determined by any other factors. */
+/** Default block length, if not determined by any other factors.
+ *
+ * The 2K default assumes a typical file is about 4MB and should be
+ * OK for files up to 32G with more than 1GB ram. */
#define RS_DEFAULT_BLOCK_LEN 2048
+/** Default strong sum length, if not determined by any other factors.
+ *
+ * This is conservative, and should be safe for files up to 32TB with
+ * a 1KB block_len. */
+#define RS_DEFAULT_STRONG_LEN 12
/**
* \brief Job of work to be done.
@@ -465,8 +473,34 @@ const rs_stats_t * rs_job_statistics(rs_job_t *job);
*/
rs_result rs_job_free(rs_job_t *);
-/**
- * \brief Start generating a signature.
+/** Get or check signature arguments for a given file size.
+ *
+ * This can be used to get the recommended arguments for generating a
+ * signature. On calling, all arguments can be set to a value to use,
+ * or zero to indicate "unknown". On return any zero inputs (except
+ * old_fsize) will be set to the recommended value to use and the
+ * returned result will indicate if any non-zero inputs were invalid.
+ *
+ * \param old_fsize - the original file size (0 for "unknown).
+ *
+ * \param *magic - the magic type to use.
+ *
+ * \param *block_len - the block length to use.
+ *
+ * \param *strong_len - the strongsum length to use.
+ *
+ * \return RS_DONE if all arguments are valid, otherwise an error code.
+ */
+rs_result rs_sig_args(rs_long_t old_fsize,
+ rs_magic_number *magic,
+ size_t *block_len,
+ size_t *strong_len);
+
+
+/** Start generating a signature.
+ *
+ * It's recommended you use rs_sig_args() to get the recommended arguments for
+ * this based on the original file size.
*
* \return A new rs_job_t into which the old file data can be passed.
*