From 38be5f3e95689ce6041c726fb681eec817317db8 Mon Sep 17 00:00:00 2001 From: "(none)!yura" <(none)!yura> Date: Fri, 12 Nov 2004 17:09:24 +0000 Subject: [PATCH] New API's ntfs_runlist_sparse and ntfs_rl_get_compressed_size. (Logical change 1.632) --- libntfs/runlist.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/libntfs/runlist.c b/libntfs/runlist.c index 1fe92da4..4dc958cb 100644 --- a/libntfs/runlist.c +++ b/libntfs/runlist.c @@ -1623,3 +1623,64 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) /* Done! */ return 0; } + +/** + * ntfs_runlist_sparse - check whether runlist have sparse regions or not. + * @rl: runlist to check + * + * Return 1 if have, 0 if not, -1 on error with errno set to the error code. + */ +int ntfs_rl_sparse(runlist *rl) +{ + runlist *rlc; + + if (!rl) { + Dprintf("%s(): Ivalid argument passed.\n"); + errno = EINVAL; + return -1; + } + + for (rlc = rl; rlc->length; rlc++) + if (rlc->lcn < 0) { + if (rlc->lcn != LCN_HOLE) { + Dprintf("%s(): Recevied unmapped runlist.\n", + __FUNCTION__); + errno = EINVAL; + return -1; + } + return 1; + } + return 0; +} + +/** + * ntfs_runlist_get_compressed_size - calculate length of non sparse regions + * @vol: ntfs volume (need for cluster size) + * @rl: runlist to calculate for + * + * Return compressed size or -1 on error with errno set to the error code. + */ +s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) +{ + runlist *rlc; + s64 ret = 0; + + if (!rl) { + Dprintf("%s(): Ivalid argument passed.\n"); + errno = EINVAL; + return -1; + } + + for (rlc = rl; rlc->length; rlc++) { + if (rlc->lcn < 0) { + if (rlc->lcn != LCN_HOLE) { + Dprintf("%s(): Recevied unmapped runlist.\n", + __FUNCTION__); + errno = EINVAL; + return -1; + } + } else + ret = rlc->length << vol->cluster_size_bits; + } + return ret; +}