commit 91b6eef4b9ed627b68b23bf84711625c9058527f Author: Andrea Mazzoleni Date: Tue Mar 1 22:19:30 2011 +0100 First web deploy diff --git a/CNAME b/CNAME new file mode 100644 index 00000000..85c7eae7 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +www.snapraid.it diff --git a/authors.html b/authors.html new file mode 100644 index 00000000..0ffe5804 --- /dev/null +++ b/authors.html @@ -0,0 +1,85 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+The author of SnapRAID is Andrea Mazzoleni. +

+

+I'm an Italian Software Engineer living in Bergamo, Italy. +My hobbies are cycling, +salsa dancing, +reading and +programming. +

+

+You can contact me by email using the address +Andrea Mazzoleni email address +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/bitcoin.png b/bitcoin.png new file mode 100644 index 00000000..faea4617 Binary files /dev/null and b/bitcoin.png differ diff --git a/compare.html b/compare.html new file mode 100644 index 00000000..a0fbb7e0 --- /dev/null +++ b/compare.html @@ -0,0 +1,255 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+SnapRAID is only one of the available not standard RAID solutions for disk arrays. +

+ +

+The best known others are: +

+

+ +

+The main factor to categorize them is when the redundancy information is updated. +In real-time solutions the parity data is updated in real-time, +without an explicit action from the user. Like in standard RAID. +In snapshot solutions the parity data is updated only upon +an explicit request from the user. Like in backups. +

+ +

+Other important factors are the support of an integrity checksum +to identify silent data corruption +and the possibility to fix it, +if you can use already filled disk, +if you can recover your data from not broken disks when you get too many failures to have a full recover, +and if all your disks are spinning when reading one file. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SnapRAIDunRAIDFlexRAIDdisParityZFSBtrfsStorage Spaces
Redundancy model
Real-time computes parity at real-time like RAID, +snapshot at request time, like Backup.
SnapshotReal-timeReal-time
Snapshot
SnapshotReal-time
Snapshot
Real-time
Snapshot
Real-time
Integrity
+If data is validated with some kind of checksum, +and which one is the default. +
Yes
SpookyHash
128 bit
NoYes
Adler32
32 bit
Yes
MD5
128 bit
Yes
fletcher4
256 bit
Yes
CRC32C
32 bit
No
Fix silent errors
+If silent errors are detected and fixed before they can propagate into the parity. +
YesNo [1]No [2]NoYes [3]Yes [3]No
Number of failures
+How many disk failures are supported? 1 is for RAID5, 2 for RAID6. +
1 2 3 4 5 611 2 3 4 5 6+11 2 31 21
Other failures
If more disks fail than the supported redundancy model, +is it possible to recover the data in the not failed disks?
YesYesYesYesNoNoNo
Power/Noise
How many disks are spinning when reading a single file?
OneOneOneOneAllAllAll
Filled disk
Can you start with already filled disks?
YesNo[4]YesYesNoNoNo
Operating system
Which OS is supported?
Linux
Windows
Mac OS X
OpenIndiana
Solaris
BSD
LinuxWindows
Linux
WindowsLinux [5]
Mac OS X
OpenIndiana
Solaris
BSD
LinuxWindows
Age
The year of the first official release supporting at least RAID5 redundancy.
2011200520082009200520132012
License/Price
+Software license and price. +
Open Source GPL3
Free
Open Source GPL2
89$/129$
Proprietary
40$/60$
Proprietary
Free
Open Source CDDL
Free
Open Source GPL2
Free
Proprietary
Windows 8
Interface
Which interface is provided? GUI or command line?
+command line
or Elucidate GUI, +or plugin for for OpenMediaVault +
command line
GUI
GUIcommand linecommand line
GUI/Plugins [6]
command lineGUI
+ +

Notes

+ +

+[1] - unRAID doesn't have any kind of checksum, and it just ignores silent errors. +Even worse, if a parity error is detected as result of a silent error in the data, +the parity is automatically recomputed, making impossible to recover the silent error, even manually. +

+ +

+[2] - Flexraid uses checksums to validate files, but such checksums +are not verified when data is read to update the parity. +This means that any silent error present will propagate into the parity, +making impossible to fix it later, even if it can be still detected comparing the file checksum. +
+You can get in a state where the "Validate" operation +reports errors, but the "Verify" one reports no problem in the parity, +making impossible to fix the errors. +

+ +

+[3] - ZFS and Btrfs provide a bit-rot protection at the same level of SnapRAID, +always checking data before using it. +In this regards all the three solutions represent the state-of-the-art. +
+A cons of ZFS is that the default Fletcher +checksum is a choice that favorites speed over quality. +The same for the default CRC32C used by Btrfs. +The 128 bits SpookyHash +used by SnapRAID is instead the state-of-the-art in checksumming quality, +without compromising in speed. +
+Another cons of ZFS is that it lacks a fast RAID implementation in assembler. +It only has a C implementation, that is from two to four times slower than SnapRAID/Btrfs. +
+ZFS also uses a sub-optimal RAID-Z3 algorithm, that requires double computations than the equivalent SnapRAID's z-parity. +
+Instead, both SnapRAID and Btrfs use top-notch assembler implementations to compute the RAID parity, +always using the best known RAID algorithm and implementation. +

+ +

+[4] - unRAID allows to use filled disks but only if they are already +formatted with the ReiserFS filesystem. +

+ +

+[5] - ZFS is also available in Linux at kernel level using ZFS on Linux. +

+ +

+[6] - ZFS has external GUIs, like Napp-it +and plugins for FreeNAS and NAS4Free. +

+ +

+If you think that some information reported is incorrect or simply unfair, please report it in the Forum. +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/cov/amber.png b/cov/amber.png new file mode 100644 index 00000000..2cab170d Binary files /dev/null and b/cov/amber.png differ diff --git a/cov/cmdline/check.c.func-sort-c.html b/cov/cmdline/check.c.func-sort-c.html new file mode 100644 index 00000000..4ab905e6 --- /dev/null +++ b/cov/cmdline/check.c.func-sort-c.html @@ -0,0 +1,108 @@ + + + + + + + LCOV - lcov.info - cmdline/check.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:68074391.5 %
Date:2015-05-12Functions:99100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled1866660
file_post933330
repair869093
blockcmp463419
repair_step256105
is_hash_matching204860
is_parity_matching8416
state_check120
state_check_process118
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/check.c.func.html b/cov/cmdline/check.c.func.html new file mode 100644 index 00000000..c04839aa --- /dev/null +++ b/cov/cmdline/check.c.func.html @@ -0,0 +1,108 @@ + + + + + + + LCOV - lcov.info - cmdline/check.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:68074391.5 %
Date:2015-05-12Functions:99100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled1866660
blockcmp463419
file_post933330
is_hash_matching204860
is_parity_matching8416
repair869093
repair_step256105
state_check120
state_check_process118
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/check.c.gcov.html b/cov/cmdline/check.c.gcov.html new file mode 100644 index 00000000..3ba87bbe --- /dev/null +++ b/cov/cmdline/check.c.gcov.html @@ -0,0 +1,2015 @@ + + + + + + + LCOV - lcov.info - cmdline/check.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:68074391.5 %
Date:2015-05-12Functions:99100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "util.h"
+      22             : #include "elem.h"
+      23             : #include "import.h"
+      24             : #include "search.h"
+      25             : #include "state.h"
+      26             : #include "parity.h"
+      27             : #include "handle.h"
+      28             : #include "raid/raid.h"
+      29             : #include "raid/combo.h"
+      30             : 
+      31             : /****************************************************************************/
+      32             : /* check */
+      33             : 
+      34             : /**
+      35             :  * A block that failed the hash check, or that was deleted.
+      36             :  */
+      37             : struct failed_struct {
+      38             :         /**
+      39             :          * If we know for sure that the block is garbage or missing
+      40             :          * and it needs to be recovered and rewritten to the disk.
+      41             :          */
+      42             :         int is_bad;
+      43             : 
+      44             :         /**
+      45             :          * If that we have recovered may be not updated data,
+      46             :          * an old version, or just garbage.
+      47             :          *
+      48             :          * Essentially, it means that we are not sure what we have recovered
+      49             :          * is really correct. It's just our best guess.
+      50             :          *
+      51             :          * These "recovered" block are also written to the disk if the block is marked as ::is_bad.
+      52             :          * But these files are marked also as FILE_IS_DAMAGED, and then renamed to .unrecoverable.
+      53             :          *
+      54             :          * Note that this could happen only for CHG blocks.
+      55             :          */
+      56             :         int is_outofdate;
+      57             : 
+      58             :         unsigned index; /**< Index of the failed block. */
+      59             :         struct snapraid_block* block; /**< The failed block, or BLOCK_DELETED for a deleted block */
+      60             :         struct snapraid_handle* handle; /**< The file containing the failed block, or 0 for a deleted block */
+      61             : };
+      62             : 
+      63             : /**
+      64             :  * Checks if a block hash matches the specified buffer.
+      65             :  * Return ==0 if equal
+      66             :  */
+      67      463419 : static int blockcmp(struct snapraid_state* state, int rehash, struct snapraid_block* block, unsigned char* buffer, unsigned char* buffer_zero)
+      68             : {
+      69             :         unsigned char hash[HASH_SIZE];
+      70             :         unsigned size;
+      71             : 
+      72      463419 :         size = block_file_size(block, state->block_size);
+      73             : 
+      74             :         /* now compute the hash of the valid part */
+      75      463419 :         if (rehash) {
+      76       22265 :                 memhash(state->prevhash, state->prevhashseed, hash, buffer, size);
+      77             :         } else {
+      78      441154 :                 memhash(state->hash, state->hashseed, hash, buffer, size);
+      79             :         }
+      80             : 
+      81             :         /* compare the hash */
+      82      463419 :         if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
+      83       13902 :                 return -1;
+      84             :         }
+      85             : 
+      86             :         /* compare to the end of the block */
+      87      449517 :         if (size < state->block_size) {
+      88      185818 :                 if (memcmp(buffer + size, buffer_zero + size, state->block_size - size) != 0) {
+      89          21 :                         return -1;
+      90             :                 }
+      91             :         }
+      92             : 
+      93      449496 :         return 0;
+      94             : }
+      95             : 
+      96             : /**
+      97             :  * Checks if the hash of all the failed block we are expecting to recover are now matching.
+      98             :  */
+      99      204860 : static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void* buffer_zero)
+     100             : {
+     101             :         unsigned j;
+     102             :         int hash_checked;
+     103             : 
+     104      204860 :         hash_checked = 0; /* keep track if we check at least one block */
+     105             : 
+     106             :         /* check if the recovered blocks are OK */
+     107      658878 :         for (j = 0; j < failed_count; ++j) {
+     108             :                 /* if we are expected to recover this block */
+     109      467941 :                 if (!failed[failed_map[j]].is_outofdate
+     110             :                         /* if the block has a hash to check */
+     111      463419 :                         && block_has_updated_hash(failed[failed_map[j]].block)
+     112             :                 ) {
+     113             :                         /* if a hash doesn't match, fail the check */
+     114      463419 :                         if (blockcmp(state, rehash, failed[failed_map[j]].block, buffer[failed[failed_map[j]].index], buffer_zero) != 0) {
+     115       13923 :                                 log_tag("hash_error: Hash mismatch on entry %u\n", failed_map[j]);
+     116       13923 :                                 return 0;
+     117             :                         }
+     118             : 
+     119      449496 :                         hash_checked = 1;
+     120             :                 }
+     121             :         }
+     122             : 
+     123             :         /* if nothing checked, we reject it */
+     124             :         /* note that we are excluding this case at upper level */
+     125             :         /* but checking again doesn't hurt */
+     126      190937 :         if (!hash_checked) {
+     127             :                 /* LCOV_EXCL_START */
+     128             :                 return 0;
+     129             :                 /* LCOV_EXCL_STOP */
+     130             :         }
+     131             : 
+     132             :         /* if we checked something, and no block failed the check */
+     133             :         /* recompute all the redundancy information */
+     134      190937 :         raid_gen(diskmax, state->level, state->block_size, buffer);
+     135      190937 :         return 1;
+     136             : }
+     137             : 
+     138             : /**
+     139             :  * Checks if specified parity is now matching with a recomputed one.
+     140             :  */
+     141        8416 : static int is_parity_matching(struct snapraid_state* state, unsigned diskmax, unsigned i, void** buffer, void** buffer_recov)
+     142             : {
+     143             :         /* recompute parity, note that we don't need parity over i */
+     144        8416 :         raid_gen(diskmax, i + 1, state->block_size, buffer);
+     145             : 
+     146             :         /* if the recovered parity block matches */
+     147        8416 :         if (memcmp(buffer[diskmax + i], buffer_recov[i], state->block_size) == 0) {
+     148             :                 /* recompute all the redundancy information */
+     149        8416 :                 raid_gen(diskmax, state->level, state->block_size, buffer);
+     150        8416 :                 return 1;
+     151             :         }
+     152             : 
+     153           0 :         return 0;
+     154             : }
+     155             : 
+     156             : /**
+     157             :  * Repair errors.
+     158             :  * Returns <0 if failure for missing strategy, >0 if data is wrong and we cannot rebuild correctly, 0 on success.
+     159             :  * If success, the parity are computed in the buffer variable.
+     160             :  */
+     161      256105 : static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero)
+     162             : {
+     163             :         unsigned i, n;
+     164             :         int error;
+     165             :         int has_hash;
+     166             :         int id[LEV_MAX];
+     167             :         int ip[LEV_MAX];
+     168             : 
+     169             :         /* no fix required, already checked at higher level, but just to be sure */
+     170      256105 :         if (failed_count == 0) {
+     171             :                 /* LCOV_EXCL_START */
+     172             :                 /* recompute only the parity */
+     173             :                 raid_gen(diskmax, state->level, state->block_size, buffer);
+     174             :                 return 0;
+     175             :                 /* LCOV_EXCL_STOP */
+     176             :         }
+     177             : 
+     178      256105 :         n = state->level;
+     179      256105 :         error = 0;
+     180             : 
+     181             :         /* setup vector of failed disk indexes */
+     182      898662 :         for (i = 0; i < failed_count; ++i)
+     183      642557 :                 id[i] = failed[failed_map[i]].index;
+     184             : 
+     185             :         /* check if there is at least a failed block that can be checked for correctness using the hash */
+     186             :         /* if there isn't, we have to sacrifice a parity block to check that the result is correct */
+     187      256105 :         has_hash = 0;
+     188      898662 :         for (i = 0; i < failed_count; ++i) {
+     189             :                 /* if we are expected to recover this block */
+     190      642557 :                 if (!failed[failed_map[i]].is_outofdate
+     191             :                         /* if the block has a hash to check */
+     192      633513 :                         && block_has_updated_hash(failed[failed_map[i]].block)
+     193             :                 )
+     194      625097 :                         has_hash = 1;
+     195             :         }
+     196             : 
+     197             :         /* if we don't have a hash, but we have an extra parity */
+     198             :         /* (strictly-less failures than number of parities) */
+     199      256105 :         if (!has_hash && failed_count < n) {
+     200             :                 /* number of parity to use, one more to check the recovering */
+     201        8416 :                 unsigned r = failed_count + 1;
+     202             : 
+     203             :                 /* all combinations (r of n) parities */
+     204        8416 :                 combination_first(r, n, ip);
+     205             :                 do {
+     206             :                         /* if a parity is missing, do nothing */
+     207       25248 :                         for (i = 0; i < r; ++i) {
+     208       16832 :                                 if (buffer_recov[ip[i]] == 0)
+     209           0 :                                         break;
+     210             :                         }
+     211        8416 :                         if (i != r)
+     212           0 :                                 continue;
+     213             : 
+     214             :                         /* copy the parities to use, one less because the last is used for checking */
+     215       16832 :                         for (i = 0; i < r - 1; ++i)
+     216        8416 :                                 memcpy(buffer[diskmax + ip[i]], buffer_recov[ip[i]], state->block_size);
+     217             : 
+     218             :                         /* recover using one less parity, the ip[r-1] one */
+     219        8416 :                         raid_data(r - 1, id, ip, diskmax, state->block_size, buffer);
+     220             : 
+     221             :                         /* use the remaining ip[r-1] parity to check the result */
+     222        8416 :                         if (is_parity_matching(state, diskmax, ip[r - 1], buffer, buffer_recov))
+     223        8416 :                                 return 0;
+     224             : 
+     225             :                         /* log */
+     226           0 :                         log_tag("parity_error:%u:", pos);
+     227           0 :                         for (i = 0; i < r; ++i) {
+     228           0 :                                 if (i != 0)
+     229           0 :                                         log_tag("/");
+     230           0 :                                 log_tag("%s", lev_config_name(ip[i]));
+     231             :                         }
+     232           0 :                         log_tag(":parity: Parity mismatch\n");
+     233           0 :                         ++error;
+     234           0 :                 } while (combination_next(r, n, ip));
+     235             :         }
+     236             : 
+     237             :         /* if we have a hash, and enough parities */
+     238             :         /* (less-or-equal failures than number of parities) */
+     239      247689 :         if (has_hash && failed_count <= n) {
+     240             :                 /* number of parities to use equal at the number of failures */
+     241      200100 :                 unsigned r = failed_count;
+     242             : 
+     243             :                 /* all combinations (r of n) parities */
+     244      200100 :                 combination_first(r, n, ip);
+     245             :                 do {
+     246             :                         /* if a parity is missing, do nothing */
+     247      677450 :                         for (i = 0; i < r; ++i) {
+     248      472590 :                                 if (buffer_recov[ip[i]] == 0)
+     249        4649 :                                         break;
+     250             :                         }
+     251      209509 :                         if (i != r)
+     252        4649 :                                 continue;
+     253             : 
+     254             :                         /* copy the parities to use */
+     255      672801 :                         for (i = 0; i < r; ++i)
+     256      467941 :                                 memcpy(buffer[diskmax + ip[i]], buffer_recov[ip[i]], state->block_size);
+     257             : 
+     258             :                         /* recover */
+     259      204860 :                         raid_data(r, id, ip, diskmax, state->block_size, buffer);
+     260             : 
+     261             :                         /* use the hash to check the result */
+     262      204860 :                         if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
+     263      190937 :                                 return 0;
+     264             : 
+     265             :                         /* log */
+     266       13923 :                         log_tag("parity_error:%u:", pos);
+     267       27846 :                         for (i = 0; i < r; ++i) {
+     268       13923 :                                 if (i != 0)
+     269           0 :                                         log_tag("/");
+     270       13923 :                                 log_tag("%s", lev_config_name(ip[i]));
+     271             :                         }
+     272       13923 :                         log_tag(":hash: Hash mismatch\n");
+     273       13923 :                         ++error;
+     274       37144 :                 } while (combination_next(r, n, ip));
+     275             :         }
+     276             : 
+     277             :         /* return the number of failed attempts, or -1 if no strategy */
+     278       56752 :         if (error)
+     279        9163 :                 return error;
+     280             : 
+     281       47589 :         log_tag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n",
+     282             :                 pos, failed_count, n, has_hash ? "with" : "without");
+     283       47589 :         return -1;
+     284             : }
+     285             : 
+     286      869093 : static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero)
+     287             : {
+     288             :         int ret;
+     289             :         int error;
+     290             :         unsigned j;
+     291             :         int n;
+     292             :         int something_to_recover;
+     293             :         int something_unsynced;
+     294             : 
+     295      869093 :         error = 0;
+     296             : 
+     297             :         /* if nothing failed, just recompute the parity */
+     298      869093 :         if (failed_count == 0) {
+     299      586158 :                 raid_gen(diskmax, state->level, state->block_size, buffer);
+     300      586158 :                 return 0;
+     301             :         }
+     302             : 
+     303             :         /* logs the status */
+     304     1006981 :         for (j = 0; j < failed_count; ++j) {
+     305             :                 const char* state;
+     306             :                 const char* hash;
+     307             :                 const char* data;
+     308      724046 :                 struct snapraid_block* block = failed[j].block;
+     309      724046 :                 unsigned block_state = block_state_get(block);
+     310             : 
+     311      724046 :                 switch (block_state) {
+     312       18454 :                 case BLOCK_STATE_DELETED : state = "delete"; break;
+     313       52111 :                 case BLOCK_STATE_CHG : state = "change"; break;
+     314       24012 :                 case BLOCK_STATE_REP : state = "replace"; break;
+     315      629469 :                 case BLOCK_STATE_BLK : state = "block"; break;
+     316             :                 /* LCOV_EXCL_START */
+     317             :                 default : state = "unknown"; break;
+     318             :                         /* LCOV_EXCL_STOP */
+     319             :                 }
+     320             : 
+     321      724046 :                 if (hash_is_invalid(block->hash)) {
+     322       13841 :                         hash = "lost";
+     323      710205 :                 } else if (hash_is_zero(block->hash)) {
+     324       29636 :                         hash = "zero";
+     325             :                 } else {
+     326      680569 :                         hash = "known";
+     327             :                 }
+     328             : 
+     329      724046 :                 if (failed[j].is_bad)
+     330      638323 :                         data = "bad";
+     331             :                 else
+     332       85723 :                         data = "good";
+     333             : 
+     334      724046 :                 if (failed[j].handle) {
+     335             :                         const char* disk;
+     336             :                         const char* sub;
+     337      705592 :                         struct snapraid_handle* handle = failed[j].handle;
+     338      705592 :                         disk = handle->disk->name;
+     339      705592 :                         sub = block_file_get(block)->sub;
+     340             : 
+     341      705592 :                         log_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block));
+     342             :                 } else {
+     343       18454 :                         log_tag("entry:%u:%s:%s:%s:\n", j, state, hash, data);
+     344             :                 }
+     345             :         }
+     346             : 
+     347             :         /* Here we have to try two different strategies to recover, because in case the 'sync' */
+     348             :         /* process is aborted, we don't know if the parity data is really updated just like after 'sync', */
+     349             :         /* or if it still represents the state before the 'sync'. */
+     350             : 
+     351             :         /* Note that if the 'sync' ends normally, we don't have any DELETED, REP and CHG blocks */
+     352             :         /* and the two strategies are identical */
+     353             : 
+     354             :         /* As first, we assume that the parity IS updated for the current state */
+     355             :         /* and that we are going to recover the state after the last 'sync'. */
+     356             :         /* In this case, parity contains info from BLK, REP and CHG blocks, */
+     357             :         /* but not for DELETED. */
+     358             :         /* We need to put in the recovering process only the bad blocks, because all the */
+     359             :         /* others already contains the correct data read from disk, and the parity is correctly computed for them. */
+     360             :         /* We are interested to recover BLK, REP and CHG blocks if they are marked as bad, */
+     361             :         /* but we are not interested in DELETED ones. */
+     362             : 
+     363      282935 :         n = 0;
+     364      282935 :         something_to_recover = 0; /* keep track if there is at least one block to fix */
+     365     1006981 :         for (j = 0; j < failed_count; ++j) {
+     366      724046 :                 if (failed[j].is_bad) {
+     367      638323 :                         unsigned block_state = block_state_get(failed[j].block);
+     368             : 
+     369      638323 :                         assert(block_state != BLOCK_STATE_DELETED); /* we cannot have bad DELETED blocks */
+     370             : 
+     371             :                         /* if we have the hash for it */
+     372      638323 :                         if ((block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP)
+     373             :                                 /* try to fetch the block using the known hash */
+     374      629907 :                                 && (state_import_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0
+     375      625435 :                                         || state_search_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0)
+     376             :                         ) {
+     377             :                                 /* we already have corrected it! */
+     378       13854 :                                 log_tag("hash_import: Fixed entry %u\n", j);
+     379             :                         } else {
+     380             :                                 /* otherwise try to recover it */
+     381      624469 :                                 failed_map[n] = j;
+     382      624469 :                                 ++n;
+     383             : 
+     384             :                                 /* we have something to try to recover */
+     385      624469 :                                 something_to_recover = 1;
+     386             :                         }
+     387             :                 }
+     388             :         }
+     389             : 
+     390             :         /* if nothing to fix */
+     391      282935 :         if (!something_to_recover) {
+     392       35874 :                 log_tag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n);
+     393             : 
+     394             :                 /* recompute only the parity */
+     395       35874 :                 raid_gen(diskmax, state->level, state->block_size, buffer);
+     396       35874 :                 return 0;
+     397             :         }
+     398             : 
+     399      247061 :         ret = repair_step(state, rehash, pos, diskmax, failed, failed_map, n, buffer, buffer_recov, buffer_zero);
+     400      247061 :         if (ret == 0) {
+     401             :                 /* reprocess the CHG blocks, for which we don't have a hash to check */
+     402             :                 /* if they were BAD we have to use some euristics to ensure that we have recovered  */
+     403             :                 /* the state after the sync. If unsure, we assume the worst case */
+     404             : 
+     405      674524 :                 for (j = 0; j < failed_count; ++j) {
+     406             :                         /* we take care only of BAD blocks we have to write back */
+     407      479693 :                         if (failed[j].is_bad) {
+     408      466179 :                                 unsigned block_state = block_state_get(failed[j].block);
+     409             : 
+     410             :                                 /* BLK and REP blocks are always OK, because at this point */
+     411             :                                 /* we have already checked their hash */
+     412      466179 :                                 if (block_state != BLOCK_STATE_CHG) {
+     413      457763 :                                         assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP);
+     414      457763 :                                         continue;
+     415             :                                 }
+     416             : 
+     417             :                                 /* for CHG blocks we have to 'guess' if they are correct or not */
+     418             : 
+     419             :                                 /* if the hash is invalid we cannot check the result */
+     420             :                                 /* this could happen if we have lost this information */
+     421             :                                 /* after an aborted sync */
+     422        8416 :                                 if (hash_is_invalid(failed[j].block->hash)) {
+     423             :                                         /* it may contain garbage */
+     424           0 :                                         failed[j].is_outofdate = 1;
+     425             : 
+     426           0 :                                         log_tag("hash_unknown: Unknown hash on entry %u\n", j);
+     427        8416 :                                 } else if (hash_is_zero(failed[j].block->hash)) {
+     428             :                                         /* if the block is not filled with 0, we are sure to have */
+     429             :                                         /* restored it to the state after the 'sync' */
+     430             :                                         /* instead, if the block is filled with 0, it could be either that the */
+     431             :                                         /* block after the sync is really filled by 0, or that */
+     432             :                                         /* we restored the block before the 'sync'. */
+     433        8416 :                                         if (memcmp(buffer[failed[j].index], buffer_zero, state->block_size) == 0) {
+     434             :                                                 /* it may contain garbage */
+     435        4205 :                                                 failed[j].is_outofdate = 1;
+     436             : 
+     437        4205 :                                                 log_tag("hash_unknown: Maybe old zero on entry %u\n", j);
+     438             :                                         }
+     439             :                                 } else {
+     440             :                                         /* if the hash is different than the previous one, we are sure to have */
+     441             :                                         /* restored it to the state after the 'sync' */
+     442             :                                         /* instead, if the hash matches, it could be either that the */
+     443             :                                         /* block after the sync has this hash, or that */
+     444             :                                         /* we restored the block before the 'sync'. */
+     445           0 :                                         if (blockcmp(state, rehash, failed[j].block, buffer[failed[j].index], buffer_zero) == 0) {
+     446             :                                                 /* it may contain garbage */
+     447           0 :                                                 failed[j].is_outofdate = 1;
+     448             : 
+     449           0 :                                                 log_tag("hash_unknown: Maybe old data on entry %u\n", j);
+     450             :                                         }
+     451             :                                 }
+     452             :                         }
+     453             :                 }
+     454             : 
+     455      194831 :                 return 0;
+     456             :         }
+     457       52230 :         if (ret > 0)
+     458        9163 :                 error += ret;
+     459             : 
+     460       52230 :         if (ret < 0)
+     461       43067 :                 log_tag("recover_sync:%u:%u: Failed with no attempts\n", pos, n);
+     462             :         else
+     463        9163 :                 log_tag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret);
+     464             : 
+     465             :         /* Now assume that the parity IS NOT updated at the current state, */
+     466             :         /* but still represent the state before the last 'sync' process. */
+     467             :         /* In this case, parity contains info from BLK, REP (old version), CHG (old version) and DELETED blocks, */
+     468             :         /* but not for REP (new version) and CHG (new version). */
+     469             :         /* We are interested to recover BLK ones marked as bad, */
+     470             :         /* but we are not interested to recover CHG (new version) and REP (new version) blocks, */
+     471             :         /* even if marked as bad, because we don't have parity for them and it's just impossible, */
+     472             :         /* and we are not interested to recover DELETED ones. */
+     473       52230 :         n = 0;
+     474       52230 :         something_to_recover = 0; /* keep track if there is at least one block to fix */
+     475       52230 :         something_unsynced = 0; /* keep track if we have some unsynced info to process */
+     476      232353 :         for (j = 0; j < failed_count; ++j) {
+     477      180123 :                 unsigned block_state = block_state_get(failed[j].block);
+     478             : 
+     479      180123 :                 if (block_state == BLOCK_STATE_DELETED
+     480      171079 :                         || block_state == BLOCK_STATE_CHG
+     481      171079 :                         || block_state == BLOCK_STATE_REP
+     482             :                 ) {
+     483             :                         /* If the block is CHG, REP or DELETED, we don't have the original content of block, */
+     484             :                         /* and we must try to recover it. */
+     485             :                         /* This apply to CHG and REP blocks even if they are not marked bad, */
+     486             :                         /* because the parity is computed with old content, and not with the new one. */
+     487             :                         /* Note that this recovering is done just to make possible to recover any other BLK one, */
+     488             :                         /* we are not really interested in DELETED, CHG (old version) and REP (old version). */
+     489        9044 :                         something_unsynced = 1;
+     490             : 
+     491        9044 :                         if (block_state == BLOCK_STATE_CHG
+     492           0 :                                 && hash_is_zero(failed[j].block->hash)
+     493             :                         ) {
+     494             :                                 /* If the block was a ZERO block, restore it to the original 0 as before the 'sync' */
+     495             :                                 /* We do this to just allow recovering of other BLK ones */
+     496             : 
+     497           0 :                                 memset(buffer[failed[j].index], 0, state->block_size);
+     498             :                                 /* note that from now the buffer is definitively lost */
+     499             :                                 /* we can do this only because it's the last retry of recovering */
+     500             : 
+     501             :                                 /* try to fetch the old block using the old hash for CHG and DELETED blocks */
+     502        9044 :                         } else if ((block_state == BLOCK_STATE_CHG || block_state == BLOCK_STATE_DELETED)
+     503        9044 :                                 && hash_is_real(failed[j].block->hash)
+     504        9044 :                                 && state_import_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0) {
+     505             : 
+     506             :                                 /* note that from now the buffer is definitively lost */
+     507             :                                 /* we can do this only because it's the last retry of recovering */
+     508             :                         } else {
+     509             :                                 /* otherwise try to recover it */
+     510        9044 :                                 failed_map[n] = j;
+     511        9044 :                                 ++n;
+     512             : 
+     513             :                                 /* note that we don't set something_to_recover, because we are */
+     514             :                                 /* not really interested to recover *only* old blocks. */
+     515             :                         }
+     516             : 
+     517             :                         /* avoid to use the hash of this block to verify the recovering */
+     518             :                         /* this applies to REP blocks because we are going to recover the old state */
+     519             :                         /* and the REP hash represent the new one */
+     520             :                         /* it also applies to CHG and DELETE blocks because we want to have */
+     521             :                         /* a succesful recovering only if a BLK one is matching */
+     522        9044 :                         failed[j].is_outofdate = 1;
+     523      171079 :                 } else if (failed[j].is_bad) {
+     524             :                         /* If the block is bad we don't know its content, and we try to recover it */
+     525             :                         /* At this point, we can have only BLK ones */
+     526             : 
+     527      171079 :                         assert(block_state == BLOCK_STATE_BLK);
+     528             : 
+     529             :                         /* we have something we are interested to recover */
+     530      171079 :                         something_to_recover = 1;
+     531             : 
+     532             :                         /* we try to recover it */
+     533      171079 :                         failed_map[n] = j;
+     534      171079 :                         ++n;
+     535             :                 }
+     536             :         }
+     537             : 
+     538             :         /* if nothing to fix, we just don't try */
+     539             :         /* if nothing unsynced we also don't retry, because it's the same try as before */
+     540       52230 :         if (something_to_recover && something_unsynced) {
+     541        9044 :                 ret = repair_step(state, rehash, pos, diskmax, failed, failed_map, n, buffer, buffer_recov, buffer_zero);
+     542        9044 :                 if (ret == 0) {
+     543             :                         /* reprocess the REP and CHG blocks, for which we have recovered and old state */
+     544             :                         /* that we don't want to save into disk */
+     545             :                         /* we have already marked them, but we redo it for logging */
+     546             : 
+     547       13566 :                         for (j = 0; j < failed_count; ++j) {
+     548             :                                 /* we take care only of BAD blocks we have to write back */
+     549        9044 :                                 if (failed[j].is_bad) {
+     550        4522 :                                         unsigned block_state = block_state_get(failed[j].block);
+     551             : 
+     552        4522 :                                         if (block_state == BLOCK_STATE_CHG
+     553        4522 :                                                 || block_state == BLOCK_STATE_REP
+     554             :                                         ) {
+     555             :                                                 /* mark that we have restored an old state */
+     556             :                                                 /* and we don't want to write it to the disk */
+     557           0 :                                                 failed[j].is_outofdate = 1;
+     558             : 
+     559           0 :                                                 log_tag("hash_unknown: Surely old data on entry %u\n", j);
+     560             :                                         }
+     561             :                                 }
+     562             :                         }
+     563             : 
+     564        4522 :                         return 0;
+     565             :                 }
+     566        4522 :                 if (ret > 0)
+     567           0 :                         error += ret;
+     568             : 
+     569        9044 :                 if (ret < 0)
+     570        4522 :                         log_tag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n);
+     571             :                 else
+     572           0 :                         log_tag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret);
+     573             :         } else {
+     574       43186 :                 log_tag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n,
+     575             :                         !something_to_recover ? " nothing to recover" : "",
+     576             :                         !something_unsynced ? " nothing unsynched" : ""
+     577             :                 );
+     578             :         }
+     579             : 
+     580             :         /* return the number of failed attempts, or -1 if no strategy */
+     581       47708 :         if (error)
+     582        4641 :                 return error;
+     583             :         else
+     584       43067 :                 return -1;
+     585             : }
+     586             : 
+     587             : /**
+     588             :  * Post process all the files at the specified block index ::i.
+     589             :  * For each file, if we are at the last block, closes it,
+     590             :  * adjust the timestamp, and prints the result.
+     591             :  */
+     592      933330 : static int file_post(struct snapraid_state* state, int fix, unsigned i, struct snapraid_handle* handle, unsigned diskmax)
+     593             : {
+     594             :         unsigned j;
+     595             :         int ret;
+     596             : 
+     597             :         /* for all the files prints the final status, and does the final time fix */
+     598             :         /* we also ensure to close files after processing the last block */
+     599     6533310 :         for (j = 0; j < diskmax; ++j) {
+     600             :                 struct snapraid_block* block;
+     601             :                 struct snapraid_disk* disk;
+     602             :                 struct snapraid_file* collide_file;
+     603             :                 struct snapraid_file* file;
+     604             :                 char path[PATH_MAX];
+     605             :                 uint64_t inode;
+     606             : 
+     607     5599980 :                 disk = handle[j].disk;
+     608     5599980 :                 if (!disk) {
+     609             :                         /* if no disk, nothing to do */
+     610     3430290 :                         continue;
+     611             :                 }
+     612             : 
+     613     5585967 :                 block = disk_block_get(disk, i);
+     614     5585967 :                 if (!block_has_file(block)) {
+     615             :                         /* if no file, nothing to do */
+     616      210457 :                         continue;
+     617             :                 }
+     618             : 
+     619     5375510 :                 file = block_file_get(block);
+     620     5375510 :                 pathprint(path, sizeof(path), "%s%s", disk->dir, file->sub);
+     621             : 
+     622             :                 /* if it isn't the last block in the file */
+     623     5375510 :                 if (!block_is_last(block)) {
+     624             :                         /* nothing to do */
+     625     3191807 :                         continue;
+     626             :                 }
+     627             : 
+     628             :                 /* if the file is excluded, we have nothing to adjust as the file is never written */
+     629     2183703 :                 if (file_flag_has(file, FILE_IS_EXCLUDED)
+     630     2086038 :                         || (state->opt.syncedonly && file_flag_has(file, FILE_IS_UNSYNCED))) {
+     631             :                         /* nothing to do, but close the file */
+     632             :                         goto close_and_continue;
+     633             :                 }
+     634             : 
+     635             :                 /* if the file is opened and not excluded, it must be the correct one */
+     636             :                 /* or at least pointing to NULL, in case it cannot be opened. */
+     637     2086038 :                 if (handle[j].file != 0 && handle[j].file != file) {
+     638             :                         /* LCOV_EXCL_START */
+     639             :                         log_fatal("Internal inconsistency in opened file for block %u\n", block->parity_pos);
+     640             :                         exit(EXIT_FAILURE);
+     641             :                         /* LCOV_EXCL_STOP */
+     642             :                 }
+     643             : 
+     644             :                 /* finish the fix process if it's the last block of the files */
+     645     2086038 :                 if (fix) {
+     646             :                         /* mark that we finished with this file */
+     647             :                         /* to identify later any NOT finished ones */
+     648      767408 :                         file_flag_set(file, FILE_IS_FINISHED);
+     649             : 
+     650             :                         /* if the file is damaged, meaning that a fix failed */
+     651      767408 :                         if (file_flag_has(file, FILE_IS_DAMAGED)) {
+     652             :                                 /* rename it to .unrecoverable */
+     653             :                                 char path_to[PATH_MAX];
+     654             : 
+     655       64977 :                                 pathprint(path_to, sizeof(path_to), "%s%s.unrecoverable", disk->dir, file->sub);
+     656             : 
+     657             :                                 /* ensure to close the file before renaming */
+     658       64977 :                                 ret = handle_close(&handle[j]);
+     659       64977 :                                 if (ret != 0) {
+     660             :                                         /* LCOV_EXCL_START */
+     661             :                                         log_fatal("Error closing '%s'. %s.\n", path, strerror(errno));
+     662             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+     663             :                                         return -1;
+     664             :                                         /* LCOV_EXCL_STOP */
+     665             :                                 }
+     666             : 
+     667       64977 :                                 ret = rename(path, path_to);
+     668       64977 :                                 if (ret != 0) {
+     669             :                                         /* LCOV_EXCL_START */
+     670             :                                         log_fatal("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno));
+     671             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+     672             :                                         return -1;
+     673             :                                         /* LCOV_EXCL_STOP */
+     674             :                                 }
+     675             : 
+     676       64977 :                                 log_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
+     677       64977 :                                 msg_info("unrecoverable %s\n", path);
+     678             : 
+     679             :                                 /* and do not set the time if damaged */
+     680       64977 :                                 goto close_and_continue;
+     681             :                         }
+     682             : 
+     683             :                         /* if the file is not fixed, meaning that it is untouched */
+     684      702431 :                         if (!file_flag_has(file, FILE_IS_FIXED)) {
+     685             :                                 /* nothing to do, but close the file */
+     686      582821 :                                 goto close_and_continue;
+     687             :                         }
+     688             : 
+     689      119610 :                         log_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
+     690      119610 :                         msg_info("recovered %s\n", path);
+     691             : 
+     692      119610 :                         inode = handle[j].st.st_ino;
+     693             : 
+     694             :                         /* search for the corresponding inode */
+     695      119610 :                         collide_file = tommy_hashdyn_search(&disk->inodeset, file_inode_compare_to_arg, &inode, file_inode_hash(inode));
+     696             : 
+     697             :                         /* if the inode is already in the database and it refers at a different file name, */
+     698             :                         /* we can fix the file time ONLY if the time and size allow to differentiate */
+     699             :                         /* between the two files */
+     700             : 
+     701             :                         /* for example, suppose we delete a bunch of files with all the same size and time, */
+     702             :                         /* when recreating them the inodes may be reused in a different order, */
+     703             :                         /* and at the next sync some files may have matching inode/size/time even if different name */
+     704             :                         /* not allowing sync to detect that the file is changed and not renamed */
+     705      119610 :                         if (!collide_file /* if not in the database, there is no collision */
+     706       37284 :                                 || strcmp(collide_file->sub, file->sub) == 0 /* if the name is the same, it's the right collision */
+     707       22374 :                                 || collide_file->size != file->size /* if the size is different, the collision is identified */
+     708           1 :                                 || collide_file->mtime_sec != file->mtime_sec /* if the mtime is different, the collision is identified */
+     709           1 :                                 || collide_file->mtime_nsec != file->mtime_nsec /* same for mtime_nsec */
+     710             :                         ) {
+     711             :                                 /* set the original modification time */
+     712      119610 :                                 ret = handle_utime(&handle[j]);
+     713      239220 :                                 if (ret == -1) {
+     714             :                                         /* LCOV_EXCL_START */
+     715             :                                         /* mark the file as damaged */
+     716             :                                         file_flag_set(file, FILE_IS_DAMAGED);
+     717             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+     718             :                                         return -1;
+     719             :                                         /* LCOV_EXCL_STOP */
+     720             :                                 }
+     721             :                         } else {
+     722           0 :                                 log_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc(file->sub), esc(collide_file->sub));
+     723             :                         }
+     724             :                 } else {
+     725             :                         /* we are not fixing, but only checking */
+     726             :                         /* print just the final status */
+     727     1318630 :                         if (file_flag_has(file, FILE_IS_DAMAGED)) {
+     728        9328 :                                 if (state->opt.auditonly) {
+     729        2759 :                                         log_tag("status:damaged:%s:%s\n", disk->name, esc(file->sub));
+     730        2759 :                                         msg_info("damaged %s\n", path);
+     731             :                                 } else {
+     732        6569 :                                         log_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
+     733        6569 :                                         msg_info("unrecoverable %s\n", path);
+     734             :                                 }
+     735     1309302 :                         } else if (file_flag_has(file, FILE_IS_FIXED)) {
+     736       76455 :                                 log_tag("status:recoverable:%s:%s\n", disk->name, esc(file->sub));
+     737       76455 :                                 msg_info("recoverable %s\n", path);
+     738             :                         } else {
+     739     1232847 :                                 log_tag("status:correct:%s:%s\n", disk->name, esc(file->sub));
+     740             :                                 /* we don't use msg_verbose() because it also goes into the log */
+     741     1232847 :                                 if (msg_level >= MSG_VERBOSE)
+     742       23188 :                                         msg_info("correct %s\n", path);
+     743             :                         }
+     744             :                 }
+     745             : 
+     746             : close_and_continue:
+     747             :                 /* if the opened file is the correct one, close it */
+     748             :                 /* in case of excluded and fragmented files it's possible */
+     749             :                 /* that the opened file is not the current one */
+     750     2183703 :                 if (handle[j].file == file) {
+     751             :                         /* ensure to close the file just after finishing with it */
+     752     1986275 :                         ret = handle_close(&handle[j]);
+     753     1986275 :                         if (ret != 0) {
+     754             :                                 /* LCOV_EXCL_START */
+     755             :                                 log_fatal("Error closing '%s'. %s.\n", path, strerror(errno));
+     756             :                                 log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+     757             :                                 return -1;
+     758             :                                 /* LCOV_EXCL_STOP */
+     759             :                         }
+     760             :                 }
+     761             :         }
+     762             : 
+     763      933330 :         return 0;
+     764             : }
+     765             : 
+     766             : /**
+     767             :  * Check if we have to process the specified block index ::i.
+     768             :  */
+     769     1866660 : static int block_is_enabled(struct snapraid_state* state, block_off_t i, struct snapraid_handle* handle, unsigned diskmax)
+     770             : {
+     771             :         int one_tocheck;
+     772             :         snapraid_info info;
+     773             :         unsigned j;
+     774             : 
+     775             :         /* get block specific info */
+     776     1866660 :         info = info_get(&state->infoarr, i);
+     777             : 
+     778             :         /* if we filter for only bad blocks */
+     779     1866660 :         if (state->opt.badonly) {
+     780             :                 /* skip if this is not bad */
+     781       18684 :                 if (!info_get_bad(info))
+     782       15078 :                         return 0;
+     783             :         }
+     784             : 
+     785             :         /* for each disk */
+     786     1851582 :         one_tocheck = 0;
+     787     2299380 :         for (j = 0; j < diskmax; ++j) {
+     788             :                 struct snapraid_block* block;
+     789             : 
+     790             :                 /* if no disk, nothing to check */
+     791     2264338 :                 if (!handle[j].disk)
+     792         708 :                         continue;
+     793             : 
+     794     2263630 :                 block = disk_block_get(handle[j].disk, i);
+     795             : 
+     796             :                 /* try to recover all files, even the ones without hash */
+     797             :                 /* because in some cases we can recover also them */
+     798     2263630 :                 if (block_has_file(block)
+     799     2111788 :                         && !file_flag_has(block_file_get(block), FILE_IS_EXCLUDED) /* only if the file is not filtered out */
+     800             :                 ) {
+     801     1816540 :                         one_tocheck = 1;
+     802     1816540 :                         break;
+     803             :                 }
+     804             :         }
+     805             : 
+     806             :         /* if no block to check skip */
+     807     1851582 :         if (!one_tocheck)
+     808       35042 :                 return 0;
+     809             : 
+     810     1816540 :         return 1;
+     811             : }
+     812             : 
+     813         118 : static int state_check_process(struct snapraid_state* state, int fix, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax)
+     814             : {
+     815             :         struct snapraid_handle* handle;
+     816             :         unsigned diskmax;
+     817             :         block_off_t i;
+     818             :         unsigned j;
+     819             :         void* buffer_alloc;
+     820             :         void** buffer;
+     821             :         unsigned buffermax;
+     822             :         int ret;
+     823             :         data_off_t countsize;
+     824             :         block_off_t countpos;
+     825             :         block_off_t countmax;
+     826             :         unsigned error;
+     827             :         unsigned unrecoverable_error;
+     828             :         unsigned recovered_error;
+     829             :         struct failed_struct* failed;
+     830             :         unsigned* failed_map;
+     831             :         unsigned l;
+     832             : 
+     833         118 :         handle = handle_map(state, &diskmax);
+     834             : 
+     835             :         /* we need 1 * data + 2 * parity + 1 * zero */
+     836         118 :         buffermax = diskmax + 2 * state->level + 1;
+     837             : 
+     838         118 :         buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc);
+     839         118 :         if (!state->opt.skip_self)
+     840           0 :                 mtest_vector(buffermax, state->block_size, buffer);
+     841             : 
+     842             :         /* fill up the zero buffer */
+     843         118 :         memset(buffer[buffermax - 1], 0, state->block_size);
+     844         118 :         raid_zero(buffer[buffermax - 1]);
+     845             : 
+     846         118 :         failed = malloc_nofail(diskmax * sizeof(struct failed_struct));
+     847         118 :         failed_map = malloc_nofail(diskmax * sizeof(unsigned));
+     848             : 
+     849         118 :         error = 0;
+     850         118 :         unrecoverable_error = 0;
+     851         118 :         recovered_error = 0;
+     852             : 
+     853             :         /* first count the number of blocks to process */
+     854         118 :         countmax = 0;
+     855      933448 :         for (i = blockstart; i < blockmax; ++i) {
+     856      933330 :                 if (!block_is_enabled(state, i, handle, diskmax))
+     857       25060 :                         continue;
+     858      908270 :                 ++countmax;
+     859             :         }
+     860             : 
+     861             :         /* check all the blocks in files */
+     862         118 :         countsize = 0;
+     863         118 :         countpos = 0;
+     864         118 :         state_progress_begin(state, blockstart, blockmax, countmax);
+     865      933448 :         for (i = blockstart; i < blockmax; ++i) {
+     866             :                 unsigned failed_count;
+     867             :                 int valid_parity;
+     868             :                 snapraid_info info;
+     869             :                 int rehash;
+     870             : 
+     871      933330 :                 if (!block_is_enabled(state, i, handle, diskmax)) {
+     872             :                         /* post process the files */
+     873       25060 :                         ret = file_post(state, fix, i, handle, diskmax);
+     874       25060 :                         if (ret == -1) {
+     875           0 :                                 log_fatal("Stopping at block %u\n", i);
+     876           0 :                                 ++unrecoverable_error;
+     877           0 :                                 goto bail;
+     878             :                         }
+     879             : 
+     880             :                         /* and now continue with the next block */
+     881       25060 :                         continue;
+     882             :                 }
+     883             : 
+     884             :                 /* If we have valid parity, and it makes sense to check its content. */
+     885             :                 /* If we already know that the parity is invalid, we just read the file */
+     886             :                 /* but we don't report parity errors */
+     887             :                 /* Note that with auditonly, we anyway skip the full parity check, */
+     888             :                 /* because we also don't read it at all */
+     889      908270 :                 valid_parity = 1;
+     890             : 
+     891             :                 /* keep track of the number of failed blocks */
+     892      908270 :                 failed_count = 0;
+     893             : 
+     894             :                 /* get block specific info */
+     895      908270 :                 info = info_get(&state->infoarr, i);
+     896             : 
+     897             :                 /* if we have to use the old hash */
+     898      908270 :                 rehash = info_get_rehash(info);
+     899             : 
+     900             :                 /* for each disk, process the block */
+     901     6357890 :                 for (j = 0; j < diskmax; ++j) {
+     902             :                         int read_size;
+     903             :                         unsigned char hash[HASH_SIZE];
+     904             :                         struct snapraid_disk* disk;
+     905             :                         struct snapraid_block* block;
+     906             :                         struct snapraid_file* file;
+     907             :                         unsigned block_state;
+     908             : 
+     909             :                         /* if the disk position is not used */
+     910     5449620 :                         disk = handle[j].disk;
+     911     5449620 :                         if (!disk) {
+     912             :                                 /* use an empty block */
+     913       14013 :                                 memset(buffer[j], 0, state->block_size);
+     914      946594 :                                 continue;
+     915             :                         }
+     916             : 
+     917             :                         /* if the disk block is not used */
+     918     5435607 :                         block = disk_block_get(disk, i);
+     919     5435607 :                         if (block == BLOCK_EMPTY) {
+     920             :                                 /* use an empty block */
+     921      188750 :                                 memset(buffer[j], 0, state->block_size);
+     922      188750 :                                 continue;
+     923             :                         }
+     924             : 
+     925             :                         /* get the state of the block */
+     926     5246857 :                         block_state = block_state_get(block);
+     927             : 
+     928             :                         /* if the parity is not valid */
+     929     5246857 :                         if (block_has_invalid_parity(block)) {
+     930             :                                 /* mark the parity as invalid, and don't try to check/fix it */
+     931             :                                 /* because it will be recomputed at the next sync */
+     932       94577 :                                 valid_parity = 0;
+     933             :                                 /* follow */
+     934             :                         }
+     935             : 
+     936             :                         /* if the block is DELETED */
+     937     5246857 :                         if (block_state == BLOCK_STATE_DELETED) {
+     938             :                                 /* use an empty block */
+     939       18454 :                                 memset(buffer[j], 0, state->block_size);
+     940             : 
+     941             :                                 /* store it in the failed set, because potentially */
+     942             :                                 /* the parity may be still computed with the previous content */
+     943       18454 :                                 failed[failed_count].is_bad = 0;
+     944       18454 :                                 failed[failed_count].is_outofdate = 0;
+     945       18454 :                                 failed[failed_count].index = j;
+     946       18454 :                                 failed[failed_count].block = block;
+     947       18454 :                                 failed[failed_count].handle = 0;
+     948       18454 :                                 ++failed_count;
+     949       18454 :                                 continue;
+     950             :                         }
+     951             : 
+     952             :                         /* get the file of this block */
+     953     5228403 :                         file = block_file_get(block);
+     954             : 
+     955             :                         /* if we are only hashing, we can skip excluded files and don't even read them */
+     956     5228403 :                         if (state->opt.auditonly && file_flag_has(file, FILE_IS_EXCLUDED)) {
+     957             :                                 /* use an empty block */
+     958             :                                 /* in true, this is unnecessary, becase we are not checking any parity */
+     959             :                                 /* but we keep it for completeness */
+     960           0 :                                 memset(buffer[j], 0, state->block_size);
+     961           0 :                                 continue;
+     962             :                         }
+     963             : 
+     964             :                         /* if the file is closed or different than the current one */
+     965     5228403 :                         if (handle[j].file == 0 || handle[j].file != file) {
+     966             :                                 /* close the old one, if any */
+     967     2255952 :                                 ret = handle_close(&handle[j]);
+     968     2255952 :                                 if (ret == -1) {
+     969             :                                         /* LCOV_EXCL_START */
+     970             :                                         log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n");
+     971             :                                         log_fatal("Stopping at block %u\n", i);
+     972             :                                         ++unrecoverable_error;
+     973             :                                         goto bail;
+     974             :                                         /* LCOV_EXCL_STOP */
+     975             :                                 }
+     976             : 
+     977             :                                 /* if fixing, and the file is not excluded, we must open for writing */
+     978     2255952 :                                 if (fix && !file_flag_has(file, FILE_IS_EXCLUDED)) {
+     979             :                                         /* if fixing, create the file, open for writing and resize if required */
+     980      773174 :                                         ret = handle_create(&handle[j], file, state->file_mode);
+     981      773174 :                                         if (ret == -1) {
+     982             :                                                 /* LCOV_EXCL_START */
+     983             :                                                 if (errno == EACCES) {
+     984             :                                                         log_fatal("WARNING! Please give write permission to the file.\n");
+     985             :                                                 } else {
+     986             :                                                         log_fatal("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n");
+     987             :                                                 }
+     988             :                                                 log_fatal("Stopping at block %u\n", i);
+     989             :                                                 ++unrecoverable_error;
+     990             :                                                 goto bail;
+     991             :                                                 /* LCOV_EXCL_STOP */
+     992             :                                         }
+     993             : 
+     994             :                                         /* check if the file was just created */
+     995     1546348 :                                         if (handle[j].created != 0) {
+     996             :                                                 /* if fragmented, it may be reopened, so remember that the file */
+     997             :                                                 /* was originally missing */
+     998      112974 :                                                 file_flag_set(file, FILE_IS_CREATED);
+     999             :                                         }
+    1000             :                                 } else {
+    1001             :                                         /* otherwise, open the file only for reading */
+    1002     1482778 :                                         ret = handle_open(&handle[j], file, state->file_mode,
+    1003     1482778 :                                                 log_error, state->opt.expected_missing ? log_expected : 0);
+    1004     1482778 :                                         if (ret == -1) {
+    1005             :                                                 /* save the failed block for the check/fix */
+    1006      189292 :                                                 failed[failed_count].is_bad = 1;
+    1007      189292 :                                                 failed[failed_count].is_outofdate = 0;
+    1008      189292 :                                                 failed[failed_count].index = j;
+    1009      189292 :                                                 failed[failed_count].block = block;
+    1010      189292 :                                                 failed[failed_count].handle = &handle[j];
+    1011      189292 :                                                 ++failed_count;
+    1012             : 
+    1013      189292 :                                                 log_tag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
+    1014      189292 :                                                 ++error;
+    1015      189292 :                                                 continue;
+    1016             :                                         }
+    1017             :                                 }
+    1018             : 
+    1019             :                                 /* if it's the first open, and not excluded */
+    1020     2066660 :                                 if (!file_flag_has(file, FILE_IS_OPENED)
+    1021     2051280 :                                         && !file_flag_has(file, FILE_IS_EXCLUDED)) {
+    1022             : 
+    1023             :                                         /* check if the file is changed */
+    1024     2011179 :                                         if (handle[j].st.st_size != block_file_get(block)->size
+    1025     1818097 :                                                 || handle[j].st.st_mtime != block_file_get(block)->mtime_sec
+    1026     1795473 :                                                 || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec
+    1027             :                                                 /* don't check the inode to support filesystem without persistent inodes */
+    1028             :                                         ) {
+    1029             :                                                 /* report that the file is not synced */
+    1030      215706 :                                                 file_flag_set(file, FILE_IS_UNSYNCED);
+    1031             :                                         }
+    1032             :                                 }
+    1033             : 
+    1034             :                                 /* if it's the first open, and not excluded and larger */
+    1035     2066660 :                                 if (!file_flag_has(file, FILE_IS_OPENED)
+    1036     2051280 :                                         && !file_flag_has(file, FILE_IS_EXCLUDED)
+    1037     2011179 :                                         && !(state->opt.syncedonly && file_flag_has(file, FILE_IS_UNSYNCED))
+    1038     2011179 :                                         && handle[j].st.st_size > file->size
+    1039             :                                 ) {
+    1040        8665 :                                         log_error("File '%s' is larger than expected.\n", handle[j].path);
+    1041        8665 :                                         log_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc(file->sub));
+    1042        8665 :                                         ++error;
+    1043             : 
+    1044        8665 :                                         if (fix) {
+    1045        3195 :                                                 ret = handle_truncate(&handle[j], file);
+    1046        3195 :                                                 if (ret == -1) {
+    1047             :                                                         /* LCOV_EXCL_START */
+    1048             :                                                         log_fatal("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n");
+    1049             :                                                         log_fatal("Stopping at block %u\n", i);
+    1050             :                                                         ++unrecoverable_error;
+    1051             :                                                         goto bail;
+    1052             :                                                         /* LCOV_EXCL_STOP */
+    1053             :                                                 }
+    1054             : 
+    1055        3195 :                                                 log_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc(file->sub));
+    1056        3195 :                                                 ++recovered_error;
+    1057             :                                         }
+    1058             :                                 }
+    1059             : 
+    1060             :                                 /* mark the file as opened at least one time */
+    1061             :                                 /* this is used to avoid to check the unsynced and size */
+    1062             :                                 /* more than one time, in case the file is reopened later */
+    1063     2066660 :                                 file_flag_set(file, FILE_IS_OPENED);
+    1064             :                         }
+    1065             : 
+    1066             :                         /* read from the file */
+    1067     5039111 :                         read_size = handle_read(&handle[j], block, buffer[j], state->block_size,
+    1068     5039111 :                                 log_error, state->opt.expected_missing ? log_expected : 0);
+    1069     5039111 :                         if (read_size == -1) {
+    1070             :                                 /* save the failed block for the check/fix */
+    1071      442133 :                                 failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */
+    1072      442133 :                                 failed[failed_count].is_outofdate = 0;
+    1073      442133 :                                 failed[failed_count].index = j;
+    1074      442133 :                                 failed[failed_count].block = block;
+    1075      442133 :                                 failed[failed_count].handle = &handle[j];
+    1076      442133 :                                 ++failed_count;
+    1077             : 
+    1078      442133 :                                 log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
+    1079      442133 :                                 ++error;
+    1080      442133 :                                 continue;
+    1081             :                         }
+    1082             : 
+    1083     4596978 :                         countsize += read_size;
+    1084             : 
+    1085             :                         /* always insert CHG blocks, the repair functions needs all of them */
+    1086             :                         /* because the parity may be still referring at the old state */
+    1087             :                         /* and the repair must be aware of it */
+    1088     4596978 :                         if (block_state == BLOCK_STATE_CHG) {
+    1089             :                                 /* we DO NOT mark them as bad to avoid to overwrite them with wrong data. */
+    1090             :                                 /* if we don't have a hash, we always assume the first read of the block correct. */
+    1091       43695 :                                 failed[failed_count].is_bad = 0; /* we assume the CHG block correct */
+    1092       43695 :                                 failed[failed_count].is_outofdate = 0;
+    1093       43695 :                                 failed[failed_count].index = j;
+    1094       43695 :                                 failed[failed_count].block = block;
+    1095       43695 :                                 failed[failed_count].handle = &handle[j];
+    1096       43695 :                                 ++failed_count;
+    1097       43695 :                                 continue;
+    1098             :                         }
+    1099             : 
+    1100     4553283 :                         assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP);
+    1101             : 
+    1102             :                         /* compute the hash of the block just read */
+    1103     4553283 :                         if (rehash) {
+    1104      286339 :                                 memhash(state->prevhash, state->prevhashseed, hash, buffer[j], read_size);
+    1105             :                         } else {
+    1106     4266944 :                                 memhash(state->hash, state->hashseed, hash, buffer[j], read_size);
+    1107             :                         }
+    1108             : 
+    1109             :                         /* compare the hash */
+    1110     4553283 :                         if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
+    1111             :                                 /* save the failed block for the check/fix */
+    1112       12670 :                                 failed[failed_count].is_bad = 1; /* it's bad because the hash doesn't match */
+    1113       12670 :                                 failed[failed_count].is_outofdate = 0;
+    1114       12670 :                                 failed[failed_count].index = j;
+    1115       12670 :                                 failed[failed_count].block = block;
+    1116       12670 :                                 failed[failed_count].handle = &handle[j];
+    1117       12670 :                                 ++failed_count;
+    1118             : 
+    1119       12670 :                                 log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
+    1120       12670 :                                 ++error;
+    1121       12670 :                                 continue;
+    1122             :                         }
+    1123             : 
+    1124             :                         /* always insert REP blocks, the repair functions needs all of them */
+    1125             :                         /* because the parity may be still referring at the old state */
+    1126             :                         /* and the repair must be aware of it */
+    1127     4540613 :                         if (block_state == BLOCK_STATE_REP) {
+    1128       23574 :                                 failed[failed_count].is_bad = 0; /* it's not bad */
+    1129       23574 :                                 failed[failed_count].is_outofdate = 0;
+    1130       23574 :                                 failed[failed_count].index = j;
+    1131       23574 :                                 failed[failed_count].block = block;
+    1132       23574 :                                 failed[failed_count].handle = &handle[j];
+    1133       23574 :                                 ++failed_count;
+    1134       23574 :                                 continue;
+    1135             :                         }
+    1136             :                 }
+    1137             : 
+    1138             :                 /* now read and check the parity if requested */
+    1139      908270 :                 if (!state->opt.auditonly) {
+    1140             :                         void* buffer_recov[LEV_MAX];
+    1141             :                         void* buffer_zero;
+    1142             : 
+    1143             :                         /* buffers for parity read and not computed */
+    1144     4138380 :                         for (l = 0; l < state->level; ++l)
+    1145     3269287 :                                 buffer_recov[l] = buffer[diskmax + state->level + l];
+    1146     2814364 :                         for (; l < LEV_MAX; ++l)
+    1147     1945271 :                                 buffer_recov[l] = 0;
+    1148             : 
+    1149             :                         /* the zero buffer is the last one */
+    1150      869093 :                         buffer_zero = buffer[buffermax - 1];
+    1151             : 
+    1152             :                         /* read the parity */
+    1153     4138380 :                         for (l = 0; l < state->level; ++l) {
+    1154     3269287 :                                 if (parity[l]) {
+    1155     3260088 :                                         ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, log_error);
+    1156     3260088 :                                         if (ret == -1) {
+    1157       90270 :                                                 buffer_recov[l] = 0; /* no parity to use */
+    1158             : 
+    1159       90270 :                                                 log_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l));
+    1160       90270 :                                                 ++error;
+    1161             :                                         }
+    1162             :                                 } else {
+    1163        9199 :                                         buffer_recov[l] = 0;
+    1164             :                                 }
+    1165             :                         }
+    1166             : 
+    1167             :                         /* try all the recovering strategies */
+    1168      869093 :                         ret = repair(state, rehash, i, diskmax, failed, failed_map, failed_count, buffer, buffer_recov, buffer_zero);
+    1169      869093 :                         if (ret != 0) {
+    1170             :                                 /* increment the number of errors */
+    1171       47708 :                                 if (ret > 0)
+    1172        4641 :                                         error += ret;
+    1173       47708 :                                 ++unrecoverable_error;
+    1174             : 
+    1175             :                                 /* print a list of all the errors in files */
+    1176      218787 :                                 for (j = 0; j < failed_count; ++j) {
+    1177      171079 :                                         if (failed[j].is_bad)
+    1178      166557 :                                                 log_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
+    1179             :                                 }
+    1180             : 
+    1181             :                                 /* keep track of damaged files */
+    1182      218787 :                                 for (j = 0; j < failed_count; ++j) {
+    1183      171079 :                                         if (failed[j].is_bad)
+    1184      166557 :                                                 file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED);
+    1185             :                                 }
+    1186             :                         } else {
+    1187             :                                 /* now counts partial recovers */
+    1188             :                                 /* note that this could happen only when we have an incomplete 'sync' */
+    1189             :                                 /* and that we have recovered is the state before the 'sync' */
+    1190      821385 :                                 int partial_recover_error = 0;
+    1191             : 
+    1192             :                                 /* print a list of all the errors in files */
+    1193     1374352 :                                 for (j = 0; j < failed_count; ++j) {
+    1194      552967 :                                         if (failed[j].is_bad && failed[j].is_outofdate) {
+    1195        4205 :                                                 ++partial_recover_error;
+    1196        4205 :                                                 log_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
+    1197             :                                         }
+    1198             :                                 }
+    1199      821385 :                                 if (partial_recover_error != 0) {
+    1200        4205 :                                         error += partial_recover_error;
+    1201        4205 :                                         ++unrecoverable_error;
+    1202             :                                 }
+    1203             : 
+    1204             :                                 /* now check parities, but only if all the blocks have it computed */
+    1205             :                                 /* if you check/fix after a partial sync, it's OK to have parity errors on the blocks with invalid parity */
+    1206             :                                 /* and doesn't make sense to try to fix it */
+    1207      821385 :                                 if (valid_parity) {
+    1208             :                                         /* check the parity */
+    1209     3695991 :                                         for (l = 0; l < state->level; ++l) {
+    1210     2936305 :                                                 if (buffer_recov[l] != 0 && memcmp(buffer_recov[l], buffer[diskmax + l], state->block_size) != 0) {
+    1211       10631 :                                                         buffer_recov[l] = 0;
+    1212             : 
+    1213       10631 :                                                         log_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l));
+    1214       10631 :                                                         ++error;
+    1215             :                                                 }
+    1216             :                                         }
+    1217             :                                 }
+    1218             : 
+    1219             :                                 /* now writes recovered files */
+    1220      821385 :                                 if (fix) {
+    1221             :                                         /* update the fixed files */
+    1222      642366 :                                         for (j = 0; j < failed_count; ++j) {
+    1223             :                                                 /* nothing to do if it doesn't need recovering */
+    1224      332980 :                                                 if (!failed[j].is_bad)
+    1225       40318 :                                                         continue;
+    1226             : 
+    1227             :                                                 /* do not fix if the file is excluded */
+    1228      292662 :                                                 if (file_flag_has(block_file_get(failed[j].block), FILE_IS_EXCLUDED)
+    1229      288068 :                                                         || (state->opt.syncedonly && file_flag_has(block_file_get(failed[j].block), FILE_IS_UNSYNCED)))
+    1230        4594 :                                                         continue;
+    1231             : 
+    1232      288068 :                                                 ret = handle_write(failed[j].handle, failed[j].block, buffer[failed[j].index], state->block_size);
+    1233      288068 :                                                 if (ret == -1) {
+    1234             :                                                         /* LCOV_EXCL_START */
+    1235             :                                                         /* mark the file as damaged */
+    1236             :                                                         file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED);
+    1237             : 
+    1238             :                                                         if (errno == EACCES) {
+    1239             :                                                                 log_fatal("WARNING! Please give write permission to the file.\n");
+    1240             :                                                         } else {
+    1241             :                                                                 /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1242             :                                                                 log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1243             :                                                         }
+    1244             :                                                         log_fatal("Stopping at block %u\n", i);
+    1245             :                                                         ++unrecoverable_error;
+    1246             :                                                         goto bail;
+    1247             :                                                         /* LCOV_EXCL_STOP */
+    1248             :                                                 }
+    1249             : 
+    1250             :                                                 /* if we are not sure that the recovered content is uptodate */
+    1251      288068 :                                                 if (failed[j].is_outofdate) {
+    1252             :                                                         /* mark the file as damaged */
+    1253        4205 :                                                         file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED);
+    1254        4205 :                                                         continue;
+    1255             :                                                 }
+    1256             : 
+    1257             :                                                 /* mark the file as containing some fixes */
+    1258             :                                                 /* note that it could be also marked as damaged in other iterations */
+    1259      283863 :                                                 file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED);
+    1260             : 
+    1261      283863 :                                                 log_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
+    1262      283863 :                                                 ++recovered_error;
+    1263             :                                         }
+    1264             : 
+    1265             :                                         /* update parity only if all the blocks have it computed */
+    1266             :                                         /* if you check/fix after a partial sync, you do not want to fix parity */
+    1267             :                                         /* for blocks that are going to have it computed in the sync completion */
+    1268      309386 :                                         if (valid_parity) {
+    1269             :                                                 /* update the parity */
+    1270      929172 :                                                 for (l = 0; l < state->level; ++l) {
+    1271      668958 :                                                         if (buffer_recov[l] == 0 && parity[l] != 0) {
+    1272       62528 :                                                                 ret = parity_write(parity[l], i, buffer[diskmax + l], state->block_size);
+    1273       62528 :                                                                 if (ret == -1) {
+    1274             :                                                                         /* LCOV_EXCL_START */
+    1275             :                                                                         /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1276             :                                                                         log_fatal("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l));
+    1277             :                                                                         log_fatal("Stopping at block %u\n", i);
+    1278             :                                                                         ++unrecoverable_error;
+    1279             :                                                                         goto bail;
+    1280             :                                                                         /* LCOV_EXCL_STOP */
+    1281             :                                                                 }
+    1282             : 
+    1283       62528 :                                                                 log_tag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l));
+    1284       62528 :                                                                 ++recovered_error;
+    1285             :                                                         }
+    1286             :                                                 }
+    1287             :                                         }
+    1288             :                                 } else {
+    1289             :                                         /* if we are not fixing, we just set the FIXED flag */
+    1290             :                                         /* meaning that we could fix this file if we try */
+    1291      731986 :                                         for (j = 0; j < failed_count; ++j) {
+    1292      219987 :                                                 if (failed[j].is_bad) {
+    1293      179104 :                                                         file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED);
+    1294             :                                                 }
+    1295             :                                         }
+    1296             :                                 }
+    1297             :                         }
+    1298             :                 } else {
+    1299             :                         /* if we are not checking, we just set the DAMAGED flag */
+    1300             :                         /* to report that the file is damaged, and we don't know if we can fix it */
+    1301       44949 :                         for (j = 0; j < failed_count; ++j) {
+    1302        5772 :                                 if (failed[j].is_bad) {
+    1303        5772 :                                         file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED);
+    1304             :                                 }
+    1305             :                         }
+    1306             :                 }
+    1307             : 
+    1308             :                 /* post process the files */
+    1309      908270 :                 ret = file_post(state, fix, i, handle, diskmax);
+    1310      908270 :                 if (ret == -1) {
+    1311           0 :                         log_fatal("Stopping at block %u\n", i);
+    1312           0 :                         ++unrecoverable_error;
+    1313           0 :                         goto bail;
+    1314             :                 }
+    1315             : 
+    1316             :                 /* count the number of processed block */
+    1317      908270 :                 ++countpos;
+    1318             : 
+    1319             :                 /* progress */
+    1320      908270 :                 if (state_progress(state, i, countpos, countmax, countsize)) {
+    1321             :                         /* LCOV_EXCL_START */
+    1322             :                         break;
+    1323             :                         /* LCOV_EXCL_STOP */
+    1324             :                 }
+    1325             :         }
+    1326             : 
+    1327             :         /* for each disk, recover empty files, symlinks and empty dirs */
+    1328         826 :         for (i = 0; i < diskmax; ++i) {
+    1329             :                 tommy_node* node;
+    1330             :                 struct snapraid_disk* disk;
+    1331             : 
+    1332         708 :                 if (!handle[i].disk)
+    1333           3 :                         continue;
+    1334             : 
+    1335             :                 /* for each empty file in the disk */
+    1336         705 :                 disk = handle[i].disk;
+    1337         705 :                 node = disk->filelist;
+    1338     2187947 :                 while (node) {
+    1339             :                         char path[PATH_MAX];
+    1340             :                         struct stat st;
+    1341             :                         struct snapraid_file* file;
+    1342     2186537 :                         int unsuccesful = 0;
+    1343             : 
+    1344     2186537 :                         file = node->data;
+    1345     2186537 :                         node = node->next; /* next node */
+    1346             : 
+    1347             :                         /* if not empty, it's already checked and continue to the next one */
+    1348     2186537 :                         if (file->size != 0) {
+    1349     4367549 :                                 continue;
+    1350             :                         }
+    1351             : 
+    1352             :                         /* if excluded continue to the next one */
+    1353        2834 :                         if (file_flag_has(file, FILE_IS_EXCLUDED)) {
+    1354         143 :                                 continue;
+    1355             :                         }
+    1356             : 
+    1357             :                         /* stat the file */
+    1358        2691 :                         pathprint(path, sizeof(path), "%s%s", disk->dir, file->sub);
+    1359        2691 :                         ret = stat(path, &st);
+    1360        2691 :                         if (ret == -1) {
+    1361         163 :                                 unsuccesful = 1;
+    1362             : 
+    1363         163 :                                 log_error("Error stating empty file '%s'. %s.\n", path, strerror(errno));
+    1364         163 :                                 log_tag("error:%s:%s: Empty file stat error\n", disk->name, esc(file->sub));
+    1365         163 :                                 ++error;
+    1366        2528 :                         } else if (!S_ISREG(st.st_mode)) {
+    1367           0 :                                 unsuccesful = 1;
+    1368             : 
+    1369           0 :                                 log_tag("error:%s:%s: Empty file error for not regular file\n", disk->name, esc(file->sub));
+    1370           0 :                                 ++error;
+    1371        2528 :                         } else if (st.st_size != 0) {
+    1372          14 :                                 unsuccesful = 1;
+    1373             : 
+    1374          14 :                                 log_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc(file->sub), st.st_size);
+    1375          14 :                                 ++error;
+    1376             :                         }
+    1377             : 
+    1378        2691 :                         if (fix && unsuccesful) {
+    1379             :                                 int f;
+    1380             : 
+    1381             :                                 /* create the ancestor directories */
+    1382         154 :                                 ret = mkancestor(path);
+    1383         154 :                                 if (ret != 0) {
+    1384             :                                         /* LCOV_EXCL_START */
+    1385             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1386             :                                         log_fatal("Stopping\n");
+    1387             :                                         ++unrecoverable_error;
+    1388             :                                         goto bail;
+    1389             :                                         /* LCOV_EXCL_STOP */
+    1390             :                                 }
+    1391             : 
+    1392             :                                 /* create it */
+    1393             :                                 /* O_NOFOLLOW: do not follow links to ensure to open the real file */
+    1394         154 :                                 f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600);
+    1395         154 :                                 if (f == -1) {
+    1396             :                                         /* LCOV_EXCL_START */
+    1397             :                                         log_fatal("Error creating empty file '%s'. %s.\n", path, strerror(errno));
+    1398             :                                         if (errno == EACCES) {
+    1399             :                                                 log_fatal("WARNING! Please give write permission to the file.\n");
+    1400             :                                         } else {
+    1401             :                                                 /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1402             :                                                 log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1403             :                                         }
+    1404             :                                         log_fatal("Stopping\n");
+    1405             :                                         ++unrecoverable_error;
+    1406             :                                         goto bail;
+    1407             :                                         /* LCOV_EXCL_STOP */
+    1408             :                                 }
+    1409             : 
+    1410             :                                 /* set the original modification time */
+    1411         154 :                                 ret = fmtime(f, file->mtime_sec, file->mtime_nsec);
+    1412         154 :                                 if (ret != 0) {
+    1413             :                                         /* LCOV_EXCL_START */
+    1414             :                                         close(f);
+    1415             : 
+    1416             :                                         log_fatal("Error timing file '%s'. %s.\n", file->sub, strerror(errno));
+    1417             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1418             :                                         log_fatal("Stopping\n");
+    1419             :                                         ++unrecoverable_error;
+    1420             :                                         goto bail;
+    1421             :                                         /* LCOV_EXCL_STOP */
+    1422             :                                 }
+    1423             : 
+    1424             :                                 /* close it */
+    1425         154 :                                 ret = close(f);
+    1426         154 :                                 if (ret != 0) {
+    1427             :                                         /* LCOV_EXCL_START */
+    1428             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1429             :                                         log_fatal("Stopping\n");
+    1430             :                                         ++unrecoverable_error;
+    1431             :                                         goto bail;
+    1432             :                                         /* LCOV_EXCL_STOP */
+    1433             :                                 }
+    1434             : 
+    1435         154 :                                 log_tag("fixed:%s:%s: Fixed empty file\n", disk->name, esc(file->sub));
+    1436         154 :                                 ++recovered_error;
+    1437             : 
+    1438         154 :                                 log_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
+    1439         154 :                                 msg_info("recovered %s%s\n", disk->dir, file->sub);
+    1440             :                         }
+    1441             :                 }
+    1442             : 
+    1443             :                 /* for each link in the disk */
+    1444         705 :                 disk = handle[i].disk;
+    1445         705 :                 node = disk->linklist;
+    1446       71529 :                 while (node) {
+    1447             :                         char path[PATH_MAX];
+    1448             :                         char pathto[PATH_MAX];
+    1449             :                         char linkto[PATH_MAX];
+    1450             :                         struct stat st;
+    1451             :                         struct stat stto;
+    1452             :                         struct snapraid_link* link;
+    1453       70119 :                         int unsuccesful = 0;
+    1454       70119 :                         int unrecoverable = 0;
+    1455             : 
+    1456       70119 :                         link = node->data;
+    1457       70119 :                         node = node->next; /* next node */
+    1458             : 
+    1459             :                         /* if excluded continue to the next one */
+    1460       70119 :                         if (link_flag_has(link, FILE_IS_EXCLUDED)) {
+    1461        2841 :                                 continue;
+    1462             :                         }
+    1463             : 
+    1464       67278 :                         if (link_flag_has(link, FILE_IS_HARDLINK)) {
+    1465             :                                 /* stat the link */
+    1466         636 :                                 pathprint(path, sizeof(path), "%s%s", disk->dir, link->sub);
+    1467         636 :                                 ret = stat(path, &st);
+    1468         636 :                                 if (ret == -1) {
+    1469          84 :                                         unsuccesful = 1;
+    1470             : 
+    1471          84 :                                         log_error("Error stating hardlink '%s'. %s.\n", path, strerror(errno));
+    1472          84 :                                         log_tag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, esc(link->sub), esc(link->linkto));
+    1473          84 :                                         ++error;
+    1474         552 :                                 } else if (!S_ISREG(st.st_mode)) {
+    1475           0 :                                         unsuccesful = 1;
+    1476             : 
+    1477           0 :                                         log_tag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
+    1478           0 :                                         ++error;
+    1479             :                                 }
+    1480             : 
+    1481             :                                 /* stat the "to" file */
+    1482         636 :                                 pathprint(pathto, sizeof(pathto), "%s%s", disk->dir, link->linkto);
+    1483         636 :                                 ret = stat(pathto, &stto);
+    1484         636 :                                 if (ret == -1) {
+    1485          52 :                                         unsuccesful = 1;
+    1486             : 
+    1487          52 :                                         if (errno == ENOENT) {
+    1488          52 :                                                 unrecoverable = 1;
+    1489          52 :                                                 if (fix) {
+    1490             :                                                         /* if the target doesn't exist, it's unrecoverable */
+    1491             :                                                         /* because we cannot create an hardlink of a file that */
+    1492             :                                                         /* doesn't exists */
+    1493          26 :                                                         ++unrecoverable_error;
+    1494             :                                                 } else {
+    1495             :                                                         /* but in check, we can assume that fixing will recover */
+    1496             :                                                         /* such missing file, so we assume a less drastic error */
+    1497          26 :                                                         ++error;
+    1498             :                                                 }
+    1499             :                                         }
+    1500             : 
+    1501          52 :                                         log_error("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno));
+    1502          52 :                                         log_tag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, esc(link->sub), esc(link->linkto));
+    1503          52 :                                         ++error;
+    1504         584 :                                 } else if (!S_ISREG(stto.st_mode)) {
+    1505           0 :                                         unsuccesful = 1;
+    1506             : 
+    1507           0 :                                         log_tag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
+    1508           0 :                                         ++error;
+    1509         584 :                                 } else if (!unsuccesful && st.st_ino != stto.st_ino) {
+    1510           0 :                                         unsuccesful = 1;
+    1511             : 
+    1512           0 :                                         log_error("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto);
+    1513           0 :                                         log_tag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc(link->sub), esc(link->linkto));
+    1514           0 :                                         ++error;
+    1515             :                                 }
+    1516             :                         } else {
+    1517             :                                 /* read the symlink */
+    1518       66642 :                                 pathprint(path, sizeof(path), "%s%s", disk->dir, link->sub);
+    1519       66642 :                                 ret = readlink(path, linkto, sizeof(linkto));
+    1520       66642 :                                 if (ret < 0) {
+    1521        4333 :                                         unsuccesful = 1;
+    1522             : 
+    1523        4333 :                                         log_error("Error reading symlink '%s'. %s.\n", path, strerror(errno));
+    1524        4333 :                                         log_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
+    1525        4333 :                                         ++error;
+    1526       62309 :                                 } else if (ret >= PATH_MAX) {
+    1527           0 :                                         unsuccesful = 1;
+    1528             : 
+    1529           0 :                                         log_error("Error reading symlink '%s'. Symlink too long.\n", path);
+    1530           0 :                                         log_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
+    1531           0 :                                         ++error;
+    1532             :                                 } else {
+    1533       62309 :                                         linkto[ret] = 0;
+    1534             : 
+    1535       62309 :                                         if (strcmp(linkto, link->linkto) != 0) {
+    1536         491 :                                                 unsuccesful = 1;
+    1537             : 
+    1538         491 :                                                 log_tag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc(link->sub), linkto, link->linkto);
+    1539         491 :                                                 ++error;
+    1540             :                                         }
+    1541             :                                 }
+    1542             :                         }
+    1543             : 
+    1544       67278 :                         if (fix && unsuccesful && !unrecoverable) {
+    1545             :                                 /* create the ancestor directories */
+    1546        3950 :                                 ret = mkancestor(path);
+    1547        3950 :                                 if (ret != 0) {
+    1548             :                                         /* LCOV_EXCL_START */
+    1549             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1550             :                                         log_fatal("Stopping\n");
+    1551             :                                         ++unrecoverable_error;
+    1552             :                                         goto bail;
+    1553             :                                         /* LCOV_EXCL_STOP */
+    1554             :                                 }
+    1555             : 
+    1556             :                                 /* if it exists, it must be deleted before recreating */
+    1557        3950 :                                 ret = remove(path);
+    1558        3950 :                                 if (ret != 0 && errno != ENOENT) {
+    1559             :                                         /* LCOV_EXCL_START */
+    1560             :                                         log_fatal("Error removing '%s'. %s.\n", path, strerror(errno));
+    1561             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1562             :                                         log_fatal("Stopping\n");
+    1563             :                                         ++unrecoverable_error;
+    1564             :                                         goto bail;
+    1565             :                                         /* LCOV_EXCL_STOP */
+    1566             :                                 }
+    1567             : 
+    1568             :                                 /* create it */
+    1569        3950 :                                 if (link_flag_has(link, FILE_IS_HARDLINK)) {
+    1570          32 :                                         ret = hardlink(pathto, path);
+    1571          32 :                                         if (ret != 0) {
+    1572             :                                                 /* LCOV_EXCL_START */
+    1573             :                                                 log_fatal("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno));
+    1574             :                                                 if (errno == EACCES) {
+    1575             :                                                         log_fatal("WARNING! Please give write permission to the hardlink.\n");
+    1576             :                                                 } else {
+    1577             :                                                         /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1578             :                                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1579             :                                                 }
+    1580             :                                                 log_fatal("Stopping\n");
+    1581             :                                                 ++unrecoverable_error;
+    1582             :                                                 goto bail;
+    1583             :                                                 /* LCOV_EXCL_STOP */
+    1584             :                                         }
+    1585             : 
+    1586          32 :                                         log_tag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, esc(link->sub));
+    1587          32 :                                         ++recovered_error;
+    1588             :                                 } else {
+    1589        3918 :                                         ret = symlink(link->linkto, path);
+    1590        3918 :                                         if (ret != 0) {
+    1591             :                                                 /* LCOV_EXCL_START */
+    1592             :                                                 log_fatal("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno));
+    1593             :                                                 if (errno == EACCES) {
+    1594             :                                                         log_fatal("WARNING! Please give write permission to the symlink.\n");
+    1595             :                                                 } else {
+    1596             :                                                         /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1597             :                                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1598             :                                                 }
+    1599             :                                                 log_fatal("Stopping\n");
+    1600             :                                                 ++unrecoverable_error;
+    1601             :                                                 goto bail;
+    1602             :                                                 /* LCOV_EXCL_STOP */
+    1603             :                                         }
+    1604             : 
+    1605        3918 :                                         log_tag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, esc(link->sub));
+    1606        3918 :                                         ++recovered_error;
+    1607             :                                 }
+    1608             : 
+    1609        3950 :                                 log_tag("status:recovered:%s:%s\n", disk->name, esc(link->sub));
+    1610        3950 :                                 msg_info("recovered %s%s\n", disk->dir, link->sub);
+    1611             :                         }
+    1612             :                 }
+    1613             : 
+    1614             :                 /* for each dir in the disk */
+    1615         705 :                 disk = handle[i].disk;
+    1616         705 :                 node = disk->dirlist;
+    1617        1850 :                 while (node) {
+    1618             :                         char path[PATH_MAX];
+    1619             :                         struct stat st;
+    1620             :                         struct snapraid_dir* dir;
+    1621         440 :                         int unsuccesful = 0;
+    1622             : 
+    1623         440 :                         dir = node->data;
+    1624         440 :                         node = node->next; /* next node */
+    1625             : 
+    1626             :                         /* if excluded continue to the next one */
+    1627         440 :                         if (dir_flag_has(dir, FILE_IS_EXCLUDED)) {
+    1628           8 :                                 continue;
+    1629             :                         }
+    1630             : 
+    1631             :                         /* stat the dir */
+    1632         432 :                         pathprint(path, sizeof(path), "%s%s", disk->dir, dir->sub);
+    1633         432 :                         ret = stat(path, &st);
+    1634         432 :                         if (ret == -1) {
+    1635          23 :                                 unsuccesful = 1;
+    1636             : 
+    1637          23 :                                 log_error("Error stating dir '%s'. %s.\n", path, strerror(errno));
+    1638          23 :                                 log_tag("dir_error:%s:%s: Dir stat error\n", disk->name, esc(dir->sub));
+    1639          23 :                                 ++error;
+    1640         409 :                         } else if (!S_ISDIR(st.st_mode)) {
+    1641           0 :                                 unsuccesful = 1;
+    1642             : 
+    1643           0 :                                 log_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc(dir->sub));
+    1644           0 :                                 ++error;
+    1645             :                         }
+    1646             : 
+    1647         432 :                         if (fix && unsuccesful) {
+    1648             :                                 /* create the ancestor directories */
+    1649          21 :                                 ret = mkancestor(path);
+    1650          21 :                                 if (ret != 0) {
+    1651             :                                         /* LCOV_EXCL_START */
+    1652             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1653             :                                         log_fatal("Stopping\n");
+    1654             :                                         ++unrecoverable_error;
+    1655             :                                         goto bail;
+    1656             :                                         /* LCOV_EXCL_STOP */
+    1657             :                                 }
+    1658             : 
+    1659             :                                 /* create it */
+    1660          21 :                                 ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+    1661          21 :                                 if (ret != 0) {
+    1662             :                                         /* LCOV_EXCL_START */
+    1663             :                                         log_fatal("Error creating dir '%s'. %s.\n", path, strerror(errno));
+    1664             :                                         if (errno == EACCES) {
+    1665             :                                                 log_fatal("WARNING! Please give write permission to the dir.\n");
+    1666             :                                         } else {
+    1667             :                                                 /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
+    1668             :                                                 log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1669             :                                         }
+    1670             :                                         log_fatal("Stopping\n");
+    1671             :                                         ++unrecoverable_error;
+    1672             :                                         goto bail;
+    1673             :                                         /* LCOV_EXCL_STOP */
+    1674             :                                 }
+    1675             : 
+    1676          21 :                                 log_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc(dir->sub));
+    1677          21 :                                 ++recovered_error;
+    1678             : 
+    1679          21 :                                 log_tag("status:recovered:%s:%s\n", disk->name, esc(dir->sub));
+    1680          21 :                                 msg_info("recovered %s%s\n", disk->dir, dir->sub);
+    1681             :                         }
+    1682             :                 }
+    1683             :         }
+    1684             : 
+    1685         118 :         state_progress_end(state, countpos, countmax, countsize);
+    1686             : 
+    1687             : bail:
+    1688             :         /* close all the files left open */
+    1689         826 :         for (j = 0; j < diskmax; ++j) {
+    1690         708 :                 ret = handle_close(&handle[j]);
+    1691         708 :                 if (ret == -1) {
+    1692             :                         /* LCOV_EXCL_START */
+    1693             :                         log_fatal("DANGER! Unexpected close error in a data disk.\n");
+    1694             :                         ++unrecoverable_error;
+    1695             :                         /* continue, as we are already exiting */
+    1696             :                         /* LCOV_EXCL_STOP */
+    1697             :                 }
+    1698             :         }
+    1699             : 
+    1700             :         /* remove all the files created from scratch that have not finished the processing */
+    1701             :         /* it happens only when aborting pressing Ctrl+C or other reason. */
+    1702         118 :         if (fix) {
+    1703             :                 /* for each disk */
+    1704         308 :                 for (i = 0; i < diskmax; ++i) {
+    1705             :                         tommy_node* node;
+    1706             :                         struct snapraid_disk* disk;
+    1707             : 
+    1708         264 :                         if (!handle[i].disk)
+    1709           1 :                                 continue;
+    1710             : 
+    1711             :                         /* for each file in the disk */
+    1712         263 :                         disk = handle[i].disk;
+    1713         263 :                         node = disk->filelist;
+    1714      859122 :                         while (node) {
+    1715             :                                 char path[PATH_MAX];
+    1716             :                                 struct snapraid_file* file;
+    1717             : 
+    1718      858596 :                                 file = node->data;
+    1719      858596 :                                 node = node->next; /* next node */
+    1720             : 
+    1721             :                                 /* if the file was not created, meaning that it was already existing */
+    1722      858596 :                                 if (!file_flag_has(file, FILE_IS_CREATED)) {
+    1723             :                                         /* nothing to do */
+    1724     1604218 :                                         continue;
+    1725             :                                 }
+    1726             : 
+    1727             :                                 /* if processing was finished */
+    1728      112974 :                                 if (file_flag_has(file, FILE_IS_FINISHED)) {
+    1729             :                                         /* nothing to do */
+    1730      112974 :                                         continue;
+    1731             :                                 }
+    1732             : 
+    1733             :                                 /* if the file was originally missing, and processing not yet finished */
+    1734             :                                 /* we have to throw it away  to ensure that at the next run we will retry */
+    1735             :                                 /* to fix it, in case we select to undelete missing files */
+    1736           0 :                                 pathprint(path, sizeof(path), "%s%s", disk->dir, file->sub);
+    1737             : 
+    1738           0 :                                 ret = remove(path);
+    1739           0 :                                 if (ret != 0) {
+    1740             :                                         /* LCOV_EXCL_START */
+    1741             :                                         log_fatal("Error removing '%s'. %s.\n", path, strerror(errno));
+    1742             :                                         log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
+    1743             :                                         ++unrecoverable_error;
+    1744             :                                         /* continue, as we are already exiting */
+    1745             :                                         /* LCOV_EXCL_STOP */
+    1746             :                                 }
+    1747             :                         }
+    1748             :                 }
+    1749             :         }
+    1750             : 
+    1751         118 :         if (error || recovered_error || unrecoverable_error) {
+    1752          67 :                 msg_status("\n");
+    1753          67 :                 msg_status("%8u errors\n", error);
+    1754          67 :                 if (fix) {
+    1755          43 :                         msg_status("%8u recovered errors\n", recovered_error);
+    1756             :                 }
+    1757         134 :                 if (unrecoverable_error) {
+    1758          13 :                         msg_status("%8u UNRECOVERABLE errors\n", unrecoverable_error);
+    1759             :                 } else {
+    1760             :                         /* without checking, we don't know if they are really recoverable or not */
+    1761          54 :                         if (!state->opt.auditonly)
+    1762          52 :                                 msg_status("%8u unrecoverable errors\n", unrecoverable_error);
+    1763          54 :                         if (fix)
+    1764          34 :                                 msg_status("Everything OK\n");
+    1765             :                 }
+    1766             :         } else {
+    1767          51 :                 msg_status("Everything OK\n");
+    1768             :         }
+    1769             : 
+    1770         118 :         if (error && !fix)
+    1771          24 :                 log_fatal("WARNING! There are errors!\n");
+    1772         118 :         if (unrecoverable_error)
+    1773          13 :                 log_fatal("DANGER! There are unrecoverable errors!\n");
+    1774             : 
+    1775         118 :         log_tag("summary:error:%u\n", error);
+    1776         118 :         if (fix)
+    1777          44 :                 log_tag("summary:error_recovered:%u\n", recovered_error);
+    1778         118 :         if (!state->opt.auditonly)
+    1779         113 :                 log_tag("summary:error_unrecoverable:%u\n", unrecoverable_error);
+    1780         118 :         if (fix) {
+    1781          44 :                 if (error + recovered_error + unrecoverable_error == 0)
+    1782           1 :                         log_tag("summary:exit:ok\n");
+    1783          43 :                 else if (unrecoverable_error == 0)
+    1784          34 :                         log_tag("summary:exit:recovered\n");
+    1785             :                 else
+    1786           9 :                         log_tag("summary:exit:unrecoverable\n");
+    1787          74 :         } else if (!state->opt.auditonly) {
+    1788          69 :                 if (error + unrecoverable_error == 0)
+    1789          47 :                         log_tag("summary:exit:ok\n");
+    1790          22 :                 else if (unrecoverable_error == 0)
+    1791          18 :                         log_tag("summary:exit:recoverable\n");
+    1792             :                 else
+    1793           4 :                         log_tag("summary:exit:unrecoverable\n");
+    1794             :         } else { /* audit only */
+    1795           5 :                 if (error == 0)
+    1796           3 :                         log_tag("summary:exit:ok\n");
+    1797             :                 else
+    1798           2 :                         log_tag("summary:exit:error\n");
+    1799             :         }
+    1800         118 :         log_flush();
+    1801             : 
+    1802         118 :         free(failed);
+    1803         118 :         free(failed_map);
+    1804         118 :         free(handle);
+    1805         118 :         free(buffer_alloc);
+    1806         118 :         free(buffer);
+    1807             : 
+    1808             :         /* fails if some error are present after the run */
+    1809         118 :         if (fix) {
+    1810          44 :                 if (state->opt.expect_unrecoverable) {
+    1811           9 :                         if (unrecoverable_error == 0)
+    1812           0 :                                 return -1;
+    1813             :                 } else {
+    1814          35 :                         if (unrecoverable_error != 0)
+    1815           0 :                                 return -1;
+    1816             :                 }
+    1817             :         } else {
+    1818          74 :                 if (state->opt.expect_unrecoverable) {
+    1819           4 :                         if (unrecoverable_error == 0)
+    1820           0 :                                 return -1;
+    1821          70 :                 } else if (state->opt.expect_recoverable) {
+    1822          20 :                         if (unrecoverable_error != 0 || error == 0)
+    1823           0 :                                 return -1;
+    1824             :                 } else {
+    1825          50 :                         if (error != 0 || unrecoverable_error != 0)
+    1826           0 :                                 return -1;
+    1827             :                 }
+    1828             :         }
+    1829             : 
+    1830         118 :         return 0;
+    1831             : }
+    1832             : 
+    1833         120 : int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, block_off_t blockcount)
+    1834             : {
+    1835             :         block_off_t blockmax;
+    1836             :         data_off_t size;
+    1837             :         data_off_t out_size;
+    1838             :         int ret;
+    1839             :         struct snapraid_parity_handle parity[LEV_MAX];
+    1840             :         struct snapraid_parity_handle* parity_ptr[LEV_MAX];
+    1841             :         unsigned error;
+    1842             :         unsigned l;
+    1843             : 
+    1844         120 :         msg_progress("Initializing...\n");
+    1845             : 
+    1846         120 :         blockmax = parity_allocated_size(state);
+    1847         120 :         size = blockmax * (data_off_t)state->block_size;
+    1848             : 
+    1849         120 :         if (blockstart > blockmax) {
+    1850             :                 /* LCOV_EXCL_START */
+    1851             :                 log_fatal("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax);
+    1852             :                 exit(EXIT_FAILURE);
+    1853             :                 /* LCOV_EXCL_STOP */
+    1854             :         }
+    1855             : 
+    1856             :         /* adjust the number of block to process */
+    1857         120 :         if (blockcount != 0 && blockstart + blockcount < blockmax) {
+    1858           0 :                 blockmax = blockstart + blockcount;
+    1859             :         }
+    1860             : 
+    1861         120 :         if (fix) {
+    1862             :                 /* if fixing, create the file and open for writing */
+    1863             :                 /* if it fails, we cannot continue */
+    1864         173 :                 for (l = 0; l < state->level; ++l) {
+    1865         129 :                         parity_ptr[l] = &parity[l];
+    1866         129 :                         ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode);
+    1867         129 :                         if (ret == -1) {
+    1868             :                                 /* LCOV_EXCL_START */
+    1869             :                                 log_fatal("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l));
+    1870             :                                 exit(EXIT_FAILURE);
+    1871             :                                 /* LCOV_EXCL_STOP */
+    1872             :                         }
+    1873             : 
+    1874         129 :                         ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate);
+    1875         129 :                         if (ret == -1) {
+    1876             :                                 /* LCOV_EXCL_START */
+    1877             :                                 log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
+    1878             :                                 exit(EXIT_FAILURE);
+    1879             :                                 /* LCOV_EXCL_STOP */
+    1880             :                         }
+    1881             :                 }
+    1882          76 :         } else if (!state->opt.auditonly) {
+    1883             :                 /* if checking, open the file for reading */
+    1884             :                 /* it may fail if the file doesn't exist, in this case we continue to check the files */
+    1885         395 :                 for (l = 0; l < state->level; ++l) {
+    1886         325 :                         parity_ptr[l] = &parity[l];
+    1887         325 :                         ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode);
+    1888         325 :                         if (ret == -1) {
+    1889           1 :                                 msg_status("No accessible %s file, only files will be checked.\n", lev_name(l));
+    1890             :                                 /* continue anyway */
+    1891           1 :                                 parity_ptr[l] = 0;
+    1892             :                         }
+    1893             :                 }
+    1894             :         } else {
+    1895             :                 /* otherwise don't use any parity */
+    1896          28 :                 for (l = 0; l < state->level; ++l)
+    1897          22 :                         parity_ptr[l] = 0;
+    1898             :         }
+    1899             : 
+    1900         120 :         if (fix)
+    1901          44 :                 msg_progress("Fixing...\n");
+    1902          76 :         else if (!state->opt.auditonly)
+    1903          70 :                 msg_progress("Checking...\n");
+    1904             :         else
+    1905           6 :                 msg_progress("Hashing...\n");
+    1906             : 
+    1907         120 :         error = 0;
+    1908             : 
+    1909             :         /* skip degenerated cases of empty parity, or skipping all */
+    1910         120 :         if (blockstart < blockmax) {
+    1911         118 :                 ret = state_check_process(state, fix, parity_ptr, blockstart, blockmax);
+    1912         118 :                 if (ret == -1) {
+    1913             :                         /* LCOV_EXCL_START */
+    1914             :                         ++error;
+    1915             :                         /* continue, as we are already exiting */
+    1916             :                         /* LCOV_EXCL_STOP */
+    1917             :                 }
+    1918             :         }
+    1919             : 
+    1920             :         /* try to close only if opened */
+    1921         596 :         for (l = 0; l < state->level; ++l) {
+    1922         476 :                 if (parity_ptr[l]) {
+    1923         453 :                         ret = parity_close(parity_ptr[l]);
+    1924             :                         /* LCOV_EXCL_START */
+    1925             :                         if (ret == -1) {
+    1926             :                                 log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l));
+    1927             :                                 ++error;
+    1928             :                                 /* continue, as we are already exiting */
+    1929             :                         }
+    1930             :                         /* LCOV_EXCL_STOP */
+    1931             :                 }
+    1932             :         }
+    1933             : 
+    1934             :         /* abort if error are present */
+    1935         120 :         if (error != 0)
+    1936           0 :                 return -1;
+    1937         120 :         return 0;
+    1938             : }
+    1939             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/device.c.func-sort-c.html b/cov/cmdline/device.c.func-sort-c.html new file mode 100644 index 00000000..5793873b --- /dev/null +++ b/cov/cmdline/device.c.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - cmdline/device.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - device.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:28031588.9 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
smart_afr_value72
printl52
poisson_prob_n_or_more_failures31
fact31
poisson_prob_n_failures31
raid_prob_of_one_or_more_failures18
printp18
smart_afr13
state_device5
state_smart1
devtest1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/device.c.func.html b/cov/cmdline/device.c.func.html new file mode 100644 index 00000000..a1417c99 --- /dev/null +++ b/cov/cmdline/device.c.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - cmdline/device.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - device.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:28031588.9 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
devtest1
fact31
poisson_prob_n_failures31
poisson_prob_n_or_more_failures31
printl52
printp18
raid_prob_of_one_or_more_failures18
smart_afr13
smart_afr_value72
state_device5
state_smart1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/device.c.gcov.html b/cov/cmdline/device.c.gcov.html new file mode 100644 index 00000000..950e3f19 --- /dev/null +++ b/cov/cmdline/device.c.gcov.html @@ -0,0 +1,1088 @@ + + + + + + + LCOV - lcov.info - cmdline/device.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - device.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:28031588.9 %
Date:2015-05-12Functions:1111100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2015 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "state.h"
+      22             : #include "raid/raid.h"
+      23             : 
+      24             : /**
+      25             :  * The following are Failure Rate tables computed from the data that
+      26             :  * BackBlaze made available at:
+      27             :  *
+      28             :  * Reliability Data Set For 41,000 Hard Drives Now Open Source
+      29             :  * https://www.backblaze.com/blog/hard-drive-data-feb2015/
+      30             :  *
+      31             :  * Hard Drive Data Sets
+      32             :  * https://www.backblaze.com/hard-drive-test-data.html
+      33             :  *
+      34             :  * Note that in this data:
+      35             :  *  - Disks all passed the load-testing and have made it to production,
+      36             :  *    and then Dead On Arrival (DOA) failures are excluded.
+      37             :  *  - Disks that are predicted to fail by BackBlaze are removed before
+      38             :  *    they really fail, not counting as a failure.
+      39             :  *
+      40             :  * The following tables are computed using the data from 2014-02-14 to 2014-12-31
+      41             :  * becasue it's the period when more SMART attributes were gathered.
+      42             :  *
+      43             :  * In this period there are 47322 disk seen, with 1988 removed because failed,
+      44             :  * and with 4121 removed because predicted to fail.
+      45             :  */
+      46             : 
+      47             : /**
+      48             :  * Number of data point in each table.
+      49             :  */
+      50             : #define SMART_MEASURES 256
+      51             : 
+      52             : /*
+      53             :  * Divider for SMART attribute 5
+      54             :  */
+      55             : static unsigned SMART_5_STEP = 1;
+      56             : 
+      57             : /*
+      58             :  * Failure rate for 30 days, for a disk
+      59             :  * with SMART attribute 5 at a given value.
+      60             :  */
+      61             : static double SMART_5_R[SMART_MEASURES] = {
+      62             :         0.0034, 0.0738, 0.0883, 0.0960, 0.1016,
+      63             :         0.1062, 0.1106, 0.1142, 0.1189, 0.1259,
+      64             :         0.1307, 0.1337, 0.1368, 0.1400, 0.1419,
+      65             :         0.1448, 0.1463, 0.1497, 0.1512, 0.1532,
+      66             :         0.1546, 0.1563, 0.1582, 0.1606, 0.1624,
+      67             :         0.1645, 0.1658, 0.1670, 0.1687, 0.1702,
+      68             :         0.1717, 0.1730, 0.1749, 0.1774, 0.1791,
+      69             :         0.1804, 0.1819, 0.1826, 0.1840, 0.1858,
+      70             :         0.1869, 0.1899, 0.1906, 0.1914, 0.1932,
+      71             :         0.1942, 0.1954, 0.1962, 0.1985, 0.2007,
+      72             :         0.2017, 0.2030, 0.2041, 0.2049, 0.2061,
+      73             :         0.2072, 0.2080, 0.2096, 0.2100, 0.2107,
+      74             :         0.2113, 0.2124, 0.2132, 0.2138, 0.2145,
+      75             :         0.2159, 0.2168, 0.2180, 0.2198, 0.2204,
+      76             :         0.2208, 0.2212, 0.2225, 0.2242, 0.2248,
+      77             :         0.2254, 0.2261, 0.2265, 0.2269, 0.2278,
+      78             :         0.2293, 0.2313, 0.2321, 0.2326, 0.2334,
+      79             :         0.2346, 0.2362, 0.2366, 0.2375, 0.2393,
+      80             :         0.2397, 0.2402, 0.2410, 0.2415, 0.2423,
+      81             :         0.2436, 0.2447, 0.2458, 0.2463, 0.2470,
+      82             :         0.2481, 0.2488, 0.2492, 0.2498, 0.2510,
+      83             :         0.2528, 0.2536, 0.2540, 0.2548, 0.2557,
+      84             :         0.2563, 0.2568, 0.2574, 0.2591, 0.2593,
+      85             :         0.2596, 0.2603, 0.2608, 0.2613, 0.2616,
+      86             :         0.2622, 0.2635, 0.2648, 0.2651, 0.2658,
+      87             :         0.2661, 0.2664, 0.2667, 0.2677, 0.2689,
+      88             :         0.2697, 0.2699, 0.2701, 0.2711, 0.2717,
+      89             :         0.2719, 0.2733, 0.2745, 0.2759, 0.2761,
+      90             :         0.2769, 0.2771, 0.2772, 0.2774, 0.2780,
+      91             :         0.2796, 0.2798, 0.2803, 0.2808, 0.2811,
+      92             :         0.2814, 0.2821, 0.2829, 0.2841, 0.2846,
+      93             :         0.2848, 0.2851, 0.2856, 0.2866, 0.2869,
+      94             :         0.2873, 0.2895, 0.2897, 0.2903, 0.2906,
+      95             :         0.2910, 0.2914, 0.2916, 0.2923, 0.2940,
+      96             :         0.2945, 0.2954, 0.2959, 0.2962, 0.2966,
+      97             :         0.2974, 0.2991, 0.3004, 0.3004, 0.3007,
+      98             :         0.3011, 0.3015, 0.3017, 0.3019, 0.3025,
+      99             :         0.3037, 0.3038, 0.3040, 0.3043, 0.3046,
+     100             :         0.3050, 0.3055, 0.3061, 0.3079, 0.3084,
+     101             :         0.3088, 0.3092, 0.3095, 0.3101, 0.3109,
+     102             :         0.3119, 0.3142, 0.3146, 0.3149, 0.3151,
+     103             :         0.3153, 0.3154, 0.3157, 0.3164, 0.3177,
+     104             :         0.3178, 0.3186, 0.3188, 0.3201, 0.3208,
+     105             :         0.3212, 0.3218, 0.3233, 0.3234, 0.3239,
+     106             :         0.3243, 0.3246, 0.3256, 0.3258, 0.3264,
+     107             :         0.3280, 0.3285, 0.3288, 0.3297, 0.3299,
+     108             :         0.3302, 0.3304, 0.3310, 0.3323, 0.3324,
+     109             :         0.3326, 0.3327, 0.3328, 0.3337, 0.3338,
+     110             :         0.3349, 0.3367, 0.3374, 0.3378, 0.3381,
+     111             :         0.3385, 0.3387, 0.3389, 0.3394, 0.3404,
+     112             :         0.3408, 0.3410, 0.3412, 0.3413, 0.3416,
+     113             :         0.3421, 
+     114             : };
+     115             : 
+     116             : /*
+     117             :  * Divider for SMART attribute 187
+     118             :  */
+     119             : static unsigned SMART_187_STEP = 1;
+     120             : 
+     121             : /*
+     122             :  * Failure rate for 30 days, for a disk
+     123             :  * with SMART attribute 187 at a given value.
+     124             :  */
+     125             : static double SMART_187_R[SMART_MEASURES] = {
+     126             :         0.0048, 0.0957, 0.1157, 0.1306, 0.1415,
+     127             :         0.1501, 0.1695, 0.2444, 0.2714, 0.2925,
+     128             :         0.3113, 0.3284, 0.3515, 0.4054, 0.4331,
+     129             :         0.4578, 0.4817, 0.5010, 0.5171, 0.5610,
+     130             :         0.5893, 0.6120, 0.6362, 0.6608, 0.6803,
+     131             :         0.7261, 0.7490, 0.7818, 0.8109, 0.8364,
+     132             :         0.8599, 0.9086, 0.9303, 0.9580, 0.9820,
+     133             :         1.0057, 1.0388, 1.0803, 1.1067, 1.1327,
+     134             :         1.1589, 1.1788, 1.1963, 1.2136, 1.2367,
+     135             :         1.2617, 1.2789, 1.2940, 1.3134, 1.3376,
+     136             :         1.3562, 1.3673, 1.3799, 1.4099, 1.4260,
+     137             :         1.4321, 1.4495, 1.4548, 1.4696, 1.4816,
+     138             :         1.5054, 1.5204, 1.5296, 1.5627, 1.5820,
+     139             :         1.5969, 1.6076, 1.6125, 1.6205, 1.6333,
+     140             :         1.6582, 1.6674, 1.6843, 1.7144, 1.7269,
+     141             :         1.7494, 1.7590, 1.7747, 1.7962, 1.8383,
+     142             :         1.8480, 1.8532, 1.8641, 1.8793, 1.8850,
+     143             :         1.8920, 1.8978, 1.9033, 1.9081, 1.9237,
+     144             :         1.9609, 1.9805, 2.0055, 2.0095, 2.0127,
+     145             :         2.0277, 2.0493, 2.0873, 2.1064, 2.1130,
+     146             :         2.1190, 2.1240, 2.1477, 2.1850, 2.1979,
+     147             :         2.2168, 2.2279, 2.2701, 2.2794, 2.2855,
+     148             :         2.3012, 2.3138, 2.3167, 2.3764, 2.3832,
+     149             :         2.3860, 2.3906, 2.4012, 2.4261, 2.4314,
+     150             :         2.4539, 2.4556, 2.4630, 2.4764, 2.4821,
+     151             :         2.4851, 2.4894, 2.4922, 2.4992, 2.5123,
+     152             :         2.5202, 2.5232, 2.5264, 2.5322, 2.5407,
+     153             :         2.5429, 2.5485, 2.5642, 2.5669, 2.5743,
+     154             :         2.5887, 2.5890, 2.6177, 2.7026, 2.7028,
+     155             :         2.7080, 2.7110, 2.7159, 2.7192, 2.7217,
+     156             :         2.7227, 2.7263, 2.7313, 2.7344, 2.7348,
+     157             :         2.7450, 2.7501, 2.7641, 2.7670, 2.7711,
+     158             :         2.7724, 2.7753, 2.7757, 2.7853, 2.7870,
+     159             :         2.7919, 2.7947, 2.7974, 2.8002, 2.8132,
+     160             :         2.8157, 2.8195, 2.8204, 2.8220, 2.8254,
+     161             :         2.8270, 2.8329, 2.8479, 2.8490, 2.8532,
+     162             :         2.8578, 2.8662, 2.8710, 2.8737, 2.8742,
+     163             :         2.8750, 2.9768, 2.9810, 2.9825, 2.9873,
+     164             :         2.9884, 3.0040, 3.0055, 3.0066, 3.0119,
+     165             :         3.0189, 3.0239, 3.0277, 3.0335, 3.0345,
+     166             :         3.0388, 3.0521, 3.0673, 3.0717, 3.0734,
+     167             :         3.0753, 3.0770, 3.0961, 3.0975, 3.0988,
+     168             :         3.1004, 3.1018, 3.1018, 3.1041, 3.1058,
+     169             :         3.1067, 3.1126, 3.1144, 3.1178, 3.1185,
+     170             :         3.1226, 3.1264, 3.1303, 3.1308, 3.1314,
+     171             :         3.1339, 3.1346, 3.1364, 3.1384, 3.1389,
+     172             :         3.1390, 3.1399, 3.1405, 3.1406, 3.1412,
+     173             :         3.1412, 3.1424, 3.1467, 3.1556, 3.1650,
+     174             :         3.1662, 3.1834, 3.1839, 3.1853, 3.1855,
+     175             :         3.1864, 3.1889, 3.1912, 3.1913, 3.1918,
+     176             :         3.1924, 3.1934, 3.1951, 3.2129, 3.2138,
+     177             :         3.2176, 
+     178             : };
+     179             : 
+     180             : /*
+     181             :  * Divider for SMART attribute 188
+     182             :  */
+     183             : static unsigned SMART_188_STEP = 1;
+     184             : 
+     185             : /*
+     186             :  * Failure rate for 30 days, for a disk
+     187             :  * with SMART attribute 188 at a given value.
+     188             :  */
+     189             : static double SMART_188_R[SMART_MEASURES] = {
+     190             :         0.0022, 0.0087, 0.0113, 0.0131, 0.0143,
+     191             :         0.0157, 0.0176, 0.0203, 0.0233, 0.0271,
+     192             :         0.0317, 0.0377, 0.0449, 0.0542, 0.0658,
+     193             :         0.0798, 0.0934, 0.1100, 0.1268, 0.1451,
+     194             :         0.1626, 0.1820, 0.1975, 0.2138, 0.2270,
+     195             :         0.2397, 0.2515, 0.2606, 0.2692, 0.2792,
+     196             :         0.2861, 0.2954, 0.3050, 0.3165, 0.3252,
+     197             :         0.3369, 0.3430, 0.3512, 0.3588, 0.3731,
+     198             :         0.3777, 0.3894, 0.3981, 0.4148, 0.4206,
+     199             :         0.4325, 0.4354, 0.4449, 0.4503, 0.4635,
+     200             :         0.4695, 0.4806, 0.4871, 0.4988, 0.5007,
+     201             :         0.5099, 0.5144, 0.5270, 0.5313, 0.5393,
+     202             :         0.5456, 0.5529, 0.5542, 0.5633, 0.5657,
+     203             :         0.5729, 0.5748, 0.5814, 0.5906, 0.5977,
+     204             :         0.6045, 0.6096, 0.6208, 0.6259, 0.6293,
+     205             :         0.6347, 0.6354, 0.6389, 0.6449, 0.6481,
+     206             :         0.6549, 0.6581, 0.6604, 0.6703, 0.6759,
+     207             :         0.6830, 0.6882, 0.6900, 0.6931, 0.7027,
+     208             :         0.7070, 0.7125, 0.7202, 0.7302, 0.7405,
+     209             :         0.7467, 0.7520, 0.7573, 0.7616, 0.7688,
+     210             :         0.7732, 0.7773, 0.7825, 0.7890, 0.7940,
+     211             :         0.8113, 0.8213, 0.8344, 0.8364, 0.8403,
+     212             :         0.8449, 0.8488, 0.8567, 0.8621, 0.8668,
+     213             :         0.8729, 0.8737, 0.8750, 0.8782, 0.8807,
+     214             :         0.8821, 0.8920, 0.8987, 0.8990, 0.9099,
+     215             :         0.9141, 0.9165, 0.9195, 0.9198, 0.9235,
+     216             :         0.9247, 0.9315, 0.9359, 0.9372, 0.9394,
+     217             :         0.9451, 0.9454, 0.9493, 0.9520, 0.9534,
+     218             :         0.9556, 0.9564, 0.9605, 0.9628, 0.9648,
+     219             :         0.9709, 0.9717, 0.9761, 0.9784, 0.9788,
+     220             :         0.9824, 0.9884, 0.9938, 0.9944, 1.0056,
+     221             :         1.0061, 1.0111, 1.0314, 1.0375, 1.0393,
+     222             :         1.0396, 1.0397, 1.0414, 1.0418, 1.0466,
+     223             :         1.0467, 1.0474, 1.0475, 1.0523, 1.0523,
+     224             :         1.0524, 1.0525, 1.0557, 1.0597, 1.0597,
+     225             :         1.0598, 1.0599, 1.0599, 1.0602, 1.0603,
+     226             :         1.0603, 1.0605, 1.0605, 1.0610, 1.0611,
+     227             :         1.0613, 1.0615, 1.0628, 1.0666, 1.0732,
+     228             :         1.0792, 1.0796, 1.0797, 1.0864, 1.0935,
+     229             :         1.0936, 1.1013, 1.1066, 1.1088, 1.1088,
+     230             :         1.1093, 1.1119, 1.1136, 1.1146, 1.1245,
+     231             :         1.1274, 1.1275, 1.1276, 1.1280, 1.1280,
+     232             :         1.1347, 1.1348, 1.1348, 1.1348, 1.1350,
+     233             :         1.1408, 1.1476, 1.1477, 1.1477, 1.1478,
+     234             :         1.1479, 1.1479, 1.1479, 1.1480, 1.1480,
+     235             :         1.1564, 1.1714, 1.1732, 1.1747, 1.1816,
+     236             :         1.1819, 1.1887, 1.1906, 1.2126, 1.2167,
+     237             :         1.2168, 1.2168, 1.2168, 1.2171, 1.2171,
+     238             :         1.2268, 1.2396, 1.2397, 1.2418, 1.2478,
+     239             :         1.2588, 1.2610, 1.2615, 1.2651, 1.2668,
+     240             :         1.2682, 1.2732, 1.2738, 1.2747, 1.2764,
+     241             :         1.2765,
+     242             : };
+     243             : 
+     244             : /*
+     245             :  * Divider for SMART attribute 193
+     246             :  */
+     247             : static unsigned SMART_193_STEP = 649;
+     248             : 
+     249             : /*
+     250             :  * Failure rate for 30 days, for a disk
+     251             :  * with SMART attribute 193 at a given value.
+     252             :  */
+     253             : static double SMART_193_R[SMART_MEASURES] = {
+     254             :         0.0000, 0.0014, 0.0027, 0.0030, 0.0031,
+     255             :         0.0033, 0.0036, 0.0038, 0.0041, 0.0043,
+     256             :         0.0046, 0.0048, 0.0050, 0.0053, 0.0056,
+     257             :         0.0058, 0.0060, 0.0064, 0.0067, 0.0069,
+     258             :         0.0073, 0.0076, 0.0079, 0.0082, 0.0085,
+     259             :         0.0088, 0.0091, 0.0094, 0.0097, 0.0100,
+     260             :         0.0104, 0.0107, 0.0110, 0.0113, 0.0115,
+     261             :         0.0117, 0.0120, 0.0123, 0.0126, 0.0129,
+     262             :         0.0131, 0.0134, 0.0138, 0.0141, 0.0144,
+     263             :         0.0149, 0.0153, 0.0156, 0.0159, 0.0162,
+     264             :         0.0166, 0.0168, 0.0171, 0.0173, 0.0176,
+     265             :         0.0179, 0.0183, 0.0186, 0.0191, 0.0196,
+     266             :         0.0202, 0.0207, 0.0213, 0.0217, 0.0221,
+     267             :         0.0225, 0.0233, 0.0238, 0.0243, 0.0247,
+     268             :         0.0252, 0.0257, 0.0261, 0.0265, 0.0271,
+     269             :         0.0278, 0.0284, 0.0290, 0.0294, 0.0298,
+     270             :         0.0304, 0.0310, 0.0316, 0.0321, 0.0325,
+     271             :         0.0329, 0.0334, 0.0340, 0.0346, 0.0351,
+     272             :         0.0355, 0.0359, 0.0365, 0.0372, 0.0379,
+     273             :         0.0387, 0.0395, 0.0405, 0.0413, 0.0419,
+     274             :         0.0424, 0.0432, 0.0440, 0.0447, 0.0455,
+     275             :         0.0461, 0.0467, 0.0471, 0.0476, 0.0481,
+     276             :         0.0486, 0.0490, 0.0495, 0.0500, 0.0505,
+     277             :         0.0512, 0.0518, 0.0524, 0.0532, 0.0540,
+     278             :         0.0545, 0.0552, 0.0559, 0.0566, 0.0574,
+     279             :         0.0582, 0.0592, 0.0601, 0.0607, 0.0616,
+     280             :         0.0623, 0.0631, 0.0639, 0.0646, 0.0654,
+     281             :         0.0661, 0.0668, 0.0677, 0.0685, 0.0696,
+     282             :         0.0707, 0.0717, 0.0727, 0.0737, 0.0749,
+     283             :         0.0759, 0.0773, 0.0783, 0.0791, 0.0800,
+     284             :         0.0809, 0.0819, 0.0829, 0.0839, 0.0847,
+     285             :         0.0858, 0.0867, 0.0876, 0.0884, 0.0895,
+     286             :         0.0906, 0.0919, 0.0931, 0.0943, 0.0954,
+     287             :         0.0966, 0.0976, 0.0985, 0.0995, 0.1009,
+     288             :         0.1021, 0.1038, 0.1051, 0.1065, 0.1076,
+     289             :         0.1090, 0.1106, 0.1119, 0.1130, 0.1146,
+     290             :         0.1158, 0.1168, 0.1181, 0.1193, 0.1206,
+     291             :         0.1216, 0.1227, 0.1241, 0.1257, 0.1268,
+     292             :         0.1277, 0.1289, 0.1302, 0.1316, 0.1329,
+     293             :         0.1341, 0.1355, 0.1372, 0.1387, 0.1400,
+     294             :         0.1415, 0.1427, 0.1438, 0.1447, 0.1458,
+     295             :         0.1470, 0.1480, 0.1491, 0.1502, 0.1517,
+     296             :         0.1528, 0.1539, 0.1555, 0.1568, 0.1583,
+     297             :         0.1594, 0.1606, 0.1618, 0.1635, 0.1649,
+     298             :         0.1665, 0.1686, 0.1700, 0.1719, 0.1731,
+     299             :         0.1743, 0.1755, 0.1777, 0.1788, 0.1802,
+     300             :         0.1812, 0.1824, 0.1835, 0.1848, 0.1859,
+     301             :         0.1869, 0.1880, 0.1890, 0.1901, 0.1913,
+     302             :         0.1926, 0.1935, 0.1948, 0.1960, 0.1977,
+     303             :         0.1989, 0.2001, 0.2013, 0.2024, 0.2036,
+     304             :         0.2049, 0.2062, 0.2074, 0.2087, 0.2099,
+     305             :         0.2111,
+     306             : };
+     307             : 
+     308             : /*
+     309             :  * Divider for SMART attribute 197
+     310             :  */
+     311             : static unsigned SMART_197_STEP = 1;
+     312             : 
+     313             : /*
+     314             :  * Failure rate for 30 days, for a disk
+     315             :  * with SMART attribute 197 at a given value.
+     316             :  */
+     317             : static double SMART_197_R[SMART_MEASURES] = {
+     318             :         0.0036, 0.2430, 0.3027, 0.3349, 0.3533,
+     319             :         0.3632, 0.3722, 0.3790, 0.4199, 0.6417,
+     320             :         0.6517, 0.6583, 0.6647, 0.6680, 0.6737,
+     321             :         0.6787, 0.7076, 0.9073, 0.9113, 0.9194,
+     322             :         0.9238, 0.9326, 0.9394, 0.9446, 0.9697,
+     323             :         1.1417, 1.1466, 1.1485, 1.1522, 1.1775,
+     324             :         1.1817, 1.1864, 1.2105, 1.3939, 1.3991,
+     325             :         1.4013, 1.4125, 1.4135, 1.4210, 1.4217,
+     326             :         1.4335, 1.6024, 1.6040, 1.6132, 1.6174,
+     327             :         1.6187, 1.6203, 1.6211, 1.6354, 1.7839,
+     328             :         1.7858, 1.7869, 1.7889, 1.7911, 1.7932,
+     329             :         1.7962, 1.8091, 1.9381, 1.9405, 1.9410,
+     330             :         1.9415, 1.9420, 1.9424, 1.9434, 1.9518,
+     331             :         2.0516, 2.0518, 2.0521, 2.0524, 2.0532,
+     332             :         2.0538, 2.0550, 2.0624, 2.1508, 2.1514,
+     333             :         2.1519, 2.1519, 2.1520, 2.1533, 2.1534,
+     334             :         2.1603, 2.2730, 2.2730, 2.2730, 2.2757,
+     335             :         2.2768, 2.2774, 2.2778, 2.2844, 2.3740,
+     336             :         2.3753, 2.3769, 2.3779, 2.3790, 2.3796,
+     337             :         2.3806, 2.3891, 2.5538, 2.5550, 2.5563,
+     338             :         2.5588, 2.5594, 2.5600, 2.5605, 2.5665,
+     339             :         2.7510, 2.7526, 2.7539, 2.7544, 2.7549,
+     340             :         2.7552, 2.7555, 2.7590, 2.8782, 2.8788,
+     341             :         2.8812, 2.8821, 2.8824, 2.8836, 2.8836,
+     342             :         2.8864, 2.9536, 2.9539, 2.9543, 2.9559,
+     343             :         2.9565, 2.9572, 2.9572, 2.9601, 3.0230,
+     344             :         3.0230, 3.0230, 3.0230, 3.0230, 3.0231,
+     345             :         3.0231, 3.0266, 3.0846, 3.0846, 3.0846,
+     346             :         3.0846, 3.0846, 3.0847, 3.0851, 3.0874,
+     347             :         3.1242, 3.1242, 3.1242, 3.1242, 3.1246,
+     348             :         3.1246, 3.1246, 3.1273, 3.1806, 3.1806,
+     349             :         3.1806, 3.1806, 3.1806, 3.1810, 3.1814,
+     350             :         3.1829, 3.2173, 3.2174, 3.2174, 3.2174,
+     351             :         3.2174, 3.2174, 3.2174, 3.2197, 3.2643,
+     352             :         3.2643, 3.2643, 3.2661, 3.2661, 3.2666,
+     353             :         3.2666, 3.2677, 3.2962, 3.2962, 3.2963,
+     354             :         3.3673, 3.3713, 3.3813, 3.3813, 3.3835,
+     355             :         3.4059, 3.4059, 3.4065, 3.4091, 3.4096,
+     356             :         3.4103, 3.4104, 3.4123, 3.4316, 3.4360,
+     357             :         3.4387, 3.4393, 3.4393, 3.4404, 3.4409,
+     358             :         3.4440, 3.5547, 3.5547, 3.5547, 3.5547,
+     359             :         3.5547, 3.5547, 3.5548, 3.5558, 3.5801,
+     360             :         3.5801, 3.5801, 3.5801, 3.5802, 3.5802,
+     361             :         3.5802, 3.5820, 3.6178, 3.6178, 3.6178,
+     362             :         3.6178, 3.6178, 3.6242, 3.6242, 3.6260,
+     363             :         3.6567, 3.6567, 3.6568, 3.6568, 3.6568,
+     364             :         3.6568, 3.6831, 3.6841, 3.7260, 3.7268,
+     365             :         3.7269, 3.7269, 3.7269, 3.7269, 3.7269,
+     366             :         3.7279, 3.7387, 3.7387, 3.7394, 3.7394,
+     367             :         3.7394, 3.7394, 3.7394, 3.7402, 3.7622,
+     368             :         3.7622, 3.7629, 3.7734, 3.7734, 3.7734,
+     369             :         3.7734, 
+     370             : };
+     371             : 
+     372             : /*
+     373             :  * Divider for SMART attribute 198
+     374             :  */
+     375             : static unsigned SMART_198_STEP = 1;
+     376             : 
+     377             : /*
+     378             :  * Failure rate for 30 days, for a disk
+     379             :  * with SMART attribute 198 at a given value.
+     380             :  */
+     381             : static double SMART_198_R[SMART_MEASURES] = {
+     382             :         0.0038, 0.3963, 0.4189, 0.4297, 0.4364,
+     383             :         0.4393, 0.4433, 0.4490, 0.4909, 0.7634,
+     384             :         0.7649, 0.7683, 0.7689, 0.7703, 0.7717,
+     385             :         0.7737, 0.8009, 1.0435, 1.0438, 1.0445,
+     386             :         1.0446, 1.0456, 1.0496, 1.0501, 1.0695,
+     387             :         1.2652, 1.2662, 1.2667, 1.2707, 1.2722,
+     388             :         1.2734, 1.2750, 1.2974, 1.5036, 1.5038,
+     389             :         1.5050, 1.5156, 1.5156, 1.5231, 1.5239,
+     390             :         1.5347, 1.7251, 1.7258, 1.7271, 1.7271,
+     391             :         1.7271, 1.7271, 1.7271, 1.7423, 1.9132,
+     392             :         1.9134, 1.9134, 1.9134, 1.9134, 1.9135,
+     393             :         1.9135, 1.9221, 2.0645, 2.0645, 2.0645,
+     394             :         2.0645, 2.0645, 2.0645, 2.0645, 2.0716,
+     395             :         2.1838, 2.1838, 2.1838, 2.1838, 2.1838,
+     396             :         2.1838, 2.1838, 2.1910, 2.2936, 2.2937,
+     397             :         2.2937, 2.2937, 2.2937, 2.2937, 2.2937,
+     398             :         2.3007, 2.4350, 2.4350, 2.4350, 2.4352,
+     399             :         2.4352, 2.4352, 2.4352, 2.4407, 2.5482,
+     400             :         2.5482, 2.5482, 2.5482, 2.5482, 2.5482,
+     401             :         2.5482, 2.5539, 2.7538, 2.7538, 2.7538,
+     402             :         2.7538, 2.7538, 2.7538, 2.7539, 2.7585,
+     403             :         2.9231, 2.9231, 2.9231, 2.9231, 2.9231,
+     404             :         2.9232, 2.9232, 2.9264, 3.0707, 3.0707,
+     405             :         3.0707, 3.0707, 3.0707, 3.0707, 3.0707,
+     406             :         3.0734, 3.1562, 3.1562, 3.1562, 3.1562,
+     407             :         3.1562, 3.1562, 3.1562, 3.1584, 3.2363,
+     408             :         3.2363, 3.2363, 3.2363, 3.2363, 3.2363,
+     409             :         3.2363, 3.2397, 3.3121, 3.3121, 3.3121,
+     410             :         3.3121, 3.3121, 3.3122, 3.3122, 3.3142,
+     411             :         3.3612, 3.3612, 3.3612, 3.3612, 3.3612,
+     412             :         3.3612, 3.3612, 3.3636, 3.4314, 3.4314,
+     413             :         3.4314, 3.4314, 3.4314, 3.4314, 3.4314,
+     414             :         3.4325, 3.4769, 3.4769, 3.4769, 3.4769,
+     415             :         3.4769, 3.4769, 3.4769, 3.4788, 3.5366,
+     416             :         3.5366, 3.5366, 3.5366, 3.5366, 3.5366,
+     417             :         3.5366, 3.5377, 3.5756, 3.5756, 3.5756,
+     418             :         3.5756, 3.5756, 3.5756, 3.5756, 3.5775,
+     419             :         3.6049, 3.6049, 3.6049, 3.6049, 3.6049,
+     420             :         3.6049, 3.6049, 3.6061, 3.6279, 3.6279,
+     421             :         3.6279, 3.6279, 3.6279, 3.6279, 3.6279,
+     422             :         3.6309, 3.7670, 3.7670, 3.7670, 3.7670,
+     423             :         3.7670, 3.7670, 3.7670, 3.7679, 3.7983,
+     424             :         3.7983, 3.7983, 3.7983, 3.7983, 3.7983,
+     425             :         3.7983, 3.8000, 3.8449, 3.8449, 3.8449,
+     426             :         3.8449, 3.8449, 3.8449, 3.8449, 3.8467,
+     427             :         3.8854, 3.9337, 3.9337, 3.9337, 3.9337,
+     428             :         3.9337, 3.9337, 3.9346, 3.9892, 3.9892,
+     429             :         3.9892, 3.9892, 3.9892, 3.9892, 3.9892,
+     430             :         3.9901, 4.0043, 4.0043, 4.0043, 4.0043,
+     431             :         4.0043, 4.0043, 4.0043, 4.0050, 4.0340,
+     432             :         4.0340, 4.0340, 4.0340, 4.0340, 4.0340,
+     433             :         4.0340, 
+     434             : };
+     435             : 
+     436             : /**
+     437             :  * Computes the estimated Annual Failure Rate from the specified table.
+     438             :  */
+     439          72 : static double smart_afr_value(double* tab, unsigned step, uint64_t value)
+     440             : {
+     441          72 :         value /= step;
+     442             : 
+     443          72 :         if (value >= SMART_MEASURES)
+     444           0 :                 value = SMART_MEASURES - 1;
+     445             : 
+     446             :         /* table rates are for a month, so we scale to a year */
+     447          72 :         return 365.0 / 30.0 * tab[value];
+     448             : }
+     449             : 
+     450             : /**
+     451             :  * Computes the estimated Annual Failure Rate of a set of SMART attributes.
+     452             :  *
+     453             :  * We define the Annual Failure Rate as the average number of
+     454             :  * failures you expect in a year from a disk slot:
+     455             :  *
+     456             :  *   AFR = 8760/MTBF (Mean Time Between Failures in hours).
+     457             :  *
+     458             :  * Note that this definition is different from the one given
+     459             :  * by Seagate, that defines AFR = 1 - exp(-8760/MTBF), that
+     460             :  * instead represents the probability of a failure in the next
+     461             :  * year.
+     462             :  *
+     463             :  * To combine the different AFR from different SMART attributes,
+     464             :  * we use the maximum rate reported, and we do not sum them,
+     465             :  * because the attributes are not independent.
+     466             :  */
+     467          13 : static double smart_afr(uint64_t* smart)
+     468             : {
+     469          13 :         double afr = 0;
+     470          13 :         uint64_t mask32 = 0xffffffffU;
+     471          13 :         uint64_t mask16 = 0xffffU;
+     472             : 
+     473          13 :         if (smart[5] != SMART_UNASSIGNED) {
+     474          12 :                 double r = smart_afr_value(SMART_5_R, SMART_5_STEP, smart[5] & mask32);
+     475          12 :                 if (afr < r)
+     476          12 :                         afr = r;
+     477             :         }
+     478             : 
+     479          13 :         if (smart[187] != SMART_UNASSIGNED) {
+     480             :                 /* with some disks, only the lower 16 bits are significative */
+     481             :                 /* See: http://web.archive.org/web/20130507072056/http://media.kingston.com/support/downloads/MKP_306_SMART_attribute.pdf */
+     482          12 :                 double r = smart_afr_value(SMART_187_R, SMART_187_STEP, smart[187] & mask16);
+     483          12 :                 if (afr < r)
+     484          12 :                         afr = r;
+     485             :         }
+     486             : 
+     487          13 :         if (smart[188] != SMART_UNASSIGNED) {
+     488             :                 /* with Seagate disks, there are three different 16 bits value reported */
+     489             :                 /* the lowest one is the most significative */
+     490          12 :                 double r = smart_afr_value(SMART_188_R, SMART_188_STEP, smart[188] & mask16);
+     491          12 :                 if (afr < r)
+     492           0 :                         afr = r;
+     493             :         }
+     494             : 
+     495          13 :         if (smart[193] != SMART_UNASSIGNED) {
+     496          12 :                 double r = smart_afr_value(SMART_193_R, SMART_193_STEP, smart[193] & mask32);
+     497          12 :                 if (afr < r)
+     498           0 :                         afr = r;
+     499             :         }
+     500             : 
+     501          13 :         if (smart[197] != SMART_UNASSIGNED) {
+     502          12 :                 double r = smart_afr_value(SMART_197_R, SMART_197_STEP, smart[197] & mask32);
+     503          12 :                 if (afr < r)
+     504          12 :                         afr = r;
+     505             :         }
+     506             : 
+     507          13 :         if (smart[198] != SMART_UNASSIGNED) {
+     508          12 :                 double r = smart_afr_value(SMART_198_R, SMART_198_STEP, smart[198] & mask32);
+     509          12 :                 if (afr < r)
+     510          12 :                         afr = r;
+     511             :         }
+     512             : 
+     513          13 :         return afr;
+     514             : }
+     515             : 
+     516             : /**
+     517             :  * Factorial.
+     518             :  */
+     519          31 : static double fact(unsigned n)
+     520             : {
+     521          31 :         double v = 1;
+     522             : 
+     523          62 :         while (n > 1)
+     524           0 :                 v *= n--;
+     525             : 
+     526          31 :         return v;
+     527             : }
+     528             : 
+     529             : /**
+     530             :  * Probability of having exactly ::n events in a Poisson
+     531             :  * distribution with rate ::rate in a time unit.
+     532             :  */
+     533          31 : static double poisson_prob_n_failures(double rate, unsigned n)
+     534             : {
+     535          31 :         return pow(rate, n) * exp(-rate) / fact(n);
+     536             : }
+     537             : 
+     538             : /**
+     539             :  * Probability of having ::n or more events in a Poisson
+     540             :  * distribution with rate ::rate in a time unit.
+     541             :  */
+     542          31 : static double poisson_prob_n_or_more_failures(double rate, unsigned n)
+     543             : {
+     544          31 :         double p_neg = 0;
+     545             :         unsigned i;
+     546             : 
+     547          62 :         for (i = 0; i < n; ++i)
+     548          31 :                 p_neg += poisson_prob_n_failures(rate, n - 1 - i);
+     549             : 
+     550          31 :         return 1 - p_neg;
+     551             : }
+     552             : 
+     553             : /**
+     554             :  * Probability of having data loss in a RAID system with the specified ::redundancy
+     555             :  * supposing the specified ::array_failure_rate, and ::replace_rate.
+     556             :  */
+     557          18 : static double raid_prob_of_one_or_more_failures(double array_failure_rate, double replace_rate, unsigned n, unsigned redundancy)
+     558             : {
+     559             :         unsigned i;
+     560             :         double MTBF;
+     561             :         double MTTR;
+     562             :         double MTTDL;
+     563             :         double raid_failure_rate;
+     564             : 
+     565             :         /*
+     566             :          * Use the MTTDL model (Mean Time To Data Loss) to estimate the
+     567             :          * failure rate of the array.
+     568             :          *
+     569             :          * See:
+     570             :          * Garth Alan Gibson, "Redundant Disk Arrays: Reliable, Parallel Secondary Storage", 1990
+     571             :          */
+     572             : 
+     573             :         /* get the Mean Time Between Failure of a single disk */
+     574             :         /* from the array failure rate */
+     575          18 :         MTBF = n / array_failure_rate;
+     576             : 
+     577             :         /* get the Mean Time Between Repair (the time that a failed disk is replaced) */
+     578             :         /* from the repair rate */
+     579          18 :         MTTR = 1.0 / replace_rate;
+     580             : 
+     581             :         /* use the approximated MTTDL equation */
+     582          18 :         MTTDL = pow(MTBF, redundancy + 1) / pow(MTTR, redundancy);
+     583          99 :         for (i = 0; i < redundancy + 1; ++i)
+     584          81 :                 MTTDL /= n - i;
+     585             : 
+     586             :         /* the raid failure rate is just the inverse of the MTTDL */
+     587          18 :         raid_failure_rate = 1.0 / MTTDL;
+     588             : 
+     589             :         /* probability of at least one RAID failure */
+     590             :         /* note that is almost equal at the probabilty of */
+     591             :         /* the first failure. */
+     592          18 :         return poisson_prob_n_or_more_failures(raid_failure_rate, 1);
+     593             : }
+     594             : 
+     595             : /**
+     596             :  * Prints a string with space padding.
+     597             :  */
+     598          52 : static void printl(const char* str, size_t pad)
+     599             : {
+     600             :         size_t len;
+     601             : 
+     602          52 :         printf("%s", str);
+     603             : 
+     604          52 :         len = strlen(str);
+     605             : 
+     606         285 :         while (len < pad) {
+     607         181 :                 printf(" ");
+     608         181 :                 ++len;
+     609             :         }
+     610          52 : }
+     611             : 
+     612             : /**
+     613             :  * Prints a probability with space padding.
+     614             :  */
+     615          18 : static void printp(double v, size_t pad)
+     616             : {
+     617             :         char buf[64];
+     618          18 :         const char* s = "%";
+     619             : 
+     620          18 :         if (v > 0.1)
+     621          18 :                 snprintf(buf, sizeof(buf), "%5.2f%s", v, s);
+     622           0 :         else if (v > 0.01)
+     623           0 :                 snprintf(buf, sizeof(buf), "%6.3f%s", v, s);
+     624           0 :         else if (v > 0.001)
+     625           0 :                 snprintf(buf, sizeof(buf), "%7.4f%s", v, s);
+     626           0 :         else if (v > 0.0001)
+     627           0 :                 snprintf(buf, sizeof(buf), "%8.5f%s", v, s);
+     628           0 :         else if (v > 0.00001)
+     629           0 :                 snprintf(buf, sizeof(buf), "%9.6f%s", v, s);
+     630           0 :         else if (v > 0.000001)
+     631           0 :                 snprintf(buf, sizeof(buf), "%10.7f%s", v, s);
+     632           0 :         else if (v > 0.0000001)
+     633           0 :                 snprintf(buf, sizeof(buf), "%11.8f%s", v, s);
+     634           0 :         else if (v > 0.00000001)
+     635           0 :                 snprintf(buf, sizeof(buf), "%12.9f%s", v, s);
+     636           0 :         else if (v > 0.000000001)
+     637           0 :                 snprintf(buf, sizeof(buf), "%13.10f%s", v, s);
+     638           0 :         else if (v > 0.0000000001)
+     639           0 :                 snprintf(buf, sizeof(buf), "%14.11f%s", v, s);
+     640           0 :         else if (v > 0.00000000001)
+     641           0 :                 snprintf(buf, sizeof(buf), "%15.12f%s", v, s);
+     642           0 :         else if (v > 0.000000000001)
+     643           0 :                 snprintf(buf, sizeof(buf), "%16.13f%s", v, s);
+     644             :         else
+     645           0 :                 snprintf(buf, sizeof(buf), "%17.14f%s", v, s);
+     646          18 :         printl(buf, pad);
+     647          18 : }
+     648             : 
+     649           1 : static void state_smart(unsigned n, tommy_list* low)
+     650             : {
+     651             :         tommy_node* i;
+     652             :         unsigned j;
+     653             :         size_t device_pad;
+     654             :         size_t serial_pad;
+     655             :         int have_parent;
+     656             :         double array_failure_rate;
+     657             :         double p_at_least_one_failure;
+     658           1 :         int make_it_fail = 0;
+     659           1 :         uint64_t mask32 = 0xffffffffU;
+     660           1 :         uint64_t mask16 = 0xffffU;
+     661             : 
+     662             :         /* compute lengths for padding */
+     663           1 :         device_pad = 0;
+     664           1 :         serial_pad = 0;
+     665           1 :         have_parent = 0;
+     666          17 :         for (i = tommy_list_head(low); i != 0; i = i->next) {
+     667             :                 size_t len;
+     668          16 :                 devinfo_t* devinfo = i->data;
+     669             : 
+     670          16 :                 len = strlen(devinfo->file);
+     671          16 :                 if (len > device_pad)
+     672           1 :                         device_pad = len;
+     673             : 
+     674          16 :                 len = strlen(devinfo->smart_serial);
+     675          16 :                 if (len > serial_pad)
+     676           2 :                         serial_pad = len;
+     677             : 
+     678          16 :                 if (devinfo->parent != 0)
+     679           0 :                         have_parent = 1;
+     680             :         }
+     681             : 
+     682           1 :         printf("SnapRAID SMART report:\n");
+     683           1 :         printf("\n");
+     684           1 :         printf("   Temp");
+     685           1 :         printf("  Power");
+     686           1 :         printf("   Error");
+     687           1 :         printf("   FP");
+     688           1 :         printf(" Size");
+     689           1 :         printf("\n");
+     690           1 :         printf("      C");
+     691           1 :         printf(" OnDays");
+     692           1 :         printf("   Count");
+     693           1 :         printf("     ");
+     694           1 :         printf("   TB");
+     695           1 :         printf("  "); printl("Serial", serial_pad);
+     696           1 :         printf("  "); printl("Device", device_pad);
+     697           1 :         printf("  Disk");
+     698           1 :         printf("\n");
+     699             :         /*      |<##################################################################72>|####80>| */
+     700           1 :         printf(" -----------------------------------------------------------------------\n");
+     701             : 
+     702           1 :         array_failure_rate = 0;
+     703          17 :         for (i = tommy_list_head(low); i != 0; i = i->next) {
+     704          16 :                 devinfo_t* devinfo = i->data;
+     705             :                 double afr;
+     706             :                 uint64_t flag;
+     707             : 
+     708          16 :                 if (devinfo->smart[194] != SMART_UNASSIGNED)
+     709          15 :                         printf("%7" PRIu64, devinfo->smart[194] & mask16);
+     710           1 :                 else if (devinfo->smart[190] != SMART_UNASSIGNED)
+     711           0 :                         printf("%7" PRIu64, devinfo->smart[190] & mask16);
+     712             :                 else
+     713           1 :                         printf("      -");
+     714             : 
+     715          16 :                 if (devinfo->smart[9] != SMART_UNASSIGNED)
+     716          15 :                         printf("%7" PRIu64, (devinfo->smart[9] & mask32) / 24);
+     717             :                 else
+     718           1 :                         printf("      -");
+     719             : 
+     720          16 :                 if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED)
+     721           8 :                         flag = devinfo->smart[SMART_FLAGS];
+     722             :                 else
+     723           8 :                         flag = 0;
+     724          16 :                 if (flag & SMARTCTL_FLAG_FAIL)
+     725           1 :                         printf("    FAIL");
+     726          15 :                 else if (flag & SMARTCTL_FLAG_PREFAIL)
+     727           1 :                         printf(" PREFAIL");
+     728          14 :                 else if (flag & SMARTCTL_FLAG_PREFAIL_LOGGED)
+     729           1 :                         printf(" logfail");
+     730          13 :                 else if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED
+     731          13 :                         && devinfo->smart[SMART_ERROR] != 0)
+     732           1 :                         printf("%8" PRIu64, devinfo->smart[SMART_ERROR]);
+     733          12 :                 else if (flag & SMARTCTL_FLAG_ERROR)
+     734           1 :                         printf("  logerr");
+     735          11 :                 else if (flag & SMARTCTL_FLAG_ERROR_LOGGED)
+     736           1 :                         printf(" selferr");
+     737          10 :                 else if (devinfo->smart[SMART_ERROR] == 0)
+     738          10 :                         printf("       0");
+     739             :                 else
+     740           0 :                         printf("       -");
+     741             : 
+     742             :                 /* if some fail/prefail attribute, make the command to fail */
+     743          16 :                 if (flag & (SMARTCTL_FLAG_FAIL | SMARTCTL_FLAG_PREFAIL))
+     744           2 :                         make_it_fail = 1;
+     745             : 
+     746             :                 /* note that in older smartmontools, like 5.x, rotation rate is not present */
+     747             :                 /* and then it could remain unassigned */
+     748             : 
+     749          16 :                 if (flag & (SMARTCTL_FLAG_UNSUPPORTED | SMARTCTL_FLAG_OPEN)) {
+     750             :                         /* if error running smartctl, skip AFR estimation */
+     751           2 :                         afr = 0;
+     752           2 :                         printf("  n/a");
+     753          14 :                 } else if (devinfo->smart[SMART_ROTATION_RATE] == 0) {
+     754             :                         /* if SSD, skip AFR estimation as data is from not SSD disks */
+     755           1 :                         afr = 0;
+     756           1 :                         printf("  SSD");
+     757             :                 } else {
+     758          13 :                         afr = smart_afr(devinfo->smart);
+     759             : 
+     760          13 :                         if (afr == 0) {
+     761             :                                 /* this happens only if no data */
+     762           1 :                                 printf("    -");
+     763             :                         } else {
+     764             :                                 /* use only the disks in the array */
+     765          12 :                                 if (devinfo->parent != 0 || !have_parent)
+     766          12 :                                         array_failure_rate += afr;
+     767             : 
+     768          12 :                                 printf("%4.0f%%", poisson_prob_n_or_more_failures(afr, 1) * 100);
+     769             :                         }
+     770             :                 }
+     771             : 
+     772          16 :                 if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED)
+     773          15 :                         printf(" %4.1f", devinfo->smart[SMART_SIZE] / 1E12);
+     774             :                 else
+     775           1 :                         printf("    -");
+     776             : 
+     777          16 :                 printf("  ");
+     778          16 :                 if (*devinfo->smart_serial)
+     779          15 :                         printl(devinfo->smart_serial, serial_pad);
+     780             :                 else
+     781           1 :                         printl("-", serial_pad);
+     782             : 
+     783          16 :                 printf("  ");
+     784          16 :                 if (*devinfo->file)
+     785          15 :                         printl(devinfo->file, device_pad);
+     786             :                 else
+     787           1 :                         printl("-", device_pad);
+     788             : 
+     789          16 :                 printf("  ");
+     790          16 :                 if (*devinfo->name)
+     791          15 :                         printf("%s", devinfo->name);
+     792             :                 else
+     793           1 :                         printf("-");
+     794             : 
+     795          16 :                 printf("\n");
+     796             : 
+     797          16 :                 log_tag("smart:%s:%s\n", devinfo->file, devinfo->name);
+     798          16 :                 if (devinfo->smart_serial[0])
+     799          15 :                         log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc(devinfo->smart_serial));
+     800          16 :                 if (afr != 0)
+     801          12 :                         log_tag("attr:%s:%s:afr:%g\n", devinfo->file, devinfo->name, afr);
+     802          16 :                 if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED)
+     803          15 :                         log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]);
+     804          16 :                 if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED)
+     805          16 :                         log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]);
+     806          16 :                 if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED)
+     807          16 :                         log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]);
+     808          16 :                 if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED)
+     809           8 :                         log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]);
+     810        4112 :                 for (j = 0; j < 256; ++j)
+     811        4096 :                         if (devinfo->smart[j] != SMART_UNASSIGNED)
+     812        3840 :                                 log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]);
+     813             :         }
+     814             : 
+     815           1 :         printf("\n");
+     816             : 
+     817             :         /*      |<##################################################################72>|####80>| */
+     818           1 :         printf("The FP column is the estimated probability (in percentage) that the disk\n");
+     819           1 :         printf("is going to fail in the next year.\n");
+     820           1 :         printf("\n");
+     821             : 
+     822             :         /*
+     823             :          * The probability of one and of at least one failure is computed assuming
+     824             :          * a Poisson distribution with the estimated array failure rate.
+     825             :          */
+     826           1 :         p_at_least_one_failure = poisson_prob_n_or_more_failures(array_failure_rate, 1);
+     827             : 
+     828           1 :         printf("Probability that at least one disk is going to fail in the next year is %.0f%%.\n", p_at_least_one_failure * 100);
+     829           1 :         log_tag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure);
+     830             : 
+     831             :         /* prints extra stats only in verbose mode */
+     832           1 :         if (msg_level < MSG_VERBOSE)
+     833           0 :                 goto bail;
+     834             : 
+     835             :         /*      |<##################################################################72>|####80>| */
+     836           1 :         printf("\n");
+     837           1 :         printf("Probability of data loss in the next year for different parity and\n");
+     838           1 :         printf("combined scrub and repair time:\n");
+     839           1 :         printf("\n");
+     840           1 :         printf("  Parity  1 Week                1 Month             3 Months\n");
+     841           1 :         printf(" -----------------------------------------------------------------------\n");
+     842           7 :         for (j = 0; j < RAID_PARITY_MAX; ++j) {
+     843           6 :                 printf("%6u", j + 1);
+     844           6 :                 printf("    ");
+     845           6 :                 printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 7, n, j + 1) * 100, 19);
+     846           6 :                 printf("    ");
+     847           6 :                 printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 30, n, j + 1) * 100, 17);
+     848           6 :                 printf("    ");
+     849           6 :                 printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 90, n, j + 1) * 100, 13);
+     850           6 :                 printf("\n");
+     851             :         }
+     852             : 
+     853           1 :         printf("\n");
+     854             : 
+     855             :         /*      |<##################################################################72>|####80>| */
+     856           1 :         printf("These values are the probabilities that in the next year you'll have a\n");
+     857           1 :         printf("sequence of failures that the parity WONT be able to recover, assuming\n");
+     858           1 :         printf("that you regularly scrub, and in case repair, the array in the specified\n");
+     859           1 :         printf("time.\n");
+     860             : 
+     861             : bail:
+     862           1 :         if (make_it_fail) {
+     863           1 :                 printf("\n");
+     864           1 :                 printf("DANGER! SMART is reporting that one or more disks are FAILING!\n");
+     865           1 :                 printf("Please take immediate action!\n");
+     866           1 :                 exit(EXIT_FAILURE);
+     867             :         }
+     868           0 : }
+     869             : 
+     870             : /**
+     871             :  * Fill with fake data the device list.
+     872             :  */
+     873           1 : static int devtest(tommy_list* low, int operation)
+     874             : {
+     875             :         unsigned c;
+     876             : 
+     877           1 :         if (operation != DEVICE_SMART)
+     878           0 :                 return -1;
+     879             : 
+     880             :         /* add some fake data */
+     881          17 :         for (c = 0; c < 16; ++c) {
+     882             :                 devinfo_t* entry;
+     883             :                 int j;
+     884             : 
+     885          16 :                 entry = calloc_nofail(1, sizeof(devinfo_t));
+     886             : 
+     887          16 :                 entry->device = c;
+     888             : 
+     889          16 :                 tommy_list_insert_tail(low, &entry->node, entry);
+     890             : 
+     891        4112 :                 for (j = 0; j < 256; ++j) {
+     892        4096 :                         switch (c) {
+     893         256 :                         case 0 : entry->smart[j] = 0; break;
+     894         256 :                         case 1 : entry->smart[j] = SMART_UNASSIGNED; break;
+     895        3584 :                         default : entry->smart[j] = c; break;
+     896             :                         }
+     897             :                 }
+     898             : 
+     899          16 :                 if (c == 0) {
+     900           1 :                         entry->smart_serial[0] = 0;
+     901           1 :                         entry->file[0] = 0;
+     902           1 :                         entry->name[0] = 0;
+     903           1 :                         entry->smart[SMART_SIZE] = SMART_UNASSIGNED;
+     904           1 :                         entry->smart[SMART_ROTATION_RATE] = 0;
+     905             :                 } else {
+     906          15 :                         snprintf(entry->smart_serial, sizeof(entry->smart_serial), "%u", c);
+     907          15 :                         pathcpy(entry->file, sizeof(entry->name), "file");
+     908          15 :                         pathcpy(entry->name, sizeof(entry->name), "name");
+     909          15 :                         entry->smart[SMART_SIZE] = c * TERA;
+     910          15 :                         entry->smart[SMART_ROTATION_RATE] = 7200;
+     911             :                 }
+     912             : 
+     913          16 :                 entry->smart[SMART_ERROR] = 0;
+     914          16 :                 entry->smart[SMART_FLAGS] = SMART_UNASSIGNED;
+     915             : 
+     916          16 :                 switch (c) {
+     917           1 :                 case 3 : entry->smart[SMART_ERROR] = 1; break;
+     918           1 :                 case 4 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_UNSUPPORTED; break;
+     919           1 :                 case 5 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_COMMAND; break;
+     920           1 :                 case 6 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_OPEN; break;
+     921           1 :                 case 7 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_FAIL; break;
+     922           1 :                 case 8 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL; break;
+     923           1 :                 case 9 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL_LOGGED; break;
+     924           1 :                 case 10 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR; break;
+     925           1 :                 case 11 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR_LOGGED; break;
+     926             :                 }
+     927             :         }
+     928             : 
+     929           1 :         return 0;
+     930             : }
+     931             : 
+     932           5 : void state_device(struct snapraid_state* state, int operation)
+     933             : {
+     934             :         tommy_node* i;
+     935             :         unsigned j;
+     936             :         tommy_list high;
+     937             :         tommy_list low;
+     938             :         int ret;
+     939             : 
+     940           5 :         switch (operation) {
+     941           1 :         case DEVICE_UP : msg_progress("Spinup...\n"); break;
+     942           1 :         case DEVICE_DOWN : msg_progress("Spindown...\n"); break;
+     943             :         }
+     944             : 
+     945           5 :         tommy_list_init(&high);
+     946           5 :         tommy_list_init(&low);
+     947             : 
+     948             :         /* for all disks */
+     949          35 :         for (i = state->disklist; i != 0; i = i->next) {
+     950          30 :                 struct snapraid_disk* disk = i->data;
+     951             :                 devinfo_t* entry;
+     952             : 
+     953          30 :                 entry = calloc_nofail(1, sizeof(devinfo_t));
+     954             : 
+     955          30 :                 entry->device = disk->device;
+     956          30 :                 pathcpy(entry->name, sizeof(entry->name), disk->name);
+     957          30 :                 pathcpy(entry->mount, sizeof(entry->mount), disk->dir);
+     958          30 :                 pathcpy(entry->smartctl, sizeof(entry->smartctl), disk->smartctl);
+     959             : 
+     960          30 :                 tommy_list_insert_tail(&high, &entry->node, entry);
+     961             :         }
+     962             : 
+     963             :         /* for all parities */
+     964          35 :         for (j = 0; j < state->level; ++j) {
+     965             :                 devinfo_t* entry;
+     966             : 
+     967          30 :                 entry = calloc_nofail(1, sizeof(devinfo_t));
+     968             : 
+     969          30 :                 entry->device = state->parity[j].device;
+     970          30 :                 pathcpy(entry->name, sizeof(entry->name), lev_config_name(j));
+     971          30 :                 pathcpy(entry->mount, sizeof(entry->mount), state->parity[j].path);
+     972          30 :                 pathcpy(entry->smartctl, sizeof(entry->smartctl), state->parity[j].smartctl);
+     973          30 :                 pathcut(entry->mount); /* remove the parity file */
+     974             : 
+     975          30 :                 tommy_list_insert_tail(&high, &entry->node, entry);
+     976             :         }
+     977             : 
+     978           5 :         if (state->opt.fake_device)
+     979           1 :                 ret = devtest(&low, operation);
+     980             :         else
+     981           4 :                 ret = devquery(&high, &low, operation);
+     982             : 
+     983           5 :         if (ret != 0) {
+     984           2 :                 const char* ope = 0;
+     985           2 :                 switch (operation) {
+     986           0 :                 case DEVICE_UP : ope = "Spinup"; break;
+     987           1 :                 case DEVICE_DOWN : ope = "Spindown"; break;
+     988           0 :                 case DEVICE_LIST : ope = "List"; break;
+     989           1 :                 case DEVICE_SMART : ope = "SMART"; break;
+     990             :                 }
+     991           2 :                 log_fatal("%s unsupported in this platform.\n", ope);
+     992             :         } else {
+     993           3 :                 if (operation == DEVICE_LIST) {
+     994          13 :                         for (i = tommy_list_head(&low); i != 0; i = i->next) {
+     995          12 :                                 devinfo_t* devinfo = i->data;
+     996          12 :                                 devinfo_t* parent = devinfo->parent;
+     997             : #ifdef _WIN32
+     998             :                                 printf("%" PRIu64 "\t%s\t%08" PRIx64 "\t%s\t%s\n", devinfo->device, devinfo->wfile, parent->device, parent->wfile, parent->name);
+     999             : #else
+    1000          12 :                                 printf("%u:%u\t%s\t%u:%u\t%s\t%s\n", major(devinfo->device), minor(devinfo->device), devinfo->file, major(parent->device), minor(parent->device), parent->file, parent->name);
+    1001             : #endif
+    1002             :                         }
+    1003             :                 }
+    1004             : 
+    1005           3 :                 if (operation == DEVICE_SMART)
+    1006           1 :                         state_smart(state->level + tommy_list_count(&state->disklist), &low);
+    1007             :         }
+    1008             : 
+    1009           4 :         tommy_list_foreach(&high, free);
+    1010           4 :         tommy_list_foreach(&low, free);
+    1011           4 : }
+    1012             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dry.c.func-sort-c.html b/cov/cmdline/dry.c.func-sort-c.html new file mode 100644 index 00000000..5e06b2ba --- /dev/null +++ b/cov/cmdline/dry.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/dry.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dry.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:728485.7 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_dry2
state_dry_process2
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dry.c.func.html b/cov/cmdline/dry.c.func.html new file mode 100644 index 00000000..3f868cd0 --- /dev/null +++ b/cov/cmdline/dry.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/dry.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dry.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:728485.7 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_dry2
state_dry_process2
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dry.c.gcov.html b/cov/cmdline/dry.c.gcov.html new file mode 100644 index 00000000..523840bc --- /dev/null +++ b/cov/cmdline/dry.c.gcov.html @@ -0,0 +1,335 @@ + + + + + + + LCOV - lcov.info - cmdline/dry.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dry.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:728485.7 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "util.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : 
+      26             : /****************************************************************************/
+      27             : /* dry */
+      28             : 
+      29           2 : static int state_dry_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax)
+      30             : {
+      31             :         struct snapraid_handle* handle;
+      32             :         unsigned diskmax;
+      33             :         block_off_t i;
+      34             :         unsigned j;
+      35             :         void* buffer_alloc;
+      36             :         unsigned char* buffer_aligned;
+      37             :         int ret;
+      38             :         data_off_t countsize;
+      39             :         block_off_t countpos;
+      40             :         block_off_t countmax;
+      41             :         unsigned error;
+      42             :         unsigned l;
+      43             : 
+      44           2 :         handle = handle_map(state, &diskmax);
+      45             : 
+      46           2 :         buffer_aligned = malloc_nofail_align(state->block_size, &buffer_alloc);
+      47             : 
+      48           2 :         error = 0;
+      49             : 
+      50             :         /* drop until now */
+      51           2 :         state_usage_waste(state);
+      52             : 
+      53           2 :         countmax = blockmax - blockstart;
+      54           2 :         countsize = 0;
+      55           2 :         countpos = 0;
+      56           2 :         state_progress_begin(state, blockstart, blockmax, countmax);
+      57        7054 :         for (i = blockstart; i < blockmax; ++i) {
+      58             :                 /* for each disk, process the block */
+      59       49364 :                 for (j = 0; j < diskmax; ++j) {
+      60             :                         int read_size;
+      61       42312 :                         struct snapraid_block* block = BLOCK_EMPTY;
+      62       42312 :                         struct snapraid_disk* disk = handle[j].disk;
+      63             : 
+      64       42312 :                         if (!disk) {
+      65             :                                 /* if no disk, nothing to do */
+      66        4671 :                                 continue;
+      67             :                         }
+      68             : 
+      69       37641 :                         block = disk_block_get(disk, i);
+      70             : 
+      71       37641 :                         if (!block_has_file(block)) {
+      72             :                                 /* if no file, nothing to do */
+      73         413 :                                 continue;
+      74             :                         }
+      75             : 
+      76             :                         /* until now is CPU */
+      77       37228 :                         state_usage_cpu(state);
+      78             : 
+      79             :                         /* if the file is closed or different than the current one */
+      80       37228 :                         if (handle[j].file == 0 || handle[j].file != block_file_get(block)) {
+      81       15082 :                                 struct snapraid_file* file = handle[j].file;
+      82       15082 :                                 if (file != 0) {
+      83       15071 :                                         ret = handle_close(&handle[j]);
+      84       15071 :                                         if (ret == -1) {
+      85             :                                                 /* LCOV_EXCL_START */
+      86             :                                                 log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+      87             :                                                 log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n");
+      88             :                                                 log_fatal("Stopping at block %u\n", i);
+      89             :                                                 ++error;
+      90             :                                                 goto bail;
+      91             :                                                 /* LCOV_EXCL_STOP */
+      92             :                                         }
+      93             :                                 }
+      94             : 
+      95             :                                 /* open the file only for reading */
+      96       15082 :                                 ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_fatal, 0);
+      97       15082 :                                 if (ret == -1) {
+      98             :                                         /* LCOV_EXCL_START */
+      99             :                                         log_fatal("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n");
+     100             :                                         log_fatal("Stopping at block %u\n", i);
+     101             :                                         ++error;
+     102             :                                         goto bail;
+     103             :                                         /* LCOV_EXCL_STOP */
+     104             :                                 }
+     105             :                         }
+     106             : 
+     107             :                         /* read from the file */
+     108       37228 :                         read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, log_error, 0);
+     109       37228 :                         if (read_size == -1) {
+     110           0 :                                 log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block));
+     111           0 :                                 ++error;
+     112           0 :                                 continue;
+     113             :                         }
+     114             : 
+     115             :                         /* until now is disk */
+     116       37228 :                         state_usage_disk(state, disk);
+     117             : 
+     118       37228 :                         countsize += read_size;
+     119             :                 }
+     120             : 
+     121             :                 /* read the parity */
+     122       49364 :                 for (l = 0; l < state->level; ++l) {
+     123       42312 :                         if (parity[l]) {
+     124             :                                 /* until now is CPU */
+     125       42312 :                                 state_usage_cpu(state);
+     126             : 
+     127       42312 :                                 ret = parity_read(parity[l], i, buffer_aligned, state->block_size, log_error);
+     128       42312 :                                 if (ret == -1) {
+     129           0 :                                         log_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l));
+     130           0 :                                         ++error;
+     131             :                                 }
+     132             : 
+     133             :                                 /* until now is parity */
+     134       42312 :                                 state_usage_parity(state, l);
+     135             :                         }
+     136             :                 }
+     137             : 
+     138             :                 /* count the number of processed block */
+     139        7052 :                 ++countpos;
+     140             : 
+     141             :                 /* progress */
+     142        7052 :                 if (state_progress(state, i, countpos, countmax, countsize)) {
+     143             :                         /* LCOV_EXCL_START */
+     144             :                         break;
+     145             :                         /* LCOV_EXCL_STOP */
+     146             :                 }
+     147             :         }
+     148             : 
+     149           2 :         state_progress_end(state, countpos, countmax, countsize);
+     150             : 
+     151           2 :         state_usage_print(state);
+     152             : 
+     153             : bail:
+     154             :         /* close all the files left open */
+     155          14 :         for (j = 0; j < diskmax; ++j) {
+     156          12 :                 struct snapraid_file* file = handle[j].file;
+     157          12 :                 struct snapraid_disk* disk = handle[j].disk;
+     158          12 :                 ret = handle_close(&handle[j]);
+     159          12 :                 if (ret == -1) {
+     160             :                         /* LCOV_EXCL_START */
+     161             :                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     162             :                         log_fatal("DANGER! Unexpected close error in a data disk.\n");
+     163             :                         ++error;
+     164             :                         /* continue, as we are already exiting */
+     165             :                         /* LCOV_EXCL_STOP */
+     166             :                 }
+     167             :         }
+     168             : 
+     169           2 :         if (error) {
+     170           0 :                 msg_status("\n");
+     171           0 :                 msg_status("%8u errors\n", error);
+     172             :         } else {
+     173           2 :                 msg_status("Everything OK\n");
+     174             :         }
+     175             : 
+     176           2 :         if (error)
+     177           0 :                 log_fatal("DANGER! Unexpected errors!\n");
+     178             : 
+     179           2 :         free(handle);
+     180           2 :         free(buffer_alloc);
+     181             : 
+     182           2 :         if (error != 0)
+     183           0 :                 return -1;
+     184           2 :         return 0;
+     185             : }
+     186             : 
+     187           2 : void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount)
+     188             : {
+     189             :         block_off_t blockmax;
+     190             :         int ret;
+     191             :         struct snapraid_parity_handle parity[LEV_MAX];
+     192             :         /* the following initialization is to avoid clang warnings about */
+     193             :         /* potential state->level change, that never happens */
+     194           2 :         struct snapraid_parity_handle* parity_ptr[LEV_MAX] = { 0 };
+     195             :         unsigned error;
+     196             :         unsigned l;
+     197             : 
+     198           2 :         msg_progress("Drying...\n");
+     199             : 
+     200           2 :         blockmax = parity_allocated_size(state);
+     201             : 
+     202           2 :         if (blockstart > blockmax) {
+     203             :                 /* LCOV_EXCL_START */
+     204             :                 log_fatal("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax);
+     205             :                 exit(EXIT_FAILURE);
+     206             :                 /* LCOV_EXCL_STOP */
+     207             :         }
+     208             : 
+     209             :         /* adjust the number of block to process */
+     210           2 :         if (blockcount != 0 && blockstart + blockcount < blockmax) {
+     211           0 :                 blockmax = blockstart + blockcount;
+     212             :         }
+     213             : 
+     214             :         /* open the file for reading */
+     215             :         /* it may fail if the file doesn't exist, in this case we continue to dry the files */
+     216          14 :         for (l = 0; l < state->level; ++l) {
+     217          12 :                 parity_ptr[l] = &parity[l];
+     218          12 :                 ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode);
+     219          12 :                 if (ret == -1) {
+     220           0 :                         msg_status("No accessible %s file.\n", lev_name(l));
+     221             :                         /* continue anyway */
+     222           0 :                         parity_ptr[l] = 0;
+     223             :                 }
+     224             :         }
+     225             : 
+     226           2 :         error = 0;
+     227             : 
+     228             :         /* skip degenerated cases of empty parity, or skipping all */
+     229           2 :         if (blockstart < blockmax) {
+     230           2 :                 ret = state_dry_process(state, parity_ptr, blockstart, blockmax);
+     231           2 :                 if (ret == -1) {
+     232             :                         /* LCOV_EXCL_START */
+     233             :                         ++error;
+     234             :                         /* continue, as we are already exiting */
+     235             :                         /* LCOV_EXCL_STOP */
+     236             :                 }
+     237             :         }
+     238             : 
+     239             :         /* try to close only if opened */
+     240          14 :         for (l = 0; l < state->level; ++l) {
+     241          12 :                 if (parity_ptr[l]) {
+     242          12 :                         ret = parity_close(parity_ptr[l]);
+     243          12 :                         if (ret == -1) {
+     244             :                                 /* LCOV_EXCL_START */
+     245             :                                 ++error;
+     246             :                                 /* continue, as we are already exiting */
+     247             :                                 /* LCOV_EXCL_STOP */
+     248             :                         }
+     249             :                 }
+     250             :         }
+     251             : 
+     252             :         /* abort if required */
+     253           2 :         if (error != 0) {
+     254             :                 /* LCOV_EXCL_START */
+     255             :                 exit(EXIT_FAILURE);
+     256             :                 /* LCOV_EXCL_STOP */
+     257             :         }
+     258           2 : }
+     259             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dup.c.func-sort-c.html b/cov/cmdline/dup.c.func-sort-c.html new file mode 100644 index 00000000..e3579b53 --- /dev/null +++ b/cov/cmdline/dup.c.func-sort-c.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - cmdline/dup.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dup.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:566093.3 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hash_alloc16957
hash_free16957
hash_hash16957
state_dup3
hash_compare2
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dup.c.func.html b/cov/cmdline/dup.c.func.html new file mode 100644 index 00000000..7743b9f3 --- /dev/null +++ b/cov/cmdline/dup.c.func.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - cmdline/dup.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dup.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:566093.3 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hash_alloc16957
hash_compare2
hash_free16957
hash_hash16957
state_dup3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/dup.c.gcov.html b/cov/cmdline/dup.c.gcov.html new file mode 100644 index 00000000..a99c1273 --- /dev/null +++ b/cov/cmdline/dup.c.gcov.html @@ -0,0 +1,232 @@ + + + + + + + LCOV - lcov.info - cmdline/dup.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - dup.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:566093.3 %
Date:2015-05-12Functions:55100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "util.h"
+      22             : #include "elem.h"
+      23             : #include "state.h"
+      24             : #include "parity.h"
+      25             : #include "handle.h"
+      26             : 
+      27             : /****************************************************************************/
+      28             : /* dup */
+      29             : 
+      30             : struct snapraid_hash {
+      31             :         struct snapraid_disk* disk; /**< Disk. */
+      32             :         struct snapraid_file* file; /**< File. */
+      33             :         unsigned char hash[HASH_SIZE]; /**< Hash of the whole file. */
+      34             : 
+      35             :         /* nodes for data structures */
+      36             :         tommy_hashdyn_node node;
+      37             : };
+      38             : 
+      39       16957 : struct snapraid_hash* hash_alloc(struct snapraid_state* state, struct snapraid_disk* disk, struct snapraid_file* file)
+      40             : {
+      41             :         struct snapraid_hash* hash;
+      42             :         block_off_t i;
+      43             :         unsigned char* buf;
+      44             : 
+      45       16957 :         hash = malloc_nofail(sizeof(struct snapraid_hash));
+      46       16957 :         hash->disk = disk;
+      47       16957 :         hash->file = file;
+      48             : 
+      49       16957 :         buf = malloc_nofail(file->blockmax * HASH_SIZE);
+      50             : 
+      51             :         /* set the back pointer */
+      52       58818 :         for (i = 0; i < file->blockmax; ++i) {
+      53       41861 :                 memcpy(buf + i * HASH_SIZE, file->blockvec[i].hash, HASH_SIZE);
+      54             : 
+      55       41861 :                 if (!block_has_updated_hash(&file->blockvec[i])) {
+      56           0 :                         free(buf);
+      57           0 :                         free(hash);
+      58           0 :                         return 0;
+      59             :                 }
+      60             :         }
+      61             : 
+      62       16957 :         memhash(state->besthash, state->hashseed, hash->hash, buf, file->blockmax * HASH_SIZE);
+      63             : 
+      64       16957 :         free(buf);
+      65             : 
+      66       16957 :         return hash;
+      67             : }
+      68             : 
+      69       16957 : static inline tommy_uint32_t hash_hash(struct snapraid_hash* hash)
+      70             : {
+      71       16957 :         return tommy_hash_u32(0, hash->hash, HASH_SIZE);
+      72             : }
+      73             : 
+      74       16957 : void hash_free(struct snapraid_hash* hash)
+      75             : {
+      76       16957 :         free(hash);
+      77       16957 : }
+      78             : 
+      79           2 : int hash_compare(const void* void_arg, const void* void_data)
+      80             : {
+      81           2 :         const char* arg = void_arg;
+      82           2 :         const struct snapraid_hash* hash = void_data;
+      83             : 
+      84           2 :         return memcmp(arg, hash->hash, HASH_SIZE);
+      85             : }
+      86             : 
+      87           3 : void state_dup(struct snapraid_state* state)
+      88             : {
+      89             :         tommy_hashdyn hashset;
+      90             :         tommy_node* i;
+      91             :         unsigned count;
+      92             :         data_off_t size;
+      93             : 
+      94           3 :         tommy_hashdyn_init(&hashset);
+      95             : 
+      96           3 :         count = 0;
+      97           3 :         size = 0;
+      98             : 
+      99           3 :         msg_progress("Comparing...\n");
+     100             : 
+     101             :         /* for each disk */
+     102          21 :         for (i = state->disklist; i != 0; i = i->next) {
+     103             :                 tommy_node* j;
+     104          18 :                 struct snapraid_disk* disk = i->data;
+     105             : 
+     106             :                 /* for each file */
+     107       16997 :                 for (j = disk->filelist; j != 0; j = j->next) {
+     108       16979 :                         struct snapraid_file* file = j->data;
+     109             :                         struct snapraid_hash* hash;
+     110             :                         tommy_hash_t hash32;
+     111             : 
+     112             :                         /* if empty, skip it */
+     113       16979 :                         if (file->size == 0)
+     114          22 :                                 continue;
+     115             : 
+     116       16957 :                         hash = hash_alloc(state, disk, file);
+     117             : 
+     118             :                         /* if no hash, skip it */
+     119       16957 :                         if (!hash)
+     120           0 :                                 continue;
+     121             : 
+     122       16957 :                         hash32 = hash_hash(hash);
+     123             : 
+     124       16957 :                         struct snapraid_hash* dup = tommy_hashdyn_search(&hashset, hash_compare, hash->hash, hash32);
+     125       16957 :                         if (dup) {
+     126           2 :                                 ++count;
+     127           2 :                                 size += dup->file->size;
+     128           2 :                                 log_tag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, esc(file->sub), dup->disk->name, esc(dup->file->sub), dup->file->size);
+     129           2 :                                 printf("%12" PRIu64 " %s%s = %s%s\n", file->size, disk->dir, file->sub, dup->disk->dir, dup->file->sub);
+     130           2 :                                 hash_free(hash);
+     131             :                         } else {
+     132       16955 :                                 tommy_hashdyn_insert(&hashset, &hash->node, hash, hash32);
+     133             :                         }
+     134             :                 }
+     135             :         }
+     136             : 
+     137           3 :         tommy_hashdyn_foreach(&hashset, (tommy_foreach_func*)hash_free);
+     138           3 :         tommy_hashdyn_done(&hashset);
+     139             : 
+     140           3 :         msg_status("\n");
+     141           3 :         msg_status("%8u duplicates, for %" PRIu64 " GB\n", count, size / GIGA);
+     142           3 :         if (count)
+     143           2 :                 msg_status("There are duplicates!\n");
+     144             :         else
+     145           1 :                 msg_status("No duplicates\n");
+     146             : 
+     147           3 :         log_tag("summary:dup_count:%u\n", count);
+     148           3 :         log_tag("summary:dup_size:%" PRIu64 "\n", size);
+     149           3 :         if (count == 0) {
+     150           1 :                 log_tag("summary:exit:unique\n");
+     151             :         } else {
+     152           2 :                 log_tag("summary:exit:dup\n");
+     153             :         }
+     154           3 :         log_flush();
+     155           3 : }
+     156             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.c.func-sort-c.html b/cov/cmdline/elem.c.func-sort-c.html new file mode 100644 index 00000000..6877b0d7 --- /dev/null +++ b/cov/cmdline/elem.c.func-sort-c.html @@ -0,0 +1,260 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:35038491.1 %
Date:2015-05-12Functions:454795.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_file_pos14832379
filter_apply11927105
block_file_size6527495
filter_recurse5969644
block_is_last5375510
file_alloc3578529
file_free3426080
filter_element3187555
filter_path3184635
filter_content3039576
file_inode_compare_to_arg848716
info_time_compare665521
deleted_alloc164533
deleted_free163984
deleted_dup135934
file_path_compare125441
filter_type125397
link_alloc115744
link_free110535
file_path_compare_to_arg98966
filter_existence80652
file_physical_compare52928
file_name47808
filter_correctness38818
link_name_compare_to_arg29409
file_namestamp_compare23904
file_name_compare23904
file_stamp_compare23658
file_copy6145
filter_dir2920
disk_alloc1411
map_alloc1381
content_alloc1362
disk_free1303
map_free1279
link_alpha_compare1252
content_free1241
dir_alloc760
disk_is_empty720
dir_free716
filter_alloc_file473
filter_free440
dir_name_compare209
file_rename155
filter_alloc_disk3
file_pathstamp_compare0
file_inode_compare0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.c.func.html b/cov/cmdline/elem.c.func.html new file mode 100644 index 00000000..4187c4c6 --- /dev/null +++ b/cov/cmdline/elem.c.func.html @@ -0,0 +1,260 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:35038491.1 %
Date:2015-05-12Functions:454795.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_file_pos14832379
block_file_size6527495
block_is_last5375510
content_alloc1362
content_free1241
deleted_alloc164533
deleted_dup135934
deleted_free163984
dir_alloc760
dir_free716
dir_name_compare209
disk_alloc1411
disk_free1303
disk_is_empty720
file_alloc3578529
file_copy6145
file_free3426080
file_inode_compare0
file_inode_compare_to_arg848716
file_name47808
file_name_compare23904
file_namestamp_compare23904
file_path_compare125441
file_path_compare_to_arg98966
file_pathstamp_compare0
file_physical_compare52928
file_rename155
file_stamp_compare23658
filter_alloc_disk3
filter_alloc_file473
filter_apply11927105
filter_content3039576
filter_correctness38818
filter_dir2920
filter_element3187555
filter_existence80652
filter_free440
filter_path3184635
filter_recurse5969644
filter_type125397
info_time_compare665521
link_alloc115744
link_alpha_compare1252
link_free110535
link_name_compare_to_arg29409
map_alloc1381
map_free1279
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.c.gcov.html b/cov/cmdline/elem.c.gcov.html new file mode 100644 index 00000000..770fd0bf --- /dev/null +++ b/cov/cmdline/elem.c.gcov.html @@ -0,0 +1,869 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:35038491.1 %
Date:2015-05-12Functions:454795.7 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "elem.h"
+      21             : #include "support.h"
+      22             : #include "util.h"
+      23             : 
+      24             : /****************************************************************************/
+      25             : /* snapraid */
+      26             : 
+      27        1362 : struct snapraid_content* content_alloc(const char* path, uint64_t dev)
+      28             : {
+      29             :         struct snapraid_content* content;
+      30             : 
+      31        1362 :         content = malloc_nofail(sizeof(struct snapraid_content));
+      32        1362 :         pathimport(content->content, sizeof(content->content), path);
+      33        1362 :         content->device = dev;
+      34             : 
+      35        1362 :         return content;
+      36             : }
+      37             : 
+      38        1241 : void content_free(struct snapraid_content* content)
+      39             : {
+      40        1241 :         free(content);
+      41        1241 : }
+      42             : 
+      43         473 : struct snapraid_filter* filter_alloc_file(int direction, const char* pattern)
+      44             : {
+      45             :         struct snapraid_filter* filter;
+      46             :         char* i;
+      47             :         char* first;
+      48             :         char* last;
+      49             : 
+      50         473 :         filter = malloc_nofail(sizeof(struct snapraid_filter));
+      51         473 :         pathimport(filter->pattern, sizeof(filter->pattern), pattern);
+      52         473 :         filter->direction = direction;
+      53             : 
+      54             :         /* find first and last slash */
+      55         473 :         first = 0;
+      56         473 :         last = 0;
+      57        5889 :         for (i = filter->pattern; *i; ++i) {
+      58        5416 :                 if (*i == '/') {
+      59           3 :                         if (!first)
+      60           2 :                                 first = i;
+      61           3 :                         last = i;
+      62             :                 }
+      63             :         }
+      64             : 
+      65             :         /* it's a file filter */
+      66         473 :         filter->is_disk = 0;
+      67             : 
+      68         473 :         if (first == 0) {
+      69             :                 /* no slash */
+      70         471 :                 filter->is_path = 0;
+      71         471 :                 filter->is_dir = 0;
+      72           2 :         } else if (first == last && last[1] == 0) {
+      73             :                 /* one slash at the end */
+      74           1 :                 filter->is_path = 0;
+      75           1 :                 filter->is_dir = 1;
+      76           1 :                 last[0] = 0;
+      77             :         } else {
+      78             :                 /* at least a slash not at the end */
+      79           1 :                 filter->is_path = 1;
+      80           1 :                 if (last[1] == 0) {
+      81           0 :                         filter->is_dir = 1;
+      82           0 :                         last[0] = 0;
+      83             :                 } else {
+      84           1 :                         filter->is_dir = 0;
+      85             :                 }
+      86             : 
+      87             :                 /* a slash must be the first char, as we reject PATH/DIR/FILE */
+      88           1 :                 if (filter->pattern[0] != '/') {
+      89             :                         /* LCOV_EXCL_START */
+      90             :                         free(filter);
+      91             :                         return 0;
+      92             :                         /* LCOV_EXCL_STOP */
+      93             :                 }
+      94             :         }
+      95             : 
+      96         473 :         return filter;
+      97             : }
+      98             : 
+      99           3 : struct snapraid_filter* filter_alloc_disk(int direction, const char* pattern)
+     100             : {
+     101             :         struct snapraid_filter* filter;
+     102             : 
+     103           3 :         filter = malloc_nofail(sizeof(struct snapraid_filter));
+     104           3 :         pathimport(filter->pattern, sizeof(filter->pattern), pattern);
+     105           3 :         filter->direction = direction;
+     106             : 
+     107             :         /* it's a disk filter */
+     108           3 :         filter->is_disk = 1;
+     109           3 :         filter->is_path = 0;
+     110           3 :         filter->is_dir = 0;
+     111             : 
+     112             :         /* no slash allowed in disk names */
+     113           3 :         if (strchr(filter->pattern, '/') != 0) {
+     114             :                 /* LCOV_EXCL_START */
+     115             :                 free(filter);
+     116             :                 return 0;
+     117             :                 /* LCOV_EXCL_STOP */
+     118             :         }
+     119             : 
+     120           3 :         return filter;
+     121             : }
+     122             : 
+     123         440 : void filter_free(struct snapraid_filter* filter)
+     124             : {
+     125         440 :         free(filter);
+     126         440 : }
+     127             : 
+     128      125397 : const char* filter_type(struct snapraid_filter* filter, char* out, size_t out_size)
+     129             : {
+     130             :         const char* direction;
+     131      125397 :         if (filter->direction < 0)
+     132      125162 :                 direction = "exclude";
+     133             :         else
+     134         235 :                 direction = "include";
+     135             : 
+     136      125397 :         if (filter->is_disk)
+     137           0 :                 pathprint(out, out_size, "%s %s:", direction, filter->pattern);
+     138      125397 :         else if (filter->is_dir)
+     139           0 :                 pathprint(out, out_size, "%s %s/", direction, filter->pattern);
+     140             :         else
+     141      125397 :                 pathprint(out, out_size, "%s %s", direction, filter->pattern);
+     142             : 
+     143      125397 :         return out;
+     144             : }
+     145             : 
+     146    11927105 : static int filter_apply(struct snapraid_filter* filter, struct snapraid_filter** reason, const char* path, const char* name, int is_dir)
+     147             : {
+     148    11927105 :         int ret = 0;
+     149             : 
+     150             :         /* matches dirs with dirs and files with files */
+     151    11927105 :         if (filter->is_dir && !is_dir)
+     152        2938 :                 return 0;
+     153    11924167 :         if (!filter->is_dir && is_dir)
+     154     5960270 :                 return 0;
+     155             : 
+     156     5963897 :         if (filter->is_path) {
+     157             :                 /* skip initial slash, as always missing from the path */
+     158        2938 :                 if (fnmatch(filter->pattern + 1, path, FNM_PATHNAME | FNM_CASEINSENSITIVE_FOR_WIN) == 0)
+     159           0 :                         ret = filter->direction;
+     160             :         } else {
+     161     5960959 :                 if (fnmatch(filter->pattern, name, FNM_CASEINSENSITIVE_FOR_WIN) == 0)
+     162      127917 :                         ret = filter->direction;
+     163             :         }
+     164             : 
+     165     5963897 :         if (reason != 0 && ret < 0)
+     166      124927 :                 *reason = filter;
+     167             : 
+     168     5963897 :         return ret;
+     169             : }
+     170             : 
+     171     5969644 : static int filter_recurse(struct snapraid_filter* filter, struct snapraid_filter** reason, const char* const_path, int is_dir)
+     172             : {
+     173             :         char path[PATH_MAX];
+     174             :         char* name;
+     175             :         unsigned i;
+     176             : 
+     177     5969644 :         pathcpy(path, sizeof(path), const_path);
+     178             : 
+     179             :         /* filter for all the directories */
+     180     5969644 :         name = path;
+     181    86217249 :         for (i = 0; path[i] != 0; ++i) {
+     182    80250595 :                 if (path[i] == '/') {
+     183             :                         /* set a terminator */
+     184     5960451 :                         path[i] = 0;
+     185             : 
+     186             :                         /* filter the directory */
+     187     5960451 :                         if (filter_apply(filter, reason, path, name, 1) != 0)
+     188        2990 :                                 return filter->direction;
+     189             : 
+     190             :                         /* restore the slash */
+     191     5957461 :                         path[i] = '/';
+     192             : 
+     193             :                         /* next name */
+     194     5957461 :                         name = path + i + 1;
+     195             :                 }
+     196             :         }
+     197             : 
+     198             :         /* filter the final file */
+     199     5966654 :         if (filter_apply(filter, reason, path, name, is_dir) != 0)
+     200      124927 :                 return filter->direction;
+     201             : 
+     202     5841727 :         return 0;
+     203             : }
+     204             : 
+     205     3187555 : static int filter_element(tommy_list* filterlist, struct snapraid_filter** reason, const char* disk, const char* sub, int is_dir)
+     206             : {
+     207             :         tommy_node* i;
+     208             : 
+     209     3187555 :         int direction = 1; /* by default include all */
+     210             : 
+     211             :         /* for each filter */
+     212     9072239 :         for (i = tommy_list_head(filterlist); i != 0; i = i->next) {
+     213             :                 int ret;
+     214     6021268 :                 struct snapraid_filter* filter = i->data;
+     215             : 
+     216     6021268 :                 if (filter->is_disk) {
+     217       51624 :                         if (fnmatch(filter->pattern, disk, FNM_CASEINSENSITIVE_FOR_WIN) == 0)
+     218        8667 :                                 ret = filter->direction;
+     219             :                         else
+     220       42957 :                                 ret = 0;
+     221       51624 :                         if (reason != 0 && ret < 0)
+     222           0 :                                 *reason = filter;
+     223             :                 } else {
+     224     5969644 :                         ret = filter_recurse(filter, reason, sub, is_dir);
+     225             :                 }
+     226             : 
+     227     6021268 :                 if (ret > 0) {
+     228             :                         /* include the file */
+     229       11657 :                         return 0;
+     230     6009611 :                 } else if (ret < 0) {
+     231             :                         /* exclude the file */
+     232      124927 :                         return -1;
+     233             :                 } else {
+     234             :                         /* default is opposite of the last filter */
+     235     5884684 :                         direction = -filter->direction;
+     236     5884684 :                         if (reason != 0 && direction < 0)
+     237     2977425 :                                 *reason = filter;
+     238             :                         /* continue with the next one */
+     239             :                 }
+     240             :         }
+     241             : 
+     242             :         /* directories are always included by default, otherwise we cannot apply rules */
+     243             :         /* to the contained files */
+     244     3050971 :         if (is_dir)
+     245        2919 :                 return 0;
+     246             : 
+     247             :         /* files are excluded/included depending of the last rule processed */
+     248     3048052 :         if (direction < 0)
+     249       45888 :                 return -1;
+     250             : 
+     251     3002164 :         return 0;
+     252             : }
+     253             : 
+     254     3184635 : int filter_path(tommy_list* filterlist, struct snapraid_filter** reason, const char* disk, const char* sub)
+     255             : {
+     256     3184635 :         return filter_element(filterlist, reason, disk, sub, 0);
+     257             : }
+     258             : 
+     259        2920 : int filter_dir(tommy_list* filterlist, struct snapraid_filter** reason, const char* disk, const char* sub)
+     260             : {
+     261        2920 :         return filter_element(filterlist, reason, disk, sub, 1);
+     262             : }
+     263             : 
+     264       80652 : int filter_existence(int filter_missing, const char* dir, const char* sub)
+     265             : {
+     266             :         char path[PATH_MAX];
+     267             :         struct stat st;
+     268             : 
+     269       80652 :         if (!filter_missing)
+     270       34956 :                 return 0;
+     271             : 
+     272             :         /* we directly check if in the disk the file is present or not */
+     273       45696 :         pathprint(path, sizeof(path), "%s%s", dir, sub);
+     274             : 
+     275       45696 :         if (lstat(path, &st) != 0) {
+     276             :                 /* if the file doesn't exist, we don't filter it out */
+     277        5019 :                 if (errno == ENOENT)
+     278        5019 :                         return 0;
+     279             :                 /* LCOV_EXCL_START */
+     280             :                 log_fatal("Error in stat file '%s'. %s.\n", path, strerror(errno));
+     281             :                 exit(EXIT_FAILURE);
+     282             :                 /* LCOV_EXCL_STOP */
+     283             :         }
+     284             : 
+     285             :         /* the file is present, so we filter it out */
+     286       40677 :         return 1;
+     287             : }
+     288             : 
+     289       38818 : int filter_correctness(int filter_error, tommy_arrayblkof* infoarr, struct snapraid_file* file)
+     290             : {
+     291             :         unsigned i;
+     292             : 
+     293       38818 :         if (!filter_error)
+     294       16290 :                 return 0;
+     295             : 
+     296             :         /* check each block of the file */
+     297       60129 :         for (i = 0; i < file->blockmax; ++i) {
+     298             :                 struct snapraid_block* block;
+     299             :                 snapraid_info info;
+     300             : 
+     301       46037 :                 block = &file->blockvec[i];
+     302             : 
+     303       46037 :                 info = info_get(infoarr, block->parity_pos);
+     304             : 
+     305             :                 /* if the file has a bad block, don't exclude it */
+     306       46037 :                 if (info_get_bad(info))
+     307        8436 :                         return 0;
+     308             :         }
+     309             : 
+     310             :         /* the file is correct, so we filter it out */
+     311       14092 :         return 1;
+     312             : }
+     313             : 
+     314     3039576 : int filter_content(tommy_list* contentlist, const char* path)
+     315             : {
+     316             :         tommy_node* i;
+     317             : 
+     318    39360526 :         for (i = tommy_list_head(contentlist); i != 0; i = i->next) {
+     319    16640687 :                 struct snapraid_content* content = i->data;
+     320             :                 char tmp[PATH_MAX];
+     321             : 
+     322    16640687 :                 if (pathcmp(content->content, path) == 0)
+     323           0 :                         return -1;
+     324             : 
+     325             :                 /* exclude also the ".tmp" copy used to save it */
+     326    16640687 :                 pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
+     327    16640687 :                 if (pathcmp(tmp, path) == 0)
+     328           0 :                         return -1;
+     329             : 
+     330             :                 /* exclude also the ".lock" file */
+     331    16640687 :                 pathprint(tmp, sizeof(tmp), "%s.lock", content->content);
+     332    16640687 :                 if (pathcmp(tmp, path) == 0)
+     333           0 :                         return -1;
+     334             :         }
+     335             : 
+     336     3039576 :         return 0;
+     337             : }
+     338             : 
+     339    14832379 : block_off_t block_file_pos(struct snapraid_block* block)
+     340             : {
+     341    14832379 :         struct snapraid_file* file = block_file_get(block);
+     342             : 
+     343    14832379 :         if (block < file->blockvec || block >= file->blockvec + file->blockmax) {
+     344             :                 /* LCOV_EXCL_START */
+     345             :                 log_fatal("Internal inconsistency in block %u ownership\n", block->parity_pos);
+     346             :                 exit(EXIT_FAILURE);
+     347             :                 /* LCOV_EXCL_STOP */
+     348             :         }
+     349             : 
+     350    14832379 :         return block - file->blockvec;
+     351             : }
+     352             : 
+     353     5375510 : int block_is_last(struct snapraid_block* block)
+     354             : {
+     355     5375510 :         struct snapraid_file* file = block_file_get(block);
+     356             : 
+     357     5375510 :         return block == file->blockvec + file->blockmax - 1;
+     358             : }
+     359             : 
+     360     6527495 : unsigned block_file_size(struct snapraid_block* block, unsigned block_size)
+     361             : {
+     362     6527495 :         block_off_t pos = block_file_pos(block);
+     363             : 
+     364             :         /* if it's the last block */
+     365     6527495 :         if (pos + 1 == block_file_get(block)->blockmax) {
+     366             :                 unsigned remainder;
+     367     2658644 :                 if (block_file_get(block)->size == 0)
+     368           0 :                         return 0;
+     369     2658644 :                 remainder = block_file_get(block)->size % block_size;
+     370     2658644 :                 if (remainder == 0)
+     371        1529 :                         remainder = block_size;
+     372     2658644 :                 return remainder;
+     373             :         }
+     374             : 
+     375     3868851 :         return block_size;
+     376             : }
+     377             : 
+     378      164533 : struct snapraid_deleted* deleted_alloc(void)
+     379             : {
+     380             :         struct snapraid_deleted* deleted;
+     381             : 
+     382      164533 :         deleted = malloc_nofail(sizeof(struct snapraid_deleted));
+     383             : 
+     384             :         /* set the state as deleted */
+     385      164533 :         deleted->block.file_mixed = BLOCK_STATE_DELETED;
+     386             : 
+     387      164533 :         return deleted;
+     388             : }
+     389             : 
+     390      135934 : struct snapraid_deleted* deleted_dup(struct snapraid_block* block)
+     391             : {
+     392             :         struct snapraid_deleted* deleted;
+     393             : 
+     394      135934 :         deleted = deleted_alloc();
+     395             : 
+     396             :         /* copy data from deleted block */
+     397      135934 :         deleted->block.parity_pos = block->parity_pos;
+     398      135934 :         memcpy(deleted->block.hash, block->hash, HASH_SIZE);
+     399             : 
+     400      135934 :         return deleted;
+     401             : }
+     402             : 
+     403      163984 : void deleted_free(struct snapraid_deleted* deleted)
+     404             : {
+     405      163984 :         free(deleted);
+     406      163984 : }
+     407             : 
+     408     3578529 : struct snapraid_file* file_alloc(unsigned block_size, const char* sub, data_off_t size, uint64_t mtime_sec, int mtime_nsec, uint64_t inode, uint64_t physical)
+     409             : {
+     410             :         struct snapraid_file* file;
+     411             :         block_off_t i;
+     412             : 
+     413     3578529 :         file = malloc_nofail(sizeof(struct snapraid_file));
+     414     3578529 :         file->sub = strdup_nofail(sub);
+     415     3578529 :         file->size = size;
+     416     3578529 :         file->blockmax = (size + block_size - 1) / block_size;
+     417     3578529 :         file->mtime_sec = mtime_sec;
+     418     3578529 :         file->mtime_nsec = mtime_nsec;
+     419     3578529 :         file->inode = inode;
+     420     3578529 :         file->physical = physical;
+     421     3578529 :         file->flag = 0;
+     422     3578529 :         file->blockvec = malloc_nofail(file->blockmax * sizeof(struct snapraid_block));
+     423             : 
+     424             :         /* set the back pointer */
+     425    12379416 :         for (i = 0; i < file->blockmax; ++i) {
+     426     8800887 :                 file->blockvec[i].parity_pos = POS_INVALID;
+     427     8800887 :                 file->blockvec[i].file_mixed = 0;
+     428             : 
+     429             :                 /* set the file */
+     430     8800887 :                 block_file_set(&file->blockvec[i], file);
+     431             : 
+     432             :                 /* set an invalid hash */
+     433     8800887 :                 block_state_set(&file->blockvec[i], BLOCK_STATE_CHG);
+     434     8800887 :                 hash_invalid_set(file->blockvec[i].hash);
+     435             :         }
+     436             : 
+     437     3578529 :         return file;
+     438             : }
+     439             : 
+     440     3426080 : void file_free(struct snapraid_file* file)
+     441             : {
+     442     3426080 :         free(file->sub);
+     443     3426080 :         free(file->blockvec);
+     444     3426080 :         free(file);
+     445     3426080 : }
+     446             : 
+     447         155 : void file_rename(struct snapraid_file* file, const char* sub)
+     448             : {
+     449         155 :         free(file->sub);
+     450         155 :         file->sub = strdup_nofail(sub);
+     451         155 : }
+     452             : 
+     453        6145 : void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file)
+     454             : {
+     455             :         block_off_t i;
+     456             : 
+     457        6145 :         if (src_file->size != dst_file->size) {
+     458             :                 /* LCOV_EXCL_START */
+     459             :                 log_fatal("Internal inconsistency in copy file with different size\n");
+     460             :                 exit(EXIT_FAILURE);
+     461             :                 /* LCOV_EXCL_STOP */
+     462             :         }
+     463             : 
+     464        6145 :         if (src_file->mtime_sec != dst_file->mtime_sec) {
+     465             :                 /* LCOV_EXCL_START */
+     466             :                 log_fatal("Internal inconsistency in copy file with different mtime_sec\n");
+     467             :                 exit(EXIT_FAILURE);
+     468             :                 /* LCOV_EXCL_STOP */
+     469             :         }
+     470             : 
+     471        6145 :         if (src_file->mtime_nsec != dst_file->mtime_nsec) {
+     472             :                 /* LCOV_EXCL_START */
+     473             :                 log_fatal("Internal inconsistency in copy file with different mtime_nsec\n");
+     474             :                 exit(EXIT_FAILURE);
+     475             :                 /* LCOV_EXCL_STOP */
+     476             :         }
+     477             : 
+     478       17785 :         for (i = 0; i < dst_file->blockmax; ++i) {
+     479             :                 /* set a block with hash computed but without parity */
+     480       11640 :                 block_state_set(&dst_file->blockvec[i], BLOCK_STATE_REP);
+     481             : 
+     482             :                 /* copy the hash */
+     483       11640 :                 memcpy(dst_file->blockvec[i].hash, src_file->blockvec[i].hash, HASH_SIZE);
+     484             :         }
+     485             : 
+     486        6145 :         file_flag_set(dst_file, FILE_IS_COPY);
+     487        6145 : }
+     488             : 
+     489       47808 : const char* file_name(const struct snapraid_file* file)
+     490             : {
+     491       47808 :         const char* r = strrchr(file->sub, '/');
+     492             : 
+     493       47808 :         if (!r)
+     494           6 :                 r = file->sub;
+     495             :         else
+     496       47802 :                 ++r;
+     497       47808 :         return r;
+     498             : }
+     499             : 
+     500      848716 : int file_inode_compare_to_arg(const void* void_arg, const void* void_data)
+     501             : {
+     502      848716 :         const uint64_t* arg = void_arg;
+     503      848716 :         const struct snapraid_file* file = void_data;
+     504             : 
+     505      848716 :         if (*arg < file->inode)
+     506           0 :                 return -1;
+     507      848716 :         if (*arg > file->inode)
+     508           0 :                 return 1;
+     509      848716 :         return 0;
+     510             : }
+     511             : 
+     512           0 : int file_inode_compare(const void* void_a, const void* void_b)
+     513             : {
+     514           0 :         const struct snapraid_file* file_a = void_a;
+     515           0 :         const struct snapraid_file* file_b = void_b;
+     516             : 
+     517           0 :         if (file_a->inode < file_b->inode)
+     518           0 :                 return -1;
+     519           0 :         if (file_a->inode > file_b->inode)
+     520           0 :                 return 1;
+     521           0 :         return 0;
+     522             : }
+     523             : 
+     524      125441 : int file_path_compare(const void* void_a, const void* void_b)
+     525             : {
+     526      125441 :         const struct snapraid_file* file_a = void_a;
+     527      125441 :         const struct snapraid_file* file_b = void_b;
+     528             : 
+     529      125441 :         return strcmp(file_a->sub, file_b->sub);
+     530             : }
+     531             : 
+     532       52928 : int file_physical_compare(const void* void_a, const void* void_b)
+     533             : {
+     534       52928 :         const struct snapraid_file* file_a = void_a;
+     535       52928 :         const struct snapraid_file* file_b = void_b;
+     536             : 
+     537       52928 :         if (file_a->physical < file_b->physical)
+     538       34086 :                 return -1;
+     539       18842 :         if (file_a->physical > file_b->physical)
+     540       18842 :                 return 1;
+     541           0 :         return 0;
+     542             : }
+     543             : 
+     544       98966 : int file_path_compare_to_arg(const void* void_arg, const void* void_data)
+     545             : {
+     546       98966 :         const char* arg = void_arg;
+     547       98966 :         const struct snapraid_file* file = void_data;
+     548             : 
+     549       98966 :         return strcmp(arg, file->sub);
+     550             : }
+     551             : 
+     552       23904 : int file_name_compare(const void* void_a, const void* void_b)
+     553             : {
+     554       23904 :         const struct snapraid_file* file_a = void_a;
+     555       23904 :         const struct snapraid_file* file_b = void_b;
+     556       23904 :         const char* name_a = file_name(file_a);
+     557       23904 :         const char* name_b = file_name(file_b);
+     558             : 
+     559       23904 :         return strcmp(name_a, name_b);
+     560             : }
+     561             : 
+     562       23658 : int file_stamp_compare(const void* void_a, const void* void_b)
+     563             : {
+     564       23658 :         const struct snapraid_file* file_a = void_a;
+     565       23658 :         const struct snapraid_file* file_b = void_b;
+     566             : 
+     567       23658 :         if (file_a->size < file_b->size)
+     568           0 :                 return -1;
+     569       23658 :         if (file_a->size > file_b->size)
+     570           0 :                 return 1;
+     571             : 
+     572       23658 :         if (file_a->mtime_sec < file_b->mtime_sec)
+     573           0 :                 return -1;
+     574       23658 :         if (file_a->mtime_sec > file_b->mtime_sec)
+     575           0 :                 return 1;
+     576             : 
+     577       23658 :         if (file_a->mtime_nsec < file_b->mtime_nsec)
+     578           0 :                 return -1;
+     579       23658 :         if (file_a->mtime_nsec > file_b->mtime_nsec)
+     580           0 :                 return 1;
+     581             : 
+     582       23658 :         return 0;
+     583             : }
+     584             : 
+     585       23904 : int file_namestamp_compare(const void* void_a, const void* void_b)
+     586             : {
+     587             :         int ret;
+     588             : 
+     589       23904 :         ret = file_name_compare(void_a, void_b);
+     590       23904 :         if (ret != 0)
+     591         246 :                 return ret;
+     592             : 
+     593       23658 :         return file_stamp_compare(void_a, void_b);
+     594             : }
+     595             : 
+     596           0 : int file_pathstamp_compare(const void* void_a, const void* void_b)
+     597             : {
+     598             :         int ret;
+     599             : 
+     600           0 :         ret = file_path_compare(void_a, void_b);
+     601           0 :         if (ret != 0)
+     602           0 :                 return ret;
+     603             : 
+     604           0 :         return file_stamp_compare(void_a, void_b);
+     605             : }
+     606             : 
+     607      115744 : struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned link_flag)
+     608             : {
+     609             :         struct snapraid_link* link;
+     610             : 
+     611      115744 :         link = malloc_nofail(sizeof(struct snapraid_link));
+     612      115744 :         link->sub = strdup_nofail(sub);
+     613      115744 :         link->linkto = strdup_nofail(linkto);
+     614      115744 :         link->flag = link_flag;
+     615             : 
+     616      115744 :         return link;
+     617             : }
+     618             : 
+     619      110535 : void link_free(struct snapraid_link* link)
+     620             : {
+     621      110535 :         free(link->sub);
+     622      110535 :         free(link->linkto);
+     623      110535 :         free(link);
+     624      110535 : }
+     625             : 
+     626       29409 : int link_name_compare_to_arg(const void* void_arg, const void* void_data)
+     627             : {
+     628       29409 :         const char* arg = void_arg;
+     629       29409 :         const struct snapraid_link* link = void_data;
+     630             : 
+     631       29409 :         return strcmp(arg, link->sub);
+     632             : }
+     633             : 
+     634        1252 : int link_alpha_compare(const void* void_a, const void* void_b)
+     635             : {
+     636        1252 :         const struct snapraid_link* link_a = void_a;
+     637        1252 :         const struct snapraid_link* link_b = void_b;
+     638             : 
+     639        1252 :         return strcmp(link_a->sub, link_b->sub);
+     640             : }
+     641             : 
+     642         760 : struct snapraid_dir* dir_alloc(const char* sub)
+     643             : {
+     644             :         struct snapraid_dir* dir;
+     645             : 
+     646         760 :         dir = malloc_nofail(sizeof(struct snapraid_dir));
+     647         760 :         dir->sub = strdup_nofail(sub);
+     648         760 :         dir->flag = 0;
+     649             : 
+     650         760 :         return dir;
+     651             : }
+     652             : 
+     653         716 : void dir_free(struct snapraid_dir* dir)
+     654             : {
+     655         716 :         free(dir->sub);
+     656         716 :         free(dir);
+     657         716 : }
+     658             : 
+     659         209 : int dir_name_compare(const void* void_arg, const void* void_data)
+     660             : {
+     661         209 :         const char* arg = void_arg;
+     662         209 :         const struct snapraid_dir* dir = void_data;
+     663             : 
+     664         209 :         return strcmp(arg, dir->sub);
+     665             : }
+     666             : 
+     667        1411 : struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev)
+     668             : {
+     669             :         struct snapraid_disk* disk;
+     670             : 
+     671        1411 :         disk = malloc_nofail(sizeof(struct snapraid_disk));
+     672        1411 :         pathcpy(disk->name, sizeof(disk->name), name);
+     673        1411 :         pathimport(disk->dir, sizeof(disk->dir), dir);
+     674             : 
+     675             :         /* ensure that the dir terminate with "/" if it isn't empty */
+     676        1411 :         pathslash(disk->dir, sizeof(disk->dir));
+     677             : 
+     678        1411 :         disk->smartctl[0] = 0;
+     679        1411 :         disk->device = dev;
+     680        1411 :         disk->tick = 0;
+     681        1411 :         disk->total_blocks = 0;
+     682        1411 :         disk->free_blocks = 0;
+     683        1411 :         disk->first_free_block = 0;
+     684        1411 :         disk->has_volatile_inodes = 0;
+     685        1411 :         disk->has_unreliable_physical = 0;
+     686        1411 :         disk->has_different_uuid = 0;
+     687        1411 :         disk->has_unsupported_uuid = 0;
+     688        1411 :         disk->had_empty_uuid = 0;
+     689        1411 :         disk->mapping_idx = -1;
+     690        1411 :         tommy_list_init(&disk->filelist);
+     691        1411 :         tommy_list_init(&disk->deletedlist);
+     692        1411 :         tommy_hashdyn_init(&disk->inodeset);
+     693        1411 :         tommy_hashdyn_init(&disk->pathset);
+     694        1411 :         tommy_hashdyn_init(&disk->stampset);
+     695        1411 :         tommy_list_init(&disk->linklist);
+     696        1411 :         tommy_hashdyn_init(&disk->linkset);
+     697        1411 :         tommy_list_init(&disk->dirlist);
+     698        1411 :         tommy_hashdyn_init(&disk->dirset);
+     699        1411 :         tommy_arrayblk_init(&disk->blockarr);
+     700             : 
+     701        1411 :         return disk;
+     702             : }
+     703             : 
+     704        1303 : void disk_free(struct snapraid_disk* disk)
+     705             : {
+     706        1303 :         tommy_list_foreach(&disk->filelist, (tommy_foreach_func*)file_free);
+     707        1303 :         tommy_list_foreach(&disk->deletedlist, (tommy_foreach_func*)deleted_free);
+     708        1303 :         tommy_hashdyn_done(&disk->inodeset);
+     709        1303 :         tommy_hashdyn_done(&disk->pathset);
+     710        1303 :         tommy_hashdyn_done(&disk->stampset);
+     711        1303 :         tommy_list_foreach(&disk->linklist, (tommy_foreach_func*)link_free);
+     712        1303 :         tommy_hashdyn_done(&disk->linkset);
+     713        1303 :         tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free);
+     714        1303 :         tommy_hashdyn_done(&disk->dirset);
+     715        1303 :         tommy_arrayblk_done(&disk->blockarr);
+     716        1303 :         free(disk);
+     717        1303 : }
+     718             : 
+     719         720 : int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax)
+     720             : {
+     721             :         block_off_t i;
+     722             : 
+     723             :         /* if there is an element, it's not empty */
+     724             :         /* even if links and dirs have no block allocation */
+     725         720 :         if (!tommy_list_empty(&disk->filelist))
+     726         712 :                 return 0;
+     727           8 :         if (!tommy_list_empty(&disk->linklist))
+     728           0 :                 return 0;
+     729           8 :         if (!tommy_list_empty(&disk->dirlist))
+     730           0 :                 return 0;
+     731             : 
+     732             :         /* limit the search to the size of the disk */
+     733           8 :         if (blockmax > tommy_arrayblk_size(&disk->blockarr))
+     734           2 :                 blockmax = tommy_arrayblk_size(&disk->blockarr);
+     735             : 
+     736             :         /* checks all the blocks to search for deleted ones */
+     737             :         /* this search is slow, but it's done only if no file is present */
+     738        4641 :         for (i = 0; i < blockmax; ++i) {
+     739        4634 :                 struct snapraid_block* block = tommy_arrayblk_get(&disk->blockarr, i);
+     740        4634 :                 unsigned block_state = block_state_get(block);
+     741             : 
+     742        4634 :                 switch (block_state) {
+     743             :                 case BLOCK_STATE_EMPTY :
+     744             :                         /* empty block are expected for an empty disk */
+     745        4633 :                         break;
+     746             :                 case BLOCK_STATE_DELETED :
+     747             :                         /* if there is a deleted block, the disk is not empty */
+     748           1 :                         return 0;
+     749             :                 default :
+     750             :                         /* LCOV_EXCL_START */
+     751             :                         log_fatal("Internal inconsistency for used block in disk '%s' without files\n", disk->name);
+     752             :                         exit(EXIT_FAILURE);
+     753             :                         /* LCOV_EXCL_STOP */
+     754             :                 }
+     755             :         }
+     756             : 
+     757             :         /* finally, it's empty */
+     758           7 :         return 1;
+     759             : }
+     760             : 
+     761        1381 : struct snapraid_map* map_alloc(const char* name, unsigned position, block_off_t total_blocks, block_off_t free_blocks, const char* uuid)
+     762             : {
+     763             :         struct snapraid_map* map;
+     764             : 
+     765        1381 :         map = malloc_nofail(sizeof(struct snapraid_map));
+     766        1381 :         pathcpy(map->name, sizeof(map->name), name);
+     767        1381 :         map->position = position;
+     768        1381 :         map->total_blocks = total_blocks;
+     769        1381 :         map->free_blocks = free_blocks;
+     770        1381 :         pathcpy(map->uuid, sizeof(map->uuid), uuid);
+     771             : 
+     772        1381 :         return map;
+     773             : }
+     774             : 
+     775        1279 : void map_free(struct snapraid_map* map)
+     776             : {
+     777        1279 :         free(map);
+     778        1279 : }
+     779             : 
+     780      665521 : int info_time_compare(const void* void_a, const void* void_b)
+     781             : {
+     782      665521 :         const snapraid_info* info_a = void_a;
+     783      665521 :         const snapraid_info* info_b = void_b;
+     784      665521 :         time_t time_a = info_get_time(*info_a);
+     785      665521 :         time_t time_b = info_get_time(*info_b);
+     786             : 
+     787      665521 :         if (time_a < time_b)
+     788       26639 :                 return -1;
+     789      638882 :         if (time_a > time_b)
+     790      160266 :                 return 1;
+     791      478616 :         return 0;
+     792             : }
+     793             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.h.func-sort-c.html b/cov/cmdline/elem.h.func-sort-c.html new file mode 100644 index 00000000..3bddebe8 --- /dev/null +++ b/cov/cmdline/elem.h.func-sort-c.html @@ -0,0 +1,224 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:11411995.8 %
Date:2015-05-12Functions:373897.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_file_get56105963
block_state_get50453929
disk_block_get39470278
file_flag_has20906140
block_state_set18101538
block_has_file15044184
block_has_invalid_parity11328231
hash_invalid_set8915482
block_file_set8800887
file_stamp_hash6126211
info_get5183926
file_flag_set4890738
file_inode_hash4779013
file_path_hash3752114
filter_hidden3039576
info_get_time2510452
block_has_updated_hash2328539
block_has_past_hash2245365
info_get_rehash2133210
info_set1599143
hash_is_zero782918
hash_is_invalid768754
info_get_bad529647
info_make417083
block_has_file_and_valid_parity220849
link_flag_has201121
hash_zero_set153240
link_name_hash147610
link_flag_get85930
hash_is_real63414
link_flag_set34707
file_flag_clear9855
info_set_rehash9199
info_set_bad1803
dir_name_hash979
dir_flag_has860
dir_flag_set227
link_flag_let0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.h.func.html b/cov/cmdline/elem.h.func.html new file mode 100644 index 00000000..b15fa457 --- /dev/null +++ b/cov/cmdline/elem.h.func.html @@ -0,0 +1,224 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:11411995.8 %
Date:2015-05-12Functions:373897.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_file_get56105963
block_file_set8800887
block_has_file15044184
block_has_file_and_valid_parity220849
block_has_invalid_parity11328231
block_has_past_hash2245365
block_has_updated_hash2328539
block_state_get50453929
block_state_set18101538
dir_flag_has860
dir_flag_set227
dir_name_hash979
disk_block_get39470278
file_flag_clear9855
file_flag_has20906140
file_flag_set4890738
file_inode_hash4779013
file_path_hash3752114
file_stamp_hash6126211
filter_hidden3039576
hash_invalid_set8915482
hash_is_invalid768754
hash_is_real63414
hash_is_zero782918
hash_zero_set153240
info_get5183926
info_get_bad529647
info_get_rehash2133210
info_get_time2510452
info_make417083
info_set1599143
info_set_bad1803
info_set_rehash9199
link_flag_get85930
link_flag_has201121
link_flag_let0
link_flag_set34707
link_name_hash147610
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/elem.h.gcov.html b/cov/cmdline/elem.h.gcov.html new file mode 100644 index 00000000..ebd2c97d --- /dev/null +++ b/cov/cmdline/elem.h.gcov.html @@ -0,0 +1,1084 @@ + + + + + + + LCOV - lcov.info - cmdline/elem.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - elem.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:11411995.8 %
Date:2015-05-12Functions:373897.4 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #ifndef __ELEM_H
+      19             : #define __ELEM_H
+      20             : 
+      21             : #include "util.h"
+      22             : #include "support.h"
+      23             : #include "tommyds/tommylist.h"
+      24             : #include "tommyds/tommyhash.h"
+      25             : #include "tommyds/tommyhashdyn.h"
+      26             : #include "tommyds/tommyarray.h"
+      27             : #include "tommyds/tommyarrayblk.h"
+      28             : #include "tommyds/tommyarrayblkof.h"
+      29             : 
+      30             : /****************************************************************************/
+      31             : /* snapraid */
+      32             : 
+      33             : /**
+      34             :  * Invalid position.
+      35             :  */
+      36             : #define POS_INVALID ((block_off_t)-1)
+      37             : 
+      38             : /**
+      39             :  * Basic block position type.
+      40             :  * With 32 bits and 128k blocks you can address 256 TB.
+      41             :  */
+      42             : typedef uint32_t block_off_t;
+      43             : 
+      44             : /**
+      45             :  * Basic data position type.
+      46             :  * It's signed as file size and offset are usually signed.
+      47             :  */
+      48             : typedef int64_t data_off_t;
+      49             : 
+      50             : /**
+      51             :  * Content file specification.
+      52             :  */
+      53             : struct snapraid_content {
+      54             :         char content[PATH_MAX]; /**< Path of the content file. */
+      55             :         uint64_t device; /**< Device identifier. */
+      56             :         tommy_node node; /**< Next node in the list. */
+      57             : };
+      58             : 
+      59             : /**
+      60             :  * Filter for paths.
+      61             :  */
+      62             : struct snapraid_filter {
+      63             :         char pattern[PATH_MAX]; /**< Filter pattern. */
+      64             :         int is_disk; /**< If the pattern is a disk one. */
+      65             :         int is_path; /**< If the pattern is only for the complete path. */
+      66             :         int is_dir; /**< If the pattern is only for dir. */
+      67             :         int direction; /**< If it's an inclusion (=1) or an exclusion (=-1). */
+      68             :         tommy_node node; /**< Next node in the list. */
+      69             : };
+      70             : 
+      71             : /**
+      72             :  * The block has both the hash and the parity computed.
+      73             :  * This is the normal state of a saved block.
+      74             :  *
+      75             :  * The block hash field IS set.
+      76             :  * The parity for this disk is updated.
+      77             :  */
+      78             : #define BLOCK_STATE_BLK 1
+      79             : 
+      80             : /**
+      81             :  * The block is new and not yet hashed.
+      82             :  * This happens when a new block overwrite a just removed block, or an empty space.
+      83             :  *
+      84             :  * The block hash field MAY be set and it represents the hash of the OLD data.
+      85             :  * The hash may be also INVALID or ZERO.
+      86             :  *
+      87             :  * If the OLD block was empty, the hash is set to the special ZERO value.
+      88             :  * If the OLD block was lost, the hash is set to the special INVALID value.
+      89             :  *
+      90             :  * The parity for this disk is not updated, but it contains the old data referenced by the hash.
+      91             :  *
+      92             :  * If the state is read from an incomplete sync, we don't really know if the hash is referring at the
+      93             :  * data used to compute the parity, because the sync process was interrupted at an unknown point,
+      94             :  * and the parity may or may not be updated.
+      95             :  *
+      96             :  * For this reson we clear all such hashes when reading the state from an incomplete sync before
+      97             :  * starting a new sync, because sync is affected by such hashes, as sync updates the parity, only
+      98             :  * if the new data read for CHG blocks has a mismatching hash.
+      99             :  * Clearing is done setting the ::clear_past_hash flag before reading the state.
+     100             :  * No clearing is done in other commands, as check and fix are instead able to work with unsynced
+     101             :  * hashes, and scrub ignores CHG/DELETED blocks.
+     102             :  */
+     103             : #define BLOCK_STATE_CHG 2
+     104             : 
+     105             : /**
+     106             :  * The block is new and hashed.
+     107             :  * This happens when a new block overwrite a just removed block, or an empty space.
+     108             :  *
+     109             :  * Note that when the file copy heuristic is enabled, the REP blocks may be set
+     110             :  * using this euristic, meaning that the hash may be wrong.
+     111             :  *
+     112             :  * For this reason, when the ::force_nocopy flag is enabled in sync, we convert all the REP blocks
+     113             :  * to CHG, invalidating the stored hash.
+     114             :  * Clearing is done setting the ::clear_past_hash flag before reading the state.
+     115             :  * No cleaering is done in other commands, as they don't stop the process like in sync
+     116             :  * when there is a false silent error.
+     117             :  *
+     118             :  * The block hash field IS set, and it represents the hash of the new data.
+     119             :  * The parity for this disk is not updated.
+     120             :  */
+     121             : #define BLOCK_STATE_REP 3
+     122             : 
+     123             : /**
+     124             :  * This block is a deleted one.
+     125             :  * This happens when a file is deleted.
+     126             :  *
+     127             :  * The block hash field IS set, and it represents the hash of the previous data,
+     128             :  * but only if it's different by all 0.
+     129             :  * The parity for this disk is not updated, but it contains the old data referenced by the hash.
+     130             :  *
+     131             :  * If the state is read from an incomplete sync, we don't really know if the hash is referring at the
+     132             :  * data used to compute the parity, because the sync process was interrupted at an unknown point,
+     133             :  * and the parity may or may not be updated.
+     134             :  *
+     135             :  * A now the sync process is not affected by DELETED hash, so clearing won't be really needed,
+     136             :  * but considering that we have to do it for CHG blocks, we do it also for DELETED ones,
+     137             :  * clearing all the past hashes.
+     138             :  * Clearing is done setting the ::clear_past_hash flag before reading the state.
+     139             :  * No clearing is done in other commands, as check and fix are instead able to work with unsynced
+     140             :  * hashes, and scrub ignores CHG/DELETED blocks.
+     141             :  */
+     142             : #define BLOCK_STATE_DELETED 4
+     143             : 
+     144             : /**
+     145             :  * Mask used to store the previous states of the block.
+     146             :  * Used to mix them inside the file pointer.
+     147             :  */
+     148             : #define BLOCK_STATE_MASK 7
+     149             : 
+     150             : /**
+     151             :  * This block is an empty one.
+     152             :  * Note that this state cannot be stored inside the block,
+     153             :  * and it's represented by the block ::BLOCK_EMPTY.
+     154             :  */
+     155             : #define BLOCK_STATE_EMPTY 8
+     156             : 
+     157             : /**
+     158             :  * Block of a file.
+     159             :  */
+     160             : struct snapraid_block {
+     161             :         uintptr_t file_mixed; /**< Back pointer to the file owning this block, mixed with some flags. */
+     162             :         block_off_t parity_pos; /**< Position of the block in the parity. */
+     163             :         unsigned char hash[HASH_SIZE]; /**< Hash of the block. */
+     164             : };
+     165             : 
+     166             : /**
+     167             :  * Block pointer used to mark unused blocks.
+     168             :  */
+     169             : #define BLOCK_EMPTY 0
+     170             : 
+     171             : /**
+     172             :  * If a file is present in the disk.
+     173             :  * It's used only in scan to detect present and missing files.
+     174             :  */
+     175             : #define FILE_IS_PRESENT 0x01
+     176             : 
+     177             : /**
+     178             :  * If it's an excluded file from the processing.
+     179             :  * It's used in both check and fix to mark files to exclude from the processing.
+     180             :  */
+     181             : #define FILE_IS_EXCLUDED 0x02
+     182             : 
+     183             : /**
+     184             :  * If a fix was attempted but it failed.
+     185             :  * It's used only in fix to mark that some data is unrecoverable.
+     186             :  */
+     187             : #define FILE_IS_DAMAGED 0x04
+     188             : 
+     189             : /**
+     190             :  * If a fix was done.
+     191             :  * It's used only in fix to mark that some data was recovered.
+     192             :  */
+     193             : #define FILE_IS_FIXED 0x08
+     194             : 
+     195             : /**
+     196             :  * If the file was originally missing, and it was created in the fix process.
+     197             :  * It's used only in fix to mark files recovered from scratch,
+     198             :  * meaning that they don't have any previous content.
+     199             :  * This is important because it means that deleting them, you are not going
+     200             :  * to lose something that cannot be recovered.
+     201             :  * Note that excluded files won't ever get this flag.
+     202             :  */
+     203             : #define FILE_IS_CREATED 0x10
+     204             : 
+     205             : /**
+     206             :  * If the file has completed its processing, meaning that it won't be opened anymore.
+     207             :  * It's used only in fix to mark when we finish processing one file.
+     208             :  * Note that excluded files won't ever get this flag.
+     209             :  */
+     210             : #define FILE_IS_FINISHED 0x20
+     211             : 
+     212             : /**
+     213             :  * If the file hash was obtained from a file copy
+     214             :  * identified by the same name, size and stamp.
+     215             :  */
+     216             : #define FILE_IS_COPY 0x40
+     217             : 
+     218             : /**
+     219             :  * If the file was opened.
+     220             :  * It's used in fix to detect if it's the first time a file is opened.
+     221             :  */
+     222             : #define FILE_IS_OPENED 0x80
+     223             : 
+     224             : /**
+     225             :  * If the file is modified from the latest sync.
+     226             :  * It's used in fix to store if the state of the file before being modified.
+     227             :  */
+     228             : #define FILE_IS_UNSYNCED 0x100
+     229             : 
+     230             : /**
+     231             :  * If the file is without inode.
+     232             :  * It could happen in filesystem where inodes are not persistent,
+     233             :  * or when restoring a full disk with "fix".
+     234             :  * In such cases we have to clear any stored duplicate inode.
+     235             :  * After the scan process completes, no file should have this flag set.
+     236             :  */
+     237             : #define FILE_IS_WITHOUT_INODE 0x200
+     238             : 
+     239             : #define FILE_IS_HARDLINK 0x1000 /**< If it's an hardlink. */
+     240             : #define FILE_IS_SYMLINK 0x2000 /**< If it's a file symlink. */
+     241             : #define FILE_IS_SYMDIR 0x4000 /**< If it's a dir symlink for Windows. Not yet supported. */
+     242             : #define FILE_IS_JUNCTION 0x8000 /**< If it's a junction for Windows. Not yet supported. */
+     243             : #define FILE_IS_LINK_MASK 0xF000 /**< Mask for link type. */
+     244             : 
+     245             : /**
+     246             :  * File.
+     247             :  */
+     248             : struct snapraid_file {
+     249             :         int64_t mtime_sec; /**< Modification time. */
+     250             :         uint64_t inode; /**< Inode. */
+     251             :         uint64_t physical; /**< Physical offset of the file. */
+     252             :         data_off_t size; /**< Size of the file. */
+     253             :         struct snapraid_block* blockvec; /**< All the blocks of the file. */
+     254             :         int mtime_nsec; /**< Modification time nanoseconds. In the range 0 <= x < 1,000,000,000, or STAT_NSEC_INVALID if not present. */
+     255             :         block_off_t blockmax; /**< Number of blocks. */
+     256             :         unsigned flag; /**< FILE_IS_* flags. */
+     257             :         char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
+     258             : 
+     259             :         /* nodes for data structures */
+     260             :         tommy_node nodelist;
+     261             :         tommy_hashdyn_node nodeset;
+     262             :         tommy_hashdyn_node pathset;
+     263             :         tommy_hashdyn_node stampset;
+     264             : };
+     265             : 
+     266             : /**
+     267             :  * Symbolic Link.
+     268             :  */
+     269             : struct snapraid_link {
+     270             :         unsigned flag; /**< FILE_IS_* flags. */
+     271             :         char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
+     272             :         char* linkto; /**< Link to. */
+     273             : 
+     274             :         /* nodes for data structures */
+     275             :         tommy_node nodelist;
+     276             :         tommy_hashdyn_node nodeset;
+     277             : };
+     278             : 
+     279             : /**
+     280             :  * Dir.
+     281             :  */
+     282             : struct snapraid_dir {
+     283             :         unsigned flag; /**< FILE_IS_* flags. */
+     284             :         char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
+     285             : 
+     286             :         /* nodes for data structures */
+     287             :         tommy_node nodelist;
+     288             :         tommy_hashdyn_node nodeset;
+     289             : };
+     290             : 
+     291             : /**
+     292             :  * Deleted entry.
+     293             :  */
+     294             : struct snapraid_deleted {
+     295             :         /**
+     296             :          * Deleted block.
+     297             :          * This block is always in state BLOCK_STATE_DELETED,
+     298             :          * and it's used to keep the old hash during a sync.
+     299             :          */
+     300             :         struct snapraid_block block;
+     301             : 
+     302             :         /* nodes for data structures */
+     303             :         tommy_node node;
+     304             : };
+     305             : 
+     306             : /**
+     307             :  * Disk.
+     308             :  */
+     309             : struct snapraid_disk {
+     310             :         char name[PATH_MAX]; /**< Name of the disk. */
+     311             :         char dir[PATH_MAX]; /**< Mount point of the disk. It always terminates with /. */
+     312             :         char smartctl[PATH_MAX]; /**< Custom command for smartctl. Empty means auto. */
+     313             :         uint64_t device; /**< Device identifier. */
+     314             : 
+     315             :         uint64_t tick; /**< Usage time of the disk. */
+     316             : 
+     317             :         block_off_t total_blocks; /**< Number of total blocks. */
+     318             :         block_off_t free_blocks; /**< Number of free blocks at the last sync. */
+     319             : 
+     320             :         /**
+     321             :          * First free searching block.
+     322             :          * Note that it doesn't necessarely point at the first free block,
+     323             :          * but it just tell you that no free block is present before this position.
+     324             :          */
+     325             :         block_off_t first_free_block;
+     326             : 
+     327             :         int has_volatile_inodes; /**< If the underline filesystem has not persistent inodes. */
+     328             :         int has_unreliable_physical; /**< If the physical offset of files has duplicates. */
+     329             :         int has_different_uuid; /**< If the disk has a different UUID, meaning that it is not the same filesystem. */
+     330             :         int has_unsupported_uuid; /**< If the disk doesn't report UUID, meaning it's not supported. */
+     331             :         int had_empty_uuid; /**< If the disk had an empty UUID, meaning that it's a new disk. */
+     332             :         int mapping_idx; /**< Index in the mapping vector. Used only as buffer when writing the content file. */
+     333             : 
+     334             :         /**<
+     335             :          * Block array of the disk.
+     336             :          *
+     337             :          * Each element points to a snapraid_block structure, or it's BLOCK_EMPTY.
+     338             :          */
+     339             :         tommy_arrayblk blockarr;
+     340             : 
+     341             :         /**
+     342             :          * List of all the snapraid_file for the disk.
+     343             :          */
+     344             :         tommy_list filelist;
+     345             : 
+     346             :         /**
+     347             :          * List of all the snapraid_deleted blocks for the disk.
+     348             :          *
+     349             :          * These files are kept allocated, because the blocks are still referenced in
+     350             :          * the ::blockarr.
+     351             :          */
+     352             :         tommy_list deletedlist;
+     353             : 
+     354             :         tommy_hashdyn inodeset; /**< Hashtable by inode of all the files. */
+     355             :         tommy_hashdyn pathset; /**< Hashtable by path of all the files. */
+     356             :         tommy_hashdyn stampset; /**< Hashtable by stamp (size and time) of all the files. */
+     357             :         tommy_list linklist; /**< List of all the links. */
+     358             :         tommy_hashdyn linkset; /**< Hashtable by name of all the links. */
+     359             :         tommy_list dirlist; /**< List of all the dirs. */
+     360             :         tommy_hashdyn dirset; /**< Hashtable by name of all the dirs. */
+     361             : 
+     362             :         /* nodes for data structures */
+     363             :         tommy_node node;
+     364             : };
+     365             : 
+     366             : /**
+     367             :  * Max UUID length.
+     368             :  */
+     369             : #define UUID_MAX 128
+     370             : 
+     371             : /**
+     372             :  * Disk mapping.
+     373             :  */
+     374             : struct snapraid_map {
+     375             :         char name[PATH_MAX]; /**< Name of the disk. */
+     376             :         char uuid[UUID_MAX]; /**< UUID of the disk. Empty if unknown. */
+     377             :         block_off_t total_blocks; /**< Number of total blocks. */
+     378             :         block_off_t free_blocks; /**< Number of free blocks at last 'sync'. */
+     379             :         unsigned position; /**< Position of the disk in the parity. */
+     380             : 
+     381             :         /* nodes for data structures */
+     382             :         tommy_node node;
+     383             : };
+     384             : 
+     385             : /**
+     386             :  * Parity.
+     387             :  */
+     388             : struct snapraid_parity {
+     389             :         char path[PATH_MAX]; /**< Path of the parity file. */
+     390             :         char uuid[UUID_MAX]; /**< UUID of the disk. Empty if unknown. */
+     391             :         char smartctl[PATH_MAX]; /**< Custom command for smartctl. Empty means auto. */
+     392             :         uint64_t device; /**< Device identifier of the parity. */
+     393             :         block_off_t total_blocks; /**< Number of total blocks. */
+     394             :         block_off_t free_blocks; /**< Number of free blocks at the last sync. */
+     395             : 
+     396             :         /**
+     397             :          * Cumulative time used for parity disks.
+     398             :          */
+     399             :         uint64_t tick;
+     400             : };
+     401             : 
+     402             : /**
+     403             :  * Info.
+     404             :  */
+     405             : typedef uint32_t snapraid_info;
+     406             : 
+     407             : /**
+     408             :  * Allocates a content.
+     409             :  */
+     410             : struct snapraid_content* content_alloc(const char* path, uint64_t dev);
+     411             : 
+     412             : /**
+     413             :  * Deallocates a content.
+     414             :  */
+     415             : void content_free(struct snapraid_content* content);
+     416             : 
+     417             : /**
+     418             :  * Allocates a filter pattern for files and directories.
+     419             :  */
+     420             : struct snapraid_filter* filter_alloc_file(int is_include, const char* pattern);
+     421             : 
+     422             : /**
+     423             :  * Allocates a filter pattern for disks.
+     424             :  */
+     425             : struct snapraid_filter* filter_alloc_disk(int is_include, const char* pattern);
+     426             : 
+     427             : /**
+     428             :  * Deallocates an exclusion.
+     429             :  */
+     430             : void filter_free(struct snapraid_filter* filter);
+     431             : 
+     432             : /**
+     433             :  * Filter type description.
+     434             :  */
+     435             : const char* filter_type(struct snapraid_filter* filter, char* out, size_t out_size);
+     436             : 
+     437             : /**
+     438             :  * Filter hidden files.
+     439             :  * Return !=0 if it matches and it should be excluded.
+     440             :  */
+     441     3039576 : static inline int filter_hidden(int enable, struct dirent* dd)
+     442             : {
+     443     3039576 :         if (enable && dirent_hidden(dd)) {
+     444           0 :                 return 1; /* filter out */
+     445             :         }
+     446             : 
+     447     3039576 :         return 0;
+     448             : }
+     449             : 
+     450             : /**
+     451             :  * Filters a path using a list of filters.
+     452             :  * For each element of the path all the filters are applied, until the first one that matches.
+     453             :  * Return !=0 if it should be excluded.
+     454             :  */
+     455             : int filter_path(tommy_list* filterlist, struct snapraid_filter** reason, const char* disk, const char* sub);
+     456             : 
+     457             : /**
+     458             :  * Filter a file/link/dir if missing.
+     459             :  * This call imply a disk check for the file presence.
+     460             :  * Return !=0 if the file is present and it should be excluded.
+     461             :  */
+     462             : int filter_existence(int filter_missing, const char* dir, const char* sub);
+     463             : 
+     464             : /**
+     465             :  * Filter a file if bad.
+     466             :  * Return !=0 if the file is correct and it should be excluded.
+     467             :  */
+     468             : int filter_correctness(int filter_error, tommy_arrayblkof* infoarr, struct snapraid_file* file);
+     469             : 
+     470             : /**
+     471             :  * Filters a dir using a list of filters.
+     472             :  * For each element of the path all the filters are applied, until the first one that matches.
+     473             :  * Return !=0 if should be excluded.
+     474             :  */
+     475             : int filter_dir(tommy_list* filterlist, struct snapraid_filter** reason, const char* disk, const char* sub);
+     476             : 
+     477             : /**
+     478             :  * Filters a path if it's a content file.
+     479             :  * Return !=0 if should be excluded.
+     480             :  */
+     481             : int filter_content(tommy_list* contentlist, const char* path);
+     482             : 
+     483             : /**
+     484             :  * Gets the file containing the block.
+     485             :  */
+     486    56105963 : static inline struct snapraid_file* block_file_get(struct snapraid_block* block)
+     487             : {
+     488    56105963 :         return (struct snapraid_file*)(block->file_mixed & ~(uintptr_t)BLOCK_STATE_MASK);
+     489             : }
+     490             : 
+     491             : /**
+     492             :  * Sets the file containing the block.
+     493             :  */
+     494     8800887 : static inline void block_file_set(struct snapraid_block* block, struct snapraid_file* file)
+     495             : {
+     496     8800887 :         uintptr_t ptr = (uintptr_t)file;
+     497             : 
+     498             :         /* ensure that the pointer doesn't use the flag space */
+     499     8800887 :         if ((ptr & (uintptr_t)BLOCK_STATE_MASK) != 0) {
+     500             :                 /* LCOV_EXCL_START */
+     501             :                 log_fatal("Internal error for pointer not aligned\n");
+     502             :                 exit(EXIT_FAILURE);
+     503             :                 /* LCOV_EXCL_STOP */
+     504             :         }
+     505             : 
+     506     8800887 :         block->file_mixed = (block->file_mixed & ~(uintptr_t)BLOCK_STATE_MASK) | ptr;
+     507     8800887 : }
+     508             : 
+     509             : /**
+     510             :  * Get the state of the block.
+     511             :  *
+     512             :  * For this function, it's allowed to pass a NULL block
+     513             :  * pointer than results in the BLOCK_STATE_EMPTY state.
+     514             :  */
+     515    50453929 : static inline unsigned block_state_get(const struct snapraid_block* block)
+     516             : {
+     517    50453929 :         if (block == BLOCK_EMPTY)
+     518     1581967 :                 return BLOCK_STATE_EMPTY;
+     519             : 
+     520    48871962 :         return block->file_mixed & BLOCK_STATE_MASK;
+     521             : }
+     522             : 
+     523    18101538 : static inline void block_state_set(struct snapraid_block* block, unsigned state)
+     524             : {
+     525             :         /* ensure that the state can be stored inside the file pointer */
+     526    18101538 :         if ((state & BLOCK_STATE_MASK) != state) {
+     527             :                 /* LCOV_EXCL_START */
+     528             :                 log_fatal("Internal error when setting the block state %u\n", state);
+     529             :                 exit(EXIT_FAILURE);
+     530             :                 /* LCOV_EXCL_STOP */
+     531             :         }
+     532             : 
+     533    18101538 :         block->file_mixed &= ~(uintptr_t)BLOCK_STATE_MASK;
+     534    18101538 :         block->file_mixed |= state & BLOCK_STATE_MASK;
+     535    18101538 : }
+     536             : 
+     537             : /**
+     538             :  * Checks if the specified block has an updated hash.
+     539             :  *
+     540             :  * Note that EMPTY / CHG / DELETED return 0.
+     541             :  */
+     542     2328539 : static inline int block_has_updated_hash(const struct snapraid_block* block)
+     543             : {
+     544     2328539 :         unsigned state = block_state_get(block);
+     545             : 
+     546     2328539 :         return state == BLOCK_STATE_BLK || state == BLOCK_STATE_REP;
+     547             : }
+     548             : 
+     549             : /**
+     550             :  * Checks if the specified block has a past hash,
+     551             :  * i.e. the hash of the data that it's now overwritten or lost.
+     552             :  *
+     553             :  * Note that EMPTY / BLK / REP return 0.
+     554             :  */
+     555     2245365 : static inline int block_has_past_hash(const struct snapraid_block* block)
+     556             : {
+     557     2245365 :         unsigned state = block_state_get(block);
+     558             : 
+     559     2245365 :         return state == BLOCK_STATE_CHG || state == BLOCK_STATE_DELETED;
+     560             : }
+     561             : 
+     562             : /**
+     563             :  * Checks if the specified hash is invalid.
+     564             :  *
+     565             :  * An invalid hash is represented with all bytes at 0x00.
+     566             :  */
+     567      768754 : static inline int hash_is_invalid(const unsigned char* hash)
+     568             : {
+     569             :         unsigned i;
+     570             : 
+     571     1257417 :         for (i = 0; i < HASH_SIZE; ++i)
+     572     1227038 :                 if (hash[i] != 0x00)
+     573      738375 :                         return 0;
+     574             : 
+     575       30379 :         return 1;
+     576             : }
+     577             : 
+     578             : /**
+     579             :  * Checks if the specified hash represent the zero block.
+     580             :  *
+     581             :  * A zero hash is represented with all bytes at 0xFF.
+     582             :  */
+     583      782918 : static inline int hash_is_zero(const unsigned char* hash)
+     584             : {
+     585             :         unsigned i;
+     586             : 
+     587     1828180 :         for (i = 0; i < HASH_SIZE; ++i)
+     588     1763006 :                 if (hash[i] != 0xFF)
+     589      717744 :                         return 0;
+     590             : 
+     591       65174 :         return 1;
+     592             : }
+     593             : 
+     594             : /**
+     595             :  * Checks if the specified hash is a real hash.
+     596             :  */
+     597       63414 : static inline int hash_is_real(const unsigned char* hash)
+     598             : {
+     599       63414 :         return !hash_is_zero(hash) && !hash_is_invalid(hash);
+     600             : }
+     601             : 
+     602             : /**
+     603             :  * Set the hash to the special INVALID value.
+     604             :  */
+     605     8915482 : static inline void hash_invalid_set(unsigned char* hash)
+     606             : {
+     607     8915482 :         memset(hash, 0x00, HASH_SIZE);
+     608     8915482 : }
+     609             : 
+     610             : /**
+     611             :  * Set the hash to the special ZERO value.
+     612             :  */
+     613      153240 : static inline void hash_zero_set(unsigned char* hash)
+     614             : {
+     615      153240 :         memset(hash, 0xFF, HASH_SIZE);
+     616      153240 : }
+     617             : 
+     618             : /**
+     619             :  * Checks if the specified block is part of a file.
+     620             :  *
+     621             :  * Note that EMPTY / DELETED return 0.
+     622             :  */
+     623    15044184 : static inline int block_has_file(const struct snapraid_block* block)
+     624             : {
+     625    15044184 :         unsigned state = block_state_get(block);
+     626             : 
+     627    15044184 :         return state == BLOCK_STATE_BLK
+     628    15044184 :                || state == BLOCK_STATE_CHG || state == BLOCK_STATE_REP;
+     629             : }
+     630             : 
+     631             : /**
+     632             :  * Checks if the block has an invalid parity than needs to be updated.
+     633             :  *
+     634             :  * Note that EMPTY / BLK return 0.
+     635             :  */
+     636    11328231 : static inline int block_has_invalid_parity(const struct snapraid_block* block)
+     637             : {
+     638    11328231 :         unsigned state = block_state_get(block);
+     639             : 
+     640    11328231 :         return state == BLOCK_STATE_DELETED
+     641    11328231 :                || state == BLOCK_STATE_CHG || state == BLOCK_STATE_REP;
+     642             : }
+     643             : 
+     644             : /**
+     645             :  * Checks if the block is part of a file with valid parity.
+     646             :  *
+     647             :  * Note that anything different than BLK return 0.
+     648             :  */
+     649      220849 : static inline int block_has_file_and_valid_parity(const struct snapraid_block* block)
+     650             : {
+     651      220849 :         unsigned state = block_state_get(block);
+     652             : 
+     653      220849 :         return state == BLOCK_STATE_BLK;
+     654             : }
+     655             : 
+     656             : /**
+     657             :  * Gets the relative position of a block inside the file.
+     658             :  */
+     659             : block_off_t block_file_pos(struct snapraid_block* block);
+     660             : 
+     661             : /**
+     662             :  * Checks if the block is the last in the file.
+     663             :  */
+     664             : int block_is_last(struct snapraid_block* block);
+     665             : 
+     666             : /**
+     667             :  * Gets the size in bytes of the block.
+     668             :  * If it's the last block of a file it could be less than block_size.
+     669             :  */
+     670             : unsigned block_file_size(struct snapraid_block* block, unsigned block_size);
+     671             : 
+     672             : /**
+     673             :  * Allocates a deleted block.
+     674             :  */
+     675             : struct snapraid_deleted* deleted_alloc(void);
+     676             : 
+     677             : /**
+     678             :  * Allocates a deleted block from a real one.
+     679             :  */
+     680             : struct snapraid_deleted* deleted_dup(struct snapraid_block* block);
+     681             : 
+     682             : /**
+     683             :  * Frees a deleted block.
+     684             :  */
+     685             : void deleted_free(struct snapraid_deleted* deleted);
+     686             : 
+     687    20906140 : static inline int file_flag_has(const struct snapraid_file* file, unsigned mask)
+     688             : {
+     689    20906140 :         return (file->flag & mask) == mask;
+     690             : }
+     691             : 
+     692     4890738 : static inline void file_flag_set(struct snapraid_file* file, unsigned mask)
+     693             : {
+     694     4890738 :         file->flag |= mask;
+     695     4890738 : }
+     696             : 
+     697        9855 : static inline void file_flag_clear(struct snapraid_file* file, unsigned mask)
+     698             : {
+     699        9855 :         file->flag &= ~mask;
+     700        9855 : }
+     701             : 
+     702             : /**
+     703             :  * Allocates a file.
+     704             :  */
+     705             : struct snapraid_file* file_alloc(unsigned block_size, const char* sub, data_off_t size, uint64_t mtime_sec, int mtime_nsec, uint64_t inode, uint64_t physical);
+     706             : 
+     707             : /**
+     708             :  * Deallocates a file.
+     709             :  */
+     710             : void file_free(struct snapraid_file* file);
+     711             : 
+     712             : /**
+     713             :  * Rename a file.
+     714             :  */
+     715             : void file_rename(struct snapraid_file* file, const char* sub);
+     716             : 
+     717             : /**
+     718             :  * Copy a file.
+     719             :  */
+     720             : void file_copy(struct snapraid_file* src_file, struct snapraid_file* dest_file);
+     721             : 
+     722             : /**
+     723             :  * Returns the name of the file, without the dir.
+     724             :  */
+     725             : const char* file_name(const struct snapraid_file* file);
+     726             : 
+     727             : /**
+     728             :  * Compares a file with an inode.
+     729             :  */
+     730             : int file_inode_compare_to_arg(const void* void_arg, const void* void_data);
+     731             : 
+     732             : /**
+     733             :  * Compares files by inode.
+     734             :  */
+     735             : int file_inode_compare(const void* void_a, const void* void_b);
+     736             : 
+     737             : /**
+     738             :  * Compares files by path.
+     739             :  */
+     740             : int file_path_compare(const void* void_a, const void* void_b);
+     741             : 
+     742             : /**
+     743             :  * Compares files by physical address.
+     744             :  */
+     745             : int file_physical_compare(const void* void_a, const void* void_b);
+     746             : 
+     747             : /**
+     748             :  * Computes the hash of a file inode.
+     749             :  */
+     750     4779013 : static inline tommy_uint32_t file_inode_hash(uint64_t inode)
+     751             : {
+     752     4779013 :         return (tommy_uint32_t)tommy_inthash_u64(inode);
+     753             : }
+     754             : 
+     755             : /**
+     756             :  * Compares a file with a path.
+     757             :  */
+     758             : int file_path_compare_to_arg(const void* void_arg, const void* void_data);
+     759             : 
+     760             : /**
+     761             :  * Compare a file with another file for name, stamp, and both.
+     762             :  */
+     763             : int file_name_compare(const void* void_a, const void* void_b);
+     764             : int file_stamp_compare(const void* void_a, const void* void_b);
+     765             : int file_namestamp_compare(const void* void_a, const void* void_b);
+     766             : int file_pathstamp_compare(const void* void_a, const void* void_b);
+     767             : 
+     768             : /**
+     769             :  * Computes the hash of a file path.
+     770             :  */
+     771     3752114 : static inline tommy_uint32_t file_path_hash(const char* sub)
+     772             : {
+     773     3752114 :         return tommy_hash_u32(0, sub, strlen(sub));
+     774             : }
+     775             : 
+     776             : /**
+     777             :  * Computes the hash of a file stamp.
+     778             :  */
+     779     6126211 : static inline tommy_uint32_t file_stamp_hash(data_off_t size, int64_t mtime_sec, int mtime_nsec)
+     780             : {
+     781     6126211 :         return tommy_inthash_u32((tommy_uint32_t)size ^ tommy_inthash_u32(mtime_sec ^ tommy_inthash_u32(mtime_nsec)));
+     782             : }
+     783             : 
+     784      201121 : static inline int link_flag_has(const struct snapraid_link* link, unsigned mask)
+     785             : {
+     786      201121 :         return (link->flag & mask) == mask;
+     787             : }
+     788             : 
+     789       34707 : static inline void link_flag_set(struct snapraid_link* link, unsigned mask)
+     790             : {
+     791       34707 :         link->flag |= mask;
+     792       34707 : }
+     793             : 
+     794             : static inline void link_flag_clear(struct snapraid_link* link, unsigned mask)
+     795             : {
+     796             :         link->flag &= ~mask;
+     797             : }
+     798             : 
+     799           0 : static inline void link_flag_let(struct snapraid_link* link, unsigned flag, unsigned mask)
+     800             : {
+     801           0 :         link->flag &= ~mask;
+     802           0 :         link->flag |= flag & mask;
+     803           0 : }
+     804             : 
+     805       85930 : static inline unsigned link_flag_get(struct snapraid_link* link, unsigned mask)
+     806             : {
+     807       85930 :         return link->flag & mask;
+     808             : }
+     809             : 
+     810             : /**
+     811             :  * Allocates a link.
+     812             :  */
+     813             : struct snapraid_link* link_alloc(const char* name, const char* link, unsigned link_flag);
+     814             : 
+     815             : /**
+     816             :  * Deallocates a link.
+     817             :  */
+     818             : void link_free(struct snapraid_link* link);
+     819             : 
+     820             : /**
+     821             :  * Compare a link with a name.
+     822             :  */
+     823             : int link_name_compare_to_arg(const void* void_arg, const void* void_data);
+     824             : 
+     825             : /**
+     826             :  * Compares links by path.
+     827             :  */
+     828             : int link_alpha_compare(const void* void_a, const void* void_b);
+     829             : 
+     830             : /**
+     831             :  * Computes the hash of a link name.
+     832             :  */
+     833      147610 : static inline tommy_uint32_t link_name_hash(const char* name)
+     834             : {
+     835      147610 :         return tommy_hash_u32(0, name, strlen(name));
+     836             : }
+     837             : 
+     838         860 : static inline int dir_flag_has(const struct snapraid_dir* dir, unsigned mask)
+     839             : {
+     840         860 :         return (dir->flag & mask) == mask;
+     841             : }
+     842             : 
+     843         227 : static inline void dir_flag_set(struct snapraid_dir* dir, unsigned mask)
+     844             : {
+     845         227 :         dir->flag |= mask;
+     846         227 : }
+     847             : 
+     848             : static inline void dir_flag_clear(struct snapraid_dir* dir, unsigned mask)
+     849             : {
+     850             :         dir->flag &= ~mask;
+     851             : }
+     852             : 
+     853             : /**
+     854             :  * Allocates a dir.
+     855             :  */
+     856             : struct snapraid_dir* dir_alloc(const char* name);
+     857             : 
+     858             : /**
+     859             :  * Deallocates a dir.
+     860             :  */
+     861             : void dir_free(struct snapraid_dir* dir);
+     862             : 
+     863             : /**
+     864             :  * Compare a dir with a name.
+     865             :  */
+     866             : int dir_name_compare(const void* void_arg, const void* void_data);
+     867             : 
+     868             : /**
+     869             :  * Computes the hash of a dir name.
+     870             :  */
+     871         979 : static inline tommy_uint32_t dir_name_hash(const char* name)
+     872             : {
+     873         979 :         return tommy_hash_u32(0, name, strlen(name));
+     874             : }
+     875             : 
+     876             : /**
+     877             :  * Allocates a disk.
+     878             :  */
+     879             : struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev);
+     880             : 
+     881             : /**
+     882             :  * Deallocates a disk.
+     883             :  */
+     884             : void disk_free(struct snapraid_disk* disk);
+     885             : 
+     886             : /**
+     887             :  * Gets a specific block of a disk.
+     888             :  * Returns 0 if the block is over the end of the disk or not used.
+     889             :  */
+     890    39470278 : static inline struct snapraid_block* disk_block_get(struct snapraid_disk* disk, block_off_t pos)
+     891             : {
+     892    39470278 :         if (pos < tommy_arrayblk_size(&disk->blockarr))
+     893    37903017 :                 return tommy_arrayblk_get(&disk->blockarr, pos);
+     894             :         else
+     895     1567261 :                 return BLOCK_EMPTY;
+     896             : }
+     897             : 
+     898             : /**
+     899             :  * Check if a disk is totally empty and can be discarded from the content file.
+     900             :  * A disk is empty if it doesn't contain any file, symlink, hardlink or dir
+     901             :  * and without any DELETED block.
+     902             :  * The blockmax is used to limit the search of DELETED block up to blockmax.
+     903             :  */
+     904             : int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax);
+     905             : 
+     906             : /**
+     907             :  * Allocates a disk mapping.
+     908             :  * Uses uuid="" if not available.
+     909             :  */
+     910             : struct snapraid_map* map_alloc(const char* name, unsigned position, block_off_t total_blocks, block_off_t free_blocks, const char* uuid);
+     911             : 
+     912             : /**
+     913             :  * Deallocates a disk mapping.
+     914             :  */
+     915             : void map_free(struct snapraid_map* map);
+     916             : 
+     917             : /**
+     918             :  * Makes an info.
+     919             :  */
+     920      417083 : static inline snapraid_info info_make(time_t last_access, int error, int rehash)
+     921             : {
+     922             :         /* clear the lowest bits as reserved for other information */
+     923      417083 :         snapraid_info info = last_access & ~0x3;
+     924             : 
+     925      417083 :         if (error != 0)
+     926        5965 :                 info |= 0x1;
+     927      417083 :         if (rehash != 0)
+     928      127352 :                 info |= 0x2;
+     929      417083 :         return info;
+     930             : }
+     931             : 
+     932             : /**
+     933             :  * Extracts the time information.
+     934             :  * This is the last time when the block was know to be correct.
+     935             :  */
+     936     2510452 : static inline time_t info_get_time(snapraid_info info)
+     937             : {
+     938     2510452 :         return info & ~0x3;
+     939             : }
+     940             : 
+     941             : /**
+     942             :  * Extracts the error information.
+     943             :  * Reports if the block address had some problem.
+     944             :  */
+     945      529647 : static inline int info_get_bad(snapraid_info info)
+     946             : {
+     947      529647 :         return (info & 0x1) != 0;
+     948             : }
+     949             : 
+     950             : /**
+     951             :  * Extracts the rehash information.
+     952             :  * Reports if the block address is using the old hash and needs to be rehashed.
+     953             :  */
+     954     2133210 : static inline int info_get_rehash(snapraid_info info)
+     955             : {
+     956     2133210 :         return (info & 0x2) != 0;
+     957             : }
+     958             : 
+     959             : /**
+     960             :  * Marks the block address as with error.
+     961             :  */
+     962        1803 : static inline snapraid_info info_set_bad(snapraid_info info)
+     963             : {
+     964        1803 :         return info | 0x1;
+     965             : }
+     966             : 
+     967             : /**
+     968             :  * Marks the block address as with rehash.
+     969             :  */
+     970        9199 : static inline snapraid_info info_set_rehash(snapraid_info info)
+     971             : {
+     972        9199 :         return info | 0x2;
+     973             : }
+     974             : 
+     975             : /**
+     976             :  * Sets the info at the specified position.
+     977             :  * The position is allocated if not yet done.
+     978             :  */
+     979     1599143 : static inline void info_set(tommy_arrayblkof* array, unsigned pos, snapraid_info info)
+     980             : {
+     981     1599143 :         tommy_arrayblkof_grow(array, pos + 1);
+     982             : 
+     983     1599143 :         memcpy(tommy_arrayblkof_ref(array, pos), &info, sizeof(snapraid_info));
+     984     1599143 : }
+     985             : 
+     986             : /**
+     987             :  * Gets the info at the specified position.
+     988             :  * For not allocated position, 0 is returned.
+     989             :  */
+     990     5183926 : static inline snapraid_info info_get(tommy_arrayblkof* array, unsigned pos)
+     991             : {
+     992             :         snapraid_info info;
+     993             : 
+     994     5183926 :         if (pos >= tommy_arrayblkof_size(array))
+     995      308546 :                 return 0;
+     996             : 
+     997     4875380 :         memcpy(&info, tommy_arrayblkof_ref(array, pos), sizeof(snapraid_info));
+     998             : 
+     999     4875380 :         return info;
+    1000             : }
+    1001             : 
+    1002             : /**
+    1003             :  * Compares info by time.
+    1004             :  */
+    1005             : int info_time_compare(const void* void_a, const void* void_b);
+    1006             : 
+    1007             : #endif
+    1008             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/handle.c.func-sort-c.html b/cov/cmdline/handle.c.func-sort-c.html new file mode 100644 index 00000000..1b073620 --- /dev/null +++ b/cov/cmdline/handle.c.func-sort-c.html @@ -0,0 +1,104 @@ + + + + + + + LCOV - lcov.info - cmdline/handle.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - handle.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:12612898.4 %
Date:2015-05-12Functions:88100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
handle_read5583462
handle_close4545866
handle_open2005010
handle_create773174
handle_write288068
handle_utime119610
handle_truncate3195
handle_map197
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/handle.c.func.html b/cov/cmdline/handle.c.func.html new file mode 100644 index 00000000..dc62f742 --- /dev/null +++ b/cov/cmdline/handle.c.func.html @@ -0,0 +1,104 @@ + + + + + + + LCOV - lcov.info - cmdline/handle.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - handle.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:12612898.4 %
Date:2015-05-12Functions:88100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
handle_close4545866
handle_create773174
handle_map197
handle_open2005010
handle_read5583462
handle_truncate3195
handle_utime119610
handle_write288068
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/handle.c.gcov.html b/cov/cmdline/handle.c.gcov.html new file mode 100644 index 00000000..4c410f9b --- /dev/null +++ b/cov/cmdline/handle.c.gcov.html @@ -0,0 +1,513 @@ + + + + + + + LCOV - lcov.info - cmdline/handle.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - handle.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:12612898.4 %
Date:2015-05-12Functions:88100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "elem.h"
+      21             : #include "support.h"
+      22             : #include "handle.h"
+      23             : 
+      24             : /****************************************************************************/
+      25             : /* handle */
+      26             : 
+      27      773174 : int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, int mode)
+      28             : {
+      29             :         int ret;
+      30             :         int flags;
+      31             : 
+      32             :         /* if it's the same file, and already opened, nothing to do */
+      33      773174 :         if (handle->file == file && handle->f != -1) {
+      34           0 :                 return 0;
+      35             :         }
+      36             : 
+      37      773174 :         pathprint(handle->path, sizeof(handle->path), "%s%s", handle->disk->dir, file->sub);
+      38             : 
+      39      773174 :         ret = mkancestor(handle->path);
+      40      773174 :         if (ret != 0) {
+      41             :                 /* LCOV_EXCL_START */
+      42             :                 return -1;
+      43             :                 /* LCOV_EXCL_STOP */
+      44             :         }
+      45             : 
+      46             :         /* initial values, changed later if required */
+      47      773174 :         handle->created = 0;
+      48             : 
+      49             :         /* flags for opening */
+      50             :         /* O_BINARY: open as binary file (Windows only) */
+      51             :         /* O_NOFOLLOW: do not follow links to ensure to open the real file */
+      52             :         /* O_SEQUENTIAL: improve performance for sequential access (Windows only) */
+      53      773174 :         flags = O_BINARY | O_NOFOLLOW;
+      54      773174 :         if ((mode & MODE_SEQUENTIAL) != 0)
+      55      773174 :                 flags |= O_SEQUENTIAL;
+      56             : 
+      57             :         /* open for read write */
+      58      773174 :         handle->f = open(handle->path, flags | O_RDWR);
+      59             : 
+      60             :         /* if failed for missing write permission */
+      61      773174 :         if (handle->f == -1 && (errno == EACCES || errno == EROFS)) {
+      62             :                 /* open for real-only */
+      63           0 :                 handle->f = open(handle->path, flags | O_RDONLY);
+      64             :         }
+      65             : 
+      66             :         /* if failed for missing file */
+      67      773174 :         if (handle->f == -1 && errno == ENOENT) {
+      68             :                 char path_from[PATH_MAX];
+      69             : 
+      70             :                 /* check if exists a .unrecoverable copy, and rename to the real one */
+      71      176361 :                 pathprint(path_from, sizeof(path_from), "%s.unrecoverable", handle->path);
+      72             : 
+      73      176361 :                 if (rename(path_from, handle->path) == 0) {
+      74             :                         /* open for read write */
+      75       63387 :                         handle->f = open(handle->path, flags | O_RDWR);
+      76             :                 } else {
+      77             :                         /* create it */
+      78      112974 :                         handle->f = open(handle->path, flags | O_RDWR | O_CREAT, 0600);
+      79      112974 :                         if (handle->f != -1) {
+      80             :                                 /* mark it as created if really done */
+      81      112974 :                                 handle->created = 1;
+      82             :                         }
+      83             :                 }
+      84             :         }
+      85             : 
+      86      773174 :         if (handle->f == -1) {
+      87             :                 /* LCOV_EXCL_START */
+      88             :                 /* invalidate for error */
+      89             :                 handle->file = 0;
+      90             :                 handle->f = -1;
+      91             :                 handle->valid_size = 0;
+      92             : 
+      93             :                 log_fatal("Error opening file '%s'. %s.\n", handle->path, strerror(errno));
+      94             :                 return -1;
+      95             :                 /* LCOV_EXCL_STOP */
+      96             :         }
+      97             : 
+      98             :         /* just opened */
+      99      773174 :         handle->file = file;
+     100             : 
+     101             :         /* get the stat info */
+     102      773174 :         ret = fstat(handle->f, &handle->st);
+     103      773174 :         if (ret != 0) {
+     104             :                 /* LCOV_EXCL_START */
+     105             :                 log_fatal("Error accessing file '%s'. %s.\n", handle->path, strerror(errno));
+     106             :                 return -1;
+     107             :                 /* LCOV_EXCL_STOP */
+     108             :         }
+     109             : 
+     110             :         /* get the size of the existing data */
+     111      773174 :         handle->valid_size = handle->st.st_size;
+     112             : 
+     113             : #if HAVE_POSIX_FADVISE
+     114      773174 :         if ((mode & MODE_SEQUENTIAL) != 0) {
+     115             :                 /* advise sequential access */
+     116      773174 :                 ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL);
+     117      773174 :                 if (ret != 0) {
+     118             :                         /* LCOV_EXCL_START */
+     119             :                         log_fatal("Error advising file '%s'. %s.\n", handle->path, strerror(ret));
+     120             :                         return -1;
+     121             :                         /* LCOV_EXCL_STOP */
+     122             :                 }
+     123             :         }
+     124             : #endif
+     125             : 
+     126      773174 :         return 0;
+     127             : }
+     128             : 
+     129        3195 : int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file)
+     130             : {
+     131             :         int ret;
+     132             : 
+     133        3195 :         ret = ftruncate(handle->f, file->size);
+     134        3195 :         if (ret != 0) {
+     135             :                 /* LCOV_EXCL_START */
+     136             :                 if (errno == EACCES) {
+     137             :                         log_fatal("Failed to truncate file '%s' for missing write permission.\n", handle->path);
+     138             :                 } else {
+     139             :                         log_fatal("Error truncating file '%s'. %s.\n", handle->path, strerror(errno));
+     140             :                 }
+     141             :                 return -1;
+     142             :                 /* LCOV_EXCL_STOP */
+     143             :         }
+     144             : 
+     145             :         /* adjust the size to the truncated size */
+     146        3195 :         handle->valid_size = file->size;
+     147             : 
+     148        3195 :         return 0;
+     149             : }
+     150             : 
+     151     2005010 : int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing)
+     152             : {
+     153             :         int ret;
+     154             :         int flags;
+     155             : 
+     156     2005010 :         if (!out_missing)
+     157     2004503 :                 out_missing = out;
+     158             : 
+     159             :         /* if already opened, nothing to do */
+     160     2005010 :         if (handle->file == file && handle->f != -1) {
+     161      284379 :                 return 0;
+     162             :         }
+     163             : 
+     164     1720631 :         pathprint(handle->path, sizeof(handle->path), "%s%s", handle->disk->dir, file->sub);
+     165             : 
+     166             :         /* for sure not created */
+     167     1720631 :         handle->created = 0;
+     168             : 
+     169             :         /* flags for opening */
+     170             :         /* O_BINARY: open as binary file (Windows only) */
+     171             :         /* O_NOFOLLOW: do not follow links to ensure to open the real file */
+     172             :         /* O_SEQUENTIAL: improve performance for sequential access (Windows only) */
+     173     1720631 :         flags = O_BINARY | O_NOFOLLOW;
+     174     1720631 :         if ((mode & MODE_SEQUENTIAL) != 0)
+     175     1709301 :                 flags |= O_SEQUENTIAL;
+     176             : 
+     177             :         /* open for read */
+     178     1720631 :         handle->f = open_noatime(handle->path, flags | O_RDONLY);
+     179     1720631 :         if (handle->f == -1) {
+     180             :                 /* invalidate for error */
+     181      189310 :                 handle->file = 0;
+     182      189310 :                 handle->f = -1;
+     183      189310 :                 handle->valid_size = 0;
+     184             : 
+     185      189310 :                 if (errno == ENOENT)
+     186      189298 :                         out_missing("Missing file '%s'.\n", handle->path);
+     187             :                 else
+     188          12 :                         out("Error opening file '%s'. %s.\n", handle->path, strerror(errno));
+     189      189310 :                 return -1;
+     190             :         }
+     191             : 
+     192             :         /* just opened */
+     193     1531321 :         handle->file = file;
+     194             : 
+     195             :         /* get the stat info */
+     196     1531321 :         ret = fstat(handle->f, &handle->st);
+     197     1531321 :         if (ret != 0) {
+     198             :                 /* LCOV_EXCL_START */
+     199             :                 out("Error accessing file '%s'. %s.\n", handle->path, strerror(errno));
+     200             :                 return -1;
+     201             :                 /* LCOV_EXCL_STOP */
+     202             :         }
+     203             : 
+     204             :         /* get the size of the existing data */
+     205     1531321 :         handle->valid_size = handle->st.st_size;
+     206             : 
+     207             : #if HAVE_POSIX_FADVISE
+     208     1531321 :         if ((mode & MODE_SEQUENTIAL) != 0) {
+     209             :                 /* advise sequential access */
+     210     1519991 :                 ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL);
+     211     1519991 :                 if (ret != 0) {
+     212             :                         /* LCOV_EXCL_START */
+     213             :                         out("Error advising file '%s'. %s.\n", handle->path, strerror(ret));
+     214             :                         return -1;
+     215             :                         /* LCOV_EXCL_STOP */
+     216             :                 }
+     217             :         }
+     218             : #endif
+     219             : 
+     220     1531321 :         return 0;
+     221             : }
+     222             : 
+     223     4545866 : int handle_close(struct snapraid_handle* handle)
+     224             : {
+     225             :         int ret;
+     226             : 
+     227             :         /* close if open */
+     228     4545866 :         if (handle->f != -1) {
+     229     2304495 :                 ret = close(handle->f);
+     230     2304495 :                 if (ret != 0) {
+     231             :                         /* LCOV_EXCL_START */
+     232             :                         log_fatal("Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno));
+     233             : 
+     234             :                         /* invalidate for error */
+     235             :                         handle->file = 0;
+     236             :                         handle->f = -1;
+     237             :                         handle->valid_size = 0;
+     238             :                         return -1;
+     239             :                         /* LCOV_EXCL_STOP */
+     240             :                 }
+     241             :         }
+     242             : 
+     243             :         /* reset the descriptor */
+     244     4545866 :         handle->file = 0;
+     245     4545866 :         handle->f = -1;
+     246     4545866 :         handle->valid_size = 0;
+     247             : 
+     248     4545866 :         return 0;
+     249             : }
+     250             : 
+     251     5583462 : int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing)
+     252             : {
+     253             :         ssize_t read_ret;
+     254             :         data_off_t offset;
+     255             :         unsigned read_size;
+     256             :         unsigned count;
+     257             : 
+     258     5583462 :         offset = block_file_pos(block) * (data_off_t)block_size;
+     259             : 
+     260     5583462 :         if (!out_missing)
+     261     5570037 :                 out_missing = out;
+     262             : 
+     263             :         /* check if we are going to read only not initialized data */
+     264     5583462 :         if (offset >= handle->valid_size) {
+     265             :                 /* if the file is missing, it's at 0 size, or it's rebuilt while reading */
+     266      432889 :                 if (offset == handle->valid_size || handle->valid_size == 0)
+     267      431572 :                         out_missing("Reading data from missing file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
+     268             :                 else
+     269        1317 :                         out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
+     270      432889 :                 return -1;
+     271             :         }
+     272             : 
+     273     5150573 :         read_size = block_file_size(block, block_size);
+     274             : 
+     275             : #if !HAVE_PREAD
+     276             :         if (lseek(handle->f, offset, SEEK_SET) != offset) {
+     277             :                 /* LCOV_EXCL_START */
+     278             :                 out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno));
+     279             :                 return -1;
+     280             :                 /* LCOV_EXCL_STOP */
+     281             :         }
+     282             : #endif
+     283             : 
+     284     5150573 :         count = 0;
+     285             :         do {
+     286             : 
+     287             : #if HAVE_PREAD
+     288     5159817 :                 read_ret = pread(handle->f, block_buffer + count, read_size - count, offset + count);
+     289             : #else
+     290             :                 read_ret = read(handle->f, block_buffer + count, read_size - count);
+     291             : #endif
+     292             : 
+     293     5159817 :                 if (read_ret < 0) {
+     294             :                         /* LCOV_EXCL_START */
+     295             :                         out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno));
+     296             :                         return -1;
+     297             :                         /* LCOV_EXCL_STOP */
+     298             :                 }
+     299     5159817 :                 if (read_ret == 0) {
+     300        9244 :                         out("Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno));
+     301        9244 :                         return -1;
+     302             :                 }
+     303             : 
+     304     5150573 :                 count += read_ret;
+     305     5150573 :         } while (count < read_size);
+     306             : 
+     307             :         /* pad with 0 */
+     308     5141329 :         if (read_size < block_size) {
+     309     2081857 :                 memset(block_buffer + read_size, 0, block_size - read_size);
+     310             :         }
+     311             : 
+     312             :         /* Here isn't needed to call posix_fadvise(..., POSIX_FADV_DONTNEED) */
+     313             :         /* because we already advised sequential access with POSIX_FADV_SEQUENTIAL. */
+     314             :         /* In Linux 2.6.33 it's enough to ensure that data is not kept in the cache. */
+     315             :         /* Better to do nothing and save a syscall for each block. */
+     316             : 
+     317             :         /* Here we cannot call posix_fadvise(..., POSIX_FADV_WILLNEED) for the next block */
+     318             :         /* because it may be blocking */
+     319             :         /* See Ted Ts'o comment in "posix_fadvise(POSIX_FADV_WILLNEED) waits before returning?" */
+     320             :         /* at: https://lkml.org/lkml/2010/12/6/122 */
+     321             :         /* We relay only on the automatic readahead triggered by POSIX_FADV_SEQUENTIAL. */
+     322             : 
+     323     5141329 :         return read_size;
+     324             : }
+     325             : 
+     326      288068 : int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size)
+     327             : {
+     328             :         ssize_t write_ret;
+     329             :         data_off_t offset;
+     330             :         unsigned write_size;
+     331             : 
+     332      288068 :         offset = block_file_pos(block) * (data_off_t)block_size;
+     333             : 
+     334      288068 :         write_size = block_file_size(block, block_size);
+     335             : 
+     336             : #if HAVE_PWRITE
+     337      288068 :         write_ret = pwrite(handle->f, block_buffer, write_size, offset);
+     338             : #else
+     339             :         if (lseek(handle->f, offset, SEEK_SET) != offset) {
+     340             :                 /* LCOV_EXCL_START */
+     341             :                 log_fatal("Error seeking file '%s'. %s.\n", handle->path, strerror(errno));
+     342             :                 return -1;
+     343             :                 /* LCOV_EXCL_STOP */
+     344             :         }
+     345             : 
+     346             :         write_ret = write(handle->f, block_buffer, write_size);
+     347             : #endif
+     348      288068 :         if (write_ret != (ssize_t)write_size) { /* conversion is safe because block_size is always small */
+     349             :                 /* LCOV_EXCL_START */
+     350             :                 log_fatal("Error writing file '%s'. %s.\n", handle->path, strerror(errno));
+     351             :                 return -1;
+     352             :                 /* LCOV_EXCL_STOP */
+     353             :         }
+     354             : 
+     355             :         /* adjust the size of the valid data */
+     356      288068 :         if (handle->valid_size < offset + write_size) {
+     357      282038 :                 handle->valid_size = offset + write_size;
+     358             :         }
+     359             : 
+     360             :         /* Here doesn't make sense to call posix_fadvise(..., POSIX_FADV_DONTNEED) because */
+     361             :         /* at this time the data is still not yet written and it cannot be discharged. */
+     362             : 
+     363      288068 :         return 0;
+     364             : }
+     365             : 
+     366      119610 : int handle_utime(struct snapraid_handle* handle)
+     367             : {
+     368             :         int ret;
+     369             : 
+     370             :         /* do nothing if not opened */
+     371      119610 :         if (handle->f == -1)
+     372           7 :                 return 0;
+     373             : 
+     374      119603 :         ret = fmtime(handle->f, handle->file->mtime_sec, handle->file->mtime_nsec);
+     375             : 
+     376      119603 :         if (ret != 0) {
+     377             :                 /* LCOV_EXCL_START */
+     378             :                 log_fatal("Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno));
+     379             :                 return -1;
+     380             :                 /* LCOV_EXCL_STOP */
+     381             :         }
+     382             : 
+     383      119603 :         return 0;
+     384             : }
+     385             : 
+     386         197 : struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handlemax)
+     387             : {
+     388             :         tommy_node* i;
+     389             :         unsigned j;
+     390         197 :         unsigned size = 0;
+     391             :         struct snapraid_handle* handle;
+     392             : 
+     393             :         /* get the size of the mapping */
+     394         197 :         size = 0;
+     395        1374 :         for (i = state->maplist; i != 0; i = i->next) {
+     396        1177 :                 struct snapraid_map* map = i->data;
+     397        1177 :                 if (map->position > size)
+     398         850 :                         size = map->position;
+     399             :         }
+     400         197 :         ++size; /* size is one more than the max */
+     401             : 
+     402         197 :         handle = malloc_nofail(size * sizeof(struct snapraid_handle));
+     403             : 
+     404        1379 :         for (j = 0; j < size; ++j) {
+     405             :                 /* default for empty position */
+     406        1182 :                 handle[j].disk = 0;
+     407        1182 :                 handle[j].file = 0;
+     408        1182 :                 handle[j].f = -1;
+     409        1182 :                 handle[j].valid_size = 0;
+     410             :         }
+     411             : 
+     412             :         /* set the vector */
+     413        1374 :         for (i = state->disklist; i != 0; i = i->next) {
+     414             :                 struct snapraid_map* map;
+     415        1177 :                 struct snapraid_disk* disk = i->data;
+     416             :                 tommy_node* k;
+     417             : 
+     418             :                 /* search the mapping for this disk */
+     419        4107 :                 for (k = state->maplist; k != 0; k = k->next) {
+     420        4107 :                         map = k->data;
+     421        4107 :                         if (strcmp(disk->name, map->name) == 0)
+     422        1177 :                                 break;
+     423             :                 }
+     424        1177 :                 if (k == 0) {
+     425             :                         /* LCOV_EXCL_START */
+     426             :                         log_fatal("Internal error for inconsistent disk mapping.\n");
+     427             :                         exit(EXIT_FAILURE);
+     428             :                         /* LCOV_EXCL_STOP */
+     429             :                 }
+     430             : 
+     431        1177 :                 handle[map->position].disk = disk;
+     432             :         }
+     433             : 
+     434         197 :         *handlemax = size;
+     435         197 :         return handle;
+     436             : }
+     437             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/import.c.func-sort-c.html b/cov/cmdline/import.c.func-sort-c.html new file mode 100644 index 00000000..ce7b3352 --- /dev/null +++ b/cov/cmdline/import.c.func-sort-c.html @@ -0,0 +1,104 @@ + + + + + + + LCOV - lcov.info - cmdline/import.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - import.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:10310598.1 %
Date:2015-05-12Functions:88100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
import_block_hash647895
state_import_fetch638951
import_block_prevhash_compare2240
import_block_hash_compare2232
import_file1750
import_file_free1750
state_import1
import_dir1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/import.c.func.html b/cov/cmdline/import.c.func.html new file mode 100644 index 00000000..dbfbd068 --- /dev/null +++ b/cov/cmdline/import.c.func.html @@ -0,0 +1,104 @@ + + + + + + + LCOV - lcov.info - cmdline/import.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - import.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:10310598.1 %
Date:2015-05-12Functions:88100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
import_block_hash647895
import_block_hash_compare2232
import_block_prevhash_compare2240
import_dir1
import_file1750
import_file_free1750
state_import1
state_import_fetch638951
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/import.c.gcov.html b/cov/cmdline/import.c.gcov.html new file mode 100644 index 00000000..8a22194c --- /dev/null +++ b/cov/cmdline/import.c.gcov.html @@ -0,0 +1,401 @@ + + + + + + + LCOV - lcov.info - cmdline/import.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - import.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:10310598.1 %
Date:2015-05-12Functions:88100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "import.h"
+      22             : 
+      23             : /****************************************************************************/
+      24             : /* import */
+      25             : 
+      26             : /**
+      27             :  * Compares the hash of two import blocks.
+      28             :  */
+      29        2232 : int import_block_hash_compare(const void* void_arg, const void* void_data)
+      30             : {
+      31        2232 :         const unsigned char* arg = void_arg;
+      32        2232 :         const struct snapraid_import_block* block = void_data;
+      33             : 
+      34        2232 :         return memcmp(arg, block->hash, HASH_SIZE);
+      35             : }
+      36             : 
+      37        2240 : int import_block_prevhash_compare(const void* void_arg, const void* void_data)
+      38             : {
+      39        2240 :         const unsigned char* arg = void_arg;
+      40        2240 :         const struct snapraid_import_block* block = void_data;
+      41             : 
+      42        2240 :         return memcmp(arg, block->prevhash, HASH_SIZE);
+      43             : }
+      44             : 
+      45             : /**
+      46             :  * Computes the hash of the hash for an import block.
+      47             :  * We just use the first 32 bit of the hash itself.
+      48             :  */
+      49      647895 : static inline tommy_uint32_t import_block_hash(const unsigned char* hash)
+      50             : {
+      51      647895 :         return *(const tommy_uint32_t*)hash;
+      52             : }
+      53             : 
+      54        1750 : static void import_file(struct snapraid_state* state, const char* path, uint64_t size)
+      55             : {
+      56             :         struct snapraid_import_file* file;
+      57             :         block_off_t i;
+      58             :         data_off_t offset;
+      59             :         void* buffer;
+      60             :         int ret;
+      61             :         int f;
+      62             :         int flags;
+      63        1750 :         unsigned block_size = state->block_size;
+      64             : 
+      65        1750 :         file = malloc_nofail(sizeof(struct snapraid_import_file));
+      66        1750 :         file->path = strdup_nofail(path);
+      67        1750 :         file->size = size;
+      68        1750 :         file->blockmax = (size + block_size - 1) / block_size;
+      69        1750 :         file->blockvec = malloc_nofail(file->blockmax * sizeof(struct snapraid_import_block));
+      70             : 
+      71        1750 :         buffer = malloc_nofail(block_size);
+      72             : 
+      73             :         /* open for read */
+      74             :         /* O_SEQUENTIAL: opening in sequential mode in Windows */
+      75        1750 :         flags = O_RDONLY | O_BINARY;
+      76        1750 :         if ((state->file_mode & MODE_SEQUENTIAL) != 0)
+      77        1750 :                 flags |= O_SEQUENTIAL;
+      78        1750 :         f = open(path, flags);
+      79        1750 :         if (f == -1) {
+      80             :                 /* LCOV_EXCL_START */
+      81             :                 log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno));
+      82             :                 exit(EXIT_FAILURE);
+      83             :                 /* LCOV_EXCL_STOP */
+      84             :         }
+      85             : 
+      86             : #if HAVE_POSIX_FADVISE
+      87        1750 :         if ((state->file_mode & MODE_SEQUENTIAL) != 0) {
+      88             :                 /* advise sequential access */
+      89        1750 :                 ret = posix_fadvise(f, 0, 0, POSIX_FADV_SEQUENTIAL);
+      90        1750 :                 if (ret != 0) {
+      91             :                         /* LCOV_EXCL_START */
+      92             :                         log_fatal("Error advising file '%s'. %s.\n", path, strerror(ret));
+      93             :                         exit(EXIT_FAILURE);
+      94             :                         /* LCOV_EXCL_STOP */
+      95             :                 }
+      96             :         }
+      97             : #endif
+      98             : 
+      99        1750 :         offset = 0;
+     100        6222 :         for (i = 0; i < file->blockmax; ++i) {
+     101        4472 :                 struct snapraid_import_block* block = &file->blockvec[i];
+     102        4472 :                 unsigned read_size = block_size;
+     103        4472 :                 if (read_size > size)
+     104        1745 :                         read_size = size;
+     105             : 
+     106        4472 :                 ret = read(f, buffer, read_size);
+     107        4472 :                 if (ret < 0 || (unsigned)ret != read_size) {
+     108             :                         /* LCOV_EXCL_START */
+     109             :                         log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno));
+     110             :                         exit(EXIT_FAILURE);
+     111             :                         /* LCOV_EXCL_STOP */
+     112             :                 }
+     113             : 
+     114        4472 :                 block->file = file;
+     115        4472 :                 block->offset = offset;
+     116        4472 :                 block->size = read_size;
+     117             : 
+     118        4472 :                 memhash(state->hash, state->hashseed, block->hash, buffer, read_size);
+     119        4472 :                 tommy_hashdyn_insert(&state->importset, &block->nodeset, block, import_block_hash(block->hash));
+     120             : 
+     121             :                 /* if we are in a rehash state */
+     122        4472 :                 if (state->prevhash != HASH_UNDEFINED) {
+     123             :                         /* compute also the previous hash */
+     124        4472 :                         memhash(state->prevhash, state->prevhashseed, block->prevhash, buffer, read_size);
+     125        4472 :                         tommy_hashdyn_insert(&state->previmportset, &block->prevnodeset, block, import_block_hash(block->prevhash));
+     126             :                 }
+     127             : 
+     128        4472 :                 offset += read_size;
+     129        4472 :                 size -= read_size;
+     130             :         }
+     131             : 
+     132        1750 :         ret = close(f);
+     133        1750 :         if (ret != 0) {
+     134             :                 /* LCOV_EXCL_START */
+     135             :                 log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno));
+     136             :                 exit(EXIT_FAILURE);
+     137             :                 /* LCOV_EXCL_STOP */
+     138             :         }
+     139             : 
+     140        1750 :         tommy_list_insert_tail(&state->importlist, &file->nodelist, file);
+     141             : 
+     142        1750 :         free(buffer);
+     143        1750 : }
+     144             : 
+     145        1750 : void import_file_free(struct snapraid_import_file* file)
+     146             : {
+     147        1750 :         free(file->path);
+     148        1750 :         free(file->blockvec);
+     149        1750 :         free(file);
+     150        1750 : }
+     151             : 
+     152      638951 : int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid_block* missing_block, unsigned char* buffer)
+     153             : {
+     154             :         struct snapraid_import_block* block;
+     155             :         int ret;
+     156             :         int f;
+     157      638951 :         const unsigned char* hash = missing_block->hash;
+     158      638951 :         unsigned block_size = state->block_size;
+     159             :         unsigned read_size;
+     160             :         unsigned char buffer_hash[HASH_SIZE];
+     161             :         const char* path;
+     162             : 
+     163      638951 :         if (rehash) {
+     164       28985 :                 block = tommy_hashdyn_search(&state->previmportset, import_block_prevhash_compare, hash, import_block_hash(hash));
+     165             :         } else {
+     166      609966 :                 block = tommy_hashdyn_search(&state->importset, import_block_hash_compare, hash, import_block_hash(hash));
+     167             :         }
+     168      638951 :         if (!block)
+     169      634479 :                 return -1;
+     170             : 
+     171        4472 :         path = block->file->path;
+     172        4472 :         read_size = block->size;
+     173             : 
+     174        4472 :         f = open(path, O_RDONLY | O_BINARY);
+     175        4472 :         if (f == -1) {
+     176             :                 /* LCOV_EXCL_START */
+     177             :                 if (errno == ENOENT) {
+     178             :                         log_fatal("DANGER! file '%s' disappeared.\n", path);
+     179             :                         log_fatal("If you moved it, please rerun the same command.\n");
+     180             :                 } else {
+     181             :                         log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno));
+     182             :                 }
+     183             :                 exit(EXIT_FAILURE);
+     184             :                 /* LCOV_EXCL_STOP */
+     185             :         }
+     186             : 
+     187        4472 :         if (lseek(f, block->offset, SEEK_SET) != block->offset) {
+     188             :                 /* LCOV_EXCL_START */
+     189             :                 log_fatal("Error seeking file '%s'. %s.\n", path, strerror(errno));
+     190             :                 exit(EXIT_FAILURE);
+     191             :                 /* LCOV_EXCL_STOP */
+     192             :         }
+     193             : 
+     194        4472 :         ret = read(f, buffer, read_size);
+     195        4472 :         if (ret < 0 || (unsigned)ret != read_size) {
+     196             :                 /* LCOV_EXCL_START */
+     197             :                 log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno));
+     198             :                 exit(EXIT_FAILURE);
+     199             :                 /* LCOV_EXCL_STOP */
+     200             :         }
+     201             : 
+     202        4472 :         ret = close(f);
+     203        4472 :         if (ret != 0) {
+     204             :                 /* LCOV_EXCL_START */
+     205             :                 log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno));
+     206             :                 exit(EXIT_FAILURE);
+     207             :                 /* LCOV_EXCL_STOP */
+     208             :         }
+     209             : 
+     210        4472 :         if (read_size != block_size) {
+     211             :                 /* fill the remaining with 0 */
+     212        1745 :                 memset(buffer + read_size, 0, block_size - read_size);
+     213             :         }
+     214             : 
+     215             :         /* recheck the hash */
+     216        4472 :         if (rehash)
+     217        2240 :                 memhash(state->prevhash, state->prevhashseed, buffer_hash, buffer, read_size);
+     218             :         else
+     219        2232 :                 memhash(state->hash, state->hashseed, buffer_hash, buffer, read_size);
+     220             : 
+     221        4472 :         if (memcmp(buffer_hash, hash, HASH_SIZE) != 0) {
+     222             :                 /* LCOV_EXCL_START */
+     223             :                 log_fatal("Error in data reading file '%s'.\n", path);
+     224             :                 log_fatal("Please don't change imported files while running.\n");
+     225             :                 exit(EXIT_FAILURE);
+     226             :                 /* LCOV_EXCL_STOP */
+     227             :         }
+     228             : 
+     229        4472 :         return 0;
+     230             : }
+     231             : 
+     232           1 : static void import_dir(struct snapraid_state* state, const char* dir)
+     233             : {
+     234             :         DIR* d;
+     235             : 
+     236           1 :         d = opendir(dir);
+     237           1 :         if (!d) {
+     238             :                 /* LCOV_EXCL_START */
+     239             :                 log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno));
+     240             :                 exit(EXIT_FAILURE);
+     241             :                 /* LCOV_EXCL_STOP */
+     242             :         }
+     243             : 
+     244             :         while (1) {
+     245             :                 char path_next[PATH_MAX];
+     246             :                 struct stat st;
+     247             :                 const char* name;
+     248             :                 struct dirent* dd;
+     249             : 
+     250             :                 /* clear errno to detect erroneous conditions */
+     251        1812 :                 errno = 0;
+     252        1812 :                 dd = readdir(d);
+     253        1812 :                 if (dd == 0 && errno != 0) {
+     254             :                         /* LCOV_EXCL_START */
+     255             :                         log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno));
+     256             :                         exit(EXIT_FAILURE);
+     257             :                         /* LCOV_EXCL_STOP */
+     258             :                 }
+     259        1812 :                 if (dd == 0) {
+     260           1 :                         break; /* finished */
+     261             :                 }
+     262             : 
+     263             :                 /* skip "." and ".." files */
+     264        1811 :                 name = dd->d_name;
+     265        1811 :                 if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
+     266           2 :                         continue;
+     267             : 
+     268        1809 :                 pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
+     269             : 
+     270             : #if HAVE_STRUCT_DIRENT_D_STAT
+     271             :                 /* convert dirent to lstat result */
+     272             :                 dirent_lstat(dd, &st);
+     273             : 
+     274             :                 /* if the st_mode field is missing, takes care to fill it using normal lstat() */
+     275             :                 /* at now this can happen only in Windows (with HAVE_STRUCT_DIRENT_D_STAT defined), */
+     276             :                 /* because we use a directory reading method that doesn't read info about ReparsePoint. */
+     277             :                 /* Note that here we cannot call here lstat_sync(), because we don't know what kind */
+     278             :                 /* of file is it, and lstat_sync() doesn't always work */
+     279             :                 if (st.st_mode == 0) {
+     280             :                         if (lstat(path_next, &st) != 0) {
+     281             :                                 /* LCOV_EXCL_START */
+     282             :                                 log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+     283             :                                 exit(EXIT_FAILURE);
+     284             :                                 /* LCOV_EXCL_STOP */
+     285             :                         }
+     286             :                 }
+     287             : #else
+     288             :                 /* get lstat info about the file */
+     289        1809 :                 if (lstat(path_next, &st) != 0) {
+     290             :                         /* LCOV_EXCL_START */
+     291             :                         log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+     292             :                         exit(EXIT_FAILURE);
+     293             :                         /* LCOV_EXCL_STOP */
+     294             :                 }
+     295             : #endif
+     296             : 
+     297        1809 :                 if (S_ISREG(st.st_mode)) {
+     298        1750 :                         import_file(state, path_next, st.st_size);
+     299          59 :                 } else if (S_ISDIR(st.st_mode)) {
+     300           0 :                         pathslash(path_next, sizeof(path_next));
+     301           0 :                         import_dir(state, path_next);
+     302             :                 }
+     303        1811 :         }
+     304             : 
+     305           1 :         if (closedir(d) != 0) {
+     306             :                 /* LCOV_EXCL_START */
+     307             :                 log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno));
+     308             :                 exit(EXIT_FAILURE);
+     309             :                 /* LCOV_EXCL_STOP */
+     310             :         }
+     311           1 : }
+     312             : 
+     313           1 : void state_import(struct snapraid_state* state, const char* dir)
+     314             : {
+     315             :         char path[PATH_MAX];
+     316             : 
+     317           1 :         msg_progress("Importing...\n");
+     318             : 
+     319             :         /* add the final slash */
+     320           1 :         pathimport(path, sizeof(path), dir);
+     321           1 :         pathslash(path, sizeof(path));
+     322             : 
+     323           1 :         import_dir(state, path);
+     324           1 : }
+     325             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/index-sort-f.html b/cov/cmdline/index-sort-f.html new file mode 100644 index 00000000..c1defe0a --- /dev/null +++ b/cov/cmdline/index-sort-f.html @@ -0,0 +1,423 @@ + + + + + + + LCOV - lcov.info - cmdline + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdlineHitTotalCoverage
Test:lcov.infoLines:7292806790.4 %
Date:2015-05-12Functions:36237596.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
support.c +
75.3%75.3%
+
75.3 %232 / 30885.3 %29 / 34
parity.c +
79.9%79.9%
+
79.9 %111 / 13990.9 %10 / 11
unix.c +
78.5%78.5%
+
78.5 %227 / 28991.3 %21 / 23
stream.h +
90.7%90.7%
+
90.7 %39 / 4391.7 %11 / 12
elem.c +
91.1%91.1%
+
91.1 %350 / 38495.7 %45 / 47
state.c +
90.7%90.7%
+
90.7 %1547 / 170596.9 %31 / 32
elem.h +
95.8%95.8%
+
95.8 %114 / 11997.4 %37 / 38
util.h +
80.0%80.0%
+
80.0 %4 / 5100.0 %1 / 1
nano.c +
100.0%
+
100.0 %26 / 26100.0 %1 / 1
portable.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1
rehash.c +
95.0%95.0%
+
95.0 %19 / 20100.0 %1 / 1
spooky2.c +
100.0%
+
100.0 %20 / 20100.0 %1 / 1
list.c +
95.7%95.7%
+
95.7 %44 / 46100.0 %1 / 1
speed.c +
99.8%99.8%
+
99.8 %403 / 404100.0 %2 / 2
mkstream.c +
100.0%
+
100.0 %55 / 55100.0 %2 / 2
murmur3.c +
100.0%
+
100.0 %70 / 70100.0 %2 / 2
dry.c +
85.7%85.7%
+
85.7 %72 / 84100.0 %2 / 2
pool.c +
94.1%94.1%
+
94.1 %64 / 68100.0 %3 / 3
status.c +
96.4%96.4%
+
96.4 %240 / 249100.0 %3 / 3
state.h +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
sync.c +
94.0%94.0%
+
94.0 %426 / 453100.0 %4 / 4
scrub.c +
77.9%77.9%
+
77.9 %215 / 276100.0 %4 / 4
dup.c +
93.3%93.3%
+
93.3 %56 / 60100.0 %5 / 5
search.c +
91.8%91.8%
+
91.8 %90 / 98100.0 %7 / 7
selftest.c +
87.7%87.7%
+
87.7 %114 / 130100.0 %7 / 7
snapraid.c +
92.5%92.5%
+
92.5 %409 / 442100.0 %7 / 7
import.c +
98.1%98.1%
+
98.1 %103 / 105100.0 %8 / 8
handle.c +
98.4%98.4%
+
98.4 %126 / 128100.0 %8 / 8
check.c +
91.5%91.5%
+
91.5 %680 / 743100.0 %9 / 9
device.c +
88.9%88.9%
+
88.9 %280 / 315100.0 %11 / 11
util.c +
95.7%95.7%
+
95.7 %67 / 70100.0 %13 / 13
mktest.c +
93.2%93.2%
+
93.2 %220 / 236100.0 %18 / 18
scan.c +
83.5%83.5%
+
83.5 %516 / 618100.0 %22 / 22
stream.c +
98.2%98.2%
+
98.2 %326 / 332100.0 %31 / 31
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/index-sort-l.html b/cov/cmdline/index-sort-l.html new file mode 100644 index 00000000..7fa00e9e --- /dev/null +++ b/cov/cmdline/index-sort-l.html @@ -0,0 +1,423 @@ + + + + + + + LCOV - lcov.info - cmdline + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdlineHitTotalCoverage
Test:lcov.infoLines:7292806790.4 %
Date:2015-05-12Functions:36237596.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
support.c +
75.3%75.3%
+
75.3 %232 / 30885.3 %29 / 34
scrub.c +
77.9%77.9%
+
77.9 %215 / 276100.0 %4 / 4
unix.c +
78.5%78.5%
+
78.5 %227 / 28991.3 %21 / 23
parity.c +
79.9%79.9%
+
79.9 %111 / 13990.9 %10 / 11
util.h +
80.0%80.0%
+
80.0 %4 / 5100.0 %1 / 1
scan.c +
83.5%83.5%
+
83.5 %516 / 618100.0 %22 / 22
dry.c +
85.7%85.7%
+
85.7 %72 / 84100.0 %2 / 2
selftest.c +
87.7%87.7%
+
87.7 %114 / 130100.0 %7 / 7
device.c +
88.9%88.9%
+
88.9 %280 / 315100.0 %11 / 11
stream.h +
90.7%90.7%
+
90.7 %39 / 4391.7 %11 / 12
state.c +
90.7%90.7%
+
90.7 %1547 / 170596.9 %31 / 32
elem.c +
91.1%91.1%
+
91.1 %350 / 38495.7 %45 / 47
check.c +
91.5%91.5%
+
91.5 %680 / 743100.0 %9 / 9
search.c +
91.8%91.8%
+
91.8 %90 / 98100.0 %7 / 7
snapraid.c +
92.5%92.5%
+
92.5 %409 / 442100.0 %7 / 7
mktest.c +
93.2%93.2%
+
93.2 %220 / 236100.0 %18 / 18
dup.c +
93.3%93.3%
+
93.3 %56 / 60100.0 %5 / 5
sync.c +
94.0%94.0%
+
94.0 %426 / 453100.0 %4 / 4
pool.c +
94.1%94.1%
+
94.1 %64 / 68100.0 %3 / 3
rehash.c +
95.0%95.0%
+
95.0 %19 / 20100.0 %1 / 1
list.c +
95.7%95.7%
+
95.7 %44 / 46100.0 %1 / 1
util.c +
95.7%95.7%
+
95.7 %67 / 70100.0 %13 / 13
elem.h +
95.8%95.8%
+
95.8 %114 / 11997.4 %37 / 38
status.c +
96.4%96.4%
+
96.4 %240 / 249100.0 %3 / 3
import.c +
98.1%98.1%
+
98.1 %103 / 105100.0 %8 / 8
stream.c +
98.2%98.2%
+
98.2 %326 / 332100.0 %31 / 31
handle.c +
98.4%98.4%
+
98.4 %126 / 128100.0 %8 / 8
speed.c +
99.8%99.8%
+
99.8 %403 / 404100.0 %2 / 2
portable.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1
spooky2.c +
100.0%
+
100.0 %20 / 20100.0 %1 / 1
state.h +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
nano.c +
100.0%
+
100.0 %26 / 26100.0 %1 / 1
mkstream.c +
100.0%
+
100.0 %55 / 55100.0 %2 / 2
murmur3.c +
100.0%
+
100.0 %70 / 70100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/index.html b/cov/cmdline/index.html new file mode 100644 index 00000000..7aaa2003 --- /dev/null +++ b/cov/cmdline/index.html @@ -0,0 +1,423 @@ + + + + + + + LCOV - lcov.info - cmdline + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdlineHitTotalCoverage
Test:lcov.infoLines:7292806790.4 %
Date:2015-05-12Functions:36237596.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
check.c +
91.5%91.5%
+
91.5 %680 / 743100.0 %9 / 9
device.c +
88.9%88.9%
+
88.9 %280 / 315100.0 %11 / 11
dry.c +
85.7%85.7%
+
85.7 %72 / 84100.0 %2 / 2
dup.c +
93.3%93.3%
+
93.3 %56 / 60100.0 %5 / 5
elem.c +
91.1%91.1%
+
91.1 %350 / 38495.7 %45 / 47
elem.h +
95.8%95.8%
+
95.8 %114 / 11997.4 %37 / 38
handle.c +
98.4%98.4%
+
98.4 %126 / 128100.0 %8 / 8
import.c +
98.1%98.1%
+
98.1 %103 / 105100.0 %8 / 8
list.c +
95.7%95.7%
+
95.7 %44 / 46100.0 %1 / 1
mkstream.c +
100.0%
+
100.0 %55 / 55100.0 %2 / 2
mktest.c +
93.2%93.2%
+
93.2 %220 / 236100.0 %18 / 18
murmur3.c +
100.0%
+
100.0 %70 / 70100.0 %2 / 2
nano.c +
100.0%
+
100.0 %26 / 26100.0 %1 / 1
parity.c +
79.9%79.9%
+
79.9 %111 / 13990.9 %10 / 11
pool.c +
94.1%94.1%
+
94.1 %64 / 68100.0 %3 / 3
portable.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1
rehash.c +
95.0%95.0%
+
95.0 %19 / 20100.0 %1 / 1
scan.c +
83.5%83.5%
+
83.5 %516 / 618100.0 %22 / 22
scrub.c +
77.9%77.9%
+
77.9 %215 / 276100.0 %4 / 4
search.c +
91.8%91.8%
+
91.8 %90 / 98100.0 %7 / 7
selftest.c +
87.7%87.7%
+
87.7 %114 / 130100.0 %7 / 7
snapraid.c +
92.5%92.5%
+
92.5 %409 / 442100.0 %7 / 7
speed.c +
99.8%99.8%
+
99.8 %403 / 404100.0 %2 / 2
spooky2.c +
100.0%
+
100.0 %20 / 20100.0 %1 / 1
state.c +
90.7%90.7%
+
90.7 %1547 / 170596.9 %31 / 32
state.h +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
status.c +
96.4%96.4%
+
96.4 %240 / 249100.0 %3 / 3
stream.c +
98.2%98.2%
+
98.2 %326 / 332100.0 %31 / 31
stream.h +
90.7%90.7%
+
90.7 %39 / 4391.7 %11 / 12
support.c +
75.3%75.3%
+
75.3 %232 / 30885.3 %29 / 34
sync.c +
94.0%94.0%
+
94.0 %426 / 453100.0 %4 / 4
unix.c +
78.5%78.5%
+
78.5 %227 / 28991.3 %21 / 23
util.c +
95.7%95.7%
+
95.7 %67 / 70100.0 %13 / 13
util.h +
80.0%80.0%
+
80.0 %4 / 5100.0 %1 / 1
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/list.c.func-sort-c.html b/cov/cmdline/list.c.func-sort-c.html new file mode 100644 index 00000000..607ae988 --- /dev/null +++ b/cov/cmdline/list.c.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/list.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - list.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:444695.7 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_list3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/list.c.func.html b/cov/cmdline/list.c.func.html new file mode 100644 index 00000000..4b2ead96 --- /dev/null +++ b/cov/cmdline/list.c.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/list.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - list.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:444695.7 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_list3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/list.c.gcov.html b/cov/cmdline/list.c.gcov.html new file mode 100644 index 00000000..4b453243 --- /dev/null +++ b/cov/cmdline/list.c.gcov.html @@ -0,0 +1,197 @@ + + + + + + + LCOV - lcov.info - cmdline/list.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - list.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:444695.7 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "util.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : 
+      26             : /****************************************************************************/
+      27             : /* list */
+      28             : 
+      29           3 : void state_list(struct snapraid_state* state)
+      30             : {
+      31             :         tommy_node* i;
+      32             :         unsigned file_count;
+      33             :         data_off_t file_size;
+      34             :         unsigned link_count;
+      35             : 
+      36           3 :         file_count = 0;
+      37           3 :         file_size = 0;
+      38           3 :         link_count = 0;
+      39             : 
+      40           3 :         msg_progress("Listing...\n");
+      41             : 
+      42             :         /* for each disk */
+      43          21 :         for (i = state->disklist; i != 0; i = i->next) {
+      44             :                 tommy_node* j;
+      45          18 :                 struct snapraid_disk* disk = i->data;
+      46             : 
+      47             :                 /* sort by name */
+      48          18 :                 tommy_list_sort(&disk->filelist, file_path_compare);
+      49             : 
+      50             :                 /* for each file */
+      51       16997 :                 for (j = disk->filelist; j != 0; j = j->next) {
+      52       16979 :                         struct snapraid_file* file = j->data;
+      53             : #if HAVE_LOCALTIME_R
+      54             :                         struct tm tm_res;
+      55             : #endif
+      56             :                         struct tm* tm;
+      57             :                         time_t t;
+      58             : 
+      59       16979 :                         ++file_count;
+      60       16979 :                         file_size += file->size;
+      61             : 
+      62       16979 :                         log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, esc(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode);
+      63             : 
+      64       16979 :                         t = file->mtime_sec;
+      65             : #if HAVE_LOCALTIME_R
+      66       16979 :                         tm = localtime_r(&t, &tm_res);
+      67             : #else
+      68             :                         tm = localtime(&t);
+      69             : #endif
+      70             : 
+      71       16979 :                         printf("%12" PRIu64 " ", file->size);
+      72       16979 :                         if (tm) {
+      73       16979 :                                 printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+      74       16979 :                                 if (msg_level >= MSG_VERBOSE)
+      75       16979 :                                         printf(":%02u.%03u", tm->tm_sec, file->mtime_nsec / 1000000);
+      76       16979 :                                 printf(" ");
+      77             :                         }
+      78       16979 :                         printf("%s%s\n", disk->dir, file->sub);
+      79             :                 }
+      80             : 
+      81             :                 /* sort by name */
+      82          18 :                 tommy_list_sort(&disk->linklist, link_alpha_compare);
+      83             : 
+      84             :                 /* for each link */
+      85         607 :                 for (j = disk->linklist; j != 0; j = j->next) {
+      86         589 :                         struct snapraid_link* link = j->data;
+      87             :                         const char* type;
+      88             : 
+      89         589 :                         switch (link->flag & FILE_IS_LINK_MASK) {
+      90           6 :                         case FILE_IS_HARDLINK : type = "hardlink"; break;
+      91         583 :                         case FILE_IS_SYMLINK : type = "symlink"; break;
+      92           0 :                         case FILE_IS_SYMDIR : type = "symdir"; break;
+      93           0 :                         case FILE_IS_JUNCTION : type = "junction"; break;
+      94             :                         /* LCOV_EXCL_START */
+      95             :                         default : type = "unknown"; break;
+      96             :                                 /* LCOV_EXCL_STOP */
+      97             :                         }
+      98             : 
+      99         589 :                         ++link_count;
+     100             : 
+     101         589 :                         log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc(link->sub), esc(link->linkto));
+     102             : 
+     103         589 :                         printf("%12s ", type);
+     104         589 :                         printf("                 ");
+     105         589 :                         if (msg_level >= MSG_VERBOSE)
+     106         589 :                                 printf("       ");
+     107         589 :                         printf("%s%s -> %s%s\n", disk->dir, link->sub, disk->dir, link->linkto);
+     108             :                 }
+     109             :         }
+     110             : 
+     111           3 :         msg_status("\n");
+     112           3 :         msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA);
+     113           3 :         msg_status("%8u links\n", link_count);
+     114             : 
+     115           3 :         log_tag("summary:file_count:%u\n", file_count);
+     116           3 :         log_tag("summary:file_size:%" PRIu64 "\n", file_size);
+     117           3 :         log_tag("summary:link_count:%u\n", link_count);
+     118           3 :         log_tag("summary:exit:ok\n");
+     119           3 :         log_flush();
+     120           3 : }
+     121             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mkstream.c.func-sort-c.html b/cov/cmdline/mkstream.c.func-sort-c.html new file mode 100644 index 00000000..359ff0e8 --- /dev/null +++ b/cov/cmdline/mkstream.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/mkstream.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mkstream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5555100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
test16
main1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mkstream.c.func.html b/cov/cmdline/mkstream.c.func.html new file mode 100644 index 00000000..45fcdcbb --- /dev/null +++ b/cov/cmdline/mkstream.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/mkstream.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mkstream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5555100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
test16
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mkstream.c.gcov.html b/cov/cmdline/mkstream.c.gcov.html new file mode 100644 index 00000000..104ea167 --- /dev/null +++ b/cov/cmdline/mkstream.c.gcov.html @@ -0,0 +1,288 @@ + + + + + + + LCOV - lcov.info - cmdline/mkstream.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mkstream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5555100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2015 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "stream.h"
+      21             : 
+      22             : #define STREAM_MAX 8
+      23             : #define BUFFER_MAX 64
+      24             : #define STR_MAX 128
+      25             : 
+      26          16 : void test(void)
+      27             : {
+      28             :         struct stream* s;
+      29             :         char file[32];
+      30             :         unsigned char buffer[BUFFER_MAX];
+      31             :         char str[STR_MAX];
+      32             :         unsigned i, j;
+      33          16 :         uint32_t u32 = -1L;
+      34          16 :         uint64_t u64 = -1LL;
+      35             :         uint32_t crc_stored;
+      36             :         uint32_t crc_computed;
+      37             : 
+      38          16 :         crc32c_init();
+      39             : 
+      40          16 :         s = sopen_multi_write(STREAM_MAX);
+      41         144 :         for (i = 0;i < STREAM_MAX; ++i) {
+      42         128 :                 snprintf(file, sizeof(file),  "stream%u.bin", i);
+      43         128 :                 if (sopen_multi_file(s, i, file) != 0) {
+      44             :                         /* LCOV_EXCL_START */
+      45             :                         exit(EXIT_FAILURE);
+      46             :                         /* LCOV_EXCL_STOP */
+      47             :                 }
+      48             :         }
+      49             : 
+      50        4112 :         for(j=0;j<256;++j) {
+      51        4096 :                 if (sputc(j, s) != 0) {
+      52             :                         /* LCOV_EXCL_START */
+      53             :                         exit(EXIT_FAILURE);
+      54             :                         /* LCOV_EXCL_STOP */
+      55             :                 }
+      56             :         }
+      57             : 
+      58         528 :         for(j=0;j<32;++j) {
+      59         512 :                 if (sputb32(u32 >> j, s) != 0) {
+      60             :                         /* LCOV_EXCL_START */
+      61             :                         exit(EXIT_FAILURE);
+      62             :                         /* LCOV_EXCL_STOP */
+      63             :                 }
+      64             :         }
+      65             : 
+      66        1040 :         for(j=0;j<64;++j) {
+      67        1024 :                 if (sputb64(u64 >> j, s) != 0) {
+      68             :                         /* LCOV_EXCL_START */
+      69             :                         exit(EXIT_FAILURE);
+      70             :                         /* LCOV_EXCL_STOP */
+      71             :                 }
+      72             :         }
+      73             : 
+      74        1040 :         for(j=0;j<BUFFER_MAX;++j) {
+      75        1024 :                 memset(buffer, j, j);
+      76        1024 :                 if (swrite(buffer, j, s) != 0) {
+      77             :                         /* LCOV_EXCL_START */
+      78             :                         exit(EXIT_FAILURE);
+      79             :                         /* LCOV_EXCL_STOP */
+      80             :                 }
+      81             :         }
+      82             : 
+      83        2048 :         for(j=1;j<STR_MAX;++j) {
+      84        2032 :                 memset(str, ' ' + j, j-1);
+      85        2032 :                 str[j-1] = 0;
+      86        2032 :                 if (sputbs(str, s) != 0) {
+      87             :                         /* LCOV_EXCL_START */
+      88             :                         exit(EXIT_FAILURE);
+      89             :                         /* LCOV_EXCL_STOP */
+      90             :                 }
+      91             :         }
+      92             : 
+      93             : 
+      94          16 :         crc_stored = scrc(s);
+      95          16 :         crc_computed = scrc_stream(s);
+      96             : 
+      97          16 :         if (crc_stored != crc_computed) {
+      98             :                 /* LCOV_EXCL_START */
+      99             :                 exit(EXIT_FAILURE);
+     100             :                 /* LCOV_EXCL_STOP */
+     101             :         }
+     102             : 
+     103          16 :         if (sputble32(crc_stored, s) != 0) {
+     104             :                 /* LCOV_EXCL_START */
+     105             :                 exit(EXIT_FAILURE);
+     106             :                 /* LCOV_EXCL_STOP */
+     107             :         }
+     108             : 
+     109          16 :         if (sclose(s) != 0) {
+     110             :                 /* LCOV_EXCL_START */
+     111             :                 exit(EXIT_FAILURE);
+     112             :                 /* LCOV_EXCL_STOP */
+     113             :         }
+     114             : 
+     115         144 :         for (i = 0; i < STREAM_MAX; ++i) {
+     116             :                 uint32_t crc_stored;
+     117             :                 uint32_t crc_computed;
+     118         128 :                 snprintf(file, sizeof(file),  "stream%u.bin", i);
+     119             : 
+     120         128 :                 s = sopen_read(file);
+     121         128 :                 if (s == 0) {
+     122             :                         /* LCOV_EXCL_START */
+     123             :                         exit(EXIT_FAILURE);
+     124             :                         /* LCOV_EXCL_STOP */
+     125             :                 }
+     126             : 
+     127       32896 :                 for(j=0;j<256;++j) {
+     128       32768 :                         int c = sgetc(s);
+     129       32768 :                         if (c == EOF || (unsigned char)c != j) {
+     130             :                                 /* LCOV_EXCL_START */
+     131             :                                 exit(EXIT_FAILURE);
+     132             :                                 /* LCOV_EXCL_STOP */
+     133             :                         }
+     134             :                 }
+     135             : 
+     136        4224 :                 for(j=0;j<32;++j) {
+     137             :                         uint32_t v32;
+     138        4096 :                         if (sgetb32(s, &v32) != 0 || v32 != (u32 >> j)) {
+     139             :                                 /* LCOV_EXCL_START */
+     140             :                                 exit(EXIT_FAILURE);
+     141             :                                 /* LCOV_EXCL_STOP */
+     142             :                         }
+     143             :                 }
+     144             : 
+     145        8320 :                 for(j=0;j<64;++j) {
+     146             :                         uint64_t v64;
+     147        8192 :                         if (sgetb64(s, &v64) != 0 || v64 != (u64 >> j)) {
+     148             :                                 /* LCOV_EXCL_START */
+     149             :                                 exit(EXIT_FAILURE);
+     150             :                                 /* LCOV_EXCL_STOP */
+     151             :                         }
+     152             :                 }
+     153             : 
+     154        8192 :                 for(j=1;j<BUFFER_MAX;++j) {
+     155             :                         char copy[BUFFER_MAX];
+     156        8064 :                         memset(buffer, j, j);
+     157        8064 :                         if (sread(s, copy, j) != 0 || memcmp(copy, buffer, j) != 0) {
+     158             :                                 /* LCOV_EXCL_START */
+     159             :                                 exit(EXIT_FAILURE);
+     160             :                                 /* LCOV_EXCL_STOP */
+     161             :                         }
+     162             :                 }
+     163             : 
+     164       16384 :                 for(j=1;j<STR_MAX;++j) {
+     165             :                         char copy[STR_MAX];
+     166       16256 :                         memset(str, ' ' + j, j-1);
+     167       16256 :                         str[j-1] = 0;
+     168       16256 :                         if (sgetbs(s, copy, sizeof(copy)) != 0 || strcmp(copy, str) != 0) {
+     169             :                                 /* LCOV_EXCL_START */
+     170             :                                 exit(EXIT_FAILURE);
+     171             :                                 /* LCOV_EXCL_STOP */
+     172             :                         }
+     173             :                 }
+     174             : 
+     175         128 :                 crc_computed = scrc(s);
+     176             : 
+     177         128 :                 if (sgetble32(s, &crc_stored) != 0) {
+     178             :                         /* LCOV_EXCL_START */
+     179             :                         exit(EXIT_FAILURE);
+     180             :                         /* LCOV_EXCL_STOP */
+     181             :                 }
+     182             : 
+     183         128 :                 if (crc_stored != crc_computed) {
+     184             :                         /* LCOV_EXCL_START */
+     185             :                         exit(EXIT_FAILURE);
+     186             :                         /* LCOV_EXCL_STOP */
+     187             :                 }
+     188             : 
+     189         128 :                 if (sclose(s) != 0) {
+     190             :                         /* LCOV_EXCL_START */
+     191             :                         exit(EXIT_FAILURE);
+     192             :                         /* LCOV_EXCL_STOP */
+     193             :                 }
+     194             :         }
+     195          16 : }
+     196             : 
+     197           1 : int main(void)
+     198             : {
+     199             :         unsigned i;
+     200          17 :         for (i = 1; i <= 16; ++i) {
+     201             : 
+     202             :                 /* test with different stream buffer size */
+     203          16 :                 STREAM_SIZE = i;
+     204             : 
+     205          16 :                 printf("Test stream buffer size %u\n", i);
+     206             : 
+     207          16 :                 test();
+     208             :         }
+     209             : 
+     210           1 :         return 0;
+     211             : }
+     212             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mktest.c.func-sort-c.html b/cov/cmdline/mktest.c.func-sort-c.html new file mode 100644 index 00000000..a4c61b8c --- /dev/null +++ b/cov/cmdline/mktest.c.func-sort-c.html @@ -0,0 +1,144 @@ + + + + + + + LCOV - lcov.info - cmdline/mktest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mktest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22023693.2 %
Date:2015-05-12Functions:1818100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
rnd50951268
rndnz50541259
file_cmp146644
rndnz_range31119
rnd_name26827
cmd_generate24000
cmd_generate_file23267
cmd_change13128
cmd_write4679
cmd_truncate3282
cmd_append3200
cmd_delete3095
cmd_damage1882
fallback1821
rndnz_damage1821
cmd_generate_symlink918
main22
help1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mktest.c.func.html b/cov/cmdline/mktest.c.func.html new file mode 100644 index 00000000..3daf7857 --- /dev/null +++ b/cov/cmdline/mktest.c.func.html @@ -0,0 +1,144 @@ + + + + + + + LCOV - lcov.info - cmdline/mktest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mktest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22023693.2 %
Date:2015-05-12Functions:1818100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
cmd_append3200
cmd_change13128
cmd_damage1882
cmd_delete3095
cmd_generate24000
cmd_generate_file23267
cmd_generate_symlink918
cmd_truncate3282
cmd_write4679
fallback1821
file_cmp146644
help1
main22
rnd50951268
rnd_name26827
rndnz50541259
rndnz_damage1821
rndnz_range31119
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/mktest.c.gcov.html b/cov/cmdline/mktest.c.gcov.html new file mode 100644 index 00000000..2494874a --- /dev/null +++ b/cov/cmdline/mktest.c.gcov.html @@ -0,0 +1,866 @@ + + + + + + + LCOV - lcov.info - cmdline/mktest.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - mktest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22023693.2 %
Date:2015-05-12Functions:1818100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : 
+      22             : /****************************************************************************/
+      23             : /* random */
+      24             : 
+      25             : /**
+      26             :  * Pseudo random number generator.
+      27             :  */
+      28             : unsigned long long seed = 0;
+      29             : 
+      30    50951268 : unsigned rnd(unsigned max)
+      31             : {
+      32    50951268 :         seed = seed * 6364136223846793005LL + 1442695040888963407LL;
+      33             : 
+      34    50951268 :         return (seed >> 32) % max;
+      35             : }
+      36             : 
+      37    50541259 : unsigned rndnz(unsigned max)
+      38             : {
+      39    50541259 :         if (max <= 1)
+      40        2831 :                 return 1;
+      41             :         else
+      42    50538428 :                 return rnd(max - 1) + 1;
+      43             : }
+      44             : 
+      45       31119 : void rndnz_range(unsigned char* data, int size)
+      46             : {
+      47             :         int i;
+      48             : 
+      49    50567120 :         for (i = 0; i < size; ++i)
+      50    50536001 :                 data[i] = rndnz(256);
+      51       31119 : }
+      52             : 
+      53        1821 : void rndnz_damage(unsigned char* data, int size)
+      54             : {
+      55             :         int i;
+      56             : 
+      57             :         /* corrupt ensuring always different data */
+      58        3642 :         for (i = 0; i < size; ++i) {
+      59             :                 unsigned char c;
+      60             : 
+      61             :                 do {
+      62        1827 :                         c = rndnz(256);
+      63        1827 :                 } while (c == data[i]);
+      64             : 
+      65        1821 :                 data[i] = c;
+      66             :         }
+      67        1821 : }
+      68             : 
+      69             : char CHARSET[] = "qwertyuiopasdfghjklzxcvbnm1234567890 .-+";
+      70             : #define CHARSET_LEN (sizeof(CHARSET) - 1)
+      71             : 
+      72       26827 : void rnd_name(char* file)
+      73             : {
+      74       26827 :         int l = 1 + rnd(20);
+      75             : 
+      76      335216 :         while (l) {
+      77      281562 :                 *file++ = CHARSET[rnd(CHARSET_LEN)];
+      78      281562 :                 --l;
+      79             :         }
+      80       26827 :         *file = 0;
+      81       26827 : }
+      82             : 
+      83             : /****************************************************************************/
+      84             : /* file */
+      85             : 
+      86      146644 : int file_cmp(const void* a, const void* b)
+      87             : {
+      88      146644 :         return strcmp(a, b);
+      89             : }
+      90             : 
+      91        1821 : int fallback(int f, struct stat* st)
+      92             : {
+      93             : #if HAVE_FUTIMENS
+      94             :         struct timespec tv[2];
+      95             : #else
+      96             :         struct timeval tv[2];
+      97             : #endif
+      98             :         int ret;
+      99             : 
+     100             : #if HAVE_FUTIMENS /* futimens() is preferred because it gives nanosecond precision */
+     101        1821 :         tv[0].tv_sec = st->st_mtime;
+     102        1821 :         if (STAT_NSEC(st) != STAT_NSEC_INVALID)
+     103        1821 :                 tv[0].tv_nsec = STAT_NSEC(st);
+     104             :         else
+     105           0 :                 tv[0].tv_nsec = 0;
+     106        1821 :         tv[1].tv_sec = tv[0].tv_sec;
+     107        1821 :         tv[1].tv_nsec = tv[0].tv_nsec;
+     108             : 
+     109        1821 :         ret = futimens(f, tv);
+     110             : #elif HAVE_FUTIMES /* fallback to futimes() if nanosecond precision is not available */
+     111             :         tv[0].tv_sec = st->st_mtime;
+     112             :         if (STAT_NSEC(st) != STAT_NSEC_INVALID)
+     113             :                 tv[0].tv_usec = STAT_NSEC(st) / 1000;
+     114             :         else
+     115             :                 tv[0].tv_usec = 0;
+     116             :         tv[1].tv_sec = tv[0].tv_sec;
+     117             :         tv[1].tv_usec = tv[0].tv_usec;
+     118             : 
+     119             :         ret = futimes(f, tv);
+     120             : #elif HAVE_FUTIMESAT /* fallback to futimesat() for Solaris, it only has futimesat() */
+     121             :         tv[0].tv_sec = st->st_mtime;
+     122             :         if (STAT_NSEC(st) != STAT_NSEC_INVALID)
+     123             :                 tv[0].tv_usec = STAT_NSEC(st) / 1000;
+     124             :         else
+     125             :                 tv[0].tv_usec = 0;
+     126             :         tv[1].tv_sec = tv[0].tv_sec;
+     127             :         tv[1].tv_usec = tv[0].tv_usec;
+     128             : 
+     129             :         ret = futimesat(f, 0, tv);
+     130             : #else
+     131             : #error No function available to set file timestamps
+     132             : #endif
+     133        1821 :         return ret;
+     134             : }
+     135             : 
+     136             : /****************************************************************************/
+     137             : /* cmd */
+     138             : 
+     139             : /**
+     140             :  * Creates a file with random content.
+     141             :  * - If the file exists it's rewritten, but avoiding to truncating it to 0.
+     142             :  */
+     143       23267 : void cmd_generate_file(const char* path, int size)
+     144             : {
+     145             :         unsigned char* data;
+     146             :         int f;
+     147             : 
+     148             :         /* remove the existing file/symlink if any */
+     149       23267 :         if (remove(path) != 0) {
+     150       22446 :                 if (errno != ENOENT) {
+     151             :                         /* LCOV_EXCL_START */
+     152             :                         log_fatal("Error removing file %s\n", path);
+     153             :                         exit(EXIT_FAILURE);
+     154             :                         /* LCOV_EXCL_STOP */
+     155             :                 }
+     156             :         } else {
+     157             :                 /* don't truncate files to 0 size to avoid ZERO file size protection */
+     158         821 :                 ++size;
+     159             :         }
+     160             : 
+     161       23267 :         data = malloc(size);
+     162             : 
+     163             :         /* We don't write zero bytes because we want to test */
+     164             :         /* the recovering of new files, after an aborted sync */
+     165             :         /* If the files contains full blocks at zero */
+     166             :         /* this is an impossible condition to recover */
+     167             :         /* because we cannot differentiate between an unused block */
+     168             :         /* and a file filled with 0 */
+     169       23267 :         rndnz_range(data, size);
+     170             : 
+     171       23267 :         f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600);
+     172       23267 :         if (f < 0) {
+     173             :                 /* LCOV_EXCL_START */
+     174             :                 log_fatal("Error creating file %s\n", path);
+     175             :                 exit(EXIT_FAILURE);
+     176             :                 /* LCOV_EXCL_STOP */
+     177             :         }
+     178             : 
+     179       23267 :         if (write(f, data, size) != size) {
+     180             :                 /* LCOV_EXCL_START */
+     181             :                 log_fatal("Error writing file %s\n", path);
+     182             :                 exit(EXIT_FAILURE);
+     183             :                 /* LCOV_EXCL_STOP */
+     184             :         }
+     185             : 
+     186       23267 :         if (close(f) != 0) {
+     187             :                 /* LCOV_EXCL_START */
+     188             :                 log_fatal("Error closing file %s\n", path);
+     189             :                 exit(EXIT_FAILURE);
+     190             :                 /* LCOV_EXCL_STOP */
+     191             :         }
+     192             : 
+     193       23267 :         free(data);
+     194       23267 : }
+     195             : 
+     196             : /**
+     197             :  * Create a symlink.
+     198             :  * - If the file already exists, it's removed.
+     199             :  */
+     200         918 : void cmd_generate_symlink(const char* path, const char* linkto)
+     201             : {
+     202             :         /* remove the existing file/symlink if any */
+     203         918 :         if (remove(path) != 0) {
+     204         897 :                 if (errno != ENOENT) {
+     205             :                         /* LCOV_EXCL_START */
+     206             :                         log_fatal("Error removing file %s\n", path);
+     207             :                         exit(EXIT_FAILURE);
+     208             :                         /* LCOV_EXCL_STOP */
+     209             :                 }
+     210             :         }
+     211             : 
+     212         918 :         if (symlink(linkto, path) != 0) {
+     213             :                 /* LCOV_EXCL_START */
+     214             :                 log_fatal("Error writing symlink %s\n", path);
+     215             :                 exit(EXIT_FAILURE);
+     216             :                 /* LCOV_EXCL_STOP */
+     217             :         }
+     218         918 : }
+     219             : 
+     220             : /**
+     221             :  * Create a file or a symlink with a random name.
+     222             :  */
+     223       24000 : void cmd_generate(int disk, int size)
+     224             : {
+     225             :         char path[PATH_MAX];
+     226             :         char* file;
+     227             : 
+     228       24000 :         snprintf(path, sizeof(path), "bench/disk%d/", disk);
+     229       24000 :         file = path + strlen(path);
+     230             : 
+     231             :         /* add a directory */
+     232       24000 :         *file++ = 'a' + rnd(2);
+     233       24000 :         *file = 0;
+     234             : 
+     235             :         /* create it */
+     236       24000 :         if (mkdir(path, 0777) != 0) {
+     237       23988 :                 if (errno != EEXIST) {
+     238             :                         /* LCOV_EXCL_START */
+     239             :                         log_fatal("Error creating directory %s\n", path);
+     240             :                         exit(EXIT_FAILURE);
+     241             :                         /* LCOV_EXCL_STOP */
+     242             :                 }
+     243             :         }
+     244             : 
+     245       24000 :         *file++ = '/';
+     246             : 
+     247             :         while (1) {
+     248             :                 /* add a random file */
+     249       25909 :                 rnd_name(file);
+     250             : 
+     251             :                 /* skip some invalid file name, see http://en.wikipedia.org/wiki/Filename */
+     252       25909 :                 if (strcmp(file, ".") == 0
+     253       25874 :                         || strcmp(file, "..") == 0
+     254       25874 :                         || strcmp(file, "prn") == 0
+     255       25874 :                         || strcmp(file, "con") == 0
+     256       25873 :                         || strcmp(file, "nul") == 0
+     257       25873 :                         || strcmp(file, "aux") == 0
+     258       25873 :                         || file[0] == ' '
+     259       25199 :                         || file[strlen(file) - 1] == ' '
+     260       24608 :                         || file[strlen(file) - 1] == '.'
+     261             :                 ) {
+     262        1909 :                         continue;
+     263             :                 }
+     264             : 
+     265       24000 :                 break;
+     266        1909 :         }
+     267             : 
+     268             : #ifndef WIN32 /* Windows XP doesn't support symlinks */
+     269       24000 :         if (rnd(32) == 0) {
+     270             :                 /* symlink */
+     271             :                 char linkto[PATH_MAX];
+     272             : 
+     273         733 :                 rnd_name(linkto);
+     274             : 
+     275         733 :                 cmd_generate_symlink(path, linkto);
+     276             :         } else
+     277             : #endif
+     278             :         {
+     279             :                 /* file */
+     280       23267 :                 cmd_generate_file(path, size);
+     281             :         }
+     282       24000 : }
+     283             : 
+     284             : /**
+     285             :  * Write a partially a file.
+     286             :  * - The file must exist.
+     287             :  * - The file size is not changed.
+     288             :  * - The written data may be equal or not at the already existing one.
+     289             :  * - If it's a symlink nothing is done.
+     290             :  */
+     291        4679 : void cmd_write(const char* path, int size)
+     292             : {
+     293             :         struct stat st;
+     294             : 
+     295        4679 :         if (lstat(path, &st) != 0) {
+     296             :                 /* LCOV_EXCL_START */
+     297             :                 log_fatal("Error accessing %s\n", path);
+     298             :                 exit(EXIT_FAILURE);
+     299             :                 /* LCOV_EXCL_STOP */
+     300             :         }
+     301             : 
+     302        4679 :         if (S_ISREG(st.st_mode)) {
+     303             :                 unsigned char* data;
+     304             :                 off_t off;
+     305             :                 int f;
+     306             : 
+     307             :                 /* not over the end */
+     308        4652 :                 if (size > st.st_size)
+     309         202 :                         size = st.st_size;
+     310             : 
+     311             :                 /* start at random position inside the file */
+     312        4652 :                 if (size < st.st_size)
+     313        4450 :                         off = rnd(st.st_size - size);
+     314             :                 else
+     315         202 :                         off = 0;
+     316             : 
+     317        4652 :                 data = malloc(size);
+     318             : 
+     319        4652 :                 rndnz_range(data, size);
+     320             : 
+     321        4652 :                 f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW);
+     322        4652 :                 if (f < 0) {
+     323             :                         /* LCOV_EXCL_START */
+     324             :                         log_fatal("Error creating file %s\n", path);
+     325             :                         exit(EXIT_FAILURE);
+     326             :                         /* LCOV_EXCL_STOP */
+     327             :                 }
+     328             : 
+     329        4652 :                 if (lseek(f, off, SEEK_SET) != off) {
+     330             :                         /* LCOV_EXCL_START */
+     331             :                         log_fatal("Error seeking file %s\n", path);
+     332             :                         exit(EXIT_FAILURE);
+     333             :                         /* LCOV_EXCL_STOP */
+     334             :                 }
+     335             : 
+     336        4652 :                 if (write(f, data, size) != size) {
+     337             :                         /* LCOV_EXCL_START */
+     338             :                         log_fatal("Error writing file %s\n", path);
+     339             :                         exit(EXIT_FAILURE);
+     340             :                         /* LCOV_EXCL_STOP */
+     341             :                 }
+     342             : 
+     343        4652 :                 if (close(f) != 0) {
+     344             :                         /* LCOV_EXCL_START */
+     345             :                         log_fatal("Error closing file %s\n", path);
+     346             :                         exit(EXIT_FAILURE);
+     347             :                         /* LCOV_EXCL_STOP */
+     348             :                 }
+     349             : 
+     350        4652 :                 free(data);
+     351             :         }
+     352        4679 : }
+     353             : 
+     354             : /**
+     355             :  * Damage a file.
+     356             :  * - The file must exist.
+     357             :  * - The file size is not changed.
+     358             :  * - The written data is SURELY different than the already existing one.
+     359             :  * - The file timestamp is NOT modified.
+     360             :  * - If it's a symlink nothing is done.
+     361             :  */
+     362        1882 : void cmd_damage(const char* path, int size)
+     363             : {
+     364             :         struct stat st;
+     365             : 
+     366             :         /* here a 0 size means to change nothing */
+     367             :         /* as also the timestamp should not be changed */
+     368        1882 :         if (!size)
+     369           3 :                 return;
+     370             : 
+     371        1882 :         if (lstat(path, &st) != 0) {
+     372             :                 /* LCOV_EXCL_START */
+     373             :                 log_fatal("Error accessing %s\n", path);
+     374             :                 exit(EXIT_FAILURE);
+     375             :                 /* LCOV_EXCL_STOP */
+     376             :         }
+     377             : 
+     378        1882 :         if (st.st_size == 0)
+     379           3 :                 return;
+     380             : 
+     381        1879 :         if (S_ISREG(st.st_mode)) {
+     382             :                 off_t off;
+     383             :                 unsigned char* data;
+     384             :                 int f;
+     385             : 
+     386             :                 /* not over the end */
+     387        1821 :                 if (size > st.st_size)
+     388           0 :                         size = st.st_size;
+     389             : 
+     390             :                 /* start at random position inside the file */
+     391        1821 :                 if (size < st.st_size)
+     392        1820 :                         off = rnd(st.st_size - size);
+     393             :                 else
+     394           1 :                         off = 0;
+     395             : 
+     396        1821 :                 data = malloc(size);
+     397             : 
+     398        1821 :                 f = open(path, O_RDWR | O_BINARY | O_NOFOLLOW);
+     399        1821 :                 if (f < 0) {
+     400             :                         /* LCOV_EXCL_START */
+     401             :                         log_fatal("Error creating file %s\n", path);
+     402             :                         exit(EXIT_FAILURE);
+     403             :                         /* LCOV_EXCL_STOP */
+     404             :                 }
+     405             : 
+     406        1821 :                 if (lseek(f, off, SEEK_SET) != off) {
+     407             :                         /* LCOV_EXCL_START */
+     408             :                         log_fatal("Error seeking file %s\n", path);
+     409             :                         exit(EXIT_FAILURE);
+     410             :                         /* LCOV_EXCL_STOP */
+     411             :                 }
+     412             : 
+     413        1821 :                 if (read(f, data, size) != size) {
+     414             :                         /* LCOV_EXCL_START */
+     415             :                         log_fatal("Error writing file %s\n", path);
+     416             :                         exit(EXIT_FAILURE);
+     417             :                         /* LCOV_EXCL_STOP */
+     418             :                 }
+     419             : 
+     420        1821 :                 rndnz_damage(data, size);
+     421             : 
+     422        1821 :                 if (lseek(f, off, SEEK_SET) != off) {
+     423             :                         /* LCOV_EXCL_START */
+     424             :                         log_fatal("Error seeking file %s\n", path);
+     425             :                         exit(EXIT_FAILURE);
+     426             :                         /* LCOV_EXCL_STOP */
+     427             :                 }
+     428             : 
+     429        1821 :                 if (write(f, data, size) != size) {
+     430             :                         /* LCOV_EXCL_START */
+     431             :                         log_fatal("Error writing file %s\n", path);
+     432             :                         exit(EXIT_FAILURE);
+     433             :                         /* LCOV_EXCL_STOP */
+     434             :                 }
+     435             : 
+     436        1821 :                 if (fallback(f, &st) != 0) {
+     437             :                         /* LCOV_EXCL_START */
+     438             :                         log_fatal("Error setting time for file %s\n", path);
+     439             :                         exit(EXIT_FAILURE);
+     440             :                         /* LCOV_EXCL_STOP */
+     441             :                 }
+     442             : 
+     443        1821 :                 if (close(f) != 0) {
+     444             :                         /* LCOV_EXCL_START */
+     445             :                         log_fatal("Error closing file %s\n", path);
+     446             :                         exit(EXIT_FAILURE);
+     447             :                         /* LCOV_EXCL_STOP */
+     448             :                 }
+     449             : 
+     450        1821 :                 free(data);
+     451             :         }
+     452             : }
+     453             : 
+     454             : /**
+     455             :  * Append to a file.
+     456             :  * - The file must exist.
+     457             :  * - If it's a symlink nothing is done.
+     458             :  */
+     459        3200 : void cmd_append(const char* path, int size)
+     460             : {
+     461             :         struct stat st;
+     462             : 
+     463        3200 :         if (lstat(path, &st) != 0) {
+     464             :                 /* LCOV_EXCL_START */
+     465             :                 log_fatal("Error accessing %s\n", path);
+     466             :                 exit(EXIT_FAILURE);
+     467             :                 /* LCOV_EXCL_STOP */
+     468             :         }
+     469             : 
+     470        3200 :         if (S_ISREG(st.st_mode)) {
+     471             :                 unsigned char* data;
+     472             :                 int f;
+     473             : 
+     474        3200 :                 data = malloc(size);
+     475             : 
+     476        3200 :                 rndnz_range(data, size);
+     477             : 
+     478        3200 :                 f = open(path, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW);
+     479        3200 :                 if (f < 0) {
+     480             :                         /* LCOV_EXCL_START */
+     481             :                         log_fatal("Error opening file %s\n", path);
+     482             :                         exit(EXIT_FAILURE);
+     483             :                         /* LCOV_EXCL_STOP */
+     484             :                 }
+     485             : 
+     486        3200 :                 if (write(f, data, size) != size) {
+     487             :                         /* LCOV_EXCL_START */
+     488             :                         log_fatal("Error writing file %s\n", path);
+     489             :                         exit(EXIT_FAILURE);
+     490             :                         /* LCOV_EXCL_STOP */
+     491             :                 }
+     492             : 
+     493        3200 :                 if (close(f) != 0) {
+     494             :                         /* LCOV_EXCL_START */
+     495             :                         log_fatal("Error closing file %s\n", path);
+     496             :                         exit(EXIT_FAILURE);
+     497             :                         /* LCOV_EXCL_STOP */
+     498             :                 }
+     499             : 
+     500        3200 :                 free(data);
+     501             :         }
+     502        3200 : }
+     503             : 
+     504             : /**
+     505             :  * Truncate a file.
+     506             :  * - The file must exist.
+     507             :  * - The file is NEVER truncated to 0.
+     508             :  * - If it's a symlink nothing is done.
+     509             :  */
+     510        3282 : void cmd_truncate(const char* path, int size)
+     511             : {
+     512             :         struct stat st;
+     513             : 
+     514        3282 :         if (lstat(path, &st) != 0) {
+     515             :                 /* LCOV_EXCL_START */
+     516             :                 log_fatal("Error accessing %s\n", path);
+     517             :                 exit(EXIT_FAILURE);
+     518             :                 /* LCOV_EXCL_STOP */
+     519             :         }
+     520             : 
+     521        3282 :         if (S_ISREG(st.st_mode)) {
+     522             :                 off_t off;
+     523             :                 int f;
+     524             : 
+     525             :                 /* if file is empty, just rewrite it */
+     526        3282 :                 if (st.st_size == 0) {
+     527           4 :                         size = 0;
+     528             :                 } else {
+     529             :                         /* don't truncate files to 0 size to avoid ZERO file size protection */
+     530        3278 :                         if (size >= st.st_size)
+     531         196 :                                 size = st.st_size - 1;
+     532             :                 }
+     533             : 
+     534        3282 :                 off = st.st_size - size;
+     535             : 
+     536        3282 :                 f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW);
+     537        3282 :                 if (f < 0) {
+     538             :                         /* LCOV_EXCL_START */
+     539             :                         log_fatal("Error opening file %s\n", path);
+     540             :                         exit(EXIT_FAILURE);
+     541             :                         /* LCOV_EXCL_STOP */
+     542             :                 }
+     543             : 
+     544        3282 :                 if (ftruncate(f, off) != 0) {
+     545             :                         /* LCOV_EXCL_START */
+     546             :                         log_fatal("Error truncating file %s\n", path);
+     547             :                         exit(EXIT_FAILURE);
+     548             :                         /* LCOV_EXCL_STOP */
+     549             :                 }
+     550             : 
+     551        3282 :                 if (close(f) != 0) {
+     552             :                         /* LCOV_EXCL_START */
+     553             :                         log_fatal("Error closing file %s\n", path);
+     554             :                         exit(EXIT_FAILURE);
+     555             :                         /* LCOV_EXCL_STOP */
+     556             :                 }
+     557             :         }
+     558        3282 : }
+     559             : 
+     560             : /**
+     561             :  * Delete a file.
+     562             :  * - The file must exist.
+     563             :  */
+     564        3095 : void cmd_delete(const char* path)
+     565             : {
+     566        3095 :         if (remove(path) != 0) {
+     567             :                 /* LCOV_EXCL_START */
+     568             :                 log_fatal("Error removing %s\n", path);
+     569             :                 exit(EXIT_FAILURE);
+     570             :                 /* LCOV_EXCL_STOP */
+     571             :         }
+     572        3095 : }
+     573             : 
+     574             : /**
+     575             :  * Change a file. Or deleted/truncated/append/created.
+     576             :  * - The file must exist.
+     577             :  */
+     578       13128 : void cmd_change(const char* path, int size)
+     579             : {
+     580             :         struct stat st;
+     581             : 
+     582       13128 :         if (!size)
+     583       13155 :                 return;
+     584             : 
+     585       13101 :         if (lstat(path, &st) != 0) {
+     586             :                 /* LCOV_EXCL_START */
+     587             :                 log_fatal("Error accessing %s\n", path);
+     588             :                 exit(EXIT_FAILURE);
+     589             :                 /* LCOV_EXCL_STOP */
+     590             :         }
+     591             : 
+     592       13101 :         if (S_ISLNK(st.st_mode)) {
+     593             :                 /* symlink */
+     594         394 :                 if (rnd(2) == 0) {
+     595             :                         /* delete */
+     596         209 :                         if (remove(path) != 0) {
+     597             :                                 /* LCOV_EXCL_START */
+     598             :                                 log_fatal("Error removing %s\n", path);
+     599             :                                 exit(EXIT_FAILURE);
+     600             :                                 /* LCOV_EXCL_STOP */
+     601             :                         }
+     602             :                 } else {
+     603             :                         /* recreate */
+     604             :                         char linkto[PATH_MAX];
+     605             : 
+     606         185 :                         if (remove(path) != 0) {
+     607             :                                 /* LCOV_EXCL_START */
+     608             :                                 log_fatal("Error removing %s\n", path);
+     609             :                                 exit(EXIT_FAILURE);
+     610             :                                 /* LCOV_EXCL_STOP */
+     611             :                         }
+     612             : 
+     613         185 :                         rnd_name(linkto);
+     614             : 
+     615         185 :                         cmd_generate_symlink(path, linkto);
+     616             :                 }
+     617       12707 :         } else if (S_ISREG(st.st_mode)) {
+     618             :                 int r;
+     619             : 
+     620       12707 :                 r = rnd(4);
+     621             : 
+     622       12707 :                 if (r == 0) {
+     623        3130 :                         cmd_write(path, size);
+     624        9577 :                 } else if (r == 1) {
+     625        3200 :                         cmd_append(path, size);
+     626        6377 :                 } else if (r == 2) {
+     627        3282 :                         cmd_truncate(path, size);
+     628             :                 } else {
+     629        3095 :                         cmd_delete(path);
+     630             :                 }
+     631             :         }
+     632             : }
+     633             : 
+     634           1 : void help(void)
+     635             : {
+     636           1 :         printf("Test for " PACKAGE " v" VERSION " by Andrea Mazzoleni, " PACKAGE_URL "\n");
+     637           1 :         printf("Usage:\n");
+     638           1 :         printf("\tmktest generate SEED DISK_NUM FILE_NUM FILE_SIZE\n");
+     639           1 :         printf("\tmktest damage SEED NUM SIZE FILE\n");
+     640           1 :         printf("\tmktest write SEED NUM SIZE FILE\n");
+     641           1 :         printf("\tmktest change SEED SIZE FILE\n");
+     642           1 :         printf("\tmktest append SEED SIZE FILE\n");
+     643           1 :         printf("\tmktest truncate SEED SIZE FILE\n");
+     644           1 : }
+     645             : 
+     646          22 : int main(int argc, char* argv[])
+     647             : {
+     648             :         int i, j, b;
+     649             : 
+     650          22 :         if (argc < 2) {
+     651           1 :                 help();
+     652           1 :                 exit(EXIT_SUCCESS);
+     653             :         }
+     654             : 
+     655          21 :         if (strcmp(argv[1], "generate") == 0) {
+     656             :                 int disk, file, size;
+     657             : 
+     658           4 :                 if (argc != 6) {
+     659             :                         /* LCOV_EXCL_START */
+     660             :                         help();
+     661             :                         exit(EXIT_FAILURE);
+     662             :                         /* LCOV_EXCL_STOP */
+     663             :                 }
+     664             : 
+     665           4 :                 seed = atoi(argv[2]);
+     666           4 :                 disk = atoi(argv[3]);
+     667           4 :                 file = atoi(argv[4]);
+     668           4 :                 size = atoi(argv[5]);
+     669             : 
+     670          28 :                 for (i = 0; i < disk; ++i) {
+     671       24024 :                         for (j = 0; j < file; ++j) {
+     672       24000 :                                 if (j == 0)
+     673             :                                         /* create at least a big one */
+     674          24 :                                         cmd_generate(i + 1, size);
+     675       23976 :                                 else if (j == 1)
+     676             :                                         /* create at least an empty one */
+     677          24 :                                         cmd_generate(i + 1, 0);
+     678             :                                 else
+     679       23952 :                                         cmd_generate(i + 1, rnd(size));
+     680             :                         }
+     681             :                 }
+     682          17 :         } else if (strcmp(argv[1], "write") == 0) {
+     683             :                 int fail, size;
+     684             : 
+     685           7 :                 if (argc < 6) {
+     686             :                         /* LCOV_EXCL_START */
+     687             :                         help();
+     688             :                         exit(EXIT_FAILURE);
+     689             :                         /* LCOV_EXCL_STOP */
+     690             :                 }
+     691             : 
+     692           7 :                 seed = atoi(argv[2]);
+     693           7 :                 fail = atoi(argv[3]);
+     694           7 :                 size = atoi(argv[4]);
+     695           7 :                 b = 5;
+     696             : 
+     697             :                 /* sort the file names */
+     698           7 :                 qsort(&argv[b], argc - b, sizeof(argv[b]), file_cmp);
+     699             : 
+     700         962 :                 for (i = b; i < argc; ++i)
+     701        2504 :                         for (j = 0; j < fail; ++j)
+     702        1549 :                                 cmd_write(argv[i], rndnz(size));
+     703          10 :         } else if (strcmp(argv[1], "damage") == 0) {
+     704             :                 int fail, size;
+     705             : 
+     706           3 :                 if (argc < 6) {
+     707             :                         /* LCOV_EXCL_START */
+     708             :                         help();
+     709             :                         exit(EXIT_FAILURE);
+     710             :                         /* LCOV_EXCL_STOP */
+     711             :                 }
+     712             : 
+     713           3 :                 seed = atoi(argv[2]);
+     714           3 :                 fail = atoi(argv[3]);
+     715           3 :                 size = atoi(argv[4]);
+     716           3 :                 b = 5;
+     717             : 
+     718             :                 /* sort the file names */
+     719           3 :                 qsort(&argv[b], argc - b, sizeof(argv[b]), file_cmp);
+     720             : 
+     721        1885 :                 for (i = b; i < argc; ++i)
+     722        3764 :                         for (j = 0; j < fail; ++j)
+     723        1882 :                                 cmd_damage(argv[i], rndnz(size)); /* at least one byte */
+     724           7 :         } else if (strcmp(argv[1], "append") == 0) {
+     725             :                 int size;
+     726             : 
+     727           0 :                 if (argc < 5) {
+     728             :                         /* LCOV_EXCL_START */
+     729             :                         help();
+     730             :                         exit(EXIT_FAILURE);
+     731             :                         /* LCOV_EXCL_STOP */
+     732             :                 }
+     733             : 
+     734           0 :                 seed = atoi(argv[2]);
+     735           0 :                 size = atoi(argv[3]);
+     736           0 :                 b = 4;
+     737             : 
+     738             :                 /* sort the file names */
+     739           0 :                 qsort(&argv[b], argc - b, sizeof(argv[b]), file_cmp);
+     740             : 
+     741           0 :                 for (i = b; i < argc; ++i)
+     742           0 :                         cmd_append(argv[i], rndnz(size)); /* at least one byte */
+     743           7 :         } else if (strcmp(argv[1], "truncate") == 0) {
+     744             :                 int size;
+     745             : 
+     746           0 :                 if (argc < 5) {
+     747             :                         /* LCOV_EXCL_START */
+     748             :                         help();
+     749             :                         exit(EXIT_FAILURE);
+     750             :                         /* LCOV_EXCL_STOP */
+     751             :                 }
+     752             : 
+     753           0 :                 seed = atoi(argv[2]);
+     754           0 :                 size = atoi(argv[3]);
+     755           0 :                 b = 4;
+     756             : 
+     757             :                 /* sort the file names */
+     758           0 :                 qsort(&argv[b], argc - b, sizeof(argv[b]), file_cmp);
+     759             : 
+     760           0 :                 for (i = b; i < argc; ++i)
+     761           0 :                         cmd_truncate(argv[i], rnd(size));
+     762           7 :         } else if (strcmp(argv[1], "change") == 0) {
+     763             :                 int size;
+     764             : 
+     765           7 :                 if (argc < 5) {
+     766             :                         /* LCOV_EXCL_START */
+     767             :                         help();
+     768             :                         exit(EXIT_FAILURE);
+     769             :                         /* LCOV_EXCL_STOP */
+     770             :                 }
+     771             : 
+     772           7 :                 seed = atoi(argv[2]);
+     773           7 :                 size = atoi(argv[3]);
+     774           7 :                 b = 4;
+     775             : 
+     776             :                 /* sort the file names */
+     777           7 :                 qsort(&argv[b], argc - b, sizeof(argv[b]), file_cmp);
+     778             : 
+     779       13135 :                 for (i = b; i < argc; ++i)
+     780       13128 :                         cmd_change(argv[i], rnd(size));
+     781             :         } else {
+     782             :                 /* LCOV_EXCL_START */
+     783             :                 help();
+     784             :                 exit(EXIT_FAILURE);
+     785             :                 /* LCOV_EXCL_STOP */
+     786             :         }
+     787             : 
+     788          21 :         return 0;
+     789             : }
+     790             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/murmur3.c.func-sort-c.html b/cov/cmdline/murmur3.c.func-sort-c.html new file mode 100644 index 00000000..a3721d1b --- /dev/null +++ b/cov/cmdline/murmur3.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/murmur3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - murmur3.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
fmix328699708
MurmurHash3_x86_1282174927
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/murmur3.c.func.html b/cov/cmdline/murmur3.c.func.html new file mode 100644 index 00000000..d72229c6 --- /dev/null +++ b/cov/cmdline/murmur3.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/murmur3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - murmur3.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
MurmurHash3_x86_1282174927
fmix328699708
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/murmur3.c.gcov.html b/cov/cmdline/murmur3.c.gcov.html new file mode 100644 index 00000000..a5df9b99 --- /dev/null +++ b/cov/cmdline/murmur3.c.gcov.html @@ -0,0 +1,269 @@ + + + + + + + LCOV - lcov.info - cmdline/murmur3.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - murmur3.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : /*
+      19             :  * Derivative work from MurmorHash3.cpp revision r136
+      20             :  *
+      21             :  * SMHasher & MurmurHash
+      22             :  * http://code.google.com/p/smhasher/
+      23             :  *
+      24             :  * Exact source used as reference:
+      25             :  * http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp?spec=svn136&r=136
+      26             :  */
+      27             : 
+      28             : // MurmurHash3 was written by Austin Appleby, and is placed in the public
+      29             : // domain. The author hereby disclaims copyright to this source code.
+      30             : 
+      31             : /* Finalization mix - force all bits of a hash block to avalanche */
+      32     8699708 : static inline uint32_t fmix32(uint32_t h)
+      33             : {
+      34     8699708 :         h ^= h >> 16;
+      35     8699708 :         h *= 0x85ebca6b;
+      36     8699708 :         h ^= h >> 13;
+      37     8699708 :         h *= 0xc2b2ae35;
+      38     8699708 :         h ^= h >> 16;
+      39     8699708 :         return h;
+      40             : }
+      41             : 
+      42             : /*
+      43             :  * Warning!
+      44             :  * Don't declare these variables static, otherwise the gcc optimizer
+      45             :  * may generate very slow code for multiplication with these constants,
+      46             :  * like:
+      47             : 
+      48             :    -> .cpp
+      49             :    k1 *= c1;
+      50             :    -> .asm
+      51             :    152:   8d 14 80                lea    (%eax,%eax,4),%edx
+      52             :    155:   8d 14 90                lea    (%eax,%edx,4),%edx
+      53             :    158:   c1 e2 03                shl    $0x3,%edx
+      54             :    15b:   29 c2                   sub    %eax,%edx
+      55             :    15d:   8d 14 d2                lea    (%edx,%edx,8),%edx
+      56             :    160:   8d 14 90                lea    (%eax,%edx,4),%edx
+      57             :    163:   8d 14 d0                lea    (%eax,%edx,8),%edx
+      58             :    166:   8d 14 90                lea    (%eax,%edx,4),%edx
+      59             :    169:   8d 14 50                lea    (%eax,%edx,2),%edx
+      60             :    16c:   8d 14 90                lea    (%eax,%edx,4),%edx
+      61             :    16f:   8d 14 92                lea    (%edx,%edx,4),%edx
+      62             :    172:   8d 14 50                lea    (%eax,%edx,2),%edx
+      63             :    175:   8d 04 d0                lea    (%eax,%edx,8),%eax
+      64             :    178:   8d 14 c5 00 00 00 00    lea    0x0(,%eax,8),%edx
+      65             :    17f:   29 d0                   sub    %edx,%eax
+      66             : 
+      67             :  * resulting in speeds of 500 MB/s instead of 3000 MB/s.
+      68             :  *
+      69             :  * Verified with gcc 4.4.4 compiling with :
+      70             :  *
+      71             :  * g++ -g -c -O2 MurmurHash3.cpp -o MurmurHash3.o
+      72             :  */
+      73             : uint32_t c1 = 0x239b961b;
+      74             : uint32_t c2 = 0xab0e9789;
+      75             : uint32_t c3 = 0x38b34ae5;
+      76             : uint32_t c4 = 0xa1e38b93;
+      77             : 
+      78     2174927 : void MurmurHash3_x86_128(const void* data, size_t size, const uint8_t* seed, void* digest)
+      79             : {
+      80             :         size_t nblocks;
+      81             :         const uint32_t* blocks;
+      82             :         const uint32_t* end;
+      83             :         size_t remainder;
+      84             : 
+      85     2174927 :         uint32_t h1 = ((const uint32_t*)seed)[0];
+      86     2174927 :         uint32_t h2 = ((const uint32_t*)seed)[1];
+      87     2174927 :         uint32_t h3 = ((const uint32_t*)seed)[2];
+      88     2174927 :         uint32_t h4 = ((const uint32_t*)seed)[3];
+      89             : 
+      90             : #if WORDS_BIGENDIAN
+      91             :         h1 = util_swap32(h1);
+      92             :         h2 = util_swap32(h2);
+      93             :         h3 = util_swap32(h3);
+      94             :         h4 = util_swap32(h4);
+      95             : #endif
+      96             : 
+      97     2174927 :         nblocks = size / 16;
+      98     2174927 :         blocks = data;
+      99     2174927 :         end = blocks + nblocks * 4;
+     100             : 
+     101             :         /* body */
+     102   115758500 :         while (blocks < end) {
+     103   111408646 :                 uint32_t k1 = blocks[0];
+     104   111408646 :                 uint32_t k2 = blocks[1];
+     105   111408646 :                 uint32_t k3 = blocks[2];
+     106   111408646 :                 uint32_t k4 = blocks[3];
+     107             : 
+     108             : #if WORDS_BIGENDIAN
+     109             :                 k1 = util_swap32(k1);
+     110             :                 k2 = util_swap32(k2);
+     111             :                 k3 = util_swap32(k3);
+     112             :                 k4 = util_swap32(k4);
+     113             : #endif
+     114             : 
+     115   111408646 :                 k1 *= c1; k1 = util_rotl32(k1, 15); k1 *= c2; h1 ^= k1;
+     116             : 
+     117   111408646 :                 h1 = util_rotl32(h1, 19); h1 += h2; h1 = h1 * 5 + 0x561ccd1b;
+     118             : 
+     119   111408646 :                 k2 *= c2; k2 = util_rotl32(k2, 16); k2 *= c3; h2 ^= k2;
+     120             : 
+     121   111408646 :                 h2 = util_rotl32(h2, 17); h2 += h3; h2 = h2 * 5 + 0x0bcaa747;
+     122             : 
+     123   111408646 :                 k3 *= c3; k3 = util_rotl32(k3, 17); k3 *= c4; h3 ^= k3;
+     124             : 
+     125   111408646 :                 h3 = util_rotl32(h3, 15); h3 += h4; h3 = h3 * 5 + 0x96cd1c35;
+     126             : 
+     127   111408646 :                 k4 *= c4; k4 = util_rotl32(k4, 18); k4 *= c1; h4 ^= k4;
+     128             : 
+     129   111408646 :                 h4 = util_rotl32(h4, 13); h4 += h1; h4 = h4 * 5 + 0x32ac3b17;
+     130             : 
+     131   111408646 :                 blocks += 4;
+     132             :         }
+     133             : 
+     134             :         /* tail */
+     135     2174927 :         remainder = size & 15;
+     136     2174927 :         if (remainder != 0) {
+     137      818892 :                 const uint8_t* tail = (const uint8_t*)blocks;
+     138             : 
+     139      818892 :                 uint32_t k1 = 0;
+     140      818892 :                 uint32_t k2 = 0;
+     141      818892 :                 uint32_t k3 = 0;
+     142      818892 :                 uint32_t k4 = 0;
+     143             : 
+     144      818892 :                 switch (remainder) {
+     145       53434 :                 case 15 : k4 ^= tail[14] << 16;
+     146      108492 :                 case 14 : k4 ^= tail[13] << 8;
+     147      163702 :                 case 13 : k4 ^= tail[12] << 0;
+     148      163702 :                         k4 *= c4; k4 = util_rotl32(k4, 18); k4 *= c1; h4 ^= k4;
+     149      218979 :                 case 12 : k3 ^= tail[11] << 24;
+     150      274534 :                 case 11 : k3 ^= tail[10] << 16;
+     151      329422 :                 case 10 : k3 ^= tail[ 9] << 8;
+     152      385757 :                 case 9 : k3 ^= tail[ 8] << 0;
+     153      385757 :                         k3 *= c3; k3 = util_rotl32(k3, 17); k3 *= c4; h3 ^= k3;
+     154      442006 :                 case 8 : k2 ^= tail[ 7] << 24;
+     155      494153 :                 case 7 : k2 ^= tail[ 6] << 16;
+     156      549477 :                 case 6 : k2 ^= tail[ 5] << 8;
+     157      602557 :                 case 5 : k2 ^= tail[ 4] << 0;
+     158      602557 :                         k2 *= c2; k2 = util_rotl32(k2, 16); k2 *= c3; h2 ^= k2;
+     159      656596 :                 case 4 : k1 ^= tail[ 3] << 24;
+     160      709640 :                 case 3 : k1 ^= tail[ 2] << 16;
+     161      763641 :                 case 2 : k1 ^= tail[ 1] << 8;
+     162      818892 :                 case 1 : k1 ^= tail[ 0] << 0;
+     163      818892 :                         k1 *= c1; k1 = util_rotl32(k1, 15); k1 *= c2; h1 ^= k1;
+     164             :                 }
+     165             :         }
+     166             : 
+     167             :         /* finalization */
+     168     2174927 :         h1 ^= size; h2 ^= size; h3 ^= size; h4 ^= size;
+     169             : 
+     170     2174927 :         h1 += h2; h1 += h3; h1 += h4;
+     171     2174927 :         h2 += h1; h3 += h1; h4 += h1;
+     172             : 
+     173     2174927 :         h1 = fmix32(h1);
+     174     2174927 :         h2 = fmix32(h2);
+     175     2174927 :         h3 = fmix32(h3);
+     176     2174927 :         h4 = fmix32(h4);
+     177             : 
+     178     2174927 :         h1 += h2; h1 += h3; h1 += h4;
+     179     2174927 :         h2 += h1; h3 += h1; h4 += h1;
+     180             : 
+     181             : #if WORDS_BIGENDIAN
+     182             :         h1 = util_swap32(h1);
+     183             :         h2 = util_swap32(h2);
+     184             :         h3 = util_swap32(h3);
+     185             :         h4 = util_swap32(h4);
+     186             : #endif
+     187             : 
+     188     2174927 :         ((uint32_t*)digest)[0] = h1;
+     189     2174927 :         ((uint32_t*)digest)[1] = h2;
+     190     2174927 :         ((uint32_t*)digest)[2] = h3;
+     191     2174927 :         ((uint32_t*)digest)[3] = h4;
+     192     2174927 : }
+     193             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/nano.c.func-sort-c.html b/cov/cmdline/nano.c.func-sort-c.html new file mode 100644 index 00000000..2629cf80 --- /dev/null +++ b/cov/cmdline/nano.c.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/nano.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - nano.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_nano1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/nano.c.func.html b/cov/cmdline/nano.c.func.html new file mode 100644 index 00000000..f9e54a50 --- /dev/null +++ b/cov/cmdline/nano.c.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/nano.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - nano.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_nano1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/nano.c.gcov.html b/cov/cmdline/nano.c.gcov.html new file mode 100644 index 00000000..a4a93979 --- /dev/null +++ b/cov/cmdline/nano.c.gcov.html @@ -0,0 +1,210 @@ + + + + + + + LCOV - lcov.info - cmdline/nano.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - nano.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2014 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "handle.h"
+      24             : 
+      25           1 : void state_nano(struct snapraid_state* state)
+      26             : {
+      27             :         tommy_node* i;
+      28             : 
+      29           1 :         msg_progress("Setting nanosecond timestamps...\n");
+      30             : 
+      31             :         /* for all disks */
+      32           7 :         for (i = state->disklist; i != 0; i = i->next) {
+      33           6 :                 struct snapraid_disk* disk = i->data;
+      34             :                 tommy_node* j;
+      35             : 
+      36             :                 /* for all files */
+      37        5723 :                 for (j = disk->filelist; j != 0; j = j->next) {
+      38        5717 :                         struct snapraid_file* file = j->data;
+      39             : 
+      40             :                         /* if the file has a zero nanosecond timestamp */
+      41             :                         /* note that symbolic links are not in the file list */
+      42             :                         /* and then are not processed */
+      43        5717 :                         if (file->mtime_nsec == 0) {
+      44             :                                 char path[PATH_MAX];
+      45             :                                 struct stat st;
+      46             :                                 int f;
+      47             :                                 int ret;
+      48             :                                 int nsec;
+      49             : 
+      50          16 :                                 pathprint(path, sizeof(path), "%s%s", disk->dir, file->sub);
+      51             : 
+      52             :                                 /* set a new nanosecond timestamp different than 0 */
+      53             :                                 do {
+      54             :                                         uint32_t nano;
+      55             : 
+      56             :                                         /* get a random nanosecond value */
+      57          16 :                                         if (randomize(&nano, sizeof(nano)) != 0) {
+      58             :                                                 /* LCOV_EXCL_START */
+      59             :                                                 log_fatal("Failed to get random values.\n");
+      60             :                                                 exit(EXIT_FAILURE);
+      61             :                                                 /* LCOV_EXCL_STOP */
+      62             :                                         }
+      63             : 
+      64          16 :                                         nsec = nano % 1000000000;
+      65          16 :                                 } while (nsec == 0);
+      66             : 
+      67             :                                 /* open it */
+      68             :                                 /* O_NOFOLLOW: do not follow links to ensure to open the real file */
+      69          16 :                                 f = open(path, O_RDONLY | O_BINARY | O_NOFOLLOW);
+      70          16 :                                 if (f == -1) {
+      71             :                                         /* LCOV_EXCL_START */
+      72             :                                         log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno));
+      73             :                                         continue;
+      74             :                                         /* LCOV_EXCL_STOP */
+      75             :                                 }
+      76             : 
+      77             :                                 /* get the present timestamp, that may be different than the one */
+      78             :                                 /* in the content file */
+      79          16 :                                 ret = fstat(f, &st);
+      80          16 :                                 if (ret == -1) {
+      81             :                                         /* LCOV_EXCL_START */
+      82             :                                         close(f);
+      83             :                                         log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno));
+      84             :                                         continue;
+      85             :                                         /* LCOV_EXCL_STOP */
+      86             :                                 }
+      87             : 
+      88             :                                 /* set the tweaked modification time, with new nano seconds */
+      89          16 :                                 ret = fmtime(f, st.st_mtime, nsec);
+      90          16 :                                 if (ret != 0) {
+      91             :                                         /* LCOV_EXCL_START */
+      92             :                                         close(f);
+      93             :                                         log_fatal("Error timing file '%s'. %s.\n", path, strerror(errno));
+      94             :                                         continue;
+      95             :                                         /* LCOV_EXCL_STOP */
+      96             :                                 }
+      97             : 
+      98             :                                 /* uses fstat again to get the present timestamp */
+      99             :                                 /* this is needed because the value read */
+     100             :                                 /* may be different than the written one */
+     101          16 :                                 ret = fstat(f, &st);
+     102          16 :                                 if (ret == -1) {
+     103             :                                         /* LCOV_EXCL_START */
+     104             :                                         close(f);
+     105             :                                         log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno));
+     106             :                                         continue;
+     107             :                                         /* LCOV_EXCL_STOP */
+     108             :                                 }
+     109             : 
+     110             :                                 /* close it */
+     111          16 :                                 ret = close(f);
+     112          16 :                                 if (ret != 0) {
+     113             :                                         /* LCOV_EXCL_START */
+     114             :                                         log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno));
+     115             :                                         continue;
+     116             :                                         /* LCOV_EXCL_STOP */
+     117             :                                 }
+     118             : 
+     119             :                                 /* set the same nanosecond value in the content file */
+     120             :                                 /* note that if the seconds value is already matching */
+     121             :                                 /* the file won't be synched because the content file will */
+     122             :                                 /* contain the new updated timestamp */
+     123          16 :                                 file->mtime_nsec = STAT_NSEC(&st);
+     124             : 
+     125             :                                 /* state changed, we need to update it */
+     126          16 :                                 state->need_write = 1;
+     127             : 
+     128          16 :                                 log_tag("nano:%s:%s\n", disk->name, esc(file->sub));
+     129          16 :                                 msg_info("nano %s%s\n", disk->dir, file->sub);
+     130             :                         }
+     131             :                 }
+     132             :         }
+     133           1 : }
+     134             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/parity.c.func-sort-c.html b/cov/cmdline/parity.c.func-sort-c.html new file mode 100644 index 00000000..eb77f51e --- /dev/null +++ b/cov/cmdline/parity.c.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - cmdline/parity.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - parity.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11113979.9 %
Date:2015-05-12Functions:101190.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
parity_read3405588
parity_write500002
parity_close887
parity_allocated_size553
parity_create497
parity_chsize497
parity_open391
parity_sync368
parity_used_size63
parity_is_invalid1
parity_overflow0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/parity.c.func.html b/cov/cmdline/parity.c.func.html new file mode 100644 index 00000000..31f6a58a --- /dev/null +++ b/cov/cmdline/parity.c.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - cmdline/parity.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - parity.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11113979.9 %
Date:2015-05-12Functions:101190.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
parity_allocated_size553
parity_chsize497
parity_close887
parity_create497
parity_is_invalid1
parity_open391
parity_overflow0
parity_read3405588
parity_sync368
parity_used_size63
parity_write500002
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/parity.c.gcov.html b/cov/cmdline/parity.c.gcov.html new file mode 100644 index 00000000..9ca45339 --- /dev/null +++ b/cov/cmdline/parity.c.gcov.html @@ -0,0 +1,601 @@ + + + + + + + LCOV - lcov.info - cmdline/parity.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - parity.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11113979.9 %
Date:2015-05-12Functions:101190.9 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : 
+      26             : /****************************************************************************/
+      27             : /* parity */
+      28             : 
+      29         553 : block_off_t parity_allocated_size(struct snapraid_state* state)
+      30             : {
+      31             :         block_off_t parity_block;
+      32             :         tommy_node* i;
+      33             : 
+      34             :         /* compute the size of the parity file */
+      35         553 :         parity_block = 0;
+      36        3861 :         for (i = state->disklist; i != 0; i = i->next) {
+      37        3308 :                 struct snapraid_disk* disk = i->data;
+      38             : 
+      39             :                 /* start from the declared size */
+      40        3308 :                 block_off_t block = tommy_arrayblk_size(&disk->blockarr);
+      41             : 
+      42             :                 /* decrease the block until an allocated one, but part of a file */
+      43             :                 /* we don't stop at deleted blocks, because we want to have them cleared */
+      44             :                 /* if they are at the end of the parity */
+      45      189015 :                 while (block > parity_block && !block_has_file(tommy_arrayblk_get(&disk->blockarr, block - 1)))
+      46      182399 :                         --block;
+      47             : 
+      48             :                 /* get the highest value */
+      49        3308 :                 if (block > parity_block)
+      50        2041 :                         parity_block = block;
+      51             :         }
+      52             : 
+      53         553 :         return parity_block;
+      54             : }
+      55             : 
+      56          63 : block_off_t parity_used_size(struct snapraid_state* state)
+      57             : {
+      58             :         block_off_t parity_block;
+      59             :         tommy_node* i;
+      60             : 
+      61             :         /* compute the size of the parity file */
+      62          63 :         parity_block = 0;
+      63         440 :         for (i = state->disklist; i != 0; i = i->next) {
+      64         377 :                 struct snapraid_disk* disk = i->data;
+      65             : 
+      66             :                 /* start from the declared size */
+      67         377 :                 block_off_t block = tommy_arrayblk_size(&disk->blockarr);
+      68             : 
+      69             :                 /* decrease the block until an used one */
+      70      221368 :                 while (block > parity_block && !block_has_file_and_valid_parity(tommy_arrayblk_get(&disk->blockarr, block - 1)))
+      71      220614 :                         --block;
+      72             : 
+      73             :                 /* get the highest value */
+      74         377 :                 if (block > parity_block)
+      75         235 :                         parity_block = block;
+      76             :         }
+      77             : 
+      78          63 :         return parity_block;
+      79             : }
+      80             : 
+      81           1 : int parity_is_invalid(struct snapraid_state* state)
+      82             : {
+      83             :         block_off_t blockmax;
+      84             :         block_off_t i;
+      85             : 
+      86           1 :         blockmax = parity_allocated_size(state);
+      87             : 
+      88           1 :         for (i = 0; i < blockmax; ++i) {
+      89             :                 tommy_node* node_disk;
+      90             :                 int one_invalid;
+      91             :                 int one_valid;
+      92             : 
+      93             :                 /* for each disk */
+      94           0 :                 one_invalid = 0;
+      95           0 :                 one_valid = 0;
+      96           0 :                 for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
+      97           0 :                         struct snapraid_disk* disk = node_disk->data;
+      98           0 :                         struct snapraid_block* block = disk_block_get(disk, i);
+      99             : 
+     100           0 :                         if (block_has_file(block))
+     101           0 :                                 one_valid = 1;
+     102           0 :                         if (block_has_invalid_parity(block))
+     103           0 :                                 one_invalid = 1;
+     104             :                 }
+     105             : 
+     106             :                 /* if both valid and invalid, we need to update */
+     107           0 :                 if (one_invalid && one_valid)
+     108           0 :                         return 1;
+     109             :         }
+     110             : 
+     111           1 :         return 0;
+     112             : }
+     113             : 
+     114           0 : void parity_overflow(struct snapraid_state* state, data_off_t size)
+     115             : {
+     116             :         tommy_node* i;
+     117             :         block_off_t blockalloc;
+     118           0 :         int first = 1;
+     119             : 
+     120             :         /* don't report if everything is outside or if the file is not accessible */
+     121           0 :         if (size == 0) {
+     122           0 :                 return;
+     123             :         }
+     124             : 
+     125           0 :         blockalloc = size / state->block_size;
+     126             : 
+     127             :         /* for all disks */
+     128           0 :         for (i = state->disklist; i != 0; i = i->next) {
+     129           0 :                 struct snapraid_disk* disk = i->data;
+     130             :                 tommy_node* j;
+     131             : 
+     132             :                 /* for all files */
+     133           0 :                 for (j = disk->filelist; j != 0; j = j->next) {
+     134           0 :                         struct snapraid_file* file = j->data;
+     135             : 
+     136           0 :                         if (file->blockmax > 0) {
+     137           0 :                                 if (file->blockvec[file->blockmax - 1].parity_pos >= blockalloc) {
+     138           0 :                                         log_tag("outofparity:%s:%s\n", disk->name, esc(file->sub));
+     139           0 :                                         if (first) {
+     140           0 :                                                 first = 0;
+     141           0 :                                                 log_fatal("\nYour data requires more parity than the available space.\n");
+     142           0 :                                                 log_fatal("Please move the files 'outofparity' to another data disk:\n");
+     143             :                                         }
+     144           0 :                                         log_fatal("outofparity %s%s\n", disk->dir, file->sub);
+     145             :                                 }
+     146             :                         }
+     147             :                 }
+     148             :         }
+     149             : }
+     150             : 
+     151         497 : int parity_create(struct snapraid_parity_handle* parity, const char* path, data_off_t* out_size, int mode)
+     152             : {
+     153             :         int ret;
+     154             :         int flags;
+     155             : 
+     156         497 :         pathcpy(parity->path, sizeof(parity->path), path);
+     157             : 
+     158             :         /* opening in sequential mode in Windows */
+     159             :         /* O_SEQUENTIAL: opening in sequential mode in Windows */
+     160         497 :         flags = O_RDWR | O_CREAT | O_BINARY;
+     161         497 :         if ((mode & MODE_SEQUENTIAL) != 0)
+     162         497 :                 flags |= O_SEQUENTIAL;
+     163         497 :         parity->f = open(parity->path, flags, 0600);
+     164         497 :         if (parity->f == -1) {
+     165             :                 /* LCOV_EXCL_START */
+     166             :                 log_fatal("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno));
+     167             :                 return -1;
+     168             :                 /* LCOV_EXCL_STOP */
+     169             :         }
+     170             : 
+     171             :         /* get the stat info */
+     172         497 :         ret = fstat(parity->f, &parity->st);
+     173         497 :         if (ret != 0) {
+     174             :                 /* LCOV_EXCL_START */
+     175             :                 log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno));
+     176             :                 goto bail;
+     177             :                 /* LCOV_EXCL_STOP */
+     178             :         }
+     179             : 
+     180             : #if HAVE_POSIX_FADVISE
+     181         497 :         if ((mode & MODE_SEQUENTIAL) != 0) {
+     182             :                 /* advise sequential access */
+     183         497 :                 ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL);
+     184         497 :                 if (ret != 0) {
+     185             :                         /* LCOV_EXCL_START */
+     186             :                         log_fatal("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret));
+     187             :                         goto bail;
+     188             :                         /* LCOV_EXCL_STOP */
+     189             :                 }
+     190             :         }
+     191             : #endif
+     192             : 
+     193             :         /* get the size of the existing data */
+     194         497 :         parity->valid_size = parity->st.st_size;
+     195         497 :         *out_size = parity->st.st_size;
+     196             : 
+     197         497 :         return 0;
+     198             : 
+     199             : bail:
+     200             :         /* LCOV_EXCL_START */
+     201             :         close(parity->f);
+     202             :         parity->f = -1;
+     203             :         parity->valid_size = 0;
+     204             :         return -1;
+     205             :         /* LCOV_EXCL_STOP */
+     206             : }
+     207             : 
+     208         497 : int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_off_t* out_size, int skip_fallocate)
+     209             : {
+     210             :         int ret;
+     211             : 
+     212         497 :         if (parity->st.st_size < size) {
+     213             :                 int f_ret;
+     214             :                 int f_errno;
+     215             :                 const char* call;
+     216             : 
+     217             : #if HAVE_FALLOCATE
+     218          65 :                 call = "fallocate";
+     219          65 :                 if (!skip_fallocate) {
+     220             :                         /* allocate real space using the specific Linux fallocate() operation. */
+     221             :                         /* If the underline filesystem doesn't support it, this operation fails, */
+     222             :                         /* instead posix_fallocate() fallbacks to write the whole file. */
+     223          64 :                         ret = fallocate(parity->f, 0, 0, size);
+     224             : 
+     225             :                         /* fallocate() returns the error number as positive integer, */
+     226             :                         /* and in this case it doesn't set errno, just like posix_fallocate() */
+     227             :                         /* Checking the glibc code (2.11.1 and 2.14.1) it seems that ENOSYS */
+     228             :                         /* may be returned in errno, so we support both the return way */
+     229          64 :                         if (ret > 0) { /* if a positive error is returned, convert it to errno */
+     230             :                                 /* LCOV_EXCL_START */
+     231             :                                 errno = ret;
+     232             :                                 ret = -1;
+     233             :                                 /* LCOV_EXCL_STOP */
+     234             :                         }
+     235             :                 } else {
+     236           1 :                         errno = EOPNOTSUPP;
+     237           1 :                         ret = -1;
+     238             :                 }
+     239             : 
+     240             :                 /* we get EOPNOTSUPP if the operation is not supported, like in ext3/ext2 */
+     241             :                 /* or ENOSYS with kernel before 2.6.23 */
+     242          65 :                 if (errno == EOPNOTSUPP || errno == ENOSYS) {
+     243             :                         /* fallback using ftruncate() */
+     244           1 :                         call = "ftruncate";
+     245           1 :                         ret = ftruncate(parity->f, size);
+     246             :                 }
+     247             : #else
+     248             :                 (void)skip_fallocate; /* avoid the warning */
+     249             : 
+     250             :                 /* allocate using a sparse file */
+     251             :                 call = "ftruncate";
+     252             :                 ret = ftruncate(parity->f, size);
+     253             : #endif
+     254             :                 /* save the state of the grow operation */
+     255          65 :                 f_ret = ret;
+     256          65 :                 f_errno = errno;
+     257             : 
+     258             :                 /* get the stat info */
+     259          65 :                 ret = fstat(parity->f, &parity->st);
+     260          65 :                 if (ret != 0) {
+     261             :                         /* LCOV_EXCL_START */
+     262             :                         log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno));
+     263             :                         goto bail;
+     264             :                         /* LCOV_EXCL_STOP */
+     265             :                 }
+     266             : 
+     267             :                 /* return the new size */
+     268          65 :                 *out_size = parity->st.st_size;
+     269             : 
+     270             :                 /* now check the error */
+     271          65 :                 if (f_ret != 0) {
+     272             :                         /* LCOV_EXCL_START */
+     273             :                         if (f_errno == ENOSPC) {
+     274             :                                 log_fatal("Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call);
+     275             :                         } else {
+     276             :                                 log_fatal("Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno));
+     277             :                         }
+     278             :                         goto bail;
+     279             :                         /* LCOV_EXCL_STOP */
+     280             :                 }
+     281         432 :         } else if (parity->st.st_size > size) {
+     282             :                 int f_ret;
+     283             :                 int f_errno;
+     284             : 
+     285             :                 /* truncate the parity file */
+     286          36 :                 ret = ftruncate(parity->f, size);
+     287             : 
+     288             :                 /* save the state of the shrink operation */
+     289          36 :                 f_ret = ret;
+     290          36 :                 f_errno = errno;
+     291             : 
+     292             :                 /* get the stat info */
+     293          36 :                 ret = fstat(parity->f, &parity->st);
+     294          36 :                 if (ret != 0) {
+     295             :                         /* LCOV_EXCL_START */
+     296             :                         log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno));
+     297             :                         goto bail;
+     298             :                         /* LCOV_EXCL_STOP */
+     299             :                 }
+     300             : 
+     301             :                 /* return the new size */
+     302          36 :                 *out_size = parity->st.st_size;
+     303             : 
+     304             :                 /* now check the error */
+     305          36 :                 if (f_ret != 0) {
+     306             :                         /* LCOV_EXCL_START */
+     307             :                         log_fatal("Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno));
+     308             :                         goto bail;
+     309             :                         /* LCOV_EXCL_STOP */
+     310             :                 }
+     311             : 
+     312             :                 /* adjust the valid to the new size */
+     313          36 :                 parity->valid_size = size;
+     314             :         }
+     315             : 
+     316         497 :         return 0;
+     317             : 
+     318             : bail:
+     319             :         /* LCOV_EXCL_START */
+     320             :         parity->valid_size = 0;
+     321             :         return -1;
+     322             :         /* LCOV_EXCL_STOP */
+     323             : }
+     324             : 
+     325         391 : int parity_open(struct snapraid_parity_handle* parity, const char* path, int mode)
+     326             : {
+     327             :         int ret;
+     328             :         int flags;
+     329             : 
+     330         391 :         pathcpy(parity->path, sizeof(parity->path), path);
+     331             : 
+     332             :         /* open for read */
+     333             :         /* O_SEQUENTIAL: opening in sequential mode in Windows */
+     334             :         /* O_NOATIME: do not change access time */
+     335         391 :         flags = O_RDONLY | O_BINARY;
+     336         391 :         if ((mode & MODE_SEQUENTIAL) != 0)
+     337         390 :                 flags |= O_SEQUENTIAL;
+     338         391 :         parity->f = open_noatime(parity->path, flags);
+     339         391 :         if (parity->f == -1) {
+     340           1 :                 log_fatal("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno));
+     341           1 :                 return -1;
+     342             :         }
+     343             : 
+     344             :         /* get the stat info */
+     345         390 :         ret = fstat(parity->f, &parity->st);
+     346         390 :         if (ret != 0) {
+     347             :                 /* LCOV_EXCL_START */
+     348             :                 log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno));
+     349             :                 goto bail;
+     350             :                 /* LCOV_EXCL_STOP */
+     351             :         }
+     352             : 
+     353             :         /* get the size of the exising data */
+     354         390 :         parity->valid_size = parity->st.st_size;
+     355             : 
+     356             : #if HAVE_POSIX_FADVISE
+     357         390 :         if ((mode & MODE_SEQUENTIAL) != 0) {
+     358             :                 /* advise sequential access */
+     359         389 :                 ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL);
+     360         389 :                 if (ret != 0) {
+     361             :                         /* LCOV_EXCL_START */
+     362             :                         log_fatal("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret));
+     363             :                         goto bail;
+     364             :                         /* LCOV_EXCL_STOP */
+     365             :                 }
+     366             :         }
+     367             : #endif
+     368             : 
+     369         390 :         return 0;
+     370             : 
+     371             : bail:
+     372             :         /* LCOV_EXCL_START */
+     373             :         close(parity->f);
+     374             :         parity->f = -1;
+     375             :         parity->valid_size = 0;
+     376             :         return -1;
+     377             :         /* LCOV_EXCL_STOP */
+     378             : }
+     379             : 
+     380         368 : int parity_sync(struct snapraid_parity_handle* parity)
+     381             : {
+     382             : #if HAVE_FSYNC
+     383             :         int ret;
+     384             : 
+     385             :         /* Ensure that data changes are written to disk. */
+     386             :         /* This is required to ensure that parity is more updated than content */
+     387             :         /* in case of a system crash. */
+     388         368 :         ret = fsync(parity->f);
+     389         368 :         if (ret != 0) {
+     390             :                 /* LCOV_EXCL_START */
+     391             :                 log_fatal("Error synching parity file '%s'. %s.\n", parity->path, strerror(errno));
+     392             :                 return -1;
+     393             :                 /* LCOV_EXCL_STOP */
+     394             :         }
+     395             : #endif
+     396             : 
+     397         368 :         return 0;
+     398             : }
+     399             : 
+     400         887 : int parity_close(struct snapraid_parity_handle* parity)
+     401             : {
+     402             :         int ret;
+     403             : 
+     404         887 :         ret = close(parity->f);
+     405         887 :         if (ret != 0) {
+     406             :                 /* LCOV_EXCL_START */
+     407             :                 /* invalidate for error */
+     408             :                 parity->f = -1;
+     409             :                 parity->valid_size = 0;
+     410             : 
+     411             :                 /* This is a serious error, as it may be the result of a failed write */
+     412             :                 /* identified at later time. */
+     413             :                 /* In a normal filesystem (not NFS) it should never happen */
+     414             :                 log_fatal("Error closing parity file '%s'. %s.\n", parity->path, strerror(errno));
+     415             :                 return -1;
+     416             :                 /* LCOV_EXCL_STOP */
+     417             :         }
+     418             : 
+     419             :         /* reset the descriptor */
+     420         887 :         parity->f = -1;
+     421         887 :         parity->valid_size = 0;
+     422             : 
+     423         887 :         return 0;
+     424             : }
+     425             : 
+     426      500002 : int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size)
+     427             : {
+     428             :         ssize_t write_ret;
+     429             :         data_off_t offset;
+     430             : 
+     431      500002 :         offset = pos * (data_off_t)block_size;
+     432             : 
+     433             : #if HAVE_PWRITE
+     434      500002 :         write_ret = pwrite(parity->f, block_buffer, block_size, offset);
+     435             : #else
+     436             :         if (lseek(parity->f, offset, SEEK_SET) != offset) {
+     437             :                 /* LCOV_EXCL_START */
+     438             :                 if (errno == ENOSPC) {
+     439             :                         log_fatal("Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path);
+     440             :                 } else {
+     441             :                         log_fatal("Error seeking file '%s'. %s.\n", parity->path, strerror(errno));
+     442             :                 }
+     443             :                 return -1;
+     444             :                 /* LCOV_EXCL_STOP */
+     445             :         }
+     446             : 
+     447             :         write_ret = write(parity->f, block_buffer, block_size);
+     448             : #endif
+     449      500002 :         if (write_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */
+     450             :                 /* LCOV_EXCL_START */
+     451             :                 if (errno == ENOSPC) {
+     452             :                         log_fatal("Failed to grow parity file '%s' using write due lack of space.\n", parity->path);
+     453             :                 } else {
+     454             :                         log_fatal("Error writing file '%s'. %s.\n", parity->path, strerror(errno));
+     455             :                 }
+     456             :                 return -1;
+     457             :                 /* LCOV_EXCL_STOP */
+     458             :         }
+     459             : 
+     460             :         /* adjust the size of the valid data */
+     461      500002 :         if (parity->valid_size < offset + block_size) {
+     462      169982 :                 parity->valid_size = offset + block_size;
+     463             :         }
+     464             : 
+     465             :         /* Here doesn't make sense to call posix_fadvise(..., POSIX_FADV_DONTNEED) because */
+     466             :         /* at this time the data is still in not yet written and it cannot be discharged. */
+     467             : 
+     468      500002 :         return 0;
+     469             : }
+     470             : 
+     471     3405588 : int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, fptr* out)
+     472             : {
+     473             :         ssize_t read_ret;
+     474             :         data_off_t offset;
+     475             :         unsigned count;
+     476             : 
+     477     3405588 :         offset = pos * (data_off_t)block_size;
+     478             : 
+     479             :         /* check if we are going to read only not initialized data */
+     480     3405588 :         if (offset >= parity->valid_size) {
+     481       90270 :                 out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", parity->path, offset);
+     482       90270 :                 return -1;
+     483             :         }
+     484             : 
+     485             : #if !HAVE_PREAD
+     486             :         if (lseek(parity->f, offset, SEEK_SET) != offset) {
+     487             :                 /* LCOV_EXCL_START */
+     488             :                 out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno));
+     489             :                 return -1;
+     490             :                 /* LCOV_EXCL_STOP */
+     491             :         }
+     492             : #endif
+     493             : 
+     494     3315318 :         count = 0;
+     495             :         do {
+     496             : 
+     497             : #if HAVE_PREAD
+     498     3315318 :                 read_ret = pread(parity->f, block_buffer + count, block_size - count, offset + count);
+     499             : #else
+     500             :                 read_ret = read(parity->f, block_buffer + count, block_size - count);
+     501             : #endif
+     502     3315318 :                 if (read_ret < 0) {
+     503             :                         /* LCOV_EXCL_START */
+     504             :                         out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno));
+     505             :                         return -1;
+     506             :                         /* LCOV_EXCL_STOP */
+     507             :                 }
+     508     3315318 :                 if (read_ret == 0) {
+     509             :                         /* LCOV_EXCL_START */
+     510             :                         out("Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno));
+     511             :                         return -1;
+     512             :                         /* LCOV_EXCL_STOP */
+     513             :                 }
+     514             : 
+     515     3315318 :                 count += read_ret;
+     516     3315318 :         } while (count < block_size);
+     517             : 
+     518             :         /* Here isn't needed to call posix_fadvise(..., POSIX_FADV_DONTNEED) */
+     519             :         /* because we already advised sequential access with POSIX_FADV_SEQUENTIAL. */
+     520             :         /* In Linux 2.6.33 it's enough to ensure that data is not kept in the cache. */
+     521             :         /* Better to do nothing and save a syscall for each block. */
+     522             : 
+     523     3315318 :         return block_size;
+     524             : }
+     525             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/pool.c.func-sort-c.html b/cov/cmdline/pool.c.func-sort-c.html new file mode 100644 index 00000000..4605ea38 --- /dev/null +++ b/cov/cmdline/pool.c.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - cmdline/pool.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - pool.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:646894.1 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
make_link17568
clean_dir5
state_pool3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/pool.c.func.html b/cov/cmdline/pool.c.func.html new file mode 100644 index 00000000..4eed1d45 --- /dev/null +++ b/cov/cmdline/pool.c.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - cmdline/pool.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - pool.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:646894.1 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
clean_dir5
make_link17568
state_pool3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/pool.c.gcov.html b/cov/cmdline/pool.c.gcov.html new file mode 100644 index 00000000..b3328511 --- /dev/null +++ b/cov/cmdline/pool.c.gcov.html @@ -0,0 +1,338 @@ + + + + + + + LCOV - lcov.info - cmdline/pool.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - pool.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:646894.1 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : 
+      24             : /**
+      25             :  * Clean a directory tree removing all the symlinks and empty directories.
+      26             :  * Return == 0 if the directory is empty, and it can be removed
+      27             :  */
+      28           5 : static int clean_dir(struct snapraid_state* state, const char* dir)
+      29             : {
+      30             :         DIR* d;
+      31           5 :         int ignored = 0;
+      32             : 
+      33           5 :         d = opendir(dir);
+      34           5 :         if (!d) {
+      35             :                 /* LCOV_EXCL_START */
+      36             :                 log_fatal("Error opening pool directory '%s'. %s.\n", dir, strerror(errno));
+      37             :                 exit(EXIT_FAILURE);
+      38             :                 /* LCOV_EXCL_STOP */
+      39             :         }
+      40             : 
+      41             :         while (1) {
+      42             :                 char path_next[PATH_MAX];
+      43             :                 struct stat st;
+      44             :                 const char* name;
+      45             :                 struct dirent* dd;
+      46             : 
+      47             :                 /* clear errno to detect erroneous conditions */
+      48        5759 :                 errno = 0;
+      49        5759 :                 dd = readdir(d);
+      50        5759 :                 if (dd == 0 && errno != 0) {
+      51             :                         /* LCOV_EXCL_START */
+      52             :                         log_fatal("Error reading pool directory '%s'. %s.\n", dir, strerror(errno));
+      53             :                         exit(EXIT_FAILURE);
+      54             :                         /* LCOV_EXCL_STOP */
+      55             :                 }
+      56        5759 :                 if (dd == 0 && errno == 0) {
+      57           5 :                         break; /* finished */
+      58             :                 }
+      59             : 
+      60             :                 /* skip "." and ".." files */
+      61        5754 :                 name = dd->d_name;
+      62        5754 :                 if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
+      63          10 :                         continue;
+      64             : 
+      65        5744 :                 pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
+      66             : 
+      67             : #if HAVE_STRUCT_DIRENT_D_STAT
+      68             :                 /* convert dirent to lstat result */
+      69             :                 dirent_lstat(dd, &st);
+      70             : 
+      71             :                 /* if the st_mode field is missing, takes care to fill it using normal lstat() */
+      72             :                 /* at now this can happen only in Windows */
+      73             :                 if (st.st_mode == 0) {
+      74             :                         if (lstat(path_next, &st) != 0) {
+      75             :                                 /* LCOV_EXCL_START */
+      76             :                                 log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+      77             :                                 exit(EXIT_FAILURE);
+      78             :                                 /* LCOV_EXCL_STOP */
+      79             :                         }
+      80             :                 }
+      81             : #else
+      82             :                 /* get lstat info about the file */
+      83        5744 :                 if (lstat(path_next, &st) != 0) {
+      84             :                         /* LCOV_EXCL_START */
+      85             :                         log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+      86             :                         exit(EXIT_FAILURE);
+      87             :                         /* LCOV_EXCL_STOP */
+      88             :                 }
+      89             : #endif
+      90             : 
+      91        5744 :                 if (S_ISLNK(st.st_mode)) {
+      92             :                         int ret;
+      93             : 
+      94             :                         /* delete the link */
+      95        5742 :                         ret = remove(path_next);
+      96        5742 :                         if (ret < 0) {
+      97             :                                 /* LCOV_EXCL_START */
+      98             :                                 log_fatal("Error removing symlink '%s'. %s.\n", path_next, strerror(errno));
+      99             :                                 exit(EXIT_FAILURE);
+     100             :                                 /* LCOV_EXCL_STOP */
+     101             :                         }
+     102           2 :                 } else if (S_ISDIR(st.st_mode)) {
+     103             :                         /* recurse */
+     104           2 :                         pathslash(path_next, sizeof(path_next));
+     105           2 :                         if (clean_dir(state, path_next) == 0) {
+     106             :                                 int ret;
+     107             : 
+     108             :                                 /* directory is empty, try to remove it */
+     109           2 :                                 ret = rmdir(path_next);
+     110           2 :                                 if (ret < 0) {
+     111             : #ifdef _WIN32
+     112             :                                         if (errno == EACCES) {
+     113             :                                                 /* in Windows just ignore EACCES errors removing directories */
+     114             :                                                 /* because it could happen that the directory is in use */
+     115             :                                                 /* and it cannot be removed */
+     116             :                                                 log_fatal("Directory '%s' not removed because it's in use.\n", path_next);
+     117             :                                                 ignored = 1;
+     118             :                                         } else
+     119             : #endif
+     120             :                                         {
+     121             :                                                 /* LCOV_EXCL_START */
+     122             :                                                 log_fatal("Error removing pool directory '%s'. %s.\n", path_next, strerror(errno));
+     123             :                                                 exit(EXIT_FAILURE);
+     124             :                                                 /* LCOV_EXCL_STOP */
+     125             :                                         }
+     126             :                                 }
+     127             :                         } else {
+     128             :                                 /* something was ignored inside the subdir */
+     129           0 :                                 ignored = 1;
+     130             :                         }
+     131             :                 } else {
+     132           0 :                         ignored = 1;
+     133           0 :                         msg_verbose("Ignoring pool file '%s'\n", path_next);
+     134             :                 }
+     135        5754 :         }
+     136             : 
+     137           5 :         if (closedir(d) != 0) {
+     138             :                 /* LCOV_EXCL_START */
+     139             :                 log_fatal("Error closing pool directory '%s'. %s.\n", dir, strerror(errno));
+     140             :                 exit(EXIT_FAILURE);
+     141             :                 /* LCOV_EXCL_STOP */
+     142             :         }
+     143             : 
+     144           5 :         return ignored;
+     145             : }
+     146             : 
+     147             : /**
+     148             :  * Creates a link to the specified disk entry.
+     149             :  */
+     150       17568 : static void make_link(const char* pool_dir, const char* share_dir, struct snapraid_disk* disk, const char* sub)
+     151             : {
+     152             :         char path[PATH_MAX];
+     153             :         char linkto[PATH_MAX];
+     154             :         char linkto_exported[PATH_MAX];
+     155             :         int ret;
+     156             : 
+     157             :         /* make the source path */
+     158       17568 :         pathprint(path, sizeof(path), "%s%s", pool_dir, sub);
+     159             : 
+     160             :         /* make the linkto path */
+     161       17568 :         if (share_dir[0] != 0) {
+     162             :                 /* with a shared directory, use it */
+     163       17568 :                 pathprint(linkto, sizeof(linkto), "%s%s/%s", share_dir, disk->name, sub);
+     164             :         } else {
+     165             :                 /* without a share directory, use the local disk paths */
+     166           0 :                 pathprint(linkto, sizeof(linkto), "%s%s", disk->dir, sub);
+     167             :         }
+     168             : 
+     169             :         /* create the ancestor directories */
+     170       17568 :         ret = mkancestor(path);
+     171       17568 :         if (ret != 0) {
+     172             :                 /* LCOV_EXCL_START */
+     173             :                 exit(EXIT_FAILURE);
+     174             :                 /* LCOV_EXCL_STOP */
+     175             :         }
+     176             : 
+     177             :         /* convert back slashes */
+     178       17568 :         pathexport(linkto_exported, sizeof(linkto_exported), linkto);
+     179             : 
+     180             :         /* create the symlink */
+     181       17568 :         ret = symlink(linkto_exported, path);
+     182       17568 :         if (ret != 0) {
+     183         523 :                 if (errno == EEXIST) {
+     184         523 :                         log_fatal("WARNING! Duplicate pooling for '%s'\n", path);
+     185             : #ifdef _WIN32
+     186             :                 } else if (errno == EPERM) {
+     187             :                         /* LCOV_EXCL_START */
+     188             :                         log_fatal("You must run as Adminstrator to be able to create symlinks.\n");
+     189             :                         exit(EXIT_FAILURE);
+     190             :                         /* LCOV_EXCL_STOP */
+     191             : #endif
+     192             :                 } else {
+     193             :                         /* LCOV_EXCL_START */
+     194             :                         log_fatal("Error writing symlink '%s'. %s.\n", path, strerror(errno));
+     195             :                         exit(EXIT_FAILURE);
+     196             :                         /* LCOV_EXCL_STOP */
+     197             :                 }
+     198             :         }
+     199       17568 : }
+     200             : 
+     201           3 : void state_pool(struct snapraid_state* state)
+     202             : {
+     203             :         tommy_node* i;
+     204             :         char pool_dir[PATH_MAX];
+     205             :         char share_dir[PATH_MAX];
+     206             :         unsigned count;
+     207             : 
+     208           3 :         if (state->pool[0] == 0) {
+     209             :                 /* LCOV_EXCL_START */
+     210             :                 log_fatal("To use the 'pool' command you must set the pool directory in the configuration file\n");
+     211             :                 exit(EXIT_FAILURE);
+     212             :                 /* LCOV_EXCL_STOP */
+     213             :         }
+     214             : 
+     215           3 :         msg_progress("Cleaning...\n");
+     216             : 
+     217             :         /* pool directory with final slash */
+     218           3 :         pathprint(pool_dir, sizeof(pool_dir), "%s", state->pool);
+     219           3 :         pathslash(pool_dir, sizeof(pool_dir));
+     220             : 
+     221             :         /* share directory with final slash */
+     222           3 :         pathprint(share_dir, sizeof(share_dir), "%s", state->share);
+     223           3 :         pathslash(share_dir, sizeof(share_dir));
+     224             : 
+     225             :         /* first clear the previous pool tree */
+     226           3 :         clean_dir(state, pool_dir);
+     227             : 
+     228           3 :         msg_progress("Pooling...\n");
+     229             : 
+     230             :         /* for each disk */
+     231           3 :         count = 0;
+     232          21 :         for (i = state->disklist; i != 0; i = i->next) {
+     233             :                 tommy_node* j;
+     234          18 :                 struct snapraid_disk* disk = i->data;
+     235             : 
+     236             :                 /* for each file */
+     237       16997 :                 for (j = disk->filelist; j != 0; j = j->next) {
+     238       16979 :                         struct snapraid_file* file = j->data;
+     239       16979 :                         make_link(pool_dir, share_dir, disk, file->sub);
+     240       16979 :                         ++count;
+     241             :                 }
+     242             : 
+     243             :                 /* for each link */
+     244         607 :                 for (j = disk->linklist; j != 0; j = j->next) {
+     245         589 :                         struct snapraid_link* link = j->data;
+     246         589 :                         make_link(pool_dir, share_dir, disk, link->sub);
+     247         589 :                         ++count;
+     248             :                 }
+     249             : 
+     250             :                 /* we ignore empty dirs in disk->dir */
+     251             :         }
+     252             : 
+     253           3 :         if (count)
+     254           2 :                 msg_status("%u links created\n", count);
+     255             :         else
+     256           1 :                 msg_status("No link created\n");
+     257             : 
+     258           3 :         log_tag("summary:link_count::%u\n", count);
+     259           3 :         log_tag("summary:exit:ok\n");
+     260           3 :         log_flush();
+     261           3 : }
+     262             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/portable.h.func-sort-c.html b/cov/cmdline/portable.h.func-sort-c.html new file mode 100644 index 00000000..61a4ba51 --- /dev/null +++ b/cov/cmdline/portable.h.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/portable.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - portable.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:22100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hardlink32
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/portable.h.func.html b/cov/cmdline/portable.h.func.html new file mode 100644 index 00000000..547b2aed --- /dev/null +++ b/cov/cmdline/portable.h.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/portable.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - portable.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:22100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hardlink32
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/portable.h.gcov.html b/cov/cmdline/portable.h.gcov.html new file mode 100644 index 00000000..a739bcf4 --- /dev/null +++ b/cov/cmdline/portable.h.gcov.html @@ -0,0 +1,498 @@ + + + + + + + LCOV - lcov.info - cmdline/portable.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - portable.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:22100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #ifndef __PORTABLE_H
+      19             : #define __PORTABLE_H
+      20             : 
+      21             : #if HAVE_CONFIG_H
+      22             : #include "config.h" /* Use " to include first in the same directory of this file */
+      23             : #endif
+      24             : 
+      25             : /***************************************************************************/
+      26             : /* Config */
+      27             : 
+      28             : #ifdef __MINGW32__
+      29             : /**
+      30             :  * Enable the GNU printf functions instead of using the MSVCRT ones.
+      31             :  *
+      32             :  * Note that this is the default if _POSIX is also defined.
+      33             :  * To disable it you have to set it to 0.
+      34             :  */
+      35             : #define __USE_MINGW_ANSI_STDIO 1
+      36             : 
+      37             : /*
+      38             :  * Define the MSVCRT version targetting Windows XP.
+      39             :  */
+      40             : #define __MSVCRT_VERSION__ 0x0601
+      41             : 
+      42             : /**
+      43             :  * Include Windows XP headers.
+      44             :  *
+      45             :  * Like for CreateHardLinkW().
+      46             :  */
+      47             : #define _WIN32_WINNT 0x501
+      48             : 
+      49             : #include <windows.h>
+      50             : #endif
+      51             : 
+      52             : /**
+      53             :  * Specify the format attribute for printf.
+      54             :  */
+      55             : #ifdef __MINGW32__
+      56             : #if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO == 1
+      57             : #define attribute_printf gnu_printf /* GNU format */
+      58             : #else
+      59             : #define attribute_printf ms_printf /* MSVCRT format */
+      60             : #endif
+      61             : #else
+      62             : #define attribute_printf printf /* GNU format is the default one */
+      63             : #endif
+      64             : 
+      65             : /**
+      66             :  * Compiler extension
+      67             :  */
+      68             : #ifndef __always_inline
+      69             : #define __always_inline inline __attribute__((always_inline))
+      70             : #endif
+      71             : 
+      72             : /**
+      73             :  * Architecture.
+      74             :  */
+      75             : #if defined(__i386__)
+      76             : #define CONFIG_X86 1
+      77             : #define CONFIG_X86_32 1
+      78             : #endif
+      79             : 
+      80             : #if defined(__x86_64__)
+      81             : #define CONFIG_X86 1
+      82             : #define CONFIG_X86_64 1
+      83             : #endif
+      84             : 
+      85             : /**
+      86             :  * Includes some platform specific headers.
+      87             :  */
+      88             : #if HAVE_SYS_PARAM_H
+      89             : #include <sys/param.h>
+      90             : #endif
+      91             : 
+      92             : #if HAVE_SYS_MOUNT_H
+      93             : #include <sys/mount.h>
+      94             : #endif
+      95             : 
+      96             : #if HAVE_SYS_VFS_H
+      97             : #include <sys/vfs.h>
+      98             : #endif
+      99             : 
+     100             : #if HAVE_SYS_STATFS_H
+     101             : #include <sys/statfs.h>
+     102             : #endif
+     103             : 
+     104             : #if HAVE_SYS_FILE_H
+     105             : #include <sys/file.h>
+     106             : #endif
+     107             : 
+     108             : #if HAVE_SYS_IOCTL_H
+     109             : #include <sys/ioctl.h>
+     110             : #endif
+     111             : 
+     112             : #if HAVE_LINUX_FS_H
+     113             : #include <linux/fs.h>
+     114             : #endif
+     115             : 
+     116             : #if HAVE_LINUX_FIEMAP_H
+     117             : #include <linux/fiemap.h>
+     118             : #endif
+     119             : 
+     120             : /**
+     121             :  * Includes some standard headers.
+     122             :  */
+     123             : #include <stdio.h>
+     124             : #include <stdlib.h> /* On many systems (e.g., Darwin), `stdio.h' is a prerequisite. */
+     125             : #include <stdarg.h>
+     126             : #include <string.h>
+     127             : #include <ctype.h>
+     128             : #include <fcntl.h>
+     129             : #include <assert.h>
+     130             : #include <errno.h>
+     131             : #include <signal.h>
+     132             : #include <limits.h>
+     133             : 
+     134             : #if HAVE_STDINT_H
+     135             : #include <stdint.h>
+     136             : #endif
+     137             : 
+     138             : #if HAVE_INTTYPES_H
+     139             : #include <inttypes.h>
+     140             : #endif
+     141             : 
+     142             : #if HAVE_UNISTD_H
+     143             : #include <unistd.h>
+     144             : #endif
+     145             : 
+     146             : #if TIME_WITH_SYS_TIME
+     147             : #include <sys/time.h>
+     148             : #include <time.h>
+     149             : #else
+     150             : #if HAVE_SYS_TIME_H
+     151             : #include <sys/time.h>
+     152             : #else
+     153             : #include <time.h>
+     154             : #endif
+     155             : #endif
+     156             : 
+     157             : #if HAVE_MACH_MACH_TIME_H
+     158             : #include <mach/mach_time.h>
+     159             : #endif
+     160             : 
+     161             : #if HAVE_DIRENT_H
+     162             : #include <dirent.h>
+     163             : #define NAMLEN(dirent) strlen((dirent)->d_name)
+     164             : #else
+     165             : #define dirent direct
+     166             : #define NAMLEN(dirent) (dirent)->d_namlen
+     167             : #if HAVE_SYS_NDIR_H
+     168             : #include <sys/ndir.h>
+     169             : #endif
+     170             : #if HAVE_SYS_DIR_H
+     171             : #include <sys/dir.h>
+     172             : #endif
+     173             : #if HAVE_NDIR_H
+     174             : #include <ndir.h>
+     175             : #endif
+     176             : #endif
+     177             : 
+     178             : #if HAVE_SYS_TYPES_H
+     179             : #include <sys/types.h>
+     180             : #endif
+     181             : 
+     182             : #if HAVE_SYS_STAT_H
+     183             : #include <sys/stat.h>
+     184             : #endif
+     185             : 
+     186             : #if HAVE_SYS_WAIT_H
+     187             : #include <sys/wait.h>
+     188             : #endif
+     189             : #ifndef WEXITSTATUS
+     190             : #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+     191             : #endif
+     192             : #ifndef WIFEXITED
+     193             : #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+     194             : #endif
+     195             : 
+     196             : #if HAVE_GETOPT_H
+     197             : #include <getopt.h>
+     198             : #endif
+     199             : 
+     200             : #if HAVE_FNMATCH_H
+     201             : #include <fnmatch.h>
+     202             : #else
+     203             : #include "fnmatch.h"
+     204             : #endif
+     205             : 
+     206             : #if HAVE_PTHREAD_H
+     207             : #include <pthread.h>
+     208             : #endif
+     209             : 
+     210             : #if HAVE_MATH_H
+     211             : #include <math.h>
+     212             : #endif
+     213             : 
+     214             : /**
+     215             :  * Disable case check in Windows.
+     216             :  */
+     217             : #ifdef _WIN32
+     218             : #define FNM_CASEINSENSITIVE_FOR_WIN FNM_CASEFOLD
+     219             : #else
+     220             : #define FNM_CASEINSENSITIVE_FOR_WIN 0
+     221             : #endif
+     222             : 
+     223             : #if HAVE_IO_H
+     224             : #include <io.h>
+     225             : #endif
+     226             : 
+     227             : #if HAVE_GETOPT_LONG
+     228             : #define SWITCH_GETOPT_LONG(a, b) a
+     229             : #else
+     230             : #define SWITCH_GETOPT_LONG(a, b) b
+     231             : #endif
+     232             : 
+     233             : /**
+     234             :  * Enables lock file support.
+     235             :  */
+     236             : #if HAVE_FLOCK && HAVE_FTRUNCATE
+     237             : #define HAVE_LOCKFILE 1
+     238             : #endif
+     239             : 
+     240             : /**
+     241             :  * Includes specific support for Windows or Linux.
+     242             :  */
+     243             : #ifdef __MINGW32__
+     244             : #include "mingw.h"
+     245             : #else
+     246             : #include "unix.h"
+     247             : #endif
+     248             : 
+     249             : /**
+     250             :  * Include list support to have tommy_node.
+     251             :  */
+     252             : #include "tommyds/tommylist.h"
+     253             : 
+     254             : /**
+     255             :  * Another name for link() to avoid confusion with local variables called "link".
+     256             :  */
+     257          32 : static inline int hardlink(const char* a, const char* b)
+     258             : {
+     259          32 :         return link(a, b);
+     260             : }
+     261             : 
+     262             : /**
+     263             :  * Get the device UUID.
+     264             :  * Returns 0 on success.
+     265             :  */
+     266             : int devuuid(uint64_t device, char* uuid, size_t size);
+     267             : 
+     268             : /**
+     269             :  * Physical offset not yet read.
+     270             :  */
+     271             : #define FILEPHY_UNREAD_OFFSET 0
+     272             : 
+     273             : /**
+     274             :  * Special value returned when the filesystem doesn't report any offset for unknown reason.
+     275             :  */
+     276             : #define FILEPHY_UNREPORTED_OFFSET 1
+     277             : 
+     278             : /**
+     279             :  * Special value returned when the file doesn't have a real offset.
+     280             :  * For example, because it's stored in the NTFS MFT.
+     281             :  */
+     282             : #define FILEPHY_WITHOUT_OFFSET 2
+     283             : 
+     284             : /**
+     285             :  * Value indicating real offsets. All offsets greater or equal at this one are real.
+     286             :  */
+     287             : #define FILEPHY_REAL_OFFSET 3
+     288             : 
+     289             : /**
+     290             :  * Get the physcal address of the specified file.
+     291             :  * This is expected to be just a hint and not necessarely correct or unique.
+     292             :  * Returns 0 on success.
+     293             :  */
+     294             : int filephy(const char* path, uint64_t size, uint64_t* physical);
+     295             : 
+     296             : /**
+     297             :  * Checks if the underline filesystem support persistent inodes.
+     298             :  * Returns -1 on error, 0 on success.
+     299             :  */
+     300             : int fsinfo(const char* path, int* has_persistent_inode, uint64_t* total_space, uint64_t* free_space);
+     301             : 
+     302             : /**
+     303             :  * Get the tick counter value.
+     304             :  *
+     305             :  * Note that the frequency is unspecified, because the time measure
+     306             :  * is meant to be used to compare the ratio between usage times.
+     307             :  */
+     308             : uint64_t tick(void);
+     309             : 
+     310             : /**
+     311             :  * Get the tick counter value in millisecond.
+     312             :  */
+     313             : uint64_t tick_ms(void);
+     314             : 
+     315             : /**
+     316             :  * Initializes the system.
+     317             :  */
+     318             : void os_init(int opt);
+     319             : 
+     320             : /**
+     321             :  * Deintialize the system.
+     322             :  */
+     323             : void os_done(void);
+     324             : 
+     325             : /**
+     326             :  * Log file.
+     327             :  *
+     328             :  * This stream if fully buffered.
+     329             :  *
+     330             :  * If no log file is selected, it's 0.
+     331             :  */
+     332             : FILE* stdlog;
+     333             : 
+     334             : /**
+     335             :  * Exit codes for testing.
+     336             :  */
+     337             : int exit_success;
+     338             : int exit_failure;
+     339             : int exit_sync_needed;
+     340             : #undef EXIT_SUCCESS
+     341             : #undef EXIT_FAILURE
+     342             : #define EXIT_SUCCESS exit_success
+     343             : #define EXIT_FAILURE exit_failure
+     344             : #define EXIT_SYNC_NEEDED exit_sync_needed
+     345             : 
+     346             : /**
+     347             :  * Fill memory with psudeo-random values.
+     348             :  */
+     349             : int randomize(void* ptr, size_t size);
+     350             : 
+     351             : /**
+     352             :  * Additional SMART attributes.
+     353             :  */
+     354             : #define SMART_ERROR 256 /**< ATA Error count. */
+     355             : #define SMART_SIZE 257 /**< Size in bytes. */
+     356             : #define SMART_ROTATION_RATE 258 /**< Rotation speed. 0 for SSD. */
+     357             : #define SMART_FLAGS 259 /**< Flags returned by smartctl. */
+     358             : 
+     359             : /**
+     360             :  * SMART attributes count.
+     361             :  */
+     362             : #define SMART_COUNT 260
+     363             : 
+     364             : /**
+     365             :  * Flags returned by smartctl.
+     366             :  */
+     367             : #define SMARTCTL_FLAG_UNSUPPORTED (1 << 0) /**< Device not recognized, requiring the -d option. */
+     368             : #define SMARTCTL_FLAG_OPEN (1 << 1) /**< Device open or identification failed. */
+     369             : #define SMARTCTL_FLAG_COMMAND (1 << 2) /**< Some SMART or ATA commands failed. This is a common error, also happening with full info gathering. */
+     370             : #define SMARTCTL_FLAG_FAIL (1 << 3) /**< SMART status check returned "DISK FAILING". */
+     371             : #define SMARTCTL_FLAG_PREFAIL (1 << 4) /**< We found prefail Attributes <= threshold. */
+     372             : #define SMARTCTL_FLAG_PREFAIL_LOGGED (1 << 5) /**< SMART status check returned "DISK OK" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past. */
+     373             : #define SMARTCTL_FLAG_ERROR (1 << 6) /**< The device error log contains records of errors. */
+     374             : #define SMARTCTL_FLAG_ERROR_LOGGED (1 << 7) /**< The device self-test log contains records of errors. */
+     375             : 
+     376             : /**
+     377             :  * SMART max attribute length.
+     378             :  */
+     379             : #define SMART_MAX 64
+     380             : 
+     381             : /**
+     382             :  * Value for unassigned SMART attribute.
+     383             :  */
+     384             : #define SMART_UNASSIGNED 0xFFFFFFFFFFFFFFFFULL
+     385             : 
+     386             : /**
+     387             :  * Device info entry.
+     388             :  */
+     389             : struct devinfo_struct {
+     390             :         uint64_t device; /**< Device ID. */
+     391             :         char name[PATH_MAX]; /**< Name of the disk. */
+     392             :         char mount[PATH_MAX]; /**< Mount point or other contained directory. */
+     393             :         char smartctl[PATH_MAX]; /**< Options for smartctl. */
+     394             :         char file[PATH_MAX]; /**< File device. */
+     395             : #ifdef _WIN32
+     396             :         char wfile[PATH_MAX]; /**< File device in Windows format. Like \\.\PhysicalDriveX, or \\?\Volume{X}. */
+     397             : #endif
+     398             :         struct devinfo_struct* parent; /**< Pointer at the parent if any. */
+     399             :         uint64_t smart[SMART_COUNT]; /**< SMART raw attributes. */
+     400             :         char smart_serial[SMART_MAX]; /**< SMART serial number. */
+     401             : #if HAVE_PTHREAD_CREATE
+     402             :         pthread_t thread;
+     403             : #endif
+     404             :         tommy_node node;
+     405             : };
+     406             : typedef struct devinfo_struct devinfo_t;
+     407             : 
+     408             : #define DEVICE_LIST 0
+     409             : #define DEVICE_DOWN 1
+     410             : #define DEVICE_UP 2
+     411             : #define DEVICE_SMART 3
+     412             : 
+     413             : /**
+     414             :  * Query all the "high" level devices with the specified operation,
+     415             :  * and produces a list of "low" level devices to operate on.
+     416             :  *
+     417             :  * The passed "low" device list must be already initialized.
+     418             :  */
+     419             : int devquery(tommy_list* high, tommy_list* low, int operation);
+     420             : 
+     421             : #endif
+     422             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/rehash.c.func-sort-c.html b/cov/cmdline/rehash.c.func-sort-c.html new file mode 100644 index 00000000..e240e387 --- /dev/null +++ b/cov/cmdline/rehash.c.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/rehash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - rehash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:192095.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_rehash1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/rehash.c.func.html b/cov/cmdline/rehash.c.func.html new file mode 100644 index 00000000..0b898004 --- /dev/null +++ b/cov/cmdline/rehash.c.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/rehash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - rehash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:192095.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_rehash1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/rehash.c.gcov.html b/cov/cmdline/rehash.c.gcov.html new file mode 100644 index 00000000..591cd0f3 --- /dev/null +++ b/cov/cmdline/rehash.c.gcov.html @@ -0,0 +1,174 @@ + + + + + + + LCOV - lcov.info - cmdline/rehash.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - rehash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:192095.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "util.h"
+      21             : #include "elem.h"
+      22             : #include "import.h"
+      23             : #include "state.h"
+      24             : #include "parity.h"
+      25             : #include "handle.h"
+      26             : #include "raid/raid.h"
+      27             : 
+      28             : /****************************************************************************/
+      29             : /* rehash */
+      30             : 
+      31           1 : void state_rehash(struct snapraid_state* state)
+      32             : {
+      33             :         block_off_t blockmax;
+      34             :         block_off_t i;
+      35             : 
+      36           1 :         blockmax = parity_allocated_size(state);
+      37             : 
+      38             :         /* check if a rehash is already in progress */
+      39           1 :         if (state->prevhash != HASH_UNDEFINED) {
+      40             :                 /* LCOV_EXCL_START */
+      41             :                 log_fatal("You already have a rehash in progress.\n");
+      42             :                 exit(EXIT_FAILURE);
+      43             :                 /* LCOV_EXCL_STOP */
+      44             :         }
+      45             : 
+      46           1 :         if (state->hash == state->besthash) {
+      47             :                 /* LCOV_EXCL_START */
+      48             :                 log_fatal("You are already using the best hash for your platform.\n");
+      49             :                 exit(EXIT_FAILURE);
+      50             :                 /* LCOV_EXCL_STOP */
+      51             :         }
+      52             : 
+      53             :         /* copy the present hash as previous one */
+      54           1 :         state->prevhash = state->hash;
+      55           1 :         memcpy(state->prevhashseed, state->hashseed, HASH_SIZE);
+      56             : 
+      57             :         /* set the new hash and seed */
+      58           1 :         state->hash = state->besthash;
+      59           1 :         if (randomize(state->hashseed, HASH_SIZE) != 0) {
+      60             :                 /* LCOV_EXCL_START */
+      61             :                 log_fatal("Failed to get random values.\n");
+      62             :                 exit(EXIT_FAILURE);
+      63             :                 /* LCOV_EXCL_STOP */
+      64             :         }
+      65             : 
+      66             :         /* mark all the block for rehashing */
+      67        9200 :         for (i = 0; i < blockmax; ++i) {
+      68             :                 snapraid_info info;
+      69             : 
+      70             :                 /* if it's unused */
+      71        9199 :                 info = info_get(&state->infoarr, i);
+      72        9199 :                 if (info == 0) {
+      73             :                         /* skip it */
+      74           0 :                         continue;
+      75             :                 }
+      76             : 
+      77        9199 :                 if (info_get_rehash(info)) {
+      78             :                         /* LCOV_EXCL_START */
+      79             :                         log_fatal("Internal inconsistency for a rehash already in progress\n");
+      80             :                         exit(EXIT_FAILURE);
+      81             :                         /* LCOV_EXCL_STOP */
+      82             :                 }
+      83             : 
+      84             :                 /* enable the rehash */
+      85        9199 :                 info = info_set_rehash(info);
+      86             : 
+      87             :                 /* save it */
+      88        9199 :                 info_set(&state->infoarr, i, info);
+      89             :         }
+      90             : 
+      91             :         /* save the new content file */
+      92           1 :         state->need_write = 1;
+      93             : 
+      94           1 :         msg_status("A rehash is now scheduled. It will take place progressively in the next\n");
+      95           1 :         msg_status("'sync' and 'scrub' commands. You can check the rehash progress using the\n");
+      96           1 :         msg_status("'status' command.\n");
+      97           1 : }
+      98             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scan.c.func-sort-c.html b/cov/cmdline/scan.c.func-sort-c.html new file mode 100644 index 00000000..2b5249e8 --- /dev/null +++ b/cov/cmdline/scan.c.func-sort-c.html @@ -0,0 +1,160 @@ + + + + + + + LCOV - lcov.info - cmdline/scan.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scan.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:51661883.5 %
Date:2015-05-12Functions:2222100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
dd_name_compare10206597
dstat976055
scan_file974966
scan_file_keep897263
file_is_full_invalid_parity_and_stable897263
dd_ino_compare103300
scan_file_delayed_insert100042
scan_file_insert100042
scan_file_refresh77377
scan_file_deallocate55207
scan_file_remove32542
scan_link31866
file_is_full_hashed_and_stable23658
scan_link_insert2457
scan_dir1502
scan_link_remove956
scan_emptydir219
state_diffscan69
state_scan63
scan_emptydir_insert10
state_diff6
scan_emptydir_remove2
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scan.c.func.html b/cov/cmdline/scan.c.func.html new file mode 100644 index 00000000..a6a50c8b --- /dev/null +++ b/cov/cmdline/scan.c.func.html @@ -0,0 +1,160 @@ + + + + + + + LCOV - lcov.info - cmdline/scan.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scan.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:51661883.5 %
Date:2015-05-12Functions:2222100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
dd_ino_compare103300
dd_name_compare10206597
dstat976055
file_is_full_hashed_and_stable23658
file_is_full_invalid_parity_and_stable897263
scan_dir1502
scan_emptydir219
scan_emptydir_insert10
scan_emptydir_remove2
scan_file974966
scan_file_deallocate55207
scan_file_delayed_insert100042
scan_file_insert100042
scan_file_keep897263
scan_file_refresh77377
scan_file_remove32542
scan_link31866
scan_link_insert2457
scan_link_remove956
state_diff6
state_diffscan69
state_scan63
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scan.c.gcov.html b/cov/cmdline/scan.c.gcov.html new file mode 100644 index 00000000..e151f5f4 --- /dev/null +++ b/cov/cmdline/scan.c.gcov.html @@ -0,0 +1,1864 @@ + + + + + + + LCOV - lcov.info - cmdline/scan.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scan.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:51661883.5 %
Date:2015-05-12Functions:2222100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : 
+      25             : struct snapraid_scan {
+      26             :         struct snapraid_state* state; /**< State used. */
+      27             :         struct snapraid_disk* disk; /**< Disk used. */
+      28             : 
+      29             :         /**
+      30             :          * Counters of changes.
+      31             :          */
+      32             :         unsigned count_equal; /**< Files equal. */
+      33             :         unsigned count_move; /**< Files with a different name, but equal inode, size and timestamp in the same disk. */
+      34             :         unsigned count_restore; /**< Files with equal name, size and timestamp, but different inode. */
+      35             :         unsigned count_change; /**< Files with same name, but different size and/or timestamp. */
+      36             :         unsigned count_copy; /**< Files new, with same name size and timestamp of a file in a different disk. */
+      37             :         unsigned count_insert; /**< Files new. */
+      38             :         unsigned count_remove; /**< Files removed. */
+      39             : 
+      40             :         tommy_list file_insert_list; /**< Files to insert. */
+      41             :         tommy_list link_insert_list; /**< Links to insert. */
+      42             :         tommy_list dir_insert_list; /**< Dirs to insert. */
+      43             : 
+      44             :         /* nodes for data structures */
+      45             :         tommy_node node;
+      46             : };
+      47             : 
+      48             : /**
+      49             :  * Removes the specified link from the data set.
+      50             :  */
+      51         956 : static void scan_link_remove(struct snapraid_scan* scan, struct snapraid_link* link)
+      52             : {
+      53         956 :         struct snapraid_state* state = scan->state;
+      54         956 :         struct snapraid_disk* disk = scan->disk;
+      55             : 
+      56             :         /* state changed */
+      57         956 :         state->need_write = 1;
+      58             : 
+      59             :         /* remove the file from the link containers */
+      60         956 :         tommy_hashdyn_remove_existing(&disk->linkset, &link->nodeset);
+      61         956 :         tommy_list_remove_existing(&disk->linklist, &link->nodelist);
+      62             : 
+      63             :         /* deallocate */
+      64         956 :         link_free(link);
+      65         956 : }
+      66             : 
+      67             : /**
+      68             :  * Inserts the specified link in the data set.
+      69             :  */
+      70        2457 : static void scan_link_insert(struct snapraid_scan* scan, struct snapraid_link* link)
+      71             : {
+      72        2457 :         struct snapraid_state* state = scan->state;
+      73        2457 :         struct snapraid_disk* disk = scan->disk;
+      74             : 
+      75             :         /* state changed */
+      76        2457 :         state->need_write = 1;
+      77             : 
+      78             :         /* insert the link in the link containers */
+      79        2457 :         tommy_hashdyn_insert(&disk->linkset, &link->nodeset, link, link_name_hash(link->sub));
+      80        2457 :         tommy_list_insert_tail(&disk->linklist, &link->nodelist, link);
+      81        2457 : }
+      82             : 
+      83             : /**
+      84             :  * Processes a symbolic link.
+      85             :  */
+      86       31866 : static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, const char* linkto, unsigned link_flag)
+      87             : {
+      88       31866 :         struct snapraid_state* state = scan->state;
+      89       31866 :         struct snapraid_disk* disk = scan->disk;
+      90             :         struct snapraid_link* link;
+      91             : 
+      92             :         /* check if the link already exists */
+      93       31866 :         link = tommy_hashdyn_search(&disk->linkset, link_name_compare_to_arg, sub, link_name_hash(sub));
+      94       31866 :         if (link) {
+      95             :                 /* check if multiple files have the same name */
+      96       29409 :                 if (link_flag_has(link, FILE_IS_PRESENT)) {
+      97             :                         /* LCOV_EXCL_START */
+      98             :                         log_fatal("Internal inconsistency for link '%s%s'\n", disk->dir, sub);
+      99             :                         exit(EXIT_FAILURE);
+     100             :                         /* LCOV_EXCL_STOP */
+     101             :                 }
+     102             : 
+     103             :                 /* mark as present */
+     104       29409 :                 link_flag_set(link, FILE_IS_PRESENT);
+     105             : 
+     106             :                 /* check if the link is not changed and it's of the same kind */
+     107       29409 :                 if (strcmp(link->linkto, linkto) == 0 && link_flag == link_flag_get(link, FILE_IS_LINK_MASK)) {
+     108             :                         /* it's equal */
+     109       29409 :                         ++scan->count_equal;
+     110             : 
+     111       58818 :                         if (state->opt.gui) {
+     112         829 :                                 log_tag("scan:equal:%s:%s\n", disk->name, esc(link->sub));
+     113             :                         }
+     114             :                 } else {
+     115             :                         /* it's an update */
+     116             : 
+     117             :                         /* we have to save the linkto/type */
+     118           0 :                         state->need_write = 1;
+     119             : 
+     120           0 :                         ++scan->count_change;
+     121             : 
+     122           0 :                         log_tag("scan:update:%s:%s\n", disk->name, esc(link->sub));
+     123           0 :                         if (is_diff) {
+     124           0 :                                 printf("update %s%s\n", disk->dir, link->sub);
+     125             :                         }
+     126             : 
+     127             :                         /* update it */
+     128           0 :                         free(link->linkto);
+     129           0 :                         link->linkto = strdup_nofail(linkto);
+     130           0 :                         link_flag_let(link, link_flag, FILE_IS_LINK_MASK);
+     131             :                 }
+     132             : 
+     133             :                 /* nothing more to do */
+     134       61275 :                 return;
+     135             :         } else {
+     136             :                 /* create the new link */
+     137        2457 :                 ++scan->count_insert;
+     138             : 
+     139        2457 :                 log_tag("scan:add:%s:%s\n", disk->name, esc(sub));
+     140        2457 :                 if (is_diff) {
+     141         598 :                         printf("add %s%s\n", disk->dir, sub);
+     142             :                 }
+     143             : 
+     144             :                 /* and continue to insert it */
+     145             :         }
+     146             : 
+     147             :         /* insert it */
+     148        2457 :         link = link_alloc(sub, linkto, link_flag);
+     149             : 
+     150             :         /* mark it as present */
+     151        2457 :         link_flag_set(link, FILE_IS_PRESENT);
+     152             : 
+     153             :         /* insert it in the delayed insert list */
+     154        2457 :         tommy_list_insert_tail(&scan->link_insert_list, &link->nodelist, link);
+     155             : }
+     156             : 
+     157             : /**
+     158             :  * Removes the specified file from the parity.
+     159             :  */
+     160       55207 : static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_file* file)
+     161             : {
+     162       55207 :         struct snapraid_state* state = scan->state;
+     163       55207 :         struct snapraid_disk* disk = scan->disk;
+     164             : 
+     165             :         block_off_t i;
+     166             : 
+     167             :         /* state changed */
+     168       55207 :         state->need_write = 1;
+     169             : 
+     170             :         /* free all the blocks of the file */
+     171      191141 :         for (i = 0; i < file->blockmax; ++i) {
+     172      135934 :                 struct snapraid_block* block = &file->blockvec[i];
+     173      135934 :                 block_off_t block_pos = block->parity_pos;
+     174             :                 unsigned block_state;
+     175             :                 struct snapraid_deleted* deleted;
+     176             : 
+     177             :                 /* adjust the first free position */
+     178             :                 /* note that doing all the deletions before alllocations, */
+     179             :                 /* first_free_block is always 0 and the "if" is never triggered */
+     180             :                 /* but we keep this code anyway for completeness. */
+     181      135934 :                 if (disk->first_free_block > block_pos)
+     182           0 :                         disk->first_free_block = block_pos;
+     183             : 
+     184             :                 /* allocated a new deleted block from the block we are going to delete */
+     185      135934 :                 deleted = deleted_dup(block);
+     186             : 
+     187             :                 /* in case we scan after an aborted sync, */
+     188             :                 /* we could get also intermediate states */
+     189      135934 :                 block_state = block_state_get(block);
+     190      135934 :                 switch (block_state) {
+     191             :                 case BLOCK_STATE_BLK :
+     192             :                         /* we keep the hash making it an "old" hash, because the parity is still containing data for it */
+     193       31139 :                         break;
+     194             :                 case BLOCK_STATE_CHG :
+     195             :                         /* if we have not already cleared the past hash */
+     196       57633 :                         if (!state->clear_past_hash) {
+     197             :                                 /* in these cases we don't know if the old state is still the one */
+     198             :                                 /* stored inside the parity, because after an aborted sync, the parity */
+     199             :                                 /* may be or may be not have been updated with the data that it's now */
+     200             :                                 /* deleted. Then we reset the hash to a bogus value. */
+     201             :                                 /* For example: */
+     202             :                                 /* - One file is added */
+     203             :                                 /* - Sync aborted after updating the parity to the new state, */
+     204             :                                 /*   but without saving the content file representing this new state. */
+     205             :                                 /* - File is now deleted after the aborted sync */
+     206             :                                 /* - Sync again, deleting the blocks (exactly here) */
+     207             :                                 /*   with the hash of CHG block not represeting the real parity state */
+     208           0 :                                 hash_invalid_set(deleted->block.hash);
+     209             :                         }
+     210       57633 :                         break;
+     211             :                 case BLOCK_STATE_REP :
+     212             :                         /* we just don't know the old hash, and then we set it to invalid */
+     213       47162 :                         hash_invalid_set(deleted->block.hash);
+     214       47162 :                         break;
+     215             :                 default :
+     216             :                         /* LCOV_EXCL_START */
+     217             :                         log_fatal("Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state);
+     218             :                         exit(EXIT_FAILURE);
+     219             :                         /* LCOV_EXCL_STOP */
+     220             :                 }
+     221             : 
+     222             :                 /* insert it in the list of deleted blocks */
+     223      135934 :                 tommy_list_insert_tail(&disk->deletedlist, &deleted->node, deleted);
+     224             : 
+     225             :                 /* set the deleted block in the block array */
+     226      135934 :                 tommy_arrayblk_set(&disk->blockarr, block_pos, &deleted->block);
+     227             :         }
+     228       55207 : }
+     229             : 
+     230             : /**
+     231             :  * Checks if a file is completely formed of blocks with invalid parity,
+     232             :  * and no rehash is tagged, and if it has at least one block.
+     233             :  */
+     234      897263 : static int file_is_full_invalid_parity_and_stable(struct snapraid_state* state, struct snapraid_file* file)
+     235             : {
+     236             :         block_off_t i;
+     237             : 
+     238             :         /* with no block, it never has an invalid parity */
+     239      897263 :         if (file->blockmax == 0)
+     240        1187 :                 return 0;
+     241             : 
+     242             :         /* check all blocks */
+     243      951882 :         for (i = 0; i < file->blockmax; ++i) {
+     244      929217 :                 struct snapraid_block* block = &file->blockvec[i];
+     245             :                 snapraid_info info;
+     246             : 
+     247             :                 /* exclude blocks with parity */
+     248      929217 :                 if (!block_has_invalid_parity(block))
+     249      873411 :                         return 0;
+     250             : 
+     251             :                 /* get block specific info */
+     252       55806 :                 info = info_get(&state->infoarr, block->parity_pos);
+     253             : 
+     254             :                 /* if rehash fails */
+     255       55806 :                 if (info_get_rehash(info))
+     256           0 :                         return 0;
+     257             :         }
+     258             : 
+     259       22665 :         return 1;
+     260             : }
+     261             : 
+     262             : /**
+     263             :  * Checks if a file is completely formed of blocks with an updated hash,
+     264             :  * and no rehash is tagged, and if it has at least one block.
+     265             :  */
+     266       23658 : static int file_is_full_hashed_and_stable(struct snapraid_state* state, struct snapraid_file* file)
+     267             : {
+     268             :         block_off_t i;
+     269             : 
+     270             :         /* with no block, it never has a hash */
+     271       23658 :         if (file->blockmax == 0)
+     272          27 :                 return 0;
+     273             : 
+     274             :         /* check all blocks */
+     275       42139 :         for (i = 0; i < file->blockmax; ++i) {
+     276       35994 :                 struct snapraid_block* block = &file->blockvec[i];
+     277             :                 snapraid_info info;
+     278             : 
+     279             :                 /* exclude blocks without hash */
+     280       35994 :                 if (!block_has_updated_hash(block))
+     281        1702 :                         return 0;
+     282             : 
+     283             :                 /* get block specific info */
+     284       34292 :                 info = info_get(&state->infoarr, block->parity_pos);
+     285             : 
+     286             :                 /* exclude blocks needing a rehash */
+     287       34292 :                 if (info_get_rehash(info))
+     288       15784 :                         return 0;
+     289             :         }
+     290             : 
+     291        6145 :         return 1;
+     292             : }
+     293             : 
+     294      100042 : static void scan_file_delayed_insert(struct snapraid_scan* scan, struct snapraid_file* file)
+     295             : {
+     296      100042 :         struct snapraid_state* state = scan->state;
+     297      100042 :         struct snapraid_disk* disk = scan->disk;
+     298             : 
+     299             :         /* if we sort for physical offsets we have to read them for new files */
+     300      100042 :         if (state->opt.force_order == SORT_PHYSICAL
+     301       11430 :                 && file->physical == FILEPHY_UNREAD_OFFSET
+     302             :         ) {
+     303             :                 char path_next[PATH_MAX];
+     304             : 
+     305       11430 :                 pathprint(path_next, sizeof(path_next), "%s%s", disk->dir, file->sub);
+     306             : 
+     307       11430 :                 if (filephy(path_next, file->size, &file->physical) != 0) {
+     308             :                         /* LCOV_EXCL_START */
+     309             :                         log_fatal("Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno));
+     310             :                         exit(EXIT_FAILURE);
+     311             :                         /* LCOV_EXCL_STOP */
+     312             :                 }
+     313             :         }
+     314             : 
+     315      100042 :         tommy_list_insert_tail(&scan->file_insert_list, &file->nodelist, file);
+     316      100042 : }
+     317             : 
+     318             : /**
+     319             :  * Refresh the file info.
+     320             :  *
+     321             :  * This is needed by Windows as the normal way to list directories may report not
+     322             :  * updated info. Only the GetFileInformationByHandle() func, called file-by-file,
+     323             :  * really ensures to return synced info.
+     324             :  *
+     325             :  * If this happens, we read also the physical offset, to avoid to read it later.
+     326             :  */
+     327       77377 : static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struct stat* st, uint64_t* physical)
+     328             : {
+     329             : #if HAVE_LSTAT_SYNC
+     330             :         struct snapraid_state* state = scan->state;
+     331             :         struct snapraid_disk* disk = scan->disk;
+     332             : 
+     333             :         /* if the st_sync is not set, ensure to get synced info */
+     334             :         if (st->st_sync == 0) {
+     335             :                 char path_next[PATH_MAX];
+     336             :                 struct stat synced_st;
+     337             : 
+     338             :                 pathprint(path_next, sizeof(path_next), "%s%s", disk->dir, sub);
+     339             : 
+     340             :                 /* if we sort for physical offsets we have to read them for new files */
+     341             :                 if (state->opt.force_order == SORT_PHYSICAL
+     342             :                         && *physical == FILEPHY_UNREAD_OFFSET
+     343             :                 ) {
+     344             :                         /* do nothing, leave the pointer to read the physical offset */
+     345             :                 } else {
+     346             :                         physical = 0; /* set the pointer to 0 to read nothing */
+     347             :                 }
+     348             : 
+     349             :                 if (lstat_sync(path_next, &synced_st, physical) != 0) {
+     350             :                         /* LCOV_EXCL_START */
+     351             :                         log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno));
+     352             :                         exit(EXIT_FAILURE);
+     353             :                         /* LCOV_EXCL_STOP */
+     354             :                 }
+     355             : 
+     356             :                 if (st->st_mtime != synced_st.st_mtime
+     357             :                         || st->st_mtimensec != synced_st.st_mtimensec
+     358             :                 ) {
+     359             : #ifndef _WIN32
+     360             :                         /*
+     361             :                          * In Windows having different metadata is expected with open files
+     362             :                          * because the metadata in the directory is updated only when the file
+     363             :                          * is closed.
+     364             :                          *
+     365             :                          * See also:
+     366             :                          * Why is the file size reported incorrectly for files that are still being written to?
+     367             :                          * http://blogs.msdn.com/b/oldnewthing/archive/2011/12/26/10251026.aspx
+     368             :                          */
+     369             :                         log_fatal("WARNING! Detected uncached time change for file '%s'\n", sub);
+     370             :                         log_fatal("It's better if you run SnapRAID without other processes running.\n");
+     371             : #endif
+     372             :                         st->st_mtime = synced_st.st_mtime;
+     373             :                         st->st_mtimensec = synced_st.st_mtimensec;
+     374             :                 }
+     375             : 
+     376             :                 if (st->st_size != synced_st.st_size) {
+     377             : #ifndef _WIN32
+     378             :                         log_fatal("WARNING! Detected uncached size change for file '%s'\n", sub);
+     379             :                         log_fatal("It's better if you run SnapRAID without other processes running.\n");
+     380             : #endif
+     381             :                         st->st_size = synced_st.st_size;
+     382             :                 }
+     383             : 
+     384             :                 if (st->st_ino != synced_st.st_ino) {
+     385             :                         log_fatal("DANGER! Detected uncached inode change for file '%s'\n", sub);
+     386             :                         log_fatal("Please ensure to run SnapRAID without other processes running.\n");
+     387             :                         /* at this point, it's too late to change inode */
+     388             :                         /* and having inconsistent inodes may result to internal failures */
+     389             :                         /* so, it's better to abort */
+     390             :                         exit(EXIT_FAILURE);
+     391             :                 }
+     392             :         }
+     393             : #else
+     394             :         (void)scan;
+     395             :         (void)sub;
+     396             :         (void)st;
+     397             :         (void)physical;
+     398             : #endif
+     399       77377 : }
+     400             : 
+     401             : /**
+     402             :  * Keeps the file as it's (or with only a name/inode modification).
+     403             :  *
+     404             :  * If the file is kept, nothing has to be done.
+     405             :  *
+     406             :  * But if a file contains only blocks with invalid parity, it's reallocated to ensure
+     407             :  * to always minimize the space used in the parity.
+     408             :  *
+     409             :  * This could happen after a failed sync, when some other files are deleted,
+     410             :  * and then new ones can be moved backward to fill the hole created.
+     411             :  */
+     412      897263 : static void scan_file_keep(struct snapraid_scan* scan, struct snapraid_file* file)
+     413             : {
+     414      897263 :         struct snapraid_disk* disk = scan->disk;
+     415             : 
+     416             :         /* if the file is full invalid, schedule a reinsert at later stage */
+     417      897263 :         if (file_is_full_invalid_parity_and_stable(scan->state, file)) {
+     418             :                 /* deallocate the file from the parity */
+     419       22665 :                 scan_file_deallocate(scan, file);
+     420             : 
+     421             :                 /* remove the file from the list */
+     422       22665 :                 tommy_list_remove_existing(&disk->filelist, &file->nodelist);
+     423             : 
+     424             :                 /* insert the file in the delayed block allocation */
+     425       22665 :                 scan_file_delayed_insert(scan, file);
+     426             :         }
+     427      897263 : }
+     428             : 
+     429             : /**
+     430             :  * Removes the specified file from the data set.
+     431             :  */
+     432       32542 : static void scan_file_remove(struct snapraid_scan* scan, struct snapraid_file* file)
+     433             : {
+     434       32542 :         struct snapraid_disk* disk = scan->disk;
+     435             : 
+     436             :         /* deallocate the file from the parity */
+     437       32542 :         scan_file_deallocate(scan, file);
+     438             : 
+     439             :         /* remove the file from the file containers */
+     440       32542 :         if (!file_flag_has(file, FILE_IS_WITHOUT_INODE)) {
+     441       32501 :                 tommy_hashdyn_remove_existing(&disk->inodeset, &file->nodeset);
+     442             :         }
+     443       32542 :         tommy_hashdyn_remove_existing(&disk->pathset, &file->pathset);
+     444       32542 :         tommy_hashdyn_remove_existing(&disk->stampset, &file->stampset);
+     445       32542 :         tommy_list_remove_existing(&disk->filelist, &file->nodelist);
+     446             : 
+     447             :         /* deallocate */
+     448       32542 :         file_free(file);
+     449       32542 : }
+     450             : 
+     451             : /**
+     452             :  * Inserts the specified file in the data set.
+     453             :  */
+     454      100042 : static void scan_file_insert(struct snapraid_scan* scan, struct snapraid_file* file)
+     455             : {
+     456      100042 :         struct snapraid_state* state = scan->state;
+     457      100042 :         struct snapraid_disk* disk = scan->disk;
+     458             :         block_off_t i;
+     459             :         block_off_t block_max;
+     460             :         block_off_t block_pos;
+     461             : 
+     462             :         /* state changed */
+     463      100042 :         state->need_write = 1;
+     464             : 
+     465             :         /* allocate the blocks of the file */
+     466      100042 :         block_pos = disk->first_free_block;
+     467      100042 :         block_max = tommy_arrayblk_size(&disk->blockarr);
+     468      346361 :         for (i = 0; i < file->blockmax; ++i) {
+     469             :                 snapraid_info info;
+     470      246319 :                 struct snapraid_block* block = &file->blockvec[i];
+     471             : 
+     472             :                 /* increment the position until the first really free block */
+     473      994796 :                 while (block_pos < block_max && block_has_file(tommy_arrayblk_get(&disk->blockarr, block_pos)))
+     474      502158 :                         ++block_pos;
+     475             : 
+     476             :                 /* if not found, allocate a new one */
+     477      246319 :                 if (block_pos == block_max) {
+     478      155209 :                         ++block_max;
+     479      155209 :                         tommy_arrayblk_grow(&disk->blockarr, block_max);
+     480             :                 }
+     481             : 
+     482             :                 /* set the position */
+     483      246319 :                 block->parity_pos = block_pos;
+     484             : 
+     485             :                 /* get block specific info */
+     486      246319 :                 info = info_get(&state->infoarr, block_pos);
+     487             : 
+     488             :                 /* if the file block already has an updated hash without rehash */
+     489      246319 :                 if (block_has_updated_hash(block) && !info_get_rehash(info)) {
+     490             :                         /* the only possible case is for REP blocks */
+     491       39390 :                         assert(block_state_get(block) == BLOCK_STATE_REP);
+     492             : 
+     493             :                         /* convert to a REP block */
+     494       39390 :                         block_state_set(&file->blockvec[i], BLOCK_STATE_REP);
+     495             : 
+     496             :                         /* and keep the hash as it's */
+     497             :                 } else {
+     498             :                         struct snapraid_block* over_block;
+     499             :                         unsigned block_state;
+     500             : 
+     501             :                         /* convert to a CHG block */
+     502      206929 :                         block_state_set(block, BLOCK_STATE_CHG);
+     503             : 
+     504             :                         /* block to overwrite */
+     505      206929 :                         over_block = tommy_arrayblk_get(&disk->blockarr, block_pos);
+     506             : 
+     507             :                         /* state of the block we are going to overwrite */
+     508      206929 :                         block_state = block_state_get(over_block);
+     509             : 
+     510             :                         /* if the block is an empty one */
+     511      206929 :                         if (block_state == BLOCK_STATE_EMPTY) {
+     512             :                                 /* the block was empty and filled with zeros */
+     513             :                                 /* set the hash to the special ZERO value */
+     514      153240 :                                 hash_zero_set(block->hash);
+     515             :                         } else {
+     516             :                                 /* otherwise it's a DELETED one */
+     517       53689 :                                 assert(block_state == BLOCK_STATE_DELETED);
+     518             : 
+     519             :                                 /* copy the past hash of the block */
+     520       53689 :                                 memcpy(block->hash, over_block->hash, HASH_SIZE);
+     521             : 
+     522             :                                 /* if we have not already cleared the past hash */
+     523       53689 :                                 if (!state->clear_past_hash) {
+     524             :                                         /* in this case we don't know if the old state is still the one */
+     525             :                                         /* stored inside the parity, because after an aborted sync, the parity */
+     526             :                                         /* may be or may be not have been updated with the new data */
+     527             :                                         /* Then we reset the hash to a bogus value */
+     528             :                                         /* For example: */
+     529             :                                         /* - One file is deleted */
+     530             :                                         /* - Sync aborted after, updating the parity to the new state, */
+     531             :                                         /*   but without saving the content file representing this new state. */
+     532             :                                         /* - Another file is added again (exactly here) */
+     533             :                                         /*   with the hash of DELETED block not represeting the real parity state */
+     534         380 :                                         hash_invalid_set(block->hash);
+     535             :                                 }
+     536             :                         }
+     537             :                 }
+     538             : 
+     539             :                 /* store in the disk map, after invalidating all the other blocks */
+     540      246319 :                 tommy_arrayblk_set(&disk->blockarr, block_pos, block);
+     541             : 
+     542             :                 /* set the new free position */
+     543      246319 :                 disk->first_free_block = block_pos + 1;
+     544             :         }
+     545             : 
+     546             :         /* note that the file is already added in the file hashtables */
+     547      100042 :         tommy_list_insert_tail(&disk->filelist, &file->nodelist, file);
+     548      100042 : }
+     549             : 
+     550             : /**
+     551             :  * Processes a file.
+     552             :  */
+     553      974966 : static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, struct stat* st, uint64_t physical)
+     554             : {
+     555      974966 :         struct snapraid_state* state = scan->state;
+     556      974966 :         struct snapraid_disk* disk = scan->disk;
+     557             :         struct snapraid_file* file;
+     558             :         tommy_node* i;
+     559             :         int is_original_file_size_different_than_zero;
+     560             :         int is_file_already_present;
+     561             :         int is_file_reported;
+     562             : 
+     563             :         /*
+     564             :          * If the disk has persistent inodes and UUID, try a search on the past inodes,
+     565             :          * to detect moved files.
+     566             :          *
+     567             :          * For persistent inodes we mean inodes that keep their values when the filesystem
+     568             :          * is unmounted and remounted. This don't always happen.
+     569             :          *
+     570             :          * Cases found are:
+     571             :          * - Linux FUSE with exFAT driver from https://code.google.com/p/exfat/.
+     572             :          *   Inodes are reassigned at every mount restarting from 1 and incrementing.
+     573             :          *   As worse, the exFAT support in FUSE doesn't use subsecond precision in timestamps
+     574             :          *   making inode collision more easy (exFAT by design supports 10ms precision).
+     575             :          * - Linux VFAT kernel (3.2) driver. Inodes are fully reassigned at every mount.
+     576             :          *
+     577             :          * In such cases, to avoid possible random collisions, it's better to disable the moved
+     578             :          * file recognition.
+     579             :          *
+     580             :          * For persistent UUID we mean that it has the same UUID as before.
+     581             :          * Otherwise, if the UUID is changed, likely it's a new recreated filesystem,
+     582             :          * and then the inode have no meaning.
+     583             :          *
+     584             :          * Note that to disable the search by past inode, we do this implicitely
+     585             :          * removing all the past inode before searching for files.
+     586             :          * This ensures that no file is found with a past inode, but at the same time,
+     587             :          * it allows to find new files with the same inode, to identify them as hardlinks.
+     588             :          */
+     589      974966 :         int has_past_inodes = !disk->has_volatile_inodes && !disk->has_different_uuid && !disk->has_unsupported_uuid;
+     590             : 
+     591             :         /* always search with the new inode, in the all new inodes found until now, */
+     592             :         /* with the eventual presence of also the past inodes */
+     593      974966 :         uint64_t inode = st->st_ino;
+     594             : 
+     595      974966 :         file = tommy_hashdyn_search(&disk->inodeset, file_inode_compare_to_arg, &inode, file_inode_hash(inode));
+     596             : 
+     597             :         /* identify moved files with past inodes and hardlinks with the new inodes */
+     598      974966 :         if (file) {
+     599             :                 /* check if the file is not changed */
+     600      811432 :                 if (file->size == st->st_size
+     601      803087 :                         && file->mtime_sec == st->st_mtime
+     602      801536 :                         && (file->mtime_nsec == STAT_NSEC(st)
+     603             :                         /* always accept the stored value if it's STAT_NSEC_INVALID */
+     604             :                         /* it happens when upgrading from an old version of SnapRAID */
+     605             :                         /* not yet supporting the nanosecond field */
+     606           0 :                         || file->mtime_nsec == STAT_NSEC_INVALID
+     607             :                         )
+     608             :                 ) {
+     609             :                         /* check if multiple files have the same inode */
+     610      801536 :                         if (file_flag_has(file, FILE_IS_PRESENT)) {
+     611             : #if HAVE_STRUCT_STAT_ST_NLINK
+     612         326 :                                 if (st->st_nlink <= 1) {
+     613             :                                         /* LCOV_EXCL_START */
+     614             :                                         log_fatal("Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub);
+     615             :                                         exit(EXIT_FAILURE);
+     616             :                                         /* LCOV_EXCL_STOP */
+     617             :                                 }
+     618             : #endif
+     619             :                                 /* it's a hardlink */
+     620         326 :                                 scan_link(scan, is_diff, sub, file->sub, FILE_IS_HARDLINK);
+     621         326 :                                 return;
+     622             :                         }
+     623             : 
+     624             :                         /* mark as present */
+     625      801210 :                         file_flag_set(file, FILE_IS_PRESENT);
+     626             : 
+     627             :                         /* update the nanoseconds mtime only if different */
+     628             :                         /* to avoid unneeded updates */
+     629      801210 :                         if (file->mtime_nsec == STAT_NSEC_INVALID
+     630           0 :                                 && STAT_NSEC(st) != file->mtime_nsec
+     631             :                         ) {
+     632           0 :                                 file->mtime_nsec = STAT_NSEC(st);
+     633             : 
+     634             :                                 /* we have to save the new mtime */
+     635           0 :                                 state->need_write = 1;
+     636             :                         }
+     637             : 
+     638      801210 :                         if (strcmp(file->sub, sub) != 0) {
+     639             :                                 /* if the path is different, it means a moved file with the same inode */
+     640         155 :                                 ++scan->count_move;
+     641             : 
+     642         155 :                                 log_tag("scan:move:%s:%s:%s\n", disk->name, esc(file->sub), esc(sub));
+     643         155 :                                 if (is_diff) {
+     644           0 :                                         printf("move %s%s -> %s%s\n", disk->dir, file->sub, disk->dir, sub);
+     645             :                                 }
+     646             : 
+     647             :                                 /* remove from the name set */
+     648         155 :                                 tommy_hashdyn_remove_existing(&disk->pathset, &file->pathset);
+     649             : 
+     650             :                                 /* save the new name */
+     651         155 :                                 file_rename(file, sub);
+     652             : 
+     653             :                                 /* reinsert in the name set */
+     654         155 :                                 tommy_hashdyn_insert(&disk->pathset, &file->pathset, file, file_path_hash(file->sub));
+     655             : 
+     656             :                                 /* we have to save the new name */
+     657         155 :                                 state->need_write = 1;
+     658             :                         } else {
+     659             :                                 /* otherwise it's equal */
+     660      801055 :                                 ++scan->count_equal;
+     661             : 
+     662      801055 :                                 if (state->opt.gui) {
+     663       22555 :                                         log_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub));
+     664             :                                 }
+     665             :                         }
+     666             : 
+     667             :                         /* mark the file as kept */
+     668      801210 :                         scan_file_keep(scan, file);
+     669             : 
+     670             :                         /* nothing more to do */
+     671      801210 :                         return;
+     672             :                 }
+     673             : 
+     674             :                 /* here the file matches the inode, but not the other info */
+     675             :                 /* if could be a modified file with the same name, */
+     676             :                 /* or a restored/copied file that get assigned a previously used inode, */
+     677             :                 /* or a filesystem with not persistent inodes */
+     678             : 
+     679             :                 /* for sure it cannot be already present */
+     680        9896 :                 if (file_flag_has(file, FILE_IS_PRESENT)) {
+     681             :                         /* LCOV_EXCL_START */
+     682             :                         log_fatal("Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' matching and already present but different\n", file->inode, disk->dir, sub, disk->dir, file->sub);
+     683             :                         exit(EXIT_FAILURE);
+     684             :                         /* LCOV_EXCL_STOP */
+     685             :                 }
+     686             : 
+     687             :                 /* assume a previously used inode, it's the worst case */
+     688             :                 /* and we handle it removing the duplicate stored inode. */
+     689             :                 /* If the file is found by name (not necessarely in this function call), */
+     690             :                 /* it will have the inode restored, otherwise, it will get removed */
+     691             : 
+     692             :                 /* remove from the inode set */
+     693        9896 :                 tommy_hashdyn_remove_existing(&disk->inodeset, &file->nodeset);
+     694             : 
+     695             :                 /* clear the inode */
+     696             :                 /* this is not really needed for correct functionality */
+     697             :                 /* because we are going to set FILE_IS_WITHOUT_INODE */
+     698             :                 /* but it's easier for debugging to have invalid inodes set to 0 */
+     699        9896 :                 file->inode = 0;
+     700             : 
+     701             :                 /* mark as missing inode */
+     702        9896 :                 file_flag_set(file, FILE_IS_WITHOUT_INODE);
+     703             : 
+     704             :                 /* go further to find it by name */
+     705             :         }
+     706             : 
+     707             :         /* initialize for later overwrite */
+     708      173430 :         is_file_reported = 0;
+     709      173430 :         is_original_file_size_different_than_zero = 0;
+     710             : 
+     711             :         /* then try finding it by name */
+     712      173430 :         file = tommy_hashdyn_search(&disk->pathset, file_path_compare_to_arg, sub, file_path_hash(sub));
+     713             : 
+     714             :         /* keep track if the file already exists */
+     715      173430 :         is_file_already_present = file != 0;
+     716             : 
+     717      173430 :         if (is_file_already_present) {
+     718             :                 /* if the file is without an inode */
+     719       98966 :                 if (file_flag_has(file, FILE_IS_WITHOUT_INODE)) {
+     720             :                         /* set it now */
+     721        9855 :                         file->inode = st->st_ino;
+     722             : 
+     723             :                         /* insert in the set */
+     724        9855 :                         tommy_hashdyn_insert(&disk->inodeset, &file->nodeset, file, file_inode_hash(file->inode));
+     725             : 
+     726             :                         /* unmark as missing inode */
+     727        9855 :                         file_flag_clear(file, FILE_IS_WITHOUT_INODE);
+     728             :                 } else {
+     729             :                         /* here the inode has to be different, otherwise we would have found it before */
+     730       89111 :                         if (file->inode == st->st_ino) {
+     731             :                                 /* LCOV_EXCL_START */
+     732             :                                 log_fatal("Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub);
+     733             :                                 exit(EXIT_FAILURE);
+     734             :                                 /* LCOV_EXCL_STOP */
+     735             :                         }
+     736             :                 }
+     737             : 
+     738             :                 /* for sure it cannot be already present */
+     739       98966 :                 if (file_flag_has(file, FILE_IS_PRESENT)) {
+     740             :                         /* LCOV_EXCL_START */
+     741             :                         log_fatal("Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub);
+     742             :                         exit(EXIT_FAILURE);
+     743             :                         /* LCOV_EXCL_STOP */
+     744             :                 }
+     745             : 
+     746             :                 /* check if the file is not changed */
+     747       98966 :                 if (file->size == st->st_size
+     748       98372 :                         && file->mtime_sec == st->st_mtime
+     749       96053 :                         && (file->mtime_nsec == STAT_NSEC(st)
+     750             :                         /* always accept the stored value if it's STAT_NSEC_INVALID */
+     751             :                         /* it happens when upgrading from an old version of SnapRAID */
+     752             :                         /* not yet supporting the nanosecond field */
+     753           0 :                         || file->mtime_nsec == STAT_NSEC_INVALID
+     754             :                         )
+     755             :                 ) {
+     756             :                         /* mark as present */
+     757       96053 :                         file_flag_set(file, FILE_IS_PRESENT);
+     758             : 
+     759             :                         /* update the nano seconds mtime only if different */
+     760             :                         /* to avoid unneeded updates */
+     761       96053 :                         if (file->mtime_nsec == STAT_NSEC_INVALID
+     762           0 :                                 && STAT_NSEC(st) != STAT_NSEC_INVALID
+     763             :                         ) {
+     764           0 :                                 file->mtime_nsec = STAT_NSEC(st);
+     765             : 
+     766             :                                 /* we have to save the new mtime */
+     767           0 :                                 state->need_write = 1;
+     768             :                         }
+     769             : 
+     770             :                         /* if when processing the disk we used the past inodes values */
+     771       96053 :                         if (has_past_inodes) {
+     772             :                                 /* if persistent inodes are supported, we are sure that the inode number */
+     773             :                                 /* is now different, because otherwise the file would have been found */
+     774             :                                 /* when searching by inode. */
+     775             :                                 /* if the inode is different, it means a rewritten file with the same path */
+     776             :                                 /* like when restoring a backup that restores also the timestamp */
+     777       96053 :                                 ++scan->count_restore;
+     778             : 
+     779       96053 :                                 log_tag("scan:restore:%s:%s\n", disk->name, esc(sub));
+     780       96053 :                                 if (is_diff) {
+     781           0 :                                         printf("restore %s%s\n", disk->dir, sub);
+     782             :                                 }
+     783             : 
+     784             :                                 /* remove from the inode set */
+     785       96053 :                                 tommy_hashdyn_remove_existing(&disk->inodeset, &file->nodeset);
+     786             : 
+     787             :                                 /* save the new inode */
+     788       96053 :                                 file->inode = st->st_ino;
+     789             : 
+     790             :                                 /* reinsert in the inode set */
+     791       96053 :                                 tommy_hashdyn_insert(&disk->inodeset, &file->nodeset, file, file_inode_hash(file->inode));
+     792             : 
+     793             :                                 /* we have to save the new inode */
+     794       96053 :                                 state->need_write = 1;
+     795             :                         } else {
+     796             :                                 /* otherwise it's the case of not persistent inode, where doesn't */
+     797             :                                 /* matter if the inode is different or equal, because they have no */
+     798             :                                 /* meaning, and then we don't even save them */
+     799           0 :                                 ++scan->count_equal;
+     800             : 
+     801           0 :                                 if (state->opt.gui) {
+     802           0 :                                         log_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub));
+     803             :                                 }
+     804             :                         }
+     805             : 
+     806             :                         /* mark the file as kept */
+     807       96053 :                         scan_file_keep(scan, file);
+     808             : 
+     809             :                         /* nothing more to do */
+     810       96053 :                         return;
+     811             :                 }
+     812             : 
+     813             :                 /* here if the file is changed but with the correct name */
+     814             : 
+     815             :                 /* keep track if the original file was not of zero size */
+     816        2913 :                 is_original_file_size_different_than_zero = file->size != 0;
+     817             : 
+     818             :                 /* remove it, and continue to insert it again */
+     819        2913 :                 scan_file_remove(scan, file);
+     820             : 
+     821             :                 /* and continue to insert it again */
+     822             :         }
+     823             : 
+     824             :         /* refresh the info, to ensure that they are synced, */
+     825             :         /* note that we refresh only the info of the new or modified files */
+     826             :         /* because this is slow operation */
+     827       77377 :         scan_file_refresh(scan, sub, st, &physical);
+     828             : 
+     829             :         /* do a safety check to ensure that the common ext4 case of zeroing */
+     830             :         /* the size of a file after a crash doesn't propagate to the backup */
+     831       77377 :         if (is_original_file_size_different_than_zero && st->st_size == 0) {
+     832           0 :                 if (!state->opt.force_zero) {
+     833             :                         /* LCOV_EXCL_START */
+     834             :                         log_fatal("The file '%s%s' has unexpected zero size!\n", disk->dir, sub);
+     835             :                         log_fatal("It's possible that after a kernel crash this file was lost,\n");
+     836             :                         log_fatal("and you can use 'snapraid --filter %s fix' to recover it.\n", sub);
+     837             :                         if (!is_diff) {
+     838             :                                 log_fatal("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command);
+     839             :                                 exit(EXIT_FAILURE);
+     840             :                         }
+     841             :                         /* LCOV_EXCL_STOP */
+     842             :                 }
+     843             :         }
+     844             : 
+     845             :         /* insert it */
+     846       77377 :         file = file_alloc(state->block_size, sub, st->st_size, st->st_mtime, STAT_NSEC(st), st->st_ino, physical);
+     847             : 
+     848             :         /* mark it as present */
+     849       77377 :         file_flag_set(file, FILE_IS_PRESENT);
+     850             : 
+     851             :         /* if copy detection is enabled */
+     852             :         /* note that the copy detection is tried also for updated files */
+     853             :         /* this makes sense because it may happen to have two different copies */
+     854             :         /* of the same file, and we move the right one over the wrong one */
+     855             :         /* in such case we have a "copy" over an "update" */
+     856       77377 :         if (!state->opt.force_nocopy) {
+     857       77377 :                 tommy_uint32_t hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec);
+     858             : 
+     859             :                 /* search for a file with the same name and stamp in all the disks */
+     860      506296 :                 for (i = state->disklist; i != 0; i = i->next) {
+     861      435064 :                         struct snapraid_disk* other_disk = i->data;
+     862             :                         struct snapraid_file* other_file;
+     863             : 
+     864             :                         /* if the nanosecond part of the time stamp is valid, search */
+     865             :                         /* for name and stamp, otherwise for path and stamp */
+     866      435064 :                         if (file->mtime_nsec != 0 && file->mtime_nsec != STAT_NSEC_INVALID)
+     867      434956 :                                 other_file = tommy_hashdyn_search(&other_disk->stampset, file_namestamp_compare, file, hash);
+     868             :                         else
+     869         108 :                                 other_file = tommy_hashdyn_search(&other_disk->stampset, file_pathstamp_compare, file, hash);
+     870             : 
+     871             :                         /* if found, and it's a fully hashed file */
+     872      435064 :                         if (other_file && file_is_full_hashed_and_stable(scan->state, other_file)) {
+     873             :                                 /* assume that the file is a copy, and reuse the hash */
+     874        6145 :                                 file_copy(other_file, file);
+     875             : 
+     876             :                                 /* revert old counter and use the copy one */
+     877        6145 :                                 ++scan->count_copy;
+     878             : 
+     879        6145 :                                 log_tag("scan:copy:%s:%s:%s:%s\n", other_disk->name, esc(other_file->sub), disk->name, esc(file->sub));
+     880        6145 :                                 if (is_diff) {
+     881          31 :                                         printf("copy %s%s -> %s%s\n", other_disk->dir, other_file->sub, disk->dir, file->sub);
+     882             :                                 }
+     883             : 
+     884             :                                 /* mark it as reported */
+     885        6145 :                                 is_file_reported = 1;
+     886             : 
+     887             :                                 /* no need to continue the search */
+     888        6145 :                                 break;
+     889             :                         }
+     890             :                 }
+     891             :         }
+     892             : 
+     893             :         /* if not yet reported, do it now */
+     894       77377 :         if (!is_file_reported) {
+     895       71232 :                 if (is_file_already_present) {
+     896        2913 :                         ++scan->count_change;
+     897             : 
+     898        2913 :                         log_tag("scan:update:%s:%s\n", disk->name, esc(sub));
+     899        2913 :                         if (is_diff) {
+     900         117 :                                 printf("update %s%s\n", disk->dir, sub);
+     901             :                         }
+     902             :                 } else {
+     903       68319 :                         ++scan->count_insert;
+     904             : 
+     905       68319 :                         log_tag("scan:add:%s:%s\n", disk->name, esc(sub));
+     906       68319 :                         if (is_diff) {
+     907       17043 :                                 printf("add %s%s\n", disk->dir, sub);
+     908             :                         }
+     909             :                 }
+     910             :         }
+     911             : 
+     912             :         /* insert the file in the file hashtables, to allow to find duplicate hardlinks */
+     913       77377 :         tommy_hashdyn_insert(&disk->inodeset, &file->nodeset, file, file_inode_hash(file->inode));
+     914       77377 :         tommy_hashdyn_insert(&disk->pathset, &file->pathset, file, file_path_hash(file->sub));
+     915       77377 :         tommy_hashdyn_insert(&disk->stampset, &file->stampset, file, file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec));
+     916             : 
+     917             :         /* insert the file in the delayed block allocation */
+     918       77377 :         scan_file_delayed_insert(scan, file);
+     919             : }
+     920             : 
+     921             : /**
+     922             :  * Removes the specified dir from the data set.
+     923             :  */
+     924           2 : static void scan_emptydir_remove(struct snapraid_scan* scan, struct snapraid_dir* dir)
+     925             : {
+     926           2 :         struct snapraid_state* state = scan->state;
+     927           2 :         struct snapraid_disk* disk = scan->disk;
+     928             : 
+     929             :         /* state changed */
+     930           2 :         state->need_write = 1;
+     931             : 
+     932             :         /* remove the file from the dir containers */
+     933           2 :         tommy_hashdyn_remove_existing(&disk->dirset, &dir->nodeset);
+     934           2 :         tommy_list_remove_existing(&disk->dirlist, &dir->nodelist);
+     935             : 
+     936             :         /* deallocate */
+     937           2 :         dir_free(dir);
+     938           2 : }
+     939             : 
+     940             : /**
+     941             :  * Inserts the specified dir in the data set.
+     942             :  */
+     943          10 : static void scan_emptydir_insert(struct snapraid_scan* scan, struct snapraid_dir* dir)
+     944             : {
+     945          10 :         struct snapraid_state* state = scan->state;
+     946          10 :         struct snapraid_disk* disk = scan->disk;
+     947             : 
+     948             :         /* state changed */
+     949          10 :         state->need_write = 1;
+     950             : 
+     951             :         /* insert the dir in the dir containers */
+     952          10 :         tommy_hashdyn_insert(&disk->dirset, &dir->nodeset, dir, dir_name_hash(dir->sub));
+     953          10 :         tommy_list_insert_tail(&disk->dirlist, &dir->nodelist, dir);
+     954          10 : }
+     955             : 
+     956             : /**
+     957             :  * Processes a dir.
+     958             :  */
+     959         219 : static void scan_emptydir(struct snapraid_scan* scan, const char* sub)
+     960             : {
+     961         219 :         struct snapraid_disk* disk = scan->disk;
+     962             :         struct snapraid_dir* dir;
+     963             : 
+     964             :         /* check if the dir already exists */
+     965         219 :         dir = tommy_hashdyn_search(&disk->dirset, dir_name_compare, sub, dir_name_hash(sub));
+     966         219 :         if (dir) {
+     967             :                 /* check if multiple files have the same name */
+     968         209 :                 if (dir_flag_has(dir, FILE_IS_PRESENT)) {
+     969             :                         /* LCOV_EXCL_START */
+     970             :                         log_fatal("Internal inconsistency for dir '%s%s'\n", disk->dir, sub);
+     971             :                         exit(EXIT_FAILURE);
+     972             :                         /* LCOV_EXCL_STOP */
+     973             :                 }
+     974             : 
+     975             :                 /* mark as present */
+     976         209 :                 dir_flag_set(dir, FILE_IS_PRESENT);
+     977             : 
+     978             :                 /* nothing more to do */
+     979         428 :                 return;
+     980             :         } else {
+     981             :                 /* and continue to insert it */
+     982             :         }
+     983             : 
+     984             :         /* insert it */
+     985          10 :         dir = dir_alloc(sub);
+     986             : 
+     987             :         /* mark it as present */
+     988          10 :         dir_flag_set(dir, FILE_IS_PRESENT);
+     989             : 
+     990             :         /* insert it in the delayed insert list */
+     991          10 :         tommy_list_insert_tail(&scan->dir_insert_list, &dir->nodelist, dir);
+     992             : }
+     993             : 
+     994             : struct dirent_sorted {
+     995             :         /* node for data structures */
+     996             :         tommy_node node;
+     997             : 
+     998             : #if HAVE_STRUCT_DIRENT_D_INO
+     999             :         uint64_t d_ino; /**< Inode number. */
+    1000             : #endif
+    1001             : #if HAVE_STRUCT_DIRENT_D_TYPE
+    1002             :         uint32_t d_type; /**< File type. */
+    1003             : #endif
+    1004             : #if HAVE_STRUCT_DIRENT_D_STAT
+    1005             :         struct stat d_stat; /**< Stat result. */
+    1006             : #endif
+    1007             :         char d_name[]; /**< Variable length name. It must be the last field. */
+    1008             : };
+    1009             : 
+    1010             : #if HAVE_STRUCT_DIRENT_D_INO
+    1011      103300 : static int dd_ino_compare(const void* void_a, const void* void_b)
+    1012             : {
+    1013      103300 :         const struct dirent_sorted* a = void_a;
+    1014      103300 :         const struct dirent_sorted* b = void_b;
+    1015             : 
+    1016      103300 :         if (a->d_ino < b->d_ino)
+    1017       49394 :                 return -1;
+    1018       53906 :         if (a->d_ino > b->d_ino)
+    1019       53906 :                 return 1;
+    1020             : 
+    1021           0 :         return 0;
+    1022             : }
+    1023             : #endif
+    1024             : 
+    1025    10206597 : static int dd_name_compare(const void* void_a, const void* void_b)
+    1026             : {
+    1027    10206597 :         const struct dirent_sorted* a = void_a;
+    1028    10206597 :         const struct dirent_sorted* b = void_b;
+    1029             : 
+    1030    10206597 :         return strcmp(a->d_name, b->d_name);
+    1031             : }
+    1032             : 
+    1033             : /**
+    1034             :  * Returns the stat info of a dir entry.
+    1035             :  */
+    1036             : #if HAVE_STRUCT_DIRENT_D_STAT
+    1037             : #define DSTAT(file, dd, buf) dstat(dd)
+    1038             : struct stat* dstat(struct dirent_sorted* dd)
+    1039             : {
+    1040             :         return &dd->d_stat;
+    1041             : }
+    1042             : #else
+    1043             : #define DSTAT(file, dd, buf) dstat(file, buf)
+    1044      976055 : struct stat* dstat(const char* file, struct stat* st)
+    1045             : {
+    1046      976055 :         if (lstat(file, st) != 0) {
+    1047             :                 /* LCOV_EXCL_START */
+    1048             :                 log_fatal("Error in stat file/directory '%s'. %s.\n", file, strerror(errno));
+    1049             :                 exit(EXIT_FAILURE);
+    1050             :                 /* LCOV_EXCL_STOP */
+    1051             :         }
+    1052      976055 :         return st;
+    1053             : }
+    1054             : #endif
+    1055             : 
+    1056             : /**
+    1057             :  * Processes a directory.
+    1058             :  * Return != 0 if at least one file or link is processed.
+    1059             :  */
+    1060        1502 : static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, const char* sub)
+    1061             : {
+    1062        1502 :         struct snapraid_state* state = scan->state;
+    1063        1502 :         struct snapraid_disk* disk = scan->disk;
+    1064        1502 :         int processed = 0;
+    1065             :         DIR* d;
+    1066             :         tommy_list list;
+    1067             :         tommy_node* node;
+    1068             : 
+    1069        1502 :         tommy_list_init(&list);
+    1070             : 
+    1071        1502 :         d = opendir(dir);
+    1072        1502 :         if (!d) {
+    1073             :                 /* LCOV_EXCL_START */
+    1074             :                 log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno));
+    1075             :                 log_fatal("You can exclude it in the config file with:\n\texclude /%s\n", sub);
+    1076             :                 exit(EXIT_FAILURE);
+    1077             :                 /* LCOV_EXCL_STOP */
+    1078             :         }
+    1079             : 
+    1080             :         /* read the full directory */
+    1081             :         while (1) {
+    1082             :                 char path_next[PATH_MAX];
+    1083             :                 char sub_next[PATH_MAX];
+    1084             :                 struct dirent_sorted* entry;
+    1085             :                 const char* name;
+    1086             :                 struct dirent* dd;
+    1087             :                 size_t name_len;
+    1088             : 
+    1089             :                 /* clear errno to detect erroneous conditions */
+    1090     1012101 :                 errno = 0;
+    1091     1012101 :                 dd = readdir(d);
+    1092     1012101 :                 if (dd == 0 && errno != 0) {
+    1093             :                         /* LCOV_EXCL_START */
+    1094             :                         log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno));
+    1095             :                         log_fatal("You can exclude it in the config file with:\n\texclude /%s\n", sub);
+    1096             :                         exit(EXIT_FAILURE);
+    1097             :                         /* LCOV_EXCL_STOP */
+    1098             :                 }
+    1099     1012101 :                 if (dd == 0) {
+    1100        1502 :                         break; /* finished */
+    1101             :                 }
+    1102             : 
+    1103             :                 /* skip "." and ".." files */
+    1104     1010599 :                 name = dd->d_name;
+    1105     1010599 :                 if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
+    1106        6008 :                         continue;
+    1107             : 
+    1108     1007595 :                 pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
+    1109     1007595 :                 pathprint(sub_next, sizeof(sub_next), "%s%s", sub, name);
+    1110             : 
+    1111             :                 /* check for not supported file names */
+    1112     1007595 :                 if (name[0] == 0) {
+    1113             :                         /* LCOV_EXCL_START */
+    1114             :                         log_fatal("Unsupported name '%s' in file '%s'.\n", name, path_next);
+    1115             :                         exit(EXIT_FAILURE);
+    1116             :                         /* LCOV_EXCL_STOP */
+    1117             :                 }
+    1118             : 
+    1119             :                 /* exclude hidden files even before calling lstat() */
+    1120     1007595 :                 if (filter_hidden(state->filter_hidden, dd) != 0) {
+    1121           0 :                         msg_verbose("Excluding hidden '%s'\n", path_next);
+    1122           0 :                         continue;
+    1123             :                 }
+    1124             : 
+    1125             :                 /* exclude content files even before calling lstat() */
+    1126     1007595 :                 if (filter_content(&state->contentlist, path_next) != 0) {
+    1127           0 :                         msg_verbose("Excluding content '%s'\n", path_next);
+    1128           0 :                         continue;
+    1129             :                 }
+    1130             : 
+    1131     1007595 :                 name_len = strlen(dd->d_name);
+    1132     1007595 :                 entry = malloc_nofail(sizeof(struct dirent_sorted) + name_len + 1);
+    1133             : 
+    1134             :                 /* copy the dir entry */
+    1135             : #if HAVE_STRUCT_DIRENT_D_INO
+    1136     1007595 :                 entry->d_ino = dd->d_ino;
+    1137             : #endif
+    1138             : #if HAVE_STRUCT_DIRENT_D_TYPE
+    1139     1007595 :                 entry->d_type = dd->d_type;
+    1140             : #endif
+    1141             : #if HAVE_STRUCT_DIRENT_D_STAT
+    1142             :                 /* convert dirent to lstat result */
+    1143             :                 dirent_lstat(dd, &entry->d_stat);
+    1144             : 
+    1145             :                 /* note that at this point the st_mode may be 0 */
+    1146             : #endif
+    1147     1007595 :                 memcpy(entry->d_name, dd->d_name, name_len + 1);
+    1148             : 
+    1149             :                 /* insert in the list */
+    1150     1007595 :                 tommy_list_insert_tail(&list, &entry->node, entry);
+    1151     1010599 :         }
+    1152             : 
+    1153        1502 :         if (closedir(d) != 0) {
+    1154             :                 /* LCOV_EXCL_START */
+    1155             :                 log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno));
+    1156             :                 exit(EXIT_FAILURE);
+    1157             :                 /* LCOV_EXCL_STOP */
+    1158             :         }
+    1159             : 
+    1160        1502 :         if (state->opt.force_order == SORT_ALPHA) {
+    1161             :                 /* if requested sort alphabetically */
+    1162             :                 /* this is mainly done for testing to ensure to always */
+    1163             :                 /* process in the same way in different platforms */
+    1164        1466 :                 tommy_list_sort(&list, dd_name_compare);
+    1165             :         }
+    1166             : #if HAVE_STRUCT_DIRENT_D_INO
+    1167          36 :         else if (!disk->has_volatile_inodes) {
+    1168             :                 /* if inodes are persistent */
+    1169             :                 /* sort the list of dir entries by inodes */
+    1170          36 :                 tommy_list_sort(&list, dd_ino_compare);
+    1171             :         }
+    1172             :         /* otherwise just keep the insertion order */
+    1173             : #endif
+    1174             : 
+    1175             :         /* process the sorted dir entries */
+    1176        1502 :         node = list;
+    1177     1010599 :         while (node != 0) {
+    1178             :                 char path_next[PATH_MAX];
+    1179             :                 char sub_next[PATH_MAX];
+    1180             :                 char out[PATH_MAX];
+    1181     1007595 :                 struct snapraid_filter* reason = 0;
+    1182     1007595 :                 struct dirent_sorted* dd = node->data;
+    1183     1007595 :                 const char* name = dd->d_name;
+    1184             :                 struct stat* st;
+    1185             :                 int type;
+    1186             : #if !HAVE_STRUCT_DIRENT_D_STAT
+    1187             :                 struct stat st_buf;
+    1188             : #endif
+    1189             : 
+    1190     1007595 :                 pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
+    1191     1007595 :                 pathprint(sub_next, sizeof(sub_next), "%s%s", sub, name);
+    1192             : 
+    1193             :                 /* start with an unknown type */
+    1194     1007595 :                 type = -1;
+    1195     1007595 :                 st = 0;
+    1196             : 
+    1197             :                 /* if dirent has the type, use it */
+    1198             : #if HAVE_STRUCT_DIRENT_D_TYPE
+    1199     1007595 :                 switch (dd->d_type) {
+    1200           0 :                 case DT_UNKNOWN : break;
+    1201      974966 :                 case DT_REG : type = 0; break;
+    1202       31540 :                 case DT_LNK : type = 1; break;
+    1203        1089 :                 case DT_DIR : type = 2; break;
+    1204           0 :                 default : type = 3; break;
+    1205             :                 }
+    1206             : #endif
+    1207             : 
+    1208             :                 /* if type is still unknown */
+    1209     1007595 :                 if (type < 0) {
+    1210             :                         /* get the type from stat */
+    1211           0 :                         st = DSTAT(path_next, dd, &st_buf);
+    1212             : 
+    1213             : #if HAVE_STRUCT_DIRENT_D_STAT
+    1214             :                         /* if the st_mode field is missing, takes care to fill it using normal lstat() */
+    1215             :                         /* at now this can happen only in Windows (with HAVE_STRUCT_DIRENT_D_STAT defined), */
+    1216             :                         /* because we use a directory reading method that doesn't read info about ReparsePoint. */
+    1217             :                         /* Note that here we cannot call here lstat_sync(), because we don't know what kind */
+    1218             :                         /* of file is it, and lstat_sync() doesn't always work */
+    1219             :                         if (st->st_mode == 0) {
+    1220             :                                 if (lstat(path_next, st) != 0) {
+    1221             :                                         /* LCOV_EXCL_START */
+    1222             :                                         log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+    1223             :                                         exit(EXIT_FAILURE);
+    1224             :                                         /* LCOV_EXCL_STOP */
+    1225             :                                 }
+    1226             :                         }
+    1227             : #endif
+    1228             : 
+    1229           0 :                         if (S_ISREG(st->st_mode))
+    1230           0 :                                 type = 0;
+    1231           0 :                         else if (S_ISLNK(st->st_mode))
+    1232           0 :                                 type = 1;
+    1233           0 :                         else if (S_ISDIR(st->st_mode))
+    1234           0 :                                 type = 2;
+    1235             :                         else
+    1236           0 :                                 type = 3;
+    1237             :                 }
+    1238             : 
+    1239     1007595 :                 if (type == 0) { /* REG */
+    1240      974966 :                         if (filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+    1241             : 
+    1242             :                                 /* late stat, if not yet called */
+    1243      974966 :                                 if (!st)
+    1244      974966 :                                         st = DSTAT(path_next, dd, &st_buf);
+    1245             : 
+    1246             : #if HAVE_LSTAT_SYNC
+    1247             :                                 /* if the st_ino field is missing, takes care to fill it using the extended lstat() */
+    1248             :                                 /* this can happen only in Windows */
+    1249             :                                 if (st->st_ino == 0) {
+    1250             :                                         if (lstat_sync(path_next, st, 0) != 0) {
+    1251             :                                                 /* LCOV_EXCL_START */
+    1252             :                                                 log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno));
+    1253             :                                                 exit(EXIT_FAILURE);
+    1254             :                                                 /* LCOV_EXCL_STOP */
+    1255             :                                         }
+    1256             :                                 }
+    1257             : #endif
+    1258             : 
+    1259      974966 :                                 scan_file(scan, is_diff, sub_next, st, FILEPHY_UNREAD_OFFSET);
+    1260      974966 :                                 processed = 1;
+    1261             :                         } else {
+    1262           0 :                                 msg_verbose("Excluding file '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+    1263             :                         }
+    1264       32629 :                 } else if (type == 1) { /* LNK */
+    1265       31540 :                         if (filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+    1266             :                                 char subnew[PATH_MAX];
+    1267             :                                 int ret;
+    1268             : 
+    1269       31540 :                                 ret = readlink(path_next, subnew, sizeof(subnew));
+    1270       31540 :                                 if (ret >= PATH_MAX) {
+    1271             :                                         /* LCOV_EXCL_START */
+    1272             :                                         log_fatal("Error in readlink file '%s'. Symlink too long.\n", path_next);
+    1273             :                                         exit(EXIT_FAILURE);
+    1274             :                                         /* LCOV_EXCL_STOP */
+    1275             :                                 }
+    1276       31540 :                                 if (ret < 0) {
+    1277             :                                         /* LCOV_EXCL_START */
+    1278             :                                         log_fatal("Error in readlink file '%s'. %s.\n", path_next, strerror(errno));
+    1279             :                                         exit(EXIT_FAILURE);
+    1280             :                                         /* LCOV_EXCL_STOP */
+    1281             :                                 }
+    1282             : 
+    1283             :                                 /* readlink doesn't put the final 0 */
+    1284       31540 :                                 subnew[ret] = 0;
+    1285             : 
+    1286             :                                 /* process as a symbolic link */
+    1287       31540 :                                 scan_link(scan, is_diff, sub_next, subnew, FILE_IS_SYMLINK);
+    1288       31540 :                                 processed = 1;
+    1289             :                         } else {
+    1290           0 :                                 msg_verbose("Excluding link '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+    1291             :                         }
+    1292        1089 :                 } else if (type == 2) { /* DIR */
+    1293        1089 :                         if (filter_dir(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+    1294             : #ifndef _WIN32
+    1295             :                                 /* late stat, if not yet called */
+    1296        1089 :                                 if (!st)
+    1297        1089 :                                         st = DSTAT(path_next, dd, &st_buf);
+    1298             : 
+    1299             :                                 /* in Unix don't follow mount points in different devices */
+    1300             :                                 /* in Windows we are already skipping them reporting them as special files */
+    1301        1089 :                                 if ((uint64_t)st->st_dev != disk->device) {
+    1302           0 :                                         log_fatal("WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next);
+    1303             :                                 } else
+    1304             : #endif
+    1305             :                                 {
+    1306             :                                         char sub_dir[PATH_MAX];
+    1307             : 
+    1308             :                                         /* recurse */
+    1309        1089 :                                         pathslash(path_next, sizeof(path_next));
+    1310        1089 :                                         pathcpy(sub_dir, sizeof(sub_dir), sub_next);
+    1311        1089 :                                         pathslash(sub_dir, sizeof(sub_dir));
+    1312        1089 :                                         if (scan_dir(scan, is_diff, path_next, sub_dir) == 0) {
+    1313             :                                                 /* scan the directory as empty dir */
+    1314         219 :                                                 scan_emptydir(scan, sub_next);
+    1315             :                                         }
+    1316             :                                         /* or we processed something internally, or we have added the empty dir */
+    1317        1089 :                                         processed = 1;
+    1318             :                                 }
+    1319             :                         } else {
+    1320           0 :                                 msg_verbose("Excluding directory '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+    1321             :                         }
+    1322             :                 } else {
+    1323           0 :                         if (filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+    1324             :                                 /* late stat, if not yet called */
+    1325           0 :                                 if (!st)
+    1326           0 :                                         st = DSTAT(path_next, dd, &st_buf);
+    1327             : 
+    1328           0 :                                 log_fatal("WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next);
+    1329             :                         } else {
+    1330           0 :                                 msg_verbose("Excluding special file '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+    1331             :                         }
+    1332             :                 }
+    1333             : 
+    1334             :                 /* next entry */
+    1335     1007595 :                 node = node->next;
+    1336             : 
+    1337             :                 /* free the present one */
+    1338     1007595 :                 free(dd);
+    1339             :         }
+    1340             : 
+    1341        1502 :         return processed;
+    1342             : }
+    1343             : 
+    1344          69 : static int state_diffscan(struct snapraid_state* state, int is_diff)
+    1345             : {
+    1346             :         tommy_node* i;
+    1347             :         tommy_node* j;
+    1348             :         tommy_list scanlist;
+    1349             :         int done;
+    1350             :         fptr* msg;
+    1351             :         struct snapraid_scan total;
+    1352             :         int no_difference;
+    1353             : 
+    1354          69 :         tommy_list_init(&scanlist);
+    1355             : 
+    1356          69 :         if (is_diff)
+    1357           6 :                 msg_progress("Comparing...\n");
+    1358             : 
+    1359             :         /* first scan all the directory and find new and deleted files */
+    1360         482 :         for (i = state->disklist; i != 0; i = i->next) {
+    1361         413 :                 struct snapraid_disk* disk = i->data;
+    1362             :                 struct snapraid_scan* scan;
+    1363             :                 tommy_node* node;
+    1364             :                 int ret;
+    1365             :                 int has_persistent_inode;
+    1366             : 
+    1367         413 :                 scan = malloc_nofail(sizeof(struct snapraid_scan));
+    1368         413 :                 scan->state = state;
+    1369         413 :                 scan->disk = disk;
+    1370         413 :                 scan->count_equal = 0;
+    1371         413 :                 scan->count_move = 0;
+    1372         413 :                 scan->count_copy = 0;
+    1373         413 :                 scan->count_restore = 0;
+    1374         413 :                 scan->count_change = 0;
+    1375         413 :                 scan->count_remove = 0;
+    1376         413 :                 scan->count_insert = 0;
+    1377         413 :                 tommy_list_init(&scan->file_insert_list);
+    1378         413 :                 tommy_list_init(&scan->link_insert_list);
+    1379         413 :                 tommy_list_init(&scan->dir_insert_list);
+    1380             : 
+    1381         413 :                 tommy_list_insert_tail(&scanlist, &scan->node, scan);
+    1382             : 
+    1383         413 :                 if (!is_diff)
+    1384         377 :                         msg_progress("Scanning disk %s...\n", disk->name);
+    1385             : 
+    1386             :                 /* check if the disk supports persistent inodes */
+    1387         413 :                 ret = fsinfo(disk->dir, &has_persistent_inode, 0, 0);
+    1388         413 :                 if (ret < 0) {
+    1389             :                         /* LCOV_EXCL_START */
+    1390             :                         log_fatal("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno));
+    1391             :                         exit(EXIT_FAILURE);
+    1392             :                         /* LCOV_EXCL_STOP */
+    1393             :                 }
+    1394         413 :                 if (!has_persistent_inode) {
+    1395           0 :                         disk->has_volatile_inodes = 1;
+    1396             :                 }
+    1397             : 
+    1398             :                 /* if inodes or UUID are not persistent/changed/unsupported */
+    1399         413 :                 if (disk->has_volatile_inodes || disk->has_different_uuid || disk->has_unsupported_uuid) {
+    1400             :                         /* removes all the inodes from the inode collection */
+    1401             :                         /* if they are not persistent, all of them could be changed now */
+    1402             :                         /* and we don't want to find false matching ones */
+    1403             :                         /* see scan_file() for more details */
+    1404          37 :                         node = disk->filelist;
+    1405          74 :                         while (node) {
+    1406           0 :                                 struct snapraid_file* file = node->data;
+    1407             : 
+    1408           0 :                                 node = node->next;
+    1409             : 
+    1410             :                                 /* remove from the inode set */
+    1411           0 :                                 tommy_hashdyn_remove_existing(&disk->inodeset, &file->nodeset);
+    1412             : 
+    1413             :                                 /* clear the inode */
+    1414           0 :                                 file->inode = 0;
+    1415             : 
+    1416             :                                 /* mark as missing inode */
+    1417           0 :                                 file_flag_set(file, FILE_IS_WITHOUT_INODE);
+    1418             :                         }
+    1419             :                 }
+    1420             : 
+    1421         413 :                 scan_dir(scan, is_diff, disk->dir, "");
+    1422             :         }
+    1423             : 
+    1424             :         /* we split the search in two phases because to detect files */
+    1425             :         /* moved from one disk to another we have to start deletion */
+    1426             :         /* only when all disks have all the new files found */
+    1427             : 
+    1428             :         /* now process all the new and deleted files */
+    1429         482 :         for (i = scanlist; i != 0; i = i->next) {
+    1430         413 :                 struct snapraid_scan* scan = i->data;
+    1431         413 :                 struct snapraid_disk* disk = scan->disk;
+    1432             :                 tommy_node* node;
+    1433             :                 unsigned phy_count;
+    1434             :                 unsigned phy_dup;
+    1435             :                 uint64_t phy_last;
+    1436             :                 struct snapraid_file* phy_file_last;
+    1437             : 
+    1438             :                 /* check for removed files */
+    1439         413 :                 node = disk->filelist;
+    1440      905053 :                 while (node) {
+    1441      904227 :                         struct snapraid_file* file = node->data;
+    1442             : 
+    1443             :                         /* next node */
+    1444      904227 :                         node = node->next;
+    1445             : 
+    1446             :                         /* remove if not present */
+    1447      904227 :                         if (!file_flag_has(file, FILE_IS_PRESENT)) {
+    1448       29629 :                                 ++scan->count_remove;
+    1449             : 
+    1450       29629 :                                 log_tag("scan:remove:%s:%s\n", disk->name, esc(file->sub));
+    1451       29629 :                                 if (is_diff) {
+    1452          97 :                                         printf("remove %s%s\n", disk->dir, file->sub);
+    1453             :                                 }
+    1454             : 
+    1455       29629 :                                 scan_file_remove(scan, file);
+    1456             :                         }
+    1457             :                 }
+    1458             : 
+    1459             :                 /* check for removed links */
+    1460         413 :                 node = disk->linklist;
+    1461       31191 :                 while (node) {
+    1462       30365 :                         struct snapraid_link* link = node->data;
+    1463             : 
+    1464             :                         /* next node */
+    1465       30365 :                         node = node->next;
+    1466             : 
+    1467             :                         /* remove if not present */
+    1468       30365 :                         if (!link_flag_has(link, FILE_IS_PRESENT)) {
+    1469         956 :                                 ++scan->count_remove;
+    1470             : 
+    1471         956 :                                 log_tag("scan:remove:%s:%s\n", disk->name, esc(link->sub));
+    1472         956 :                                 if (is_diff) {
+    1473           9 :                                         printf("remove %s%s\n", disk->dir, link->sub);
+    1474             :                                 }
+    1475             : 
+    1476         956 :                                 scan_link_remove(scan, link);
+    1477             :                         }
+    1478             :                 }
+    1479             : 
+    1480             :                 /* check for removed dirs */
+    1481         413 :                 node = disk->dirlist;
+    1482        1037 :                 while (node) {
+    1483         211 :                         struct snapraid_dir* dir = node->data;
+    1484             : 
+    1485             :                         /* next node */
+    1486         211 :                         node = node->next;
+    1487             : 
+    1488             :                         /* remove if not present */
+    1489         211 :                         if (!dir_flag_has(dir, FILE_IS_PRESENT)) {
+    1490           2 :                                 scan_emptydir_remove(scan, dir);
+    1491             :                         }
+    1492             :                 }
+    1493             : 
+    1494             :                 /* sort the files before inserting them */
+    1495             :                 /* we use a stable sort to ensure that if the reported physical offset/inode */
+    1496             :                 /* are always 0, we keep at least the directory order */
+    1497         413 :                 switch (state->opt.force_order) {
+    1498             :                 case SORT_PHYSICAL :
+    1499          12 :                         tommy_list_sort(&scan->file_insert_list, file_physical_compare);
+    1500          12 :                         break;
+    1501             :                 case SORT_INODE :
+    1502           0 :                         tommy_list_sort(&scan->file_insert_list, file_inode_compare);
+    1503           0 :                         break;
+    1504             :                 case SORT_ALPHA :
+    1505         401 :                         tommy_list_sort(&scan->file_insert_list, file_path_compare);
+    1506         401 :                         break;
+    1507             :                 case SORT_DIR :
+    1508             :                         /* already in order */
+    1509           0 :                         break;
+    1510             :                 }
+    1511             : 
+    1512             :                 /* insert all the new files, we insert them only after the deletion */
+    1513             :                 /* to reuse the just freed space */
+    1514             :                 /* also check if the physical offset reported are fakes or not */
+    1515         413 :                 node = scan->file_insert_list;
+    1516         413 :                 phy_count = 0;
+    1517         413 :                 phy_dup = 0;
+    1518         413 :                 phy_last = FILEPHY_UNREAD_OFFSET;
+    1519         413 :                 phy_file_last = 0;
+    1520      100868 :                 while (node) {
+    1521      100042 :                         struct snapraid_file* file = node->data;
+    1522             : 
+    1523             :                         /* if the file is not empty, count duplicate physical offsets */
+    1524      100042 :                         if (state->opt.force_order == SORT_PHYSICAL && file->size != 0) {
+    1525       11418 :                                 if (phy_file_last != 0 && file->physical == phy_last
+    1526             :                                         /* files without offset are expected to have duplicates */
+    1527           0 :                                         && phy_last != FILEPHY_WITHOUT_OFFSET
+    1528             :                                 ) {
+    1529             :                                         /* if verbose, prints the list of duplicates real offsets */
+    1530             :                                         /* other cases are for offsets not supported, so we don't need to report them file by file */
+    1531           0 :                                         if (phy_last >= FILEPHY_REAL_OFFSET) {
+    1532           0 :                                                 log_fatal("WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last);
+    1533             :                                         }
+    1534           0 :                                         ++phy_dup;
+    1535             :                                 }
+    1536       11418 :                                 phy_file_last = file;
+    1537       11418 :                                 phy_last = file->physical;
+    1538       11418 :                                 ++phy_count;
+    1539             :                         }
+    1540             : 
+    1541             :                         /* next node */
+    1542      100042 :                         node = node->next;
+    1543             : 
+    1544             :                         /* insert it */
+    1545      100042 :                         scan_file_insert(scan, file);
+    1546             :                 }
+    1547             : 
+    1548             :                 /* mark the disk without reliable physical offset if it has duplicates */
+    1549             :                 /* here it should never happen because we already sorted out hardlinks */
+    1550         413 :                 if (state->opt.force_order == SORT_PHYSICAL && phy_dup > 0) {
+    1551           0 :                         disk->has_unreliable_physical = 1;
+    1552             :                 }
+    1553             : 
+    1554             :                 /* insert all the new links */
+    1555         413 :                 node = scan->link_insert_list;
+    1556        3283 :                 while (node) {
+    1557        2457 :                         struct snapraid_link* link = node->data;
+    1558             : 
+    1559             :                         /* next node */
+    1560        2457 :                         node = node->next;
+    1561             : 
+    1562             :                         /* insert it */
+    1563        2457 :                         scan_link_insert(scan, link);
+    1564             :                 }
+    1565             : 
+    1566             :                 /* insert all the new dirs */
+    1567         413 :                 node = scan->dir_insert_list;
+    1568         836 :                 while (node) {
+    1569          10 :                         struct snapraid_dir* dir = node->data;
+    1570             : 
+    1571             :                         /* next node */
+    1572          10 :                         node = node->next;
+    1573             : 
+    1574             :                         /* insert it */
+    1575          10 :                         scan_emptydir_insert(scan, dir);
+    1576             :                 }
+    1577             :         }
+    1578             : 
+    1579             :         /* checks for disks where all the previously existing files where removed */
+    1580          69 :         if (!state->opt.force_empty) {
+    1581          68 :                 int all_missing = 0;
+    1582          68 :                 int all_rewritten = 0;
+    1583          68 :                 done = 0;
+    1584         475 :                 for (i = state->disklist, j = scanlist; i != 0; i = i->next, j = j->next) {
+    1585         407 :                         struct snapraid_disk* disk = i->data;
+    1586         407 :                         struct snapraid_scan* scan = j->data;
+    1587             : 
+    1588         407 :                         if (scan->count_equal == 0
+    1589          37 :                                 && scan->count_move == 0
+    1590          37 :                                 && scan->count_restore == 0
+    1591          37 :                                 && (scan->count_remove != 0 || scan->count_change != 0)
+    1592             :                         ) {
+    1593           0 :                                 if (!done) {
+    1594           0 :                                         done = 1;
+    1595           0 :                                         log_fatal("WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir);
+    1596             :                                 } else {
+    1597           0 :                                         log_fatal(", disk '%s' at dir '%s'", disk->name, disk->dir);
+    1598             :                                 }
+    1599             : 
+    1600             :                                 /* detect the special condition of all files missing */
+    1601           0 :                                 if (scan->count_change == 0)
+    1602           0 :                                         all_missing = 1;
+    1603             : 
+    1604             :                                 /* detect the special condition of all files rewritten */
+    1605           0 :                                 if (scan->count_remove == 0)
+    1606           0 :                                         all_rewritten = 1;
+    1607             :                         }
+    1608             :                 }
+    1609          68 :                 if (done) {
+    1610           0 :                         log_fatal("\nare now missing or rewritten!\n");
+    1611           0 :                         if (all_rewritten) {
+    1612           0 :                                 log_fatal("This could happen when restoring a disk with a backup\n");
+    1613           0 :                                 log_fatal("program that is not setting correctly the timestamps.\n");
+    1614             :                         }
+    1615           0 :                         if (all_missing) {
+    1616           0 :                                 log_fatal("This could happen when some disks are not mounted\n");
+    1617           0 :                                 log_fatal("in the expected directory.\n");
+    1618             :                         }
+    1619           0 :                         if (!is_diff) {
+    1620           0 :                                 log_fatal("If you want to '%s' anyway, use 'snapraid --force-empty %s'.", state->command, state->command);
+    1621           0 :                                 exit(EXIT_FAILURE);
+    1622             :                         }
+    1623             :                 }
+    1624             :         }
+    1625             : 
+    1626             :         /* checks for disks without the physical offset support */
+    1627          69 :         if (state->opt.force_order == SORT_PHYSICAL) {
+    1628           2 :                 done = 0;
+    1629          14 :                 for (i = state->disklist; i != 0; i = i->next) {
+    1630          12 :                         struct snapraid_disk* disk = i->data;
+    1631             : 
+    1632          12 :                         if (disk->has_unreliable_physical) {
+    1633           0 :                                 if (!done) {
+    1634           0 :                                         done = 1;
+    1635           0 :                                         log_fatal("WARNING! Physical offsets not supported for disk '%s'", disk->name);
+    1636             :                                 } else {
+    1637           0 :                                         log_fatal(", '%s'", disk->name);
+    1638             :                                 }
+    1639             :                         }
+    1640             :                 }
+    1641           2 :                 if (done) {
+    1642           0 :                         log_fatal(". Files order won't be optimal.\n");
+    1643             :                 }
+    1644             :         }
+    1645             : 
+    1646             :         /* checks for disks without persistent inodes */
+    1647          69 :         done = 0;
+    1648         482 :         for (i = state->disklist; i != 0; i = i->next) {
+    1649         413 :                 struct snapraid_disk* disk = i->data;
+    1650             : 
+    1651         413 :                 if (disk->has_volatile_inodes) {
+    1652           0 :                         if (!done) {
+    1653           0 :                                 done = 1;
+    1654           0 :                                 log_fatal("WARNING! Inodes are not persistent for disks: '%s'", disk->name);
+    1655             :                         } else {
+    1656           0 :                                 log_fatal(", '%s'", disk->name);
+    1657             :                         }
+    1658             :                 }
+    1659             :         }
+    1660          69 :         if (done) {
+    1661           0 :                 log_fatal(". Move operations won't be optimal.\n");
+    1662             :         }
+    1663             : 
+    1664             :         /* checks for disks with changed UUID */
+    1665          69 :         done = 0;
+    1666         482 :         for (i = state->disklist; i != 0; i = i->next) {
+    1667         413 :                 struct snapraid_disk* disk = i->data;
+    1668             : 
+    1669             :                 /* don't print the message if the UUID changed because before */
+    1670             :                 /* it was no set. */
+    1671             :                 /* this is the normal condition for an empty disk because it */
+    1672             :                 /* isn't stored */
+    1673         413 :                 if (disk->has_different_uuid && !disk->had_empty_uuid) {
+    1674           0 :                         if (!done) {
+    1675           0 :                                 done = 1;
+    1676           0 :                                 log_fatal("WARNING! UUID is changed for disks: '%s'", disk->name);
+    1677             :                         } else {
+    1678           0 :                                 log_fatal(", '%s'", disk->name);
+    1679             :                         }
+    1680             :                 }
+    1681             :         }
+    1682          69 :         if (done) {
+    1683           0 :                 log_fatal(". Move operations won't be optimal.\n");
+    1684             :         }
+    1685             : 
+    1686             :         /* checks for disks with unsupported UUID */
+    1687          69 :         done = 0;
+    1688         482 :         for (i = state->disklist; i != 0; i = i->next) {
+    1689         413 :                 struct snapraid_disk* disk = i->data;
+    1690             : 
+    1691         413 :                 if (disk->has_unsupported_uuid) {
+    1692           0 :                         if (!done) {
+    1693           0 :                                 done = 1;
+    1694           0 :                                 log_fatal("WARNING! UUID is unsupported for disks: '%s'", disk->name);
+    1695             :                         } else {
+    1696           0 :                                 log_fatal(", '%s'", disk->name);
+    1697             :                         }
+    1698             :                 }
+    1699             :         }
+    1700          69 :         if (done) {
+    1701           0 :                 log_fatal(". Move operations won't be optimal.\n");
+    1702             :         }
+    1703             : 
+    1704          69 :         total.count_equal = 0;
+    1705          69 :         total.count_move = 0;
+    1706          69 :         total.count_copy = 0;
+    1707          69 :         total.count_restore = 0;
+    1708          69 :         total.count_change = 0;
+    1709          69 :         total.count_remove = 0;
+    1710          69 :         total.count_insert = 0;
+    1711             : 
+    1712         482 :         for (i = scanlist; i != 0; i = i->next) {
+    1713         413 :                 struct snapraid_scan* scan = i->data;
+    1714         413 :                 total.count_equal += scan->count_equal;
+    1715         413 :                 total.count_move += scan->count_move;
+    1716         413 :                 total.count_copy += scan->count_copy;
+    1717         413 :                 total.count_restore += scan->count_restore;
+    1718         413 :                 total.count_change += scan->count_change;
+    1719         413 :                 total.count_remove += scan->count_remove;
+    1720         413 :                 total.count_insert += scan->count_insert;
+    1721             :         }
+    1722             : 
+    1723          69 :         if (is_diff) {
+    1724           6 :                 msg_status("\n");
+    1725           6 :                 msg = msg_status;
+    1726             :         } else {
+    1727          63 :                 msg = msg_verbose;
+    1728             :         }
+    1729             : 
+    1730          69 :         msg("%8u equal\n", total.count_equal);
+    1731          69 :         msg("%8u moved\n", total.count_move);
+    1732          69 :         msg("%8u copied\n", total.count_copy);
+    1733          69 :         msg("%8u restored\n", total.count_restore);
+    1734          69 :         msg("%8u updated\n", total.count_change);
+    1735          69 :         msg("%8u removed\n", total.count_remove);
+    1736          69 :         msg("%8u added\n", total.count_insert);
+    1737             : 
+    1738          69 :         log_tag("summary:equal:%u\n", total.count_equal);
+    1739          69 :         log_tag("summary:moved:%u\n", total.count_move);
+    1740          69 :         log_tag("summary:copied:%u\n", total.count_copy);
+    1741          69 :         log_tag("summary:restored:%u\n", total.count_restore);
+    1742          69 :         log_tag("summary:updated:%u\n", total.count_change);
+    1743          69 :         log_tag("summary:removed:%u\n", total.count_remove);
+    1744          69 :         log_tag("summary:added:%u\n", total.count_insert);
+    1745             : 
+    1746         206 :         no_difference = !total.count_move && !total.count_copy && !total.count_restore
+    1747         109 :                 && !total.count_change && !total.count_remove && !total.count_insert;
+    1748             : 
+    1749          69 :         if (is_diff) {
+    1750           6 :                 if (no_difference) {
+    1751           1 :                         msg_status("No differences\n");
+    1752             :                 } else {
+    1753           5 :                         msg_status("There are differences!\n");
+    1754             :                 }
+    1755             :         }
+    1756             : 
+    1757          69 :         if (no_difference) {
+    1758           7 :                 log_tag("summary:exit:equal\n");
+    1759             :         } else {
+    1760          62 :                 log_tag("summary:exit:diff\n");
+    1761             :         }
+    1762          69 :         log_flush();
+    1763             : 
+    1764          69 :         tommy_list_foreach(&scanlist, (tommy_foreach_func*)free);
+    1765             : 
+    1766          69 :         if (is_diff) {
+    1767             :                 /* check for file difference */
+    1768           6 :                 if (!no_difference)
+    1769           5 :                         return 1;
+    1770             : 
+    1771             :                 /* check also for incomplete "sync" */
+    1772           1 :                 if (parity_is_invalid(state))
+    1773           0 :                         return 1;
+    1774             :         }
+    1775             : 
+    1776          64 :         return 0;
+    1777             : }
+    1778             : 
+    1779           6 : int state_diff(struct snapraid_state* state)
+    1780             : {
+    1781           6 :         return state_diffscan(state, 1);
+    1782             : }
+    1783             : 
+    1784          63 : void state_scan(struct snapraid_state* state)
+    1785             : {
+    1786          63 :         (void)state_diffscan(state, 0); /* ignore return value */
+    1787          63 : }
+    1788             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scrub.c.func-sort-c.html b/cov/cmdline/scrub.c.func-sort-c.html new file mode 100644 index 00000000..cdea3385 --- /dev/null +++ b/cov/cmdline/scrub.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/scrub.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scrub.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:21527677.9 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled93134
state_scrub_process9
state_scrub9
md6
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scrub.c.func.html b/cov/cmdline/scrub.c.func.html new file mode 100644 index 00000000..0f9ca33d --- /dev/null +++ b/cov/cmdline/scrub.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/scrub.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scrub.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:21527677.9 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled93134
md6
state_scrub9
state_scrub_process9
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/scrub.c.gcov.html b/cov/cmdline/scrub.c.gcov.html new file mode 100644 index 00000000..8d821e7b --- /dev/null +++ b/cov/cmdline/scrub.c.gcov.html @@ -0,0 +1,782 @@ + + + + + + + LCOV - lcov.info - cmdline/scrub.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - scrub.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:21527677.9 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : #include "raid/raid.h"
+      26             : 
+      27             : /****************************************************************************/
+      28             : /* scrub */
+      29             : 
+      30             : /**
+      31             :  * Buffer for storing the new hashes.
+      32             :  */
+      33             : struct snapraid_rehash {
+      34             :         unsigned char hash[HASH_SIZE];
+      35             :         struct snapraid_block* block;
+      36             : };
+      37             : 
+      38             : /**
+      39             :  * Check if we have to process the specified block index ::i.
+      40             :  */
+      41       93134 : static int block_is_enabled(struct snapraid_state* state, block_off_t i, time_t timelimit, block_off_t lastlimit, block_off_t* countlast)
+      42             : {
+      43             :         time_t blocktime;
+      44             :         snapraid_info info;
+      45             : 
+      46             :         /* if it's unused */
+      47       93134 :         info = info_get(&state->infoarr, i);
+      48       93134 :         if (info == 0) {
+      49             :                 /* skip it */
+      50           0 :                 return 0;
+      51             :         }
+      52             : 
+      53             :         /* blocks marked as bad are always checked */
+      54       93134 :         if (!info_get_bad(info)) {
+      55             : 
+      56             :                 /* if it's too new */
+      57       89528 :                 blocktime = info_get_time(info);
+      58       89528 :                 if (blocktime > timelimit) {
+      59             :                         /* skip it */
+      60       37584 :                         return 0;
+      61             :                 }
+      62             : 
+      63             :                 /* skip odd blocks, used only for testing */
+      64       51944 :                 if (state->opt.force_scrub_even && (i % 2) != 0) {
+      65             :                         /* skip it */
+      66        9198 :                         return 0;
+      67             :                 }
+      68             : 
+      69             :                 /* if the time is less than the limit, always include */
+      70             :                 /* otherwise, check if we reached the last limit count */
+      71       42746 :                 if (blocktime == timelimit) {
+      72             :                         /* if we reached the count limit */
+      73       20014 :                         if (*countlast >= lastlimit) {
+      74             :                                 /* skip it */
+      75       11882 :                                 return 0;
+      76             :                         }
+      77             : 
+      78        8132 :                         ++*countlast;
+      79             :                 }
+      80             :         }
+      81             : 
+      82       34470 :         return 1;
+      83             : }
+      84             : 
+      85           9 : static int state_scrub_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax, time_t timelimit, block_off_t lastlimit, time_t now)
+      86             : {
+      87             :         struct snapraid_handle* handle;
+      88             :         void* rehandle_alloc;
+      89             :         struct snapraid_rehash* rehandle;
+      90             :         unsigned diskmax;
+      91             :         block_off_t i;
+      92             :         unsigned j;
+      93             :         void* buffer_alloc;
+      94             :         void** buffer;
+      95             :         unsigned buffermax;
+      96             :         data_off_t countsize;
+      97             :         block_off_t countpos;
+      98             :         block_off_t countmax;
+      99             :         block_off_t countlast;
+     100             :         block_off_t autosavedone;
+     101             :         block_off_t autosavelimit;
+     102             :         block_off_t autosavemissing;
+     103             :         int ret;
+     104             :         unsigned error;
+     105             :         unsigned silent_error;
+     106             :         unsigned io_error;
+     107             :         unsigned l;
+     108             : 
+     109             :         /* maps the disks to handles */
+     110           9 :         handle = handle_map(state, &diskmax);
+     111             : 
+     112             :         /* rehash buffers */
+     113           9 :         rehandle = malloc_nofail_align(diskmax * sizeof(struct snapraid_rehash), &rehandle_alloc);
+     114             : 
+     115             :         /* we need disk + 2 for each parity level buffers */
+     116           9 :         buffermax = diskmax + state->level * 2;
+     117             : 
+     118           9 :         buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc);
+     119           9 :         if (!state->opt.skip_self)
+     120           0 :                 mtest_vector(buffermax, state->block_size, buffer);
+     121             : 
+     122           9 :         error = 0;
+     123           9 :         silent_error = 0;
+     124           9 :         io_error = 0;
+     125             : 
+     126             :         /* first count the number of blocks to process */
+     127           9 :         countmax = 0;
+     128           9 :         countlast = 0;
+     129       46576 :         for (i = blockstart; i < blockmax; ++i) {
+     130       46567 :                 if (!block_is_enabled(state, i, timelimit, lastlimit, &countlast))
+     131       29332 :                         continue;
+     132             : 
+     133       17235 :                 ++countmax;
+     134             :         }
+     135             : 
+     136             :         /* compute the autosave size for all disk, even if not read */
+     137             :         /* this makes sense because the speed should be almost the same */
+     138             :         /* if the disks are read in parallel */
+     139           9 :         autosavelimit = state->autosave / (diskmax * state->block_size);
+     140           9 :         autosavemissing = countmax; /* blocks to do */
+     141           9 :         autosavedone = 0; /* blocks done */
+     142             : 
+     143             :         /* drop until now */
+     144           9 :         state_usage_waste(state);
+     145             : 
+     146           9 :         countsize = 0;
+     147           9 :         countpos = 0;
+     148           9 :         countlast = 0;
+     149           9 :         state_progress_begin(state, blockstart, blockmax, countmax);
+     150       46576 :         for (i = blockstart; i < blockmax; ++i) {
+     151             :                 snapraid_info info;
+     152             :                 int error_on_this_block;
+     153             :                 int silent_error_on_this_block;
+     154             :                 int io_error_on_this_block;
+     155             :                 int block_is_unsynced;
+     156             :                 int rehash;
+     157             : 
+     158       46567 :                 if (!block_is_enabled(state, i, timelimit, lastlimit, &countlast))
+     159       29332 :                         continue;
+     160             : 
+     161             :                 /* one more block processed for autosave */
+     162       17235 :                 ++autosavedone;
+     163       17235 :                 --autosavemissing;
+     164             : 
+     165             :                 /* by default process the block, and skip it if something goes wrong */
+     166       17235 :                 error_on_this_block = 0;
+     167       17235 :                 silent_error_on_this_block = 0;
+     168       17235 :                 io_error_on_this_block = 0;
+     169             : 
+     170             :                 /* if all the blocks at this address are synced */
+     171             :                 /* if not, parity is not even checked */
+     172       17235 :                 block_is_unsynced = 0;
+     173             : 
+     174             :                 /* get block specific info */
+     175       17235 :                 info = info_get(&state->infoarr, i);
+     176             : 
+     177             :                 /* if we have to use the old hash */
+     178       17235 :                 rehash = info_get_rehash(info);
+     179             : 
+     180             :                 /* for each disk, process the block */
+     181      120645 :                 for (j = 0; j < diskmax; ++j) {
+     182             :                         int read_size;
+     183             :                         unsigned char hash[HASH_SIZE];
+     184             :                         struct snapraid_block* block;
+     185             :                         int file_is_unsynced;
+     186      103410 :                         struct snapraid_disk* disk = handle[j].disk;
+     187             : 
+     188             :                         /* if the file on this disk is synced */
+     189             :                         /* if not, silent errors are assumed as expected error */
+     190      103410 :                         file_is_unsynced = 0;
+     191             : 
+     192             :                         /* by default no rehash in case of "continue" */
+     193      103410 :                         rehandle[j].block = 0;
+     194             : 
+     195             :                         /* if the disk position is not used */
+     196      103410 :                         if (!disk) {
+     197             :                                 /* use an empty block */
+     198           0 :                                 memset(buffer[j], 0, state->block_size);
+     199        1871 :                                 continue;
+     200             :                         }
+     201             : 
+     202             :                         /* if the block is not used */
+     203      103410 :                         block = disk_block_get(disk, i);
+     204      103410 :                         if (!block_has_file(block)) {
+     205             :                                 /* use an empty block */
+     206         951 :                                 memset(buffer[j], 0, state->block_size);
+     207         951 :                                 continue;
+     208             :                         }
+     209             : 
+     210             :                         /* if the block is unsynced, errors are expected */
+     211      102459 :                         if (block_has_invalid_parity(block)) {
+     212             :                                 /* report that the block and the file are not synced */
+     213           0 :                                 block_is_unsynced = 1;
+     214           0 :                                 file_is_unsynced = 1;
+     215             :                                 /* follow */
+     216             :                         }
+     217             : 
+     218             :                         /* until now is CPU */
+     219      102459 :                         state_usage_cpu(state);
+     220             : 
+     221             :                         /* if the file is different than the current one, close it */
+     222      102459 :                         if (handle[j].file != 0 && handle[j].file != block_file_get(block)) {
+     223             :                                 /* keep a pointer at the file we are going to close for error reporting */
+     224       54520 :                                 struct snapraid_file* file = handle[j].file;
+     225       54520 :                                 ret = handle_close(&handle[j]);
+     226       54520 :                                 if (ret == -1) {
+     227             :                                         /* LCOV_EXCL_START */
+     228             :                                         /* This one is really an unexpected error, because we are only reading */
+     229             :                                         /* and closing a descriptor should never fail */
+     230             :                                         if (errno == EIO) {
+     231             :                                                 log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     232             :                                                 log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to scrub.\n");
+     233             :                                                 log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     234             :                                                 log_fatal("Stopping at block %u\n", i);
+     235             :                                                 ++io_error;
+     236             :                                                 goto bail;
+     237             :                                         }
+     238             : 
+     239             :                                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     240             :                                         log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to scrub.\n");
+     241             :                                         log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     242             :                                         log_fatal("Stopping at block %u\n", i);
+     243             :                                         ++error;
+     244             :                                         goto bail;
+     245             :                                         /* LCOV_EXCL_STOP */
+     246             :                                 }
+     247             :                         }
+     248             : 
+     249      102459 :                         ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0);
+     250      102459 :                         if (ret == -1) {
+     251             :                                 /* file we have tried to open for error reporting */
+     252           0 :                                 struct snapraid_file* file = block_file_get(block);
+     253           0 :                                 if (errno == EIO) {
+     254             :                                         /* LCOV_EXCL_START */
+     255             :                                         log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     256             :                                         log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to scrub.\n");
+     257             :                                         log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     258             :                                         log_fatal("Stopping at block %u\n", i);
+     259             :                                         ++io_error;
+     260             :                                         goto bail;
+     261             :                                         /* LCOV_EXCL_STOP */
+     262             :                                 }
+     263             : 
+     264           0 :                                 log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     265           0 :                                 ++error;
+     266           0 :                                 error_on_this_block = 1;
+     267           0 :                                 continue;
+     268             :                         }
+     269             : 
+     270             :                         /* check if the file is changed */
+     271      102459 :                         if (handle[j].st.st_size != block_file_get(block)->size
+     272      102459 :                                 || handle[j].st.st_mtime != block_file_get(block)->mtime_sec
+     273      102450 :                                 || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec
+     274             :                                 /* don't check the inode to support filesystem without persistent inodes */
+     275             :                         ) {
+     276             :                                 /* report that the block and the file are not synced */
+     277           9 :                                 block_is_unsynced = 1;
+     278           9 :                                 file_is_unsynced = 1;
+     279             :                                 /* follow */
+     280             :                         }
+     281             : 
+     282             :                         /* note that we intentionally don't abort if the file has different attributes */
+     283             :                         /* from the last sync, as we are expected to return errors if running */
+     284             :                         /* in an unsynced array. This is just like the check command. */
+     285             : 
+     286      102459 :                         read_size = handle_read(&handle[j], block, buffer[j], state->block_size, log_error, 0);
+     287      102459 :                         if (read_size == -1) {
+     288             :                                 /* file we are processing for error reporting */
+     289           0 :                                 struct snapraid_file* file = block_file_get(block);
+     290           0 :                                 if (errno == EIO) {
+     291           0 :                                         log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     292           0 :                                         if (io_error >= state->opt.io_error_limit) {
+     293             :                                                 /* LCOV_EXCL_START */
+     294             :                                                 log_fatal("DANGER! Too many input/output read error in a data disk, it isn't possible to scrub.\n");
+     295             :                                                 log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     296             :                                                 log_fatal("Stopping at block %u\n", i);
+     297             :                                                 ++io_error;
+     298             :                                                 goto bail;
+     299             :                                                 /* LCOV_EXCL_STOP */
+     300             :                                         }
+     301             : 
+     302           0 :                                         log_error("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
+     303           0 :                                         ++io_error;
+     304           0 :                                         io_error_on_this_block = 1;
+     305           0 :                                         continue;
+     306             :                                 }
+     307             : 
+     308           0 :                                 log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     309           0 :                                 ++error;
+     310           0 :                                 error_on_this_block = 1;
+     311           0 :                                 continue;
+     312             :                         }
+     313             : 
+     314             :                         /* until now is disk */
+     315      102459 :                         state_usage_disk(state, disk);
+     316             : 
+     317      102459 :                         countsize += read_size;
+     318             : 
+     319             :                         /* now compute the hash */
+     320      102459 :                         if (rehash) {
+     321       27207 :                                 memhash(state->prevhash, state->prevhashseed, hash, buffer[j], read_size);
+     322             : 
+     323             :                                 /* compute the new hash, and store it */
+     324       27207 :                                 rehandle[j].block = block;
+     325       27207 :                                 memhash(state->hash, state->hashseed, rehandle[j].hash, buffer[j], read_size);
+     326             :                         } else {
+     327       75252 :                                 memhash(state->hash, state->hashseed, hash, buffer[j], read_size);
+     328             :                         }
+     329             : 
+     330      102459 :                         if (block_has_updated_hash(block)) {
+     331             :                                 /* compare the hash */
+     332      102459 :                                 if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
+     333         920 :                                         log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(handle[j].file->sub), block_file_pos(block));
+     334             : 
+     335             :                                         /* it's a silent error only if we are dealing with synced files */
+     336         920 :                                         if (file_is_unsynced) {
+     337           0 :                                                 ++error;
+     338           0 :                                                 error_on_this_block = 1;
+     339             :                                         } else {
+     340         920 :                                                 log_error("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
+     341         920 :                                                 ++silent_error;
+     342         920 :                                                 silent_error_on_this_block = 1;
+     343             :                                         }
+     344         920 :                                         continue;
+     345             :                                 }
+     346             :                         }
+     347             :                 }
+     348             : 
+     349             :                 /* if we have read all the data required and it's correct, proceed with the parity check */
+     350       17235 :                 if (!error_on_this_block && !silent_error_on_this_block && !io_error_on_this_block) {
+     351             :                         unsigned char* buffer_recov[LEV_MAX];
+     352             : 
+     353             :                         /* until now is CPU */
+     354       16315 :                         state_usage_cpu(state);
+     355             : 
+     356             :                         /* buffers for parity read and not computed */
+     357      114205 :                         for (l = 0; l < state->level; ++l)
+     358       97890 :                                 buffer_recov[l] = buffer[diskmax + state->level + l];
+     359       16315 :                         for (; l < LEV_MAX; ++l)
+     360           0 :                                 buffer_recov[l] = 0;
+     361             : 
+     362             :                         /* read the parity */
+     363      114205 :                         for (l = 0; l < state->level; ++l) {
+     364       97890 :                                 ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, log_error);
+     365       97890 :                                 if (ret == -1) {
+     366           0 :                                         buffer_recov[l] = 0;
+     367             : 
+     368           0 :                                         if (errno == EIO) {
+     369           0 :                                                 log_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno));
+     370           0 :                                                 if (io_error >= state->opt.io_error_limit) {
+     371             :                                                         /* LCOV_EXCL_START */
+     372             :                                                         log_fatal("DANGER! Too many input/output read error in the %s disk, it isn't possible to scrub.\n", lev_name(l));
+     373             :                                                         log_fatal("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l));
+     374             :                                                         log_fatal("Stopping at block %u\n", i);
+     375             :                                                         ++io_error;
+     376             :                                                         goto bail;
+     377             :                                                         /* LCOV_EXCL_STOP */
+     378             :                                                 }
+     379             : 
+     380           0 :                                                 log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i);
+     381           0 :                                                 ++io_error;
+     382           0 :                                                 io_error_on_this_block = 1;
+     383           0 :                                                 continue;
+     384             :                                         }
+     385             : 
+     386           0 :                                         log_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno));
+     387           0 :                                         ++error;
+     388           0 :                                         error_on_this_block = 1;
+     389           0 :                                         continue;
+     390             :                                 }
+     391             : 
+     392             :                                 /* until now is parity */
+     393       97890 :                                 state_usage_parity(state, l);
+     394             :                         }
+     395             : 
+     396             :                         /* compute the parity */
+     397       16315 :                         raid_gen(diskmax, state->level, state->block_size, buffer);
+     398             : 
+     399             :                         /* compare the parity */
+     400      114205 :                         for (l = 0; l < state->level; ++l) {
+     401       97890 :                                 if (buffer_recov[l] && memcmp(buffer[diskmax + l], buffer_recov[l], state->block_size) != 0) {
+     402           0 :                                         log_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l));
+     403             : 
+     404             :                                         /* it's a silent error only if we are dealing with synced blocks */
+     405           0 :                                         if (block_is_unsynced) {
+     406           0 :                                                 ++error;
+     407           0 :                                                 error_on_this_block = 1;
+     408             :                                         } else {
+     409           0 :                                                 log_fatal("Data error in parity '%s' at position '%u'\n", lev_config_name(l), i);
+     410           0 :                                                 ++silent_error;
+     411           0 :                                                 silent_error_on_this_block = 1;
+     412             :                                         }
+     413             :                                 }
+     414             :                         }
+     415             :                 }
+     416             : 
+     417       17235 :                 if (silent_error_on_this_block || io_error_on_this_block) {
+     418             :                         /* set the error status keeping the existing time and hash */
+     419         920 :                         info_set(&state->infoarr, i, info_set_bad(info));
+     420       16315 :                 } else if (error_on_this_block) {
+     421             :                         /* do nothing, as this is a generic error */
+     422             :                         /* likely caused by a not synced array */
+     423             :                 } else {
+     424             :                         /* if rehash is needed */
+     425       16315 :                         if (rehash) {
+     426             :                                 /* store all the new hash already computed */
+     427       32200 :                                 for (j = 0; j < diskmax; ++j) {
+     428       27600 :                                         if (rehandle[j].block)
+     429       27207 :                                                 memcpy(rehandle[j].block->hash, rehandle[j].hash, HASH_SIZE);
+     430             :                                 }
+     431             :                         }
+     432             : 
+     433             :                         /* update the time info of the block */
+     434             :                         /* and clear any other flag */
+     435       16315 :                         info_set(&state->infoarr, i, info_make(now, 0, 0));
+     436             :                 }
+     437             : 
+     438             :                 /* mark the state as needing write */
+     439       17235 :                 state->need_write = 1;
+     440             : 
+     441             :                 /* count the number of processed block */
+     442       17235 :                 ++countpos;
+     443             : 
+     444             :                 /* progress */
+     445       17235 :                 if (state_progress(state, i, countpos, countmax, countsize)) {
+     446             :                         /* LCOV_EXCL_START */
+     447             :                         break;
+     448             :                         /* LCOV_EXCL_STOP */
+     449             :                 }
+     450             : 
+     451             :                 /* autosave */
+     452       17235 :                 if (state->autosave != 0
+     453           0 :                         && autosavedone >= autosavelimit /* if we have reached the limit */
+     454           0 :                         && autosavemissing >= autosavelimit /* if we have at least a full step to do */
+     455             :                 ) {
+     456           0 :                         autosavedone = 0; /* restart the counter */
+     457             : 
+     458             :                         /* until now is CPU */
+     459           0 :                         state_usage_cpu(state);
+     460             : 
+     461           0 :                         state_progress_stop(state);
+     462             : 
+     463           0 :                         msg_progress("Autosaving...\n");
+     464           0 :                         state_write(state);
+     465             : 
+     466           0 :                         state_progress_restart(state);
+     467             : 
+     468             :                         /* drop until now */
+     469           0 :                         state_usage_waste(state);
+     470             :                 }
+     471             :         }
+     472             : 
+     473           9 :         state_progress_end(state, countpos, countmax, countsize);
+     474             : 
+     475           9 :         state_usage_print(state);
+     476             : 
+     477           9 :         if (error || silent_error || io_error) {
+     478           1 :                 msg_status("\n");
+     479           1 :                 msg_status("%8u file errors\n", error);
+     480           1 :                 msg_status("%8u io errors\n", io_error);
+     481           1 :                 msg_status("%8u data errors\n", silent_error);
+     482             :         } else {
+     483             :                 /* print the result only if processed something */
+     484           8 :                 if (countpos != 0)
+     485           7 :                         msg_status("Everything OK\n");
+     486             :         }
+     487             : 
+     488           9 :         if (error)
+     489           0 :                 log_fatal("WARNING! Unexpected file errors!\n");
+     490           9 :         if (io_error)
+     491           0 :                 log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n");
+     492           9 :         if (silent_error)
+     493           1 :                 log_fatal("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n");
+     494           9 :         if (io_error || silent_error) {
+     495           1 :                 log_fatal("Use 'snapraid status' to list the bad blocks.\n");
+     496           1 :                 log_fatal("Use 'snapraid -e fix' to recover.\n");
+     497             :         }
+     498             : 
+     499           9 :         log_tag("summary:error_file:%u\n", error);
+     500           9 :         log_tag("summary:error_io:%u\n", io_error);
+     501           9 :         log_tag("summary:error_data:%u\n", silent_error);
+     502           9 :         if (error + silent_error + io_error == 0)
+     503           8 :                 log_tag("summary:exit:ok\n");
+     504             :         else
+     505           1 :                 log_tag("summary:exit:error\n");
+     506           9 :         log_flush();
+     507             : 
+     508             : bail:
+     509          63 :         for (j = 0; j < diskmax; ++j) {
+     510          54 :                 struct snapraid_file* file = handle[j].file;
+     511          54 :                 struct snapraid_disk* disk = handle[j].disk;
+     512          54 :                 ret = handle_close(&handle[j]);
+     513          54 :                 if (ret == -1) {
+     514             :                         /* LCOV_EXCL_START */
+     515             :                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     516             :                         log_fatal("DANGER! Unexpected close error in a data disk.\n");
+     517             :                         ++error;
+     518             :                         /* continue, as we are already exiting */
+     519             :                         /* LCOV_EXCL_STOP */
+     520             :                 }
+     521             :         }
+     522             : 
+     523           9 :         free(handle);
+     524           9 :         free(buffer_alloc);
+     525           9 :         free(buffer);
+     526           9 :         free(rehandle_alloc);
+     527             : 
+     528           9 :         if (state->opt.expect_recoverable) {
+     529           1 :                 if (error + silent_error + io_error == 0)
+     530           0 :                         return -1;
+     531             :         } else {
+     532           8 :                 if (error + silent_error + io_error != 0)
+     533           0 :                         return -1;
+     534             :         }
+     535           9 :         return 0;
+     536             : }
+     537             : 
+     538             : /**
+     539             :  * Returns a * b / c approximated to the upper value.
+     540             :  */
+     541           6 : static uint32_t md(uint32_t a, uint32_t b, uint32_t c)
+     542             : {
+     543           6 :         uint64_t v = a;
+     544             : 
+     545           6 :         v *= b;
+     546           6 :         v += c - 1;
+     547           6 :         v /= c;
+     548             : 
+     549           6 :         return v;
+     550             : }
+     551             : 
+     552           9 : int state_scrub(struct snapraid_state* state, int percentage, int olderthan)
+     553             : {
+     554             :         block_off_t blockmax;
+     555             :         block_off_t countlimit;
+     556             :         block_off_t lastlimit;
+     557             :         block_off_t i;
+     558             :         time_t timelimit;
+     559             :         time_t recentlimit;
+     560             :         unsigned count;
+     561             :         int ret;
+     562             :         struct snapraid_parity_handle parity[LEV_MAX];
+     563             :         struct snapraid_parity_handle* parity_ptr[LEV_MAX];
+     564             :         snapraid_info* infomap;
+     565             :         unsigned error;
+     566             :         time_t now;
+     567             :         unsigned l;
+     568             : 
+     569             :         /* get the present time */
+     570           9 :         now = time(0);
+     571             : 
+     572           9 :         msg_progress("Initializing...\n");
+     573             : 
+     574           9 :         blockmax = parity_allocated_size(state);
+     575             : 
+     576           9 :         if (state->opt.force_scrub_even) {
+     577             :                 /* no limit */
+     578           1 :                 countlimit = blockmax;
+     579           1 :                 recentlimit = now;
+     580           8 :         } else if (state->opt.force_scrub_at) {
+     581             :                 /* scrub the specified amount of blocks */
+     582           4 :                 countlimit = state->opt.force_scrub_at;
+     583           4 :                 recentlimit = now;
+     584             :         } else {
+     585             :                 /* by default scrub 1/12 of the array */
+     586           4 :                 countlimit = md(blockmax, 1, 12);
+     587             : 
+     588           4 :                 if (percentage != -1)
+     589           2 :                         countlimit = md(blockmax, percentage, 100);
+     590             : 
+     591             :                 /* by default use a 10 day time limit */
+     592           4 :                 recentlimit = now - 10 * 24 * 3600;
+     593             : 
+     594           4 :                 if (olderthan != -1)
+     595           1 :                         recentlimit = now - olderthan * 24 * 3600;
+     596             :         }
+     597             : 
+     598             :         /* identify the time limit */
+     599             :         /* we sort all the block times, and we identify the time limit for which we reach the quota */
+     600             :         /* this allow to process first the oldest blocks */
+     601           9 :         infomap = malloc_nofail(blockmax * sizeof(snapraid_info));
+     602             : 
+     603             :         /* copy the info in the temp vector */
+     604           9 :         count = 0;
+     605           9 :         log_tag("block_count:%u\n", blockmax);
+     606       46576 :         for (i = 0; i < blockmax; ++i) {
+     607       46567 :                 snapraid_info info = info_get(&state->infoarr, i);
+     608             : 
+     609             :                 /* skip unused blocks */
+     610       46567 :                 if (info == 0)
+     611           0 :                         continue;
+     612             : 
+     613       46567 :                 infomap[count++] = info;
+     614             :         }
+     615             : 
+     616           9 :         if (!count) {
+     617             :                 /* LCOV_EXCL_START */
+     618             :                 log_fatal("The array appears to be empty.\n");
+     619             :                 exit(EXIT_FAILURE);
+     620             :                 /* LCOV_EXCL_STOP */
+     621             :         }
+     622             : 
+     623             :         /* sort it */
+     624           9 :         qsort(infomap, count, sizeof(snapraid_info), info_time_compare);
+     625             : 
+     626             :         /* output the info map */
+     627           9 :         i = 0;
+     628           9 :         log_tag("info_count:%u\n", count);
+     629          42 :         while (i < count) {
+     630          24 :                 unsigned j = i + 1;
+     631       46591 :                 while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j]))
+     632       46543 :                         ++j;
+     633          24 :                 log_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i);
+     634          24 :                 i = j;
+     635             :         }
+     636             : 
+     637             :         /* no more than the full count */
+     638           9 :         if (countlimit > count)
+     639           2 :                 countlimit = count;
+     640             : 
+     641             :         /* decrease until we reach the specific recentlimit */
+     642        5079 :         while (countlimit > 0 && info_get_time(infomap[countlimit - 1]) > recentlimit)
+     643        5061 :                 --countlimit;
+     644             : 
+     645             :         /* if there is something to scrub */
+     646           9 :         if (countlimit > 0) {
+     647             :                 /* get the most recent time we want to scrub */
+     648           6 :                 timelimit = info_get_time(infomap[countlimit - 1]);
+     649             : 
+     650             :                 /* count how many entries for this exact time we have to scrub */
+     651             :                 /* if the blocks have all the same time, we end with countlimit == lastlimit */
+     652           6 :                 lastlimit = 1;
+     653        5562 :                 while (countlimit > lastlimit && info_get_time(infomap[countlimit - lastlimit - 1]) == timelimit)
+     654        5550 :                         ++lastlimit;
+     655             :         } else {
+     656             :                 /* if nothing to scrub, disable also other limits */
+     657           3 :                 timelimit = 0;
+     658           3 :                 lastlimit = 0;
+     659             :         }
+     660             : 
+     661           9 :         log_tag("count_limit:%u\n", countlimit);
+     662           9 :         log_tag("time_limit:%" PRIu64 "\n", (uint64_t)timelimit);
+     663           9 :         log_tag("last_limit:%u\n", lastlimit);
+     664             : 
+     665             :         /* free the temp vector */
+     666           9 :         free(infomap);
+     667             : 
+     668             :         /* open the file for reading */
+     669          63 :         for (l = 0; l < state->level; ++l) {
+     670          54 :                 parity_ptr[l] = &parity[l];
+     671          54 :                 ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode);
+     672          54 :                 if (ret == -1) {
+     673             :                         /* LCOV_EXCL_START */
+     674             :                         log_fatal("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l));
+     675             :                         exit(EXIT_FAILURE);
+     676             :                         /* LCOV_EXCL_STOP */
+     677             :                 }
+     678             :         }
+     679             : 
+     680           9 :         msg_progress("Scrubbing...\n");
+     681             : 
+     682           9 :         error = 0;
+     683             : 
+     684           9 :         ret = state_scrub_process(state, parity_ptr, 0, blockmax, timelimit, lastlimit, now);
+     685           9 :         if (ret == -1) {
+     686           0 :                 ++error;
+     687             :                 /* continue, as we are already exiting */
+     688             :         }
+     689             : 
+     690          63 :         for (l = 0; l < state->level; ++l) {
+     691          54 :                 ret = parity_close(parity_ptr[l]);
+     692          54 :                 if (ret == -1) {
+     693             :                         /* LCOV_EXCL_START */
+     694             :                         log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l));
+     695             :                         ++error;
+     696             :                         /* continue, as we are already exiting */
+     697             :                         /* LCOV_EXCL_STOP */
+     698             :                 }
+     699             :         }
+     700             : 
+     701             :         /* abort if required */
+     702           9 :         if (error != 0)
+     703           0 :                 return -1;
+     704           9 :         return 0;
+     705             : }
+     706             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/search.c.func-sort-c.html b/cov/cmdline/search.c.func-sort-c.html new file mode 100644 index 00000000..a89d603c --- /dev/null +++ b/cov/cmdline/search.c.func-sort-c.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/search.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - search.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:909891.8 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
search_file1844870
search_file_free1844870
state_search_fetch625435
search_file_compare11468
search_dir2465
state_search_array114
state_search1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/search.c.func.html b/cov/cmdline/search.c.func.html new file mode 100644 index 00000000..7632633e --- /dev/null +++ b/cov/cmdline/search.c.func.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/search.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - search.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:909891.8 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
search_dir2465
search_file1844870
search_file_compare11468
search_file_free1844870
state_search1
state_search_array114
state_search_fetch625435
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/search.c.gcov.html b/cov/cmdline/search.c.gcov.html new file mode 100644 index 00000000..0aca163b --- /dev/null +++ b/cov/cmdline/search.c.gcov.html @@ -0,0 +1,366 @@ + + + + + + + LCOV - lcov.info - cmdline/search.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - search.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:909891.8 %
Date:2015-05-12Functions:77100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2014 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "search.h"
+      22             : 
+      23             : /****************************************************************************/
+      24             : /* search */
+      25             : 
+      26     1844870 : static void search_file(struct snapraid_state* state, const char* path, data_off_t size, int64_t mtime_sec, int mtime_nsec)
+      27             : {
+      28             :         struct snapraid_search_file* file;
+      29             :         tommy_uint32_t file_hash;
+      30             : 
+      31     1844870 :         file = malloc_nofail(sizeof(struct snapraid_search_file));
+      32     1844870 :         file->path = strdup_nofail(path);
+      33     1844870 :         file->size = size;
+      34     1844870 :         file->mtime_sec = mtime_sec;
+      35     1844870 :         file->mtime_nsec = mtime_nsec;
+      36             : 
+      37     1844870 :         file_hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec);
+      38             : 
+      39     1844870 :         tommy_hashdyn_insert(&state->searchset, &file->node, file, file_hash);
+      40     1844870 : }
+      41             : 
+      42     1844870 : void search_file_free(struct snapraid_search_file* file)
+      43             : {
+      44     1844870 :         free(file->path);
+      45     1844870 :         free(file);
+      46     1844870 : }
+      47             : 
+      48             : struct search_file_compare_arg {
+      49             :         const struct snapraid_state* state;
+      50             :         const struct snapraid_block* block;
+      51             :         const struct snapraid_file* file;
+      52             :         unsigned char* buffer;
+      53             :         data_off_t offset;
+      54             :         unsigned read_size;
+      55             :         int prevhash;
+      56             : };
+      57             : 
+      58       11468 : int search_file_compare(const void* void_arg, const void* void_data)
+      59             : {
+      60       11468 :         const struct search_file_compare_arg* arg = void_arg;
+      61       11468 :         const struct snapraid_search_file* file = void_data;
+      62       11468 :         const struct snapraid_state* state = arg->state;
+      63             :         unsigned char buffer_hash[HASH_SIZE];
+      64       11468 :         const char* path = file->path;
+      65             :         int f;
+      66             :         ssize_t ret;
+      67             : 
+      68             :         /* compare file info */
+      69       11468 :         if (arg->file->size != file->size)
+      70           0 :                 return -1;
+      71             : 
+      72       11468 :         if (arg->file->mtime_sec != file->mtime_sec)
+      73           0 :                 return -1;
+      74             : 
+      75       11468 :         if (arg->file->mtime_nsec != file->mtime_nsec)
+      76           0 :                 return -1;
+      77             : 
+      78             :         /* read the block and compare the hash */
+      79       11468 :         f = open(path, O_RDONLY | O_BINARY);
+      80       11468 :         if (f == -1) {
+      81             :                 /* LCOV_EXCL_START */
+      82             :                 if (errno == ENOENT) {
+      83             :                         log_fatal("DANGER! file '%s' disappeared.\n", path);
+      84             :                         log_fatal("If you moved it, please rerun the same command.\n");
+      85             :                 } else {
+      86             :                         log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno));
+      87             :                 }
+      88             :                 exit(EXIT_FAILURE);
+      89             :                 /* LCOV_EXCL_STOP */
+      90             :         }
+      91             : 
+      92       11468 :         if (lseek(f, arg->offset, SEEK_SET) != arg->offset) {
+      93             :                 /* LCOV_EXCL_START */
+      94             :                 log_fatal("Error seeking file '%s'. %s.\n", path, strerror(errno));
+      95             :                 exit(EXIT_FAILURE);
+      96             :                 /* LCOV_EXCL_STOP */
+      97             :         }
+      98             : 
+      99       11468 :         ret = read(f, arg->buffer, arg->read_size);
+     100       11468 :         if (ret < 0 || (unsigned)ret != arg->read_size) {
+     101             :                 /* LCOV_EXCL_START */
+     102             :                 log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno));
+     103             :                 exit(EXIT_FAILURE);
+     104             :                 /* LCOV_EXCL_STOP */
+     105             :         }
+     106             : 
+     107       11468 :         ret = close(f);
+     108       11468 :         if (ret != 0) {
+     109             :                 /* LCOV_EXCL_START */
+     110             :                 log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno));
+     111             :                 exit(EXIT_FAILURE);
+     112             :                 /* LCOV_EXCL_STOP */
+     113             :         }
+     114             : 
+     115             :         /* compute the hash */
+     116       11468 :         if (arg->prevhash)
+     117        4503 :                 memhash(state->prevhash, state->prevhashseed, buffer_hash, arg->buffer, arg->read_size);
+     118             :         else
+     119        6965 :                 memhash(state->hash, state->hashseed, buffer_hash, arg->buffer, arg->read_size);
+     120             : 
+     121             :         /* check if the hash is matching */
+     122       11468 :         if (memcmp(buffer_hash, arg->block->hash, HASH_SIZE) != 0)
+     123        2086 :                 return -1;
+     124             : 
+     125        9382 :         if (arg->read_size != state->block_size) {
+     126             :                 /* fill the remaining with 0 */
+     127        3922 :                 memset(arg->buffer + arg->read_size, 0, state->block_size - arg->read_size);
+     128             :         }
+     129             : 
+     130        9382 :         return 0;
+     131             : }
+     132             : 
+     133      625435 : int state_search_fetch(struct snapraid_state* state, int prevhash, struct snapraid_block* missing_block, unsigned char* buffer)
+     134             : {
+     135             :         struct snapraid_search_file* file;
+     136             :         tommy_uint32_t file_hash;
+     137             :         struct search_file_compare_arg arg;
+     138             : 
+     139      625435 :         arg.state = state;
+     140      625435 :         arg.block = missing_block;
+     141      625435 :         arg.file = block_file_get(missing_block);
+     142      625435 :         arg.buffer = buffer;
+     143      625435 :         arg.offset = state->block_size * (data_off_t)block_file_pos(missing_block);
+     144      625435 :         arg.read_size = block_file_size(missing_block, state->block_size);
+     145      625435 :         arg.prevhash = prevhash;
+     146             : 
+     147      625435 :         file_hash = file_stamp_hash(arg.file->size, arg.file->mtime_sec, arg.file->mtime_nsec);
+     148             : 
+     149             :         /* search in the hashtable, and also check if the data matches the hash */
+     150      625435 :         file = tommy_hashdyn_search(&state->searchset, search_file_compare, &arg, file_hash);
+     151      625435 :         if (!file)
+     152      616053 :                 return -1;
+     153             : 
+     154             :         /* if found, buffer is already set with data */
+     155        9382 :         return 0;
+     156             : }
+     157             : 
+     158        2465 : static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, const char* dir, const char* sub)
+     159             : {
+     160             :         DIR* d;
+     161             : 
+     162        2465 :         d = opendir(dir);
+     163        2465 :         if (!d) {
+     164             :                 /* LCOV_EXCL_START */
+     165             :                 log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno));
+     166             :                 exit(EXIT_FAILURE);
+     167             :                 /* LCOV_EXCL_STOP */
+     168             :         }
+     169             : 
+     170             :         while (1) {
+     171             :                 char path_next[PATH_MAX];
+     172             :                 char sub_next[PATH_MAX];
+     173             :                 char out[PATH_MAX];
+     174     2041185 :                 struct snapraid_filter* reason = 0;
+     175             :                 struct stat st;
+     176             :                 const char* name;
+     177             :                 struct dirent* dd;
+     178             : 
+     179             :                 /* clear errno to detect erroneous conditions */
+     180     2041185 :                 errno = 0;
+     181     2041185 :                 dd = readdir(d);
+     182     2041185 :                 if (dd == 0 && errno != 0) {
+     183             :                         /* LCOV_EXCL_START */
+     184             :                         log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno));
+     185             :                         exit(EXIT_FAILURE);
+     186             :                         /* LCOV_EXCL_STOP */
+     187             :                 }
+     188     2041185 :                 if (dd == 0) {
+     189        2465 :                         break; /* finished */
+     190             :                 }
+     191             : 
+     192             :                 /* skip "." and ".." files */
+     193     2038720 :                 name = dd->d_name;
+     194     2038720 :                 if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
+     195        9860 :                         continue;
+     196             : 
+     197     2033790 :                 pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
+     198     2033790 :                 pathprint(sub_next, sizeof(sub_next), "%s%s", sub, name);
+     199             : 
+     200             :                 /* exclude hidden files even before calling lstat() */
+     201     2033790 :                 if (disk != 0 && filter_hidden(state->filter_hidden, dd) != 0) {
+     202           0 :                         msg_verbose("Excluding hidden '%s'\n", path_next);
+     203           0 :                         continue;
+     204             :                 }
+     205             : 
+     206             :                 /* exclude content files even before calling lstat() */
+     207     2033790 :                 if (disk != 0 && filter_content(&state->contentlist, path_next) != 0) {
+     208           0 :                         msg_verbose("Excluding content '%s'\n", path_next);
+     209           0 :                         continue;
+     210             :                 }
+     211             : 
+     212             : #if HAVE_STRUCT_DIRENT_D_STAT
+     213             :                 /* convert dirent to lstat result */
+     214             :                 dirent_lstat(dd, &st);
+     215             : 
+     216             :                 /* if the st_mode field is missing, takes care to fill it using normal lstat() */
+     217             :                 /* at now this can happen only in Windows (with HAVE_STRUCT_DIRENT_D_STAT defined), */
+     218             :                 /* because we use a directory reading method that doesn't read info about ReparsePoint. */
+     219             :                 /* Note that here we cannot call here lstat_sync(), because we don't know what kind */
+     220             :                 /* of file is it, and lstat_sync() doesn't always work */
+     221             :                 if (st.st_mode == 0) {
+     222             :                         if (lstat(path_next, &st) != 0) {
+     223             :                                 /* LCOV_EXCL_START */
+     224             :                                 log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+     225             :                                 exit(EXIT_FAILURE);
+     226             :                                 /* LCOV_EXCL_STOP */
+     227             :                         }
+     228             :                 }
+     229             : #else
+     230             :                 /* get lstat info about the file */
+     231     2033790 :                 if (lstat(path_next, &st) != 0) {
+     232             :                         /* LCOV_EXCL_START */
+     233             :                         log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
+     234             :                         exit(EXIT_FAILURE);
+     235             :                         /* LCOV_EXCL_STOP */
+     236             :                 }
+     237             : #endif
+     238             : 
+     239     2033790 :                 if (S_ISREG(st.st_mode)) {
+     240     1969797 :                         if (disk == 0 || filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+     241     1844870 :                                 search_file(state, path_next, st.st_size, st.st_mtime, STAT_NSEC(&st));
+     242             :                         } else {
+     243      124927 :                                 msg_verbose("Excluding link '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+     244             :                         }
+     245       63993 :                 } else if (S_ISDIR(st.st_mode)) {
+     246        1783 :                         if (disk == 0 || filter_dir(&state->filterlist, &reason, disk->name, sub_next) == 0) {
+     247        1783 :                                 pathslash(path_next, sizeof(path_next));
+     248        1783 :                                 pathslash(sub_next, sizeof(sub_next));
+     249        1783 :                                 search_dir(state, disk, path_next, sub_next);
+     250             :                         } else {
+     251           0 :                                 msg_verbose("Excluding directory '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
+     252             :                         }
+     253             :                 }
+     254     2038720 :         }
+     255             : 
+     256        2465 :         if (closedir(d) != 0) {
+     257             :                 /* LCOV_EXCL_START */
+     258             :                 log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno));
+     259             :                 exit(EXIT_FAILURE);
+     260             :                 /* LCOV_EXCL_STOP */
+     261             :         }
+     262        2465 : }
+     263             : 
+     264           1 : void state_search(struct snapraid_state* state, const char* dir)
+     265             : {
+     266             :         char path[PATH_MAX];
+     267             : 
+     268           1 :         msg_progress("Importing...\n");
+     269             : 
+     270             :         /* add the final slash */
+     271           1 :         pathimport(path, sizeof(path), dir);
+     272           1 :         pathslash(path, sizeof(path));
+     273             : 
+     274           1 :         search_dir(state, 0, path, "");
+     275           1 : }
+     276             : 
+     277         114 : void state_search_array(struct snapraid_state* state)
+     278             : {
+     279             :         tommy_node* i;
+     280             : 
+     281             :         /* import from all the disks */
+     282         795 :         for (i = state->disklist; i != 0; i = i->next) {
+     283         681 :                 struct snapraid_disk* disk = i->data;
+     284             : 
+     285         681 :                 msg_progress("Scanning disk %s...\n", disk->name);
+     286             : 
+     287         681 :                 search_dir(state, disk, disk->dir, "");
+     288             :         }
+     289         114 : }
+     290             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/selftest.c.func-sort-c.html b/cov/cmdline/selftest.c.func-sort-c.html new file mode 100644 index 00000000..e9eb7d25 --- /dev/null +++ b/cov/cmdline/selftest.c.func-sort-c.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/selftest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - selftest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11413087.7 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_test_search384
tommy_test_foreach256
tommy_test_foreach_arg256
test_tommy1
test_crc32c1
test_hash1
selftest1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/selftest.c.func.html b/cov/cmdline/selftest.c.func.html new file mode 100644 index 00000000..20ba8a20 --- /dev/null +++ b/cov/cmdline/selftest.c.func.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/selftest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - selftest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11413087.7 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
selftest1
test_crc32c1
test_hash1
test_tommy1
tommy_test_foreach256
tommy_test_foreach_arg256
tommy_test_search384
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/selftest.c.gcov.html b/cov/cmdline/selftest.c.gcov.html new file mode 100644 index 00000000..9d651328 --- /dev/null +++ b/cov/cmdline/selftest.c.gcov.html @@ -0,0 +1,530 @@ + + + + + + + LCOV - lcov.info - cmdline/selftest.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - selftest.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:11413087.7 %
Date:2015-05-12Functions:77100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "snapraid.h"
+      21             : #include "util.h"
+      22             : #include "raid/raid.h"
+      23             : #include "raid/cpu.h"
+      24             : #include "raid/combo.h"
+      25             : #include "raid/internal.h"
+      26             : #include "raid/test.h"
+      27             : #include "elem.h"
+      28             : #include "state.h"
+      29             : #include "support.h"
+      30             : #include "tommyds/tommyhash.h"
+      31             : #include "tommyds/tommyarray.h"
+      32             : #include "tommyds/tommyarrayblk.h"
+      33             : #include "tommyds/tommyarrayblkof.h"
+      34             : #include "tommyds/tommyhashdyn.h"
+      35             : 
+      36             : struct hash32_test_vector {
+      37             :         const char* data;
+      38             :         int len;
+      39             :         uint32_t digest;
+      40             : };
+      41             : 
+      42             : struct hash64_test_vector {
+      43             :         const char* data;
+      44             :         int len;
+      45             :         uint64_t digest;
+      46             : };
+      47             : 
+      48             : struct hash_test_vector {
+      49             :         const char* data;
+      50             :         int len;
+      51             :         unsigned char digest[HASH_SIZE];
+      52             : };
+      53             : 
+      54             : /**
+      55             :  * Test vectors for tommy_hash32
+      56             :  */
+      57             : static struct hash32_test_vector TEST_HASH32[] = {
+      58             :         { "", 0, 0x8614384c },
+      59             :         { "a", 1, 0x12c16c36 },
+      60             :         { "abc", 3, 0xc58e8af5 },
+      61             :         { "message digest", 14, 0x006b32f1 },
+      62             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x7e6fcfe0 },
+      63             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x8604adf8 },
+      64             :         { "The quick brown fox jumps over the lazy dog", 43, 0xdeba3d3a },
+      65             :         { "\x00", 1, 0x4a7d1c33 },
+      66             :         { "\x16\x27", 2, 0x8b50899b },
+      67             :         { "\xe2\x56\xb4", 3, 0x60406493 },
+      68             :         { "\xc9\x4d\x9c\xda", 4, 0xa049144a },
+      69             :         { "\x79\xf1\x29\x69\x5d", 5, 0x4da2c2f1 },
+      70             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x59de30cf },
+      71             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x219e149c },
+      72             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x25067520 },
+      73             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8 },
+      74             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d },
+      75             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f },
+      76             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382 },
+      77             :         { 0, 0, 0 }
+      78             : };
+      79             : 
+      80             : /**
+      81             :  * Test vectors for tommy_hash64
+      82             :  */
+      83             : static struct hash64_test_vector TEST_HASH64[] = {
+      84             :         { "", 0, 0x8614384cb5165fbfULL },
+      85             :         { "a", 1, 0x1a2e0298a8e94a3dULL },
+      86             :         { "abc", 3, 0x7555796b7a7d21ebULL },
+      87             :         { "message digest", 14, 0x9411a57d04b92fb4ULL },
+      88             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x3ca3f8d2b4e69832ULL },
+      89             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x6dae542ba0015a4dULL },
+      90             :         { "The quick brown fox jumps over the lazy dog", 43, 0xe06d8cbb3d2ea1a6ULL },
+      91             :         { "\x00", 1, 0x201e664fb5f2c021ULL },
+      92             :         { "\x16\x27", 2, 0xef42fa8032c4b775ULL },
+      93             :         { "\xe2\x56\xb4", 3, 0x6e6c498a6688466cULL },
+      94             :         { "\xc9\x4d\x9c\xda", 4, 0x5195005419905423ULL },
+      95             :         { "\x79\xf1\x29\x69\x5d", 5, 0x221235b48afee7c1ULL },
+      96             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x1b1f18b9266f095bULL },
+      97             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x2cbafa8e741d49caULL },
+      98             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x4677f04c06e0758dULL },
+      99             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL },
+     100             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL },
+     101             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL },
+     102             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL },
+     103             :         { 0, 0, 0 }
+     104             : };
+     105             : 
+     106             : /**
+     107             :  * Test vectors for MurmorHash3_x86_128
+     108             :  */
+     109             : static struct hash_test_vector TEST_MURMUR3[] = {
+     110             : #include "murmur3test.c"
+     111             :         { 0, 0, { 0 } }
+     112             : };
+     113             : 
+     114             : /**
+     115             :  * Test vectors for SpookyHash_128
+     116             :  */
+     117             : static struct hash_test_vector TEST_SPOOKY2[] = {
+     118             : #include "spooky2test.c"
+     119             :         { 0, 0, { 0 } }
+     120             : };
+     121             : 
+     122             : #define HASH_TEST_MAX 512 /* tests are never longer than 512 bytes */
+     123             : 
+     124           1 : static void test_hash(void)
+     125             : {
+     126             :         unsigned i;
+     127             :         unsigned char* seed_aligned;
+     128             :         void* seed_alloc;
+     129             :         unsigned char* buffer_aligned;
+     130             :         void* buffer_alloc;
+     131             :         uint32_t seed32;
+     132             :         uint64_t seed64;
+     133             : 
+     134           1 :         seed_aligned = malloc_nofail_align(HASH_SIZE, &seed_alloc);
+     135           1 :         buffer_aligned = malloc_nofail_align(HASH_TEST_MAX, &buffer_alloc);
+     136             : 
+     137           1 :         seed32 = 0xa766795d;
+     138           1 :         seed64 = 0x2f022773a766795dULL;
+     139             : 
+     140           1 :         seed_aligned[0] = 0x5d;
+     141           1 :         seed_aligned[1] = 0x79;
+     142           1 :         seed_aligned[2] = 0x66;
+     143           1 :         seed_aligned[3] = 0xa7;
+     144           1 :         seed_aligned[4] = 0x73;
+     145           1 :         seed_aligned[5] = 0x27;
+     146           1 :         seed_aligned[6] = 0x02;
+     147           1 :         seed_aligned[7] = 0x2f;
+     148           1 :         seed_aligned[8] = 0x6a;
+     149           1 :         seed_aligned[9] = 0xa1;
+     150           1 :         seed_aligned[10] = 0x9e;
+     151           1 :         seed_aligned[11] = 0xc1;
+     152           1 :         seed_aligned[12] = 0x14;
+     153           1 :         seed_aligned[13] = 0x8c;
+     154           1 :         seed_aligned[14] = 0x9e;
+     155           1 :         seed_aligned[15] = 0x43;
+     156             : 
+     157          20 :         for (i = 0; TEST_HASH32[i].data; ++i) {
+     158             :                 uint32_t digest;
+     159          19 :                 memcpy(buffer_aligned, TEST_HASH32[i].data, TEST_HASH32[i].len);
+     160          19 :                 digest = tommy_hash_u32(seed32, buffer_aligned, TEST_MURMUR3[i].len);
+     161          19 :                 if (digest != TEST_HASH32[i].digest) {
+     162             :                         /* LCOV_EXCL_START */
+     163             :                         log_fatal("Failed hash32 test\n");
+     164             :                         exit(EXIT_FAILURE);
+     165             :                         /* LCOV_EXCL_STOP */
+     166             :                 }
+     167             :         }
+     168             : 
+     169          20 :         for (i = 0; TEST_HASH64[i].data; ++i) {
+     170             :                 uint64_t digest;
+     171          19 :                 memcpy(buffer_aligned, TEST_HASH64[i].data, TEST_HASH64[i].len);
+     172          19 :                 digest = tommy_hash_u64(seed64, buffer_aligned, TEST_MURMUR3[i].len);
+     173          19 :                 if (digest != TEST_HASH64[i].digest) {
+     174             :                         /* LCOV_EXCL_START */
+     175             :                         log_fatal("Failed hash64 test\n");
+     176             :                         exit(EXIT_FAILURE);
+     177             :                         /* LCOV_EXCL_STOP */
+     178             :                 }
+     179             :         }
+     180             : 
+     181             : 
+     182         264 :         for (i = 0; TEST_MURMUR3[i].data; ++i) {
+     183             :                 unsigned char digest[HASH_SIZE];
+     184         263 :                 memcpy(buffer_aligned, TEST_MURMUR3[i].data, TEST_MURMUR3[i].len);
+     185         263 :                 memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len);
+     186         263 :                 if (memcmp(digest, TEST_MURMUR3[i].digest, HASH_SIZE) != 0) {
+     187             :                         /* LCOV_EXCL_START */
+     188             :                         log_fatal("Failed Murmur3 test\n");
+     189             :                         exit(EXIT_FAILURE);
+     190             :                         /* LCOV_EXCL_STOP */
+     191             :                 }
+     192             :         }
+     193             : 
+     194         264 :         for (i = 0; TEST_SPOOKY2[i].data; ++i) {
+     195             :                 unsigned char digest[HASH_SIZE];
+     196         263 :                 memcpy(buffer_aligned, TEST_SPOOKY2[i].data, TEST_SPOOKY2[i].len);
+     197         263 :                 memhash(HASH_SPOOKY2, seed_aligned, digest, buffer_aligned, TEST_SPOOKY2[i].len);
+     198         263 :                 if (memcmp(digest, TEST_SPOOKY2[i].digest, HASH_SIZE) != 0) {
+     199             :                         /* LCOV_EXCL_START */
+     200             :                         log_fatal("Failed Spooky2 test\n");
+     201             :                         exit(EXIT_FAILURE);
+     202             :                         /* LCOV_EXCL_STOP */
+     203             :                 }
+     204             :         }
+     205             : 
+     206           1 :         free(buffer_alloc);
+     207           1 :         free(seed_alloc);
+     208           1 : }
+     209             : 
+     210             : struct crc_test_vector {
+     211             :         const char* data;
+     212             :         int len;
+     213             :         uint32_t digest;
+     214             : };
+     215             : 
+     216             : /**
+     217             :  * Test vectors for CRC32C (Castagnoli)
+     218             :  */
+     219             : static struct crc_test_vector TEST_CRC32C[] = {
+     220             :         { "", 0, 0 },
+     221             :         { "\x61", 1, 0xc1d04330 },
+     222             :         { "\x66\x6f\x6f", 3, 0xcfc4ae1d },
+     223             :         { "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa },
+     224             :         { "\x68\x65\x6c\x6c\x6f\x20", 6, 0x7e627e58 },
+     225             :         { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0x8a9136aa },
+     226             :         { "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32, 0x62a8ab43 },
+     227             :         { "\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 32, 0x113fdb5c },
+     228             :         { "\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 48, 0xd9963a56 },
+     229             :         { "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32, 0x46dd794e },
+     230             :         { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28", 40, 0x0e2c157f },
+     231             :         { "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50", 40, 0xe980ebf6 },
+     232             :         { "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78", 40, 0xde74bded },
+     233             :         { "\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0", 40, 0xd579c862 },
+     234             :         { "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8", 40, 0xba979ad0 },
+     235             :         { "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 40, 0x2b29d913 },
+     236             :         { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 240, 0x24c5d375 },
+     237             :         { 0, 0, 0 }
+     238             : };
+     239             : 
+     240           1 : static void test_crc32c(void)
+     241             : {
+     242             :         unsigned i;
+     243             : 
+     244          18 :         for (i = 0; TEST_CRC32C[i].data; ++i) {
+     245             :                 uint32_t digest;
+     246          17 :                 digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
+     247          17 :                 if (digest != TEST_CRC32C[i].digest) {
+     248             :                         /* LCOV_EXCL_START */
+     249             :                         log_fatal("Failed CRC32C test\n");
+     250             :                         exit(EXIT_FAILURE);
+     251             :                         /* LCOV_EXCL_STOP */
+     252             :                 }
+     253             :         }
+     254           1 : }
+     255             : 
+     256             : /**
+     257             :  * Size of tommy data structures.
+     258             :  */
+     259             : #define TOMMY_SIZE 256
+     260             : 
+     261         384 : static int tommy_test_search(const void* arg, const void* obj)
+     262             : {
+     263         384 :         return arg != obj;
+     264             : }
+     265             : 
+     266             : static unsigned tommy_test_foreach_count;
+     267             : 
+     268         256 : static void tommy_test_foreach(void* obj)
+     269             : {
+     270             :         (void)obj;
+     271             : 
+     272         256 :         ++tommy_test_foreach_count;
+     273         256 : }
+     274             : 
+     275         256 : static void tommy_test_foreach_arg(void* void_arg, void* obj)
+     276             : {
+     277         256 :         unsigned* arg = void_arg;
+     278             : 
+     279             :         (void)obj;
+     280             : 
+     281         256 :         ++*arg;
+     282         256 : }
+     283             : 
+     284           1 : static void test_tommy(void)
+     285             : {
+     286             :         tommy_array array;
+     287             :         tommy_arrayblk arrayblk;
+     288             :         tommy_arrayblkof arrayblkof;
+     289             :         tommy_list list;
+     290             :         tommy_hashdyn hashdyn;
+     291             :         tommy_hashdyn_node node[TOMMY_SIZE];
+     292             :         unsigned i;
+     293             : 
+     294           1 :         tommy_array_init(&array);
+     295           1 :         tommy_arrayblk_init(&arrayblk);
+     296           1 :         tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));
+     297             : 
+     298         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
+     299         256 :                 tommy_array_insert(&array, &node[i]);
+     300         256 :                 tommy_arrayblk_insert(&arrayblk, &node[i]);
+     301         256 :                 tommy_arrayblkof_grow(&arrayblkof, i + 1);
+     302         256 :                 *(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
+     303             :         }
+     304             : 
+     305           1 :         if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*))
+     306           0 :                 goto bail;
+     307           1 :         if (tommy_arrayblk_memory_usage(&arrayblk) < TOMMY_SIZE * sizeof(void*))
+     308           0 :                 goto bail;
+     309           1 :         if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned))
+     310           0 :                 goto bail;
+     311             : 
+     312         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
+     313         256 :                 if (tommy_array_get(&array, i) != &node[i])
+     314           0 :                         goto bail;
+     315         256 :                 if (tommy_arrayblk_get(&arrayblk, i) != &node[i])
+     316           0 :                         goto bail;
+     317         256 :                 if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i)
+     318           0 :                         goto bail;
+     319             :         }
+     320             : 
+     321           1 :         tommy_arrayblkof_done(&arrayblkof);
+     322           1 :         tommy_arrayblk_done(&arrayblk);
+     323           1 :         tommy_array_done(&array);
+     324             : 
+     325           1 :         tommy_list_init(&list);
+     326             : 
+     327           1 :         if (!tommy_list_empty(&list))
+     328           0 :                 goto bail;
+     329             : 
+     330           1 :         if (tommy_list_tail(&list))
+     331           0 :                 goto bail;
+     332             : 
+     333           1 :         if (tommy_list_head(&list))
+     334           0 :                 goto bail;
+     335             : 
+     336           1 :         tommy_hashdyn_init(&hashdyn);
+     337             : 
+     338         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
+     339         256 :                 tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);
+     340             : 
+     341           1 :         if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE)
+     342           0 :                 goto bail;
+     343             : 
+     344           1 :         if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(void*))
+     345           0 :                 goto bail;
+     346             : 
+     347           1 :         tommy_test_foreach_count = 0;
+     348           1 :         tommy_hashdyn_foreach(&hashdyn, tommy_test_foreach);
+     349           1 :         if (tommy_test_foreach_count != TOMMY_SIZE)
+     350           0 :                 goto bail;
+     351             : 
+     352           1 :         tommy_test_foreach_count = 0;
+     353           1 :         tommy_hashdyn_foreach_arg(&hashdyn, tommy_test_foreach_arg, &tommy_test_foreach_count);
+     354           1 :         if (tommy_test_foreach_count != TOMMY_SIZE)
+     355           0 :                 goto bail;
+     356             : 
+     357         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
+     358         128 :                 tommy_hashdyn_remove_existing(&hashdyn, &node[i]);
+     359             : 
+     360         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
+     361         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0)
+     362           0 :                         goto bail;
+     363             : 
+     364         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i)
+     365         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0)
+     366           0 :                         goto bail;
+     367             : 
+     368           1 :         if (tommy_hashdyn_count(&hashdyn) != 0)
+     369           0 :                 goto bail;
+     370             : 
+     371           1 :         tommy_hashdyn_done(&hashdyn);
+     372             : 
+     373           1 :         return;
+     374             : bail:
+     375             :         /* LCOV_EXCL_START */
+     376             :         log_fatal("Failed tommy test\n");
+     377             :         exit(EXIT_FAILURE);
+     378             :         /* LCOV_EXCL_STOP */
+     379             : }
+     380             : 
+     381           1 : void selftest(void)
+     382             : {
+     383           1 :         log_tag("selftest:\n");
+     384           1 :         log_flush();
+     385             : 
+     386           1 :         msg_progress("Self test...\n");
+     387             : 
+     388             :         /* large file check */
+     389             :         if (sizeof(off_t) < sizeof(uint64_t)) {
+     390             :                 /* LCOV_EXCL_START */
+     391             :                 log_fatal("Missing support for large files\n");
+     392             :                 exit(EXIT_FAILURE);
+     393             :                 /* LCOV_EXCL_STOP */
+     394             :         }
+     395             : 
+     396           1 :         test_hash();
+     397           1 :         test_crc32c();
+     398           1 :         test_tommy();
+     399           1 :         if (raid_selftest() != 0) {
+     400             :                 /* LCOV_EXCL_START */
+     401             :                 log_fatal("Failed SELF test\n");
+     402             :                 exit(EXIT_FAILURE);
+     403             :                 /* LCOV_EXCL_STOP */
+     404             :         }
+     405           1 :         if (raid_test_sort() != 0) {
+     406             :                 /* LCOV_EXCL_START */
+     407             :                 log_fatal("Failed SORT test\n");
+     408             :                 exit(EXIT_FAILURE);
+     409             :                 /* LCOV_EXCL_STOP */
+     410             :         }
+     411           1 :         if (raid_test_insert() != 0) {
+     412             :                 /* LCOV_EXCL_START */
+     413             :                 log_fatal("Failed INSERT test\n");
+     414             :                 exit(EXIT_FAILURE);
+     415             :                 /* LCOV_EXCL_STOP */
+     416             :         }
+     417           1 :         if (raid_test_combo() != 0) {
+     418             :                 /* LCOV_EXCL_START */
+     419             :                 log_fatal("Failed COMBO test\n");
+     420             :                 exit(EXIT_FAILURE);
+     421             :                 /* LCOV_EXCL_STOP */
+     422             :         }
+     423           1 :         if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) {
+     424             :                 /* LCOV_EXCL_START */
+     425             :                 log_fatal("Failed GEN Vandermonde test\n");
+     426             :                 exit(EXIT_FAILURE);
+     427             :                 /* LCOV_EXCL_STOP */
+     428             :         }
+     429           1 :         if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) {
+     430             :                 /* LCOV_EXCL_START */
+     431             :                 log_fatal("Failed REC Vandermonde test\n");
+     432             :                 exit(EXIT_FAILURE);
+     433             :                 /* LCOV_EXCL_STOP */
+     434             :         }
+     435           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) {
+     436             :                 /* LCOV_EXCL_START */
+     437             :                 log_fatal("Failed GEN Cauchy test\n");
+     438             :                 exit(EXIT_FAILURE);
+     439             :                 /* LCOV_EXCL_STOP */
+     440             :         }
+     441           1 :         if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) {
+     442             :                 /* LCOV_EXCL_START */
+     443             :                 log_fatal("Failed REC Cauchy test\n");
+     444             :                 exit(EXIT_FAILURE);
+     445             :                 /* LCOV_EXCL_STOP */
+     446             :         }
+     447           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) {
+     448             :                 /* LCOV_EXCL_START */
+     449             :                 log_fatal("Failed GEN Cauchy test sigle data disk\n");
+     450             :                 exit(EXIT_FAILURE);
+     451             :                 /* LCOV_EXCL_STOP */
+     452             :         }
+     453           1 : }
+     454             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/snapraid.c.func-sort-c.html b/cov/cmdline/snapraid.c.func-sort-c.html new file mode 100644 index 00000000..4934d724 --- /dev/null +++ b/cov/cmdline/snapraid.c.func-sort-c.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/snapraid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - snapraid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40944292.5 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
config242
main242
log_open235
log_close217
memory213
version2
usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/snapraid.c.func.html b/cov/cmdline/snapraid.c.func.html new file mode 100644 index 00000000..e9419154 --- /dev/null +++ b/cov/cmdline/snapraid.c.func.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - cmdline/snapraid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - snapraid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40944292.5 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
config242
log_close217
log_open235
main242
memory213
usage1
version2
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/snapraid.c.gcov.html b/cov/cmdline/snapraid.c.gcov.html new file mode 100644 index 00000000..23dbf585 --- /dev/null +++ b/cov/cmdline/snapraid.c.gcov.html @@ -0,0 +1,1281 @@ + + + + + + + LCOV - lcov.info - cmdline/snapraid.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - snapraid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40944292.5 %
Date:2015-05-12Functions:77100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "snapraid.h"
+      21             : #include "support.h"
+      22             : #include "elem.h"
+      23             : #include "import.h"
+      24             : #include "search.h"
+      25             : #include "state.h"
+      26             : #include "raid/raid.h"
+      27             : 
+      28             : /****************************************************************************/
+      29             : /* main */
+      30             : 
+      31           2 : void version(void)
+      32             : {
+      33           2 :         msg_status(PACKAGE " v" VERSION " by Andrea Mazzoleni, " PACKAGE_URL "\n");
+      34           2 : }
+      35             : 
+      36           1 : void usage(void)
+      37             : {
+      38           1 :         version();
+      39             : 
+      40           1 :         printf("Usage: " PACKAGE " status|diff|sync|scrub|list|dup|up|down|smart|pool|check|fix [options]\n");
+      41           1 :         printf("\n");
+      42           1 :         printf("Commands:\n");
+      43           1 :         printf("  status Print the status of the array\n");
+      44           1 :         printf("  diff   Show the changes that needs to be syncronized\n");
+      45           1 :         printf("  sync   Syncronize the state of the array\n");
+      46           1 :         printf("  scrub  Scrub the array\n");
+      47           1 :         printf("  list   List the array content\n");
+      48           1 :         printf("  dup    Find duplicate files\n");
+      49           1 :         printf("  up     Spinup the array\n");
+      50           1 :         printf("  down   Spindown the array\n");
+      51           1 :         printf("  smart  SMART attributes of the array\n");
+      52           1 :         printf("  pool   Create or update the virtual view of the array\n");
+      53           1 :         printf("  check  Check the array\n");
+      54           1 :         printf("  fix    Fix the array\n");
+      55           1 :         printf("\n");
+      56           1 :         printf("Options:\n");
+      57           1 :         printf("  " SWITCH_GETOPT_LONG("-c, --conf FILE       ", "-c") "  Configuration file\n");
+      58           1 :         printf("  " SWITCH_GETOPT_LONG("-f, --filter PATTERN  ", "-f") "  Process only files matching the pattern\n");
+      59           1 :         printf("  " SWITCH_GETOPT_LONG("-d, --filter-disk NAME", "-f") "  Process only files in the specified disk\n");
+      60           1 :         printf("  " SWITCH_GETOPT_LONG("-m, --filter-missing  ", "-m") "  Process only missing/deleted files\n");
+      61           1 :         printf("  " SWITCH_GETOPT_LONG("-e, --filter-error    ", "-e") "  Process only files with errors\n");
+      62           1 :         printf("  " SWITCH_GETOPT_LONG("-p, --percentage PERC ", "-p") "  Process only a part of the array\n");
+      63           1 :         printf("  " SWITCH_GETOPT_LONG("-o, --older-than DAYS ", "-o") "  Process only the older part of the array\n");
+      64           1 :         printf("  " SWITCH_GETOPT_LONG("-i, --import DIR      ", "-i") "  Import deleted files\n");
+      65           1 :         printf("  " SWITCH_GETOPT_LONG("-l, --log FILE        ", "-l") "  Log file. Default none\n");
+      66           1 :         printf("  " SWITCH_GETOPT_LONG("-a, --audit-only      ", "-a") "  Check only file data and not parity\n");
+      67           1 :         printf("  " SWITCH_GETOPT_LONG("-h, --pre-hash        ", "-h") "  Pre hash all the new data\n");
+      68           1 :         printf("  " SWITCH_GETOPT_LONG("-Z, --force-zero      ", "-Z") "  Force synching of files that get zero size\n");
+      69           1 :         printf("  " SWITCH_GETOPT_LONG("-E, --force-empty     ", "-E") "  Force synching of disks that get empty\n");
+      70           1 :         printf("  " SWITCH_GETOPT_LONG("-U, --force-uuid      ", "-U") "  Force commands on disks with uuid changed\n");
+      71           1 :         printf("  " SWITCH_GETOPT_LONG("-D, --force-device    ", "-D") "  Force commands on disks with same device id\n");
+      72           1 :         printf("  " SWITCH_GETOPT_LONG("-N, --force-nocopy    ", "-N") "  Force commands disabling the copy detection\n");
+      73           1 :         printf("  " SWITCH_GETOPT_LONG("-F, --force-full      ", "-F") "  Force commands requiring a full sync\n");
+      74           1 :         printf("  " SWITCH_GETOPT_LONG("-v, --verbose         ", "-v") "  Verbose\n");
+      75           1 : }
+      76             : 
+      77         213 : void memory(void)
+      78             : {
+      79         213 :         log_tag("memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter());
+      80             : 
+      81             :         /* size of the block + the size of the blockarr pointer to it */
+      82         213 :         log_tag("memory:block:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_block) + sizeof(void*)));
+      83             : 
+      84             :         /* size of the file + the size of the 3 hashtables pointers to it, * 2 for the hashtable grow factor */
+      85         213 :         log_tag("memory:file:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_file) + 3*2*sizeof(void*)));
+      86             : 
+      87         213 :         msg_progress("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / (1024 * 1024)));
+      88             : 
+      89         213 : }
+      90             : 
+      91             : /****************************************************************************/
+      92             : /* log */
+      93             : 
+      94         235 : void log_open(const char* log)
+      95             : {
+      96             :         char path[PATH_MAX];
+      97             :         const char* mode;
+      98             :         char text_T[32];
+      99             :         char text_D[32];
+     100             :         time_t t;
+     101             :         struct tm* tm;
+     102             : 
+     103             :         /* leave stdlog at 0 if not specified */
+     104         235 :         if (log == 0)
+     105         322 :                 return;
+     106             : 
+     107          75 :         t = time(0);
+     108          75 :         tm = localtime(&t);
+     109          75 :         if (tm) {
+     110          75 :                 strftime(text_T, sizeof(text_T), "%H%M%S", tm);
+     111          75 :                 strftime(text_D, sizeof(text_T), "%Y%m%d", tm);
+     112             :         } else {
+     113             :                 /* LCOV_EXCL_START */
+     114             :                 strcpy(text_T, "invalid");
+     115             :                 strcpy(text_D, "invalid");
+     116             :                 /* LCOV_EXCL_STOP */
+     117             :         }
+     118             : 
+     119             :         /* file mode */
+     120          75 :         mode = "wt";
+     121          75 :         if (*log == '>') {
+     122           3 :                 ++log;
+     123             : 
+     124           3 :                 if (*log == '>') {
+     125           1 :                         mode = "at";
+     126           1 :                         ++log;
+     127             :                 }
+     128             : 
+     129           3 :                 if (log[0] == '&' && log[1] == '1') {
+     130           1 :                         stdlog = stdout;
+     131           1 :                         return;
+     132             :                 }
+     133             : 
+     134           2 :                 if (log[0] == '&' && log[1] == '2') {
+     135           1 :                         stdlog = stderr;
+     136           1 :                         return;
+     137             :                 }
+     138             :         }
+     139             : 
+     140             :         /* process the path */
+     141         928 :         for (*path = 0; *log != 0; ) {
+     142         782 :                 switch (*log) {
+     143             :                 case '%' :
+     144           2 :                         ++log;
+     145           2 :                         switch (*log) {
+     146             :                         case '%' :
+     147           0 :                                 pathcatc(path, sizeof(path), '%');
+     148           0 :                                 break;
+     149             :                         case 'T' :
+     150           1 :                                 pathcat(path, sizeof(path), text_T);
+     151           1 :                                 break;
+     152             :                         case 'D' :
+     153           1 :                                 pathcat(path, sizeof(path), text_D);
+     154           1 :                                 break;
+     155             :                         default :
+     156             :                                 /* LCOV_EXCL_START */
+     157             :                                 log_fatal("Invalid type specifier '%c' in the log file.\n", *log);
+     158             :                                 exit(EXIT_FAILURE);
+     159             :                                 /* LCOV_EXCL_STOP */
+     160             :                         }
+     161           2 :                         break;
+     162             :                 default :
+     163         780 :                         pathcatc(path, sizeof(path), *log);
+     164         780 :                         break;
+     165             :                 }
+     166         782 :                 ++log;
+     167             :         }
+     168             : 
+     169          73 :         stdlog = fopen(path, mode);
+     170          73 :         if (!stdlog) {
+     171             :                 /* LCOV_EXCL_START */
+     172             :                 log_fatal("Error opening the log file '%s'. %s.\n", path, strerror(errno));
+     173             :                 exit(EXIT_FAILURE);
+     174             :                 /* LCOV_EXCL_STOP */
+     175             :         }
+     176             : }
+     177             : 
+     178         217 : void log_close(const char* log)
+     179             : {
+     180         217 :         if (stdlog != stdout && stdlog != stderr && stdlog != 0) {
+     181          73 :                 if (fclose(stdlog) != 0) {
+     182             :                         /* LCOV_EXCL_START */
+     183             :                         log_fatal("Error closing the log file '%s'. %s.\n", log, strerror(errno));
+     184             :                         exit(EXIT_FAILURE);
+     185             :                         /* LCOV_EXCL_STOP */
+     186             :                 }
+     187             :         }
+     188             : 
+     189         217 :         stdlog = 0;
+     190         217 : }
+     191             : 
+     192             : /****************************************************************************/
+     193             : /* config */
+     194             : 
+     195         242 : void config(char* conf, size_t conf_size, const char* argv0)
+     196             : {
+     197             : #ifdef _WIN32
+     198             :         char* slash;
+     199             : 
+     200             :         pathimport(conf, conf_size, argv0);
+     201             : 
+     202             :         slash = strrchr(conf, '/');
+     203             :         if (slash) {
+     204             :                 slash[1] = 0;
+     205             :                 pathcat(conf, conf_size, PACKAGE ".conf");
+     206             :         } else {
+     207             :                 pathcpy(conf, conf_size, PACKAGE ".conf");
+     208             :         }
+     209             : #else
+     210             :         (void)argv0;
+     211             : 
+     212         242 :         pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
+     213             : #endif
+     214         242 : }
+     215             : 
+     216             : /****************************************************************************/
+     217             : /* main */
+     218             : 
+     219             : #define OPT_TEST_SKIP_SELF 256
+     220             : #define OPT_TEST_KILL_AFTER_SYNC 257
+     221             : #define OPT_TEST_EXPECT_UNRECOVERABLE 258
+     222             : #define OPT_TEST_EXPECT_RECOVERABLE 259
+     223             : #define OPT_TEST_SKIP_SIGN 260
+     224             : #define OPT_TEST_SKIP_FALLOCATE 261
+     225             : #define OPT_TEST_SKIP_DEVICE 262
+     226             : #define OPT_TEST_SKIP_SEQUENTIAL 263
+     227             : #define OPT_TEST_FORCE_MURMUR3 264
+     228             : #define OPT_TEST_FORCE_SPOOKY2 265
+     229             : #define OPT_TEST_SKIP_LOCK 266
+     230             : #define OPT_TEST_FORCE_ORDER_PHYSICAL 267
+     231             : #define OPT_TEST_FORCE_ORDER_INODE 268
+     232             : #define OPT_TEST_FORCE_ORDER_ALPHA 269
+     233             : #define OPT_TEST_FORCE_ORDER_DIR 270
+     234             : #define OPT_TEST_FORCE_SCRUB_AT 271
+     235             : #define OPT_TEST_FORCE_SCRUB_EVEN 272
+     236             : #define OPT_TEST_FORCE_CONTENT_WRITE 273
+     237             : #define OPT_TEST_FORCE_CONTENT_TEXT 274
+     238             : #define OPT_TEST_SKIP_CONTENT_CHECK 275
+     239             : #define OPT_TEST_SKIP_PARITY_ACCESS 276
+     240             : #define OPT_TEST_EXPECT_FAILURE 277
+     241             : #define OPT_TEST_RUN 278
+     242             : #define OPT_TEST_FORCE_SCAN_WINFIND 279
+     243             : #define OPT_TEST_IMPORT_CONTENT 280
+     244             : #define OPT_TEST_FORCE_PROGRESS 281
+     245             : #define OPT_TEST_SKIP_DISK_ACCESS 282
+     246             : #define OPT_TEST_FORCE_AUTOSAVE_AT 283
+     247             : #define OPT_TEST_FAKE_DEVICE 284
+     248             : #define OPT_TEST_EXPECT_NEED_SYNC 285
+     249             : 
+     250             : #if HAVE_GETOPT_LONG
+     251             : struct option long_options[] = {
+     252             :         { "conf", 1, 0, 'c' },
+     253             :         { "filter", 1, 0, 'f' },
+     254             :         { "filter-disk", 1, 0, 'd' },
+     255             :         { "filter-missing", 0, 0, 'm' },
+     256             :         { "filter-error", 0, 0, 'e' },
+     257             :         { "percentage", 1, 0, 'p' },
+     258             :         { "older-than", 1, 0, 'o' },
+     259             :         { "start", 1, 0, 'S' },
+     260             :         { "count", 1, 0, 'B' },
+     261             :         { "error-limit", 1, 0, 'L' },
+     262             :         { "import", 1, 0, 'i' },
+     263             :         { "log", 1, 0, 'l' },
+     264             :         { "force-zero", 0, 0, 'Z' },
+     265             :         { "force-empty", 0, 0, 'E' },
+     266             :         { "force-uuid", 0, 0, 'U' },
+     267             :         { "force-device", 0, 0, 'D' },
+     268             :         { "force-nocopy", 0, 0, 'N' },
+     269             :         { "force-full", 0, 0, 'F' },
+     270             :         { "audit-only", 0, 0, 'a' },
+     271             :         { "pre-hash", 0, 0, 'h' },
+     272             :         { "speed-test", 0, 0, 'T' }, /* undocumented speed test command */
+     273             :         { "gen-conf", 1, 0, 'C' },
+     274             :         { "verbose", 0, 0, 'v' },
+     275             :         { "quiet", 0, 0, 'q' }, /* undocumented quiet option */
+     276             :         { "gui", 0, 0, 'G' }, /* undocumented GUI interface option */
+     277             :         { "help", 0, 0, 'H' },
+     278             :         { "version", 0, 0, 'V' },
+     279             : 
+     280             :         /* The following are test specific options, DO NOT USE! */
+     281             : 
+     282             :         /* After syncing, do not write the new content file */
+     283             :         { "test-kill-after-sync", 0, 0, OPT_TEST_KILL_AFTER_SYNC },
+     284             : 
+     285             :         /* Exit with failure if after check/fix there ARE NOT unrecoverable errors. */
+     286             :         { "test-expect-unrecoverable", 0, 0, OPT_TEST_EXPECT_UNRECOVERABLE },
+     287             : 
+     288             :         /* Exit with failure if after check/fix there ARE NOT recoverable errors. */
+     289             :         { "test-expect-recoverable", 0, 0, OPT_TEST_EXPECT_RECOVERABLE },
+     290             : 
+     291             :         /* Skip the initial self test */
+     292             :         { "test-skip-self", 0, 0, OPT_TEST_SKIP_SELF },
+     293             : 
+     294             :         /* Skip the initial sign check when reading the content file */
+     295             :         { "test-skip-sign", 0, 0, OPT_TEST_SKIP_SIGN },
+     296             : 
+     297             :         /* Skip the fallocate() when growing the parity files */
+     298             :         { "test-skip-fallocate", 0, 0, OPT_TEST_SKIP_FALLOCATE },
+     299             : 
+     300             :         /* Skip the sequential hint when reading files */
+     301             :         { "test-skip-sequential", 0, 0, OPT_TEST_SKIP_SEQUENTIAL },
+     302             : 
+     303             :         /* Skip the device check */
+     304             :         { "test-skip-device", 0, 0, OPT_TEST_SKIP_DEVICE },
+     305             : 
+     306             :         /* Force Murmur3 hash */
+     307             :         { "test-force-murmur3", 0, 0, OPT_TEST_FORCE_MURMUR3 },
+     308             : 
+     309             :         /* Force Spooky2 hash */
+     310             :         { "test-force-spooky2", 0, 0, OPT_TEST_FORCE_SPOOKY2 },
+     311             : 
+     312             :         /* Skip the use of lock file */
+     313             :         { "test-skip-lock", 0, 0, OPT_TEST_SKIP_LOCK },
+     314             : 
+     315             :         /* Force a sort order for files */
+     316             :         { "test-force-order-physical", 0, 0, OPT_TEST_FORCE_ORDER_PHYSICAL },
+     317             :         { "test-force-order-inode", 0, 0, OPT_TEST_FORCE_ORDER_INODE },
+     318             :         { "test-force-order-alpha", 0, 0, OPT_TEST_FORCE_ORDER_ALPHA },
+     319             :         { "test-force-order-dir", 0, 0, OPT_TEST_FORCE_ORDER_DIR },
+     320             : 
+     321             :         /* Force scrub of the specified number of blocks */
+     322             :         { "test-force-scrub-at", 1, 0, OPT_TEST_FORCE_SCRUB_AT },
+     323             : 
+     324             :         /* Force scrub of all the even blocks. This is really for testing, don't try it */
+     325             :         { "test-force-scrub-even", 0, 0, OPT_TEST_FORCE_SCRUB_EVEN },
+     326             : 
+     327             :         /* Force write of the content file even if no modification is done */
+     328             :         { "test-force-content-write", 0, 0, OPT_TEST_FORCE_CONTENT_WRITE },
+     329             : 
+     330             :         /* Force the use of text content file */
+     331             :         { "test-force-content-text", 0, 0, OPT_TEST_FORCE_CONTENT_TEXT },
+     332             : 
+     333             :         /* Relax the checks done at the content file */
+     334             :         { "test-skip-content-check", 0, 0, OPT_TEST_SKIP_CONTENT_CHECK },
+     335             : 
+     336             :         /* Skip the parity access */
+     337             :         { "test-skip-parity-access", 0, 0, OPT_TEST_SKIP_PARITY_ACCESS },
+     338             : 
+     339             :         /* Exit generic failure */
+     340             :         { "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE },
+     341             : 
+     342             :         /* Exit generic need sync */
+     343             :         { "test-expect-need-sync", 0, 0, OPT_TEST_EXPECT_NEED_SYNC },
+     344             : 
+     345             :         /* Run some command after loading the state and before the command */
+     346             :         { "test-run", 1, 0, OPT_TEST_RUN },
+     347             : 
+     348             :         /* Use the FindFirst/Next approach in Windows to list files */
+     349             :         { "test-force-scan-winfind", 0, 0, OPT_TEST_FORCE_SCAN_WINFIND },
+     350             : 
+     351             :         /* Alternative import working by data */
+     352             :         { "test-import-content", 1, 0, OPT_TEST_IMPORT_CONTENT },
+     353             : 
+     354             :         /* Force immediate progress state update */
+     355             :         { "test-force-progress", 0, 0, OPT_TEST_FORCE_PROGRESS },
+     356             : 
+     357             :         /* Skip the disk access */
+     358             :         { "test-skip-disk-access", 0, 0, OPT_TEST_SKIP_DISK_ACCESS },
+     359             : 
+     360             :         /* Force autosave at the specified block */
+     361             :         { "test-force-autosave-at", 1, 0, OPT_TEST_FORCE_AUTOSAVE_AT },
+     362             : 
+     363             :         /* Fake device data */
+     364             :         { "test-fake-device", 0, 0, OPT_TEST_FAKE_DEVICE },
+     365             : 
+     366             :         { 0, 0, 0, 0 }
+     367             : };
+     368             : #endif
+     369             : 
+     370             : #define OPTIONS "c:f:d:mep:o:S:B:L:i:l:ZEUDNFahTC:vqHVG"
+     371             : 
+     372             : volatile int global_interrupt = 0;
+     373             : 
+     374             : /* LCOV_EXCL_START */
+     375             : void signal_handler(int signal)
+     376             : {
+     377             :         switch (signal) {
+     378             :         case SIGINT :
+     379             :                 global_interrupt = 1;
+     380             :                 break;
+     381             :         }
+     382             : }
+     383             : /* LCOV_EXCL_STOP */
+     384             : 
+     385             : #define OPERATION_DIFF 0
+     386             : #define OPERATION_SYNC 1
+     387             : #define OPERATION_CHECK 2
+     388             : #define OPERATION_FIX 3
+     389             : #define OPERATION_DRY 4
+     390             : #define OPERATION_DUP 5
+     391             : #define OPERATION_LIST 6
+     392             : #define OPERATION_POOL 7
+     393             : #define OPERATION_REHASH 8
+     394             : #define OPERATION_SCRUB 9
+     395             : #define OPERATION_STATUS 10
+     396             : #define OPERATION_REWRITE 11
+     397             : #define OPERATION_NANO 12
+     398             : #define OPERATION_SPINUP 13
+     399             : #define OPERATION_SPINDOWN 14
+     400             : #define OPERATION_DEVICES 15
+     401             : #define OPERATION_SMART 16
+     402             : 
+     403         242 : int main(int argc, char* argv[])
+     404             : {
+     405             :         int c;
+     406             :         struct snapraid_option opt;
+     407             :         char conf[PATH_MAX];
+     408             :         struct snapraid_state state;
+     409             :         int operation;
+     410             :         block_off_t blockstart;
+     411             :         block_off_t blockcount;
+     412             :         int ret;
+     413             :         tommy_list filterlist_file;
+     414             :         tommy_list filterlist_disk;
+     415             :         int filter_missing;
+     416             :         int filter_error;
+     417             :         int percentage;
+     418             :         int olderthan;
+     419             :         char* e;
+     420             :         const char* command;
+     421             :         const char* import_timestamp;
+     422             :         const char* import_content;
+     423             :         const char* log;
+     424             :         int lock;
+     425             :         const char* gen_conf;
+     426             :         const char* run;
+     427             :         int speedtest;
+     428             :         int period;
+     429             :         time_t t;
+     430             :         struct tm* tm;
+     431             :         int i;
+     432             : 
+     433             :         /* defaults */
+     434         242 :         config(conf, sizeof(conf), argv[0]);
+     435         242 :         memset(&opt, 0, sizeof(opt));
+     436         242 :         opt.io_error_limit = 100;
+     437         242 :         blockstart = 0;
+     438         242 :         blockcount = 0;
+     439         242 :         tommy_list_init(&filterlist_file);
+     440         242 :         tommy_list_init(&filterlist_disk);
+     441         242 :         period = 1000;
+     442         242 :         filter_missing = 0;
+     443         242 :         filter_error = 0;
+     444         242 :         percentage = -1;
+     445         242 :         olderthan = -1;
+     446         242 :         import_timestamp = 0;
+     447         242 :         import_content = 0;
+     448         242 :         log = 0;
+     449         242 :         lock = 0;
+     450         242 :         gen_conf = 0;
+     451         242 :         speedtest = 0;
+     452         242 :         run = 0;
+     453             : 
+     454         242 :         opterr = 0;
+     455        2551 :         while ((c =
+     456             : #if HAVE_GETOPT_LONG
+     457             :                 getopt_long(argc, argv, OPTIONS, long_options, 0))
+     458             : #else
+     459             :                 getopt(argc, argv, OPTIONS))
+     460             : #endif
+     461             :                 != EOF) {
+     462        2069 :                 switch (c) {
+     463             :                 case 'c' :
+     464         235 :                         pathimport(conf, sizeof(conf), optarg);
+     465         235 :                         break;
+     466             :                 case 'f' : {
+     467           3 :                         struct snapraid_filter* filter = filter_alloc_file(1, optarg);
+     468           3 :                         if (!filter) {
+     469             :                                 /* LCOV_EXCL_START */
+     470             :                                 log_fatal("Invalid filter specification '%s'\n", optarg);
+     471             :                                 exit(EXIT_FAILURE);
+     472             :                                 /* LCOV_EXCL_STOP */
+     473             :                         }
+     474           3 :                         tommy_list_insert_tail(&filterlist_file, &filter->node, filter);
+     475           3 :                 } break;
+     476             :                 case 'd' : {
+     477           3 :                         struct snapraid_filter* filter = filter_alloc_disk(1, optarg);
+     478           3 :                         if (!filter) {
+     479             :                                 /* LCOV_EXCL_START */
+     480             :                                 log_fatal("Invalid filter specification '%s'\n", optarg);
+     481             :                                 exit(EXIT_FAILURE);
+     482             :                                 /* LCOV_EXCL_STOP */
+     483             :                         }
+     484           3 :                         tommy_list_insert_tail(&filterlist_disk, &filter->node, filter);
+     485           3 :                 } break;
+     486             :                 case 'm' :
+     487           2 :                         filter_missing = 1;
+     488           2 :                         opt.expected_missing = 1;
+     489           2 :                         break;
+     490             :                 case 'e' :
+     491             :                         /* when processing only error, we filter both files and blocks */
+     492             :                         /* and we apply fixes only to synced ones */
+     493           2 :                         filter_error = 1;
+     494           2 :                         opt.badonly = 1;
+     495           2 :                         opt.syncedonly = 1;
+     496           2 :                         break;
+     497             :                 case 'p' :
+     498           2 :                         percentage = strtoul(optarg, &e, 10);
+     499           2 :                         if (!e || *e || percentage > 100) {
+     500             :                                 /* LCOV_EXCL_START */
+     501             :                                 log_fatal("Invalid percentage '%s'\n", optarg);
+     502             :                                 exit(EXIT_FAILURE);
+     503             :                                 /* LCOV_EXCL_STOP */
+     504             :                         }
+     505           2 :                         break;
+     506             :                 case 'o' :
+     507           1 :                         olderthan = strtoul(optarg, &e, 10);
+     508           1 :                         if (!e || *e || olderthan > 1000) {
+     509             :                                 /* LCOV_EXCL_START */
+     510             :                                 log_fatal("Invalid number of days '%s'\n", optarg);
+     511             :                                 exit(EXIT_FAILURE);
+     512             :                                 /* LCOV_EXCL_STOP */
+     513             :                         }
+     514           1 :                         break;
+     515             :                 case 'S' :
+     516           0 :                         blockstart = strtoul(optarg, &e, 0);
+     517           0 :                         if (!e || *e) {
+     518             :                                 /* LCOV_EXCL_START */
+     519             :                                 log_fatal("Invalid start position '%s'\n", optarg);
+     520             :                                 exit(EXIT_FAILURE);
+     521             :                                 /* LCOV_EXCL_STOP */
+     522             :                         }
+     523           0 :                         break;
+     524             :                 case 'B' :
+     525           5 :                         blockcount = strtoul(optarg, &e, 0);
+     526           5 :                         if (!e || *e) {
+     527             :                                 /* LCOV_EXCL_START */
+     528             :                                 log_fatal("Invalid count number '%s'\n", optarg);
+     529             :                                 exit(EXIT_FAILURE);
+     530             :                                 /* LCOV_EXCL_STOP */
+     531             :                         }
+     532           5 :                         break;
+     533             :                 case 'L' :
+     534           0 :                         opt.io_error_limit = strtoul(optarg, &e, 0);
+     535           0 :                         if (!e || *e) {
+     536             :                                 /* LCOV_EXCL_START */
+     537             :                                 log_fatal("Invalid error limit number '%s'\n", optarg);
+     538             :                                 exit(EXIT_FAILURE);
+     539             :                                 /* LCOV_EXCL_STOP */
+     540             :                         }
+     541           0 :                         break;
+     542             :                 case 'i' :
+     543           1 :                         if (import_timestamp) {
+     544             :                                 /* LCOV_EXCL_START */
+     545             :                                 log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp);
+     546             :                                 exit(EXIT_FAILURE);
+     547             :                                 /* LCOV_EXCL_STOP */
+     548             :                         }
+     549           1 :                         import_timestamp = optarg;
+     550           1 :                         break;
+     551             :                 case OPT_TEST_IMPORT_CONTENT :
+     552           1 :                         if (import_content) {
+     553             :                                 /* LCOV_EXCL_START */
+     554             :                                 log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_content);
+     555             :                                 exit(EXIT_FAILURE);
+     556             :                                 /* LCOV_EXCL_STOP */
+     557             :                         }
+     558           1 :                         import_content = optarg;
+     559           1 :                         break;
+     560             :                 case 'l' :
+     561          75 :                         if (log) {
+     562             :                                 /* LCOV_EXCL_START */
+     563             :                                 log_fatal("Log file '%s' already specified as '%s'\n", optarg, log);
+     564             :                                 exit(EXIT_FAILURE);
+     565             :                                 /* LCOV_EXCL_STOP */
+     566             :                         }
+     567          75 :                         log = optarg;
+     568          75 :                         break;
+     569             :                 case 'Z' :
+     570           0 :                         opt.force_zero = 1;
+     571           0 :                         break;
+     572             :                 case 'E' :
+     573           1 :                         opt.force_empty = 1;
+     574           1 :                         break;
+     575             :                 case 'U' :
+     576           0 :                         opt.force_uuid = 1;
+     577           0 :                         break;
+     578             :                 case 'D' :
+     579           0 :                         opt.force_device = 1;
+     580           0 :                         break;
+     581             :                 case 'N' :
+     582           1 :                         opt.force_nocopy = 1;
+     583           1 :                         break;
+     584             :                 case 'F' :
+     585           1 :                         opt.force_full = 1;
+     586           1 :                         break;
+     587             :                 case 'a' :
+     588           6 :                         opt.auditonly = 1;
+     589           6 :                         break;
+     590             :                 case 'h' :
+     591           6 :                         opt.prehash = 1;
+     592           6 :                         break;
+     593             :                 case 'v' :
+     594          20 :                         ++msg_level;
+     595          20 :                         break;
+     596             :                 case 'q' :
+     597         645 :                         --msg_level;
+     598         645 :                         break;
+     599             :                 case 'G' :
+     600          20 :                         opt.gui = 1;
+     601          20 :                         break;
+     602             :                 case 'H' :
+     603           1 :                         usage();
+     604           1 :                         exit(EXIT_SUCCESS);
+     605             :                 case 'V' :
+     606           1 :                         version();
+     607           1 :                         exit(EXIT_SUCCESS);
+     608             :                 case 'T' :
+     609           4 :                         speedtest = 1;
+     610           4 :                         break;
+     611             :                 case 'C' :
+     612           1 :                         gen_conf = optarg;
+     613           1 :                         break;
+     614             :                 case OPT_TEST_KILL_AFTER_SYNC :
+     615           9 :                         opt.kill_after_sync = 1;
+     616           9 :                         break;
+     617             :                 case OPT_TEST_EXPECT_UNRECOVERABLE :
+     618          13 :                         opt.expect_unrecoverable = 1;
+     619          13 :                         break;
+     620             :                 case OPT_TEST_EXPECT_RECOVERABLE :
+     621          22 :                         opt.expect_recoverable = 1;
+     622          22 :                         break;
+     623             :                 case OPT_TEST_SKIP_SELF :
+     624         235 :                         opt.skip_self = 1;
+     625         235 :                         break;
+     626             :                 case OPT_TEST_SKIP_SIGN :
+     627           0 :                         opt.skip_sign = 1;
+     628           0 :                         break;
+     629             :                 case OPT_TEST_SKIP_FALLOCATE :
+     630           1 :                         opt.skip_fallocate = 1;
+     631           1 :                         break;
+     632             :                 case OPT_TEST_SKIP_SEQUENTIAL :
+     633           1 :                         opt.skip_sequential = 1;
+     634           1 :                         break;
+     635             :                 case OPT_TEST_SKIP_DEVICE :
+     636         242 :                         opt.skip_device = 1;
+     637         242 :                         period = 50; /* reduce period of the speed test */
+     638         242 :                         break;
+     639             :                 case OPT_TEST_SKIP_CONTENT_CHECK :
+     640           0 :                         opt.skip_content_check = 1;
+     641           0 :                         break;
+     642             :                 case OPT_TEST_SKIP_PARITY_ACCESS :
+     643           0 :                         opt.skip_parity_access = 1;
+     644           0 :                         break;
+     645             :                 case OPT_TEST_SKIP_DISK_ACCESS :
+     646           0 :                         opt.skip_disk_access = 1;
+     647           0 :                         break;
+     648             :                 case OPT_TEST_FORCE_MURMUR3 :
+     649           1 :                         opt.force_murmur3 = 1;
+     650           1 :                         break;
+     651             :                 case OPT_TEST_FORCE_SPOOKY2 :
+     652           1 :                         opt.force_spooky2 = 1;
+     653           1 :                         break;
+     654             :                 case OPT_TEST_SKIP_LOCK :
+     655           0 :                         opt.skip_lock = 1;
+     656           0 :                         break;
+     657             :                 case OPT_TEST_FORCE_ORDER_PHYSICAL :
+     658           2 :                         opt.force_order = SORT_PHYSICAL;
+     659           2 :                         break;
+     660             :                 case OPT_TEST_FORCE_ORDER_INODE :
+     661           0 :                         opt.force_order = SORT_INODE;
+     662           0 :                         break;
+     663             :                 case OPT_TEST_FORCE_ORDER_ALPHA :
+     664         233 :                         opt.force_order = SORT_ALPHA;
+     665         233 :                         break;
+     666             :                 case OPT_TEST_FORCE_ORDER_DIR :
+     667           0 :                         opt.force_order = SORT_DIR;
+     668           0 :                         break;
+     669             :                 case OPT_TEST_FORCE_SCRUB_AT :
+     670           4 :                         opt.force_scrub_at = atoi(optarg);
+     671           4 :                         break;
+     672             :                 case OPT_TEST_FORCE_SCRUB_EVEN :
+     673           1 :                         opt.force_scrub_even = 1;
+     674           1 :                         break;
+     675             :                 case OPT_TEST_FORCE_CONTENT_WRITE :
+     676           0 :                         opt.force_content_write = 1;
+     677           0 :                         break;
+     678             :                 case OPT_TEST_FORCE_CONTENT_TEXT :
+     679           4 :                         opt.force_content_text = 1;
+     680           4 :                         break;
+     681             :                 case OPT_TEST_EXPECT_FAILURE :
+     682             :                         /* invert the exit codes */
+     683          13 :                         exit_success = 1;
+     684          13 :                         exit_failure = 0;
+     685          13 :                         break;
+     686             :                 case OPT_TEST_EXPECT_NEED_SYNC :
+     687             :                         /* invert the exit codes */
+     688           5 :                         exit_success = 1;
+     689           5 :                         exit_sync_needed = 0;
+     690           5 :                         break;
+     691             :                 case OPT_TEST_RUN :
+     692          10 :                         run = optarg;
+     693          10 :                         break;
+     694             :                 case OPT_TEST_FORCE_SCAN_WINFIND :
+     695           0 :                         opt.force_scan_winfind = 1;
+     696           0 :                         break;
+     697             :                 case OPT_TEST_FORCE_PROGRESS :
+     698         233 :                         opt.force_progress = 1;
+     699         233 :                         break;
+     700             :                 case OPT_TEST_FORCE_AUTOSAVE_AT :
+     701           1 :                         opt.force_autosave_at = atoi(optarg);
+     702           1 :                         break;
+     703             :                 case OPT_TEST_FAKE_DEVICE :
+     704           1 :                         opt.fake_device = 1;
+     705           1 :                         break;
+     706             :                 default :
+     707             :                         /* LCOV_EXCL_START */
+     708             :                         log_fatal("Unknown option '%c'\n", (char)c);
+     709             :                         exit(EXIT_FAILURE);
+     710             :                         /* LCOV_EXCL_STOP */
+     711             :                 }
+     712             :         }
+     713             : 
+     714         240 :         os_init(opt.force_scan_winfind);
+     715         240 :         raid_init();
+     716         240 :         crc32c_init();
+     717             : 
+     718         240 :         if (speedtest != 0) {
+     719           4 :                 speed(period);
+     720           4 :                 os_done();
+     721           4 :                 exit(EXIT_SUCCESS);
+     722             :         }
+     723             : 
+     724         236 :         if (gen_conf != 0) {
+     725           1 :                 generate_configuration(gen_conf);
+     726           1 :                 os_done();
+     727           1 :                 exit(EXIT_SUCCESS);
+     728             :         }
+     729             : 
+     730         235 :         if (optind + 1 != argc) {
+     731             :                 /* LCOV_EXCL_START */
+     732             :                 usage();
+     733             :                 exit(EXIT_FAILURE);
+     734             :                 /* LCOV_EXCL_STOP */
+     735             :         }
+     736             : 
+     737         235 :         command = argv[optind];
+     738         235 :         if (strcmp(command, "diff") == 0) {
+     739           6 :                 operation = OPERATION_DIFF;
+     740         229 :         } else if (strcmp(argv[optind], "sync") == 0) {
+     741          64 :                 operation = OPERATION_SYNC;
+     742         165 :         } else if (strcmp(argv[optind], "check") == 0) {
+     743          76 :                 operation = OPERATION_CHECK;
+     744          89 :         } else if (strcmp(argv[optind], "fix") == 0) {
+     745          44 :                 operation = OPERATION_FIX;
+     746          45 :         } else if (strcmp(argv[optind], "test-dry") == 0) {
+     747           2 :                 operation = OPERATION_DRY;
+     748          43 :         } else if (strcmp(argv[optind], "dup") == 0) {
+     749           3 :                 operation = OPERATION_DUP;
+     750          40 :         } else if (strcmp(argv[optind], "list") == 0) {
+     751           3 :                 operation = OPERATION_LIST;
+     752          37 :         } else if (strcmp(argv[optind], "pool") == 0) {
+     753           3 :                 operation = OPERATION_POOL;
+     754          34 :         } else if (strcmp(argv[optind], "rehash") == 0) {
+     755           1 :                 operation = OPERATION_REHASH;
+     756          33 :         } else if (strcmp(argv[optind], "scrub") == 0) {
+     757           9 :                 operation = OPERATION_SCRUB;
+     758          24 :         } else if (strcmp(argv[optind], "status") == 0) {
+     759          14 :                 operation = OPERATION_STATUS;
+     760          10 :         } else if (strcmp(argv[optind], "test-rewrite") == 0) {
+     761           4 :                 operation = OPERATION_REWRITE;
+     762           6 :         } else if (strcmp(argv[optind], "test-nano") == 0) {
+     763           1 :                 operation = OPERATION_NANO;
+     764           5 :         } else if (strcmp(argv[optind], "up") == 0) {
+     765           1 :                 operation = OPERATION_SPINUP;
+     766           4 :         } else if (strcmp(argv[optind], "down") == 0) {
+     767           1 :                 operation = OPERATION_SPINDOWN;
+     768           3 :         } else if (strcmp(argv[optind], "devices") == 0) {
+     769           1 :                 operation = OPERATION_DEVICES;
+     770           2 :         } else if (strcmp(argv[optind], "smart") == 0) {
+     771           2 :                 operation = OPERATION_SMART;
+     772             :         } else {
+     773             :                 /* LCOV_EXCL_START */
+     774             :                 log_fatal("Unknown command '%s'\n", argv[optind]);
+     775             :                 exit(EXIT_FAILURE);
+     776             :                 /* LCOV_EXCL_STOP */
+     777             :         }
+     778             : 
+     779             :         /* check options compatibility */
+     780         235 :         switch (operation) {
+     781             :         case OPERATION_CHECK :
+     782          76 :                 break;
+     783             :         default :
+     784         159 :                 if (opt.auditonly) {
+     785             :                         /* LCOV_EXCL_START */
+     786             :                         log_fatal("You cannot use -a, --audit-only with the '%s' command\n", command);
+     787             :                         exit(EXIT_FAILURE);
+     788             :                         /* LCOV_EXCL_STOP */
+     789             :                 }
+     790             :         }
+     791             : 
+     792         235 :         switch (operation) {
+     793             :         case OPERATION_SYNC :
+     794             :         case OPERATION_CHECK :
+     795             :         case OPERATION_FIX :
+     796         184 :                 break;
+     797             :         default :
+     798          51 :                 if (opt.force_nocopy) {
+     799             :                         /* LCOV_EXCL_START */
+     800             :                         log_fatal("You cannot use -N, --force-nocopy with the '%s' command\n", command);
+     801             :                         exit(EXIT_FAILURE);
+     802             :                         /* LCOV_EXCL_STOP */
+     803             :                 }
+     804             :         }
+     805             : 
+     806         235 :         switch (operation) {
+     807             :         case OPERATION_SYNC :
+     808          64 :                 break;
+     809             :         default :
+     810         171 :                 if (opt.prehash) {
+     811             :                         /* LCOV_EXCL_START */
+     812             :                         log_fatal("You cannot use -h, --pre-hash with the '%s' command\n", command);
+     813             :                         exit(EXIT_FAILURE);
+     814             :                         /* LCOV_EXCL_STOP */
+     815             :                 }
+     816             : 
+     817         171 :                 if (opt.force_full) {
+     818             :                         /* LCOV_EXCL_START */
+     819             :                         log_fatal("You cannot use -F, --force-full with the '%s' command\n", command);
+     820             :                         exit(EXIT_FAILURE);
+     821             :                         /* LCOV_EXCL_STOP */
+     822             :                 }
+     823             :         }
+     824             : 
+     825         235 :         if (opt.force_full && opt.force_nocopy) {
+     826             :                 /* LCOV_EXCL_START */
+     827             :                 log_fatal("You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n");
+     828             :                 exit(EXIT_FAILURE);
+     829             :                 /* LCOV_EXCL_STOP */
+     830             :         }
+     831             : 
+     832         235 :         if (opt.prehash && opt.force_nocopy) {
+     833             :                 /* LCOV_EXCL_START */
+     834             :                 log_fatal("You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n");
+     835             :                 exit(EXIT_FAILURE);
+     836             :                 /* LCOV_EXCL_STOP */
+     837             :         }
+     838             : 
+     839         235 :         switch (operation) {
+     840             :         case OPERATION_CHECK :
+     841             :         case OPERATION_FIX :
+     842             :         case OPERATION_DRY :
+     843         122 :                 break;
+     844             :         default :
+     845         113 :                 if (!tommy_list_empty(&filterlist_file)) {
+     846             :                         /* LCOV_EXCL_START */
+     847             :                         log_fatal("You cannot use -f, --filter with the '%s' command\n", command);
+     848             :                         exit(EXIT_FAILURE);
+     849             :                         /* LCOV_EXCL_STOP */
+     850             :                 }
+     851         113 :                 if (!tommy_list_empty(&filterlist_disk)) {
+     852             :                         /* LCOV_EXCL_START */
+     853             :                         log_fatal("You cannot use -d, --filter-disk with the '%s' command\n", command);
+     854             :                         exit(EXIT_FAILURE);
+     855             :                         /* LCOV_EXCL_STOP */
+     856             :                 }
+     857         113 :                 if (filter_missing != 0) {
+     858             :                         /* LCOV_EXCL_START */
+     859             :                         log_fatal("You cannot use -m, --filter-missing with the '%s' command\n", command);
+     860             :                         exit(EXIT_FAILURE);
+     861             :                         /* LCOV_EXCL_STOP */
+     862             :                 }
+     863         113 :                 if (filter_error != 0) {
+     864             :                         /* LCOV_EXCL_START */
+     865             :                         log_fatal("You cannot use -e, --filter-error with the '%s' command\n", command);
+     866             :                         exit(EXIT_FAILURE);
+     867             :                         /* LCOV_EXCL_STOP */
+     868             :                 }
+     869             :         }
+     870             : 
+     871         235 :         switch (operation) {
+     872             :         case OPERATION_CHECK :
+     873             :         case OPERATION_FIX :
+     874         120 :                 break;
+     875             :         default :
+     876         115 :                 if (import_timestamp != 0 || import_content != 0) {
+     877             :                         /* LCOV_EXCL_START */
+     878             :                         log_fatal("You cannot import with the '%s' command\n", command);
+     879             :                         exit(EXIT_FAILURE);
+     880             :                         /* LCOV_EXCL_STOP */
+     881             :                 }
+     882             :         }
+     883             : 
+     884         235 :         switch (operation) {
+     885             :         case OPERATION_LIST :
+     886             :         case OPERATION_DUP :
+     887             :         case OPERATION_STATUS :
+     888             :         case OPERATION_REWRITE :
+     889             :         case OPERATION_REHASH :
+     890             :         case OPERATION_SPINUP : /* we want to do it in different threads to avoid blocking */
+     891             :                 /* avoid to check and access data disks if not needed */
+     892          26 :                 opt.skip_disk_access = 1;
+     893          26 :                 break;
+     894             :         }
+     895             : 
+     896         235 :         switch (operation) {
+     897             :         case OPERATION_DIFF :
+     898             :         case OPERATION_LIST :
+     899             :         case OPERATION_DUP :
+     900             :         case OPERATION_POOL :
+     901             :         case OPERATION_STATUS :
+     902             :         case OPERATION_REWRITE :
+     903             :         case OPERATION_REHASH :
+     904             :         case OPERATION_NANO :
+     905             :         case OPERATION_SPINUP : /* we want to do it in different threads to avoid blocking */
+     906             :                 /* avoid to check and access parity disks if not needed */
+     907          36 :                 opt.skip_parity_access = 1;
+     908          36 :                 break;
+     909             :         }
+     910             : 
+     911         235 :         switch (operation) {
+     912             :         case OPERATION_DIFF :
+     913             :         case OPERATION_LIST :
+     914             :         case OPERATION_DUP :
+     915             :         case OPERATION_POOL :
+     916             :         case OPERATION_NANO :
+     917             :         case OPERATION_SPINUP :
+     918             :         case OPERATION_SPINDOWN :
+     919             :         case OPERATION_DEVICES :
+     920             :         case OPERATION_SMART :
+     921          21 :                 opt.skip_self = 1;
+     922          21 :                 break;
+     923             :         }
+     924             : 
+     925         235 :         switch (operation) {
+     926             :         case OPERATION_DEVICES :
+     927             :         case OPERATION_SMART :
+     928             :                 /* we may need to use these commands during operations */
+     929           3 :                 opt.skip_lock = 1;
+     930           3 :                 break;
+     931             :         }
+     932             : 
+     933             :         /* open the log file */
+     934         235 :         log_open(log);
+     935             : 
+     936             :         /* print generic info into the log */
+     937         235 :         t = time(0);
+     938         235 :         tm = localtime(&t);
+     939         235 :         log_tag("version:%s\n", PACKAGE_VERSION);
+     940         235 :         log_tag("unixtime:%" PRIi64 "\n", (int64_t)t);
+     941         235 :         if (tm) {
+     942             :                 char datetime[64];
+     943         235 :                 strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm);
+     944         235 :                 log_tag("time:%s\n", datetime);
+     945             :         }
+     946         235 :         log_tag("command:%s\n", command);
+     947        3095 :         for (i = 0; i < argc; ++i)
+     948        2860 :                 log_tag("argv:%u:%s\n", i, argv[i]);
+     949         235 :         log_flush();
+     950             : 
+     951         235 :         if (!opt.skip_self)
+     952           1 :                 selftest();
+     953             : 
+     954         235 :         state_init(&state);
+     955             : 
+     956             :         /* read the configuration file */
+     957         235 :         state_config(&state, conf, command, &opt, &filterlist_disk);
+     958             : 
+     959             :         /* set the raid mode */
+     960         235 :         raid_mode(state.raid_mode);
+     961             : 
+     962             : #if HAVE_LOCKFILE
+     963             :         /* create the lock file */
+     964         235 :         if (!opt.skip_lock) {
+     965         232 :                 lock = lock_lock(state.lockfile);
+     966         232 :                 if (lock == -1) {
+     967             :                         /* LCOV_EXCL_START */
+     968             :                         if (errno != EWOULDBLOCK) {
+     969             :                                 log_fatal("Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
+     970             :                         } else {
+     971             :                                 log_fatal("The lock file '%s' is already locked!\n", state.lockfile);
+     972             :                                 log_fatal("SnapRAID is already in use!\n");
+     973             :                         }
+     974             :                         exit(EXIT_FAILURE);
+     975             :                         /* LCOV_EXCL_STOP */
+     976             :                 }
+     977             :         }
+     978             : #else
+     979             :         (void)lock;
+     980             : #endif
+     981             : 
+     982         235 :         if (operation == OPERATION_DIFF) {
+     983           6 :                 state_read(&state);
+     984             : 
+     985           6 :                 ret = state_diff(&state);
+     986             : 
+     987             :                 /* abort if sync needed */
+     988           6 :                 if (ret > 0)
+     989           5 :                         exit(EXIT_SYNC_NEEDED);
+     990         229 :         } else if (operation == OPERATION_SYNC) {
+     991             : 
+     992             :                 /* in the next state read ensures to clear all the past hashes in case */
+     993             :                 /* we are reading from an incomplete sync */
+     994             :                 /* The undeterminated hash are only for CHG/DELETED blocks for which we don't */
+     995             :                 /* know if the previous interrupted sync was able to update or not the parity */
+     996             :                 /* The sync process instead needs to trust this information because it's used */
+     997             :                 /* to avoid to recompute the parity if all the input are equals as before. */
+     998          64 :                 state.clear_past_hash = 1;
+     999             : 
+    1000          64 :                 state_read(&state);
+    1001             : 
+    1002          63 :                 state_scan(&state);
+    1003             : 
+    1004             :                 /* refresh the size info before the content write */
+    1005          63 :                 state_refresh(&state);
+    1006             : 
+    1007          63 :                 memory();
+    1008             : 
+    1009             :                 /* intercept Ctrl+C */
+    1010          63 :                 signal(SIGINT, &signal_handler);
+    1011             : 
+    1012             :                 /* save the new state before the sync */
+    1013             :                 /* this allow to recover the case of the changes in the array after an aborted sync. */
+    1014             : 
+    1015             :                 /* for example, think at this case: */
+    1016             :                 /* - add some files at the array */
+    1017             :                 /* - run a sync command, it will recompute the parity adding the new files */
+    1018             :                 /* - abort the sync command before it stores the new content file */
+    1019             :                 /* - delete the not yet synced files from the array */
+    1020             :                 /* - run a new sync command */
+    1021             : 
+    1022             :                 /* the new sync command has now way to know that the parity file was modified */
+    1023             :                 /* because the files triggering these changes are now deleted */
+    1024             :                 /* and they aren't listed in the content file */
+    1025             : 
+    1026          63 :                 if (state.need_write)
+    1027          61 :                         state_write(&state);
+    1028             : 
+    1029             :                 /* run a test command if required */
+    1030          63 :                 if (run != 0) {
+    1031          10 :                         ret = system(run); /* ignore error */
+    1032          10 :                         if (ret != 0) {
+    1033             :                                 /* LCOV_EXCL_START */
+    1034             :                                 log_fatal("Error in running command '%s'.\n", run);
+    1035             :                                 exit(EXIT_FAILURE);
+    1036             :                                 /* LCOV_EXCL_STOP */
+    1037             :                         }
+    1038             :                 }
+    1039             : 
+    1040             :                 /* waits some time to ensure that any concurrent modification done at the files, */
+    1041             :                 /* using the same mtime read by the scan process, will be read by sync. */
+    1042             :                 /* Note that any later modification done, potentially not read by sync, will have */
+    1043             :                 /* a different mtime, and it will be syncronized at the next sync. */
+    1044             :                 /* The worst case is the FAT filesystem with a two seconds resolution for mtime. */
+    1045             :                 /* If you don't use FAT, the wait is not needed, because most filesystems have now */
+    1046             :                 /* at least microseconds resolution, but better to be safe. */
+    1047          63 :                 if (!opt.skip_self)
+    1048           0 :                         sleep(2);
+    1049             : 
+    1050          63 :                 ret = state_sync(&state, blockstart, blockcount);
+    1051             : 
+    1052             :                 /* save the new state if required */
+    1053          63 :                 if (!opt.kill_after_sync && (state.need_write || state.opt.force_content_write))
+    1054          41 :                         state_write(&state);
+    1055             : 
+    1056             :                 /* abort if required */
+    1057          63 :                 if (ret != 0) {
+    1058             :                         /* LCOV_EXCL_START */
+    1059             :                         exit(EXIT_FAILURE);
+    1060             :                         /* LCOV_EXCL_STOP */
+    1061             :                 }
+    1062         165 :         } else if (operation == OPERATION_DRY) {
+    1063           2 :                 state_read(&state);
+    1064             : 
+    1065             :                 /* apply the command line filter */
+    1066           2 :                 state_filter(&state, &filterlist_file, &filterlist_disk, filter_missing, filter_error);
+    1067             : 
+    1068           2 :                 memory();
+    1069             : 
+    1070             :                 /* intercept Ctrl+C */
+    1071           2 :                 signal(SIGINT, &signal_handler);
+    1072             : 
+    1073           2 :                 state_dry(&state, blockstart, blockcount);
+    1074         163 :         } else if (operation == OPERATION_REHASH) {
+    1075           1 :                 state_read(&state);
+    1076             : 
+    1077             :                 /* intercept Ctrl+C */
+    1078           1 :                 signal(SIGINT, &signal_handler);
+    1079             : 
+    1080           1 :                 state_rehash(&state);
+    1081             : 
+    1082             :                 /* save the new state if required */
+    1083           1 :                 if (state.need_write)
+    1084           1 :                         state_write(&state);
+    1085         162 :         } else if (operation == OPERATION_SCRUB) {
+    1086           9 :                 state_read(&state);
+    1087             : 
+    1088           9 :                 memory();
+    1089             : 
+    1090             :                 /* intercept Ctrl+C */
+    1091           9 :                 signal(SIGINT, &signal_handler);
+    1092             : 
+    1093           9 :                 ret = state_scrub(&state, percentage, olderthan);
+    1094             : 
+    1095             :                 /* save the new state if required */
+    1096           9 :                 if (state.need_write || state.opt.force_content_write)
+    1097           8 :                         state_write(&state);
+    1098             : 
+    1099             :                 /* abort if required */
+    1100           9 :                 if (ret != 0) {
+    1101             :                         /* LCOV_EXCL_START */
+    1102             :                         exit(EXIT_FAILURE);
+    1103             :                         /* LCOV_EXCL_STOP */
+    1104             :                 }
+    1105         153 :         } else if (operation == OPERATION_REWRITE) {
+    1106           4 :                 state_read(&state);
+    1107             : 
+    1108           4 :                 state_write(&state);
+    1109             : 
+    1110           4 :                 memory();
+    1111         149 :         } else if (operation == OPERATION_NANO) {
+    1112           1 :                 state_read(&state);
+    1113             : 
+    1114           1 :                 state_nano(&state);
+    1115             : 
+    1116           1 :                 state_write(&state);
+    1117             : 
+    1118           1 :                 memory();
+    1119         148 :         } else if (operation == OPERATION_SPINUP) {
+    1120           1 :                 state_device(&state, DEVICE_UP);
+    1121         147 :         } else if (operation == OPERATION_SPINDOWN) {
+    1122           1 :                 state_device(&state, DEVICE_DOWN);
+    1123         146 :         } else if (operation == OPERATION_DEVICES) {
+    1124           1 :                 state_device(&state, DEVICE_LIST);
+    1125         145 :         } else if (operation == OPERATION_SMART) {
+    1126           2 :                 state_device(&state, DEVICE_SMART);
+    1127         143 :         } else if (operation == OPERATION_STATUS) {
+    1128          14 :                 state_read(&state);
+    1129             : 
+    1130          14 :                 memory();
+    1131             : 
+    1132          14 :                 state_status(&state);
+    1133         129 :         } else if (operation == OPERATION_DUP) {
+    1134           3 :                 state_read(&state);
+    1135             : 
+    1136           3 :                 state_dup(&state);
+    1137         126 :         } else if (operation == OPERATION_LIST) {
+    1138           3 :                 state_read(&state);
+    1139             : 
+    1140           3 :                 state_list(&state);
+    1141         123 :         } else if (operation == OPERATION_POOL) {
+    1142           3 :                 state_read(&state);
+    1143             : 
+    1144           3 :                 state_pool(&state);
+    1145             :         } else {
+    1146         120 :                 state_read(&state);
+    1147             : 
+    1148             :                 /* if we are also trying to recover */
+    1149         120 :                 if (!state.opt.auditonly) {
+    1150             :                         /* import the user specified dirs */
+    1151         114 :                         if (import_timestamp != 0)
+    1152           1 :                                 state_search(&state, import_timestamp);
+    1153         114 :                         if (import_content != 0)
+    1154           1 :                                 state_import(&state, import_content);
+    1155             : 
+    1156             :                         /* import from all the array */
+    1157         114 :                         if (!state.opt.force_nocopy)
+    1158         114 :                                 state_search_array(&state);
+    1159             :                 }
+    1160             : 
+    1161             :                 /* apply the command line filter */
+    1162         120 :                 state_filter(&state, &filterlist_file, &filterlist_disk, filter_missing, filter_error);
+    1163             : 
+    1164         120 :                 memory();
+    1165             : 
+    1166             :                 /* intercept Ctrl+C */
+    1167         120 :                 signal(SIGINT, &signal_handler);
+    1168             : 
+    1169         120 :                 if (operation == OPERATION_CHECK) {
+    1170          76 :                         ret = state_check(&state, 0, blockstart, blockcount);
+    1171             :                 } else { /* it's fix */
+    1172          44 :                         ret = state_check(&state, 1, blockstart, blockcount);
+    1173             :                 }
+    1174             : 
+    1175             :                 /* abort if required */
+    1176         120 :                 if (ret != 0) {
+    1177             :                         /* LCOV_EXCL_START */
+    1178             :                         exit(EXIT_FAILURE);
+    1179             :                         /* LCOV_EXCL_STOP */
+    1180             :                 }
+    1181             :         }
+    1182             : 
+    1183             :         /* close log file */
+    1184         217 :         log_close(log);
+    1185             : 
+    1186             : #if HAVE_LOCKFILE
+    1187         217 :         if (!opt.skip_lock) {
+    1188         215 :                 if (lock_unlock(lock) == -1) {
+    1189             :                         /* LCOV_EXCL_START */
+    1190             :                         log_fatal("Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
+    1191             :                         exit(EXIT_FAILURE);
+    1192             :                         /* LCOV_EXCL_STOP */
+    1193             :                 }
+    1194             :         }
+    1195             : #endif
+    1196             : 
+    1197         217 :         state_done(&state);
+    1198         217 :         tommy_list_foreach(&filterlist_file, (tommy_foreach_func*)filter_free);
+    1199         217 :         tommy_list_foreach(&filterlist_disk, (tommy_foreach_func*)filter_free);
+    1200             : 
+    1201         217 :         os_done();
+    1202             : 
+    1203         217 :         return EXIT_SUCCESS;
+    1204             : }
+    1205             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/speed.c.func-sort-c.html b/cov/cmdline/speed.c.func-sort-c.html new file mode 100644 index 00000000..6bd46e8e --- /dev/null +++ b/cov/cmdline/speed.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/speed.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - speed.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40340499.8 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
diffgettimeofday1839
speed4
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/speed.c.func.html b/cov/cmdline/speed.c.func.html new file mode 100644 index 00000000..6fd9f927 --- /dev/null +++ b/cov/cmdline/speed.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - cmdline/speed.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - speed.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40340499.8 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
diffgettimeofday1839
speed4
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/speed.c.gcov.html b/cov/cmdline/speed.c.gcov.html new file mode 100644 index 00000000..d25ad510 --- /dev/null +++ b/cov/cmdline/speed.c.gcov.html @@ -0,0 +1,1016 @@ + + + + + + + LCOV - lcov.info - cmdline/speed.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - speed.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:40340499.8 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "snapraid.h"
+      21             : #include "util.h"
+      22             : #include "raid/raid.h"
+      23             : #include "raid/cpu.h"
+      24             : #include "raid/internal.h"
+      25             : #include "raid/memory.h"
+      26             : #include "state.h"
+      27             : 
+      28             : /*
+      29             :  * Size of the blocks to test.
+      30             :  */
+      31             : #define TEST_SIZE (256 * 1024)
+      32             : 
+      33             : /*
+      34             :  * Number of data blocks to test.
+      35             :  */
+      36             : #define TEST_COUNT (8)
+      37             : 
+      38             : /**
+      39             :  * Differential us of two timeval.
+      40             :  */
+      41        1839 : static int64_t diffgettimeofday(struct timeval *start, struct timeval *stop)
+      42             : {
+      43             :         int64_t d;
+      44             : 
+      45        1839 :         d = 1000000LL * (stop->tv_sec - start->tv_sec);
+      46        1839 :         d += stop->tv_usec - start->tv_usec;
+      47             : 
+      48        1839 :         return d;
+      49             : }
+      50             : 
+      51             : /**
+      52             :  * Start time measurement.
+      53             :  */
+      54             : #define SPEED_START \
+      55             :         count = 0; \
+      56             :         gettimeofday(&start, 0); \
+      57             :         do { \
+      58             :                 for (i = 0; i < delta; ++i)
+      59             : 
+      60             : /**
+      61             :  * Stop time measurement.
+      62             :  */
+      63             : #define SPEED_STOP \
+      64             :                 count += delta; \
+      65             :                 gettimeofday(&stop, 0); \
+      66             :         } while (diffgettimeofday(&start, &stop) < period * 1000LL) ; \
+      67             :         ds = size * (int64_t)count * nd; \
+      68             :         dt = diffgettimeofday(&start, &stop);
+      69             : 
+      70           4 : void speed(int period)
+      71             : {
+      72             :         struct timeval start;
+      73             :         struct timeval stop;
+      74             :         int64_t ds;
+      75             :         int64_t dt;
+      76             :         int i, j;
+      77             :         unsigned char digest[HASH_SIZE];
+      78             :         unsigned char seed[HASH_SIZE];
+      79             :         int id[RAID_PARITY_MAX];
+      80             :         int ip[RAID_PARITY_MAX];
+      81             :         int count;
+      82           4 :         int delta = period >= 1000 ? 10 : 1;
+      83           4 :         int size = TEST_SIZE;
+      84           4 :         int nd = TEST_COUNT;
+      85             :         int nv;
+      86             :         void *v_alloc;
+      87             :         void **v;
+      88             : 
+      89           4 :         nv = nd + RAID_PARITY_MAX + 1;
+      90             : 
+      91           4 :         v = malloc_nofail_vector_align(nd, nv, size, &v_alloc);
+      92             : 
+      93             :         /* initialize disks with fixed data */
+      94          36 :         for (i = 0; i < nd; ++i)
+      95          32 :                 memset(v[i], i, size);
+      96             : 
+      97             :         /* zero buffer */
+      98           4 :         memset(v[nd + RAID_PARITY_MAX], 0, size);
+      99           4 :         raid_zero(v[nd + RAID_PARITY_MAX]);
+     100             : 
+     101             :         /* hash seed */
+     102          68 :         for (i = 0; i < HASH_SIZE; ++i)
+     103          64 :                 seed[i] = i;
+     104             : 
+     105             :         /* basic disks and parity mapping */
+     106          28 :         for (i = 0; i < RAID_PARITY_MAX; ++i) {
+     107          24 :                 id[i] = i;
+     108          24 :                 ip[i] = i;
+     109             :         }
+     110             : 
+     111           4 :         printf(PACKAGE " v" VERSION " by Andrea Mazzoleni, " PACKAGE_URL "\n");
+     112             : 
+     113             : #ifdef __GNUC__
+     114           4 :         printf("Compiler gcc " __VERSION__ "\n");
+     115             : #endif
+     116             : 
+     117             : #ifdef CONFIG_X86
+     118             :         {
+     119             :                 char vendor[CPU_VENDOR_MAX];
+     120             :                 unsigned family;
+     121             :                 unsigned model;
+     122             : 
+     123           4 :                 raid_cpu_info(vendor, &family, &model);
+     124             : 
+     125          24 :                 printf("CPU %s, family %u, model %u, flags%s%s%s%s%s%s\n", vendor, family, model,
+     126           4 :                         raid_cpu_has_sse2() ? " sse2" : "",
+     127           4 :                         raid_cpu_has_ssse3() ? " ssse3" : "",
+     128           4 :                         raid_cpu_has_crc32() ? " crc32" : "",
+     129           4 :                         raid_cpu_has_avx2() ? " avx2" : "",
+     130           4 :                         raid_cpu_has_slowmult() ? " slowmult" : "",
+     131           4 :                         raid_cpu_has_slowextendedreg() ? " slowext" : ""
+     132             :                 );
+     133             :         }
+     134             : #else
+     135             :         printf("CPU is not a x86/x64\n");
+     136             : #endif
+     137             : #if WORDS_BIGENDIAN
+     138             :         printf("Memory is big-endian %d-bit\n", (int)sizeof(void *) * 8);
+     139             : #else
+     140           4 :         printf("Memory is little-endian %d-bit\n", (int)sizeof(void *) * 8);
+     141             : #endif
+     142             : 
+     143             : #if HAVE_FUTIMENS
+     144           4 :         printf("Support nanosecond timestamps with futimens()\n");
+     145             : #elif HAVE_FUTIMES
+     146             :         printf("Support nanosecond timestamps with futimes()\n");
+     147             : #elif HAVE_FUTIMESAT
+     148             :         printf("Support nanosecond timestamps with futimesat()\n");
+     149             : #else
+     150             :         printf("Does not support nanosecond timestamps\n");
+     151             : #endif
+     152             : 
+     153           4 :         printf("\n");
+     154             : 
+     155           4 :         printf("Speed test using %u data buffers of %u bytes, for a total of %u KiB.\n", nd, size, nd * size / 1024);
+     156           4 :         printf("Memory blocks have a displacement of %u bytes to improve cache performance.\n", RAID_MALLOC_DISPLACEMENT);
+     157           4 :         printf("The reported values are the aggregate bandwidth of all data blocks in MiB/s,\n");
+     158           4 :         printf("not counting parity blocks.\n");
+     159           4 :         printf("\n");
+     160             : 
+     161           4 :         printf("Memory write speed using the C memset() function:\n");
+     162           4 :         printf("%8s", "memset");
+     163           4 :         fflush(stdout);
+     164             : 
+     165         377 :         SPEED_START {
+     166        3357 :                 for (j = 0; j < nd; ++j)
+     167        2984 :                         memset(v[j], j, size);
+     168         373 :         } SPEED_STOP
+     169             : 
+     170           4 :         printf("%8" PRIu64, ds / dt);
+     171           4 :         printf("\n");
+     172           4 :         printf("\n");
+     173             : 
+     174             :         /* crc table */
+     175           4 :         printf("CRC used to check the content file integrity:\n");
+     176             : 
+     177           4 :         printf("%8s", "table");
+     178           4 :         fflush(stdout);
+     179             : 
+     180          42 :         SPEED_START {
+     181         342 :                 for (j = 0; j < nd; ++j)
+     182         304 :                         crc32c_gen(0, v[j], size);
+     183          38 :         } SPEED_STOP
+     184             : 
+     185           4 :         printf("%8" PRIu64, ds / dt);
+     186           4 :         printf("\n");
+     187             : 
+     188           4 :         printf("%8s", "intel");
+     189           4 :         fflush(stdout);
+     190             : 
+     191             : #if HAVE_SSE42
+     192           4 :         if (raid_cpu_has_crc32()) {
+     193          50 :                 SPEED_START {
+     194         432 :                         for (j = 0; j < nd; ++j)
+     195         384 :                                 crc32c_x86(0, v[j], size);
+     196          48 :                 } SPEED_STOP
+     197             : 
+     198           2 :                 printf("%8" PRIu64, ds / dt);
+     199             :         }
+     200             : #endif
+     201           4 :         printf("\n");
+     202           4 :         printf("\n");
+     203             : 
+     204             :         /* hash table */
+     205           4 :         printf("Hash used to check the data blocks integrity:\n");
+     206             : 
+     207           4 :         printf("%8s", "");
+     208           4 :         printf("%8s", "best");
+     209           4 :         printf("%8s", "murmur3");
+     210           4 :         printf("%8s", "spooky2");
+     211           4 :         printf("\n");
+     212             : 
+     213           4 :         printf("%8s", "hash");
+     214             : #ifdef CONFIG_X86
+     215           4 :         if (sizeof(void *) == 4 && !raid_cpu_has_slowmult())
+     216           4 :                 printf("%8s", "murmur3");
+     217             :         else
+     218           0 :                 printf("%8s", "spooky2");
+     219             : #else
+     220             :         if (sizeof(void *) == 4)
+     221             :                 printf("%8s", "murmur3");
+     222             :         else
+     223             :                 printf("%8s", "spooky2");
+     224             : #endif
+     225           4 :         fflush(stdout);
+     226             : 
+     227          20 :         SPEED_START {
+     228         144 :                 for (j = 0; j < nd; ++j)
+     229         128 :                         memhash(HASH_MURMUR3, seed, digest, v[j], size);
+     230          16 :         } SPEED_STOP
+     231             : 
+     232           4 :         printf("%8" PRIu64, ds / dt);
+     233           4 :         fflush(stdout);
+     234             : 
+     235          35 :         SPEED_START {
+     236         279 :                 for (j = 0; j < nd; ++j)
+     237         248 :                         memhash(HASH_SPOOKY2, seed, digest, v[j], size);
+     238          31 :         } SPEED_STOP
+     239             : 
+     240           4 :         printf("%8" PRIu64, ds / dt);
+     241           4 :         printf("\n");
+     242           4 :         printf("\n");
+     243             : 
+     244             :         /* RAID table */
+     245           4 :         printf("RAID functions used for computing the parity with 'sync':\n");
+     246           4 :         printf("%8s", "");
+     247           4 :         printf("%8s", "best");
+     248           4 :         printf("%8s", "int8");
+     249           4 :         printf("%8s", "int32");
+     250           4 :         printf("%8s", "int64");
+     251             : #ifdef CONFIG_X86
+     252           4 :         printf("%8s", "sse2");
+     253             : #ifdef CONFIG_X86_64
+     254             :         printf("%8s", "sse2e");
+     255             : #endif
+     256           4 :         printf("%8s", "ssse3");
+     257             : #ifdef CONFIG_X86_64
+     258             :         printf("%8s", "ssse3e");
+     259             : #endif
+     260           4 :         printf("%8s", "avx2");
+     261             : #ifdef CONFIG_X86_64
+     262             :         printf("%8s", "avx2e");
+     263             : #endif
+     264             : #endif
+     265           4 :         printf("\n");
+     266             : 
+     267             :         /* GEN1 */
+     268           4 :         printf("%8s", "gen1");
+     269           4 :         printf("%8s", raid_gen1_tag());
+     270           4 :         fflush(stdout);
+     271             : 
+     272           4 :         printf("%8s", "");
+     273             : 
+     274         117 :         SPEED_START {
+     275         113 :                 raid_gen1_int32(nd, size, v);
+     276         113 :         } SPEED_STOP
+     277             : 
+     278           4 :         printf("%8" PRIu64, ds / dt);
+     279           4 :         fflush(stdout);
+     280             : 
+     281         188 :         SPEED_START {
+     282         184 :                 raid_gen1_int64(nd, size, v);
+     283         184 :         } SPEED_STOP
+     284             : 
+     285           4 :         printf("%8" PRIu64, ds / dt);
+     286           4 :         fflush(stdout);
+     287             : 
+     288             : #ifdef CONFIG_X86
+     289             : #ifdef CONFIG_SSE2
+     290           4 :         if (raid_cpu_has_sse2()) {
+     291         315 :                 SPEED_START {
+     292         311 :                         raid_gen1_sse2(nd, size, v);
+     293         311 :                 } SPEED_STOP
+     294             : 
+     295           4 :                 printf("%8" PRIu64, ds / dt);
+     296           4 :                 fflush(stdout);
+     297             :         }
+     298             : #endif
+     299             : 
+     300             : #ifdef CONFIG_X86_64
+     301             :         printf("%8s", "");
+     302             : #endif
+     303           4 :         printf("%8s", "");
+     304             : #ifdef CONFIG_X86_64
+     305             :         printf("%8s", "");
+     306             : #endif
+     307             : #ifdef CONFIG_AVX2
+     308           4 :         if (raid_cpu_has_avx2()) {
+     309          14 :                 SPEED_START {
+     310          13 :                         raid_gen1_avx2(nd, size, v);
+     311          13 :                 } SPEED_STOP
+     312             : 
+     313           1 :                 printf("%8" PRIu64, ds / dt);
+     314           1 :                 fflush(stdout);
+     315             :         }
+     316             : #endif
+     317             : #endif
+     318           4 :         printf("\n");
+     319             : 
+     320             :         /* GEN2 */
+     321           4 :         printf("%8s", "gen2");
+     322           4 :         printf("%8s", raid_gen2_tag());
+     323           4 :         fflush(stdout);
+     324             : 
+     325           4 :         printf("%8s", "");
+     326             : 
+     327          48 :         SPEED_START {
+     328          44 :                 raid_gen2_int32(nd, size, v);
+     329          44 :         } SPEED_STOP
+     330             : 
+     331           4 :         printf("%8" PRIu64, ds / dt);
+     332           4 :         fflush(stdout);
+     333             : 
+     334          48 :         SPEED_START {
+     335          44 :                 raid_gen2_int64(nd, size, v);
+     336          44 :         } SPEED_STOP
+     337             : 
+     338           4 :         printf("%8" PRIu64, ds / dt);
+     339           4 :         fflush(stdout);
+     340             : 
+     341             : #ifdef CONFIG_X86
+     342             : #ifdef CONFIG_SSE2
+     343           4 :         if (raid_cpu_has_sse2()) {
+     344         146 :                 SPEED_START {
+     345         142 :                         raid_gen2_sse2(nd, size, v);
+     346         142 :                 } SPEED_STOP
+     347             : 
+     348           4 :                 printf("%8" PRIu64, ds / dt);
+     349           4 :                 fflush(stdout);
+     350             : 
+     351             : #ifdef CONFIG_X86_64
+     352             :                 SPEED_START {
+     353             :                         raid_gen2_sse2ext(nd, size, v);
+     354             :                 } SPEED_STOP
+     355             : 
+     356             :                 printf("%8" PRIu64, ds / dt);
+     357             :                 fflush(stdout);
+     358             : #endif
+     359             :         }
+     360             : #endif
+     361             : 
+     362           4 :         printf("%8s", "");
+     363             : #ifdef CONFIG_X86_64
+     364             :         printf("%8s", "");
+     365             : #endif
+     366             : #ifdef CONFIG_AVX2
+     367           4 :         if (raid_cpu_has_avx2()) {
+     368           4 :                 SPEED_START {
+     369           3 :                         raid_gen2_avx2(nd, size, v);
+     370           3 :                 } SPEED_STOP
+     371             : 
+     372           1 :                 printf("%8" PRIu64, ds / dt);
+     373           1 :                 fflush(stdout);
+     374             :         }
+     375             : #endif
+     376             : #endif
+     377           4 :         printf("\n");
+     378             : 
+     379             :         /* GENz */
+     380           4 :         printf("%8s", "genz");
+     381           4 :         printf("%8s", raid_genz_tag());
+     382           4 :         fflush(stdout);
+     383             : 
+     384           4 :         printf("%8s", "");
+     385             : 
+     386          32 :         SPEED_START {
+     387          28 :                 raid_genz_int32(nd, size, v);
+     388          28 :         } SPEED_STOP
+     389             : 
+     390           4 :         printf("%8" PRIu64, ds / dt);
+     391           4 :         fflush(stdout);
+     392             : 
+     393          32 :         SPEED_START {
+     394          28 :                 raid_genz_int64(nd, size, v);
+     395          28 :         } SPEED_STOP
+     396             : 
+     397           4 :         printf("%8" PRIu64, ds / dt);
+     398           4 :         fflush(stdout);
+     399             : 
+     400             : #ifdef CONFIG_X86
+     401             : #ifdef CONFIG_SSE2
+     402           4 :         if (raid_cpu_has_sse2()) {
+     403          86 :                 SPEED_START {
+     404          82 :                         raid_genz_sse2(nd, size, v);
+     405          82 :                 } SPEED_STOP
+     406             : 
+     407           4 :                 printf("%8" PRIu64, ds / dt);
+     408           4 :                 fflush(stdout);
+     409             : 
+     410             : #ifdef CONFIG_X86_64
+     411             :                 SPEED_START {
+     412             :                         raid_genz_sse2ext(nd, size, v);
+     413             :                 } SPEED_STOP
+     414             : 
+     415             :                 printf("%8" PRIu64, ds / dt);
+     416             :                 fflush(stdout);
+     417             : #endif
+     418             :         }
+     419             : #endif
+     420             : 
+     421           4 :         printf("%8s", "");
+     422             : #ifdef CONFIG_X86_64
+     423             :         printf("%8s", "");
+     424             : #endif
+     425           4 :         printf("%8s", "");
+     426             : 
+     427             : #ifdef CONFIG_X86_64
+     428             : #ifdef CONFIG_AVX2
+     429             :         if (raid_cpu_has_avx2()) {
+     430             :                 SPEED_START {
+     431             :                         raid_genz_avx2ext(nd, size, v);
+     432             :                 } SPEED_STOP
+     433             : 
+     434             :                 printf("%8" PRIu64, ds / dt);
+     435             :                 fflush(stdout);
+     436             :         }
+     437             : #endif
+     438             : #endif
+     439             : #endif
+     440           4 :         printf("\n");
+     441             : 
+     442             :         /* GEN3 */
+     443           4 :         printf("%8s", "gen3");
+     444           4 :         printf("%8s", raid_gen3_tag());
+     445           4 :         fflush(stdout);
+     446             : 
+     447          12 :         SPEED_START {
+     448           8 :                 raid_gen3_int8(nd, size, v);
+     449           8 :         } SPEED_STOP
+     450             : 
+     451           4 :         printf("%8" PRIu64, ds / dt);
+     452           4 :         fflush(stdout);
+     453             : 
+     454           4 :         printf("%8s", "");
+     455           4 :         printf("%8s", "");
+     456             : 
+     457             : #ifdef CONFIG_X86
+     458           4 :         if (raid_cpu_has_sse2()) {
+     459           4 :                 printf("%8s", "");
+     460             : 
+     461             : #ifdef CONFIG_X86_64
+     462             :                 printf("%8s", "");
+     463             : #endif
+     464             :         }
+     465             : #endif
+     466             : 
+     467             : #ifdef CONFIG_X86
+     468             : #ifdef CONFIG_SSSE3
+     469           4 :         if (raid_cpu_has_ssse3()) {
+     470          53 :                 SPEED_START {
+     471          50 :                         raid_gen3_ssse3(nd, size, v);
+     472          50 :                 } SPEED_STOP
+     473             : 
+     474           3 :                 printf("%8" PRIu64, ds / dt);
+     475           3 :                 fflush(stdout);
+     476             : 
+     477             : #ifdef CONFIG_X86_64
+     478             :                 SPEED_START {
+     479             :                         raid_gen3_ssse3ext(nd, size, v);
+     480             :                 } SPEED_STOP
+     481             : 
+     482             :                 printf("%8" PRIu64, ds / dt);
+     483             :                 fflush(stdout);
+     484             : #endif
+     485             :         }
+     486             : #endif
+     487             : 
+     488           4 :         printf("%8s", "");
+     489             : 
+     490             : #ifdef CONFIG_X86_64
+     491             : #ifdef CONFIG_AVX2
+     492             :         if (raid_cpu_has_avx2()) {
+     493             :                 SPEED_START {
+     494             :                         raid_gen3_avx2ext(nd, size, v);
+     495             :                 } SPEED_STOP
+     496             : 
+     497             :                 printf("%8" PRIu64, ds / dt);
+     498             :                 fflush(stdout);
+     499             :         }
+     500             : #endif
+     501             : #endif
+     502             : #endif
+     503           4 :         printf("\n");
+     504             : 
+     505             :         /* GEN4 */
+     506           4 :         printf("%8s", "gen4");
+     507           4 :         printf("%8s", raid_gen4_tag());
+     508           4 :         fflush(stdout);
+     509             : 
+     510          12 :         SPEED_START {
+     511           8 :                 raid_gen4_int8(nd, size, v);
+     512           8 :         } SPEED_STOP
+     513             : 
+     514           4 :         printf("%8" PRIu64, ds / dt);
+     515           4 :         fflush(stdout);
+     516             : 
+     517           4 :         printf("%8s", "");
+     518           4 :         printf("%8s", "");
+     519             : 
+     520             : #ifdef CONFIG_X86
+     521             : #ifdef CONFIG_SSE2
+     522           4 :         if (raid_cpu_has_sse2()) {
+     523           4 :                 printf("%8s", "");
+     524             : 
+     525             : #ifdef CONFIG_X86_64
+     526             :                 printf("%8s", "");
+     527             : #endif
+     528             :         }
+     529             : #endif
+     530             : #endif
+     531             : 
+     532             : #ifdef CONFIG_X86
+     533             : #ifdef CONFIG_SSSE3
+     534           4 :         if (raid_cpu_has_ssse3()) {
+     535          35 :                 SPEED_START {
+     536          32 :                         raid_gen4_ssse3(nd, size, v);
+     537          32 :                 } SPEED_STOP
+     538             : 
+     539           3 :                 printf("%8" PRIu64, ds / dt);
+     540           3 :                 fflush(stdout);
+     541             : 
+     542             : #ifdef CONFIG_X86_64
+     543             :                 SPEED_START {
+     544             :                         raid_gen4_ssse3ext(nd, size, v);
+     545             :                 } SPEED_STOP
+     546             : 
+     547             :                 printf("%8" PRIu64, ds / dt);
+     548             :                 fflush(stdout);
+     549             : #endif
+     550             :         }
+     551             : #endif
+     552             : 
+     553           4 :         printf("%8s", "");
+     554             : 
+     555             : #ifdef CONFIG_X86_64
+     556             : #ifdef CONFIG_AVX2
+     557             :         if (raid_cpu_has_avx2()) {
+     558             :                 SPEED_START {
+     559             :                         raid_gen4_avx2ext(nd, size, v);
+     560             :                 } SPEED_STOP
+     561             : 
+     562             :                 printf("%8" PRIu64, ds / dt);
+     563             :                 fflush(stdout);
+     564             :         }
+     565             : #endif
+     566             : #endif
+     567             : #endif
+     568           4 :         printf("\n");
+     569             : 
+     570             :         /* GEN5 */
+     571           4 :         printf("%8s", "gen5");
+     572           4 :         printf("%8s", raid_gen5_tag());
+     573           4 :         fflush(stdout);
+     574             : 
+     575          12 :         SPEED_START {
+     576           8 :                 raid_gen5_int8(nd, size, v);
+     577           8 :         } SPEED_STOP
+     578             : 
+     579           4 :         printf("%8" PRIu64, ds / dt);
+     580           4 :         fflush(stdout);
+     581             : 
+     582           4 :         printf("%8s", "");
+     583           4 :         printf("%8s", "");
+     584             : 
+     585             : #ifdef CONFIG_X86
+     586             : #ifdef CONFIG_SSE2
+     587           4 :         if (raid_cpu_has_sse2()) {
+     588           4 :                 printf("%8s", "");
+     589             : 
+     590             : #ifdef CONFIG_X86_64
+     591             :                 printf("%8s", "");
+     592             : #endif
+     593             :         }
+     594             : #endif
+     595             : #endif
+     596             : 
+     597             : #ifdef CONFIG_X86
+     598             : #ifdef CONFIG_SSSE3
+     599           4 :         if (raid_cpu_has_ssse3()) {
+     600          26 :                 SPEED_START {
+     601          23 :                         raid_gen5_ssse3(nd, size, v);
+     602          23 :                 } SPEED_STOP
+     603             : 
+     604           3 :                 printf("%8" PRIu64, ds / dt);
+     605           3 :                 fflush(stdout);
+     606             : 
+     607             : #ifdef CONFIG_X86_64
+     608             :                 SPEED_START {
+     609             :                         raid_gen5_ssse3ext(nd, size, v);
+     610             :                 } SPEED_STOP
+     611             : 
+     612             :                 printf("%8" PRIu64, ds / dt);
+     613             :                 fflush(stdout);
+     614             : #endif
+     615             :         }
+     616             : #endif
+     617             : 
+     618           4 :         printf("%8s", "");
+     619             : 
+     620             : #ifdef CONFIG_X86_64
+     621             : #ifdef CONFIG_AVX2
+     622             :         if (raid_cpu_has_avx2()) {
+     623             :                 SPEED_START {
+     624             :                         raid_gen5_avx2ext(nd, size, v);
+     625             :                 } SPEED_STOP
+     626             : 
+     627             :                 printf("%8" PRIu64, ds / dt);
+     628             :                 fflush(stdout);
+     629             :         }
+     630             : #endif
+     631             : #endif
+     632             : #endif
+     633           4 :         printf("\n");
+     634             : 
+     635             :         /* GEN6 */
+     636           4 :         printf("%8s", "gen6");
+     637           4 :         printf("%8s", raid_gen6_tag());
+     638           4 :         fflush(stdout);
+     639             : 
+     640           9 :         SPEED_START {
+     641           5 :                 raid_gen6_int8(nd, size, v);
+     642           5 :         } SPEED_STOP
+     643             : 
+     644           4 :         printf("%8" PRIu64, ds / dt);
+     645           4 :         fflush(stdout);
+     646             : 
+     647           4 :         printf("%8s", "");
+     648           4 :         printf("%8s", "");
+     649             : 
+     650             : #ifdef CONFIG_X86
+     651             : #ifdef CONFIG_SSE2
+     652           4 :         if (raid_cpu_has_sse2()) {
+     653           4 :                 printf("%8s", "");
+     654             : 
+     655             : #ifdef CONFIG_X86_64
+     656             :                 printf("%8s", "");
+     657             : #endif
+     658             :         }
+     659             : #endif
+     660             : #endif
+     661             : 
+     662             : #ifdef CONFIG_X86
+     663             : #ifdef CONFIG_SSSE3
+     664           4 :         if (raid_cpu_has_ssse3()) {
+     665          20 :                 SPEED_START {
+     666          17 :                         raid_gen6_ssse3(nd, size, v);
+     667          17 :                 } SPEED_STOP
+     668             : 
+     669           3 :                 printf("%8" PRIu64, ds / dt);
+     670           3 :                 fflush(stdout);
+     671             : 
+     672             : #ifdef CONFIG_X86_64
+     673             :                 SPEED_START {
+     674             :                         raid_gen6_ssse3ext(nd, size, v);
+     675             :                 } SPEED_STOP
+     676             : 
+     677             :                 printf("%8" PRIu64, ds / dt);
+     678             :                 fflush(stdout);
+     679             : #endif
+     680             :         }
+     681             : #endif
+     682             : 
+     683           4 :         printf("%8s", "");
+     684             : 
+     685             : #ifdef CONFIG_X86_64
+     686             : #ifdef CONFIG_AVX2
+     687             :         if (raid_cpu_has_avx2()) {
+     688             :                 SPEED_START {
+     689             :                         raid_gen6_avx2ext(nd, size, v);
+     690             :                 } SPEED_STOP
+     691             : 
+     692             :                 printf("%8" PRIu64, ds / dt);
+     693             :                 fflush(stdout);
+     694             :         }
+     695             : #endif
+     696             : #endif
+     697             : #endif
+     698           4 :         printf("\n");
+     699           4 :         printf("\n");
+     700             : 
+     701             :         /* recover table */
+     702           4 :         printf("RAID functions used for recovering with 'fix':\n");
+     703           4 :         printf("%8s", "");
+     704           4 :         printf("%8s", "best");
+     705           4 :         printf("%8s", "int8");
+     706             : #ifdef CONFIG_X86
+     707           4 :         printf("%8s", "ssse3");
+     708           4 :         printf("%8s", "avx2");
+     709             : #endif
+     710           4 :         printf("\n");
+     711             : 
+     712           4 :         printf("%8s", "rec1");
+     713           4 :         printf("%8s", raid_rec1_tag());
+     714           4 :         fflush(stdout);
+     715             : 
+     716          11 :         SPEED_START {
+     717          63 :                 for (j = 0; j < nd; ++j)
+     718             :                         /* +1 to avoid GEN1 optimized case */
+     719          56 :                         raid_rec1_int8(1, id, ip + 1, nd, size, v);
+     720           7 :         } SPEED_STOP
+     721             : 
+     722           4 :         printf("%8" PRIu64, ds / dt);
+     723           4 :         fflush(stdout);
+     724             : 
+     725             : #ifdef CONFIG_X86
+     726             : #ifdef CONFIG_SSSE3
+     727           4 :         if (raid_cpu_has_ssse3()) {
+     728          10 :                 SPEED_START {
+     729          63 :                         for (j = 0; j < nd; ++j)
+     730             :                                 /* +1 to avoid GEN1 optimized case */
+     731          56 :                                 raid_rec1_ssse3(1, id, ip + 1, nd, size, v);
+     732           7 :                 } SPEED_STOP
+     733             : 
+     734           3 :                 printf("%8" PRIu64, ds / dt);
+     735             :         }
+     736             : #endif
+     737             : #ifdef CONFIG_AVX2
+     738           4 :         if (raid_cpu_has_avx2()) {
+     739           2 :                 SPEED_START {
+     740           9 :                         for (j = 0; j < nd; ++j)
+     741             :                                 /* +1 to avoid GEN1 optimized case */
+     742           8 :                                 raid_rec1_avx2(1, id, ip + 1, nd, size, v);
+     743           1 :                 } SPEED_STOP
+     744             : 
+     745           1 :                 printf("%8" PRIu64, ds / dt);
+     746             :         }
+     747             : #endif
+     748             : #endif
+     749           4 :         printf("\n");
+     750             : 
+     751           4 :         printf("%8s", "rec2");
+     752           4 :         printf("%8s", raid_rec2_tag());
+     753           4 :         fflush(stdout);
+     754             : 
+     755           8 :         SPEED_START {
+     756          36 :                 for (j = 0; j < nd; ++j)
+     757             :                         /* +1 to avoid GEN2 optimized case */
+     758          32 :                         raid_rec2_int8(2, id, ip + 1, nd, size, v);
+     759           4 :         } SPEED_STOP
+     760             : 
+     761           4 :         printf("%8" PRIu64, ds / dt);
+     762           4 :         fflush(stdout);
+     763             : 
+     764             : #ifdef CONFIG_X86
+     765             : #ifdef CONFIG_SSSE3
+     766           4 :         if (raid_cpu_has_ssse3()) {
+     767           9 :                 SPEED_START {
+     768          54 :                         for (j = 0; j < nd; ++j)
+     769             :                                 /* +1 to avoid GEN2 optimized case */
+     770          48 :                                 raid_rec2_ssse3(2, id, ip + 1, nd, size, v);
+     771           6 :                 } SPEED_STOP
+     772             : 
+     773           3 :                 printf("%8" PRIu64, ds / dt);
+     774             :         }
+     775             : #endif
+     776             : #ifdef CONFIG_AVX2
+     777           4 :         if (raid_cpu_has_avx2()) {
+     778           2 :                 SPEED_START {
+     779           9 :                         for (j = 0; j < nd; ++j)
+     780             :                                 /* +1 to avoid GEN1 optimized case */
+     781           8 :                                 raid_rec2_avx2(2, id, ip + 1, nd, size, v);
+     782           1 :                 } SPEED_STOP
+     783             : 
+     784           1 :                 printf("%8" PRIu64, ds / dt);
+     785             :         }
+     786             : #endif
+     787             : #endif
+     788           4 :         printf("\n");
+     789             : 
+     790           4 :         printf("%8s", "rec3");
+     791           4 :         printf("%8s", raid_recX_tag());
+     792           4 :         fflush(stdout);
+     793             : 
+     794           8 :         SPEED_START {
+     795          36 :                 for (j = 0; j < nd; ++j)
+     796          32 :                         raid_recX_int8(3, id, ip, nd, size, v);
+     797           4 :         } SPEED_STOP
+     798             : 
+     799           4 :         printf("%8" PRIu64, ds / dt);
+     800           4 :         fflush(stdout);
+     801             : 
+     802             : #ifdef CONFIG_X86
+     803             : #ifdef CONFIG_SSSE3
+     804           4 :         if (raid_cpu_has_ssse3()) {
+     805           6 :                 SPEED_START {
+     806          27 :                         for (j = 0; j < nd; ++j)
+     807          24 :                                 raid_recX_ssse3(3, id, ip, nd, size, v);
+     808           3 :                 } SPEED_STOP
+     809             : 
+     810           3 :                 printf("%8" PRIu64, ds / dt);
+     811             :         }
+     812             : #endif
+     813             : #ifdef CONFIG_AVX2
+     814           4 :         if (raid_cpu_has_avx2()) {
+     815           2 :                 SPEED_START {
+     816           9 :                         for (j = 0; j < nd; ++j)
+     817           8 :                                 raid_recX_avx2(3, id, ip, nd, size, v);
+     818           1 :                 } SPEED_STOP
+     819             : 
+     820           1 :                 printf("%8" PRIu64, ds / dt);
+     821             :         }
+     822             : #endif
+     823             : #endif
+     824           4 :         printf("\n");
+     825             : 
+     826           4 :         printf("%8s", "rec4");
+     827           4 :         printf("%8s", raid_recX_tag());
+     828           4 :         fflush(stdout);
+     829             : 
+     830           8 :         SPEED_START {
+     831          36 :                 for (j = 0; j < nd; ++j)
+     832          32 :                         raid_recX_int8(4, id, ip, nd, size, v);
+     833           4 :         } SPEED_STOP
+     834             : 
+     835           4 :         printf("%8" PRIu64, ds / dt);
+     836           4 :         fflush(stdout);
+     837             : 
+     838             : #ifdef CONFIG_X86
+     839             : #ifdef CONFIG_SSSE3
+     840           4 :         if (raid_cpu_has_ssse3()) {
+     841           6 :                 SPEED_START {
+     842          27 :                         for (j = 0; j < nd; ++j)
+     843          24 :                                 raid_recX_ssse3(4, id, ip, nd, size, v);
+     844           3 :                 } SPEED_STOP
+     845             : 
+     846           3 :                 printf("%8" PRIu64, ds / dt);
+     847             :         }
+     848             : #endif
+     849             : #ifdef CONFIG_AVX2
+     850           4 :         if (raid_cpu_has_avx2()) {
+     851           2 :                 SPEED_START {
+     852           9 :                         for (j = 0; j < nd; ++j)
+     853           8 :                                 raid_recX_avx2(4, id, ip, nd, size, v);
+     854           1 :                 } SPEED_STOP
+     855             : 
+     856           1 :                 printf("%8" PRIu64, ds / dt);
+     857             :         }
+     858             : #endif
+     859             : #endif
+     860           4 :         printf("\n");
+     861             : 
+     862           4 :         printf("%8s", "rec5");
+     863           4 :         printf("%8s", raid_recX_tag());
+     864           4 :         fflush(stdout);
+     865             : 
+     866           8 :         SPEED_START {
+     867          36 :                 for (j = 0; j < nd; ++j)
+     868          32 :                         raid_recX_int8(5, id, ip, nd, size, v);
+     869           4 :         } SPEED_STOP
+     870             : 
+     871           4 :         printf("%8" PRIu64, ds / dt);
+     872           4 :         fflush(stdout);
+     873             : 
+     874             : #ifdef CONFIG_X86
+     875             : #ifdef CONFIG_SSSE3
+     876           4 :         if (raid_cpu_has_ssse3()) {
+     877           6 :                 SPEED_START {
+     878          27 :                         for (j = 0; j < nd; ++j)
+     879          24 :                                 raid_recX_ssse3(5, id, ip, nd, size, v);
+     880           3 :                 } SPEED_STOP
+     881             : 
+     882           3 :                 printf("%8" PRIu64, ds / dt);
+     883             :         }
+     884             : #endif
+     885             : #ifdef CONFIG_AVX2
+     886           4 :         if (raid_cpu_has_avx2()) {
+     887           2 :                 SPEED_START {
+     888           9 :                         for (j = 0; j < nd; ++j)
+     889           8 :                                 raid_recX_avx2(5, id, ip, nd, size, v);
+     890           1 :                 } SPEED_STOP
+     891             : 
+     892           1 :                 printf("%8" PRIu64, ds / dt);
+     893             :         }
+     894             : #endif
+     895             : #endif
+     896           4 :         printf("\n");
+     897             : 
+     898           4 :         printf("%8s", "rec6");
+     899           4 :         printf("%8s", raid_recX_tag());
+     900           4 :         fflush(stdout);
+     901             : 
+     902           8 :         SPEED_START {
+     903          36 :                 for (j = 0; j < nd; ++j)
+     904          32 :                         raid_recX_int8(6, id, ip, nd, size, v);
+     905           4 :         } SPEED_STOP
+     906             : 
+     907           4 :         printf("%8" PRIu64, ds / dt);
+     908           4 :         fflush(stdout);
+     909             : 
+     910             : #ifdef CONFIG_X86
+     911             : #ifdef CONFIG_SSSE3
+     912           4 :         if (raid_cpu_has_ssse3()) {
+     913           6 :                 SPEED_START {
+     914          27 :                         for (j = 0; j < nd; ++j)
+     915          24 :                                 raid_recX_ssse3(6, id, ip, nd, size, v);
+     916           3 :                 } SPEED_STOP
+     917             : 
+     918           3 :                 printf("%8" PRIu64, ds / dt);
+     919             :         }
+     920             : #endif
+     921             : #ifdef CONFIG_AVX2
+     922           4 :         if (raid_cpu_has_avx2()) {
+     923           2 :                 SPEED_START {
+     924           9 :                         for (j = 0; j < nd; ++j)
+     925           8 :                                 raid_recX_avx2(6, id, ip, nd, size, v);
+     926           1 :                 } SPEED_STOP
+     927             : 
+     928           1 :                 printf("%8" PRIu64, ds / dt);
+     929             :         }
+     930             : #endif
+     931             : #endif
+     932           4 :         printf("\n");
+     933           4 :         printf("\n");
+     934             : 
+     935           4 :         printf("If the 'best' expectations are wrong, please report it in the SnapRAID forum\n\n");
+     936             : 
+     937           4 :         free(v_alloc);
+     938           4 :         free(v);
+     939           4 : }
+     940             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/spooky2.c.func-sort-c.html b/cov/cmdline/spooky2.c.func-sort-c.html new file mode 100644 index 00000000..c40e83ab --- /dev/null +++ b/cov/cmdline/spooky2.c.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/spooky2.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - spooky2.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2020100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
SpookyHash1283471988
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/spooky2.c.func.html b/cov/cmdline/spooky2.c.func.html new file mode 100644 index 00000000..27476e7d --- /dev/null +++ b/cov/cmdline/spooky2.c.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/spooky2.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - spooky2.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2020100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
SpookyHash1283471988
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/spooky2.c.gcov.html b/cov/cmdline/spooky2.c.gcov.html new file mode 100644 index 00000000..d45b027f --- /dev/null +++ b/cov/cmdline/spooky2.c.gcov.html @@ -0,0 +1,249 @@ + + + + + + + LCOV - lcov.info - cmdline/spooky2.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - spooky2.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2020100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : /*
+      19             :  * Derivative work from SpookyV2.cpp/h
+      20             :  *
+      21             :  * WARNING!!!! Note that this implementation doesn't use the short hash optimization
+      22             :  * resulting in different hashes for any length shorter than 192 bytes
+      23             :  *
+      24             :  * SpookyHash
+      25             :  * http://burtleburtle.net/bob/hash/spooky.html
+      26             :  *
+      27             :  * Exact source used as reference:
+      28             :  * http://burtleburtle.net/bob/c/SpookyV2.h
+      29             :  * http://burtleburtle.net/bob/c/SpookyV2.cpp
+      30             :  */
+      31             : 
+      32             : // Spooky Hash
+      33             : // A 128-bit noncryptographic hash, for checksums and table lookup
+      34             : // By Bob Jenkins.  Public domain.
+      35             : //   Oct 31 2010: published framework, disclaimer ShortHash isn't right
+      36             : //   Nov 7 2010: disabled ShortHash
+      37             : //   Oct 31 2011: replace End, ShortMix, ShortEnd, enable ShortHash again
+      38             : //   April 10 2012: buffer overflow on platforms without unaligned reads
+      39             : //   July 12 2012: was passing out variables in final to in/out in short
+      40             : //   July 30 2012: I reintroduced the buffer overflow
+      41             : //   August 5 2012: SpookyV2: d = should be d += in short hash, and remove extra mix from long hash
+      42             : //
+      43             : // Up to 3 bytes/cycle for long messages.  Reasonably fast for short messages.
+      44             : // All 1 or 2 bit deltas achieve avalanche within 1% bias per output bit.
+      45             : //
+      46             : // This was developed for and tested on 64-bit x86-compatible processors.
+      47             : // It assumes the processor is little-endian.  There is a macro
+      48             : // controlling whether unaligned reads are allowed (by default they are).
+      49             : // This should be an equally good hash on big-endian machines, but it will
+      50             : // compute different results on them than on little-endian machines.
+      51             : //
+      52             : // Google's CityHash has similar specs to SpookyHash, and CityHash is faster
+      53             : // on new Intel boxes.  MD4 and MD5 also have similar specs, but they are orders
+      54             : // of magnitude slower.  CRCs are two or more times slower, but unlike
+      55             : // SpookyHash, they have nice math for combining the CRCs of pieces to form
+      56             : // the CRCs of wholes.  There are also cryptographic hashes, but those are even
+      57             : // slower than MD5.
+      58             : //
+      59             : 
+      60             : #define Mix(data, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \
+      61             :         s0 += data[0];   s2 ^= s10;  s11 ^= s0;   s0 = util_rotl64(s0, 11);   s11 += s1; \
+      62             :         s1 += data[1];   s3 ^= s11;  s0 ^= s1;   s1 = util_rotl64(s1, 32);   s0 += s2; \
+      63             :         s2 += data[2];   s4 ^= s0;   s1 ^= s2;   s2 = util_rotl64(s2, 43);   s1 += s3; \
+      64             :         s3 += data[3];   s5 ^= s1;   s2 ^= s3;   s3 = util_rotl64(s3, 31);   s2 += s4; \
+      65             :         s4 += data[4];   s6 ^= s2;   s3 ^= s4;   s4 = util_rotl64(s4, 17);   s3 += s5; \
+      66             :         s5 += data[5];   s7 ^= s3;   s4 ^= s5;   s5 = util_rotl64(s5, 28);   s4 += s6; \
+      67             :         s6 += data[6];   s8 ^= s4;   s5 ^= s6;   s6 = util_rotl64(s6, 39);   s5 += s7; \
+      68             :         s7 += data[7];   s9 ^= s5;   s6 ^= s7;   s7 = util_rotl64(s7, 57);   s6 += s8; \
+      69             :         s8 += data[8];   s10 ^= s6;   s7 ^= s8;   s8 = util_rotl64(s8, 55);   s7 += s9; \
+      70             :         s9 += data[9];   s11 ^= s7;   s8 ^= s9;   s9 = util_rotl64(s9, 54);   s8 += s10; \
+      71             :         s10 += data[10];  s0 ^= s8;   s9 ^= s10;  s10 = util_rotl64(s10, 22);  s9 += s11; \
+      72             :         s11 += data[11];  s1 ^= s9;   s10 ^= s11;  s11 = util_rotl64(s11, 46);  s10 += s0;
+      73             : 
+      74             : #define EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11) \
+      75             :         h11 += h1;   h2 ^= h11;  h1 = util_rotl64(h1, 44); \
+      76             :         h0 += h2;   h3 ^= h0;   h2 = util_rotl64(h2, 15); \
+      77             :         h1 += h3;   h4 ^= h1;   h3 = util_rotl64(h3, 34); \
+      78             :         h2 += h4;   h5 ^= h2;   h4 = util_rotl64(h4, 21); \
+      79             :         h3 += h5;   h6 ^= h3;   h5 = util_rotl64(h5, 38); \
+      80             :         h4 += h6;   h7 ^= h4;   h6 = util_rotl64(h6, 33); \
+      81             :         h5 += h7;   h8 ^= h5;   h7 = util_rotl64(h7, 10); \
+      82             :         h6 += h8;   h9 ^= h6;   h8 = util_rotl64(h8, 13); \
+      83             :         h7 += h9;   h10 ^= h7;   h9 = util_rotl64(h9, 38); \
+      84             :         h8 += h10;  h11 ^= h8;   h10 = util_rotl64(h10, 53); \
+      85             :         h9 += h11;  h0 ^= h9;   h11 = util_rotl64(h11, 42); \
+      86             :         h10 += h0;   h1 ^= h10;  h0 = util_rotl64(h0, 54);
+      87             : 
+      88             : #define End(data, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11) \
+      89             :         h0 += data[0];  h1 += data[1];  h2 += data[2];    h3 += data[3]; \
+      90             :         h4 += data[4];  h5 += data[5];  h6 += data[6];    h7 += data[7]; \
+      91             :         h8 += data[8];  h9 += data[9];  h10 += data[10];   h11 += data[11]; \
+      92             :         EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); \
+      93             :         EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); \
+      94             :         EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11);
+      95             : 
+      96             : // number of uint64_t's in internal state
+      97             : #define sc_numVars 12
+      98             : 
+      99             : // size of the internal state
+     100             : #define sc_blockSize (sc_numVars * 8)
+     101             : 
+     102             : //
+     103             : // sc_const: a constant which:
+     104             : //  * is not zero
+     105             : //  * is odd
+     106             : //  * is a not-very-regular mix of 1's and 0's
+     107             : //  * does not need any other special mathematical properties
+     108             : //
+     109             : #define sc_const 0xdeadbeefdeadbeefLL
+     110             : 
+     111     3471988 : void SpookyHash128(const void* data, size_t size, const uint8_t* seed, uint8_t* digest)
+     112             : {
+     113             :         uint64_t h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11;
+     114             :         uint64_t buf[sc_numVars];
+     115             :         size_t nblocks;
+     116             :         const uint64_t* blocks;
+     117             :         const uint64_t* end;
+     118             :         size_t remainder;
+     119             : #if WORDS_BIGENDIAN
+     120             :         unsigned i;
+     121             : #endif
+     122             : 
+     123     3471988 :         h9 = ((const uint64_t*)seed)[0];
+     124     3471988 :         h10 = ((const uint64_t*)seed)[1];
+     125             : 
+     126             : #if WORDS_BIGENDIAN
+     127             :         h9 = util_swap64(h9);
+     128             :         h10 = util_swap64(h10);
+     129             : #endif
+     130             : 
+     131     3471988 :         h0 = h3 = h6 = h9;
+     132     3471988 :         h1 = h4 = h7 = h10;
+     133     3471988 :         h2 = h5 = h8 = h11 = sc_const;
+     134             : 
+     135     3471988 :         nblocks = size / sc_blockSize;
+     136     3471988 :         blocks = data;
+     137     3471988 :         end = blocks + nblocks * sc_numVars;
+     138             : 
+     139             :         /* body */
+     140    34947661 :         while (blocks < end) {
+     141             : #if WORDS_BIGENDIAN
+     142             :                 for (i = 0; i < sc_numVars; ++i)
+     143             :                         buf[i] = util_swap64(blocks[i]);
+     144             :                 Mix(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11);
+     145             : #else
+     146    28003685 :                 Mix(blocks, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11);
+     147             : #endif
+     148    28003685 :                 blocks += sc_numVars;
+     149             :         }
+     150             : 
+     151             :         /* tail */
+     152     3471988 :         remainder = (size - ((const uint8_t*)end - (const uint8_t*)data));
+     153     3471988 :         memcpy(buf, end, remainder);
+     154     3471988 :         memset(((uint8_t*)buf) + remainder, 0, sc_blockSize - remainder);
+     155     3471988 :         ((uint8_t*)buf)[sc_blockSize - 1] = remainder;
+     156             : 
+     157             :         /* finalization */
+     158             : #if WORDS_BIGENDIAN
+     159             :         for (i = 0; i < sc_numVars; ++i)
+     160             :                 buf[i] = util_swap64(buf[i]);
+     161             : #endif
+     162             : 
+     163     3471988 :         End(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11);
+     164             : 
+     165             : #if WORDS_BIGENDIAN
+     166             :         h0 = util_swap64(h0);
+     167             :         h1 = util_swap64(h1);
+     168             : #endif
+     169             : 
+     170     3471988 :         ((uint64_t*)digest)[0] = h0;
+     171     3471988 :         ((uint64_t*)digest)[1] = h1;
+     172     3471988 : }
+     173             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.c.func-sort-c.html b/cov/cmdline/state.c.func-sort-c.html new file mode 100644 index 00000000..0525f1e3 --- /dev/null +++ b/cov/cmdline/state.c.func-sort-c.html @@ -0,0 +1,200 @@ + + + + + + + LCOV - lcov.info - cmdline/state.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:1547170590.7 %
Date:2015-05-12Functions:313296.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
is_block_deleted4423464
info_is_required1498181
state_progress1025177
position_is_required738011
lev_config_name178682
find_disk102384
lev_config_scan5612
validate_smartctl324
state_init236
lev_raid_name235
state_config_check235
state_config235
state_read231
state_map230
state_content_check223
state_read_binary219
state_done218
state_progress_end197
state_progress_begin197
state_refresh126
state_filter122
state_write120
state_write_binary115
state_usage_print73
lev_name7
state_read_text5
state_write_text5
state_progress_restart1
generate_configuration1
decoding_error1
state_progress_stop1
position_clear_deleted0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.c.func.html b/cov/cmdline/state.c.func.html new file mode 100644 index 00000000..0780b3fe --- /dev/null +++ b/cov/cmdline/state.c.func.html @@ -0,0 +1,200 @@ + + + + + + + LCOV - lcov.info - cmdline/state.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:1547170590.7 %
Date:2015-05-12Functions:313296.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
decoding_error1
find_disk102384
generate_configuration1
info_is_required1498181
is_block_deleted4423464
lev_config_name178682
lev_config_scan5612
lev_name7
lev_raid_name235
position_clear_deleted0
position_is_required738011
state_config235
state_config_check235
state_content_check223
state_done218
state_filter122
state_init236
state_map230
state_progress1025177
state_progress_begin197
state_progress_end197
state_progress_restart1
state_progress_stop1
state_read231
state_read_binary219
state_read_text5
state_refresh126
state_usage_print73
state_write120
state_write_binary115
state_write_text5
validate_smartctl324
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.c.gcov.html b/cov/cmdline/state.c.gcov.html new file mode 100644 index 00000000..fd4ee958 --- /dev/null +++ b/cov/cmdline/state.c.gcov.html @@ -0,0 +1,5097 @@ + + + + + + + LCOV - lcov.info - cmdline/state.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:1547170590.7 %
Date:2015-05-12Functions:313296.9 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "elem.h"
+      21             : #include "import.h"
+      22             : #include "search.h"
+      23             : #include "state.h"
+      24             : #include "support.h"
+      25             : #include "parity.h"
+      26             : #include "stream.h"
+      27             : #include "raid/raid.h"
+      28             : #include "raid/cpu.h"
+      29             : 
+      30           7 : const char* lev_name(unsigned l)
+      31             : {
+      32           7 :         switch (l) {
+      33           2 :         case 0 : return "Parity";
+      34           1 :         case 1 : return "2-Parity";
+      35           1 :         case 2 : return "3-Parity";
+      36           1 :         case 3 : return "4-Parity";
+      37           1 :         case 4 : return "5-Parity";
+      38           1 :         case 5 : return "6-Parity";
+      39             :         }
+      40             : 
+      41           0 :         return 0;
+      42             : }
+      43             : 
+      44      178682 : const char* lev_config_name(unsigned l)
+      45             : {
+      46      178682 :         switch (l) {
+      47       70474 :         case 0 : return "parity";
+      48       57403 :         case 1 : return "2-parity";
+      49       12706 :         case 2 : return "3-parity";
+      50       12703 :         case 3 : return "4-parity";
+      51       12700 :         case 4 : return "5-parity";
+      52       12696 :         case 5 : return "6-parity";
+      53             :         }
+      54             : 
+      55           0 :         return 0;
+      56             : }
+      57             : 
+      58        5612 : static int lev_config_scan(const char* s, unsigned* level, unsigned* mode)
+      59             : {
+      60        5612 :         if (strcmp(s, "parity") == 0 || strcmp(s, "1-parity") == 0) {
+      61         397 :                 *level = 0;
+      62         397 :                 return 0;
+      63             :         }
+      64             : 
+      65        5215 :         if (strcmp(s, "q-parity") == 0 || strcmp(s, "2-parity") == 0) {
+      66         202 :                 *level = 1;
+      67         202 :                 return 0;
+      68             :         }
+      69             : 
+      70        5013 :         if (strcmp(s, "r-parity") == 0 || strcmp(s, "3-parity") == 0) {
+      71         177 :                 *level = 2;
+      72         177 :                 return 0;
+      73             :         }
+      74             : 
+      75        4836 :         if (strcmp(s, "4-parity") == 0) {
+      76         174 :                 *level = 3;
+      77         174 :                 return 0;
+      78             :         }
+      79             : 
+      80        4662 :         if (strcmp(s, "5-parity") == 0) {
+      81         171 :                 *level = 4;
+      82         171 :                 return 0;
+      83             :         }
+      84             : 
+      85        4491 :         if (strcmp(s, "6-parity") == 0) {
+      86         167 :                 *level = 5;
+      87         167 :                 return 0;
+      88             :         }
+      89             : 
+      90        4324 :         if (strcmp(s, "z-parity") == 0) {
+      91           0 :                 *level = 2;
+      92           0 :                 if (mode)
+      93           0 :                         *mode = RAID_MODE_VANDERMONDE;
+      94           0 :                 return 0;
+      95             :         }
+      96             : 
+      97        4324 :         return -1;
+      98             : }
+      99             : 
+     100         235 : const char* lev_raid_name(unsigned mode, unsigned n)
+     101             : {
+     102         235 :         switch (n) {
+     103          33 :         case 1 : return "par1";
+     104          25 :         case 2 : return "par2";
+     105           3 :         case 3 : if (mode == RAID_MODE_CAUCHY)
+     106           3 :                         return "par3";
+     107             :                 else
+     108           0 :                         return "parz";
+     109           3 :         case 4 : return "par4";
+     110           4 :         case 5 : return "par5";
+     111         167 :         case 6 : return "par6";
+     112             :         }
+     113             : 
+     114           0 :         return 0;
+     115             : }
+     116             : 
+     117         236 : void state_init(struct snapraid_state* state)
+     118             : {
+     119             :         unsigned l;
+     120             : 
+     121         236 :         memset(&state->opt, 0, sizeof(state->opt));
+     122         236 :         state->filter_hidden = 0;
+     123         236 :         state->autosave = 0;
+     124         236 :         state->need_write = 0;
+     125         236 :         state->checked_read = 0;
+     126         236 :         state->block_size = 256 * 1024; /* default 256 KiB */
+     127         236 :         state->raid_mode = RAID_MODE_CAUCHY;
+     128         236 :         state->file_mode = MODE_SEQUENTIAL;
+     129        1652 :         for (l = 0; l < LEV_MAX; ++l) {
+     130        1416 :                 state->parity[l].path[0] = 0;
+     131        1416 :                 state->parity[l].smartctl[0] = 0;
+     132        1416 :                 state->parity[l].uuid[0] = 0;
+     133        1416 :                 state->parity[l].device = 0;
+     134        1416 :                 state->parity[l].total_blocks = 0;
+     135        1416 :                 state->parity[l].free_blocks = 0;
+     136        1416 :                 state->parity[l].tick = 0;
+     137             :         }
+     138         236 :         state->tick_io = 0;
+     139         236 :         state->tick_cpu = 0;
+     140         236 :         state->tick_last = tick();
+     141         236 :         state->share[0] = 0;
+     142         236 :         state->pool[0] = 0;
+     143         236 :         state->pool_device = 0;
+     144         236 :         state->lockfile[0] = 0;
+     145         236 :         state->level = 1; /* default is the lowest protection */
+     146         236 :         state->clear_past_hash = 0;
+     147         236 :         state->no_conf = 0;
+     148             : 
+     149         236 :         tommy_list_init(&state->disklist);
+     150         236 :         tommy_list_init(&state->maplist);
+     151         236 :         tommy_list_init(&state->contentlist);
+     152         236 :         tommy_list_init(&state->filterlist);
+     153         236 :         tommy_list_init(&state->importlist);
+     154         236 :         tommy_hashdyn_init(&state->importset);
+     155         236 :         tommy_hashdyn_init(&state->previmportset);
+     156         236 :         tommy_hashdyn_init(&state->searchset);
+     157         236 :         tommy_arrayblkof_init(&state->infoarr, sizeof(snapraid_info));
+     158         236 : }
+     159             : 
+     160         218 : void state_done(struct snapraid_state* state)
+     161             : {
+     162         218 :         tommy_list_foreach(&state->disklist, (tommy_foreach_func*)disk_free);
+     163         218 :         tommy_list_foreach(&state->maplist, (tommy_foreach_func*)map_free);
+     164         218 :         tommy_list_foreach(&state->contentlist, (tommy_foreach_func*)content_free);
+     165         218 :         tommy_list_foreach(&state->filterlist, (tommy_foreach_func*)filter_free);
+     166         218 :         tommy_list_foreach(&state->importlist, (tommy_foreach_func*)import_file_free);
+     167         218 :         tommy_hashdyn_foreach(&state->searchset, (tommy_foreach_func*)search_file_free);
+     168         218 :         tommy_hashdyn_done(&state->importset);
+     169         218 :         tommy_hashdyn_done(&state->previmportset);
+     170         218 :         tommy_hashdyn_done(&state->searchset);
+     171         218 :         tommy_arrayblkof_done(&state->infoarr);
+     172         218 : }
+     173             : 
+     174             : /**
+     175             :  * Checks the configuration.
+     176             :  */
+     177         235 : static void state_config_check(struct snapraid_state* state, const char* path, tommy_list* filterlist_disk)
+     178             : {
+     179             :         tommy_node* i;
+     180             :         unsigned l;
+     181             : 
+     182             :         /* check for parity level */
+     183         235 :         if (state->raid_mode == RAID_MODE_VANDERMONDE) {
+     184           0 :                 if (state->level > 3) {
+     185             :                         /* LCOV_EXCL_START */
+     186             :                         log_fatal("If you use the z-parity you cannot have more than 3 parities.\n");
+     187             :                         exit(EXIT_FAILURE);
+     188             :                         /* LCOV_EXCL_STIO */
+     189             :                 }
+     190             :         }
+     191             : 
+     192             :         for (l = 0; l < state->level; ++l) {
+     193             :                 if (state->parity[l].path[0] == 0) {
+     194             :                         /* LCOV_EXCL_START */
+     195             :                         log_fatal("No '%s' specification in '%s'\n", lev_config_name(l), path);
+     196             :                         exit(EXIT_FAILURE);
+     197             :                         /* LCOV_EXCL_STOP */
+     198             :                 }
+     199             :         }
+     200             : 
+     201         235 :         if (tommy_list_empty(&state->contentlist)) {
+     202             :                 /* LCOV_EXCL_START */
+     203             :                 log_fatal("No 'content' specification in '%s'\n", path);
+     204             :                 exit(EXIT_FAILURE);
+     205             :                 /* LCOV_EXCL_STOP */
+     206             :         }
+     207             : 
+     208             :         /* checks for equal paths */
+     209        1596 :         for (i = state->contentlist; i != 0; i = i->next) {
+     210        1361 :                 struct snapraid_content* content = i->data;
+     211             : 
+     212        8807 :                 for (l = 0; l < state->level; ++l) {
+     213        7446 :                         if (pathcmp(state->parity[l].path, content->content) == 0) {
+     214             :                                 /* LCOV_EXCL_START */
+     215             :                                 log_fatal("Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content);
+     216             :                                 exit(EXIT_FAILURE);
+     217             :                                 /* LCOV_EXCL_STOP */
+     218             :                         }
+     219             :                 }
+     220             :         }
+     221             : 
+     222             :         /* check device of data disks */
+     223         235 :         if (!state->opt.skip_device && !state->opt.skip_disk_access) {
+     224           0 :                 for (i = state->disklist; i != 0; i = i->next) {
+     225             :                         tommy_node* j;
+     226           0 :                         struct snapraid_disk* disk = i->data;
+     227             : 
+     228             : #ifdef _WIN32
+     229             :                         if (disk->device == 0) {
+     230             :                                 /* LCOV_EXCL_START */
+     231             :                                 log_fatal("Disk '%s' has a zero serial number.\n", disk->dir);
+     232             :                                 log_fatal("This is not necessarely wrong, but for using SnapRAID\n");
+     233             :                                 log_fatal("it's better to change the serial number of the disk.\n");
+     234             :                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n");
+     235             :                                 exit(EXIT_FAILURE);
+     236             :                                 /* LCOV_EXCL_STOP */
+     237             :                         }
+     238             : #endif
+     239             : 
+     240           0 :                         if (!state->opt.force_device) {
+     241           0 :                                 for (j = i->next; j != 0; j = j->next) {
+     242           0 :                                         struct snapraid_disk* other = j->data;
+     243           0 :                                         if (disk->device == other->device) {
+     244             :                                                 /* LCOV_EXCL_START */
+     245             :                                                 log_fatal("Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir);
+     246             : #ifdef _WIN32
+     247             :                                                 log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device);
+     248             :                                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n");
+     249             :                                                 log_fatal("to change one of the disk serial.\n");
+     250             : #endif
+     251             :                                                 /* in "fix" we allow to continue anyway */
+     252             :                                                 if (strcmp(state->command, "fix") == 0) {
+     253             :                                                         log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command);
+     254             :                                                 }
+     255             :                                                 exit(EXIT_FAILURE);
+     256             :                                                 /* LCOV_EXCL_STOP */
+     257             :                                         }
+     258             :                                 }
+     259             :                         }
+     260             : 
+     261           0 :                         if (!state->opt.skip_parity_access) {
+     262           0 :                                 for (l = 0; l < state->level; ++l) {
+     263           0 :                                         if (disk->device == state->parity[l].device) {
+     264             :                                                 /* LCOV_EXCL_START */
+     265             :                                                 log_fatal("Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].path);
+     266             : #ifdef _WIN32
+     267             :                                                 log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device);
+     268             :                                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n");
+     269             :                                                 log_fatal("to change one of the disk serial.\n");
+     270             : #endif
+     271             :                                                 exit(EXIT_FAILURE);
+     272             :                                                 /* LCOV_EXCL_STOP */
+     273             :                                         }
+     274             :                                 }
+     275             :                         }
+     276             : 
+     277           0 :                         if (state->pool[0] != 0 && disk->device == state->pool_device) {
+     278             :                                 /* LCOV_EXCL_START */
+     279             :                                 log_fatal("Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool);
+     280             : #ifdef _WIN32
+     281             :                                 log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device);
+     282             :                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n");
+     283             :                                 log_fatal("to change one of the disk serial.\n");
+     284             : #endif
+     285             :                                 exit(EXIT_FAILURE);
+     286             :                                 /* LCOV_EXCL_STOP */
+     287             :                         }
+     288             :                 }
+     289             :         }
+     290             : 
+     291             :         /* check device of parity disks */
+     292         235 :         if (!state->opt.skip_device && !state->opt.skip_parity_access) {
+     293             : #ifdef _WIN32
+     294             :                 for (l = 0; l < state->level; ++l) {
+     295             :                         if (state->parity[l].device == 0) {
+     296             :                                 /* LCOV_EXCL_START */
+     297             :                                 log_fatal("Disk '%s' has a zero serial number.\n", state->parity[l].path);
+     298             :                                 log_fatal("This is not necessarely wrong, but for using SnapRAID\n");
+     299             :                                 log_fatal("it's better to change the serial number of the disk.\n");
+     300             :                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n");
+     301             :                                 exit(EXIT_FAILURE);
+     302             :                                 /* LCOV_EXCL_STOP */
+     303             :                         }
+     304             :                 }
+     305             : #endif
+     306             : 
+     307           0 :                 for (l = 0; l < state->level; ++l) {
+     308             :                         unsigned j;
+     309           0 :                         for (j = l + 1; j < state->level; ++j) {
+     310           0 :                                 if (state->parity[l].device == state->parity[j].device) {
+     311             :                                         /* LCOV_EXCL_START */
+     312             :                                         log_fatal("Parity '%s' and '%s' are on the same device.\n", state->parity[l].path, state->parity[j].path);
+     313             : #ifdef _WIN32
+     314             :                                         log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->parity[l].device);
+     315             :                                         log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n");
+     316             :                                         log_fatal("to change one of the disk serial.\n");
+     317             : #endif
+     318             :                                         exit(EXIT_FAILURE);
+     319             :                                         /* LCOV_EXCL_STOP */
+     320             :                                 }
+     321             :                         }
+     322             :                 }
+     323             : 
+     324           0 :                 for (l = 0; l < state->level; ++l) {
+     325           0 :                         if (state->pool[0] != 0 && state->pool_device == state->parity[l].device) {
+     326             :                                 /* LCOV_EXCL_START */
+     327             :                                 log_fatal("Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].path);
+     328             : #ifdef _WIN32
+     329             :                                 log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->pool_device);
+     330             :                                 log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n");
+     331             :                                 log_fatal("to change one of the disk serial.\n");
+     332             : #endif
+     333             :                                 exit(EXIT_FAILURE);
+     334             :                                 /* LCOV_EXCL_STOP */
+     335             :                         }
+     336             :                 }
+     337             :         }
+     338             : 
+     339             :         /* check device of pool disk */
+     340             : #ifdef _WIN32
+     341             :         if (!state->opt.skip_device) {
+     342             :                 if (state->pool[0] != 0 && state->pool_device == 0) {
+     343             :                         /* LCOV_EXCL_START */
+     344             :                         log_fatal("Disk '%s' has a zero serial number.\n", state->pool);
+     345             :                         log_fatal("This is not necessarely wrong, but for using SnapRAID\n");
+     346             :                         log_fatal("it's better to change the serial number of the disk.\n");
+     347             :                         log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n");
+     348             :                         exit(EXIT_FAILURE);
+     349             :                         /* LCOV_EXCL_STOP */
+     350             :                 }
+     351             :         }
+     352             : #endif
+     353             : 
+     354             :         /* count the content files */
+     355         235 :         if (!state->opt.skip_device) {
+     356             :                 unsigned content_count;
+     357             : 
+     358           0 :                 content_count = 0;
+     359           0 :                 for (i = state->contentlist; i != 0; i = i->next) {
+     360             :                         tommy_node* j;
+     361           0 :                         struct snapraid_content* content = i->data;
+     362             : 
+     363             :                         /* check if there are others in the same disk */
+     364           0 :                         for (j = i->next; j != 0; j = j->next) {
+     365           0 :                                 struct snapraid_content* other = j->data;
+     366           0 :                                 if (content->device == other->device) {
+     367           0 :                                         break;
+     368             :                                 }
+     369             :                         }
+     370           0 :                         if (j != 0) {
+     371             :                                 /* skip it */
+     372           0 :                                 continue;
+     373             :                         }
+     374             : 
+     375           0 :                         ++content_count;
+     376             :                 }
+     377             : 
+     378           0 :                 if (content_count < state->level + 1) {
+     379             :                         /* LCOV_EXCL_START */
+     380             :                         log_fatal("You must have at least %d 'content' files in different disks.\n", state->level + 1);
+     381             :                         exit(EXIT_FAILURE);
+     382             :                         /* LCOV_EXCL_STOP */
+     383             :                 }
+     384             :         }
+     385             : 
+     386             :         /* check for speed */
+     387             : #ifdef CONFIG_X86
+     388         235 :         if (!raid_cpu_has_ssse3())
+     389             : #endif
+     390           0 :         if (state->raid_mode == RAID_MODE_CAUCHY) {
+     391           0 :                 if (state->level == 3) {
+     392           0 :                         log_fatal("WARNING! Your CPU doesn't have a fast implementation for triple parity.\n");
+     393           0 :                         log_fatal("WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n");
+     394           0 :                 } else if (state->level > 3) {
+     395           0 :                         log_fatal("WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n");
+     396           0 :                         log_fatal("WARNING! It's recommended to reduce the parity levels to triple parity.\n");
+     397             :                 }
+     398             :         }
+     399             : 
+     400             :         /* ensure that specified filter disks are valid ones */
+     401         238 :         for (i = tommy_list_head(filterlist_disk); i != 0; i = i->next) {
+     402             :                 tommy_node* j;
+     403           3 :                 struct snapraid_filter* filter = i->data;
+     404           8 :                 for (j = state->disklist; j != 0; j = j->next) {
+     405           8 :                         struct snapraid_disk* disk = j->data;
+     406           8 :                         if (fnmatch(filter->pattern, disk->name, FNM_CASEINSENSITIVE_FOR_WIN) == 0)
+     407           3 :                                 break;
+     408             :                 }
+     409           3 :                 if (j == 0) {
+     410             :                         /* LCOV_EXCL_START */
+     411             :                         log_fatal("Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern);
+     412             :                         exit(EXIT_FAILURE);
+     413             :                         /* LCOV_EXCL_STOP */
+     414             :                 }
+     415             :         }
+     416         235 : }
+     417             : 
+     418             : /**
+     419             :  * Validate the smartctl command.
+     420             :  *
+     421             :  * It must contains only one %s string, and not other % chars.
+     422             :  */
+     423         324 : static int validate_smartctl(const char* custom)
+     424             : {
+     425         324 :         const char* s = custom;
+     426         324 :         int arg = 0;
+     427             : 
+     428        2268 :         while (*s) {
+     429        1620 :                 if (s[0] == '%' && s[1] == 's') {
+     430         162 :                         if (arg) {
+     431             :                                 /* LCOV_EXCL_START */
+     432             :                                 return -1;
+     433             :                                 /* LCOV_EXCL_STOP */
+     434             :                         }
+     435         162 :                         arg = 1;
+     436        1458 :                 } else if (s[0] == '%') {
+     437             :                         /* LCOV_EXCL_START */
+     438             :                         return -1;
+     439             :                         /* LCOV_EXCL_STOP */
+     440             :                 }
+     441             : 
+     442        1620 :                 ++s;
+     443             :         }
+     444             : 
+     445         324 :         return 0;
+     446             : }
+     447             : 
+     448         235 : void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk)
+     449             : {
+     450             :         STREAM* f;
+     451             :         unsigned line;
+     452             :         tommy_node* i;
+     453             :         unsigned l;
+     454             : 
+     455             :         /* copy the options */
+     456         235 :         state->opt = *opt;
+     457             : 
+     458             :         /* if unset, sort by physical order */
+     459         235 :         if (!state->opt.force_order)
+     460           1 :                 state->opt.force_order = SORT_PHYSICAL;
+     461             : 
+     462             :         /* adjust file mode */
+     463         235 :         if (state->opt.skip_sequential)
+     464           1 :                 state->file_mode &= ~MODE_SEQUENTIAL;
+     465             : 
+     466             :         /* store current command */
+     467         235 :         state->command = command;
+     468             : 
+     469         235 :         log_tag("conf:%s\n", path);
+     470             : 
+     471         235 :         f = sopen_read(path);
+     472         235 :         if (!f) {
+     473             :                 /* LCOV_EXCL_START */
+     474             :                 if (errno == ENOENT) {
+     475             :                         log_fatal("No configuration file found at '%s'\n", path);
+     476             :                 } else if (errno == EACCES) {
+     477             :                         log_fatal("You do not have rights to access the configuration file '%s'\n", path);
+     478             :                 } else {
+     479             :                         log_fatal("Error opening the configuration file '%s'. %s.\n", path, strerror(errno));
+     480             :                 }
+     481             :                 exit(EXIT_FAILURE);
+     482             :                 /* LCOV_EXCL_STOP */
+     483             :         }
+     484             : 
+     485         235 :         line = 1;
+     486             :         while (1) {
+     487             :                 char tag[PATH_MAX];
+     488             :                 char buffer[PATH_MAX];
+     489             :                 int ret;
+     490             :                 int c;
+     491             :                 unsigned level;
+     492             : 
+     493             :                 /* skip initial spaces */
+     494        5523 :                 sgetspace(f);
+     495             : 
+     496             :                 /* read the command */
+     497        5523 :                 ret = sgettok(f, tag, sizeof(tag));
+     498        5523 :                 if (ret < 0) {
+     499             :                         /* LCOV_EXCL_START */
+     500             :                         log_fatal("Error reading the configuration file '%s' at line %u\n", path, line);
+     501             :                         exit(EXIT_FAILURE);
+     502             :                         /* LCOV_EXCL_STOP */
+     503             :                 }
+     504             : 
+     505             :                 /* skip spaces after the command */
+     506        5523 :                 sgetspace(f);
+     507             : 
+     508        5523 :                 if (strcmp(tag, "blocksize") == 0
+     509             :                         /* block_size is the old format of the option */
+     510        5288 :                         || strcmp(tag, "block_size") == 0) {
+     511             : 
+     512         235 :                         ret = sgetu32(f, &state->block_size);
+     513         235 :                         if (ret < 0) {
+     514             :                                 /* LCOV_EXCL_START */
+     515             :                                 log_fatal("Invalid 'blocksize' specification in '%s' at line %u\n", path, line);
+     516             :                                 exit(EXIT_FAILURE);
+     517             :                                 /* LCOV_EXCL_STOP */
+     518             :                         }
+     519         235 :                         if (state->block_size < 1) {
+     520             :                                 /* LCOV_EXCL_START */
+     521             :                                 log_fatal("Too small 'blocksize' specification in '%s' at line %u\n", path, line);
+     522             :                                 exit(EXIT_FAILURE);
+     523             :                                 /* LCOV_EXCL_STOP */
+     524             :                         }
+     525         235 :                         if (state->block_size > 16 * 1024) {
+     526             :                                 /* LCOV_EXCL_START */
+     527             :                                 log_fatal("Too big 'blocksize' specification in '%s' at line %u\n", path, line);
+     528             :                                 exit(EXIT_FAILURE);
+     529             :                                 /* LCOV_EXCL_STOP */
+     530             :                         }
+     531             :                         /* check if it's a power of 2 */
+     532         235 :                         if ((state->block_size & (state->block_size - 1)) != 0) {
+     533             :                                 /* LCOV_EXCL_START */
+     534             :                                 log_fatal("Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line);
+     535             :                                 exit(EXIT_FAILURE);
+     536             :                                 /* LCOV_EXCL_STOP */
+     537             :                         }
+     538         235 :                         state->block_size *= 1024;
+     539        5288 :                 } else if (lev_config_scan(tag, &level, &state->raid_mode) == 0) {
+     540             :                         char device[PATH_MAX];
+     541             :                         char* slash;
+     542             : 
+     543        1126 :                         if (*state->parity[level].path) {
+     544             :                                 /* LCOV_EXCL_START */
+     545             :                                 log_fatal("Multiple '%s' specification in '%s' at line %u\n", tag, path, line);
+     546             :                                 exit(EXIT_FAILURE);
+     547             :                                 /* LCOV_EXCL_STOP */
+     548             :                         }
+     549             : 
+     550        1126 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     551        1126 :                         if (ret < 0) {
+     552             :                                 /* LCOV_EXCL_START */
+     553             :                                 log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line);
+     554             :                                 exit(EXIT_FAILURE);
+     555             :                                 /* LCOV_EXCL_STOP */
+     556             :                         }
+     557             : 
+     558        1126 :                         if (!*buffer) {
+     559             :                                 /* LCOV_EXCL_START */
+     560             :                                 log_fatal("Empty '%s' specification in '%s' at line %u\n", tag, path, line);
+     561             :                                 exit(EXIT_FAILURE);
+     562             :                                 /* LCOV_EXCL_STOP */
+     563             :                         }
+     564             : 
+     565        1126 :                         pathimport(state->parity[level].path, sizeof(state->parity[level].path), buffer);
+     566             : 
+     567        1126 :                         if (!state->opt.skip_parity_access) {
+     568             :                                 struct stat st;
+     569             : 
+     570             :                                 /* get the device of the directory containing the parity file */
+     571         940 :                                 pathimport(device, sizeof(device), buffer);
+     572         940 :                                 slash = strrchr(device, '/');
+     573         940 :                                 if (slash)
+     574         940 :                                         *slash = 0;
+     575             :                                 else
+     576           0 :                                         pathcpy(device, sizeof(device), ".");
+     577         940 :                                 if (stat(device, &st) != 0) {
+     578             :                                         /* LCOV_EXCL_START */
+     579             :                                         log_fatal("Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line);
+     580             :                                         exit(EXIT_FAILURE);
+     581             :                                         /* LCOV_EXCL_STOP */
+     582             :                                 }
+     583             : 
+     584         940 :                                 state->parity[level].device = st.st_dev;
+     585             :                         } else {
+     586             :                                 /* if parity is skipped, uses a fake device */
+     587         186 :                                 state->parity[level].device = 0;
+     588             :                         }
+     589             : 
+     590             :                         /* adjust the level */
+     591        1126 :                         if (state->level < level + 1)
+     592         891 :                                 state->level = level + 1;
+     593        4162 :                 } else if (strcmp(tag, "share") == 0) {
+     594          33 :                         if (*state->share) {
+     595             :                                 /* LCOV_EXCL_START */
+     596             :                                 log_fatal("Multiple 'share' specification in '%s' at line %u\n", path, line);
+     597             :                                 exit(EXIT_FAILURE);
+     598             :                                 /* LCOV_EXCL_STOP */
+     599             :                         }
+     600             : 
+     601          33 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     602          33 :                         if (ret < 0) {
+     603             :                                 /* LCOV_EXCL_START */
+     604             :                                 log_fatal("Invalid 'share' specification in '%s' at line %u\n", path, line);
+     605             :                                 exit(EXIT_FAILURE);
+     606             :                                 /* LCOV_EXCL_STOP */
+     607             :                         }
+     608             : 
+     609          33 :                         if (!*buffer) {
+     610             :                                 /* LCOV_EXCL_START */
+     611             :                                 log_fatal("Empty 'share' specification in '%s' at line %u\n", path, line);
+     612             :                                 exit(EXIT_FAILURE);
+     613             :                                 /* LCOV_EXCL_STOP */
+     614             :                         }
+     615             : 
+     616          33 :                         pathimport(state->share, sizeof(state->share), buffer);
+     617        4129 :                 } else if (strcmp(tag, "pool") == 0) {
+     618             :                         struct stat st;
+     619             : 
+     620          33 :                         if (*state->pool) {
+     621             :                                 /* LCOV_EXCL_START */
+     622             :                                 log_fatal("Multiple 'pool' specification in '%s' at line %u\n", path, line);
+     623             :                                 exit(EXIT_FAILURE);
+     624             :                                 /* LCOV_EXCL_STOP */
+     625             :                         }
+     626             : 
+     627          33 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     628          33 :                         if (ret < 0) {
+     629             :                                 /* LCOV_EXCL_START */
+     630             :                                 log_fatal("Invalid 'pool' specification in '%s' at line %u\n", path, line);
+     631             :                                 exit(EXIT_FAILURE);
+     632             :                                 /* LCOV_EXCL_STOP */
+     633             :                         }
+     634             : 
+     635          33 :                         if (!*buffer) {
+     636             :                                 /* LCOV_EXCL_START */
+     637             :                                 log_fatal("Empty 'pool' specification in '%s' at line %u\n", path, line);
+     638             :                                 exit(EXIT_FAILURE);
+     639             :                                 /* LCOV_EXCL_STOP */
+     640             :                         }
+     641             : 
+     642          33 :                         pathimport(state->pool, sizeof(state->pool), buffer);
+     643             : 
+     644             :                         /* get the device of the directory containing the pool tree */
+     645          33 :                         if (stat(buffer, &st) != 0) {
+     646             :                                 /* LCOV_EXCL_START */
+     647             :                                 log_fatal("Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line);
+     648             :                                 exit(EXIT_FAILURE);
+     649             :                                 /* LCOV_EXCL_STOP */
+     650             :                         }
+     651             : 
+     652          33 :                         state->pool_device = st.st_dev;
+     653        4096 :                 } else if (strcmp(tag, "content") == 0) {
+     654             :                         struct snapraid_content* content;
+     655             :                         char device[PATH_MAX];
+     656             :                         char* slash;
+     657             :                         struct stat st;
+     658             : 
+     659        1361 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     660        1361 :                         if (ret < 0) {
+     661             :                                 /* LCOV_EXCL_START */
+     662             :                                 log_fatal("Invalid 'content' specification in '%s' at line %u\n", path, line);
+     663             :                                 exit(EXIT_FAILURE);
+     664             :                                 /* LCOV_EXCL_STOP */
+     665             :                         }
+     666             : 
+     667        1361 :                         if (pathcmp(buffer, "/dev/null") == 0 || pathcmp(buffer, "NUL") == 0) {
+     668             :                                 /* LCOV_EXCL_START */
+     669             :                                 log_fatal("You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line);
+     670             :                                 exit(EXIT_FAILURE);
+     671             :                                 /* LCOV_EXCL_STOP */
+     672             :                         }
+     673             : 
+     674        1361 :                         if (!*buffer) {
+     675             :                                 /* LCOV_EXCL_START */
+     676             :                                 log_fatal("Empty 'content' specification in '%s' at line %u\n", path, line);
+     677             :                                 exit(EXIT_FAILURE);
+     678             :                                 /* LCOV_EXCL_STOP */
+     679             :                         }
+     680             : 
+     681             :                         /* check if the content file is already specified */
+     682        5084 :                         for (i = state->contentlist; i != 0; i = i->next) {
+     683        3723 :                                 content = i->data;
+     684        3723 :                                 if (pathcmp(content->content, buffer) == 0)
+     685           0 :                                         break;
+     686             :                         }
+     687        1361 :                         if (i) {
+     688             :                                 /* LCOV_EXCL_START */
+     689             :                                 log_fatal("Duplicate 'content' specification in '%s' at line %u\n", path, line);
+     690             :                                 exit(EXIT_FAILURE);
+     691             :                                 /* LCOV_EXCL_STOP */
+     692             :                         }
+     693             : 
+     694             :                         /* get the device of the directory containing the content file */
+     695        1361 :                         pathimport(device, sizeof(device), buffer);
+     696        1361 :                         slash = strrchr(device, '/');
+     697        1361 :                         if (slash)
+     698        1361 :                                 *slash = 0;
+     699             :                         else
+     700           0 :                                 pathcpy(device, sizeof(device), ".");
+     701        1361 :                         if (stat(device, &st) != 0) {
+     702             :                                 /* LCOV_EXCL_START */
+     703             :                                 log_fatal("Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line);
+     704             :                                 exit(EXIT_FAILURE);
+     705             :                                 /* LCOV_EXCL_STOP */
+     706             :                         }
+     707             : 
+     708             :                         /* set the lock file at the first content file */
+     709        1361 :                         if (tommy_list_empty(&state->contentlist)) {
+     710         235 :                                 pathcpy(state->lockfile, sizeof(state->lockfile), buffer);
+     711         235 :                                 pathcat(state->lockfile, sizeof(state->lockfile), ".lock");
+     712             :                         }
+     713             : 
+     714        1361 :                         content = content_alloc(buffer, st.st_dev);
+     715             : 
+     716        1361 :                         tommy_list_insert_tail(&state->contentlist, &content->node, content);
+     717        2735 :                 } else if (strcmp(tag, "disk") == 0) {
+     718             :                         char dir[PATH_MAX];
+     719             :                         char device[PATH_MAX];
+     720             :                         struct snapraid_disk* disk;
+     721             :                         uint64_t dev;
+     722             : 
+     723        1405 :                         ret = sgettok(f, buffer, sizeof(buffer));
+     724        1405 :                         if (ret < 0) {
+     725             :                                 /* LCOV_EXCL_START */
+     726             :                                 log_fatal("Invalid 'disk' name specification in '%s' at line %u\n", path, line);
+     727             :                                 exit(EXIT_FAILURE);
+     728             :                                 /* LCOV_EXCL_STOP */
+     729             :                         }
+     730             : 
+     731        1405 :                         if (!*buffer) {
+     732             :                                 /* LCOV_EXCL_START */
+     733             :                                 log_fatal("Empty 'disk' name specification in '%s' at line %u\n", path, line);
+     734             :                                 exit(EXIT_FAILURE);
+     735             :                                 /* LCOV_EXCL_STOP */
+     736             :                         }
+     737             : 
+     738        1405 :                         sgetspace(f);
+     739             : 
+     740        1405 :                         ret = sgetlasttok(f, dir, sizeof(dir));
+     741        1405 :                         if (ret < 0) {
+     742             :                                 /* LCOV_EXCL_START */
+     743             :                                 log_fatal("Invalid 'disk' dir specification in '%s' at line %u\n", path, line);
+     744             :                                 exit(EXIT_FAILURE);
+     745             :                                 /* LCOV_EXCL_STOP */
+     746             :                         }
+     747             : 
+     748        1405 :                         if (!*dir) {
+     749             :                                 /* LCOV_EXCL_START */
+     750             :                                 log_fatal("Empty 'disk' dir specification in '%s' at line %u\n", path, line);
+     751             :                                 exit(EXIT_FAILURE);
+     752             :                                 /* LCOV_EXCL_STOP */
+     753             :                         }
+     754             : 
+     755             :                         /* get the device of the dir */
+     756        1405 :                         pathimport(device, sizeof(device), dir);
+     757             : 
+     758             :                         /* check if the disk name already exists */
+     759        4905 :                         for (i = state->disklist; i != 0; i = i->next) {
+     760        3500 :                                 disk = i->data;
+     761        3500 :                                 if (strcmp(disk->name, buffer) == 0)
+     762           0 :                                         break;
+     763             :                         }
+     764        1405 :                         if (i) {
+     765             :                                 /* LCOV_EXCL_START */
+     766             :                                 log_fatal("Duplicate disk name '%s' at line %u\n", buffer, line);
+     767             :                                 exit(EXIT_FAILURE);
+     768             :                                 /* LCOV_EXCL_STOP */
+     769             :                         }
+     770             : 
+     771        1405 :                         if (!state->opt.skip_disk_access) {
+     772             :                                 struct stat st;
+     773             : 
+     774        1249 :                                 if (stat(device, &st) != 0) {
+     775             :                                         /* LCOV_EXCL_START */
+     776             :                                         log_fatal("Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line);
+     777             :                                         exit(EXIT_FAILURE);
+     778             :                                         /* LCOV_EXCL_STOP */
+     779             :                                 }
+     780             : 
+     781        1249 :                                 dev = st.st_dev;
+     782             :                         } else {
+     783             :                                 /* if data disks are skipped, uses a fake device */
+     784         156 :                                 dev = 0;
+     785             :                         }
+     786             : 
+     787        1405 :                         disk = disk_alloc(buffer, dir, dev);
+     788             : 
+     789        1405 :                         tommy_list_insert_tail(&state->disklist, &disk->node, disk);
+     790        1330 :                 } else if (strcmp(tag, "smartctl") == 0) {
+     791             :                         char custom[PATH_MAX];
+     792             : 
+     793         324 :                         ret = sgettok(f, buffer, sizeof(buffer));
+     794         324 :                         if (ret < 0) {
+     795             :                                 /* LCOV_EXCL_START */
+     796             :                                 log_fatal("Invalid 'smartctl' name specification in '%s' at line %u\n", path, line);
+     797             :                                 exit(EXIT_FAILURE);
+     798             :                                 /* LCOV_EXCL_STOP */
+     799             :                         }
+     800             : 
+     801         324 :                         if (!*buffer) {
+     802             :                                 /* LCOV_EXCL_START */
+     803             :                                 log_fatal("Empty 'smartctl' name specification in '%s' at line %u\n", path, line);
+     804             :                                 exit(EXIT_FAILURE);
+     805             :                                 /* LCOV_EXCL_STOP */
+     806             :                         }
+     807             : 
+     808         324 :                         sgetspace(f);
+     809             : 
+     810         324 :                         ret = sgetlasttok(f, custom, sizeof(custom));
+     811         324 :                         if (ret < 0) {
+     812             :                                 /* LCOV_EXCL_START */
+     813             :                                 log_fatal("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line);
+     814             :                                 exit(EXIT_FAILURE);
+     815             :                                 /* LCOV_EXCL_STOP */
+     816             :                         }
+     817             : 
+     818         324 :                         if (!*custom) {
+     819             :                                 /* LCOV_EXCL_START */
+     820             :                                 log_fatal("Empty 'smartctl' option specification in '%s' at line %u\n", path, line);
+     821             :                                 exit(EXIT_FAILURE);
+     822             :                                 /* LCOV_EXCL_STOP */
+     823             :                         }
+     824             : 
+     825         324 :                         if (validate_smartctl(custom) != 0) {
+     826             :                                 /* LCOV_EXCL_START */
+     827             :                                 log_fatal("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line);
+     828             :                                 exit(EXIT_FAILURE);
+     829             :                                 /* LCOV_EXCL_STOP */
+     830             :                         }
+     831             : 
+     832             :                         /* search for parity */
+     833         324 :                         if (lev_config_scan(buffer, &level, 0) == 0) {
+     834         162 :                                 if (state->parity[level].smartctl[0] != 0) {
+     835             :                                         /* LCOV_EXCL_START */
+     836             :                                         log_fatal("Duplicate parity smartctl '%s' at line %u\n", buffer, line);
+     837             :                                         exit(EXIT_FAILURE);
+     838             :                                         /* LCOV_EXCL_STOP */
+     839             :                                 }
+     840             : 
+     841         162 :                                 pathcpy(state->parity[level].smartctl, sizeof(state->parity[level].smartctl), custom);
+     842             :                         } else {
+     843             :                                 /* search the disk */
+     844             :                                 struct snapraid_disk* disk;
+     845         162 :                                 for (i = state->disklist; i != 0; i = i->next) {
+     846         162 :                                         disk = i->data;
+     847         162 :                                         if (strcmp(disk->name, buffer) == 0)
+     848         162 :                                                 break;
+     849             :                                 }
+     850         162 :                                 if (!i) {
+     851             :                                         /* LCOV_EXCL_START */
+     852             :                                         log_fatal("Missing disk smartctl '%s' at line %u\n", buffer, line);
+     853             :                                         exit(EXIT_FAILURE);
+     854             :                                         /* LCOV_EXCL_STOP */
+     855             :                                 }
+     856         162 :                                 if (disk->smartctl[0] != 0) {
+     857             :                                         /* LCOV_EXCL_START */
+     858             :                                         log_fatal("Duplicate disk name '%s' at line %u\n", buffer, line);
+     859             :                                         exit(EXIT_FAILURE);
+     860             :                                         /* LCOV_EXCL_STOP */
+     861             :                                 }
+     862             : 
+     863         162 :                                 pathcpy(disk->smartctl, sizeof(disk->smartctl), custom);
+     864             :                         }
+     865        1006 :                 } else if (strcmp(tag, "nohidden") == 0) {
+     866           0 :                         state->filter_hidden = 1;
+     867        1006 :                 } else if (strcmp(tag, "exclude") == 0) {
+     868             :                         struct snapraid_filter* filter;
+     869             : 
+     870         235 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     871         235 :                         if (ret < 0) {
+     872             :                                 /* LCOV_EXCL_START */
+     873             :                                 log_fatal("Invalid 'exclude' specification in '%s' at line %u\n", path, line);
+     874             :                                 exit(EXIT_FAILURE);
+     875             :                                 /* LCOV_EXCL_STOP */
+     876             :                         }
+     877             : 
+     878         235 :                         if (!*buffer) {
+     879             :                                 /* LCOV_EXCL_START */
+     880             :                                 log_fatal("Empty 'exclude' specification in '%s' at line %u\n", path, line);
+     881             :                                 exit(EXIT_FAILURE);
+     882             :                                 /* LCOV_EXCL_STOP */
+     883             :                         }
+     884             : 
+     885         235 :                         filter = filter_alloc_file(-1, buffer);
+     886         235 :                         if (!filter) {
+     887             :                                 /* LCOV_EXCL_START */
+     888             :                                 log_fatal("Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line);
+     889             :                                 exit(EXIT_FAILURE);
+     890             :                                 /* LCOV_EXCL_STOP */
+     891             :                         }
+     892         235 :                         tommy_list_insert_tail(&state->filterlist, &filter->node, filter);
+     893         771 :                 } else if (strcmp(tag, "include") == 0) {
+     894             :                         struct snapraid_filter* filter;
+     895             : 
+     896         235 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     897         235 :                         if (ret < 0) {
+     898             :                                 /* LCOV_EXCL_START */
+     899             :                                 log_fatal("Invalid 'include' specification in '%s' at line %u\n", path, line);
+     900             :                                 exit(EXIT_FAILURE);
+     901             :                                 /* LCOV_EXCL_STOP */
+     902             :                         }
+     903             : 
+     904         235 :                         if (!*buffer) {
+     905             :                                 /* LCOV_EXCL_START */
+     906             :                                 log_fatal("Empty 'include' specification in '%s' at line %u\n", path, line);
+     907             :                                 exit(EXIT_FAILURE);
+     908             :                                 /* LCOV_EXCL_STOP */
+     909             :                         }
+     910             : 
+     911         235 :                         filter = filter_alloc_file(1, buffer);
+     912         235 :                         if (!filter) {
+     913             :                                 /* LCOV_EXCL_START */
+     914             :                                 log_fatal("Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line);
+     915             :                                 exit(EXIT_FAILURE);
+     916             :                                 /* LCOV_EXCL_STOP */
+     917             :                         }
+     918         235 :                         tommy_list_insert_tail(&state->filterlist, &filter->node, filter);
+     919         536 :                 } else if (strcmp(tag, "autosave") == 0) {
+     920             :                         char* e;
+     921             : 
+     922          33 :                         ret = sgetlasttok(f, buffer, sizeof(buffer));
+     923          33 :                         if (ret < 0) {
+     924             :                                 /* LCOV_EXCL_START */
+     925             :                                 log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line);
+     926             :                                 exit(EXIT_FAILURE);
+     927             :                                 /* LCOV_EXCL_STOP */
+     928             :                         }
+     929             : 
+     930          33 :                         if (!*buffer) {
+     931             :                                 /* LCOV_EXCL_START */
+     932             :                                 log_fatal("Empty 'autosave' specification in '%s' at line %u\n", path, line);
+     933             :                                 exit(EXIT_FAILURE);
+     934             :                                 /* LCOV_EXCL_STOP */
+     935             :                         }
+     936             : 
+     937          33 :                         state->autosave = strtoul(buffer, &e, 0);
+     938             : 
+     939          33 :                         if (!e || *e) {
+     940             :                                 /* LCOV_EXCL_START */
+     941             :                                 log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line);
+     942             :                                 exit(EXIT_FAILURE);
+     943             :                                 /* LCOV_EXCL_STOP */
+     944             :                         }
+     945             : 
+     946             :                         /* convert to GB */
+     947          33 :                         state->autosave *= GIGA;
+     948         503 :                 } else if (tag[0] == 0) {
+     949             :                         /* allow empty lines */
+     950          33 :                 } else if (tag[0] == '#') {
+     951          33 :                         ret = sgetline(f, buffer, sizeof(buffer));
+     952          33 :                         if (ret < 0) {
+     953             :                                 /* LCOV_EXCL_START */
+     954             :                                 log_fatal("Invalid comment in '%s' at line %u\n", path, line);
+     955             :                                 exit(EXIT_FAILURE);
+     956             :                                 /* LCOV_EXCL_STOP */
+     957             :                         }
+     958             :                 } else {
+     959             :                         /* LCOV_EXCL_START */
+     960             :                         log_fatal("Invalid command '%s' in '%s' at line %u\n", tag, path, line);
+     961             :                         exit(EXIT_FAILURE);
+     962             :                         /* LCOV_EXCL_STOP */
+     963             :                 }
+     964             : 
+     965             :                 /* skip final spaces */
+     966        5523 :                 sgetspace(f);
+     967             : 
+     968             :                 /* next line */
+     969        5523 :                 c = sgeteol(f);
+     970        5523 :                 if (c == EOF) {
+     971         235 :                         break;
+     972             :                 }
+     973        5288 :                 if (c != '\n') {
+     974             :                         /* LCOV_EXCL_START */
+     975             :                         log_fatal("Extra data in '%s' at line %u\n", path, line);
+     976             :                         exit(EXIT_FAILURE);
+     977             :                         /* LCOV_EXCL_STOP */
+     978             :                 }
+     979        5288 :                 ++line;
+     980        5288 :         }
+     981             : 
+     982         235 :         if (serror(f)) {
+     983             :                 /* LCOV_EXCL_START */
+     984             :                 log_fatal("Error reading the configuration file '%s' at line %u\n", path, line);
+     985             :                 exit(EXIT_FAILURE);
+     986             :                 /* LCOV_EXCL_STOP */
+     987             :         }
+     988             : 
+     989         235 :         sclose(f);
+     990             : 
+     991         235 :         state_config_check(state, path, filterlist_disk);
+     992             : 
+     993             :         /* select the default hash */
+     994         235 :         if (state->opt.force_murmur3) {
+     995           1 :                 state->besthash = HASH_MURMUR3;
+     996         234 :         } else if (state->opt.force_spooky2) {
+     997           1 :                 state->besthash = HASH_SPOOKY2;
+     998             :         } else {
+     999             : #ifdef CONFIG_X86
+    1000         233 :                 if (sizeof(void*) == 4 && !raid_cpu_has_slowmult())
+    1001         233 :                         state->besthash = HASH_MURMUR3;
+    1002             :                 else
+    1003           0 :                         state->besthash = HASH_SPOOKY2;
+    1004             : #else
+    1005             :                 if (sizeof(void*) == 4)
+    1006             :                         state->besthash = HASH_MURMUR3;
+    1007             :                 else
+    1008             :                         state->besthash = HASH_SPOOKY2;
+    1009             : #endif
+    1010             :         }
+    1011             : 
+    1012             :         /* by default use the best hash */
+    1013         235 :         state->hash = state->besthash;
+    1014             : 
+    1015             :         /* by default use a random hash seed */
+    1016         235 :         if (randomize(state->hashseed, HASH_SIZE) != 0) {
+    1017             :                 /* LCOV_EXCL_START */
+    1018             :                 log_fatal("Failed to get random values.\n");
+    1019             :                 exit(EXIT_FAILURE);
+    1020             :                 /* LCOV_EXCL_STOP */
+    1021             :         }
+    1022             : 
+    1023             :         /* no previous hash by default */
+    1024         235 :         state->prevhash = HASH_UNDEFINED;
+    1025             : 
+    1026             :         /* intentionally not set the prevhashseed, if used valgrind will warn about it */
+    1027             : 
+    1028         235 :         log_tag("blocksize:%u\n", state->block_size);
+    1029        1640 :         for (i = state->disklist; i != 0; i = i->next) {
+    1030        1405 :                 struct snapraid_disk* disk = i->data;
+    1031        1405 :                 log_tag("disk:%s:%s\n", disk->name, disk->dir);
+    1032             :         }
+    1033             : 
+    1034         235 :         log_tag("mode:%s\n", lev_raid_name(state->raid_mode, state->level));
+    1035        1361 :         for (l = 0; l < state->level; ++l)
+    1036        1126 :                 log_tag("%s:%s\n", lev_config_name(l), state->parity[l].path);
+    1037         235 :         if (state->pool[0] != 0)
+    1038          33 :                 log_tag("pool:%s\n", state->pool);
+    1039         235 :         if (state->share[0] != 0)
+    1040          33 :                 log_tag("share:%s\n", state->share);
+    1041         235 :         if (state->autosave != 0)
+    1042          33 :                 log_tag("autosave:%" PRIu64 "\n", state->autosave);
+    1043         705 :         for (i = tommy_list_head(&state->filterlist); i != 0; i = i->next) {
+    1044             :                 char out[PATH_MAX];
+    1045         470 :                 struct snapraid_filter* filter = i->data;
+    1046         470 :                 log_tag("filter:%s\n", filter_type(filter, out, sizeof(out)));
+    1047             :         }
+    1048         235 :         if (state->filter_hidden)
+    1049           0 :                 log_tag("filter:nohidden:\n");
+    1050         235 :         log_flush();
+    1051         235 : }
+    1052             : 
+    1053             : /**
+    1054             :  * Finds a disk by name.
+    1055             :  */
+    1056      102384 : static struct snapraid_disk* find_disk(struct snapraid_state* state, const char* name)
+    1057             : {
+    1058             :         tommy_node* i;
+    1059             : 
+    1060      359771 :         for (i = state->disklist; i != 0; i = i->next) {
+    1061      359765 :                 struct snapraid_disk* disk = i->data;
+    1062      359765 :                 if (strcmp(disk->name, name) == 0)
+    1063      102378 :                         return disk;
+    1064             :         }
+    1065             : 
+    1066           6 :         if (state->no_conf) {
+    1067             :                 /* without a configuration file, add disks automatically */
+    1068             :                 struct snapraid_disk* disk;
+    1069             : 
+    1070           6 :                 disk = disk_alloc(name, "DUMMY/", -1);
+    1071             : 
+    1072           6 :                 tommy_list_insert_tail(&state->disklist, &disk->node, disk);
+    1073             : 
+    1074           6 :                 return disk;
+    1075             :         }
+    1076             : 
+    1077           0 :         return 0;
+    1078             : }
+    1079             : 
+    1080             : /**
+    1081             :  * Updates the disk mapping if required.
+    1082             :  */
+    1083         230 : static void state_map(struct snapraid_state* state)
+    1084             : {
+    1085             :         unsigned hole;
+    1086             :         tommy_node* i;
+    1087             :         unsigned uuid_mismatch;
+    1088             :         unsigned diskcount;
+    1089             :         unsigned l;
+    1090             : 
+    1091             :         /* removes all the mapping without a disk */
+    1092             :         /* this happens when a disk is removed from the configuration file */
+    1093             :         /* From SnapRAID 4.0 mappings are automatically removed if a disk is not used */
+    1094             :         /* when saving the content file, but we keep this code to import older content files. */
+    1095        1731 :         for (i = state->maplist; i != 0; ) {
+    1096        1271 :                 struct snapraid_map* map = i->data;
+    1097             :                 struct snapraid_disk* disk;
+    1098             : 
+    1099        1271 :                 disk = find_disk(state, map->name);
+    1100             : 
+    1101             :                 /* go to the next mapping before removing */
+    1102        1271 :                 i = i->next;
+    1103             : 
+    1104        1271 :                 if (disk == 0) {
+    1105             :                         /* disk not found, remove the mapping */
+    1106           0 :                         tommy_list_remove_existing(&state->maplist, &map->node);
+    1107           0 :                         map_free(map);
+    1108             :                 }
+    1109             :         }
+    1110             : 
+    1111             :         /* maps each unmapped disk present in the configuration file in the first available hole */
+    1112             :         /* this happens when you add disks for the first time in the configuration file */
+    1113         230 :         hole = 0; /* first position to try */
+    1114        1605 :         for (i = state->disklist; i != 0; i = i->next) {
+    1115        1375 :                 struct snapraid_disk* disk = i->data;
+    1116             :                 struct snapraid_map* map;
+    1117             :                 tommy_node* j;
+    1118             : 
+    1119             :                 /* check if the disk is already mapped */
+    1120        4800 :                 for (j = state->maplist; j != 0; j = j->next) {
+    1121        4696 :                         map = j->data;
+    1122        4696 :                         if (strcmp(disk->name, map->name) == 0) {
+    1123             :                                 /* mapping found */
+    1124        1271 :                                 break;
+    1125             :                         }
+    1126             :                 }
+    1127        1375 :                 if (j != 0) {
+    1128             :                         /* mapping is present, then copy the free blocks into to disk */
+    1129        1271 :                         disk->total_blocks = map->total_blocks;
+    1130        1271 :                         disk->free_blocks = map->free_blocks;
+    1131        1271 :                         continue;
+    1132             :                 }
+    1133             : 
+    1134             :                 /* mapping not found, search for an hole */
+    1135             :                 while (1) {
+    1136         626 :                         for (j = state->maplist; j != 0; j = j->next) {
+    1137         522 :                                 map = j->data;
+    1138         522 :                                 if (map->position == hole) {
+    1139             :                                         /* position already used */
+    1140          87 :                                         break;
+    1141             :                                 }
+    1142             :                         }
+    1143         191 :                         if (j == 0) {
+    1144             :                                 /* hole found */
+    1145         104 :                                 break;
+    1146             :                         }
+    1147             : 
+    1148             :                         /* try with the next one */
+    1149          87 :                         ++hole;
+    1150          87 :                 }
+    1151             : 
+    1152             :                 /* insert the new mapping */
+    1153         104 :                 map = map_alloc(disk->name, hole, 0, 0, "");
+    1154             : 
+    1155         104 :                 tommy_list_insert_tail(&state->maplist, &map->node, map);
+    1156             :         }
+    1157             : 
+    1158             :         /* without configuration don't check for number of data disks or uuid changes */
+    1159         230 :         if (state->no_conf)
+    1160         231 :                 return;
+    1161             : 
+    1162             :         /* counter for the number of UUID mismatches */
+    1163         229 :         uuid_mismatch = 0;
+    1164             : 
+    1165             :         /* checks if mapping match the disk uuid */
+    1166         229 :         if (!state->opt.skip_disk_access) {
+    1167        1423 :                 for (i = state->maplist; i != 0; i = i->next) {
+    1168        1219 :                         struct snapraid_map* map = i->data;
+    1169             :                         struct snapraid_disk* disk;
+    1170             :                         char uuid[UUID_MAX];
+    1171             :                         int ret;
+    1172             : 
+    1173        1219 :                         disk = find_disk(state, map->name);
+    1174        1219 :                         if (disk == 0) {
+    1175             :                                 /* LCOV_EXCL_START */
+    1176             :                                 log_fatal("Internal inconsistency for mapping '%s'\n", map->name);
+    1177             :                                 exit(EXIT_FAILURE);
+    1178             :                                 /* LCOV_EXCL_STOP */
+    1179             :                         }
+    1180             : 
+    1181        1219 :                         ret = devuuid(disk->device, uuid, sizeof(uuid));
+    1182        1219 :                         if (ret != 0) {
+    1183             :                                 /* uuid not available, just ignore but marks the disk with unsupported UUID */
+    1184           0 :                                 disk->has_unsupported_uuid = 1;
+    1185           0 :                                 continue;
+    1186             :                         }
+    1187             : 
+    1188             :                         /* if the uuid is changed */
+    1189        1219 :                         if (strcmp(uuid, map->uuid) != 0) {
+    1190             :                                 /* mark the disk as with an UUID change */
+    1191          56 :                                 disk->has_different_uuid = 1;
+    1192             : 
+    1193             :                                 /* if the previous uuid is available */
+    1194          56 :                                 if (map->uuid[0] != 0) {
+    1195             :                                         /* count the number of uuid change */
+    1196           0 :                                         ++uuid_mismatch;
+    1197           0 :                                         log_fatal("UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, uuid);
+    1198             :                                 } else {
+    1199             :                                         /* no message here, because having a disk without */
+    1200             :                                         /* UUID is the normal state of an empty disk */
+    1201          56 :                                         disk->had_empty_uuid = 1;
+    1202             :                                 }
+    1203             : 
+    1204             :                                 /* update the uuid in the mapping, */
+    1205          56 :                                 pathcpy(map->uuid, sizeof(map->uuid), uuid);
+    1206             : 
+    1207             :                                 /* write the new state with the new uuid */
+    1208          56 :                                 state->need_write = 1;
+    1209             :                         }
+    1210             :                 }
+    1211             :         }
+    1212             : 
+    1213             :         /* checks the parity uuid */
+    1214         229 :         if (!state->opt.skip_parity_access) {
+    1215        1104 :                 for (l = 0; l < state->level; ++l) {
+    1216             :                         char uuid[UUID_MAX];
+    1217             :                         int ret;
+    1218             : 
+    1219         910 :                         ret = devuuid(state->parity[l].device, uuid, sizeof(uuid));
+    1220         910 :                         if (ret != 0) {
+    1221             :                                 /* uuid not available, just ignore */
+    1222           0 :                                 continue;
+    1223             :                         }
+    1224             : 
+    1225             :                         /* if the uuid is changed */
+    1226         910 :                         if (strcmp(uuid, state->parity[l].uuid) != 0) {
+    1227             :                                 /* if the previous uuid is available */
+    1228          42 :                                 if (state->parity[l].uuid[0] != 0) {
+    1229             :                                         /* count the number of uuid change */
+    1230           0 :                                         ++uuid_mismatch;
+    1231           0 :                                         log_fatal("UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid);
+    1232             :                                 }
+    1233             : 
+    1234             :                                 /* update the uuid */
+    1235          42 :                                 pathcpy(state->parity[l].uuid, sizeof(state->parity[l].uuid), uuid);
+    1236             : 
+    1237             :                                 /* write the new state with the new uuid */
+    1238          42 :                                 state->need_write = 1;
+    1239             :                         }
+    1240             :                 }
+    1241             :         }
+    1242             : 
+    1243         229 :         if (!state->opt.force_uuid && uuid_mismatch > state->level) {
+    1244             :                 /* LCOV_EXCL_START */
+    1245             :                 log_fatal("Too many disks have UUID changed from the latest 'sync'.\n");
+    1246             :                 log_fatal("If this happens because you really replaced them,\n");
+    1247             :                 log_fatal("you can '%s' anyway, using 'snapraid --force-uuid %s'.\n", state->command, state->command);
+    1248             :                 log_fatal("Instead, it's possible that you messed up the disk mount points,\n");
+    1249             :                 log_fatal("and you have to restore the mount points at the state of the latest sync.\n");
+    1250             :                 exit(EXIT_FAILURE);
+    1251             :                 /* LCOV_EXCL_STOP */
+    1252             :         }
+    1253             : 
+    1254             :         /* count the number of data disks, including holes left after removing some */
+    1255         229 :         diskcount = 0;
+    1256        1598 :         for (i = state->maplist; i != 0; i = i->next) {
+    1257        1369 :                 struct snapraid_map* map = i->data;
+    1258             : 
+    1259        1369 :                 if (map->position + 1 > diskcount)
+    1260        1234 :                         diskcount = map->position + 1;
+    1261             :         }
+    1262             : 
+    1263             :         /* ensure to don't go over the limit of the RAID engine */
+    1264         229 :         if (diskcount > RAID_DATA_MAX) {
+    1265             :                 /* LCOV_EXCL_START */
+    1266             :                 log_fatal("Too many data disks. No more than %u.\n", RAID_DATA_MAX);
+    1267             :                 exit(EXIT_FAILURE);
+    1268             :                 /* LCOV_EXCL_STOP */
+    1269             :         }
+    1270             : 
+    1271             :         /* now count the real number of data disks, excluding holes left after removing some */
+    1272         229 :         diskcount = tommy_list_count(&state->maplist);
+    1273             : 
+    1274             :         /* recommend number of parities */
+    1275         229 :         if (diskcount >= 36 && state->level < 6) {
+    1276           0 :                 log_fatal("WARNING! With %u disks it's recommended to use six parity levels.\n", diskcount);
+    1277         229 :         } else if (diskcount >= 29 && state->level < 5) {
+    1278           0 :                 log_fatal("WARNING! With %u disks it's recommended to use five parity levels.\n", diskcount);
+    1279         229 :         } else if (diskcount >= 22 && state->level < 4) {
+    1280           0 :                 log_fatal("WARNING! With %u disks it's recommended to use four parity levels.\n", diskcount);
+    1281         229 :         } else if (diskcount >= 15 && state->level < 3) {
+    1282           0 :                 log_fatal("WARNING! With %u disks it's recommended to use three parity levels.\n", diskcount);
+    1283         229 :         } else if (diskcount >= 5 && state->level < 2) {
+    1284          33 :                 log_fatal("WARNING! With %u disks it's recommended to use two parity levels.\n", diskcount);
+    1285             :         }
+    1286             : }
+    1287             : 
+    1288         126 : void state_refresh(struct snapraid_state* state)
+    1289             : {
+    1290             :         tommy_node* i;
+    1291             :         unsigned l;
+    1292             : 
+    1293             :         /* for all disks */
+    1294         880 :         for (i = state->maplist; i != 0; i = i->next) {
+    1295         754 :                 struct snapraid_map* map = i->data;
+    1296             :                 struct snapraid_disk* disk;
+    1297             :                 uint64_t total_space;
+    1298             :                 uint64_t free_space;
+    1299             :                 int ret;
+    1300             : 
+    1301         754 :                 disk = find_disk(state, map->name);
+    1302         754 :                 if (disk == 0) {
+    1303             :                         /* LCOV_EXCL_START */
+    1304             :                         log_fatal("Internal inconsistency for mapping '%s'\n", map->name);
+    1305             :                         exit(EXIT_FAILURE);
+    1306             :                         /* LCOV_EXCL_STOP */
+    1307             :                 }
+    1308             : 
+    1309         754 :                 ret = fsinfo(disk->dir, 0, &total_space, &free_space);
+    1310         754 :                 if (ret != 0) {
+    1311             :                         /* LCOV_EXCL_START */
+    1312             :                         log_fatal("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno));
+    1313             :                         exit(EXIT_FAILURE);
+    1314             :                         /* LCOV_EXCL_STOP */
+    1315             :                 }
+    1316             : 
+    1317             :                 /* set the new free blocks */
+    1318         754 :                 map->total_blocks = total_space / state->block_size;
+    1319         754 :                 map->free_blocks = free_space / state->block_size;
+    1320             : 
+    1321             :                 /* also update the disk info */
+    1322         754 :                 disk->total_blocks = map->total_blocks;
+    1323         754 :                 disk->free_blocks = map->free_blocks;
+    1324             :         }
+    1325             : 
+    1326             :         /* for all parities */
+    1327         862 :         for (l = 0; l < state->level; ++l) {
+    1328             :                 uint64_t total_space;
+    1329             :                 uint64_t free_space;
+    1330             :                 int ret;
+    1331             : 
+    1332         736 :                 ret = fsinfo(state->parity[l].path, 0, &total_space, &free_space);
+    1333         736 :                 if (ret != 0) {
+    1334             :                         /* LCOV_EXCL_START */
+    1335             :                         log_fatal("Error accessing file '%s' to get filesystem info. %s.\n", state->parity[l].path, strerror(errno));
+    1336             :                         exit(EXIT_FAILURE);
+    1337             :                         /* LCOV_EXCL_STOP */
+    1338             :                 }
+    1339             : 
+    1340             :                 /* set the new free blocks */
+    1341         736 :                 state->parity[l].total_blocks = total_space / state->block_size;
+    1342         736 :                 state->parity[l].free_blocks = free_space / state->block_size;
+    1343             :         }
+    1344             : 
+    1345             :         /* note what we don't set need_write = 1, because we don't want */
+    1346             :         /* to update the content file only for the free space info. */
+    1347         126 : }
+    1348             : 
+    1349             : /**
+    1350             :  * Checks the content.
+    1351             :  */
+    1352         223 : static void state_content_check(struct snapraid_state* state, const char* path)
+    1353             : {
+    1354             :         tommy_node* i;
+    1355             : 
+    1356             :         /* checks that any map has different name and position */
+    1357        1556 :         for (i = state->maplist; i != 0; i = i->next) {
+    1358        1333 :                 struct snapraid_map* map = i->data;
+    1359             :                 tommy_node* j;
+    1360        4653 :                 for (j = i->next; j != 0; j = j->next) {
+    1361        3320 :                         struct snapraid_map* other = j->data;
+    1362        3320 :                         if (strcmp(map->name, other->name) == 0) {
+    1363             :                                 /* LCOV_EXCL_START */
+    1364             :                                 log_fatal("Colliding 'map' disk specification in '%s'\n", path);
+    1365             :                                 exit(EXIT_FAILURE);
+    1366             :                                 /* LCOV_EXCL_STOP */
+    1367             :                         }
+    1368        3320 :                         if (map->position == other->position) {
+    1369             :                                 /* LCOV_EXCL_START */
+    1370             :                                 log_fatal("Colliding 'map' index specification in '%s'\n", path);
+    1371             :                                 exit(EXIT_FAILURE);
+    1372             :                                 /* LCOV_EXCL_STOP */
+    1373             :                         }
+    1374             :                 }
+    1375             :         }
+    1376         223 : }
+    1377             : 
+    1378             : /**
+    1379             :  * Checks if the position is REQUIRED, or we can completely clear it from the state.
+    1380             :  *
+    1381             :  * Note that position with only DELETED blocks are discarged.
+    1382             :  */
+    1383      738011 : static int position_is_required(struct snapraid_state* state, block_off_t pos)
+    1384             : {
+    1385             :         tommy_node* i;
+    1386             : 
+    1387             :         /* check for each disk */
+    1388      783686 :         for (i = state->disklist; i != 0; i = i->next) {
+    1389      783686 :                 struct snapraid_disk* disk = i->data;
+    1390      783686 :                 struct snapraid_block* block = disk_block_get(disk, pos);
+    1391             : 
+    1392             :                 /* if we have at least one file, the position is needed */
+    1393      783686 :                 if (block_has_file(block))
+    1394      738011 :                         return 1;
+    1395             :         }
+    1396             : 
+    1397           0 :         return 0;
+    1398             : }
+    1399             : 
+    1400             : /**
+    1401             :  * Checks if the info block is REQUIREQ.
+    1402             :  *
+    1403             :  * This is used to ensure that we keep the last check used for scrubbing.
+    1404             :  * and the we add it when importing old context files.
+    1405             :  *
+    1406             :  * Note that you can have position without info blocks, for example
+    1407             :  * if all the blocks are not synced.
+    1408             :  *
+    1409             :  * Note also that not requiring an info block, doesn't mean that if present it
+    1410             :  * can be discarded.
+    1411             :  */
+    1412     1498181 : static int info_is_required(struct snapraid_state* state, block_off_t pos)
+    1413             : {
+    1414             :         tommy_node* i;
+    1415             : 
+    1416             :         /* check for each disk */
+    1417     2020186 :         for (i = state->disklist; i != 0; i = i->next) {
+    1418     1957309 :                 struct snapraid_disk* disk = i->data;
+    1419     1957309 :                 struct snapraid_block* block = disk_block_get(disk, pos);
+    1420             : 
+    1421             :                 /* if we have at least one synced file, the info is required */
+    1422     1957309 :                 if (block_state_get(block) == BLOCK_STATE_BLK)
+    1423     1435304 :                         return 1;
+    1424             :         }
+    1425             : 
+    1426       62877 :         return 0;
+    1427             : }
+    1428             : 
+    1429           0 : static void position_clear_deleted(struct snapraid_state* state, block_off_t pos)
+    1430             : {
+    1431             :         tommy_node* i;
+    1432             : 
+    1433             :         /* check for each disk if block is really used */
+    1434           0 :         for (i = state->disklist; i != 0; i = i->next) {
+    1435           0 :                 struct snapraid_disk* disk = i->data;
+    1436           0 :                 struct snapraid_block* block = disk_block_get(disk, pos);
+    1437             : 
+    1438             :                 /* if the block is deleted */
+    1439           0 :                 if (block_state_get(block) == BLOCK_STATE_DELETED) {
+    1440             :                         /* set it to empty */
+    1441           0 :                         tommy_arrayblk_set(&disk->blockarr, pos, BLOCK_EMPTY);
+    1442             :                 }
+    1443             :         }
+    1444           0 : }
+    1445             : 
+    1446             : /**
+    1447             :  * Checks if a block position in a disk is deleted.
+    1448             :  */
+    1449     4423464 : static int is_block_deleted(struct snapraid_disk* disk, block_off_t pos)
+    1450             : {
+    1451     4423464 :         struct snapraid_block* block = disk_block_get(disk, pos);
+    1452             : 
+    1453     4423464 :         return block_state_get(block) == BLOCK_STATE_DELETED;
+    1454             : }
+    1455             : 
+    1456           5 : static void state_read_text(struct snapraid_state* state, const char* path, STREAM* f, time_t save_time)
+    1457             : {
+    1458             :         struct snapraid_disk* disk;
+    1459             :         struct snapraid_file* file;
+    1460             :         block_off_t blockidx;
+    1461             :         block_off_t blockmax;
+    1462             :         unsigned line;
+    1463             :         unsigned count_file;
+    1464             :         unsigned count_hardlink;
+    1465             :         unsigned count_symlink;
+    1466             :         unsigned count_dir;
+    1467             :         block_off_t b;
+    1468             : 
+    1469           5 :         disk = 0;
+    1470           5 :         file = 0;
+    1471           5 :         line = 1;
+    1472           5 :         blockidx = 0;
+    1473           5 :         blockmax = 0;
+    1474           5 :         count_file = 0;
+    1475           5 :         count_hardlink = 0;
+    1476           5 :         count_symlink = 0;
+    1477           5 :         count_dir = 0;
+    1478             : 
+    1479             :         while (1) {
+    1480             :                 char buffer[PATH_MAX];
+    1481             :                 char tag[PATH_MAX];
+    1482             :                 int ret;
+    1483             :                 int c;
+    1484             : 
+    1485             :                 /* read the command */
+    1486      364527 :                 ret = sgettok(f, tag, sizeof(tag));
+    1487      364527 :                 if (ret < 0) {
+    1488             :                         /* LCOV_EXCL_START */
+    1489             :                         log_fatal("Error reading the configuration file '%s' at line %u\n", path, line);
+    1490             :                         exit(EXIT_FAILURE);
+    1491             :                         /* LCOV_EXCL_STOP */
+    1492             :                 }
+    1493             : 
+    1494             :                 /* skip only one space if present */
+    1495      364527 :                 c = sgetc(f);
+    1496      364527 :                 if (c != ' ') {
+    1497           5 :                         sungetc(c, f);
+    1498             :                 }
+    1499             : 
+    1500      364527 :                 if (strcmp(tag, "blk") == 0 || strcmp(tag, "new") == 0
+    1501      161439 :                         || strcmp(tag, "chg") == 0 || strcmp(tag, "rep") == 0
+    1502      231282 :                 ) {
+    1503             :                         /* "blk"/""new"/"chg"/"rep" command */
+    1504             :                         block_off_t v_pos;
+    1505             :                         struct snapraid_block* block;
+    1506             : 
+    1507      231282 :                         if (!file) {
+    1508             :                                 /* LCOV_EXCL_START */
+    1509             :                                 log_fatal("Unexpected '%s' specification in '%s' at line %u\n", tag, path, line);
+    1510             :                                 exit(EXIT_FAILURE);
+    1511             :                                 /* LCOV_EXCL_STOP */
+    1512             :                         }
+    1513             : 
+    1514      231282 :                         ret = sgetu32(f, &v_pos);
+    1515      231282 :                         if (ret < 0) {
+    1516             :                                 /* LCOV_EXCL_START */
+    1517             :                                 log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line);
+    1518             :                                 exit(EXIT_FAILURE);
+    1519             :                                 /* LCOV_EXCL_STOP */
+    1520             :                         }
+    1521             : 
+    1522      231282 :                         if (blockidx >= file->blockmax) {
+    1523             :                                 /* LCOV_EXCL_START */
+    1524             :                                 log_fatal("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line);
+    1525             :                                 exit(EXIT_FAILURE);
+    1526             :                                 /* LCOV_EXCL_STOP */
+    1527             :                         }
+    1528             : 
+    1529      231282 :                         block = &file->blockvec[blockidx];
+    1530             : 
+    1531      231282 :                         if (block->parity_pos != POS_INVALID) {
+    1532             :                                 /* LCOV_EXCL_START */
+    1533             :                                 log_fatal("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line);
+    1534             :                                 exit(EXIT_FAILURE);
+    1535             :                                 /* LCOV_EXCL_STOP */
+    1536             :                         }
+    1537             : 
+    1538             :                         /* set the parity only if present */
+    1539      231282 :                         switch (tag[0]) {
+    1540             :                         case 'b' :
+    1541      203088 :                                 block_state_set(block, BLOCK_STATE_BLK);
+    1542      203088 :                                 break;
+    1543             :                         case 'n' :
+    1544             :                                 /* deprecated NEW blocks are converted to CHG ones */
+    1545           0 :                                 block_state_set(block, BLOCK_STATE_CHG);
+    1546           0 :                                 break;
+    1547             :                         case 'c' :
+    1548       28194 :                                 block_state_set(block, BLOCK_STATE_CHG);
+    1549       28194 :                                 break;
+    1550             :                         case 'r' :
+    1551           0 :                                 block_state_set(block, BLOCK_STATE_REP);
+    1552           0 :                                 break;
+    1553             :                         }
+    1554             : 
+    1555      231282 :                         block->parity_pos = v_pos;
+    1556             : 
+    1557             :                         /* keep track of the max block number used in parity */
+    1558      231282 :                         if (v_pos + 1 > blockmax)
+    1559       38008 :                                 blockmax = v_pos + 1;
+    1560             : 
+    1561             :                         /* read the hash only for 'blk/chg/rep', and not for 'new' */
+    1562      231282 :                         if (tag[0] != 'n') {
+    1563      231282 :                                 c = sgetc(f);
+    1564      231282 :                                 if (c != ' ') {
+    1565             :                                         /* LCOV_EXCL_START */
+    1566             :                                         log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line);
+    1567             :                                         exit(EXIT_FAILURE);
+    1568             :                                         /* LCOV_EXCL_STOP */
+    1569             :                                 }
+    1570             : 
+    1571      231282 :                                 ret = sgethex(f, block->hash, HASH_SIZE);
+    1572      231282 :                                 if (ret < 0) {
+    1573             :                                         /* LCOV_EXCL_START */
+    1574             :                                         log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line);
+    1575             :                                         exit(EXIT_FAILURE);
+    1576             :                                         /* LCOV_EXCL_STOP */
+    1577             :                                 }
+    1578             :                         } else {
+    1579             :                                 /* set the ZERO hash for deprecated NEW blocks */
+    1580           0 :                                 hash_zero_set(block->hash);
+    1581             :                         }
+    1582             : 
+    1583             :                         /* if the block contains a hash of past data */
+    1584             :                         /* and we are clearing such undeterminated hashes */
+    1585      231282 :                         if (state->clear_past_hash
+    1586       95231 :                                 && block_has_past_hash(block)
+    1587             :                         ) {
+    1588             :                                 /* set the hash value to INVALID */
+    1589       14097 :                                 hash_invalid_set(block->hash);
+    1590             :                         }
+    1591             : 
+    1592             :                         /* if we are disabling the copy optimization */
+    1593             :                         /* we want also to clear any already previously stored information */
+    1594             :                         /* in other sync commands */
+    1595             :                         /* note that this is required only in sync, and we detect */
+    1596             :                         /* this using the clear_past_hash flag */
+    1597      231282 :                         if (state->clear_past_hash
+    1598       95231 :                                 && state->opt.force_nocopy
+    1599           0 :                                 && block_state_get(block) == BLOCK_STATE_REP
+    1600             :                         ) {
+    1601             :                                 /* set the hash value to INVALID */
+    1602           0 :                                 hash_invalid_set(block->hash);
+    1603             :                                 /* convert from REP to CHG block */
+    1604           0 :                                 block_state_set(block, BLOCK_STATE_CHG);
+    1605             :                         }
+    1606             : 
+    1607             :                         /* if we want a full sync, marks block as invalid parity */
+    1608             :                         /* note that we do this after the force_nocopy option */
+    1609             :                         /* to avoid to mixup the two things */
+    1610      231282 :                         if (state->opt.force_full
+    1611           0 :                                 && block_state_get(block) == BLOCK_STATE_BLK) {
+    1612             :                                 /* convert from BLK to REP */
+    1613           0 :                                 block_state_set(block, BLOCK_STATE_REP);
+    1614             :                         }
+    1615             : 
+    1616             :                         /* we must not overwrite existing blocks */
+    1617      231282 :                         if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
+    1618             :                                 /* LCOV_EXCL_START */
+    1619             :                                 log_fatal("Internal inconsistency for '%s' specification in '%s' at line %u\n", tag, path, line);
+    1620             :                                 exit(EXIT_FAILURE);
+    1621             :                                 /* LCOV_EXCL_STOP */
+    1622             :                         }
+    1623             : 
+    1624             :                         /* insert the block in the block array */
+    1625      231282 :                         tommy_arrayblk_grow(&disk->blockarr, v_pos + 1);
+    1626      231282 :                         tommy_arrayblk_set(&disk->blockarr, v_pos, block);
+    1627             : 
+    1628             :                         /* check for termination of the block list */
+    1629      231282 :                         ++blockidx;
+    1630      231282 :                         if (blockidx == file->blockmax) {
+    1631       93967 :                                 file = 0;
+    1632       93967 :                                 disk = 0;
+    1633             :                         }
+    1634      133245 :                 } else if (strcmp(tag, "inf") == 0) {
+    1635             :                         /* "inf" command */
+    1636             :                         block_off_t v_pos;
+    1637             :                         snapraid_info info;
+    1638             :                         int rehash;
+    1639             :                         int bad;
+    1640             :                         uint32_t t;
+    1641             : 
+    1642       34905 :                         ret = sgetu32(f, &v_pos);
+    1643       34905 :                         if (ret < 0) {
+    1644             :                                 /* LCOV_EXCL_START */
+    1645             :                                 log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line);
+    1646             :                                 exit(EXIT_FAILURE);
+    1647             :                                 /* LCOV_EXCL_STOP */
+    1648             :                         }
+    1649             : 
+    1650       34905 :                         if (v_pos >= blockmax) {
+    1651             :                                 /* LCOV_EXCL_START */
+    1652             :                                 log_fatal("Internal inconsistency in position for 'inf' specification in '%s' at line %u\n", path, line);
+    1653             :                                 exit(EXIT_FAILURE);
+    1654             :                                 /* LCOV_EXCL_STOP */
+    1655             :                         }
+    1656             : 
+    1657       34905 :                         c = sgetc(f);
+    1658       34905 :                         if (c != ' ') {
+    1659             :                                 /* LCOV_EXCL_START */
+    1660             :                                 log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line);
+    1661             :                                 exit(EXIT_FAILURE);
+    1662             :                                 /* LCOV_EXCL_STOP */
+    1663             :                         }
+    1664             : 
+    1665       34905 :                         ret = sgetu32(f, &t);
+    1666       34905 :                         if (ret < 0) {
+    1667             :                                 /* LCOV_EXCL_START */
+    1668             :                                 log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line);
+    1669             :                                 exit(EXIT_FAILURE);
+    1670             :                                 /* LCOV_EXCL_STOP */
+    1671             :                         }
+    1672             : 
+    1673             :                         /* read extra tags if present */
+    1674       34905 :                         rehash = 0;
+    1675       34905 :                         bad = 0;
+    1676       34905 :                         c = sgetc(f);
+    1677       69810 :                         while (c == ' ') {
+    1678           0 :                                 ret = sgettok(f, buffer, sizeof(buffer));
+    1679           0 :                                 if (ret < 0) {
+    1680             :                                         /* LCOV_EXCL_START */
+    1681             :                                         log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line);
+    1682             :                                         exit(EXIT_FAILURE);
+    1683             :                                         /* LCOV_EXCL_STOP */
+    1684             :                                 }
+    1685             : 
+    1686           0 :                                 if (strcmp(buffer, "bad") == 0) {
+    1687           0 :                                         bad = 1;
+    1688           0 :                                 } else if (strcmp(buffer, "rehash") == 0) {
+    1689           0 :                                         rehash = 1;
+    1690             : 
+    1691           0 :                                         if (state->prevhash == HASH_UNDEFINED) {
+    1692             :                                                 /* LCOV_EXCL_START */
+    1693             :                                                 log_fatal("Internal inconsistency for missing previous checksum in '%s' at line %u\n", path, line);
+    1694             :                                                 exit(EXIT_FAILURE);
+    1695             :                                                 /* LCOV_EXCL_STOP */
+    1696             :                                         }
+    1697             :                                 } else {
+    1698             :                                         /* LCOV_EXCL_START */
+    1699             :                                         log_fatal("Invalid 'inf' specification '%s' in '%s' at line %u\n", buffer, path, line);
+    1700             :                                         exit(EXIT_FAILURE);
+    1701             :                                         /* LCOV_EXCL_STOP */
+    1702             :                                 }
+    1703             : 
+    1704           0 :                                 c = sgetc(f);
+    1705             :                         }
+    1706       34905 :                         sungetc(c, f);
+    1707             : 
+    1708       34905 :                         info = info_make(t, bad, rehash);
+    1709             : 
+    1710             :                         /* insert the info in the array */
+    1711       34905 :                         info_set(&state->infoarr, v_pos, info);
+    1712       98340 :                 } else if (strcmp(tag, "off") == 0) {
+    1713             :                         /* "off" command */
+    1714             :                         block_off_t v_pos;
+    1715             :                         struct snapraid_deleted* deleted;
+    1716             : 
+    1717        1098 :                         if (!disk) {
+    1718             :                                 /* LCOV_EXCL_START */
+    1719             :                                 log_fatal("Unexpected 'off' specification in '%s' at line %u\n", path, line);
+    1720             :                                 exit(EXIT_FAILURE);
+    1721             :                                 /* LCOV_EXCL_STOP */
+    1722             :                         }
+    1723             : 
+    1724             :                         /* allocate a new deleted block */
+    1725        1098 :                         deleted = deleted_alloc();
+    1726             : 
+    1727        1098 :                         ret = sgetu32(f, &v_pos);
+    1728        1098 :                         if (ret < 0) {
+    1729             :                                 /* LCOV_EXCL_START */
+    1730             :                                 log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line);
+    1731             :                                 exit(EXIT_FAILURE);
+    1732             :                                 /* LCOV_EXCL_STOP */
+    1733             :                         }
+    1734             : 
+    1735        1098 :                         deleted->block.parity_pos = v_pos;
+    1736             : 
+    1737             :                         /* read the hash */
+    1738        1098 :                         c = sgetc(f);
+    1739        1098 :                         if (c != ' ') {
+    1740             :                                 /* LCOV_EXCL_START */
+    1741             :                                 log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line);
+    1742             :                                 exit(EXIT_FAILURE);
+    1743             :                                 /* LCOV_EXCL_STOP */
+    1744             :                         }
+    1745             : 
+    1746             :                         /* set the hash only if present */
+    1747        1098 :                         ret = sgethex(f, deleted->block.hash, HASH_SIZE);
+    1748        1098 :                         if (ret < 0) {
+    1749             :                                 /* LCOV_EXCL_START */
+    1750             :                                 log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line);
+    1751             :                                 exit(EXIT_FAILURE);
+    1752             :                                 /* LCOV_EXCL_STOP */
+    1753             :                         }
+    1754             : 
+    1755             :                         /* if we are clearing undeterminated hashes */
+    1756        1098 :                         if (state->clear_past_hash) {
+    1757             :                                 /* set the hash value to INVALID */
+    1758         366 :                                 hash_invalid_set(deleted->block.hash);
+    1759             :                         }
+    1760             : 
+    1761             :                         /* we must not overwrite existing blocks */
+    1762        1098 :                         if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
+    1763             :                                 /* LCOV_EXCL_START */
+    1764             :                                 log_fatal("Internal inconsistency for 'off' specification in '%s' at line %u\n", path, line);
+    1765             :                                 exit(EXIT_FAILURE);
+    1766             :                                 /* LCOV_EXCL_STOP */
+    1767             :                         }
+    1768             : 
+    1769             :                         /* insert it in the list of deleted blocks */
+    1770        1098 :                         tommy_list_insert_tail(&disk->deletedlist, &deleted->node, deleted);
+    1771             : 
+    1772             :                         /* insert the block in the block array */
+    1773        1098 :                         tommy_arrayblk_grow(&disk->blockarr, v_pos + 1);
+    1774        1098 :                         tommy_arrayblk_set(&disk->blockarr, v_pos, &deleted->block);
+    1775       97242 :                 } else if (strcmp(tag, "file") == 0) {
+    1776             :                         /* file */
+    1777             :                         char sub[PATH_MAX];
+    1778             :                         uint64_t v_size;
+    1779             :                         uint64_t v_mtime_sec;
+    1780             :                         uint32_t v_mtime_nsec;
+    1781             :                         uint64_t v_inode;
+    1782             : 
+    1783       94092 :                         if (file) {
+    1784             :                                 /* LCOV_EXCL_START */
+    1785             :                                 log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line);
+    1786             :                                 exit(EXIT_FAILURE);
+    1787             :                                 /* LCOV_EXCL_STOP */
+    1788             :                         }
+    1789             : 
+    1790       94092 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    1791       94092 :                         if (ret < 0) {
+    1792             :                                 /* LCOV_EXCL_START */
+    1793             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1794             :                                 exit(EXIT_FAILURE);
+    1795             :                                 /* LCOV_EXCL_STOP */
+    1796             :                         }
+    1797             : 
+    1798       94092 :                         c = sgetc(f);
+    1799       94092 :                         if (c != ' ') {
+    1800             :                                 /* LCOV_EXCL_START */
+    1801             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1802             :                                 exit(EXIT_FAILURE);
+    1803             :                                 /* LCOV_EXCL_STOP */
+    1804             :                         }
+    1805             : 
+    1806       94092 :                         ret = sgetu64(f, &v_size);
+    1807       94092 :                         if (ret < 0) {
+    1808             :                                 /* LCOV_EXCL_START */
+    1809             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1810             :                                 exit(EXIT_FAILURE);
+    1811             :                                 /* LCOV_EXCL_STOP */
+    1812             :                         }
+    1813             : 
+    1814       94092 :                         c = sgetc(f);
+    1815       94092 :                         if (c != ' ') {
+    1816             :                                 /* LCOV_EXCL_START */
+    1817             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1818             :                                 exit(EXIT_FAILURE);
+    1819             :                                 /* LCOV_EXCL_STOP */
+    1820             :                         }
+    1821             : 
+    1822       94092 :                         ret = sgetu64(f, &v_mtime_sec);
+    1823       94092 :                         if (ret < 0) {
+    1824             :                                 /* LCOV_EXCL_START */
+    1825             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1826             :                                 exit(EXIT_FAILURE);
+    1827             :                                 /* LCOV_EXCL_STOP */
+    1828             :                         }
+    1829             : 
+    1830       94092 :                         c = sgetc(f);
+    1831       94092 :                         if (c == '.') { /* the nanosecond field is present only from version 1.14 */
+    1832       94092 :                                 ret = sgetu32(f, &v_mtime_nsec);
+    1833       94092 :                                 if (ret < 0) {
+    1834             :                                         /* LCOV_EXCL_START */
+    1835             :                                         log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1836             :                                         exit(EXIT_FAILURE);
+    1837             :                                         /* LCOV_EXCL_STOP */
+    1838             :                                 }
+    1839             : 
+    1840       94092 :                                 c = sgetc(f);
+    1841             :                         } else {
+    1842             :                                 /* use a special value, meaning that we don't have this information */
+    1843           0 :                                 v_mtime_nsec = STAT_NSEC_INVALID;
+    1844             :                         }
+    1845             : 
+    1846       94092 :                         if (c != ' ') {
+    1847             :                                 /* LCOV_EXCL_START */
+    1848             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1849             :                                 exit(EXIT_FAILURE);
+    1850             :                                 /* LCOV_EXCL_STOP */
+    1851             :                         }
+    1852             : 
+    1853       94092 :                         ret = sgetu64(f, &v_inode);
+    1854       94092 :                         if (ret < 0) {
+    1855             :                                 /* LCOV_EXCL_START */
+    1856             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1857             :                                 exit(EXIT_FAILURE);
+    1858             :                                 /* LCOV_EXCL_STOP */
+    1859             :                         }
+    1860             : 
+    1861       94092 :                         c = sgetc(f);
+    1862       94092 :                         if (c != ' ') {
+    1863             :                                 /* LCOV_EXCL_START */
+    1864             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1865             :                                 exit(EXIT_FAILURE);
+    1866             :                                 /* LCOV_EXCL_STOP */
+    1867             :                         }
+    1868             : 
+    1869       94092 :                         ret = sgetline(f, sub, sizeof(sub));
+    1870       94092 :                         if (ret < 0) {
+    1871             :                                 /* LCOV_EXCL_START */
+    1872             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1873             :                                 exit(EXIT_FAILURE);
+    1874             :                                 /* LCOV_EXCL_STOP */
+    1875             :                         }
+    1876             : 
+    1877       94092 :                         if (!*sub) {
+    1878             :                                 /* LCOV_EXCL_START */
+    1879             :                                 log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line);
+    1880             :                                 exit(EXIT_FAILURE);
+    1881             :                                 /* LCOV_EXCL_STOP */
+    1882             :                         }
+    1883             : 
+    1884             :                         /* find the disk */
+    1885       94092 :                         disk = find_disk(state, buffer);
+    1886       94092 :                         if (!disk) {
+    1887             :                                 /* LCOV_EXCL_START */
+    1888             :                                 log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line);
+    1889             :                                 exit(EXIT_FAILURE);
+    1890             :                                 /* LCOV_EXCL_STOP */
+    1891             :                         }
+    1892             : 
+    1893             :                         /* allocate the file */
+    1894       94092 :                         file = file_alloc(state->block_size, sub, v_size, v_mtime_sec, v_mtime_nsec, v_inode, 0);
+    1895             : 
+    1896             :                         /* insert the file in the file containers */
+    1897       94092 :                         tommy_hashdyn_insert(&disk->inodeset, &file->nodeset, file, file_inode_hash(file->inode));
+    1898       94092 :                         tommy_hashdyn_insert(&disk->pathset, &file->pathset, file, file_path_hash(file->sub));
+    1899       94092 :                         tommy_hashdyn_insert(&disk->stampset, &file->stampset, file, file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec));
+    1900       94092 :                         tommy_list_insert_tail(&disk->filelist, &file->nodelist, file);
+    1901             : 
+    1902             :                         /* start the block allocation of the file */
+    1903       94092 :                         blockidx = 0;
+    1904             : 
+    1905             :                         /* check for empty file */
+    1906       94092 :                         if (blockidx == file->blockmax) {
+    1907         125 :                                 file = 0;
+    1908         125 :                                 disk = 0;
+    1909             :                         }
+    1910             : 
+    1911             :                         /* stat */
+    1912       94092 :                         ++count_file;
+    1913        3150 :                 } else if (strcmp(tag, "hole") == 0) {
+    1914             :                         /* hole */
+    1915             : 
+    1916          30 :                         if (file) {
+    1917             :                                 /* LCOV_EXCL_START */
+    1918             :                                 log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line);
+    1919             :                                 exit(EXIT_FAILURE);
+    1920             :                                 /* LCOV_EXCL_STOP */
+    1921             :                         }
+    1922             : 
+    1923          30 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    1924          30 :                         if (ret < 0) {
+    1925             :                                 /* LCOV_EXCL_START */
+    1926             :                                 log_fatal("Invalid 'hole' specification in '%s' at line %u\n", path, line);
+    1927             :                                 exit(EXIT_FAILURE);
+    1928             :                                 /* LCOV_EXCL_STOP */
+    1929             :                         }
+    1930             : 
+    1931             :                         /* find the disk */
+    1932          30 :                         disk = find_disk(state, buffer);
+    1933          30 :                         if (!disk) {
+    1934             :                                 /* LCOV_EXCL_START */
+    1935             :                                 log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line);
+    1936             :                                 exit(EXIT_FAILURE);
+    1937             :                                 /* LCOV_EXCL_STOP */
+    1938             :                         }
+    1939        3120 :                 } else if (strcmp(tag, "symlink") == 0) {
+    1940             :                         /* symlink */
+    1941             :                         char sub[PATH_MAX];
+    1942             :                         char linkto[PATH_MAX];
+    1943             :                         char tokento[32];
+    1944             :                         struct snapraid_link* link;
+    1945             : 
+    1946        2995 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    1947        2995 :                         if (ret < 0) {
+    1948             :                                 /* LCOV_EXCL_START */
+    1949             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1950             :                                 exit(EXIT_FAILURE);
+    1951             :                                 /* LCOV_EXCL_STOP */
+    1952             :                         }
+    1953             : 
+    1954        2995 :                         c = sgetc(f);
+    1955        2995 :                         if (c != ' ') {
+    1956             :                                 /* LCOV_EXCL_START */
+    1957             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1958             :                                 exit(EXIT_FAILURE);
+    1959             :                                 /* LCOV_EXCL_STOP */
+    1960             :                         }
+    1961             : 
+    1962        2995 :                         ret = sgetline(f, sub, sizeof(sub));
+    1963        2995 :                         if (ret < 0) {
+    1964             :                                 /* LCOV_EXCL_START */
+    1965             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1966             :                                 exit(EXIT_FAILURE);
+    1967             :                                 /* LCOV_EXCL_STOP */
+    1968             :                         }
+    1969             : 
+    1970        2995 :                         c = sgeteol(f);
+    1971        2995 :                         if (c != '\n') {
+    1972             :                                 /* LCOV_EXCL_START */
+    1973             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1974             :                                 exit(EXIT_FAILURE);
+    1975             :                                 /* LCOV_EXCL_STOP */
+    1976             :                         }
+    1977        2995 :                         ++line;
+    1978             : 
+    1979        2995 :                         ret = sgettok(f, tokento, sizeof(tokento));
+    1980        2995 :                         if (ret < 0) {
+    1981             :                                 /* LCOV_EXCL_START */
+    1982             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1983             :                                 exit(EXIT_FAILURE);
+    1984             :                                 /* LCOV_EXCL_STOP */
+    1985             :                         }
+    1986        2995 :                         if (strcmp(tokento, "to") != 0) {
+    1987             :                                 /* LCOV_EXCL_START */
+    1988             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1989             :                                 exit(EXIT_FAILURE);
+    1990             :                                 /* LCOV_EXCL_STOP */
+    1991             :                         }
+    1992             : 
+    1993        2995 :                         c = sgetc(f);
+    1994        2995 :                         if (c != ' ') {
+    1995             :                                 /* LCOV_EXCL_START */
+    1996             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    1997             :                                 exit(EXIT_FAILURE);
+    1998             :                                 /* LCOV_EXCL_STOP */
+    1999             :                         }
+    2000             : 
+    2001        2995 :                         ret = sgetline(f, linkto, sizeof(linkto));
+    2002        2995 :                         if (ret < 0) {
+    2003             :                                 /* LCOV_EXCL_START */
+    2004             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    2005             :                                 exit(EXIT_FAILURE);
+    2006             :                                 /* LCOV_EXCL_STOP */
+    2007             :                         }
+    2008             : 
+    2009        2995 :                         if (!*sub || !*linkto) {
+    2010             :                                 /* LCOV_EXCL_START */
+    2011             :                                 log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line);
+    2012             :                                 exit(EXIT_FAILURE);
+    2013             :                                 /* LCOV_EXCL_STOP */
+    2014             :                         }
+    2015             : 
+    2016             :                         /* find the disk */
+    2017        2995 :                         disk = find_disk(state, buffer);
+    2018        2995 :                         if (!disk) {
+    2019             :                                 /* LCOV_EXCL_START */
+    2020             :                                 log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line);
+    2021             :                                 exit(EXIT_FAILURE);
+    2022             :                                 /* LCOV_EXCL_STOP */
+    2023             :                         }
+    2024             : 
+    2025             :                         /* allocate the link as symbolic link */
+    2026        2995 :                         link = link_alloc(sub, linkto, FILE_IS_SYMLINK);
+    2027             : 
+    2028             :                         /* insert the link in the link containers */
+    2029        2995 :                         tommy_hashdyn_insert(&disk->linkset, &link->nodeset, link, link_name_hash(link->sub));
+    2030        2995 :                         tommy_list_insert_tail(&disk->linklist, &link->nodelist, link);
+    2031             : 
+    2032             :                         /* stat */
+    2033        2995 :                         ++count_symlink;
+    2034         125 :                 } else if (strcmp(tag, "hardlink") == 0) {
+    2035             :                         /* hardlink */
+    2036             :                         char sub[PATH_MAX];
+    2037             :                         char linkto[PATH_MAX];
+    2038             :                         char tokento[32];
+    2039             :                         struct snapraid_link* link;
+    2040             : 
+    2041          30 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    2042          30 :                         if (ret < 0) {
+    2043             :                                 /* LCOV_EXCL_START */
+    2044             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2045             :                                 exit(EXIT_FAILURE);
+    2046             :                                 /* LCOV_EXCL_STOP */
+    2047             :                         }
+    2048             : 
+    2049          30 :                         c = sgetc(f);
+    2050          30 :                         if (c != ' ') {
+    2051             :                                 /* LCOV_EXCL_START */
+    2052             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2053             :                                 exit(EXIT_FAILURE);
+    2054             :                                 /* LCOV_EXCL_STOP */
+    2055             :                         }
+    2056             : 
+    2057          30 :                         ret = sgetline(f, sub, sizeof(sub));
+    2058          30 :                         if (ret < 0) {
+    2059             :                                 /* LCOV_EXCL_START */
+    2060             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2061             :                                 exit(EXIT_FAILURE);
+    2062             :                                 /* LCOV_EXCL_STOP */
+    2063             :                         }
+    2064             : 
+    2065          30 :                         c = sgeteol(f);
+    2066          30 :                         if (c != '\n') {
+    2067             :                                 /* LCOV_EXCL_START */
+    2068             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2069             :                                 exit(EXIT_FAILURE);
+    2070             :                                 /* LCOV_EXCL_STOP */
+    2071             :                         }
+    2072          30 :                         ++line;
+    2073             : 
+    2074          30 :                         ret = sgettok(f, tokento, sizeof(tokento));
+    2075          30 :                         if (ret < 0) {
+    2076             :                                 /* LCOV_EXCL_START */
+    2077             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2078             :                                 exit(EXIT_FAILURE);
+    2079             :                                 /* LCOV_EXCL_STOP */
+    2080             :                         }
+    2081          30 :                         if (strcmp(tokento, "to") != 0) {
+    2082             :                                 /* LCOV_EXCL_START */
+    2083             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2084             :                                 exit(EXIT_FAILURE);
+    2085             :                                 /* LCOV_EXCL_STOP */
+    2086             :                         }
+    2087             : 
+    2088          30 :                         c = sgetc(f);
+    2089          30 :                         if (c != ' ') {
+    2090             :                                 /* LCOV_EXCL_START */
+    2091             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2092             :                                 exit(EXIT_FAILURE);
+    2093             :                                 /* LCOV_EXCL_STOP */
+    2094             :                         }
+    2095             : 
+    2096          30 :                         ret = sgetline(f, linkto, sizeof(linkto));
+    2097          30 :                         if (ret < 0) {
+    2098             :                                 /* LCOV_EXCL_START */
+    2099             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2100             :                                 exit(EXIT_FAILURE);
+    2101             :                                 /* LCOV_EXCL_STOP */
+    2102             :                         }
+    2103             : 
+    2104          30 :                         if (!*sub || !*linkto) {
+    2105             :                                 /* LCOV_EXCL_START */
+    2106             :                                 log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line);
+    2107             :                                 exit(EXIT_FAILURE);
+    2108             :                                 /* LCOV_EXCL_STOP */
+    2109             :                         }
+    2110             : 
+    2111             :                         /* find the disk */
+    2112          30 :                         disk = find_disk(state, buffer);
+    2113          30 :                         if (!disk) {
+    2114             :                                 /* LCOV_EXCL_START */
+    2115             :                                 log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line);
+    2116             :                                 exit(EXIT_FAILURE);
+    2117             :                                 /* LCOV_EXCL_STOP */
+    2118             :                         }
+    2119             : 
+    2120             :                         /* allocate the link as hard link */
+    2121          30 :                         link = link_alloc(sub, linkto, FILE_IS_HARDLINK);
+    2122             : 
+    2123             :                         /* insert the link in the link containers */
+    2124          30 :                         tommy_hashdyn_insert(&disk->linkset, &link->nodeset, link, link_name_hash(link->sub));
+    2125          30 :                         tommy_list_insert_tail(&disk->linklist, &link->nodelist, link);
+    2126             : 
+    2127             :                         /* stat */
+    2128          30 :                         ++count_hardlink;
+    2129          95 :                 } else if (strcmp(tag, "dir") == 0) {
+    2130             :                         /* dir */
+    2131             :                         char sub[PATH_MAX];
+    2132             :                         struct snapraid_dir* dir;
+    2133             : 
+    2134          20 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    2135          20 :                         if (ret < 0) {
+    2136             :                                 /* LCOV_EXCL_START */
+    2137             :                                 log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line);
+    2138             :                                 exit(EXIT_FAILURE);
+    2139             :                                 /* LCOV_EXCL_STOP */
+    2140             :                         }
+    2141             : 
+    2142          20 :                         c = sgetc(f);
+    2143          20 :                         if (c != ' ') {
+    2144             :                                 /* LCOV_EXCL_START */
+    2145             :                                 log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line);
+    2146             :                                 exit(EXIT_FAILURE);
+    2147             :                                 /* LCOV_EXCL_STOP */
+    2148             :                         }
+    2149             : 
+    2150          20 :                         ret = sgetline(f, sub, sizeof(sub));
+    2151          20 :                         if (ret < 0) {
+    2152             :                                 /* LCOV_EXCL_START */
+    2153             :                                 log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line);
+    2154             :                                 exit(EXIT_FAILURE);
+    2155             :                                 /* LCOV_EXCL_STOP */
+    2156             :                         }
+    2157             : 
+    2158          20 :                         if (!*sub) {
+    2159             :                                 /* LCOV_EXCL_START */
+    2160             :                                 log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line);
+    2161             :                                 exit(EXIT_FAILURE);
+    2162             :                                 /* LCOV_EXCL_STOP */
+    2163             :                         }
+    2164             : 
+    2165             :                         /* find the disk */
+    2166          20 :                         disk = find_disk(state, buffer);
+    2167          20 :                         if (!disk) {
+    2168             :                                 /* LCOV_EXCL_START */
+    2169             :                                 log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line);
+    2170             :                                 exit(EXIT_FAILURE);
+    2171             :                                 /* LCOV_EXCL_STOP */
+    2172             :                         }
+    2173             : 
+    2174             :                         /* allocate the dir */
+    2175          20 :                         dir = dir_alloc(sub);
+    2176             : 
+    2177             :                         /* insert the dir in the dir containers */
+    2178          20 :                         tommy_hashdyn_insert(&disk->dirset, &dir->nodeset, dir, dir_name_hash(dir->sub));
+    2179          20 :                         tommy_list_insert_tail(&disk->dirlist, &dir->nodelist, dir);
+    2180             : 
+    2181             :                         /* stat */
+    2182          20 :                         ++count_dir;
+    2183          75 :                 } else if (strcmp(tag, "checksum") == 0) {
+    2184             : 
+    2185           5 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    2186           5 :                         if (ret < 0) {
+    2187             :                                 /* LCOV_EXCL_START */
+    2188             :                                 log_fatal("Invalid 'checksum' specification in '%s' at line %u\n", path, line);
+    2189             :                                 exit(EXIT_FAILURE);
+    2190             :                                 /* LCOV_EXCL_STOP */
+    2191             :                         }
+    2192             : 
+    2193           5 :                         if (strcmp(buffer, "murmur3") == 0) {
+    2194           5 :                                 state->hash = HASH_MURMUR3;
+    2195           0 :                         } else if (strcmp(buffer, "spooky2") == 0) {
+    2196           0 :                                 state->hash = HASH_SPOOKY2;
+    2197             :                         } else {
+    2198             :                                 /* LCOV_EXCL_START */
+    2199             :                                 log_fatal("Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line);
+    2200             :                                 exit(EXIT_FAILURE);
+    2201             :                                 /* LCOV_EXCL_STOP */
+    2202             :                         }
+    2203             : 
+    2204           5 :                         c = sgetc(f);
+    2205           5 :                         if (c == ' ') {
+    2206             :                                 /* read the seed if present */
+    2207           5 :                                 ret = sgethex(f, state->hashseed, HASH_SIZE);
+    2208           5 :                                 if (ret < 0) {
+    2209             :                                         /* LCOV_EXCL_START */
+    2210             :                                         log_fatal("Invalid 'seed' specification in '%s' at line %u\n", path, line);
+    2211             :                                         exit(EXIT_FAILURE);
+    2212             :                                         /* LCOV_EXCL_STOP */
+    2213             :                                 }
+    2214             :                         } else {
+    2215           0 :                                 sungetc(c, f);
+    2216           0 :                                 memset(state->hashseed, 0, HASH_SIZE);
+    2217             :                         }
+    2218          70 :                 } else if (strcmp(tag, "prevchecksum") == 0) {
+    2219             : 
+    2220           0 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    2221           0 :                         if (ret < 0) {
+    2222             :                                 /* LCOV_EXCL_START */
+    2223             :                                 log_fatal("Invalid 'prevchecksum' specification in '%s' at line %u\n", path, line);
+    2224             :                                 exit(EXIT_FAILURE);
+    2225             :                                 /* LCOV_EXCL_STOP */
+    2226             :                         }
+    2227             : 
+    2228           0 :                         if (strcmp(buffer, "murmur3") == 0) {
+    2229           0 :                                 state->prevhash = HASH_MURMUR3;
+    2230           0 :                         } else if (strcmp(buffer, "spooky2") == 0) {
+    2231           0 :                                 state->prevhash = HASH_SPOOKY2;
+    2232             :                         } else {
+    2233             :                                 /* LCOV_EXCL_START */
+    2234             :                                 log_fatal("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line);
+    2235             :                                 exit(EXIT_FAILURE);
+    2236             :                                 /* LCOV_EXCL_STOP */
+    2237             :                         }
+    2238             : 
+    2239           0 :                         c = sgetc(f);
+    2240           0 :                         if (c != ' ') {
+    2241             :                                 /* LCOV_EXCL_START */
+    2242             :                                 log_fatal("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line);
+    2243             :                                 exit(EXIT_FAILURE);
+    2244             :                                 /* LCOV_EXCL_STOP */
+    2245             :                         }
+    2246             : 
+    2247             :                         /* read the seed */
+    2248           0 :                         ret = sgethex(f, state->prevhashseed, HASH_SIZE);
+    2249           0 :                         if (ret < 0) {
+    2250             :                                 /* LCOV_EXCL_START */
+    2251             :                                 log_fatal("Invalid 'seed' specification in '%s' at line %u\n", path, line);
+    2252             :                                 exit(EXIT_FAILURE);
+    2253             :                                 /* LCOV_EXCL_STOP */
+    2254             :                         }
+    2255          70 :                 } else if (strcmp(tag, "blksize") == 0) {
+    2256             :                         block_off_t blksize;
+    2257             : 
+    2258           5 :                         ret = sgetu32(f, &blksize);
+    2259           5 :                         if (ret < 0) {
+    2260             :                                 /* LCOV_EXCL_START */
+    2261             :                                 log_fatal("Invalid 'blksize' specification in '%s' at line %u\n", path, line);
+    2262             :                                 exit(EXIT_FAILURE);
+    2263             :                                 /* LCOV_EXCL_STOP */
+    2264             :                         }
+    2265             : 
+    2266             :                         /* without configuration, auto assign the block size */
+    2267           5 :                         if (state->no_conf) {
+    2268           0 :                                 state->block_size = blksize;
+    2269             :                         }
+    2270             : 
+    2271           5 :                         if (blksize != state->block_size) {
+    2272             :                                 /* LCOV_EXCL_START */
+    2273             :                                 log_fatal("Mismatching 'blksize' and 'blocksize' specification in '%s' at line %u\n", path, line);
+    2274             :                                 log_fatal("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024);
+    2275             :                                 exit(EXIT_FAILURE);
+    2276             :                                 /* LCOV_EXCL_STOP */
+    2277             :                         }
+    2278          95 :                 } else if (strcmp(tag, "map") == 0 || strcmp(tag, "mapping") == 0) {
+    2279             :                         struct snapraid_map* map;
+    2280             :                         char uuid[UUID_MAX];
+    2281             :                         uint32_t v_pos;
+    2282             :                         uint32_t v_total_blocks;
+    2283             :                         uint32_t v_free_blocks;
+    2284             : 
+    2285          30 :                         ret = sgettok(f, buffer, sizeof(buffer));
+    2286          30 :                         if (ret < 0) {
+    2287             :                                 /* LCOV_EXCL_START */
+    2288             :                                 log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2289             :                                 exit(EXIT_FAILURE);
+    2290             :                                 /* LCOV_EXCL_STOP */
+    2291             :                         }
+    2292             : 
+    2293          30 :                         c = sgetc(f);
+    2294          30 :                         if (c != ' ') {
+    2295             :                                 /* LCOV_EXCL_START */
+    2296             :                                 log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2297             :                                 exit(EXIT_FAILURE);
+    2298             :                                 /* LCOV_EXCL_STOP */
+    2299             :                         }
+    2300             : 
+    2301          30 :                         ret = sgetu32(f, &v_pos);
+    2302          30 :                         if (ret < 0) {
+    2303             :                                 /* LCOV_EXCL_START */
+    2304             :                                 log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2305             :                                 exit(EXIT_FAILURE);
+    2306             :                                 /* LCOV_EXCL_STOP */
+    2307             :                         }
+    2308             : 
+    2309             :                         /* from SnapRAID 7.0 the 'mapping' command includes the free space */
+    2310          30 :                         if (strcmp(tag, "mapping") == 0) {
+    2311          30 :                                 c = sgetc(f);
+    2312          30 :                                 if (c != ' ') {
+    2313             :                                         /* LCOV_EXCL_START */
+    2314             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2315             :                                         exit(EXIT_FAILURE);
+    2316             :                                         /* LCOV_EXCL_STOP */
+    2317             :                                 }
+    2318             : 
+    2319          30 :                                 ret = sgetu32(f, &v_total_blocks);
+    2320          30 :                                 if (ret < 0) {
+    2321             :                                         /* LCOV_EXCL_START */
+    2322             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2323             :                                         exit(EXIT_FAILURE);
+    2324             :                                         /* LCOV_EXCL_STOP */
+    2325             :                                 }
+    2326             : 
+    2327          30 :                                 c = sgetc(f);
+    2328          30 :                                 if (c != ' ') {
+    2329             :                                         /* LCOV_EXCL_START */
+    2330             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2331             :                                         exit(EXIT_FAILURE);
+    2332             :                                         /* LCOV_EXCL_STOP */
+    2333             :                                 }
+    2334             : 
+    2335          30 :                                 ret = sgetu32(f, &v_free_blocks);
+    2336          30 :                                 if (ret < 0) {
+    2337             :                                         /* LCOV_EXCL_START */
+    2338             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2339             :                                         exit(EXIT_FAILURE);
+    2340             :                                         /* LCOV_EXCL_STOP */
+    2341             :                                 }
+    2342             :                         } else {
+    2343           0 :                                 v_total_blocks = 0;
+    2344           0 :                                 v_free_blocks = 0;
+    2345             :                         }
+    2346             : 
+    2347             :                         /* check if the uuid is present */
+    2348             :                         /* uuid must be the latest one as it could be also empty */
+    2349          30 :                         c = sgetc(f);
+    2350          30 :                         if (c != ' ') {
+    2351           0 :                                 sungetc(c, f);
+    2352           0 :                                 uuid[0] = 0;
+    2353             :                         } else {
+    2354             :                                 /* read the uuid */
+    2355          30 :                                 ret = sgettok(f, uuid, sizeof(uuid));
+    2356          30 :                                 if (ret < 0) {
+    2357             :                                         /* LCOV_EXCL_START */
+    2358             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2359             :                                         exit(EXIT_FAILURE);
+    2360             :                                         /* LCOV_EXCL_STOP */
+    2361             :                                 }
+    2362             :                         }
+    2363             : 
+    2364          30 :                         map = map_alloc(buffer, v_pos, v_total_blocks, v_free_blocks, uuid);
+    2365             : 
+    2366          30 :                         tommy_list_insert_tail(&state->maplist, &map->node, map);
+    2367          35 :                 } else if (strcmp(tag, "parity") == 0) {
+    2368             :                         /* from SnapRAID 7.0 the 'parity' command includes the free space */
+    2369             :                         char uuid[UUID_MAX];
+    2370             :                         uint32_t v_level;
+    2371             :                         uint32_t v_total_blocks;
+    2372             :                         uint32_t v_free_blocks;
+    2373             : 
+    2374          30 :                         ret = sgetu32(f, &v_level);
+    2375          30 :                         if (ret < 0) {
+    2376             :                                 /* LCOV_EXCL_START */
+    2377             :                                 log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line);
+    2378             :                                 exit(EXIT_FAILURE);
+    2379             :                                 /* LCOV_EXCL_STOP */
+    2380             :                         }
+    2381             : 
+    2382          30 :                         c = sgetc(f);
+    2383          30 :                         if (c != ' ') {
+    2384             :                                 /* LCOV_EXCL_START */
+    2385             :                                 log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line);
+    2386             :                                 exit(EXIT_FAILURE);
+    2387             :                                 /* LCOV_EXCL_STOP */
+    2388             :                         }
+    2389             : 
+    2390          30 :                         ret = sgetu32(f, &v_total_blocks);
+    2391          30 :                         if (ret < 0) {
+    2392             :                                 /* LCOV_EXCL_START */
+    2393             :                                 log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line);
+    2394             :                                 exit(EXIT_FAILURE);
+    2395             :                                 /* LCOV_EXCL_STOP */
+    2396             :                         }
+    2397             : 
+    2398          30 :                         c = sgetc(f);
+    2399          30 :                         if (c != ' ') {
+    2400             :                                 /* LCOV_EXCL_START */
+    2401             :                                 log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line);
+    2402             :                                 exit(EXIT_FAILURE);
+    2403             :                                 /* LCOV_EXCL_STOP */
+    2404             :                         }
+    2405             : 
+    2406          30 :                         ret = sgetu32(f, &v_free_blocks);
+    2407          30 :                         if (ret < 0) {
+    2408             :                                 /* LCOV_EXCL_START */
+    2409             :                                 log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line);
+    2410             :                                 exit(EXIT_FAILURE);
+    2411             :                                 /* LCOV_EXCL_STOP */
+    2412             :                         }
+    2413             : 
+    2414             :                         /* check if the uuid is present */
+    2415             :                         /* uuid must be the latest one as it could be also empty */
+    2416          30 :                         c = sgetc(f);
+    2417          30 :                         if (c != ' ') {
+    2418           0 :                                 sungetc(c, f);
+    2419           0 :                                 uuid[0] = 0;
+    2420             :                         } else {
+    2421             :                                 /* read the uuid */
+    2422          30 :                                 ret = sgettok(f, uuid, sizeof(uuid));
+    2423          30 :                                 if (ret < 0) {
+    2424             :                                         /* LCOV_EXCL_START */
+    2425             :                                         log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line);
+    2426             :                                         exit(EXIT_FAILURE);
+    2427             :                                         /* LCOV_EXCL_STOP */
+    2428             :                                 }
+    2429             :                         }
+    2430             : 
+    2431             :                         /* auto configure if configuration is missing */
+    2432          30 :                         if (state->no_conf && v_level < LEV_MAX && v_level >= state->level)
+    2433           0 :                                 state->level = v_level + 1;
+    2434             : 
+    2435             :                         /* if we use this parity entry */
+    2436          30 :                         if (v_level < state->level) {
+    2437             :                                 /* set the parity info */
+    2438          30 :                                 pathcpy(state->parity[v_level].uuid, sizeof(state->parity[v_level].uuid), uuid);
+    2439          30 :                                 state->parity[v_level].total_blocks = v_total_blocks;
+    2440          30 :                                 state->parity[v_level].free_blocks = v_free_blocks;
+    2441             :                         }
+    2442           5 :                 } else if (strcmp(tag, "sign") == 0) {
+    2443             :                         uint32_t sign;
+    2444             : 
+    2445           0 :                         ret = sgetu32(f, &sign);
+    2446           0 :                         if (ret < 0) {
+    2447             :                                 /* LCOV_EXCL_START */
+    2448             :                                 log_fatal("Invalid 'sign' specification in '%s' at line %u\n", path, line);
+    2449             :                                 exit(EXIT_FAILURE);
+    2450             :                                 /* LCOV_EXCL_STOP */
+    2451             :                         }
+    2452             : 
+    2453             :                         /* sign check not supported anymore for the text content file */
+    2454           5 :                 } else if (tag[0] == 0) {
+    2455             :                         /* allow empty lines */
+    2456           5 :                         sgetspace(f);
+    2457           0 :                 } else if (tag[0] == '#') {
+    2458           0 :                         ret = sgetline(f, buffer, sizeof(buffer));
+    2459           0 :                         if (ret < 0) {
+    2460             :                                 /* LCOV_EXCL_START */
+    2461             :                                 log_fatal("Invalid comment in '%s' at line %u\n", path, line);
+    2462             :                                 exit(EXIT_FAILURE);
+    2463             :                                 /* LCOV_EXCL_STOP */
+    2464             :                         }
+    2465             :                 } else {
+    2466             :                         /* LCOV_EXCL_START */
+    2467             :                         log_fatal("Invalid command '%s' in '%s' at line %u\n", tag, path, line);
+    2468             :                         exit(EXIT_FAILURE);
+    2469             :                         /* LCOV_EXCL_STOP */
+    2470             :                 }
+    2471             : 
+    2472             :                 /* next line */
+    2473      364527 :                 c = sgeteol(f);
+    2474      364527 :                 if (c == EOF) {
+    2475           5 :                         break;
+    2476             :                 }
+    2477      364522 :                 if (c != '\n') {
+    2478             :                         /* LCOV_EXCL_START */
+    2479             :                         log_fatal("Extra data in '%s' at line %u\n", path, line);
+    2480             :                         exit(EXIT_FAILURE);
+    2481             :                         /* LCOV_EXCL_STOP */
+    2482             :                 }
+    2483      364522 :                 ++line;
+    2484      364522 :         }
+    2485             : 
+    2486           5 :         if (serror(f)) {
+    2487             :                 /* LCOV_EXCL_START */
+    2488             :                 log_fatal("Error reading the content file '%s' at line %u\n", path, line);
+    2489             :                 exit(EXIT_FAILURE);
+    2490             :                 /* LCOV_EXCL_STOP */
+    2491             :         }
+    2492             : 
+    2493           5 :         if (file) {
+    2494             :                 /* LCOV_EXCL_START */
+    2495             :                 log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line);
+    2496             :                 exit(EXIT_FAILURE);
+    2497             :                 /* LCOV_EXCL_STOP */
+    2498             :         }
+    2499             : 
+    2500             :         /* check that the stored parity size matches the loaded state */
+    2501           5 :         if (blockmax != parity_allocated_size(state)) {
+    2502             :                 /* LCOV_EXCL_START */
+    2503             :                 log_fatal("Internal inconsistency in parity size in '%s' at line %u\n", path, line);
+    2504             :                 exit(EXIT_FAILURE);
+    2505             :                 /* LCOV_EXCL_STOP */
+    2506             :         }
+    2507             : 
+    2508             :         /* to be backward compatible with old context files without info */
+    2509             :         /* create info records if missing */
+    2510       39346 :         for (b = 0; b < blockmax; ++b) {
+    2511             :                 /* if the position is used */
+    2512       39341 :                 if (info_is_required(state, b)) {
+    2513       34905 :                         snapraid_info info = info_get(&state->infoarr, b);
+    2514             : 
+    2515             :                         /* if no info is present  */
+    2516       34905 :                         if (!info) {
+    2517             :                                 /* LCOV_EXCL_START */
+    2518             :                                 /* set a fake info block */
+    2519             :                                 info = info_make(save_time, 0, 0);
+    2520             : 
+    2521             :                                 /* insert the info in the array */
+    2522             :                                 info_set(&state->infoarr, b, info);
+    2523             :                                 /* LCOV_EXCL_STOP */
+    2524             :                         }
+    2525             :                 }
+    2526             :         }
+    2527             : 
+    2528           5 :         msg_verbose("%8u files\n", count_file);
+    2529           5 :         msg_verbose("%8u hardlinks\n", count_hardlink);
+    2530           5 :         msg_verbose("%8u symlinks\n", count_symlink);
+    2531           5 :         msg_verbose("%8u empty dirs\n", count_dir);
+    2532           5 : }
+    2533             : 
+    2534           5 : static void state_write_text(struct snapraid_state* state, STREAM* f)
+    2535             : {
+    2536             :         unsigned count_file;
+    2537             :         unsigned count_hardlink;
+    2538             :         unsigned count_symlink;
+    2539             :         unsigned count_dir;
+    2540             :         tommy_node* i;
+    2541             :         block_off_t b;
+    2542             :         block_off_t blockmax;
+    2543             :         int info_has_rehash;
+    2544             :         unsigned l;
+    2545             : 
+    2546           5 :         count_file = 0;
+    2547           5 :         count_hardlink = 0;
+    2548           5 :         count_symlink = 0;
+    2549           5 :         count_dir = 0;
+    2550             : 
+    2551             :         /* blocks of all array */
+    2552           5 :         blockmax = parity_allocated_size(state);
+    2553             : 
+    2554             :         /* clear the info for unused blocks */
+    2555             :         /* and get some other info */
+    2556           5 :         info_has_rehash = 0; /* if there is a rehash info */
+    2557       41564 :         for (b = 0; b < blockmax; ++b) {
+    2558             :                 /* if the position is used */
+    2559       41559 :                 if (position_is_required(state, b)) {
+    2560       41559 :                         snapraid_info info = info_get(&state->infoarr, b);
+    2561             : 
+    2562             :                         /* only if there is some info to store */
+    2563       41559 :                         if (info) {
+    2564       34905 :                                 if (info_get_rehash(info))
+    2565           0 :                                         info_has_rehash = 1;
+    2566             :                         }
+    2567             :                 } else {
+    2568             :                         /* clear any previous info */
+    2569           0 :                         info_set(&state->infoarr, b, 0);
+    2570             : 
+    2571             :                         /* and clear any deleted blocks */
+    2572           0 :                         position_clear_deleted(state, b);
+    2573             :                 }
+    2574             :         }
+    2575             : 
+    2576           5 :         sputsl("blksize ", f);
+    2577           5 :         sputu32(state->block_size, f);
+    2578           5 :         sputeol(f);
+    2579           5 :         if (serror(f)) {
+    2580             :                 /* LCOV_EXCL_START */
+    2581             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2582             :                 exit(EXIT_FAILURE);
+    2583             :                 /* LCOV_EXCL_STOP */
+    2584             :         }
+    2585             : 
+    2586           5 :         if (state->hash == HASH_MURMUR3) {
+    2587           5 :                 sputsl("checksum murmur3", f);
+    2588           0 :         } else if (state->hash == HASH_SPOOKY2) {
+    2589           0 :                 sputsl("checksum spooky2", f);
+    2590             :         } else {
+    2591             :                 /* LCOV_EXCL_START */
+    2592             :                 log_fatal("Unexpected hash when writing the content file '%s'.\n", serrorfile(f));
+    2593             :                 exit(EXIT_FAILURE);
+    2594             :                 /* LCOV_EXCL_STOP */
+    2595             :         }
+    2596           5 :         sputc(' ', f);
+    2597           5 :         sputhex(state->hashseed, HASH_SIZE, f);
+    2598           5 :         sputeol(f);
+    2599           5 :         if (serror(f)) {
+    2600             :                 /* LCOV_EXCL_START */
+    2601             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2602             :                 exit(EXIT_FAILURE);
+    2603             :                 /* LCOV_EXCL_STOP */
+    2604             :         }
+    2605             : 
+    2606             :         /* previous hash only present */
+    2607           5 :         if (state->prevhash != HASH_UNDEFINED) {
+    2608             :                 /* if at least one rehash tag found, we have to save the previous hash */
+    2609           0 :                 if (info_has_rehash) {
+    2610           0 :                         if (state->prevhash == HASH_MURMUR3) {
+    2611           0 :                                 sputsl("prevchecksum murmur3", f);
+    2612           0 :                         } else if (state->prevhash == HASH_SPOOKY2) {
+    2613           0 :                                 sputsl("prevchecksum spooky2", f);
+    2614             :                         } else {
+    2615             :                                 /* LCOV_EXCL_START */
+    2616             :                                 log_fatal("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f));
+    2617             :                                 exit(EXIT_FAILURE);
+    2618             :                                 /* LCOV_EXCL_STOP */
+    2619             :                         }
+    2620           0 :                         sputc(' ', f);
+    2621           0 :                         sputhex(state->prevhashseed, HASH_SIZE, f);
+    2622           0 :                         sputeol(f);
+    2623           0 :                         if (serror(f)) {
+    2624             :                                 /* LCOV_EXCL_START */
+    2625             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2626             :                                 exit(EXIT_FAILURE);
+    2627             :                                 /* LCOV_EXCL_STOP */
+    2628             :                         }
+    2629             :                 }
+    2630             :         }
+    2631             : 
+    2632             :         /* for each map */
+    2633          35 :         for (i = state->maplist; i != 0; i = i->next) {
+    2634          30 :                 struct snapraid_map* map = i->data;
+    2635             :                 struct snapraid_disk* disk;
+    2636             : 
+    2637             :                 /* find the disk for this mapping */
+    2638          30 :                 disk = find_disk(state, map->name);
+    2639          30 :                 if (!disk) {
+    2640             :                         /* LCOV_EXCL_START */
+    2641             :                         log_fatal("Internal inconsistency for unmapped disk '%s'\n", map->name);
+    2642             :                         exit(EXIT_FAILURE);
+    2643             :                         /* LCOV_EXCL_STOP */
+    2644             :                 }
+    2645             : 
+    2646             :                 /* save the mapping only for not empty disks */
+    2647          30 :                 if (!disk_is_empty(disk, blockmax)) {
+    2648          30 :                         sputsl("mapping ", f);
+    2649          30 :                         sputs(map->name, f);
+    2650          30 :                         sputc(' ', f);
+    2651          30 :                         sputu32(map->position, f);
+    2652          30 :                         sputc(' ', f);
+    2653          30 :                         sputu32(map->total_blocks, f);
+    2654          30 :                         sputc(' ', f);
+    2655          30 :                         sputu32(map->free_blocks, f);
+    2656             : 
+    2657             :                         /* if there is an uuid, print it */
+    2658          30 :                         if (map->uuid[0]) {
+    2659          30 :                                 sputc(' ', f);
+    2660          30 :                                 sputs(map->uuid, f);
+    2661             :                         }
+    2662             : 
+    2663          30 :                         sputeol(f);
+    2664          30 :                         if (serror(f)) {
+    2665             :                                 /* LCOV_EXCL_START */
+    2666             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2667             :                                 exit(EXIT_FAILURE);
+    2668             :                                 /* LCOV_EXCL_STOP */
+    2669             :                         }
+    2670             : 
+    2671             :                         /* mark the disk as with mapping */
+    2672          30 :                         disk->mapping_idx = 0;
+    2673             :                 } else {
+    2674             :                         /* mark the disk as without mapping */
+    2675           0 :                         disk->mapping_idx = -1;
+    2676             :                 }
+    2677             :         }
+    2678             : 
+    2679             :         /* for each parity */
+    2680          35 :         for (l = 0; l < state->level; ++l) {
+    2681          30 :                 sputsl("parity ", f);
+    2682          30 :                 sputu32(l, f);
+    2683          30 :                 sputc(' ', f);
+    2684          30 :                 sputu32(state->parity[l].total_blocks, f);
+    2685          30 :                 sputc(' ', f);
+    2686          30 :                 sputu32(state->parity[l].free_blocks, f);
+    2687             : 
+    2688             :                 /* if there is an uuid, print it */
+    2689          30 :                 if (state->parity[l].uuid[0]) {
+    2690          30 :                         sputc(' ', f);
+    2691          30 :                         sputs(state->parity[l].uuid, f);
+    2692             :                 }
+    2693             : 
+    2694          30 :                 sputeol(f);
+    2695          30 :                 if (serror(f)) {
+    2696             :                         /* LCOV_EXCL_START */
+    2697             :                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2698             :                         exit(EXIT_FAILURE);
+    2699             :                         /* LCOV_EXCL_STOP */
+    2700             :                 }
+    2701             :         }
+    2702             : 
+    2703             :         /* for each disk */
+    2704          35 :         for (i = state->disklist; i != 0; i = i->next) {
+    2705             :                 tommy_node* j;
+    2706          30 :                 struct snapraid_disk* disk = i->data;
+    2707             : 
+    2708             :                 /* if the disk is not mapped, skip it */
+    2709          30 :                 if (disk->mapping_idx < 0)
+    2710           0 :                         continue;
+    2711             : 
+    2712             :                 /* for each file */
+    2713       99663 :                 for (j = disk->filelist; j != 0; j = j->next) {
+    2714       99633 :                         struct snapraid_file* file = j->data;
+    2715             :                         uint64_t size;
+    2716             :                         uint64_t mtime_sec;
+    2717             :                         int32_t mtime_nsec;
+    2718             :                         uint64_t inode;
+    2719             : 
+    2720       99633 :                         size = file->size;
+    2721       99633 :                         mtime_sec = file->mtime_sec;
+    2722       99633 :                         mtime_nsec = file->mtime_nsec;
+    2723       99633 :                         inode = file->inode;
+    2724             : 
+    2725       99633 :                         sputsl("file ", f);
+    2726       99633 :                         sputs(disk->name, f);
+    2727       99633 :                         sputc(' ', f);
+    2728       99633 :                         sputu64(size, f);
+    2729       99633 :                         sputc(' ', f);
+    2730       99633 :                         sputu64(mtime_sec, f);
+    2731       99633 :                         if (mtime_nsec != STAT_NSEC_INVALID) {
+    2732       99633 :                                 sputc('.', f);
+    2733       99633 :                                 sputu32(mtime_nsec, f);
+    2734             :                         }
+    2735       99633 :                         sputc(' ', f);
+    2736       99633 :                         sputu64(inode, f);
+    2737       99633 :                         sputc(' ', f);
+    2738       99633 :                         sputs(file->sub, f);
+    2739       99633 :                         sputeol(f);
+    2740       99633 :                         if (serror(f)) {
+    2741             :                                 /* LCOV_EXCL_START */
+    2742             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2743             :                                 exit(EXIT_FAILURE);
+    2744             :                                 /* LCOV_EXCL_STOP */
+    2745             :                         }
+    2746             : 
+    2747             :                         /* for each block in the file */
+    2748      344506 :                         for (b = 0; b < file->blockmax; ++b) {
+    2749      244873 :                                 struct snapraid_block* block = &file->blockvec[b];
+    2750      244873 :                                 unsigned block_state = block_state_get(block);
+    2751             : 
+    2752             :                                 /* consistency check */
+    2753      244873 :                                 if (block != disk_block_get(disk, block->parity_pos)) {
+    2754             :                                         /* LCOV_EXCL_START */
+    2755             :                                         log_fatal("Internal inconsistency mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub);
+    2756             :                                         exit(EXIT_FAILURE);
+    2757             :                                         /* LCOV_EXCL_STOP */
+    2758             :                                 }
+    2759             : 
+    2760      244873 :                                 switch (block_state) {
+    2761             :                                 case BLOCK_STATE_BLK :
+    2762      202580 :                                         sputsl("blk ", f);
+    2763      202580 :                                         break;
+    2764             :                                 case BLOCK_STATE_CHG :
+    2765       42293 :                                         sputsl("chg ", f);
+    2766       42293 :                                         break;
+    2767             :                                 case BLOCK_STATE_REP :
+    2768           0 :                                         sputsl("rep ", f);
+    2769           0 :                                         break;
+    2770             :                                 default :
+    2771             :                                         /* LCOV_EXCL_START */
+    2772             :                                         log_fatal("Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state);
+    2773             :                                         exit(EXIT_FAILURE);
+    2774             :                                         /* LCOV_EXCL_STOP */
+    2775             :                                 }
+    2776             : 
+    2777      244873 :                                 sputu32(block->parity_pos, f);
+    2778             : 
+    2779      244873 :                                 sputc(' ', f);
+    2780      244873 :                                 sputhex(block->hash, HASH_SIZE, f);
+    2781             : 
+    2782      244873 :                                 sputeol(f);
+    2783      244873 :                                 if (serror(f)) {
+    2784             :                                         /* LCOV_EXCL_START */
+    2785             :                                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2786             :                                         exit(EXIT_FAILURE);
+    2787             :                                         /* LCOV_EXCL_STOP */
+    2788             :                                 }
+    2789             :                         }
+    2790             : 
+    2791       99633 :                         ++count_file;
+    2792             :                 }
+    2793             : 
+    2794             :                 /* for each link */
+    2795        3215 :                 for (j = disk->linklist; j != 0; j = j->next) {
+    2796        3185 :                         struct snapraid_link* link = j->data;
+    2797             : 
+    2798        3185 :                         switch (link_flag_get(link, FILE_IS_LINK_MASK)) {
+    2799             :                         case FILE_IS_HARDLINK :
+    2800          30 :                                 sputsl("hardlink ", f);
+    2801          30 :                                 ++count_hardlink;
+    2802          30 :                                 break;
+    2803             :                         case FILE_IS_SYMLINK :
+    2804        3155 :                                 sputsl("symlink ", f);
+    2805        3155 :                                 ++count_symlink;
+    2806        3155 :                                 break;
+    2807             :                         }
+    2808             : 
+    2809        3185 :                         sputs(disk->name, f);
+    2810        3185 :                         sputc(' ', f);
+    2811        3185 :                         sputs(link->sub, f);
+    2812        3185 :                         sputeol(f);
+    2813        3185 :                         sputsl("to ", f);
+    2814        3185 :                         sputs(link->linkto, f);
+    2815        3185 :                         sputeol(f);
+    2816        3185 :                         if (serror(f)) {
+    2817             :                                 /* LCOV_EXCL_START */
+    2818             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2819             :                                 exit(EXIT_FAILURE);
+    2820             :                                 /* LCOV_EXCL_STOP */
+    2821             :                         }
+    2822             :                 }
+    2823             : 
+    2824             :                 /* for each dir */
+    2825          50 :                 for (j = disk->dirlist; j != 0; j = j->next) {
+    2826          20 :                         struct snapraid_dir* dir = j->data;
+    2827             : 
+    2828          20 :                         sputsl("dir ", f);
+    2829          20 :                         sputs(disk->name, f);
+    2830          20 :                         sputc(' ', f);
+    2831          20 :                         sputs(dir->sub, f);
+    2832          20 :                         sputeol(f);
+    2833          20 :                         if (serror(f)) {
+    2834             :                                 /* LCOV_EXCL_START */
+    2835             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2836             :                                 exit(EXIT_FAILURE);
+    2837             :                                 /* LCOV_EXCL_STOP */
+    2838             :                         }
+    2839             : 
+    2840          20 :                         ++count_dir;
+    2841             :                 }
+    2842             : 
+    2843             :                 /* deleted blocks of the disk */
+    2844          30 :                 sputsl("hole ", f);
+    2845          30 :                 sputs(disk->name, f);
+    2846          30 :                 sputeol(f);
+    2847          30 :                 if (serror(f)) {
+    2848             :                         /* LCOV_EXCL_START */
+    2849             :                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2850             :                         exit(EXIT_FAILURE);
+    2851             :                         /* LCOV_EXCL_STOP */
+    2852             :                 }
+    2853      249384 :                 for (b = 0; b < blockmax; ++b) {
+    2854      249354 :                         if (is_block_deleted(disk, b)) {
+    2855         732 :                                 struct snapraid_block* block = disk_block_get(disk, b);
+    2856             : 
+    2857             :                                 /* consistency check */
+    2858         732 :                                 if (block->parity_pos != b) {
+    2859             :                                         /* LCOV_EXCL_START */
+    2860             :                                         log_fatal("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, b);
+    2861             :                                         exit(EXIT_FAILURE);
+    2862             :                                         /* LCOV_EXCL_STOP */
+    2863             :                                 }
+    2864             : 
+    2865         732 :                                 sputsl("off ", f);
+    2866         732 :                                 sputu32(b, f);
+    2867         732 :                                 sputc(' ', f);
+    2868         732 :                                 sputhex(block->hash, HASH_SIZE, f);
+    2869         732 :                                 sputeol(f);
+    2870         732 :                                 if (serror(f)) {
+    2871             :                                         /* LCOV_EXCL_START */
+    2872             :                                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2873             :                                         exit(EXIT_FAILURE);
+    2874             :                                         /* LCOV_EXCL_STOP */
+    2875             :                                 }
+    2876             :                         }
+    2877             :                 }
+    2878             :         }
+    2879             : 
+    2880             :         /* write the info for each block */
+    2881       41564 :         for (b = 0; b < blockmax; ++b) {
+    2882       41559 :                 snapraid_info info = info_get(&state->infoarr, b);
+    2883             : 
+    2884             :                 /* save only stuffs different than 0 */
+    2885       41559 :                 if (info != 0) {
+    2886       34905 :                         sputsl("inf ", f);
+    2887             : 
+    2888       34905 :                         sputu32(b, f);
+    2889       34905 :                         sputc(' ', f);
+    2890       34905 :                         sputu32(info, f);
+    2891       34905 :                         if (info_get_bad(info)) {
+    2892           0 :                                 sputsl(" bad", f);
+    2893             :                         }
+    2894       34905 :                         if (info_get_rehash(info)) {
+    2895           0 :                                 sputsl(" rehash", f);
+    2896             :                         }
+    2897       34905 :                         sputeol(f);
+    2898       34905 :                         if (serror(f)) {
+    2899             :                                 /* LCOV_EXCL_START */
+    2900             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2901             :                                 exit(EXIT_FAILURE);
+    2902             :                                 /* LCOV_EXCL_STOP */
+    2903             :                         }
+    2904             :                 }
+    2905             :         }
+    2906             : 
+    2907           5 :         if (serror(f)) {
+    2908             :                 /* LCOV_EXCL_START */
+    2909             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    2910             :                 exit(EXIT_FAILURE);
+    2911             :                 /* LCOV_EXCL_STOP */
+    2912             :         }
+    2913             : 
+    2914           5 :         msg_verbose("%8u files\n", count_file);
+    2915           5 :         msg_verbose("%8u hardlinks\n", count_hardlink);
+    2916           5 :         msg_verbose("%8u symlinks\n", count_symlink);
+    2917           5 :         msg_verbose("%8u empty dirs\n", count_dir);
+    2918           5 : }
+    2919             : 
+    2920             : /**
+    2921             :  * Flush the file checking the final CRC.
+    2922             :  * We exploit the fact that the CRC is always stored in the last 4 bytes.
+    2923             :  */
+    2924           1 : static void decoding_error(const char* path, STREAM* f)
+    2925             : {
+    2926             :         unsigned char buf[4];
+    2927             :         uint32_t crc_stored;
+    2928             :         uint32_t crc_computed;
+    2929             : 
+    2930           1 :         if (seof(f)) {
+    2931             :                 /* LCOV_EXCL_START */
+    2932             :                 log_fatal("Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f));
+    2933             :                 log_fatal("This content file is truncated. Use an alternate copy.\n");
+    2934             :                 exit(EXIT_FAILURE);
+    2935             :                 /* LCOV_EXCL_STOP */
+    2936             :         }
+    2937             : 
+    2938           1 :         if (serror(f)) {
+    2939             :                 /* LCOV_EXCL_START */
+    2940             :                 log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f));
+    2941             :                 exit(EXIT_FAILURE);
+    2942             :                 /* LCOV_EXCL_STOP */
+    2943             :         }
+    2944             : 
+    2945           1 :         log_fatal("Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f));
+    2946             : 
+    2947           1 :         buf[0] = 0;
+    2948           1 :         buf[1] = 0;
+    2949           1 :         buf[2] = 0;
+    2950           1 :         buf[3] = 0;
+    2951             : 
+    2952             :         /* read until the end of the file */
+    2953             :         while (1) {
+    2954      855102 :                 int c = sgetc(f);
+    2955      855102 :                 if (c == EOF) {
+    2956           1 :                         break;
+    2957             :                 }
+    2958             : 
+    2959             :                 /* keep the last four bytes */
+    2960      855101 :                 buf[0] = buf[1];
+    2961      855101 :                 buf[1] = buf[2];
+    2962      855101 :                 buf[2] = buf[3];
+    2963      855101 :                 buf[3] = c;
+    2964      855101 :         }
+    2965             : 
+    2966           1 :         if (serror(f)) {
+    2967             :                 /* LCOV_EXCL_START */
+    2968             :                 log_fatal("Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f));
+    2969             :                 exit(EXIT_FAILURE);
+    2970             :                 /* LCOV_EXCL_STOP */
+    2971             :         }
+    2972             : 
+    2973             :         /* get the stored crc from the last four bytes */
+    2974           1 :         crc_stored = buf[0] | (uint32_t)buf[1] << 8 | (uint32_t)buf[2] << 16 | (uint32_t)buf[3] << 24;
+    2975             : 
+    2976             :         /* get the computed crc */
+    2977           1 :         crc_computed = scrc(f);
+    2978             : 
+    2979             :         /* adjust the stored crc to include itself */
+    2980           1 :         crc_stored = crc32c(crc_stored, buf, 4);
+    2981             : 
+    2982           1 :         if (crc_computed != crc_stored) {
+    2983           1 :                 log_fatal("Mismatching CRC in '%s'\n", path);
+    2984           1 :                 log_fatal("This content file is damaged! Use an alternate copy.\n");
+    2985           1 :                 exit(EXIT_FAILURE);
+    2986             :         } else {
+    2987           0 :                 log_fatal("The file CRC is correct!\n");
+    2988             :         }
+    2989           0 : }
+    2990             : 
+    2991         219 : static void state_read_binary(struct snapraid_state* state, const char* path, STREAM* f)
+    2992             : {
+    2993             :         block_off_t blockmax;
+    2994             :         unsigned count_file;
+    2995             :         unsigned count_hardlink;
+    2996             :         unsigned count_symlink;
+    2997             :         unsigned count_dir;
+    2998             :         int crc_checked;
+    2999             :         char buffer[PATH_MAX];
+    3000             :         int ret;
+    3001             :         tommy_array disk_mapping;
+    3002             :         uint32_t mapping_max;
+    3003             : 
+    3004         219 :         blockmax = 0;
+    3005         219 :         count_file = 0;
+    3006         219 :         count_hardlink = 0;
+    3007         219 :         count_symlink = 0;
+    3008         219 :         count_dir = 0;
+    3009         219 :         crc_checked = 0;
+    3010         219 :         mapping_max = 0;
+    3011         219 :         tommy_array_init(&disk_mapping);
+    3012             : 
+    3013         219 :         ret = sread(f, buffer, 12);
+    3014         219 :         if (ret < 0) {
+    3015             :                 /* LCOV_EXCL_START */
+    3016             :                 decoding_error(path, f);
+    3017             :                 log_fatal("Invalid header!\n");
+    3018             :                 exit(EXIT_FAILURE);
+    3019             :                 /* LCOV_EXCL_STOP */
+    3020             :         }
+    3021             : 
+    3022             :         /*
+    3023             :          * File format versions:
+    3024             :          *  - SNAPCNT1/SnapRAID 4.0 First version.
+    3025             :          *  - SNAPCNT2/SnapRAID 7.0 Adds entries 'M' and 'P', to add free_blocks support.
+    3026             :          *    The previous 'm' entry is now deprecated, but supported for importing.
+    3027             :          *    Similarly for text file, we add 'mapping' and 'parity' deprecating 'map'.
+    3028             :          */
+    3029         219 :         if (memcmp(buffer, "SNAPCNT1\n\3\0\0", 12) != 0
+    3030         219 :                 && memcmp(buffer, "SNAPCNT2\n\3\0\0", 12) != 0) {
+    3031             :                 /* LCOV_EXCL_START */
+    3032             :                 if (memcmp(buffer, "SNAPCNT", 7) != 0) {
+    3033             :                         decoding_error(path, f);
+    3034             :                         log_fatal("Invalid header!\n");
+    3035             :                 } else {
+    3036             :                         log_fatal("The content file '%s' was generated with a newer version of SnapRAID!\n", path);
+    3037             :                 }
+    3038             :                 exit(EXIT_FAILURE);
+    3039             :                 /* LCOV_EXCL_STOP */
+    3040             :         }
+    3041             : 
+    3042             :         while (1) {
+    3043             :                 int c;
+    3044             : 
+    3045             :                 /* read the command */
+    3046     3523188 :                 c = sgetc(f);
+    3047     3523188 :                 if (c == EOF) {
+    3048         218 :                         break;
+    3049             :                 }
+    3050             : 
+    3051     3522970 :                 if (c == 'f') {
+    3052             :                         /* file */
+    3053             :                         char sub[PATH_MAX];
+    3054             :                         uint64_t v_size;
+    3055             :                         uint64_t v_mtime_sec;
+    3056             :                         uint32_t v_mtime_nsec;
+    3057             :                         uint64_t v_inode;
+    3058             :                         uint32_t v_idx;
+    3059             :                         struct snapraid_file* file;
+    3060             :                         struct snapraid_disk* disk;
+    3061             :                         uint32_t mapping;
+    3062             : 
+    3063     3407060 :                         ret = sgetb32(f, &mapping);
+    3064     3407060 :                         if (ret < 0 || mapping >= mapping_max) {
+    3065             :                                 /* LCOV_EXCL_START */
+    3066             :                                 decoding_error(path, f);
+    3067             :                                 log_fatal("Internal inconsistency in mapping index!\n");
+    3068             :                                 exit(EXIT_FAILURE);
+    3069             :                                 /* LCOV_EXCL_STOP */
+    3070             :                         }
+    3071     3407060 :                         disk = tommy_array_get(&disk_mapping, mapping);
+    3072             : 
+    3073     3407060 :                         ret = sgetb64(f, &v_size);
+    3074     3407060 :                         if (ret < 0) {
+    3075             :                                 /* LCOV_EXCL_START */
+    3076             :                                 decoding_error(path, f);
+    3077             :                                 exit(EXIT_FAILURE);
+    3078             :                                 /* LCOV_EXCL_STOP */
+    3079             :                         }
+    3080             : 
+    3081             :                         /* check for impossible file size to avoid to crash for a too big allocation */
+    3082     3407060 :                         if (v_size / state->block_size > blockmax) {
+    3083             :                                 /* LCOV_EXCL_START */
+    3084             :                                 decoding_error(path, f);
+    3085             :                                 log_fatal("Internal inconsistency in file size too big!\n");
+    3086             :                                 exit(EXIT_FAILURE);
+    3087             :                                 /* LCOV_EXCL_STOP */
+    3088             :                         }
+    3089             : 
+    3090     3407060 :                         ret = sgetb64(f, &v_mtime_sec);
+    3091     3407060 :                         if (ret < 0) {
+    3092             :                                 /* LCOV_EXCL_START */
+    3093             :                                 decoding_error(path, f);
+    3094             :                                 exit(EXIT_FAILURE);
+    3095             :                                 /* LCOV_EXCL_STOP */
+    3096             :                         }
+    3097             : 
+    3098     3407060 :                         ret = sgetb32(f, &v_mtime_nsec);
+    3099     3407060 :                         if (ret < 0) {
+    3100             :                                 /* LCOV_EXCL_START */
+    3101             :                                 decoding_error(path, f);
+    3102             :                                 exit(EXIT_FAILURE);
+    3103             :                                 /* LCOV_EXCL_STOP */
+    3104             :                         }
+    3105             : 
+    3106             :                         /* STAT_NSEC_INVALID is encoded as 0 */
+    3107     3407060 :                         if (v_mtime_nsec == 0)
+    3108           0 :                                 v_mtime_nsec = STAT_NSEC_INVALID;
+    3109             :                         else
+    3110     3407060 :                                 --v_mtime_nsec;
+    3111             : 
+    3112     3407060 :                         ret = sgetb64(f, &v_inode);
+    3113     3407060 :                         if (ret < 0) {
+    3114             :                                 /* LCOV_EXCL_START */
+    3115             :                                 decoding_error(path, f);
+    3116             :                                 exit(EXIT_FAILURE);
+    3117             :                                 /* LCOV_EXCL_STOP */
+    3118             :                         }
+    3119             : 
+    3120     3407060 :                         ret = sgetbs(f, sub, sizeof(sub));
+    3121     3407060 :                         if (ret < 0) {
+    3122             :                                 /* LCOV_EXCL_START */
+    3123             :                                 decoding_error(path, f);
+    3124             :                                 exit(EXIT_FAILURE);
+    3125             :                                 /* LCOV_EXCL_STOP */
+    3126             :                         }
+    3127     3407060 :                         if (!*sub) {
+    3128             :                                 /* LCOV_EXCL_START */
+    3129             :                                 decoding_error(path, f);
+    3130             :                                 exit(EXIT_FAILURE);
+    3131             :                                 /* LCOV_EXCL_STOP */
+    3132             :                         }
+    3133             : 
+    3134             :                         /* allocate the file */
+    3135     3407060 :                         file = file_alloc(state->block_size, sub, v_size, v_mtime_sec, v_mtime_nsec, v_inode, 0);
+    3136             : 
+    3137             :                         /* insert the file in the file containers */
+    3138     3407060 :                         tommy_hashdyn_insert(&disk->inodeset, &file->nodeset, file, file_inode_hash(file->inode));
+    3139     3407060 :                         tommy_hashdyn_insert(&disk->pathset, &file->pathset, file, file_path_hash(file->sub));
+    3140     3407060 :                         tommy_hashdyn_insert(&disk->stampset, &file->stampset, file, file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec));
+    3141     3407060 :                         tommy_list_insert_tail(&disk->filelist, &file->nodelist, file);
+    3142             : 
+    3143             :                         /* reads all the blocks */
+    3144     3407060 :                         v_idx = 0;
+    3145    10240996 :                         while (v_idx < file->blockmax) {
+    3146             :                                 block_off_t v_pos;
+    3147             :                                 uint32_t v_count;
+    3148             : 
+    3149             :                                 /* get the "subcommand */
+    3150     3426876 :                                 c = sgetc(f);
+    3151             : 
+    3152     3426876 :                                 ret = sgetb32(f, &v_pos);
+    3153     3426876 :                                 if (ret < 0) {
+    3154             :                                         /* LCOV_EXCL_START */
+    3155             :                                         decoding_error(path, f);
+    3156             :                                         exit(EXIT_FAILURE);
+    3157             :                                         /* LCOV_EXCL_STOP */
+    3158             :                                 }
+    3159             : 
+    3160     3426876 :                                 ret = sgetb32(f, &v_count);
+    3161     3426876 :                                 if (ret < 0) {
+    3162             :                                         /* LCOV_EXCL_START */
+    3163             :                                         decoding_error(path, f);
+    3164             :                                         exit(EXIT_FAILURE);
+    3165             :                                         /* LCOV_EXCL_STOP */
+    3166             :                                 }
+    3167             : 
+    3168     3426876 :                                 if (v_idx + v_count > file->blockmax) {
+    3169             :                                         /* LCOV_EXCL_START */
+    3170             :                                         decoding_error(path, f);
+    3171             :                                         log_fatal("Internal inconsistency in block number!\n");
+    3172             :                                         exit(EXIT_FAILURE);
+    3173             :                                         /* LCOV_EXCL_STOP */
+    3174             :                                 }
+    3175             : 
+    3176     3426876 :                                 if (v_pos + v_count > blockmax) {
+    3177             :                                         /* LCOV_EXCL_START */
+    3178             :                                         log_fatal("Internal inconsistency in block size %u/%u!\n", blockmax, v_pos + v_count);
+    3179             :                                         decoding_error(path, f);
+    3180             :                                         exit(EXIT_FAILURE);
+    3181             :                                         /* LCOV_EXCL_START */
+    3182             :                                 }
+    3183             : 
+    3184             :                                 /* grow the array */
+    3185             :                                 tommy_arrayblk_grow(&disk->blockarr, v_pos + v_count);
+    3186             : 
+    3187             :                                 /* fill the blocks in the run */
+    3188             :                                 while (v_count) {
+    3189             :                                         struct snapraid_block* block = &file->blockvec[v_idx];
+    3190             : 
+    3191             :                                         if (block->parity_pos != POS_INVALID) {
+    3192             :                                                 /* LCOV_EXCL_START */
+    3193             :                                                 decoding_error(path, f);
+    3194             :                                                 log_fatal("Internal inconsistency in block position!\n");
+    3195             :                                                 exit(EXIT_FAILURE);
+    3196             :                                                 /* LCOV_EXCL_STOP */
+    3197             :                                         }
+    3198             : 
+    3199     8379092 :                                         switch (c) {
+    3200             :                                         case 'b' :
+    3201     8225914 :                                                 block_state_set(block, BLOCK_STATE_BLK);
+    3202     8225914 :                                                 break;
+    3203             :                                         case 'n' :
+    3204             :                                                 /* deprecated NEW blocks are converted to CHG ones */
+    3205           0 :                                                 block_state_set(block, BLOCK_STATE_CHG);
+    3206           0 :                                                 break;
+    3207             :                                         case 'g' :
+    3208      109750 :                                                 block_state_set(block, BLOCK_STATE_CHG);
+    3209      109750 :                                                 break;
+    3210             :                                         case 'p' :
+    3211       43428 :                                                 block_state_set(block, BLOCK_STATE_REP);
+    3212       43428 :                                                 break;
+    3213             :                                         default :
+    3214             :                                                 /* LCOV_EXCL_START */
+    3215             :                                                 decoding_error(path, f);
+    3216             :                                                 log_fatal("Invalid block type!\n");
+    3217             :                                                 exit(EXIT_FAILURE);
+    3218             :                                                 /* LCOV_EXCL_STOP */
+    3219             :                                         }
+    3220             : 
+    3221     8379092 :                                         block->parity_pos = v_pos;
+    3222             : 
+    3223             :                                         /* read the hash only for 'blk/chg/rep', and not for 'new' */
+    3224     8379092 :                                         if (c != 'n') {
+    3225     8379092 :                                                 ret = sread(f, block->hash, HASH_SIZE);
+    3226     8379092 :                                                 if (ret < 0) {
+    3227             :                                                         /* LCOV_EXCL_START */
+    3228             :                                                         decoding_error(path, f);
+    3229             :                                                         exit(EXIT_FAILURE);
+    3230             :                                                         /* LCOV_EXCL_STOP */
+    3231             :                                                 }
+    3232             :                                         } else {
+    3233             :                                                 /* set the ZERO hash for deprecated NEW blocks */
+    3234           0 :                                                 hash_zero_set(block->hash);
+    3235             :                                         }
+    3236             : 
+    3237             :                                         /* if the block contains a hash of past data */
+    3238             :                                         /* and we are clearing such undeterminated hashes */
+    3239     8379092 :                                         if (state->clear_past_hash
+    3240     2150134 :                                                 && block_has_past_hash(block)
+    3241             :                                         ) {
+    3242             :                                                 /* set the hash value to INVALID */
+    3243       43542 :                                                 hash_invalid_set(block->hash);
+    3244             :                                         }
+    3245             : 
+    3246             :                                         /* if we are disabling the copy optimization */
+    3247             :                                         /* we want also to clear any already previously stored information */
+    3248             :                                         /* in other sync commands */
+    3249             :                                         /* note that this is required only in sync, and we detect */
+    3250             :                                         /* this using the clear_past_hash flag */
+    3251     8379092 :                                         if (state->clear_past_hash
+    3252     2150134 :                                                 && state->opt.force_nocopy
+    3253       14115 :                                                 && block_state_get(block) == BLOCK_STATE_REP
+    3254             :                                         ) {
+    3255             :                                                 /* set the hash value to INVALID */
+    3256           1 :                                                 hash_invalid_set(block->hash);
+    3257             :                                                 /* convert from REP to CHG block */
+    3258           1 :                                                 block_state_set(block, BLOCK_STATE_CHG);
+    3259             :                                         }
+    3260             : 
+    3261             :                                         /* if we want a full sync, marks block as invalid parity */
+    3262             :                                         /* note that we do this after the force_nocopy option */
+    3263             :                                         /* to avoid to mixup the two things */
+    3264     8379092 :                                         if (state->opt.force_full
+    3265       27747 :                                                 && block_state_get(block) == BLOCK_STATE_BLK) {
+    3266             :                                                 /* convert from BLK to REP */
+    3267       27747 :                                                 block_state_set(block, BLOCK_STATE_REP);
+    3268             :                                         }
+    3269             : 
+    3270             :                                         /* we must not overwrite existing blocks */
+    3271     8379092 :                                         if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
+    3272             :                                                 /* LCOV_EXCL_START */
+    3273             :                                                 decoding_error(path, f);
+    3274             :                                                 log_fatal("Internal inconsistency in block existence!\n");
+    3275             :                                                 exit(EXIT_FAILURE);
+    3276             :                                                 /* LCOV_EXCL_STOP */
+    3277             :                                         }
+    3278             : 
+    3279             :                                         /* insert the block in the block array */
+    3280     8379092 :                                         tommy_arrayblk_set(&disk->blockarr, v_pos, block);
+    3281             : 
+    3282             :                                         /* go to the next block */
+    3283     8379092 :                                         ++v_idx;
+    3284     8379092 :                                         ++v_pos;
+    3285     8379092 :                                         --v_count;
+    3286             :                                 }
+    3287             :                         }
+    3288             : 
+    3289             :                         /* stat */
+    3290     3407060 :                         ++count_file;
+    3291      115910 :                 } else if (c == 'i') {
+    3292             :                         /* "inf" command */
+    3293             :                         snapraid_info info;
+    3294             :                         uint32_t v_pos;
+    3295             :                         uint32_t v_oldest;
+    3296             : 
+    3297         218 :                         ret = sgetb32(f, &v_oldest);
+    3298         218 :                         if (ret < 0) {
+    3299             :                                 /* LCOV_EXCL_START */
+    3300             :                                 decoding_error(path, f);
+    3301             :                                 exit(EXIT_FAILURE);
+    3302             :                                 /* LCOV_EXCL_STOP */
+    3303             :                         }
+    3304             : 
+    3305         218 :                         v_pos = 0;
+    3306      288233 :                         while (v_pos < blockmax) {
+    3307             :                                 int rehash;
+    3308             :                                 int bad;
+    3309             :                                 uint32_t t;
+    3310             :                                 uint32_t flag;
+    3311             :                                 uint32_t v_count;
+    3312             : 
+    3313      287797 :                                 ret = sgetb32(f, &v_count);
+    3314      287797 :                                 if (ret < 0) {
+    3315             :                                         /* LCOV_EXCL_START */
+    3316             :                                         decoding_error(path, f);
+    3317             :                                         exit(EXIT_FAILURE);
+    3318             :                                         /* LCOV_EXCL_STOP */
+    3319             :                                 }
+    3320             : 
+    3321      287797 :                                 if (v_pos + v_count > blockmax) {
+    3322             :                                         /* LCOV_EXCL_START */
+    3323             :                                         log_fatal("Internal inconsistency in info size %u/%u!\n", blockmax, v_pos + v_count);
+    3324             :                                         decoding_error(path, f);
+    3325             :                                         exit(EXIT_FAILURE);
+    3326             :                                         /* LCOV_EXCL_STOP */
+    3327             :                                 }
+    3328             : 
+    3329      287797 :                                 ret = sgetb32(f, &flag);
+    3330      287797 :                                 if (ret < 0) {
+    3331             :                                         /* LCOV_EXCL_START */
+    3332             :                                         decoding_error(path, f);
+    3333             :                                         exit(EXIT_FAILURE);
+    3334             :                                         /* LCOV_EXCL_STOP */
+    3335             :                                 }
+    3336             : 
+    3337             :                                 /* if there is an info */
+    3338      287797 :                                 if ((flag & 1) != 0) {
+    3339             :                                         /* read the time */
+    3340      287782 :                                         ret = sgetb32(f, &t);
+    3341      287782 :                                         if (ret < 0) {
+    3342             :                                                 /* LCOV_EXCL_START */
+    3343             :                                                 decoding_error(path, f);
+    3344             :                                                 exit(EXIT_FAILURE);
+    3345             :                                                 /* LCOV_EXCL_STOP */
+    3346             :                                         }
+    3347             : 
+    3348             :                                         /* analyze the flags */
+    3349      287782 :                                         bad = (flag & 2) != 0;
+    3350      287782 :                                         rehash = (flag & 4) != 0;
+    3351             : 
+    3352      287782 :                                         if (rehash && state->prevhash == HASH_UNDEFINED) {
+    3353             :                                                 /* LCOV_EXCL_START */
+    3354             :                                                 decoding_error(path, f);
+    3355             :                                                 log_fatal("Internal inconsistency for missing previous checksum!\n");
+    3356             :                                                 exit(EXIT_FAILURE);
+    3357             :                                                 /* LCOV_EXCL_STOP */
+    3358             :                                         }
+    3359             : 
+    3360      287782 :                                         info = info_make(t + v_oldest, bad, rehash);
+    3361             :                                 } else {
+    3362          15 :                                         info = 0;
+    3363             :                                 }
+    3364             : 
+    3365     2034434 :                                 while (v_count) {
+    3366             :                                         /* insert the info in the array */
+    3367     1458840 :                                         info_set(&state->infoarr, v_pos, info);
+    3368             : 
+    3369             :                                         /* ensure that an info is present only for used positions */
+    3370     1458840 :                                         if (info_is_required(state, v_pos)) {
+    3371     1400399 :                                                 if (!info) {
+    3372             :                                                         /* LCOV_EXCL_START */
+    3373             :                                                         decoding_error(path, f);
+    3374             :                                                         log_fatal("Internal inconsistency for missing info!\n");
+    3375             :                                                         exit(EXIT_FAILURE);
+    3376             :                                                         /* LCOV_EXCL_STOP */
+    3377             :                                                 }
+    3378             :                                         } else {
+    3379             :                                                 /* extra info are accepted for backward compatibility */
+    3380             :                                                 /* they are discarged at the first write */
+    3381             :                                         }
+    3382             : 
+    3383             :                                         /* go to next block */
+    3384     1458840 :                                         ++v_pos;
+    3385     1458840 :                                         --v_count;
+    3386             :                                 }
+    3387             :                         }
+    3388      115692 :                 } else if (c == 'h') {
+    3389             :                         /* hole */
+    3390             :                         uint32_t v_pos;
+    3391             :                         struct snapraid_disk* disk;
+    3392             :                         uint32_t mapping;
+    3393             : 
+    3394        1241 :                         ret = sgetb32(f, &mapping);
+    3395        1241 :                         if (ret < 0 || mapping >= mapping_max) {
+    3396             :                                 /* LCOV_EXCL_START */
+    3397             :                                 decoding_error(path, f);
+    3398             :                                 log_fatal("Internal inconsistency in mapping index!\n");
+    3399             :                                 exit(EXIT_FAILURE);
+    3400             :                                 /* LCOV_EXCL_STOP */
+    3401             :                         }
+    3402        1241 :                         disk = tommy_array_get(&disk_mapping, mapping);
+    3403             : 
+    3404        1241 :                         v_pos = 0;
+    3405        3765 :                         while (v_pos < blockmax) {
+    3406             :                                 uint32_t v_count;
+    3407             : 
+    3408        1283 :                                 ret = sgetb32(f, &v_count);
+    3409        1283 :                                 if (ret < 0) {
+    3410             :                                         /* LCOV_EXCL_START */
+    3411             :                                         decoding_error(path, f);
+    3412             :                                         exit(EXIT_FAILURE);
+    3413             :                                         /* LCOV_EXCL_STOP */
+    3414             :                                 }
+    3415             : 
+    3416        1283 :                                 if (v_pos + v_count > blockmax) {
+    3417             :                                         /* LCOV_EXCL_START */
+    3418             :                                         log_fatal("Internal inconsistency in hole size %u/%u!\n", blockmax, v_pos + v_count);
+    3419             :                                         decoding_error(path, f);
+    3420             :                                         exit(EXIT_FAILURE);
+    3421             :                                         /* LCOV_EXCL_STOP */
+    3422             :                                 }
+    3423             : 
+    3424             :                                 /* get the subcommand */
+    3425        1283 :                                 c = sgetc(f);
+    3426             : 
+    3427        1283 :                                 switch (c) {
+    3428             :                                 case 'o' :
+    3429             :                                         /* grow the array */
+    3430          21 :                                         tommy_arrayblk_grow(&disk->blockarr, v_pos + v_count);
+    3431             : 
+    3432             :                                         /* if it's a run of deleted blocks */
+    3433       27543 :                                         while (v_count) {
+    3434             :                                                 struct snapraid_deleted* deleted;
+    3435             : 
+    3436             :                                                 /* allocate a new deleted block */
+    3437       27501 :                                                 deleted = deleted_alloc();
+    3438             : 
+    3439             :                                                 /* set the position */
+    3440       27501 :                                                 deleted->block.parity_pos = v_pos;
+    3441             : 
+    3442             :                                                 /* read the hash */
+    3443       27501 :                                                 ret = sread(f, deleted->block.hash, HASH_SIZE);
+    3444       27501 :                                                 if (ret < 0) {
+    3445             :                                                         /* LCOV_EXCL_START */
+    3446             :                                                         decoding_error(path, f);
+    3447             :                                                         exit(EXIT_FAILURE);
+    3448             :                                                         /* LCOV_EXCL_STOP */
+    3449             :                                                 }
+    3450             : 
+    3451             :                                                 /* if we are clearing undeterminated hashes */
+    3452       27501 :                                                 if (state->clear_past_hash) {
+    3453             :                                                         /* set the hash value to INVALID */
+    3454        9047 :                                                         hash_invalid_set(deleted->block.hash);
+    3455             :                                                 }
+    3456             : 
+    3457             :                                                 /* we must not overwrite existing blocks */
+    3458       27501 :                                                 if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
+    3459             :                                                         /* LCOV_EXCL_START */
+    3460             :                                                         log_fatal("Internal inconsistency for used hole at pos %u!\n", v_pos);
+    3461             :                                                         if (state->opt.skip_content_check) {
+    3462             :                                                                 log_fatal("Overriding as used.\n");
+    3463             :                                                                 deleted_free(deleted);
+    3464             :                                                         } else {
+    3465             :                                                                 decoding_error(path, f);
+    3466             :                                                                 exit(EXIT_FAILURE);
+    3467             :                                                         }
+    3468             :                                                         /* LCOV_EXCL_STOP */
+    3469             :                                                 } else {
+    3470             :                                                         /* insert it in the list of deleted blocks */
+    3471       27501 :                                                         tommy_list_insert_tail(&disk->deletedlist, &deleted->node, deleted);
+    3472             : 
+    3473             :                                                         /* insert the block in the block array */
+    3474       27501 :                                                         tommy_arrayblk_set(&disk->blockarr, v_pos, &deleted->block);
+    3475             :                                                 }
+    3476             : 
+    3477             :                                                 /* go to next block */
+    3478       27501 :                                                 ++v_pos;
+    3479       27501 :                                                 --v_count;
+    3480             :                                         }
+    3481          21 :                                         break;
+    3482             :                                 case 'O' :
+    3483             :                                         /* go to the next run */
+    3484        1262 :                                         v_pos += v_count;
+    3485        1262 :                                         break;
+    3486             :                                 default :
+    3487             :                                         /* LCOV_EXCL_START */
+    3488             :                                         decoding_error(path, f);
+    3489             :                                         log_fatal("Invalid hole type!\n");
+    3490             :                                         exit(EXIT_FAILURE);
+    3491             :                                         /* LCOV_EXCL_STOP */
+    3492             :                                 }
+    3493             :                         }
+    3494      114451 :                 } else if (c == 's') {
+    3495             :                         /* symlink */
+    3496             :                         char sub[PATH_MAX];
+    3497             :                         char linkto[PATH_MAX];
+    3498             :                         struct snapraid_link* link;
+    3499             :                         struct snapraid_disk* disk;
+    3500             :                         uint32_t mapping;
+    3501             : 
+    3502      109172 :                         ret = sgetb32(f, &mapping);
+    3503      109172 :                         if (ret < 0 || mapping >= mapping_max) {
+    3504             :                                 /* LCOV_EXCL_START */
+    3505             :                                 decoding_error(path, f);
+    3506             :                                 log_fatal("Internal inconsistency in mapping index!\n");
+    3507             :                                 exit(EXIT_FAILURE);
+    3508             :                                 /* LCOV_EXCL_STOP */
+    3509             :                         }
+    3510      109172 :                         disk = tommy_array_get(&disk_mapping, mapping);
+    3511             : 
+    3512      109172 :                         ret = sgetbs(f, sub, sizeof(sub));
+    3513      109172 :                         if (ret < 0) {
+    3514             :                                 /* LCOV_EXCL_START */
+    3515             :                                 decoding_error(path, f);
+    3516             :                                 exit(EXIT_FAILURE);
+    3517             :                                 /* LCOV_EXCL_STOP */
+    3518             :                         }
+    3519             : 
+    3520      109172 :                         ret = sgetbs(f, linkto, sizeof(linkto));
+    3521      109172 :                         if (ret < 0) {
+    3522             :                                 /* LCOV_EXCL_START */
+    3523             :                                 decoding_error(path, f);
+    3524             :                                 exit(EXIT_FAILURE);
+    3525             :                                 /* LCOV_EXCL_STOP */
+    3526             :                         }
+    3527             : 
+    3528      109172 :                         if (!*sub || !*linkto) {
+    3529             :                                 /* LCOV_EXCL_START */
+    3530             :                                 decoding_error(path, f);
+    3531             :                                 exit(EXIT_FAILURE);
+    3532             :                                 /* LCOV_EXCL_STOP */
+    3533             :                         }
+    3534             : 
+    3535             :                         /* allocate the link as symbolic link */
+    3536      109172 :                         link = link_alloc(sub, linkto, FILE_IS_SYMLINK);
+    3537             : 
+    3538             :                         /* insert the link in the link containers */
+    3539      109172 :                         tommy_hashdyn_insert(&disk->linkset, &link->nodeset, link, link_name_hash(link->sub));
+    3540      109172 :                         tommy_list_insert_tail(&disk->linklist, &link->nodelist, link);
+    3541             : 
+    3542             :                         /* stat */
+    3543      109172 :                         ++count_symlink;
+    3544        5279 :                 } else if (c == 'a') {
+    3545             :                         /* hardlink */
+    3546             :                         char sub[PATH_MAX];
+    3547             :                         char linkto[PATH_MAX];
+    3548             :                         struct snapraid_link* link;
+    3549             :                         struct snapraid_disk* disk;
+    3550             :                         uint32_t mapping;
+    3551             : 
+    3552        1090 :                         ret = sgetb32(f, &mapping);
+    3553        1090 :                         if (ret < 0 || mapping >= mapping_max) {
+    3554             :                                 /* LCOV_EXCL_START */
+    3555             :                                 decoding_error(path, f);
+    3556             :                                 log_fatal("Internal inconsistency in mapping index!\n");
+    3557             :                                 exit(EXIT_FAILURE);
+    3558             :                                 /* LCOV_EXCL_STOP */
+    3559             :                         }
+    3560        1090 :                         disk = tommy_array_get(&disk_mapping, mapping);
+    3561             : 
+    3562        1090 :                         ret = sgetbs(f, sub, sizeof(sub));
+    3563        1090 :                         if (ret < 0) {
+    3564             :                                 /* LCOV_EXCL_START */
+    3565             :                                 decoding_error(path, f);
+    3566             :                                 exit(EXIT_FAILURE);
+    3567             :                                 /* LCOV_EXCL_STOP */
+    3568             :                         }
+    3569             : 
+    3570        1090 :                         ret = sgetbs(f, linkto, sizeof(linkto));
+    3571        1090 :                         if (ret < 0) {
+    3572             :                                 /* LCOV_EXCL_START */
+    3573             :                                 decoding_error(path, f);
+    3574             :                                 exit(EXIT_FAILURE);
+    3575             :                                 /* LCOV_EXCL_STOP */
+    3576             :                         }
+    3577             : 
+    3578        1090 :                         if (!*sub || !*linkto) {
+    3579             :                                 /* LCOV_EXCL_START */
+    3580             :                                 decoding_error(path, f);
+    3581             :                                 exit(EXIT_FAILURE);
+    3582             :                                 /* LCOV_EXCL_STOP */
+    3583             :                         }
+    3584             : 
+    3585             :                         /* allocate the link as hard link */
+    3586        1090 :                         link = link_alloc(sub, linkto, FILE_IS_HARDLINK);
+    3587             : 
+    3588             :                         /* insert the link in the link containers */
+    3589        1090 :                         tommy_hashdyn_insert(&disk->linkset, &link->nodeset, link, link_name_hash(link->sub));
+    3590        1090 :                         tommy_list_insert_tail(&disk->linklist, &link->nodelist, link);
+    3591             : 
+    3592             :                         /* stat */
+    3593        1090 :                         ++count_hardlink;
+    3594        4189 :                 } else if (c == 'r') {
+    3595             :                         /* dir */
+    3596             :                         char sub[PATH_MAX];
+    3597             :                         struct snapraid_dir* dir;
+    3598             :                         struct snapraid_disk* disk;
+    3599             :                         uint32_t mapping;
+    3600             : 
+    3601         730 :                         ret = sgetb32(f, &mapping);
+    3602         730 :                         if (ret < 0 || mapping >= mapping_max) {
+    3603             :                                 /* LCOV_EXCL_START */
+    3604             :                                 decoding_error(path, f);
+    3605             :                                 log_fatal("Internal inconsistency in mapping index!\n");
+    3606             :                                 exit(EXIT_FAILURE);
+    3607             :                                 /* LCOV_EXCL_STOP */
+    3608             :                         }
+    3609         730 :                         disk = tommy_array_get(&disk_mapping, mapping);
+    3610             : 
+    3611         730 :                         ret = sgetbs(f, sub, sizeof(sub));
+    3612         730 :                         if (ret < 0) {
+    3613             :                                 /* LCOV_EXCL_START */
+    3614             :                                 decoding_error(path, f);
+    3615             :                                 exit(EXIT_FAILURE);
+    3616             :                                 /* LCOV_EXCL_STOP */
+    3617             :                         }
+    3618             : 
+    3619         730 :                         if (!*sub) {
+    3620             :                                 /* LCOV_EXCL_START */
+    3621             :                                 decoding_error(path, f);
+    3622             :                                 exit(EXIT_FAILURE);
+    3623             :                                 /* LCOV_EXCL_STOP */
+    3624             :                         }
+    3625             : 
+    3626             :                         /* allocate the dir */
+    3627         730 :                         dir = dir_alloc(sub);
+    3628             : 
+    3629             :                         /* insert the dir in the dir containers */
+    3630         730 :                         tommy_hashdyn_insert(&disk->dirset, &dir->nodeset, dir, dir_name_hash(dir->sub));
+    3631         730 :                         tommy_list_insert_tail(&disk->dirlist, &dir->nodelist, dir);
+    3632             : 
+    3633             :                         /* stat */
+    3634         730 :                         ++count_dir;
+    3635        3459 :                 } else if (c == 'c') {
+    3636             :                         /* get the subcommand */
+    3637         219 :                         c = sgetc(f);
+    3638             : 
+    3639         219 :                         switch (c) {
+    3640             :                         case 'u' :
+    3641         132 :                                 state->hash = HASH_MURMUR3;
+    3642         132 :                                 break;
+    3643             :                         case 'k' :
+    3644          87 :                                 state->hash = HASH_SPOOKY2;
+    3645          87 :                                 break;
+    3646             :                         default :
+    3647             :                                 /* LCOV_EXCL_START */
+    3648             :                                 decoding_error(path, f);
+    3649             :                                 log_fatal("Invalid checksum!\n");
+    3650             :                                 exit(EXIT_FAILURE);
+    3651             :                                 /* LCOV_EXCL_STOP */
+    3652             :                         }
+    3653             : 
+    3654             :                         /* read the seed */
+    3655         219 :                         ret = sread(f, state->hashseed, HASH_SIZE);
+    3656         219 :                         if (ret < 0) {
+    3657             :                                 /* LCOV_EXCL_START */
+    3658             :                                 decoding_error(path, f);
+    3659             :                                 exit(EXIT_FAILURE);
+    3660             :                                 /* LCOV_EXCL_STOP */
+    3661             :                         }
+    3662        3240 :                 } else if (c == 'C') {
+    3663             :                         /* get the subcommand */
+    3664          87 :                         c = sgetc(f);
+    3665             : 
+    3666          87 :                         switch (c) {
+    3667             :                         case 'u' :
+    3668          87 :                                 state->prevhash = HASH_MURMUR3;
+    3669          87 :                                 break;
+    3670             :                         case 'k' :
+    3671           0 :                                 state->prevhash = HASH_SPOOKY2;
+    3672           0 :                                 break;
+    3673             :                         default :
+    3674             :                                 /* LCOV_EXCL_START */
+    3675             :                                 decoding_error(path, f);
+    3676             :                                 log_fatal("Invalid checksum!\n");
+    3677             :                                 exit(EXIT_FAILURE);
+    3678             :                                 /* LCOV_EXCL_STOP */
+    3679             :                         }
+    3680             : 
+    3681             :                         /* read the seed */
+    3682          87 :                         ret = sread(f, state->prevhashseed, HASH_SIZE);
+    3683          87 :                         if (ret < 0) {
+    3684             :                                 /* LCOV_EXCL_START */
+    3685             :                                 decoding_error(path, f);
+    3686             :                                 exit(EXIT_FAILURE);
+    3687             :                                 /* LCOV_EXCL_STOP */
+    3688             :                         }
+    3689        3153 :                 } else if (c == 'z') {
+    3690             :                         block_off_t blksize;
+    3691             : 
+    3692         219 :                         ret = sgetb32(f, &blksize);
+    3693         219 :                         if (ret < 0) {
+    3694             :                                 /* LCOV_EXCL_START */
+    3695             :                                 decoding_error(path, f);
+    3696             :                                 exit(EXIT_FAILURE);
+    3697             :                                 /* LCOV_EXCL_STOP */
+    3698             :                         }
+    3699             : 
+    3700             :                         /* without configuration, auto assign the block size */
+    3701         219 :                         if (state->no_conf) {
+    3702           1 :                                 state->block_size = blksize;
+    3703             :                         }
+    3704             : 
+    3705         219 :                         if (blksize != state->block_size) {
+    3706             :                                 /* LCOV_EXCL_START */
+    3707             :                                 decoding_error(path, f);
+    3708             :                                 log_fatal("Mismatching 'blksize' and 'blocksize' specification!\n");
+    3709             :                                 log_fatal("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024);
+    3710             :                                 exit(EXIT_FAILURE);
+    3711             :                                 /* LCOV_EXCL_STOP */
+    3712             :                         }
+    3713        2934 :                 } else if (c == 'x') {
+    3714         219 :                         ret = sgetb32(f, &blockmax);
+    3715         219 :                         if (ret < 0) {
+    3716             :                                 /* LCOV_EXCL_START */
+    3717             :                                 decoding_error(path, f);
+    3718             :                                 exit(EXIT_FAILURE);
+    3719             :                                 /* LCOV_EXCL_STOP */
+    3720             :                         }
+    3721        3962 :                 } else if (c == 'm' || c == 'M') {
+    3722             :                         struct snapraid_map* map;
+    3723             :                         char uuid[UUID_MAX];
+    3724             :                         uint32_t v_pos;
+    3725             :                         uint32_t v_total_blocks;
+    3726             :                         uint32_t v_free_blocks;
+    3727             :                         struct snapraid_disk* disk;
+    3728             : 
+    3729        1247 :                         ret = sgetbs(f, buffer, sizeof(buffer));
+    3730        1247 :                         if (ret < 0) {
+    3731             :                                 /* LCOV_EXCL_START */
+    3732             :                                 decoding_error(path, f);
+    3733             :                                 exit(EXIT_FAILURE);
+    3734             :                                 /* LCOV_EXCL_STOP */
+    3735             :                         }
+    3736             : 
+    3737        1247 :                         ret = sgetb32(f, &v_pos);
+    3738        1247 :                         if (ret < 0) {
+    3739             :                                 /* LCOV_EXCL_START */
+    3740             :                                 decoding_error(path, f);
+    3741             :                                 exit(EXIT_FAILURE);
+    3742             :                                 /* LCOV_EXCL_STOP */
+    3743             :                         }
+    3744             : 
+    3745             :                         /* from SnapRAID 7.0 the 'M' command includes the free space */
+    3746        1247 :                         if (c == 'M') {
+    3747        1247 :                                 ret = sgetb32(f, &v_total_blocks);
+    3748        1247 :                                 if (ret < 0) {
+    3749             :                                         /* LCOV_EXCL_START */
+    3750             :                                         decoding_error(path, f);
+    3751             :                                         exit(EXIT_FAILURE);
+    3752             :                                         /* LCOV_EXCL_STOP */
+    3753             :                                 }
+    3754             : 
+    3755        1247 :                                 ret = sgetb32(f, &v_free_blocks);
+    3756        1247 :                                 if (ret < 0) {
+    3757             :                                         /* LCOV_EXCL_START */
+    3758             :                                         decoding_error(path, f);
+    3759             :                                         exit(EXIT_FAILURE);
+    3760             :                                         /* LCOV_EXCL_STOP */
+    3761             :                                 }
+    3762             :                         } else {
+    3763           0 :                                 v_total_blocks = 0;
+    3764           0 :                                 v_free_blocks = 0;
+    3765             :                         }
+    3766             : 
+    3767             :                         /* read the uuid */
+    3768        1247 :                         ret = sgetbs(f, uuid, sizeof(uuid));
+    3769        1247 :                         if (ret < 0) {
+    3770             :                                 /* LCOV_EXCL_START */
+    3771             :                                 decoding_error(path, f);
+    3772             :                                 exit(EXIT_FAILURE);
+    3773             :                                 /* LCOV_EXCL_STOP */
+    3774             :                         }
+    3775             : 
+    3776        1247 :                         map = map_alloc(buffer, v_pos, v_total_blocks, v_free_blocks, uuid);
+    3777             : 
+    3778        1247 :                         tommy_list_insert_tail(&state->maplist, &map->node, map);
+    3779             : 
+    3780             :                         /* find the disk */
+    3781        1247 :                         disk = find_disk(state, buffer);
+    3782        1247 :                         if (!disk) {
+    3783             :                                 /* LCOV_EXCL_START */
+    3784             :                                 decoding_error(path, f);
+    3785             :                                 log_fatal("Disk named '%s' not present in the configuration file!\n", buffer);
+    3786             :                                 log_fatal("If you have removed it from the configuration file, please restore it\n");
+    3787             :                                 exit(EXIT_FAILURE);
+    3788             :                                 /* LCOV_EXCL_STOP */
+    3789             :                         }
+    3790             : 
+    3791             :                         /* insert in the mapping vector */
+    3792        1247 :                         tommy_array_grow(&disk_mapping, mapping_max + 1);
+    3793        1247 :                         tommy_array_set(&disk_mapping, mapping_max, disk);
+    3794        1247 :                         ++mapping_max;
+    3795        1468 :                 } else if (c == 'P') {
+    3796             :                         /* from SnapRAID 7.0 the 'P' command includes the free space */
+    3797             :                         char uuid[UUID_MAX];
+    3798             :                         uint32_t v_level;
+    3799             :                         uint32_t v_total_blocks;
+    3800             :                         uint32_t v_free_blocks;
+    3801             : 
+    3802        1249 :                         ret = sgetb32(f, &v_level);
+    3803        1249 :                         if (ret < 0) {
+    3804             :                                 /* LCOV_EXCL_START */
+    3805             :                                 decoding_error(path, f);
+    3806             :                                 exit(EXIT_FAILURE);
+    3807             :                                 /* LCOV_EXCL_STOP */
+    3808             :                         }
+    3809             : 
+    3810        1249 :                         ret = sgetb32(f, &v_total_blocks);
+    3811        1249 :                         if (ret < 0) {
+    3812             :                                 /* LCOV_EXCL_START */
+    3813             :                                 decoding_error(path, f);
+    3814             :                                 exit(EXIT_FAILURE);
+    3815             :                                 /* LCOV_EXCL_STOP */
+    3816             :                         }
+    3817             : 
+    3818        1249 :                         ret = sgetb32(f, &v_free_blocks);
+    3819        1249 :                         if (ret < 0) {
+    3820             :                                 /* LCOV_EXCL_START */
+    3821             :                                 decoding_error(path, f);
+    3822             :                                 exit(EXIT_FAILURE);
+    3823             :                                 /* LCOV_EXCL_STOP */
+    3824             :                         }
+    3825             : 
+    3826        1249 :                         ret = sgetbs(f, uuid, sizeof(uuid));
+    3827        1249 :                         if (ret < 0) {
+    3828             :                                 /* LCOV_EXCL_START */
+    3829             :                                 decoding_error(path, f);
+    3830             :                                 exit(EXIT_FAILURE);
+    3831             :                                 /* LCOV_EXCL_STOP */
+    3832             :                         }
+    3833             : 
+    3834             :                         /* auto configure if configuration is missing */
+    3835        1249 :                         if (state->no_conf && v_level < LEV_MAX && v_level >= state->level)
+    3836           5 :                                 state->level = v_level + 1;
+    3837             : 
+    3838             :                         /* if we use this parity entry */
+    3839        1249 :                         if (v_level < state->level) {
+    3840             :                                 /* set the parity info */
+    3841         995 :                                 pathcpy(state->parity[v_level].uuid, sizeof(state->parity[v_level].uuid), uuid);
+    3842         995 :                                 state->parity[v_level].total_blocks = v_total_blocks;
+    3843         995 :                                 state->parity[v_level].free_blocks = v_free_blocks;
+    3844             :                         }
+    3845         219 :                 } else if (c == 'N') {
+    3846             :                         uint32_t crc_stored;
+    3847             :                         uint32_t crc_computed;
+    3848             : 
+    3849             :                         /* get the crc before reading it from the file */
+    3850         218 :                         crc_computed = scrc(f);
+    3851             : 
+    3852         218 :                         ret = sgetble32(f, &crc_stored);
+    3853         218 :                         if (ret < 0) {
+    3854             :                                 /* LCOV_EXCL_START */
+    3855             :                                 /* here don't call decoding_error() because it's too late to get the crc */
+    3856             :                                 log_fatal("Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f));
+    3857             :                                 log_fatal("This content file is damaged! Use an alternate copy.\n");
+    3858             :                                 exit(EXIT_FAILURE);
+    3859             :                                 /* LCOV_EXCL_STOP */
+    3860             :                         }
+    3861             : 
+    3862         218 :                         if (crc_stored != crc_computed) {
+    3863             :                                 /* LCOV_EXCL_START */
+    3864             :                                 /* here don't call decoding_error() because it's too late to get the crc */
+    3865             :                                 log_fatal("Mismatching CRC in '%s'\n", path);
+    3866             :                                 log_fatal("This content file is damaged! Use an alternate copy.\n");
+    3867             :                                 exit(EXIT_FAILURE);
+    3868             :                                 /* LCOV_EXCL_STOP */
+    3869             :                         }
+    3870             : 
+    3871         218 :                         crc_checked = 1;
+    3872             :                 } else {
+    3873             :                         /* LCOV_EXCL_START */
+    3874             :                         decoding_error(path, f);
+    3875             :                         log_fatal("Invalid command '%c'!\n", (char)c);
+    3876             :                         exit(EXIT_FAILURE);
+    3877             :                         /* LCOV_EXCL_STOP */
+    3878             :                 }
+    3879     3522969 :         }
+    3880             : 
+    3881         218 :         tommy_array_done(&disk_mapping);
+    3882             : 
+    3883         218 :         if (serror(f)) {
+    3884             :                 /* LCOV_EXCL_START */
+    3885             :                 log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f));
+    3886             :                 exit(EXIT_FAILURE);
+    3887             :                 /* LCOV_EXCL_STOP */
+    3888             :         }
+    3889             : 
+    3890         218 :         if (!crc_checked) {
+    3891             :                 /* LCOV_EXCL_START */
+    3892             :                 log_fatal("Finished reading '%s' without finding the CRC\n", path);
+    3893             :                 log_fatal("This content file is truncated or damaged! Use an alternate copy.\n");
+    3894             :                 exit(EXIT_FAILURE);
+    3895             :                 /* LCOV_EXCL_STOP */
+    3896             :         }
+    3897             : 
+    3898             :         /* check that the stored parity size matches the loaded state */
+    3899         218 :         if (blockmax != parity_allocated_size(state)) {
+    3900             :                 /* LCOV_EXCL_START */
+    3901             :                 log_fatal("Internal inconsistency in parity size %u/%u in '%s' at offset %" PRIi64 "\n", blockmax, parity_allocated_size(state), path, stell(f));
+    3902             :                 if (state->opt.skip_content_check) {
+    3903             :                         log_fatal("Overriding.\n");
+    3904             :                         blockmax = parity_allocated_size(state);
+    3905             :                 } else {
+    3906             :                         exit(EXIT_FAILURE);
+    3907             :                 }
+    3908             :                 /* LCOV_EXCL_STOP */
+    3909             :         }
+    3910             : 
+    3911         218 :         msg_verbose("%8u files\n", count_file);
+    3912         218 :         msg_verbose("%8u hardlinks\n", count_hardlink);
+    3913         218 :         msg_verbose("%8u symlinks\n", count_symlink);
+    3914         218 :         msg_verbose("%8u empty dirs\n", count_dir);
+    3915         218 : }
+    3916             : 
+    3917         115 : static void state_write_binary(struct snapraid_state* state, STREAM* f)
+    3918             : {
+    3919             :         unsigned count_file;
+    3920             :         unsigned count_hardlink;
+    3921             :         unsigned count_symlink;
+    3922             :         unsigned count_dir;
+    3923             :         tommy_node* i;
+    3924             :         block_off_t b;
+    3925             :         block_off_t blockmax;
+    3926             :         block_off_t begin;
+    3927             :         time_t info_oldest;
+    3928             :         int info_has_rehash;
+    3929             :         int mapping_idx;
+    3930             :         unsigned l;
+    3931             :         uint32_t crc;
+    3932             : 
+    3933         115 :         count_file = 0;
+    3934         115 :         count_hardlink = 0;
+    3935         115 :         count_symlink = 0;
+    3936         115 :         count_dir = 0;
+    3937             : 
+    3938             :         /* blocks of all array */
+    3939         115 :         blockmax = parity_allocated_size(state);
+    3940             : 
+    3941             :         /* clear the info for unused blocks */
+    3942             :         /* and get some other info */
+    3943         115 :         info_oldest = 0; /* oldest time in info */
+    3944         115 :         info_has_rehash = 0; /* if there is a rehash info */
+    3945      696567 :         for (b = 0; b < blockmax; ++b) {
+    3946             :                 /* if the position is used */
+    3947      696452 :                 if (position_is_required(state, b)) {
+    3948      696452 :                         snapraid_info info = info_get(&state->infoarr, b);
+    3949             : 
+    3950             :                         /* only if there is some info to store */
+    3951      696452 :                         if (info) {
+    3952      650122 :                                 time_t time = info_get_time(info);
+    3953             : 
+    3954      650122 :                                 if (!info_oldest || time < info_oldest)
+    3955         160 :                                         info_oldest = time;
+    3956             : 
+    3957      650122 :                                 if (info_get_rehash(info))
+    3958      108415 :                                         info_has_rehash = 1;
+    3959             :                         }
+    3960             :                 } else {
+    3961             :                         /* clear any previous info */
+    3962           0 :                         info_set(&state->infoarr, b, 0);
+    3963             : 
+    3964             :                         /* and clear any deleted blocks */
+    3965           0 :                         position_clear_deleted(state, b);
+    3966             :                 }
+    3967             :         }
+    3968             : 
+    3969             :         /* write header */
+    3970         115 :         swrite("SNAPCNT2\n\3\0\0", 12, f);
+    3971             : 
+    3972             :         /* write block size and block max */
+    3973         115 :         sputc('z', f);
+    3974         115 :         sputb32(state->block_size, f);
+    3975         115 :         sputc('x', f);
+    3976         115 :         sputb32(blockmax, f);
+    3977         115 :         if (serror(f)) {
+    3978             :                 /* LCOV_EXCL_START */
+    3979             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    3980             :                 exit(EXIT_FAILURE);
+    3981             :                 /* LCOV_EXCL_STOP */
+    3982             :         }
+    3983             : 
+    3984         115 :         sputc('c', f);
+    3985         115 :         if (state->hash == HASH_MURMUR3) {
+    3986          86 :                 sputc('u', f);
+    3987          29 :         } else if (state->hash == HASH_SPOOKY2) {
+    3988          29 :                 sputc('k', f);
+    3989             :         } else {
+    3990             :                 /* LCOV_EXCL_START */
+    3991             :                 log_fatal("Unexpected hash when writing the content file '%s'.\n", serrorfile(f));
+    3992             :                 exit(EXIT_FAILURE);
+    3993             :                 /* LCOV_EXCL_STOP */
+    3994             :         }
+    3995         115 :         swrite(state->hashseed, HASH_SIZE, f);
+    3996         115 :         if (serror(f)) {
+    3997             :                 /* LCOV_EXCL_START */
+    3998             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    3999             :                 exit(EXIT_FAILURE);
+    4000             :                 /* LCOV_EXCL_STOP */
+    4001             :         }
+    4002             : 
+    4003             :         /* previous hash only present */
+    4004         115 :         if (state->prevhash != HASH_UNDEFINED) {
+    4005             :                 /* if at least one rehash tag found, we have to save the previous hash */
+    4006          29 :                 if (info_has_rehash) {
+    4007          29 :                         sputc('C', f);
+    4008          29 :                         if (state->prevhash == HASH_MURMUR3) {
+    4009          29 :                                 sputc('u', f);
+    4010           0 :                         } else if (state->prevhash == HASH_SPOOKY2) {
+    4011           0 :                                 sputc('k', f);
+    4012             :                         } else {
+    4013             :                                 /* LCOV_EXCL_START */
+    4014             :                                 log_fatal("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f));
+    4015             :                                 exit(EXIT_FAILURE);
+    4016             :                                 /* LCOV_EXCL_STOP */
+    4017             :                         }
+    4018          29 :                         swrite(state->prevhashseed, HASH_SIZE, f);
+    4019          29 :                         if (serror(f)) {
+    4020             :                                 /* LCOV_EXCL_START */
+    4021             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4022             :                                 exit(EXIT_FAILURE);
+    4023             :                                 /* LCOV_EXCL_STOP */
+    4024             :                         }
+    4025             :                 }
+    4026             :         }
+    4027             : 
+    4028             :         /* for each map */
+    4029         115 :         mapping_idx = 0;
+    4030         805 :         for (i = state->maplist; i != 0; i = i->next) {
+    4031         690 :                 struct snapraid_map* map = i->data;
+    4032             :                 struct snapraid_disk* disk;
+    4033             : 
+    4034             :                 /* find the disk for this mapping */
+    4035         690 :                 disk = find_disk(state, map->name);
+    4036         690 :                 if (!disk) {
+    4037             :                         /* LCOV_EXCL_START */
+    4038             :                         log_fatal("Internal inconsistency for unmapped disk '%s'\n", map->name);
+    4039             :                         exit(EXIT_FAILURE);
+    4040             :                         /* LCOV_EXCL_STOP */
+    4041             :                 }
+    4042             : 
+    4043             :                 /* save the mapping only for not empty disks */
+    4044         690 :                 if (!disk_is_empty(disk, blockmax)) {
+    4045         683 :                         sputc('M', f);
+    4046         683 :                         sputbs(map->name, f);
+    4047         683 :                         sputb32(map->position, f);
+    4048         683 :                         sputb32(map->total_blocks, f);
+    4049         683 :                         sputb32(map->free_blocks, f);
+    4050         683 :                         sputbs(map->uuid, f);
+    4051         683 :                         if (serror(f)) {
+    4052             :                                 /* LCOV_EXCL_START */
+    4053             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4054             :                                 exit(EXIT_FAILURE);
+    4055             :                                 /* LCOV_EXCL_STOP */
+    4056             :                         }
+    4057             : 
+    4058             :                         /* assign the mapping index used to identify disks */
+    4059         683 :                         disk->mapping_idx = mapping_idx;
+    4060         683 :                         ++mapping_idx;
+    4061             :                 } else {
+    4062             :                         /* mark the disk as without mapping */
+    4063           7 :                         disk->mapping_idx = -1;
+    4064             :                 }
+    4065             :         }
+    4066             : 
+    4067             :         /* for each parity */
+    4068         790 :         for (l = 0; l < state->level; ++l) {
+    4069         675 :                 sputc('P', f);
+    4070         675 :                 sputb32(l, f);
+    4071         675 :                 sputb32(state->parity[l].total_blocks, f);
+    4072         675 :                 sputb32(state->parity[l].free_blocks, f);
+    4073         675 :                 sputbs(state->parity[l].uuid, f);
+    4074         675 :                 if (serror(f)) {
+    4075             :                         /* LCOV_EXCL_START */
+    4076             :                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4077             :                         exit(EXIT_FAILURE);
+    4078             :                         /* LCOV_EXCL_STOP */
+    4079             :                 }
+    4080             :         }
+    4081             : 
+    4082             :         /* for each disk */
+    4083         805 :         for (i = state->disklist; i != 0; i = i->next) {
+    4084             :                 tommy_node* j;
+    4085         690 :                 struct snapraid_disk* disk = i->data;
+    4086             : 
+    4087             :                 /* if the disk is not mapped, skip it */
+    4088         690 :                 if (disk->mapping_idx < 0)
+    4089           7 :                         continue;
+    4090             : 
+    4091             :                 /* for each file */
+    4092     1629343 :                 for (j = disk->filelist; j != 0; j = j->next) {
+    4093     1628660 :                         struct snapraid_file* file = j->data;
+    4094     1628660 :                         struct snapraid_block* blockvec = file->blockvec;
+    4095             :                         uint64_t size;
+    4096             :                         uint64_t mtime_sec;
+    4097             :                         int32_t mtime_nsec;
+    4098             :                         uint64_t inode;
+    4099             : 
+    4100     1628660 :                         size = file->size;
+    4101     1628660 :                         mtime_sec = file->mtime_sec;
+    4102     1628660 :                         mtime_nsec = file->mtime_nsec;
+    4103     1628660 :                         inode = file->inode;
+    4104             : 
+    4105     1628660 :                         sputc('f', f);
+    4106     1628660 :                         sputb32(disk->mapping_idx, f);
+    4107     1628660 :                         sputb64(size, f);
+    4108     1628660 :                         sputb64(mtime_sec, f);
+    4109             :                         /* encode STAT_NSEC_INVALID as 0 */
+    4110     1628660 :                         if (mtime_nsec == STAT_NSEC_INVALID)
+    4111           0 :                                 sputb32(0, f);
+    4112             :                         else
+    4113     1628660 :                                 sputb32(mtime_nsec + 1, f);
+    4114     1628660 :                         sputb64(inode, f);
+    4115     1628660 :                         sputbs(file->sub, f);
+    4116     1628660 :                         if (serror(f)) {
+    4117             :                                 /* LCOV_EXCL_START */
+    4118             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4119             :                                 exit(EXIT_FAILURE);
+    4120             :                                 /* LCOV_EXCL_STOP */
+    4121             :                         }
+    4122             : 
+    4123             :                         /* for all the blocks of the file */
+    4124     1628660 :                         begin = 0;
+    4125     4895594 :                         while (begin < file->blockmax) {
+    4126     1638274 :                                 unsigned block_state = block_state_get(blockvec + begin);
+    4127     1638274 :                                 uint32_t v_pos = blockvec[begin].parity_pos;
+    4128             :                                 uint32_t v_count;
+    4129             : 
+    4130             :                                 block_off_t end;
+    4131             : 
+    4132             :                                 /* find the end of run of blocks */
+    4133     1638274 :                                 end = begin + 1;
+    4134     5645649 :                                 while (end < file->blockmax
+    4135     2380866 :                                         && block_state == block_state_get(blockvec + end)
+    4136     2380856 :                                         && blockvec[end - 1].parity_pos + 1 == blockvec[end].parity_pos
+    4137             :                                 ) {
+    4138     2369101 :                                         ++end;
+    4139             :                                 }
+    4140             : 
+    4141     1638274 :                                 switch (block_state) {
+    4142             :                                 case BLOCK_STATE_BLK :
+    4143     1537959 :                                         sputc('b', f);
+    4144     1537959 :                                         break;
+    4145             :                                 case BLOCK_STATE_CHG :
+    4146       77650 :                                         sputc('g', f);
+    4147       77650 :                                         break;
+    4148             :                                 case BLOCK_STATE_REP :
+    4149       22665 :                                         sputc('p', f);
+    4150       22665 :                                         break;
+    4151             :                                 default :
+    4152             :                                         /* LCOV_EXCL_START */
+    4153             :                                         log_fatal("Internal inconsistency in state for block %u state %u\n", v_pos, block_state);
+    4154             :                                         exit(EXIT_FAILURE);
+    4155             :                                         /* LCOV_EXCL_STOP */
+    4156             :                                 }
+    4157             : 
+    4158     1638274 :                                 sputb32(v_pos, f);
+    4159             : 
+    4160     1638274 :                                 v_count = end - begin;
+    4161     1638274 :                                 sputb32(v_count, f);
+    4162             : 
+    4163             :                                 /* write hashes */
+    4164     5645649 :                                 for (b = begin; b < end; ++b) {
+    4165     4007375 :                                         struct snapraid_block* block = blockvec + b;
+    4166             : 
+    4167             :                                         /* consistency check */
+    4168     4007375 :                                         if (block != disk_block_get(disk, block->parity_pos)) {
+    4169             :                                                 /* LCOV_EXCL_START */
+    4170             :                                                 log_fatal("Internal inconsistency in mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub);
+    4171             :                                                 exit(EXIT_FAILURE);
+    4172             :                                                 /* LCOV_EXCL_STOP */
+    4173             :                                         }
+    4174             : 
+    4175     4007375 :                                         swrite(block->hash, HASH_SIZE, f);
+    4176             :                                 }
+    4177             : 
+    4178     1638274 :                                 if (serror(f)) {
+    4179             :                                         /* LCOV_EXCL_START */
+    4180             :                                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4181             :                                         exit(EXIT_FAILURE);
+    4182             :                                         /* LCOV_EXCL_STOP */
+    4183             :                                 }
+    4184             : 
+    4185             :                                 /* next begin position */
+    4186     1638274 :                                 begin = end;
+    4187             :                         }
+    4188             : 
+    4189     1628660 :                         ++count_file;
+    4190             :                 }
+    4191             : 
+    4192             :                 /* for each link */
+    4193       54019 :                 for (j = disk->linklist; j != 0; j = j->next) {
+    4194       53336 :                         struct snapraid_link* link = j->data;
+    4195             : 
+    4196       53336 :                         switch (link_flag_get(link, FILE_IS_LINK_MASK)) {
+    4197             :                         case FILE_IS_HARDLINK :
+    4198         572 :                                 sputc('a', f);
+    4199         572 :                                 ++count_hardlink;
+    4200         572 :                                 break;
+    4201             :                         case FILE_IS_SYMLINK :
+    4202       52764 :                                 sputc('s', f);
+    4203       52764 :                                 ++count_symlink;
+    4204       52764 :                                 break;
+    4205             :                         }
+    4206             : 
+    4207       53336 :                         sputb32(disk->mapping_idx, f);
+    4208       53336 :                         sputbs(link->sub, f);
+    4209       53336 :                         sputbs(link->linkto, f);
+    4210       53336 :                         if (serror(f)) {
+    4211             :                                 /* LCOV_EXCL_START */
+    4212             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4213             :                                 exit(EXIT_FAILURE);
+    4214             :                                 /* LCOV_EXCL_STOP */
+    4215             :                         }
+    4216             :                 }
+    4217             : 
+    4218             :                 /* for each dir */
+    4219        1066 :                 for (j = disk->dirlist; j != 0; j = j->next) {
+    4220         383 :                         struct snapraid_dir* dir = j->data;
+    4221             : 
+    4222         383 :                         sputc('r', f);
+    4223         383 :                         sputb32(disk->mapping_idx, f);
+    4224         383 :                         sputbs(dir->sub, f);
+    4225         383 :                         if (serror(f)) {
+    4226             :                                 /* LCOV_EXCL_START */
+    4227             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4228             :                                 exit(EXIT_FAILURE);
+    4229             :                                 /* LCOV_EXCL_STOP */
+    4230             :                         }
+    4231             : 
+    4232         383 :                         ++count_dir;
+    4233             :                 }
+    4234             : 
+    4235             :                 /* deleted blocks of the disk */
+    4236         683 :                 sputc('h', f);
+    4237         683 :                 sputb32(disk->mapping_idx, f);
+    4238         683 :                 if (serror(f)) {
+    4239             :                         /* LCOV_EXCL_START */
+    4240             :                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4241             :                         exit(EXIT_FAILURE);
+    4242             :                         /* LCOV_EXCL_STOP */
+    4243             :                 }
+    4244         683 :                 begin = 0;
+    4245        2118 :                 while (begin < blockmax) {
+    4246             :                         int is_deleted;
+    4247             :                         block_off_t end;
+    4248             : 
+    4249         752 :                         is_deleted = is_block_deleted(disk, begin);
+    4250             : 
+    4251             :                         /* find the end of run of blocks */
+    4252         752 :                         end = begin + 1;
+    4253     4174793 :                         while (end < blockmax
+    4254     4173358 :                                 && is_deleted == is_block_deleted(disk, end)
+    4255             :                         ) {
+    4256     4173289 :                                 ++end;
+    4257             :                         }
+    4258             : 
+    4259         752 :                         sputb32(end - begin, f);
+    4260             : 
+    4261         752 :                         if (is_deleted) {
+    4262             :                                 /* write the run of deleted blocks with hash */
+    4263          40 :                                 sputc('o', f);
+    4264             : 
+    4265             :                                 /* write all the hash */
+    4266       16035 :                                 while (begin < end) {
+    4267       15955 :                                         struct snapraid_block* block = disk_block_get(disk, begin);
+    4268             : 
+    4269             :                                         /* consistency check */
+    4270       15955 :                                         if (block->parity_pos != begin) {
+    4271             :                                                 /* LCOV_EXCL_START */
+    4272             :                                                 log_fatal("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, begin);
+    4273             :                                                 exit(EXIT_FAILURE);
+    4274             :                                                 /* LCOV_EXCL_STOP */
+    4275             :                                         }
+    4276             : 
+    4277       15955 :                                         swrite(block->hash, HASH_SIZE, f);
+    4278             : 
+    4279       15955 :                                         ++begin;
+    4280             :                                 }
+    4281             :                         } else {
+    4282             :                                 /* write the run of blocks without hash */
+    4283             :                                 /* they can be either used or empty blocks */
+    4284         712 :                                 sputc('O', f);
+    4285             : 
+    4286             :                                 /* next begin position */
+    4287         712 :                                 begin = end;
+    4288             :                         }
+    4289             : 
+    4290         752 :                         if (serror(f)) {
+    4291             :                                 /* LCOV_EXCL_START */
+    4292             :                                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4293             :                                 exit(EXIT_FAILURE);
+    4294             :                                 /* LCOV_EXCL_STOP */
+    4295             :                         }
+    4296             :                 }
+    4297             :         }
+    4298             : 
+    4299             :         /* write the info for each block */
+    4300         115 :         sputc('i', f);
+    4301         115 :         sputb32(info_oldest, f);
+    4302         115 :         begin = 0;
+    4303      216979 :         while (begin < blockmax) {
+    4304             :                 snapraid_info info;
+    4305             :                 block_off_t end;
+    4306             :                 time_t t;
+    4307             :                 unsigned flag;
+    4308             : 
+    4309      216749 :                 info = info_get(&state->infoarr, begin);
+    4310             : 
+    4311             :                 /* find the end of run of blocks */
+    4312      216749 :                 end = begin + 1;
+    4313      913201 :                 while (end < blockmax
+    4314      696338 :                         && info == info_get(&state->infoarr, end)
+    4315             :                 ) {
+    4316      479703 :                         ++end;
+    4317             :                 }
+    4318             : 
+    4319      216749 :                 sputb32(end - begin, f);
+    4320             : 
+    4321             :                 /* if there is info */
+    4322      216749 :                 if (info) {
+    4323             :                         /* other flags */
+    4324      216733 :                         flag = 1; /* info is present */
+    4325      216733 :                         if (info_get_bad(info))
+    4326        1467 :                                 flag |= 2;
+    4327      216733 :                         if (info_get_rehash(info))
+    4328       99829 :                                 flag |= 4;
+    4329      216733 :                         sputb32(flag, f);
+    4330             : 
+    4331      216733 :                         t = info_get_time(info) - info_oldest;
+    4332      216733 :                         sputb32(t, f);
+    4333             :                 } else {
+    4334             :                         /* write a special 0 flag to mark missing info */
+    4335          16 :                         sputb32(0, f);
+    4336             :                 }
+    4337             : 
+    4338      216749 :                 if (serror(f)) {
+    4339             :                         /* LCOV_EXCL_START */
+    4340             :                         log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4341             :                         exit(EXIT_FAILURE);
+    4342             :                         /* LCOV_EXCL_STOP */
+    4343             :                 }
+    4344             : 
+    4345             :                 /* next begin position */
+    4346      216749 :                 begin = end;
+    4347             :         }
+    4348             : 
+    4349         115 :         sputc('N', f);
+    4350             : 
+    4351             :         /* flush data written to the disk */
+    4352         115 :         if (sflush(f)) {
+    4353             :                 /* LCOV_EXCL_START */
+    4354             :                 log_fatal("Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno));
+    4355             :                 exit(EXIT_FAILURE);
+    4356             :                 /* LCOV_EXCL_STOP */
+    4357             :         }
+    4358             : 
+    4359             :         /* get the file crc */
+    4360         115 :         crc = scrc(f);
+    4361             : 
+    4362             :         /* compare the crc of the data written to file */
+    4363             :         /* with the one of the data written to the stream */
+    4364         115 :         if (crc != scrc_stream(f)) {
+    4365             :                 /* LCOV_EXCL_START */
+    4366             :                 log_fatal("CRC mismatch writing the content stream.\n");
+    4367             :                 log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n");
+    4368             :                 log_fatal("Try running a memory test like http://www.memtest86.com/\n");
+    4369             :                 exit(EXIT_FAILURE);
+    4370             :                 /* LCOV_EXCL_STOP */
+    4371             :         }
+    4372             : 
+    4373         115 :         sputble32(crc, f);
+    4374         115 :         if (serror(f)) {
+    4375             :                 /* LCOV_EXCL_START */
+    4376             :                 log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
+    4377             :                 exit(EXIT_FAILURE);
+    4378             :                 /* LCOV_EXCL_STOP */
+    4379             :         }
+    4380             : 
+    4381         115 :         msg_verbose("%8u files\n", count_file);
+    4382         115 :         msg_verbose("%8u hardlinks\n", count_hardlink);
+    4383         115 :         msg_verbose("%8u symlinks\n", count_symlink);
+    4384         115 :         msg_verbose("%8u empty dirs\n", count_dir);
+    4385         115 : }
+    4386             : 
+    4387         231 : void state_read(struct snapraid_state* state)
+    4388             : {
+    4389             :         STREAM* f;
+    4390             :         char path[PATH_MAX];
+    4391             :         struct stat st;
+    4392             :         tommy_node* node;
+    4393             :         int ret;
+    4394             :         int c;
+    4395             : 
+    4396             :         /* iterate over all the available content files and load the first one present */
+    4397         231 :         f = 0;
+    4398         231 :         node = tommy_list_head(&state->contentlist);
+    4399         512 :         while (node) {
+    4400         274 :                 struct snapraid_content* content = node->data;
+    4401         274 :                 pathcpy(path, sizeof(path), content->content);
+    4402             : 
+    4403         274 :                 if (!state->no_conf) {
+    4404         273 :                         log_tag("content:%s\n", path);
+    4405         273 :                         log_flush();
+    4406             :                 }
+    4407         274 :                 msg_progress("Loading state from %s...\n", path);
+    4408             : 
+    4409         274 :                 f = sopen_read(path);
+    4410         274 :                 if (f != 0) {
+    4411             :                         /* if openend stop the search */
+    4412         224 :                         break;
+    4413             :                 } else {
+    4414             :                         /* if it's real error of an existing file, abort */
+    4415          50 :                         if (errno != ENOENT) {
+    4416             :                                 /* LCOV_EXCL_START */
+    4417             :                                 log_fatal("Error opening the content file '%s'. %s.\n", path, strerror(errno));
+    4418             :                                 exit(EXIT_FAILURE);
+    4419             :                                 /* LCOV_EXCL_STOP */
+    4420             :                         }
+    4421             : 
+    4422             :                         /* otherwise continue */
+    4423          50 :                         if (node->next) {
+    4424          43 :                                 log_fatal("WARNING! Content file '%s' not found, trying with another copy...\n", path);
+    4425             : 
+    4426             :                                 /* ensure to rewrite all the content files */
+    4427          43 :                                 state->need_write = 1;
+    4428             :                         }
+    4429             :                 }
+    4430             : 
+    4431             :                 /* next content file */
+    4432          50 :                 node = node->next;
+    4433             :         }
+    4434             : 
+    4435             :         /* if not found, assume empty */
+    4436         231 :         if (!f) {
+    4437           7 :                 log_fatal("No content file found. Assuming empty.\n");
+    4438             : 
+    4439             :                 /* create the initial mapping */
+    4440           7 :                 state_map(state);
+    4441         237 :                 return;
+    4442             :         }
+    4443             : 
+    4444             :         /* get the stat of the content file */
+    4445         224 :         ret = fstat(shandle(f), &st);
+    4446         224 :         if (ret != 0) {
+    4447             :                 /* LCOV_EXCL_START */
+    4448             :                 log_fatal("Error stating the content file '%s'. %s.\n", path, strerror(errno));
+    4449             :                 exit(EXIT_FAILURE);
+    4450             :                 /* LCOV_EXCL_STOP */
+    4451             :         }
+    4452             : 
+    4453             :         /* go further to check other content files */
+    4454        1725 :         while (node) {
+    4455             :                 char other_path[PATH_MAX];
+    4456             :                 struct stat other_st;
+    4457        1277 :                 struct snapraid_content* content = node->data;
+    4458        1277 :                 pathcpy(other_path, sizeof(other_path), content->content);
+    4459             : 
+    4460        1277 :                 ret = stat(other_path, &other_st);
+    4461        1277 :                 if (ret != 0) {
+    4462             :                         /* allow missing content files, but not any other kind of error */
+    4463           0 :                         if (errno != ENOENT) {
+    4464             :                                 /* LCOV_EXCL_START */
+    4465             :                                 log_fatal("Error stating the content file '%s'. %s.\n", other_path, strerror(errno));
+    4466             :                                 exit(EXIT_FAILURE);
+    4467             :                                 /* LCOV_EXCL_STOP */
+    4468             :                         }
+    4469             : 
+    4470             :                         /* ensure to rewrite all the content files */
+    4471           0 :                         state->need_write = 1;
+    4472             :                 } else {
+    4473             :                         /* if the size is different */
+    4474        1277 :                         if (other_st.st_size != st.st_size) {
+    4475          35 :                                 log_fatal("WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path);
+    4476          35 :                                 log_fatal("Likely one of the two is broken!\n");
+    4477             : 
+    4478             :                                 /* ensure to rewrite all the content files */
+    4479          35 :                                 state->need_write = 1;
+    4480             :                         }
+    4481             :                 }
+    4482             : 
+    4483             :                 /* next content file */
+    4484        1277 :                 node = node->next;
+    4485             :         }
+    4486             : 
+    4487             :         /* start with a undefined default. */
+    4488             :         /* it's for compatibility with version 1.0 where MD5 was implicit. */
+    4489         224 :         state->hash = HASH_UNDEFINED;
+    4490             : 
+    4491             :         /* start with a zero seed, it was the default in old versions */
+    4492         224 :         memset(state->hashseed, 0, HASH_SIZE);
+    4493             : 
+    4494             :         /* previous hash, start with an undefined value */
+    4495         224 :         state->prevhash = HASH_UNDEFINED;
+    4496             : 
+    4497             :         /* intentionally not set the prevhashseed, if used valgrind will warn about it */
+    4498             : 
+    4499             :         /* get the first char to detect the file type */
+    4500         224 :         c = sgetc(f);
+    4501         224 :         sungetc(c, f);
+    4502             : 
+    4503             :         /* guess the file type from the first char */
+    4504         224 :         if (c == 'S') {
+    4505         219 :                 state_read_binary(state, path, f);
+    4506             :         } else {
+    4507           5 :                 state_read_text(state, path, f, st.st_mtime);
+    4508             : 
+    4509             :                 /* force a rewrite to convert to binary */
+    4510           5 :                 state->need_write = 1;
+    4511             :         }
+    4512             : 
+    4513         223 :         sclose(f);
+    4514             : 
+    4515         223 :         if (state->hash == HASH_UNDEFINED) {
+    4516             :                 /* LCOV_EXCL_START */
+    4517             :                 log_fatal("The checksum to use is not specified.\n");
+    4518             :                 log_fatal("This happens because you are likely upgrading from SnapRAID 1.0.\n");
+    4519             :                 log_fatal("To use a new SnapRAID you must restart from scratch,\n");
+    4520             :                 log_fatal("deleting all the content and parity files.\n");
+    4521             :                 exit(EXIT_FAILURE);
+    4522             :                 /* LCOV_EXCL_STOP */
+    4523             :         }
+    4524             : 
+    4525             :         /* update the mapping */
+    4526         223 :         state_map(state);
+    4527             : 
+    4528         223 :         state_content_check(state, path);
+    4529             : 
+    4530             :         /* mark that we read the content file, and it passed all the checks */
+    4531         223 :         state->checked_read = 1;
+    4532             : }
+    4533             : 
+    4534         120 : void state_write(struct snapraid_state* state)
+    4535             : {
+    4536             :         STREAM* f;
+    4537             :         unsigned count_content;
+    4538             :         tommy_node* i;
+    4539             :         unsigned k;
+    4540             : 
+    4541             :         /* count the content files */
+    4542         120 :         count_content = 0;
+    4543         120 :         i = tommy_list_head(&state->contentlist);
+    4544        1065 :         while (i) {
+    4545         825 :                 struct snapraid_content* content = i->data;
+    4546         825 :                 msg_progress("Saving state to %s...\n", content->content);
+    4547         825 :                 ++count_content;
+    4548         825 :                 i = i->next;
+    4549             :         }
+    4550             : 
+    4551             :         /* open all the content files */
+    4552         120 :         f = sopen_multi_write(count_content);
+    4553         120 :         if (!f) {
+    4554             :                 /* LCOV_EXCL_START */
+    4555             :                 log_fatal("Error opening the content files.\n");
+    4556             :                 exit(EXIT_FAILURE);
+    4557             :                 /* LCOV_EXCL_STOP */
+    4558             :         }
+    4559             : 
+    4560         120 :         k = 0;
+    4561         120 :         i = tommy_list_head(&state->contentlist);
+    4562        1065 :         while (i) {
+    4563         825 :                 struct snapraid_content* content = i->data;
+    4564             :                 char tmp[PATH_MAX];
+    4565         825 :                 pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
+    4566         825 :                 if (sopen_multi_file(f, k, tmp) != 0) {
+    4567             :                         /* LCOV_EXCL_START */
+    4568             :                         log_fatal("Error opening the content file '%s'. %s.\n", tmp, strerror(errno));
+    4569             :                         exit(EXIT_FAILURE);
+    4570             :                         /* LCOV_EXCL_STOP */
+    4571             :                 }
+    4572         825 :                 ++k;
+    4573         825 :                 i = i->next;
+    4574             :         }
+    4575             : 
+    4576         120 :         if (state->opt.force_content_text)
+    4577           5 :                 state_write_text(state, f);
+    4578             :         else
+    4579         115 :                 state_write_binary(state, f);
+    4580             : 
+    4581             :         /* Use the sequence fflush() -> fsync() -> fclose() -> rename() to ensure */
+    4582             :         /* than even in a system crash event we have one valid copy of the file. */
+    4583             : 
+    4584         120 :         if (sflush(f) != 0) {
+    4585             :                 /* LCOV_EXCL_START */
+    4586             :                 log_fatal("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno));
+    4587             :                 exit(EXIT_FAILURE);
+    4588             :                 /* LCOV_EXCL_STOP */
+    4589             :         }
+    4590             : 
+    4591             : #if HAVE_FSYNC
+    4592         120 :         if (ssync(f) != 0) {
+    4593             :                 /* LCOV_EXCL_START */
+    4594             :                 log_fatal("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno));
+    4595             :                 exit(EXIT_FAILURE);
+    4596             :                 /* LCOV_EXCL_STOP */
+    4597             :         }
+    4598             : #endif
+    4599             : 
+    4600         120 :         if (sclose(f) != 0) {
+    4601             :                 /* LCOV_EXCL_START */
+    4602             :                 log_fatal("Error closing the content files in close(). %s.\n", strerror(errno));
+    4603             :                 exit(EXIT_FAILURE);
+    4604             :                 /* LCOV_EXCL_STOP */
+    4605             :         }
+    4606             : 
+    4607         120 :         i = tommy_list_head(&state->contentlist);
+    4608        1065 :         while (i) {
+    4609         825 :                 struct snapraid_content* content = i->data;
+    4610             :                 char tmp[PATH_MAX];
+    4611             : 
+    4612             :                 /* now renames the just written copy with the correct name */
+    4613         825 :                 pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
+    4614         825 :                 if (rename(tmp, content->content) != 0) {
+    4615             :                         /* LCOV_EXCL_START */
+    4616             :                         log_fatal("Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno));
+    4617             :                         exit(EXIT_FAILURE);
+    4618             :                         /* LCOV_EXCL_STOP */
+    4619             :                 }
+    4620             : 
+    4621         825 :                 i = i->next;
+    4622             :         }
+    4623             : 
+    4624         120 :         state->need_write = 0; /* no write needed anymore */
+    4625         120 :         state->checked_read = 0; /* what we wrote is not checked in read */
+    4626         120 : }
+    4627             : 
+    4628         122 : void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tommy_list* filterlist_disk, int filter_missing, int filter_error)
+    4629             : {
+    4630             :         tommy_node* i;
+    4631             : 
+    4632             :         /* if no filter, include all */
+    4633         122 :         if (!filter_missing && !filter_error && tommy_list_empty(filterlist_file) && tommy_list_empty(filterlist_disk))
+    4634         236 :                 return;
+    4635             : 
+    4636           8 :         msg_progress("Filtering...\n");
+    4637             : 
+    4638          11 :         for (i = tommy_list_head(filterlist_disk); i != 0; i = i->next) {
+    4639           3 :                 struct snapraid_filter* filter = i->data;
+    4640           3 :                 msg_verbose("\t%s%s\n", filter->pattern, filter->is_disk ? "//" : "");
+    4641             :         }
+    4642          11 :         for (i = tommy_list_head(filterlist_file); i != 0; i = i->next) {
+    4643           3 :                 struct snapraid_filter* filter = i->data;
+    4644           3 :                 msg_verbose("\t%s%s\n", filter->pattern, filter->is_dir ? "/" : "");
+    4645             :         }
+    4646           8 :         if (filter_missing)
+    4647           2 :                 msg_verbose("\t<missing>\n");
+    4648           8 :         if (filter_error)
+    4649           2 :                 msg_verbose("\t<error>\n");
+    4650             : 
+    4651             :         /* for each disk */
+    4652          56 :         for (i = state->disklist; i != 0; i = i->next) {
+    4653             :                 tommy_node* j;
+    4654          48 :                 struct snapraid_disk* disk = i->data;
+    4655             : 
+    4656             :                 /* if we filter for presence, we have to access the disk, so better to print something */
+    4657          48 :                 if (filter_missing)
+    4658          12 :                         msg_progress("Scanning disk %s...\n", disk->name);
+    4659             : 
+    4660             :                 /* for each file */
+    4661      122582 :                 for (j = tommy_list_head(&disk->filelist); j != 0; j = j->next) {
+    4662      122534 :                         struct snapraid_file* file = j->data;
+    4663             : 
+    4664      122534 :                         if (filter_path(filterlist_disk, 0, disk->name, file->sub) != 0
+    4665       80923 :                                 || filter_path(filterlist_file, 0, disk->name, file->sub) != 0
+    4666       78090 :                                 || filter_existence(filter_missing, disk->dir, file->sub) != 0
+    4667       38818 :                                 || filter_correctness(filter_error, &state->infoarr, file) != 0
+    4668             :                         ) {
+    4669       97808 :                                 file_flag_set(file, FILE_IS_EXCLUDED);
+    4670             :                         }
+    4671             :                 }
+    4672             : 
+    4673             :                 /* for each link */
+    4674        4030 :                 for (j = tommy_list_head(&disk->linklist); j != 0; j = j->next) {
+    4675        3982 :                         struct snapraid_link* link = j->data;
+    4676             : 
+    4677        3982 :                         if (filter_path(filterlist_disk, 0, disk->name, link->sub) != 0
+    4678        2643 :                                 || filter_path(filterlist_file, 0, disk->name, link->sub) != 0
+    4679        2538 :                                 || filter_existence(filter_missing, disk->dir, link->sub) != 0
+    4680             :                         ) {
+    4681        2841 :                                 link_flag_set(link, FILE_IS_EXCLUDED);
+    4682             :                         }
+    4683             :                 }
+    4684             : 
+    4685             :                 /* for each dir */
+    4686          72 :                 for (j = tommy_list_head(&disk->dirlist); j != 0; j = j->next) {
+    4687          24 :                         struct snapraid_dir* dir = j->data;
+    4688             : 
+    4689          24 :                         if (filter_dir(filterlist_disk, 0, disk->name, dir->sub) != 0
+    4690          24 :                                 || filter_dir(filterlist_file, 0, disk->name, dir->sub) != 0
+    4691          24 :                                 || filter_existence(filter_missing, disk->dir, dir->sub) != 0
+    4692             :                         ) {
+    4693           8 :                                 dir_flag_set(dir, FILE_IS_EXCLUDED);
+    4694             :                         }
+    4695             :                 }
+    4696             :         }
+    4697             : }
+    4698             : 
+    4699         197 : int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, block_off_t countmax)
+    4700             : {
+    4701             :         time_t now;
+    4702             : 
+    4703         197 :         if (state->opt.gui) {
+    4704           5 :                 log_tag("run:begin:%u:%u:%u\n", blockstart, blockmax, countmax);
+    4705           5 :                 log_flush();
+    4706             :         }
+    4707             : 
+    4708         197 :         now = time(0);
+    4709             : 
+    4710         197 :         state->progress_whole_start = now;
+    4711             : 
+    4712         197 :         state->progress_tick = 0;
+    4713         197 :         state->progress_ptr = 0;
+    4714         197 :         state->progress_wasted = 0;
+    4715             : 
+    4716             :         /* stop if requested */
+    4717         197 :         if (global_interrupt) {
+    4718             :                 /* LCOV_EXCL_START */
+    4719             :                 if (!state->opt.gui) {
+    4720             :                         msg_status("Not starting for interruption\n");
+    4721             :                 }
+    4722             :                 log_tag("sigint:0: SIGINT received\n");
+    4723             :                 log_flush();
+    4724             :                 return 0;
+    4725             :                 /* LCOV_EXCL_STOP */
+    4726             :         }
+    4727             : 
+    4728         197 :         return 1;
+    4729             : }
+    4730             : 
+    4731         197 : void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize)
+    4732             : {
+    4733         197 :         if (state->opt.gui) {
+    4734           5 :                 log_tag("run:end\n");
+    4735           5 :                 log_flush();
+    4736         192 :         } else if (countmax == 0) {
+    4737          15 :                 msg_status("Nothing to do\n");
+    4738             :         } else {
+    4739             :                 time_t now;
+    4740             :                 time_t elapsed;
+    4741             : 
+    4742         177 :                 unsigned countsize_MB = (countsize + MEGA - 1) / MEGA;
+    4743             : 
+    4744         177 :                 now = time(0);
+    4745             : 
+    4746         177 :                 elapsed = now - state->progress_whole_start - state->progress_wasted;
+    4747             : 
+    4748         177 :                 msg_bar("%u%% completed, %u MB processed", countpos * 100 / countmax, countsize_MB);
+    4749         177 :                 if (elapsed >= 60)
+    4750           0 :                         msg_bar(" in %u:%02u", (unsigned)(elapsed / 3600), (unsigned)((elapsed % 3600) / 60));
+    4751         177 :                 msg_bar("\n");
+    4752         177 :                 msg_flush();
+    4753             :         }
+    4754         197 : }
+    4755             : 
+    4756           1 : void state_progress_stop(struct snapraid_state* state)
+    4757             : {
+    4758             :         time_t now;
+    4759             : 
+    4760           1 :         now = time(0);
+    4761             : 
+    4762           1 :         if (!state->opt.gui) {
+    4763           1 :                 msg_bar("\n");
+    4764           1 :                 msg_flush();
+    4765             :         }
+    4766             : 
+    4767           1 :         state->progress_interruption = now;
+    4768           1 : }
+    4769             : 
+    4770           1 : void state_progress_restart(struct snapraid_state* state)
+    4771             : {
+    4772             :         time_t now;
+    4773             : 
+    4774           1 :         now = time(0);
+    4775             : 
+    4776             :         /* reset the progress counter */
+    4777           1 :         state->progress_tick = 0;
+    4778           1 :         state->progress_ptr = 0;
+    4779             : 
+    4780           1 :         if (now >= state->progress_interruption) /* avoid degenerated cases when the clock is manually adjusted */
+    4781           1 :                 state->progress_wasted += now - state->progress_interruption;
+    4782           1 : }
+    4783             : 
+    4784             : #define PROGRESS_CLEAR "          "
+    4785             : 
+    4786     1025177 : int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize)
+    4787             : {
+    4788             :         time_t now;
+    4789             :         int pred;
+    4790             : 
+    4791     1025177 :         now = time(0);
+    4792             : 
+    4793             :         /* previous position */
+    4794     1025177 :         pred = state->progress_ptr + PROGRESS_MAX - 1;
+    4795     1025177 :         if (pred >= PROGRESS_MAX)
+    4796     1024997 :                 pred -= PROGRESS_MAX;
+    4797             : 
+    4798             :         /* if the previous measure is different */
+    4799     1025177 :         if (state->progress_tick == 0
+    4800     1024997 :                 || state->progress_time[pred] != now
+    4801             :         ) {
+    4802             :                 uint64_t tick_total;
+    4803             :                 uint64_t tick_cpu;
+    4804             :                 time_t elapsed;
+    4805         251 :                 unsigned out_perc = 0;
+    4806         251 :                 unsigned out_speed = 0;
+    4807         251 :                 unsigned out_cpu = 0;
+    4808         251 :                 unsigned out_eta = 0;
+    4809             : 
+    4810         251 :                 tick_total = state->tick_cpu + state->tick_io;
+    4811         251 :                 tick_cpu = state->tick_cpu;
+    4812         251 :                 elapsed = now - state->progress_whole_start - state->progress_wasted;
+    4813             : 
+    4814             :                 /* completion percentage */
+    4815         251 :                 if (countmax)
+    4816         251 :                         out_perc = countpos * 100 / countmax;
+    4817             : 
+    4818             :                 /* if we have at least 5 measures */
+    4819         251 :                 if (state->progress_tick >= 5
+    4820             :                         /* or if we are running in test mode, with at least one measure */
+    4821         251 :                         || (state->opt.force_progress && state->progress_tick >= 1)
+    4822             :                 ) {
+    4823             :                         int oldest;
+    4824             :                         int past;
+    4825             :                         time_t delta_time;
+    4826             :                         block_off_t delta_pos;
+    4827             :                         data_off_t delta_size;
+    4828             :                         uint64_t delta_tick_total;
+    4829             :                         uint64_t delta_tick_cpu;
+    4830             : 
+    4831             :                         /* number of past measures */
+    4832          71 :                         past = state->progress_tick;
+    4833             : 
+    4834             :                         /* drop the oldest ones, to promptly */
+    4835             :                         /* skip the startup phase */
+    4836          71 :                         past -= past / 5;
+    4837             : 
+    4838             :                         /* check how much we can go in the past */
+    4839          71 :                         if (past >= PROGRESS_MAX) {
+    4840             :                                 /* the vector is filled, so we are already in position */
+    4841             :                                 /* to get the possible oldest one */
+    4842           0 :                                 oldest = state->progress_ptr;
+    4843             :                         } else {
+    4844             :                                 /* go backward the number of positions selected */
+    4845          71 :                                 oldest = state->progress_ptr + PROGRESS_MAX - past;
+    4846          71 :                                 if (oldest >= PROGRESS_MAX)
+    4847          71 :                                         oldest -= PROGRESS_MAX;
+    4848             :                         }
+    4849             : 
+    4850          71 :                         delta_time = now - state->progress_time[oldest];
+    4851          71 :                         delta_pos = countpos - state->progress_pos[oldest];
+    4852          71 :                         delta_size = countsize - state->progress_size[oldest];
+    4853          71 :                         delta_tick_total = tick_total - state->progress_tick_total[oldest];
+    4854          71 :                         delta_tick_cpu = tick_cpu - state->progress_tick_cpu[oldest];
+    4855             : 
+    4856             :                         /* estimate the speed in MiB/s */
+    4857          71 :                         if (delta_time != 0)
+    4858          71 :                                 out_speed = (unsigned)(delta_size / MEGA / delta_time);
+    4859             : 
+    4860             :                         /* estimate the cpu usage percentage */
+    4861          71 :                         if (delta_tick_total != 0)
+    4862           8 :                                 out_cpu = (unsigned)(delta_tick_cpu * 100U / delta_tick_total);
+    4863             : 
+    4864             :                         /* estimate the remaining time in minutes */
+    4865          71 :                         if (delta_pos != 0)
+    4866          71 :                                 out_eta = (countmax - countpos) * delta_time / (60 * delta_pos);
+    4867             :                 }
+    4868             : 
+    4869         251 :                 if (state->opt.gui) {
+    4870           6 :                         log_tag("run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed);
+    4871           6 :                         log_flush();
+    4872             :                 } else {
+    4873         245 :                         msg_bar("%u%%, %u MiB", out_perc, (unsigned)(countsize / MEGA));
+    4874         245 :                         if (out_speed)
+    4875          63 :                                 msg_bar(", %u MiB/s", out_speed);
+    4876         245 :                         if (out_cpu)
+    4877           8 :                                 msg_bar(", CPU %u%%", out_cpu);
+    4878         245 :                         if (out_eta)
+    4879           1 :                                 msg_bar(", %u:%02u ETA", out_eta / 60, out_eta % 60);
+    4880         245 :                         msg_bar("%s\r", PROGRESS_CLEAR);
+    4881         245 :                         msg_flush();
+    4882             :                 }
+    4883             : 
+    4884             :                 /* store the new measure */
+    4885         251 :                 state->progress_time[state->progress_ptr] = now;
+    4886         251 :                 state->progress_pos[state->progress_ptr] = countpos;
+    4887         251 :                 state->progress_size[state->progress_ptr] = countsize;
+    4888         251 :                 state->progress_tick_cpu[state->progress_ptr] = tick_cpu;
+    4889         251 :                 state->progress_tick_total[state->progress_ptr] = tick_total;
+    4890             : 
+    4891             :                 /* next position */
+    4892         251 :                 ++state->progress_ptr;
+    4893         251 :                 if (state->progress_ptr >= PROGRESS_MAX)
+    4894           0 :                         state->progress_ptr -= PROGRESS_MAX;
+    4895             : 
+    4896             :                 /* one more measure */
+    4897         251 :                 ++state->progress_tick;
+    4898             :         }
+    4899             : 
+    4900             :         /* stop if requested */
+    4901     1025177 :         if (global_interrupt) {
+    4902             :                 /* LCOV_EXCL_START */
+    4903             :                 if (!state->opt.gui) {
+    4904             :                         log_fatal("\n");
+    4905             :                         log_fatal("Stopping for interruption at block %u\n", blockpos);
+    4906             :                 }
+    4907             :                 log_tag("sigint:%u: SIGINT received\n", blockpos);
+    4908             :                 log_flush();
+    4909             :                 return 1;
+    4910             :                 /* LCOV_EXCL_STOP */
+    4911             :         }
+    4912             : 
+    4913     1025177 :         return 0;
+    4914             : }
+    4915             : 
+    4916          73 : void state_usage_print(struct snapraid_state* state)
+    4917             : {
+    4918             :         uint64_t tick_total;
+    4919             :         uint64_t tick_max;
+    4920             :         tommy_node* i;
+    4921             :         unsigned l;
+    4922             : 
+    4923          73 :         tick_max = 0;
+    4924          73 :         tick_total = 0;
+    4925         509 :         for (i = state->disklist; i != 0; i = i->next) {
+    4926         436 :                 struct snapraid_disk* disk = i->data;
+    4927         436 :                 tick_total += disk->tick;
+    4928         436 :                 if (disk->tick > tick_max)
+    4929          88 :                         tick_max = disk->tick;
+    4930             :         }
+    4931         501 :         for (l = 0; l < state->level; ++l) {
+    4932         428 :                 tick_total += state->parity[l].tick;
+    4933         428 :                 if (state->parity[l].tick > tick_max)
+    4934           5 :                         tick_max = state->parity[l].tick;
+    4935             :         }
+    4936             : 
+    4937          73 :         if (!tick_total)
+    4938          88 :                 return;
+    4939             : 
+    4940          58 :         if (msg_level >= MSG_PROGRESS) {
+    4941             :                 /* here we don't use msg_progress() because it doesn't allow partial output */
+    4942           1 :                 printf("Time for disk:");
+    4943           7 :                 for (i = state->disklist; i != 0; i = i->next) {
+    4944           6 :                         struct snapraid_disk* disk = i->data;
+    4945           6 :                         if (disk->tick == tick_max)
+    4946           1 :                                 printf(" %s:", disk->name);
+    4947             :                         else
+    4948           5 :                                 printf(" ");
+    4949           6 :                         printf("%" PRIu64 "%%", disk->tick * 100U / tick_total);
+    4950             :                 }
+    4951           1 :                 printf("\n");
+    4952             : 
+    4953           1 :                 printf("Time for parity:");
+    4954           7 :                 for (l = 0; l < state->level; ++l) {
+    4955           6 :                         if (state->parity[l].tick == tick_max)
+    4956           0 :                                 printf(" %s:", lev_config_name(l));
+    4957             :                         else
+    4958           6 :                                 printf(" ");
+    4959           6 :                         printf("%" PRIu64 "%%", state->parity[l].tick * 100U / tick_total);
+    4960             :                 }
+    4961           1 :                 printf("\n");
+    4962             :         }
+    4963             : }
+    4964             : 
+    4965           1 : void generate_configuration(const char* path)
+    4966             : {
+    4967             :         struct snapraid_state state;
+    4968             :         struct snapraid_content* content;
+    4969             :         unsigned i;
+    4970             :         tommy_node* j;
+    4971             : 
+    4972           1 :         state_init(&state);
+    4973             : 
+    4974             :         /* mark that we are without a configuration file */
+    4975           1 :         state.no_conf = 1;
+    4976             : 
+    4977             :         /* create the dummy content entry */
+    4978           1 :         content = content_alloc(path, -1);
+    4979             : 
+    4980             :         /* adds the content entry */
+    4981           1 :         tommy_list_insert_tail(&state.contentlist, &content->node, content);
+    4982             : 
+    4983             :         /* read the content file */
+    4984           1 :         state_read(&state);
+    4985             : 
+    4986             :         /* output a dummy configuration file */
+    4987           1 :         printf("# Configuration file generated from %s\n", path);
+    4988           1 :         printf("\n");
+    4989           1 :         printf("# Use this blocksize\n");
+    4990           1 :         printf("blocksize %u\n", state.block_size / 1024);
+    4991           1 :         printf("\n");
+    4992           7 :         for (i = 0; i < state.level; ++i) {
+    4993           6 :                 printf("# Set the correct path for the %s file\n", lev_name(i));
+    4994           6 :                 if (state.parity[i].uuid[0])
+    4995           6 :                         printf("# The file was in the disk with id '%s'\n", state.parity[i].uuid);
+    4996           6 :                 printf("%s ENTER_HERE_THE_PARITY_FILE\n", lev_config_name(i));
+    4997           6 :                 printf("\n");
+    4998             :         }
+    4999           1 :         printf("# Add any other content file\n");
+    5000           1 :         printf("content %s\n", path);
+    5001           1 :         printf("\n");
+    5002           7 :         for (j = state.maplist; j; j = j->next) {
+    5003           6 :                 struct snapraid_map* map = j->data;
+    5004             :                 struct snapraid_disk* disk;
+    5005           6 :                 printf("# Set the correct dir for disk '%s'\n", map->name);
+    5006           6 :                 if (map->uuid[0])
+    5007           6 :                         printf("# Disk '%s' is the one with id '%s'\n", map->name, map->uuid);
+    5008           6 :                 disk = find_disk(&state, map->name);
+    5009           6 :                 if (disk && disk->filelist) {
+    5010           6 :                         struct snapraid_file* file = disk->filelist->data;
+    5011           6 :                         if (file) {
+    5012           6 :                                 printf("# and containing: %s\n", file->sub);
+    5013             :                         }
+    5014             :                 }
+    5015           6 :                 printf("disk %s ENTER_HERE_THE_DIR\n", map->name);
+    5016           6 :                 printf("\n");
+    5017             :         }
+    5018             : 
+    5019           1 :         state_done(&state);
+    5020           1 : }
+    5021             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.h.func-sort-c.html b/cov/cmdline/state.h.func-sort-c.html new file mode 100644 index 00000000..2e0fa38c --- /dev/null +++ b/cov/cmdline/state.h.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/state.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_usage_cpu682853
state_usage_parity582974
state_usage_disk544351
state_usage_waste80
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.h.func.html b/cov/cmdline/state.h.func.html new file mode 100644 index 00000000..da1f3d9d --- /dev/null +++ b/cov/cmdline/state.h.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/state.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
state_usage_cpu682853
state_usage_disk544351
state_usage_parity582974
state_usage_waste80
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/state.h.gcov.html b/cov/cmdline/state.h.gcov.html new file mode 100644 index 00000000..3dfc9750 --- /dev/null +++ b/cov/cmdline/state.h.gcov.html @@ -0,0 +1,453 @@ + + + + + + + LCOV - lcov.info - cmdline/state.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - state.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #ifndef __STATE_H
+      19             : #define __STATE_H
+      20             : 
+      21             : #include "elem.h"
+      22             : 
+      23             : /****************************************************************************/
+      24             : /* parity level */
+      25             : 
+      26             : /**
+      27             :  * Max level of parity supported.
+      28             :  */
+      29             : #define LEV_MAX 6
+      30             : 
+      31             : /**
+      32             :  * Returns the parity name: Parity, 2-Parity, 3-Parity, 4-Parity, 5-Parity, 6-Parity.
+      33             :  */
+      34             : const char* lev_name(unsigned level);
+      35             : 
+      36             : /**
+      37             :  * Returns the parity name used in the config file: parity, 2-parity, 3-parity, 4-parity, 5-parity, 6-parity.
+      38             :  */
+      39             : const char* lev_config_name(unsigned level);
+      40             : 
+      41             : /****************************************************************************/
+      42             : /* state */
+      43             : 
+      44             : /**
+      45             :  * Units for disk space.
+      46             :  */
+      47             : #define MEGA (1000 * 1000)
+      48             : #define GIGA (1000 * 1000 * 1000)
+      49             : #define TERA (1000 * 1000 * 1000 * 1000LL)
+      50             : 
+      51             : /**
+      52             :  * File modes.
+      53             :  */
+      54             : #define MODE_SEQUENTIAL 1 /**< Open the file in sequential mode. */
+      55             : 
+      56             : /**
+      57             :  * Global variable to identify if Ctrl+C is pressed.
+      58             :  */
+      59             : extern volatile int global_interrupt;
+      60             : 
+      61             : #define SORT_PHYSICAL 1 /**< Sort by physical order. */
+      62             : #define SORT_INODE 2 /**< Sort by inode. */
+      63             : #define SORT_ALPHA 3 /**< Sort by alphabetic order. */
+      64             : #define SORT_DIR 4 /**< Sort by directory order. */
+      65             : 
+      66             : /**
+      67             :  * Options set only at startup.
+      68             :  * For all these options a value of 0 means nothing set, and to use the default.
+      69             :  */
+      70             : struct snapraid_option {
+      71             :         int gui; /**< Gui output. */
+      72             :         int auditonly; /**< In check, checks only the hash and not the parity. */
+      73             :         int badonly; /**< In fix, fixes only the blocks marked as bad. */
+      74             :         int syncedonly; /**< In fix, fixes only files that are synced. */
+      75             :         int prehash; /**< Enables the prehash mode for sync. */
+      76             :         unsigned io_error_limit; /**< Max number of input/output errors before aborting. */
+      77             :         int force_zero; /**< Forced dangerous operations of synching files now with zero size. */
+      78             :         int force_empty; /**< Forced dangerous operations of synching disks now empty. */
+      79             :         int force_uuid; /**< Forced dangerous operations of synching disks with uuid changed. */
+      80             :         int force_device; /**< Forced dangerous operations of using disks with save device id. */
+      81             :         int force_nocopy; /**< Force dangerous operations of synching files without using copy detection. */
+      82             :         int force_full; /**< Force a full sync when using an old content file. */
+      83             :         int expect_unrecoverable; /**< Expect presence of unrecoverable error in checking or fixing. */
+      84             :         int expect_recoverable; /**< Expect presence of recoverable error in checking. */
+      85             :         int skip_device; /**< Skip devices matching checks. */
+      86             :         int skip_sign; /**< Skip the sign check for content files. */
+      87             :         int skip_fallocate; /**< Skip the use of fallocate(). */
+      88             :         int skip_sequential; /**< Skip sequential hint. */
+      89             :         int skip_lock; /**< Skip the lock file protection. */
+      90             :         int skip_self; /**< Skip the self-test. */
+      91             :         int skip_content_check; /**< Relax some content file checks. */
+      92             :         int skip_parity_access; /**< Skip the parity access for commands that don't need it. */
+      93             :         int skip_disk_access; /**< Skip the data disk access for commands that don't need it. */
+      94             :         int kill_after_sync; /**< Kill the process after sync without saving the final state. */
+      95             :         int force_murmur3; /**< Force Murmur3 choice. */
+      96             :         int force_spooky2; /**< Force Spooky2 choice. */
+      97             :         int force_order; /**< Force sorting order. One of the SORT_* defines. */
+      98             :         unsigned force_scrub_at; /**< Force scrub for the specified number of blocks. */
+      99             :         int force_scrub_even; /**< Force scrub of all the even blocks. */
+     100             :         int force_content_write; /**< Force the update of the content file. */
+     101             :         int force_content_text; /**< Force the use of text version of content file. */
+     102             :         int force_scan_winfind; /**< Force the use of FindFirst/Next in Windows to list directories. */
+     103             :         int force_progress; /**< Force the use of the progress status. */
+     104             :         unsigned force_autosave_at; /**< Force autosave at the specified block. */
+     105             :         int fake_device; /**< Fake device data. */
+     106             :         int expected_missing; /**< If missing files are expected and should not be reported. */
+     107             : };
+     108             : 
+     109             : /**
+     110             :  * Number of measures of the operation progress.
+     111             :  */
+     112             : #define PROGRESS_MAX 100
+     113             : 
+     114             : struct snapraid_state {
+     115             :         struct snapraid_option opt; /**< Setup options. */
+     116             :         int filter_hidden; /**< Filter out hidden files. */
+     117             :         uint64_t autosave; /**< Autosave after the specified amount of data. 0 to disable. */
+     118             :         int need_write; /**< If the state is changed. */
+     119             :         int checked_read; /**< If the state was read and checked. */
+     120             :         uint32_t block_size; /**< Block size in bytes. */
+     121             :         unsigned raid_mode; /**< Raid mode to use. RAID_MODE_DEFAULT or RAID_MODE_ALTERNATE. */
+     122             :         int file_mode; /**< File access mode. Combination of MODE_* flags. */
+     123             :         struct snapraid_parity parity[LEV_MAX]; /**< Parity vector. */
+     124             :         char share[PATH_MAX]; /**< Path of the share tree. If !=0 pool links are created in a different way. */
+     125             :         char pool[PATH_MAX]; /**< Path of the pool tree. */
+     126             :         uint64_t pool_device; /**< Device identifier of the pool. */
+     127             :         unsigned char hashseed[HASH_SIZE]; /**< Hash seed. Just after a uint64 to provide a minimal alignment. */
+     128             :         unsigned char prevhashseed[HASH_SIZE]; /**< Previous hash seed. In case of rehash. */
+     129             :         char lockfile[PATH_MAX]; /**< Path of the lock file to use. */
+     130             :         unsigned level; /**< Number of parity levels. 1 for PAR1, 2 for PAR2. */
+     131             :         unsigned hash; /**< Hash kind used. */
+     132             :         unsigned prevhash; /**< Previous hash kind used.  In case of rehash. */
+     133             :         unsigned besthash; /**< Best hash suggested. */
+     134             :         const char* command; /**< Command running. */
+     135             :         tommy_list contentlist; /**< List of content files. */
+     136             :         tommy_list disklist; /**< List of all the disks. */
+     137             :         tommy_list maplist; /**< List of all the disk mappings. */
+     138             :         tommy_list filterlist; /**< List of inclusion/exclusion. */
+     139             :         tommy_list importlist; /**< List of import file. */
+     140             :         tommy_hashdyn importset; /**< Hashtable by hash of all the import blocks. */
+     141             :         tommy_hashdyn previmportset; /**< Hashtable by prevhash of all the import blocks. Valid only if we are in a rehash state. */
+     142             :         tommy_hashdyn searchset; /**< Hashtable by timestamp of all the search files. */
+     143             :         tommy_arrayblkof infoarr; /**< Block information array. */
+     144             : 
+     145             :         /**
+     146             :          * Cumulative time used for computations.
+     147             :          */
+     148             :         uint64_t tick_cpu;
+     149             : 
+     150             :         /**
+     151             :          * Cumulative time used for all io operations of disks.
+     152             :          */
+     153             :         uint64_t tick_io;
+     154             : 
+     155             :         /**
+     156             :          * Last time used for time measure.
+     157             :          */
+     158             :         uint64_t tick_last;
+     159             : 
+     160             :         int clear_past_hash; /**< Clear all the hash from CHG and DELETED blocks when reading the state from an incomplete sync. */
+     161             : 
+     162             :         time_t progress_whole_start; /**< Initial start of the whole process. */
+     163             :         time_t progress_interruption; /**< Time of the start of the progress interruption. */
+     164             :         time_t progress_wasted; /**< Time wasted in interruptions. */
+     165             : 
+     166             :         time_t progress_time[PROGRESS_MAX]; /**< Last times of progress. */
+     167             :         block_off_t progress_pos[PROGRESS_MAX]; /**< Last positions of progress. */
+     168             :         data_off_t progress_size[PROGRESS_MAX]; /**< Last sizes of progress. */
+     169             :         uint64_t progress_tick_cpu[PROGRESS_MAX]; /**< Last cpu ticks of progress. */
+     170             :         uint64_t progress_tick_total[PROGRESS_MAX]; /**< Last total ticks of progress. */
+     171             : 
+     172             :         int progress_ptr; /**< Pointer to the next position to fill. Rolling over. */
+     173             :         int progress_tick; /**< Number of measures done. */
+     174             : 
+     175             :         int no_conf; /**< Automatically add missing info. Used to load content without a configuration file. */
+     176             : };
+     177             : 
+     178             : /**
+     179             :  * Initializes the state.
+     180             :  */
+     181             : void state_init(struct snapraid_state* state);
+     182             : 
+     183             : /**
+     184             :  * Deinitializes the state.
+     185             :  */
+     186             : void state_done(struct snapraid_state* state);
+     187             : 
+     188             : /**
+     189             :  * Reads the configuration file.
+     190             :  */
+     191             : void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk);
+     192             : 
+     193             : /**
+     194             :  * Reads the state.
+     195             :  */
+     196             : void state_read(struct snapraid_state* state);
+     197             : 
+     198             : /**
+     199             :  * Writes the new state.
+     200             :  */
+     201             : void state_write(struct snapraid_state* state);
+     202             : 
+     203             : /**
+     204             :  * Diff all the disks.
+     205             :  */
+     206             : int state_diff(struct snapraid_state* state);
+     207             : 
+     208             : /**
+     209             :  * Scans all the disks to update the state.
+     210             :  */
+     211             : void state_scan(struct snapraid_state* state);
+     212             : 
+     213             : /**
+     214             :  * Sets the nanosecond timestamp of all files that have a zero value.
+     215             :  */
+     216             : void state_nano(struct snapraid_state* state);
+     217             : 
+     218             : /**
+     219             :  * Devices operations.
+     220             :  */
+     221             : void state_device(struct snapraid_state* state, int operation);
+     222             : 
+     223             : /**
+     224             :  * Syncs the parity data.
+     225             :  */
+     226             : int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount);
+     227             : 
+     228             : /**
+     229             :  * Checks (and fixes) all the files and parity data.
+     230             :  * \param fix If we have to fix, after checking.
+     231             :  */
+     232             : int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, block_off_t blockcount);
+     233             : 
+     234             : /**
+     235             :  * Dry the files.
+     236             :  */
+     237             : void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount);
+     238             : 
+     239             : /**
+     240             :  * Rehash the files.
+     241             :  */
+     242             : void state_rehash(struct snapraid_state* state);
+     243             : 
+     244             : /**
+     245             :  * Scrub the files.
+     246             :  */
+     247             : int state_scrub(struct snapraid_state* state, int percentage, int olderthan);
+     248             : 
+     249             : /**
+     250             :  * Print the status.
+     251             :  */
+     252             : int state_status(struct snapraid_state* state);
+     253             : 
+     254             : /**
+     255             :  * Finds duplicates.
+     256             :  */
+     257             : void state_dup(struct snapraid_state* state);
+     258             : 
+     259             : /**
+     260             :  * List content.
+     261             :  */
+     262             : void state_list(struct snapraid_state* state);
+     263             : 
+     264             : /**
+     265             :  * Creates pool tree.
+     266             :  */
+     267             : void state_pool(struct snapraid_state* state);
+     268             : 
+     269             : /**
+     270             :  * Refresh the free space info.
+     271             :  *
+     272             :  * Note that it requires disks access.
+     273             :  */
+     274             : void state_refresh(struct snapraid_state* state);
+     275             : 
+     276             : /**
+     277             :  * Filter files, symlinks and dirs.
+     278             :  * Apply an additional filter to the list currently loaded.
+     279             :  */
+     280             : void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tommy_list* filterlist_disk, int filter_missing, int filter_error);
+     281             : 
+     282             : /**
+     283             :  * Begins the progress visualization.
+     284             :  */
+     285             : int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, block_off_t countmax);
+     286             : 
+     287             : /**
+     288             :  * Ends the progress visualization.
+     289             :  */
+     290             : void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize);
+     291             : 
+     292             : /**
+     293             :  * Writes the progress.
+     294             :  */
+     295             : int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize);
+     296             : 
+     297             : /**
+     298             :  * Stop temporarely the progress.
+     299             :  */
+     300             : void state_progress_stop(struct snapraid_state* state);
+     301             : 
+     302             : /**
+     303             :  * Restart the progress.
+     304             :  */
+     305             : void state_progress_restart(struct snapraid_state* state);
+     306             : 
+     307             : /**
+     308             :  * Set the usage time as wasted one not counted.
+     309             :  */
+     310          80 : static inline void state_usage_waste(struct snapraid_state* state)
+     311             : {
+     312          80 :         uint64_t now = tick();
+     313             : 
+     314          80 :         state->tick_last = now;
+     315          80 : }
+     316             : 
+     317             : /**
+     318             :  * Set the usage time for CPU.
+     319             :  */
+     320      682853 : static inline void state_usage_cpu(struct snapraid_state* state)
+     321             : {
+     322      682853 :         uint64_t now = tick();
+     323      682853 :         uint64_t delta = now - state->tick_last;
+     324             : 
+     325             :         /* increment the time spent in computations */
+     326      682853 :         state->tick_cpu += delta;
+     327             : 
+     328      682853 :         state->tick_last = now;
+     329      682853 : }
+     330             : 
+     331             : /**
+     332             :  * Set the usage time for data disk.
+     333             :  */
+     334      544351 : static inline void state_usage_disk(struct snapraid_state* state, struct snapraid_disk* disk)
+     335             : {
+     336      544351 :         uint64_t now = tick();
+     337      544351 :         uint64_t delta = now - state->tick_last;
+     338             : 
+     339             :         /* increment the time spent in the data disk */
+     340      544351 :         disk->tick += delta;
+     341      544351 :         state->tick_io += delta;
+     342             : 
+     343      544351 :         state->tick_last = now;
+     344      544351 : }
+     345             : 
+     346             : /**
+     347             :  * Set the usage time for parity disk.
+     348             :  */
+     349      582974 : static inline void state_usage_parity(struct snapraid_state* state, unsigned level)
+     350             : {
+     351      582974 :         uint64_t now = tick();
+     352      582974 :         uint64_t delta = now - state->tick_last;
+     353             : 
+     354      582974 :         assert(level < LEV_MAX);
+     355             : 
+     356             :         /* increment the time spent in the parity disk */
+     357      582974 :         state->parity[level].tick += delta;
+     358      582974 :         state->tick_io += delta;
+     359             : 
+     360      582974 :         state->tick_last = now;
+     361      582974 : }
+     362             : 
+     363             : /**
+     364             :  * Prints the stats of the usage time.
+     365             :  */
+     366             : void state_usage_print(struct snapraid_state* state);
+     367             : 
+     368             : /****************************************************************************/
+     369             : /* misc */
+     370             : 
+     371             : /**
+     372             :  * Generate a dummy configuration file from a content file.
+     373             :  */
+     374             : void generate_configuration(const char* content);
+     375             : 
+     376             : #endif
+     377             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/status.c.func-sort-c.html b/cov/cmdline/status.c.func-sort-c.html new file mode 100644 index 00000000..1d9deb87 --- /dev/null +++ b/cov/cmdline/status.c.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - cmdline/status.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - status.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:24024996.4 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
perc62
day_ago24
state_status14
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/status.c.func.html b/cov/cmdline/status.c.func.html new file mode 100644 index 00000000..374099d5 --- /dev/null +++ b/cov/cmdline/status.c.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - cmdline/status.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - status.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:24024996.4 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
day_ago24
perc62
state_status14
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/status.c.gcov.html b/cov/cmdline/status.c.gcov.html new file mode 100644 index 00000000..57343bcf --- /dev/null +++ b/cov/cmdline/status.c.gcov.html @@ -0,0 +1,546 @@ + + + + + + + LCOV - lcov.info - cmdline/status.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - status.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:24024996.4 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : #include "raid/raid.h"
+      26             : 
+      27             : /****************************************************************************/
+      28             : /* status */
+      29             : 
+      30          24 : unsigned day_ago(time_t time, time_t now)
+      31             : {
+      32          24 :         return (now - time) / (24 * 3600);
+      33             : }
+      34             : 
+      35             : #define GRAPH_COLUMN 70
+      36             : #define GRAPH_ROW 15
+      37             : 
+      38          62 : static unsigned perc(uint64_t part, uint64_t total)
+      39             : {
+      40          62 :         if (!total)
+      41           6 :                 return 0;
+      42             : 
+      43          56 :         return (unsigned)(part * 100 / total);
+      44             : }
+      45             : 
+      46          14 : int state_status(struct snapraid_state* state)
+      47             : {
+      48             :         block_off_t blockmax;
+      49             :         block_off_t i;
+      50             :         snapraid_info* infomap;
+      51             :         time_t now;
+      52             :         block_off_t bad;
+      53             :         block_off_t bad_first;
+      54             :         block_off_t bad_last;
+      55             :         block_off_t rehash;
+      56             :         block_off_t count;
+      57             :         unsigned l;
+      58             :         unsigned dayoldest, daymedian, daynewest;
+      59             :         unsigned bar[GRAPH_COLUMN];
+      60             :         unsigned barpos;
+      61             :         unsigned barmax;
+      62             :         time_t oldest, newest, median;
+      63             :         unsigned x, y;
+      64             :         tommy_node* node_disk;
+      65             :         unsigned file_count;
+      66             :         unsigned file_fragmented;
+      67             :         unsigned extra_fragment;
+      68             :         uint64_t file_size;
+      69             :         uint64_t file_block_count;
+      70             :         uint64_t file_block_free;
+      71             :         block_off_t parity_block_free;
+      72             :         unsigned unsynced_blocks;
+      73             :         uint64_t all_wasted;
+      74             :         int free_not_zero;
+      75             : 
+      76             :         /* get the present time */
+      77          14 :         now = time(0);
+      78             : 
+      79             :         /* keep track if at least a free info is available */
+      80          14 :         free_not_zero = 0;
+      81             : 
+      82          14 :         blockmax = parity_allocated_size(state);
+      83             : 
+      84          14 :         log_tag("summary:block_size:%u\n", state->block_size);
+      85          14 :         log_tag("summary:parity_block_count:%u\n", blockmax);
+      86             : 
+      87             :         /* get the minimum parity free space */
+      88          14 :         parity_block_free = state->parity[0].free_blocks;
+      89          98 :         for (l = 0; l < state->level; ++l) {
+      90          84 :                 log_tag("summary:parity_block_total:%s:%u\n", lev_config_name(l), state->parity[l].total_blocks);
+      91          84 :                 log_tag("summary:parity_block_free:%s:%u\n", lev_config_name(l), state->parity[l].free_blocks);
+      92          84 :                 if (state->parity[l].free_blocks < parity_block_free)
+      93           4 :                         parity_block_free = state->parity[l].free_blocks;
+      94          84 :                 if (state->parity[l].free_blocks != 0)
+      95          58 :                         free_not_zero = 1;
+      96             :         }
+      97          14 :         log_tag("summary:parity_block_free_min:%u\n", parity_block_free);
+      98             : 
+      99          14 :         printf("SnapRAID status report:\n");
+     100          14 :         printf("\n");
+     101          14 :         printf("   Files Fragmented Excess  Wasted  Used    Free  Use Name\n");
+     102          14 :         printf("            Files  Fragments  GB      GB      GB\n");
+     103             : 
+     104             :         /* count fragments */
+     105          14 :         file_count = 0;
+     106          14 :         file_size = 0;
+     107          14 :         file_block_count = 0;
+     108          14 :         file_block_free = 0;
+     109          14 :         file_fragmented = 0;
+     110          14 :         extra_fragment = 0;
+     111          14 :         all_wasted = 0;
+     112          98 :         for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
+     113          84 :                 struct snapraid_disk* disk = node_disk->data;
+     114             :                 tommy_node* node;
+     115             :                 block_off_t i;
+     116          84 :                 unsigned disk_file_count = 0;
+     117          84 :                 unsigned disk_file_fragmented = 0;
+     118          84 :                 unsigned disk_extra_fragment = 0;
+     119          84 :                 block_off_t disk_block_count = 0;
+     120          84 :                 uint64_t disk_file_size = 0;
+     121          84 :                 block_off_t disk_block_latest_used = 0;
+     122             :                 block_off_t disk_block_max_by_space;
+     123             :                 block_off_t disk_block_max_by_parity;
+     124             :                 block_off_t disk_block_max;
+     125             :                 int64_t wasted;
+     126             : 
+     127             :                 /* for each file in the disk */
+     128          84 :                 node = disk->filelist;
+     129       95610 :                 while (node) {
+     130             :                         struct snapraid_file* file;
+     131             : 
+     132       95442 :                         file = node->data;
+     133       95442 :                         node = node->next; /* next node */
+     134             : 
+     135             :                         /* check fragmentation */
+     136       95442 :                         if (file->blockmax != 0) {
+     137             :                                 block_off_t prev_pos;
+     138             :                                 int fragmented;
+     139             : 
+     140       95312 :                                 fragmented = 0;
+     141       95312 :                                 prev_pos = file->blockvec[0].parity_pos;
+     142      235007 :                                 for (i = 1; i < file->blockmax; ++i) {
+     143      139695 :                                         block_off_t parity_pos = file->blockvec[i].parity_pos;
+     144      139695 :                                         if (prev_pos + 1 != parity_pos) {
+     145         698 :                                                 fragmented = 1;
+     146         698 :                                                 ++extra_fragment;
+     147         698 :                                                 ++disk_extra_fragment;
+     148             :                                         }
+     149      139695 :                                         prev_pos = parity_pos;
+     150             :                                 }
+     151             : 
+     152             :                                 /* keep track of latest block used */
+     153       95312 :                                 if (file->blockvec[file->blockmax - 1].parity_pos > disk_block_latest_used) {
+     154       92455 :                                         disk_block_latest_used = file->blockvec[file->blockmax - 1].parity_pos;
+     155             :                                 }
+     156             : 
+     157       95312 :                                 if (fragmented) {
+     158         582 :                                         ++file_fragmented;
+     159         582 :                                         ++disk_file_fragmented;
+     160             :                                 }
+     161             : 
+     162       95312 :                                 disk_block_count += file->blockmax;
+     163             :                         }
+     164             : 
+     165             :                         /* count files */
+     166       95442 :                         ++file_count;
+     167       95442 :                         ++disk_file_count;
+     168       95442 :                         file_size += file->size;
+     169       95442 :                         file_block_count += file->blockmax;
+     170       95442 :                         disk_file_size += file->size;
+     171             :                 }
+     172             : 
+     173          84 :                 if (disk->free_blocks != 0)
+     174          48 :                         free_not_zero = 1;
+     175             : 
+     176             :                 /* get the free block info */
+     177          84 :                 disk_block_max_by_space = disk_block_count + disk->free_blocks;
+     178          84 :                 disk_block_max_by_parity = blockmax + parity_block_free;
+     179             : 
+     180             :                 /* the maximum usable space in a disk is limited by the smallest */
+     181             :                 /* of the disk size and the parity size */
+     182             :                 /* the wasted space is the space that we have to leave */
+     183             :                 /* free on the data disk, when the parity is filled up */
+     184          84 :                 if (disk_block_max_by_space < disk_block_max_by_parity) {
+     185          50 :                         disk_block_max = disk_block_max_by_space;
+     186             :                 } else {
+     187          34 :                         disk_block_max = disk_block_max_by_parity;
+     188             :                 }
+     189             : 
+     190             :                 /* wasted space is the difference of the two maximum size */
+     191             :                 /* if negative, it's extra space available in parity */
+     192          84 :                 wasted = (int64_t)disk_block_max_by_space - (int64_t)disk_block_max_by_parity;
+     193          84 :                 wasted *= state->block_size;
+     194             : 
+     195          84 :                 if (wasted > 0)
+     196          24 :                         all_wasted += wasted;
+     197          84 :                 file_block_free += disk_block_max - disk_block_count;
+     198             : 
+     199          84 :                 printf("%8u", disk_file_count);
+     200          84 :                 printf("%8u", disk_file_fragmented);
+     201          84 :                 printf("%8u", disk_extra_fragment);
+     202          84 :                 if (wasted < -100LL * GIGA) {
+     203          30 :                         printf("       -");
+     204             :                 } else {
+     205          54 :                         printf("%8.1f", (double)wasted / GIGA);
+     206             :                 }
+     207          84 :                 printf("%8" PRIu64, disk_file_size / GIGA);
+     208             : 
+     209          84 :                 if (disk_block_max == 0 && disk_block_count == 0) {
+     210             :                         /* if the disk is empty and we don't have the free space info */
+     211          36 :                         printf("       -");
+     212          36 :                         printf("   - ");
+     213             :                 } else {
+     214          48 :                         printf("%8" PRIu64, (disk_block_max - disk_block_count) * (uint64_t)state->block_size / GIGA);
+     215          48 :                         printf(" %3u%%", perc(disk_block_count, disk_block_max));
+     216             :                 }
+     217          84 :                 printf(" %s\n", disk->name);
+     218             : 
+     219          84 :                 log_tag("summary:disk_file_count:%s:%u\n", disk->name, disk_file_count);
+     220          84 :                 log_tag("summary:disk_block_count:%s:%u\n", disk->name, disk_block_count);
+     221          84 :                 log_tag("summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented);
+     222          84 :                 log_tag("summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment);
+     223          84 :                 log_tag("summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size);
+     224          84 :                 log_tag("summary:disk_block_allocated:%s:%u\n", disk->name, disk_block_latest_used + 1);
+     225          84 :                 log_tag("summary:disk_block_total:%s:%u\n", disk->name, disk->total_blocks);
+     226          84 :                 log_tag("summary:disk_block_free:%s:%u\n", disk->name, disk->free_blocks);
+     227          84 :                 log_tag("summary:disk_block_max_by_space:%s:%u\n", disk->name, disk_block_max_by_space);
+     228          84 :                 log_tag("summary:disk_block_max_by_parity:%s:%u\n", disk->name, disk_block_max_by_parity);
+     229          84 :                 log_tag("summary:disk_block_max:%s:%u\n", disk->name, disk_block_max);
+     230          84 :                 log_tag("summary:disk_space_wasted:%s:%" PRId64 "\n", disk->name, wasted);
+     231             :         }
+     232             : 
+     233             :         /* totals */
+     234          14 :         printf(" --------------------------------------------------------------------------\n");
+     235          14 :         printf("%8u", file_count);
+     236          14 :         printf("%8u", file_fragmented);
+     237          14 :         printf("%8u", extra_fragment);
+     238          14 :         printf("%8.1f", (double)all_wasted / GIGA);
+     239          14 :         printf("%8" PRIu64, file_size / GIGA);
+     240          14 :         printf("%8" PRIu64, file_block_free * state->block_size / GIGA);
+     241          14 :         printf(" %3u%%", perc(file_block_count, file_block_count + file_block_free));
+     242          14 :         printf("\n");
+     243             : 
+     244             :         /* warn about invalid data free info */
+     245          14 :         if (!free_not_zero)
+     246           1 :                 printf("\nWARNING! Free space info will be valid after the first sync.\n");
+     247             : 
+     248          14 :         log_tag("summary:file_count:%u\n", file_count);
+     249          14 :         log_tag("summary:file_block_count:%" PRIu64 "\n", file_block_count);
+     250          14 :         log_tag("summary:fragmented_file_count:%u\n", file_fragmented);
+     251          14 :         log_tag("summary:excess_fragment_count:%u\n", extra_fragment);
+     252          14 :         log_tag("summary:file_size:%" PRIu64 "\n", file_size);
+     253          14 :         log_tag("summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size);
+     254          14 :         log_tag("summary:parity_size_max:%" PRIu64 "\n", (blockmax + parity_block_free) * (uint64_t)state->block_size);
+     255          14 :         log_tag("summary:hash:%s\n", hash_config_name(state->hash));
+     256          14 :         log_tag("summary:prev_hash:%s\n", hash_config_name(state->prevhash));
+     257          14 :         log_tag("summary:best_hash:%s\n", hash_config_name(state->besthash));
+     258          14 :         log_flush();
+     259             : 
+     260             :         /* copy the info a temp vector, and count bad/rehash/unsynced blocks */
+     261          14 :         infomap = malloc_nofail(blockmax * sizeof(snapraid_info));
+     262          14 :         bad = 0;
+     263          14 :         bad_first = 0;
+     264          14 :         bad_last = 0;
+     265          14 :         count = 0;
+     266          14 :         rehash = 0;
+     267          14 :         unsynced_blocks = 0;
+     268          14 :         log_tag("block_count:%u\n", blockmax);
+     269       39620 :         for (i = 0; i < blockmax; ++i) {
+     270             :                 int one_invalid;
+     271             :                 int one_valid;
+     272             : 
+     273       39606 :                 snapraid_info info = info_get(&state->infoarr, i);
+     274             : 
+     275             :                 /* for each disk */
+     276       39606 :                 one_invalid = 0;
+     277       39606 :                 one_valid = 0;
+     278      277242 :                 for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
+     279      237636 :                         struct snapraid_disk* disk = node_disk->data;
+     280      237636 :                         struct snapraid_block* block = disk_block_get(disk, i);
+     281             : 
+     282      237636 :                         if (block_has_file(block))
+     283      235007 :                                 one_valid = 1;
+     284      237636 :                         if (block_has_invalid_parity(block))
+     285           0 :                                 one_invalid = 1;
+     286             :                 }
+     287             : 
+     288             :                 /* if both valid and invalid, we need to update */
+     289       39606 :                 if (one_invalid && one_valid) {
+     290           0 :                         ++unsynced_blocks;
+     291             :                 }
+     292             : 
+     293             :                 /* skip unused blocks */
+     294       39606 :                 if (info != 0) {
+     295       39606 :                         if (info_get_bad(info)) {
+     296        1803 :                                 if (bad == 0)
+     297           2 :                                         bad_first = i;
+     298        1803 :                                 bad_last = i;
+     299        1803 :                                 ++bad;
+     300             :                         }
+     301             : 
+     302       39606 :                         if (info_get_rehash(info))
+     303        4599 :                                 ++rehash;
+     304             : 
+     305       39606 :                         infomap[count++] = info;
+     306             :                 }
+     307             : 
+     308       39606 :                 if (state->opt.gui) {
+     309           0 :                         if (info != 0)
+     310           0 :                                 log_tag("block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : "");
+     311             :                         else
+     312           0 :                                 log_tag("block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : "");
+     313             :                 }
+     314             :         }
+     315             : 
+     316          14 :         log_tag("summary:has_unsynced:%u\n", unsynced_blocks);
+     317          14 :         log_tag("summary:has_rehash:%u\n", rehash);
+     318          14 :         log_tag("summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last);
+     319          14 :         log_flush();
+     320             : 
+     321          14 :         if (!count) {
+     322           6 :                 log_fatal("The array is empty.\n");
+     323           6 :                 free(infomap);
+     324           6 :                 return 0;
+     325             :         }
+     326             : 
+     327             :         /* sort the info to get the time info */
+     328           8 :         qsort(infomap, count, sizeof(snapraid_info), info_time_compare);
+     329             : 
+     330             :         /* output the info map */
+     331           8 :         i = 0;
+     332           8 :         log_tag("info_count:%u\n", count);
+     333          37 :         while (i < count) {
+     334          21 :                 unsigned j = i + 1;
+     335       39627 :                 while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j]))
+     336       39585 :                         ++j;
+     337          21 :                 log_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i);
+     338          21 :                 i = j;
+     339             :         }
+     340             : 
+     341           8 :         oldest = info_get_time(infomap[0]);
+     342           8 :         median = info_get_time(infomap[count / 2]);
+     343           8 :         newest = info_get_time(infomap[count - 1]);
+     344           8 :         dayoldest = day_ago(oldest, now);
+     345           8 :         daymedian = day_ago(median, now);
+     346           8 :         daynewest = day_ago(newest, now);
+     347             : 
+     348             :         /* compute graph limits */
+     349           8 :         barpos = 0;
+     350           8 :         barmax = 0;
+     351         568 :         for (i = 0; i < GRAPH_COLUMN; ++i) {
+     352             :                 time_t limit;
+     353             :                 unsigned step;
+     354             : 
+     355         560 :                 limit = oldest + (newest - oldest) * (i + 1) / GRAPH_COLUMN;
+     356             : 
+     357         560 :                 step = 0;
+     358       40726 :                 while (barpos < count && info_get_time(infomap[barpos]) <= limit) {
+     359       39606 :                         ++barpos;
+     360       39606 :                         ++step;
+     361             :                 }
+     362             : 
+     363         560 :                 if (step > barmax)
+     364          13 :                         barmax = step;
+     365             : 
+     366         560 :                 bar[i] = step;
+     367             :         }
+     368             : 
+     369           8 :         printf("\n\n");
+     370             : 
+     371             :         /* print the graph */
+     372         128 :         for (y = 0; y < GRAPH_ROW; ++y) {
+     373         120 :                 if (y == 0)
+     374           8 :                         printf("%3u%%|", barmax * 100 / count);
+     375         112 :                 else if (y == GRAPH_ROW - 1)
+     376           8 :                         printf("  0%%|");
+     377         104 :                 else if (y == GRAPH_ROW / 2)
+     378           8 :                         printf("%3u%%|", barmax * 50 / count);
+     379             :                 else
+     380          96 :                         printf("    |");
+     381        8520 :                 for (x = 0; x < GRAPH_COLUMN; ++x) {
+     382        8400 :                         unsigned pivot = barmax * (GRAPH_ROW - y) / GRAPH_ROW;
+     383             :                         /* if it's the baseline */
+     384        8400 :                         if (y == GRAPH_ROW - 1) {
+     385         560 :                                 if (bar[x] >= pivot) {
+     386          18 :                                         printf("*");
+     387         542 :                                 } else if (bar[x] > 0) {
+     388           3 :                                         printf("+");
+     389             :                                 } else {
+     390         539 :                                         printf("_");
+     391             :                                 }
+     392             :                         } else {
+     393        7840 :                                 unsigned halfpivot = pivot - barmax / GRAPH_ROW / 2;
+     394        7840 :                                 if (bar[x] >= pivot) {
+     395         154 :                                         printf("*");
+     396        7686 :                                 } else if (bar[x] >= halfpivot) {
+     397           8 :                                         printf("+");
+     398             :                                 } else {
+     399        7678 :                                         printf(" ");
+     400             :                                 }
+     401             :                         }
+     402             :                 }
+     403         120 :                 printf("\n");
+     404             :         }
+     405           8 :         printf("   %3u                    days ago of the last scrub                    %3u\n", dayoldest, daynewest);
+     406             : 
+     407           8 :         printf("\n");
+     408             : 
+     409           8 :         printf("The oldest block was scrubbed %u days ago, the median %u, the newest %u.\n", dayoldest, daymedian, daynewest);
+     410             : 
+     411           8 :         printf("\n");
+     412             : 
+     413           8 :         if (unsynced_blocks) {
+     414           0 :                 printf("WARNING! The array is NOT fully synced.\n");
+     415           0 :                 printf("You have a sync in progress at %u%%.\n", (blockmax - unsynced_blocks) * 100 / blockmax);
+     416             :         } else {
+     417           8 :                 printf("No sync is in progress.\n");
+     418             :         }
+     419             : 
+     420           8 :         if (rehash) {
+     421           1 :                 printf("You have a rehash in progress at %u%%.\n", (count - rehash) * 100 / count);
+     422             :         } else {
+     423           7 :                 if (state->besthash != state->hash) {
+     424           0 :                         printf("No rehash is in progress, but for optimal performance one is recommended.\n");
+     425             :                 } else {
+     426           7 :                         printf("No rehash is in progress or needed.\n");
+     427             :                 }
+     428             :         }
+     429             : 
+     430           8 :         if (bad) {
+     431             :                 block_off_t bad_print;
+     432             : 
+     433           2 :                 printf("DANGER! In the array there are %u errors!\n\n", bad);
+     434             : 
+     435           2 :                 printf("They are from block %u to %u, specifically at blocks:", bad_first, bad_last);
+     436             : 
+     437             :                 /* print some of the errors */
+     438           2 :                 bad_print = 0;
+     439         610 :                 for (i = 0; i < blockmax; ++i) {
+     440         610 :                         snapraid_info info = info_get(&state->infoarr, i);
+     441             : 
+     442             :                         /* skip unused blocks */
+     443         610 :                         if (info == 0)
+     444           0 :                                 continue;
+     445             : 
+     446         610 :                         if (info_get_bad(info)) {
+     447         202 :                                 printf(" %u", i);
+     448         202 :                                 ++bad_print;
+     449             :                         }
+     450             : 
+     451         610 :                         if (bad_print > 100) {
+     452           2 :                                 printf(" and %u more...", bad - bad_print);
+     453           2 :                                 break;
+     454             :                         }
+     455             :                 }
+     456             : 
+     457           2 :                 printf("\n\n");
+     458             : 
+     459           2 :                 printf("To fix them use the command 'snapraid -e fix'.\n");
+     460           2 :                 printf("The errors will disapper from the 'status' at the next 'scrub' command.\n");
+     461             :         } else {
+     462           6 :                 printf("No error detected.\n");
+     463             :         }
+     464             : 
+     465             :         /* free the temp vector */
+     466           8 :         free(infomap);
+     467             : 
+     468           8 :         return 0;
+     469             : }
+     470             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.c.func-sort-c.html b/cov/cmdline/stream.c.func-sort-c.html new file mode 100644 index 00000000..b48386e0 --- /dev/null +++ b/cov/cmdline/stream.c.func-sort-c.html @@ -0,0 +1,196 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:32633298.2 %
Date:2015-05-12Functions:3131100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
swrite20736098
sgetb3218305317
sread12063841
sgetb6410229372
sputb328983972
sputb644887004
sgetbs3648313
sputbs1739788
sgettok472066
sputu32415233
sgetu32396702
sputu64298899
sfill298684
sgetu64282276
sputhex245610
sgethex232385
sputs208981
sgetline104980
sflush39066
sgetlasttok4785
sopen_multi_file953
sclose722
sopen_read637
scrc478
sgetble32346
shandle224
sopen_multi_write136
scrc_stream131
sputble32131
ssync120
stell1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.c.func.html b/cov/cmdline/stream.c.func.html new file mode 100644 index 00000000..d2afc3aa --- /dev/null +++ b/cov/cmdline/stream.c.func.html @@ -0,0 +1,196 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:32633298.2 %
Date:2015-05-12Functions:3131100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
sclose722
scrc478
scrc_stream131
sfill298684
sflush39066
sgetb3218305317
sgetb6410229372
sgetble32346
sgetbs3648313
sgethex232385
sgetlasttok4785
sgetline104980
sgettok472066
sgetu32396702
sgetu64282276
shandle224
sopen_multi_file953
sopen_multi_write136
sopen_read637
sputb328983972
sputb644887004
sputble32131
sputbs1739788
sputhex245610
sputs208981
sputu32415233
sputu64298899
sread12063841
ssync120
stell1
swrite20736098
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.c.gcov.html b/cov/cmdline/stream.c.gcov.html new file mode 100644 index 00000000..6c421411 --- /dev/null +++ b/cov/cmdline/stream.c.gcov.html @@ -0,0 +1,975 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:32633298.2 %
Date:2015-05-12Functions:3131100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "util.h"
+      22             : #include "stream.h"
+      23             : 
+      24             : /****************************************************************************/
+      25             : /* hex conversion table */
+      26             : 
+      27             : static char strhexset[16] = "0123456789abcdef";
+      28             : 
+      29             : static unsigned strdecset[256] =
+      30             : {
+      31             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      32             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      33             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      34             :         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
+      35             :         -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      36             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      37             :         -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      38             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      39             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      40             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      41             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      42             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      43             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      44             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      45             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      46             :         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+      47             : };
+      48             : 
+      49             : /****************************************************************************/
+      50             : /* stream */
+      51             : 
+      52             : unsigned STREAM_SIZE = 1024 * 64;
+      53             : 
+      54         637 : STREAM* sopen_read(const char* file)
+      55             : {
+      56             : #if HAVE_POSIX_FADVISE
+      57             :         int ret;
+      58             : #endif
+      59         637 :         STREAM* s = malloc_nofail(sizeof(STREAM));
+      60             : 
+      61         637 :         s->handle_size = 1;
+      62         637 :         s->handle = malloc_nofail(sizeof(struct stream_handle));
+      63             : 
+      64         637 :         pathcpy(s->handle[0].path, sizeof(s->handle[0].path), file);
+      65         637 :         s->handle[0].f = open(file, O_RDONLY | O_BINARY | O_SEQUENTIAL);
+      66         637 :         if (s->handle[0].f == -1) {
+      67          50 :                 free(s->handle);
+      68          50 :                 free(s);
+      69          50 :                 return 0;
+      70             :         }
+      71             : 
+      72             : #if HAVE_POSIX_FADVISE
+      73             :         /* advise sequential access */
+      74         587 :         ret = posix_fadvise(s->handle[0].f, 0, 0, POSIX_FADV_SEQUENTIAL);
+      75         587 :         if (ret != 0) {
+      76             :                 /* LCOV_EXCL_START */
+      77             :                 close(s->handle[0].f);
+      78             :                 free(s->handle);
+      79             :                 free(s);
+      80             :                 return 0;
+      81             :                 /* LCOV_EXCL_STOP */
+      82             :         }
+      83             : #endif
+      84             : 
+      85         587 :         s->buffer = malloc_nofail_test(STREAM_SIZE);
+      86         587 :         s->pos = s->buffer;
+      87         587 :         s->end = s->buffer;
+      88         587 :         s->state = STREAM_STATE_READ;
+      89         587 :         s->state_index = 0;
+      90         587 :         s->offset = 0;
+      91         587 :         s->offset_uncached = 0;
+      92         587 :         s->crc = 0;
+      93         587 :         s->crc_uncached = 0;
+      94         587 :         s->crc_stream = CRC_IV;
+      95             : 
+      96         587 :         return s;
+      97             : }
+      98             : 
+      99         136 : STREAM* sopen_multi_write(unsigned count)
+     100             : {
+     101             :         unsigned i;
+     102             : 
+     103         136 :         STREAM* s = malloc_nofail(sizeof(STREAM));
+     104             : 
+     105         136 :         s->handle_size = count;
+     106         136 :         s->handle = malloc_nofail(count * sizeof(struct stream_handle));
+     107             : 
+     108        1089 :         for (i = 0; i < count; ++i)
+     109         953 :                 s->handle[i].f = -1;
+     110             : 
+     111         136 :         s->buffer = malloc_nofail_test(STREAM_SIZE);
+     112         136 :         s->pos = s->buffer;
+     113         136 :         s->end = s->buffer + STREAM_SIZE;
+     114         136 :         s->state = STREAM_STATE_WRITE;
+     115         136 :         s->state_index = 0;
+     116         136 :         s->offset = 0;
+     117         136 :         s->offset_uncached = 0;
+     118         136 :         s->crc = 0;
+     119         136 :         s->crc_uncached = 0;
+     120         136 :         s->crc_stream = CRC_IV;
+     121             : 
+     122         136 :         return s;
+     123             : }
+     124             : 
+     125         953 : int sopen_multi_file(STREAM* s, unsigned i, const char* file)
+     126             : {
+     127             : #if HAVE_POSIX_FADVISE
+     128             :         int ret;
+     129             : #endif
+     130             :         int f;
+     131             : 
+     132         953 :         pathcpy(s->handle[i].path, sizeof(s->handle[i].path), file);
+     133             : 
+     134         953 :         f = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_SEQUENTIAL, 0600);
+     135         953 :         if (f == -1) {
+     136             :                 /* LCOV_EXCL_START */
+     137             :                 return -1;
+     138             :                 /* LCOV_EXCL_STOP */
+     139             :         }
+     140             : 
+     141             : #if HAVE_POSIX_FADVISE
+     142             :         /* advise sequential access */
+     143         953 :         ret = posix_fadvise(f, 0, 0, POSIX_FADV_SEQUENTIAL);
+     144         953 :         if (ret != 0) {
+     145             :                 /* LCOV_EXCL_START */
+     146             :                 close(f);
+     147             :                 return -1;
+     148             :                 /* LCOV_EXCL_STOP */
+     149             :         }
+     150             : #endif
+     151             : 
+     152         953 :         s->handle[i].f = f;
+     153             : 
+     154         953 :         return 0;
+     155             : }
+     156             : 
+     157         722 : int sclose(STREAM* s)
+     158             : {
+     159         722 :         int fail = 0;
+     160             :         unsigned i;
+     161             : 
+     162         722 :         if (s->state == STREAM_STATE_WRITE) {
+     163         136 :                 if (sflush(s) != 0) {
+     164             :                         /* LCOV_EXCL_START */
+     165             :                         fail = 1;
+     166             :                         /* LCOV_EXCL_STOP */
+     167             :                 }
+     168             :         }
+     169             : 
+     170        2261 :         for (i = 0; i < s->handle_size; ++i) {
+     171        1539 :                 if (close(s->handle[i].f) != 0) {
+     172             :                         /* LCOV_EXCL_START */
+     173             :                         fail = 1;
+     174             :                         /* LCOV_EXCL_STOP */
+     175             :                 }
+     176             :         }
+     177             : 
+     178         722 :         free(s->handle);
+     179         722 :         free(s->buffer);
+     180         722 :         free(s);
+     181             : 
+     182         722 :         if (fail) {
+     183             :                 /* LCOV_EXCL_START */
+     184             :                 return -1;
+     185             :                 /* LCOV_EXCL_STOP */
+     186             :         }
+     187             : 
+     188         722 :         return 0;
+     189             : }
+     190             : 
+     191         224 : int shandle(STREAM* s)
+     192             : {
+     193         224 :         if (!s->handle_size) {
+     194             :                 /* LCOV_EXCL_START */
+     195             :                 return -1;
+     196             :                 /* LCOV_EXCL_STOP */
+     197             :         }
+     198             : 
+     199         224 :         return s->handle[0].f;
+     200             : }
+     201             : 
+     202      298684 : int sfill(STREAM* s)
+     203             : {
+     204             :         ssize_t ret;
+     205             : 
+     206      298684 :         if (s->state != STREAM_STATE_READ) {
+     207             :                 /* LCOV_EXCL_START */
+     208             :                 return EOF;
+     209             :                 /* LCOV_EXCL_STOP */
+     210             :         }
+     211             : 
+     212      297729 :         ret = read(s->handle[0].f, s->buffer, STREAM_SIZE);
+     213             : 
+     214      297729 :         if (ret < 0) {
+     215             :                 /* LCOV_EXCL_START */
+     216             :                 s->state = STREAM_STATE_ERROR;
+     217             :                 return EOF;
+     218             :                 /* LCOV_EXCL_STOP */
+     219             :         }
+     220      297729 :         if (ret == 0) {
+     221         459 :                 s->state = STREAM_STATE_EOF;
+     222         459 :                 return EOF;
+     223             :         }
+     224             : 
+     225             :         /* update the crc */
+     226      297270 :         s->crc_uncached = s->crc;
+     227      297270 :         s->crc = crc32c(s->crc, s->buffer, ret);
+     228             : 
+     229             :         /* update the offset */
+     230      297270 :         s->offset_uncached = s->offset;
+     231      297270 :         s->offset += ret;
+     232             : 
+     233      297270 :         s->pos = s->buffer;
+     234      297270 :         s->end = s->buffer + ret;
+     235             : 
+     236      297270 :         return *s->pos++;
+     237             : }
+     238             : 
+     239       39066 : int sflush(STREAM* s)
+     240             : {
+     241             :         ssize_t ret;
+     242             :         ssize_t size;
+     243             :         unsigned i;
+     244             : 
+     245       39066 :         if (s->state != STREAM_STATE_WRITE) {
+     246             :                 /* LCOV_EXCL_START */
+     247             :                 return EOF;
+     248             :                 /* LCOV_EXCL_STOP */
+     249             :         }
+     250             : 
+     251       39066 :         size = s->pos - s->buffer;
+     252       39066 :         if (!size)
+     253         120 :                 return 0;
+     254             : 
+     255             :         /* update the crc */
+     256       38946 :         s->crc = crc32c(s->crc, s->buffer, size);
+     257       38946 :         s->crc_uncached = s->crc;
+     258             : 
+     259      347852 :         for (i = 0; i < s->handle_size; ++i) {
+     260      308906 :                 ret = write(s->handle[i].f, s->buffer, size);
+     261             : 
+     262      308906 :                 if (ret != size) {
+     263             :                         /* LCOV_EXCL_START */
+     264             :                         s->state = STREAM_STATE_ERROR;
+     265             :                         s->state_index = i;
+     266             :                         return EOF;
+     267             :                         /* LCOV_EXCL_STOP */
+     268             :                 }
+     269             :         }
+     270             : 
+     271             :         /* update the offset */
+     272       38946 :         s->offset += size;
+     273       38946 :         s->offset_uncached = s->offset;
+     274             : 
+     275       38946 :         s->pos = s->buffer;
+     276             : 
+     277       38946 :         return 0;
+     278             : }
+     279             : 
+     280           1 : int64_t stell(STREAM* s)
+     281             : {
+     282           1 :         return s->offset_uncached + (s->pos - s->buffer);
+     283             : }
+     284             : 
+     285         478 : uint32_t scrc(STREAM*s)
+     286             : {
+     287         478 :         return crc32c(s->crc_uncached, s->buffer, s->pos - s->buffer);
+     288             : }
+     289             : 
+     290         131 : uint32_t scrc_stream(STREAM*s)
+     291             : {
+     292         131 :         return s->crc_stream ^ CRC_IV;
+     293             : }
+     294             : 
+     295      472066 : int sgettok(STREAM* f, char* str, int size)
+     296             : {
+     297      472066 :         char* i = str;
+     298      472066 :         char* send = str + size;
+     299             :         int c;
+     300             : 
+     301             :         while (1) {
+     302     2207452 :                 c = sgetc(f);
+     303     2207452 :                 if (c == EOF) {
+     304         240 :                         break;
+     305             :                 }
+     306     2207212 :                 if (c == ' ' || c == '\t') {
+     307      471501 :                         sungetc(c, f);
+     308      471501 :                         break;
+     309             :                 }
+     310     1735711 :                 if (c == '\n') {
+     311             :                         /* remove ending carrige return to support the Windows CR+LF format */
+     312         325 :                         if (i != str && i[-1] == '\r')
+     313           0 :                                 --i;
+     314         325 :                         sungetc(c, f);
+     315         325 :                         break;
+     316             :                 }
+     317             : 
+     318     1735386 :                 *i++ = c;
+     319             : 
+     320     1735386 :                 if (i == send) {
+     321             :                         /* LCOV_EXCL_START */
+     322             :                         return -1;
+     323             :                         /* LCOV_EXCL_STOP */
+     324             :                 }
+     325     1735386 :         }
+     326             : 
+     327      472066 :         *i = 0;
+     328             : 
+     329      472066 :         return i - str;
+     330             : }
+     331             : 
+     332    12063841 : int sread(STREAM* f, void* void_data, unsigned size)
+     333             : {
+     334    12063841 :         unsigned char* data = void_data;
+     335             : 
+     336             :         /* if there is enough space in memory */
+     337    12063841 :         if (sptrlookup(f, size)) {
+     338             :                 /* optimized version with all the data in memory */
+     339    12037955 :                 unsigned char* pos = sptrget(f);
+     340             : 
+     341             :                 /* copy it */
+     342   204965594 :                 while (size--)
+     343   180889684 :                         *data++ = *pos++;
+     344             : 
+     345    12037955 :                 sptrset(f, pos);
+     346             :         } else {
+     347             :                 /* standard version using sgetc() */
+     348     1370910 :                 while (size--) {
+     349     1319138 :                         int c = sgetc(f);
+     350     1319138 :                         if (c == EOF) {
+     351             :                                 /* LCOV_EXCL_START */
+     352             :                                 return -1;
+     353             :                                 /* LCOV_EXCL_STOP */
+     354             :                         }
+     355             : 
+     356     1319138 :                         *data++ = c;
+     357             :                 }
+     358             :         }
+     359             : 
+     360    12063841 :         return 0;
+     361             : }
+     362             : 
+     363      104980 : int sgetline(STREAM* f, char* str, int size)
+     364             : {
+     365      104980 :         char* i = str;
+     366      104980 :         char* send = str + size;
+     367             :         int c;
+     368             : 
+     369             :         /* if there is enough data in memory */
+     370      104980 :         if (sptrlookup(f, size)) {
+     371             :                 /* optimized version with all the data in memory */
+     372       93954 :                 unsigned char* pos = sptrget(f);
+     373             : 
+     374             :                 while (1) {
+     375     1288074 :                         c = *pos++;
+     376     1288074 :                         if (c == '\n') {
+     377             :                                 /* remove ending carrige return to support the Windows CR+LF format */
+     378       93954 :                                 if (i != str && i[-1] == '\r')
+     379           0 :                                         --i;
+     380       93954 :                                 --pos;
+     381       93954 :                                 break;
+     382             :                         }
+     383             : 
+     384     1194120 :                         *i++ = c;
+     385             : 
+     386     1194120 :                         if (i == send) {
+     387             :                                 /* LCOV_EXCL_START */
+     388             :                                 return -1;
+     389             :                                 /* LCOV_EXCL_STOP */
+     390             :                         }
+     391     1194120 :                 }
+     392             : 
+     393       93954 :                 sptrset(f, pos);
+     394             :         } else {
+     395             :                 while (1) {
+     396      150901 :                         c = sgetc(f);
+     397      150901 :                         if (c == EOF) {
+     398             :                                 /* LCOV_EXCL_START */
+     399             :                                 break;
+     400             :                                 /* LCOV_EXCL_STOP */
+     401             :                         }
+     402      150901 :                         if (c == '\n') {
+     403             :                                 /* remove ending carrige return to support the Windows CR+LF format */
+     404       11026 :                                 if (i != str && i[-1] == '\r')
+     405           0 :                                         --i;
+     406       11026 :                                 sungetc(c, f);
+     407       11026 :                                 break;
+     408             :                         }
+     409             : 
+     410      139875 :                         *i++ = c;
+     411             : 
+     412      139875 :                         if (i == send) {
+     413             :                                 /* LCOV_EXCL_START */
+     414             :                                 return -1;
+     415             :                                 /* LCOV_EXCL_STOP */
+     416             :                         }
+     417      139875 :                 }
+     418             :         }
+     419             : 
+     420      104980 :         *i = 0;
+     421             : 
+     422      104980 :         return i - str;
+     423             : }
+     424             : 
+     425        4785 : int sgetlasttok(STREAM* f, char* str, int size)
+     426             : {
+     427             :         int ret;
+     428             : 
+     429        4785 :         ret = sgetline(f, str, size);
+     430        4785 :         if (ret < 0) {
+     431             :                 /* LCOV_EXCL_START */
+     432             :                 return ret;
+     433             :                 /* LCOV_EXCL_STOP */
+     434             :         }
+     435             : 
+     436        9570 :         while (ret > 0 && (str[ret - 1] == ' ' || str[ret - 1] == '\t'))
+     437           0 :                 --ret;
+     438             : 
+     439        4785 :         str[ret] = 0;
+     440             : 
+     441        4785 :         return ret;
+     442             : }
+     443             : 
+     444      396702 : int sgetu32(STREAM* f, uint32_t* value)
+     445             : {
+     446             :         int c;
+     447             : 
+     448      396702 :         c = sgetc(f);
+     449      396702 :         if (c >= '0' && c <= '9') {
+     450             :                 uint32_t v;
+     451             : 
+     452      396702 :                 v = c - '0';
+     453             : 
+     454      396702 :                 c = sgetc(f);
+     455     2620869 :                 while (c >= '0' && c <= '9') {
+     456     1827465 :                         v *= 10;
+     457     1827465 :                         v += c - '0';
+     458     1827465 :                         c = sgetc(f);
+     459             :                 }
+     460             : 
+     461      396702 :                 *value = v;
+     462             : 
+     463      396702 :                 sungetc(c, f);
+     464      396702 :                 return 0;
+     465             :         } else {
+     466             :                 /* LCOV_EXCL_START */
+     467             :                 /* nothing read */
+     468             :                 return -1;
+     469             :                 /* LCOV_EXCL_STOP */
+     470             :         }
+     471             : }
+     472             : 
+     473      282276 : int sgetu64(STREAM* f, uint64_t* value)
+     474             : {
+     475             :         int c;
+     476             : 
+     477      282276 :         c = sgetc(f);
+     478      282276 :         if (c >= '0' && c <= '9') {
+     479             :                 uint64_t v;
+     480             : 
+     481      282276 :                 v = c - '0';
+     482             : 
+     483      282276 :                 c = sgetc(f);
+     484     2325776 :                 while (c >= '0' && c <= '9') {
+     485     1761224 :                         v *= 10;
+     486     1761224 :                         v += c - '0';
+     487     1761224 :                         c = sgetc(f);
+     488             :                 }
+     489             : 
+     490      282276 :                 *value = v;
+     491             : 
+     492      282276 :                 sungetc(c, f);
+     493      282276 :                 return 0;
+     494             :         } else {
+     495             :                 /* LCOV_EXCL_START */
+     496             :                 /* nothing read */
+     497             :                 return -1;
+     498             :                 /* LCOV_EXCL_STOP */
+     499             :         }
+     500             : }
+     501             : 
+     502      232385 : int sgethex(STREAM* f, void* void_data, int size)
+     503             : {
+     504      232385 :         unsigned char* data = void_data;
+     505             : 
+     506             :         /* if there is enough data in memory */
+     507      232385 :         if (sptrlookup(f, size * 2)) {
+     508             :                 /* optimized version with all the data in memory */
+     509      232285 :                 unsigned char* pos = sptrget(f);
+     510      232285 :                 unsigned x = 0;
+     511             : 
+     512     4181130 :                 while (size--) {
+     513             :                         unsigned b0;
+     514             :                         unsigned b1;
+     515             :                         unsigned b;
+     516             : 
+     517     3716560 :                         b0 = strdecset[pos[0]];
+     518     3716560 :                         b1 = strdecset[pos[1]];
+     519     3716560 :                         pos += 2;
+     520             : 
+     521     3716560 :                         b = (b0 << 4) | b1;
+     522             : 
+     523     3716560 :                         x |= b;
+     524             : 
+     525     3716560 :                         *data++ = b;
+     526             :                 }
+     527             : 
+     528             :                 /* at the end check if a digit was wrong */
+     529      232285 :                 if (x > 0xFF) {
+     530             :                         /* LCOV_EXCL_START */
+     531             :                         return -1;
+     532             :                         /* LCOV_EXCL_STOP */
+     533             :                 }
+     534             : 
+     535      232285 :                 sptrset(f, pos);
+     536             :         } else {
+     537             :                 /* standard version using sgetc() */
+     538        1800 :                 while (size--) {
+     539             :                         unsigned b0;
+     540             :                         unsigned b1;
+     541             :                         unsigned b;
+     542             :                         int c;
+     543             : 
+     544        1600 :                         c = sgetc(f);
+     545        1600 :                         if (c == EOF) {
+     546             :                                 /* LCOV_EXCL_START */
+     547             :                                 return -1;
+     548             :                                 /* LCOV_EXCL_STOP */
+     549             :                         }
+     550        1600 :                         b0 = strdecset[(unsigned char)c];
+     551             : 
+     552        1600 :                         c = sgetc(f);
+     553        1600 :                         if (c == EOF) {
+     554             :                                 /* LCOV_EXCL_START */
+     555             :                                 return -1;
+     556             :                                 /* LCOV_EXCL_STOP */
+     557             :                         }
+     558        1600 :                         b1 = strdecset[(unsigned char)c];
+     559             : 
+     560        1600 :                         b = (b0 << 4) | b1;
+     561             : 
+     562        1600 :                         if (b > 0xFF) {
+     563             :                                 /* LCOV_EXCL_START */
+     564             :                                 return -1;
+     565             :                                 /* LCOV_EXCL_STOP */
+     566             :                         }
+     567             : 
+     568        1600 :                         *data++ = b;
+     569             :                 }
+     570             :         }
+     571             : 
+     572      232385 :         return 0;
+     573             : }
+     574             : 
+     575    18305317 : int sgetb32(STREAM* f, uint32_t* value)
+     576             : {
+     577             :         uint32_t v;
+     578             :         unsigned char b;
+     579             :         unsigned char s;
+     580             :         int c;
+     581             : 
+     582    18305317 :         v = 0;
+     583    18305317 :         s = 0;
+     584             : loop:
+     585    35258730 :         c = sgetc(f);
+     586    35258730 :         if (c == EOF) {
+     587             :                 /* LCOV_EXCL_START */
+     588             :                 return -1;
+     589             :                 /* LCOV_EXCL_STOP */
+     590             :         }
+     591             : 
+     592    35258730 :         b = (unsigned char)c;
+     593    35258730 :         if ((b & 0x80) == 0) {
+     594    16953413 :                 v |= (uint32_t)b << s;
+     595    16953413 :                 s += 7;
+     596    16953413 :                 if (s >= 32) {
+     597             :                         /* LCOV_EXCL_START */
+     598             :                         return -1;
+     599             :                         /* LCOV_EXCL_STOP */
+     600             :                 }
+     601    16953413 :                 goto loop;
+     602             :         }
+     603             : 
+     604    18305317 :         v |= (uint32_t)(b & 0x7f) << s;
+     605             : 
+     606    18305317 :         *value = v;
+     607             : 
+     608    18305317 :         return 0;
+     609             : }
+     610             : 
+     611    10229372 : int sgetb64(STREAM* f, uint64_t* value)
+     612             : {
+     613             :         uint64_t v;
+     614             :         unsigned char b;
+     615             :         unsigned char s;
+     616             :         int c;
+     617             : 
+     618    10229372 :         v = 0;
+     619    10229372 :         s = 0;
+     620             : loop:
+     621    37406793 :         c = sgetc(f);
+     622    37406793 :         if (c == EOF) {
+     623             :                 /* LCOV_EXCL_START */
+     624             :                 return -1;
+     625             :                 /* LCOV_EXCL_STOP */
+     626             :         }
+     627             : 
+     628    37406793 :         b = (unsigned char)c;
+     629    37406793 :         if ((b & 0x80) == 0) {
+     630    27177421 :                 v |= (uint64_t)b << s;
+     631    27177421 :                 s += 7;
+     632    27177421 :                 if (s >= 64) {
+     633             :                         /* LCOV_EXCL_START */
+     634             :                         return -1;
+     635             :                         /* LCOV_EXCL_STOP */
+     636             :                 }
+     637    27177421 :                 goto loop;
+     638             :         }
+     639             : 
+     640    10229372 :         v |= (uint64_t)(b & 0x7f) << s;
+     641             : 
+     642    10229372 :         *value = v;
+     643             : 
+     644    10229372 :         return 0;
+     645             : }
+     646             : 
+     647         346 : int sgetble32(STREAM* f, uint32_t* value)
+     648             : {
+     649             :         unsigned char buf[4];
+     650             : 
+     651         346 :         if (sread(f, buf, 4) != 0) {
+     652             :                 /* LCOV_EXCL_START */
+     653             :                 return -1;
+     654             :                 /* LCOV_EXCL_STOP */
+     655             :         }
+     656             : 
+     657         346 :         *value = buf[0] | (uint32_t)buf[1] << 8 | (uint32_t)buf[2] << 16 | (uint32_t)buf[3] << 24;
+     658             : 
+     659         346 :         return 0;
+     660             : }
+     661             : 
+     662     3648313 : int sgetbs(STREAM* f, char* str, int size)
+     663             : {
+     664             :         uint32_t len;
+     665             : 
+     666     3648313 :         if (sgetb32(f, &len) < 0) {
+     667             :                 /* LCOV_EXCL_START */
+     668             :                 return -1;
+     669             :                 /* LCOV_EXCL_STOP */
+     670             :         }
+     671             : 
+     672     3648313 :         if (len + 1 > (uint32_t)size) {
+     673             :                 /* LCOV_EXCL_START */
+     674             :                 return -1;
+     675             :                 /* LCOV_EXCL_STOP */
+     676             :         }
+     677             : 
+     678     3648313 :         str[len] = 0;
+     679             : 
+     680     3648313 :         return sread(f, str, (int)len);
+     681             : }
+     682             : 
+     683      208981 : int sputs(const char* str, STREAM* f)
+     684             : {
+     685     2284072 :         while (*str) {
+     686     1866110 :                 if (sputc(*str++, f) != 0) {
+     687             :                         /* LCOV_EXCL_START */
+     688             :                         return -1;
+     689             :                         /* LCOV_EXCL_STOP */
+     690             :                 }
+     691             :         }
+     692             : 
+     693      208981 :         return 0;
+     694             : }
+     695             : 
+     696    20736098 : int swrite(const void* void_data, unsigned size, STREAM* f)
+     697             : {
+     698    20736098 :         const unsigned char* data = void_data;
+     699             : 
+     700             :         /* if there is enough space in memory */
+     701    20736098 :         if (sptrlookup(f, size)) {
+     702             :                 /* optimized version with all the data in memory */
+     703    20729979 :                 unsigned char* pos = sptrget(f);
+     704             : 
+     705             :                 /* copy it */
+     706   169093531 :                 while (size--) {
+     707   127633573 :                         f->crc_stream = crc32c_plain(f->crc_stream, *data);
+     708   127633573 :                         *pos++ = *data++;
+     709             :                 }
+     710             : 
+     711    20729979 :                 sptrset(f, pos);
+     712             :         } else {
+     713             :                 /* standard version using sputc() */
+     714      199614 :                 while (size--) {
+     715      187376 :                         if (sputc(*data++, f) != 0) {
+     716             :                                 /* LCOV_EXCL_START */
+     717             :                                 return -1;
+     718             :                                 /* LCOV_EXCL_STOP */
+     719             :                         }
+     720             :                 }
+     721             :         }
+     722             : 
+     723    20736098 :         return 0;
+     724             : }
+     725             : 
+     726      415233 : int sputu32(uint32_t value, STREAM* s)
+     727             : {
+     728             :         char buf[16];
+     729             :         int i;
+     730             : 
+     731      415233 :         if (!value)
+     732          45 :                 return sputc('0', s);
+     733             : 
+     734      415188 :         i = sizeof(buf);
+     735             : 
+     736     3157044 :         while (value) {
+     737     2326668 :                 buf[--i] = (value % 10) + '0';
+     738     2326668 :                 value /= 10;
+     739             :         }
+     740             : 
+     741      415188 :         return swrite(buf + i, sizeof(buf) - i, s);
+     742             : }
+     743             : 
+     744      298899 : int sputu64(uint64_t value, STREAM* s)
+     745             : {
+     746             :         char buf[32];
+     747             :         uint32_t value32;
+     748             :         int i;
+     749             : 
+     750      298899 :         if (!value)
+     751         130 :                 return sputc('0', s);
+     752             : 
+     753      298769 :         i = sizeof(buf);
+     754             : 
+     755      597538 :         while (value > 0xFFFFFFFF) {
+     756           0 :                 buf[--i] = (value % 10) + '0';
+     757           0 :                 value /= 10;
+     758             :         }
+     759             : 
+     760      298769 :         value32 = (uint32_t)value;
+     761             : 
+     762     2761238 :         while (value32) {
+     763     2163700 :                 buf[--i] = (value32 % 10) + '0';
+     764     2163700 :                 value32 /= 10;
+     765             :         }
+     766             : 
+     767      298769 :         return swrite(buf + i, sizeof(buf) - i, s);
+     768             : }
+     769             : 
+     770      245610 : int sputhex(const void* void_data, int size, STREAM* f)
+     771             : {
+     772      245610 :         const unsigned char* data = void_data;
+     773             : 
+     774             :         /* if there is enough space in memory */
+     775      245610 :         if (sptrlookup(f, size * 2)) {
+     776             :                 /* optimized version with all the data in memory */
+     777      245505 :                 unsigned char* pos = sptrget(f);
+     778             : 
+     779     4419090 :                 while (size) {
+     780     3928080 :                         unsigned b = *data;
+     781             : 
+     782     3928080 :                         *pos++ = strhexset[b >> 4];
+     783     3928080 :                         *pos++ = strhexset[b & 0xF];
+     784             : 
+     785     3928080 :                         ++data;
+     786     3928080 :                         --size;
+     787             :                 }
+     788             : 
+     789      245505 :                 sptrset(f, pos);
+     790             :         } else {
+     791             :                 /* standard version using sputc() */
+     792        1890 :                 while (size) {
+     793        1680 :                         unsigned b = *data;
+     794             : 
+     795        1680 :                         if (sputc(strhexset[b >> 4], f) != 0) {
+     796             :                                 /* LCOV_EXCL_START */
+     797             :                                 return -1;
+     798             :                                 /* LCOV_EXCL_STOP */
+     799             :                         }
+     800        1680 :                         if (sputc(strhexset[b & 0xF], f) != 0) {
+     801             :                                 /* LCOV_EXCL_START */
+     802             :                                 return -1;
+     803             :                                 /* LCOV_EXCL_STOP */
+     804             :                         }
+     805             : 
+     806        1680 :                         ++data;
+     807        1680 :                         --size;
+     808             :                 }
+     809             :         }
+     810             : 
+     811      245610 :         return 0;
+     812             : }
+     813             : 
+     814     8983972 : int sputb32(uint32_t value, STREAM* s)
+     815             : {
+     816             :         unsigned char b;
+     817             :         unsigned char buf[16];
+     818             :         unsigned i;
+     819             : 
+     820     8983972 :         i = 0;
+     821             : loop:
+     822    17090262 :         b = value & 0x7f;
+     823    17090262 :         value >>= 7;
+     824             : 
+     825    17090262 :         if (value) {
+     826     8106290 :                 buf[i++] = b;
+     827     8106290 :                 goto loop;
+     828             :         }
+     829             : 
+     830     8983972 :         buf[i++] = b | 0x80;
+     831             : 
+     832     8983972 :         return swrite(buf, i, s);
+     833             : }
+     834             : 
+     835     4887004 : int sputb64(uint64_t value, STREAM* s)
+     836             : {
+     837             :         unsigned char b;
+     838             :         unsigned char buf[16];
+     839             :         unsigned i;
+     840             : 
+     841     4887004 :         i = 0;
+     842             : loop:
+     843    17866904 :         b = value & 0x7f;
+     844    17866904 :         value >>= 7;
+     845             : 
+     846    17866904 :         if (value) {
+     847    12979900 :                 buf[i++] = b;
+     848    12979900 :                 goto loop;
+     849             :         }
+     850             : 
+     851     4887004 :         buf[i++] = b | 0x80;
+     852             : 
+     853     4887004 :         return swrite(buf, i, s);
+     854             : }
+     855             : 
+     856         131 : int sputble32(uint32_t value, STREAM* s)
+     857             : {
+     858             :         unsigned char buf[4];
+     859             : 
+     860         131 :         buf[0] = value & 0xFF;
+     861         131 :         buf[1] = (value >> 8) & 0xFF;
+     862         131 :         buf[2] = (value >> 16) & 0xFF;
+     863         131 :         buf[3] = (value >> 24) & 0xFF;
+     864             : 
+     865         131 :         return swrite(buf, 4, s);
+     866             : }
+     867             : 
+     868     1739788 : int sputbs(const char* str, STREAM* f)
+     869             : {
+     870     1739788 :         size_t len = strlen(str);
+     871             : 
+     872     1739788 :         if (sputb32(len, f) != 0) {
+     873             :                 /* LCOV_EXCL_START */
+     874             :                 return -1;
+     875             :                 /* LCOV_EXCL_STOP */
+     876             :         }
+     877             : 
+     878     1739788 :         return swrite(str, len, f);
+     879             : }
+     880             : 
+     881             : #if HAVE_FSYNC
+     882         120 : int ssync(STREAM* s)
+     883             : {
+     884             :         unsigned i;
+     885             : 
+     886         945 :         for (i = 0; i < s->handle_size; ++i) {
+     887         825 :                 if (fsync(s->handle[i].f) != 0) {
+     888             :                         /* LCOV_EXCL_START */
+     889             :                         s->state = STREAM_STATE_ERROR;
+     890             :                         s->state_index = i;
+     891             :                         return -1;
+     892             :                         /* LCOV_EXCL_STOP */
+     893             :                 }
+     894             :         }
+     895             : 
+     896         120 :         return 0;
+     897             : }
+     898             : #endif
+     899             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.h.func-sort-c.html b/cov/cmdline/stream.h.func-sort-c.html new file mode 100644 index 00000000..4e927baf --- /dev/null +++ b/cov/cmdline/stream.h.func-sort-c.html @@ -0,0 +1,120 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:394390.7 %
Date:2015-05-12Functions:111291.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
sgetc90674228
sptrlookup33382914
sptrset33339678
sptrget33339678
sputc6554039
serror3924482
sungetc1215267
sputeol386633
sgeteol373075
sgetspace18303
seof1
serrorfile0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.h.func.html b/cov/cmdline/stream.h.func.html new file mode 100644 index 00000000..66a5ad0c --- /dev/null +++ b/cov/cmdline/stream.h.func.html @@ -0,0 +1,120 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:394390.7 %
Date:2015-05-12Functions:111291.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
seof1
serror3924482
serrorfile0
sgetc90674228
sgeteol373075
sgetspace18303
sptrget33339678
sptrlookup33382914
sptrset33339678
sputc6554039
sputeol386633
sungetc1215267
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/stream.h.gcov.html b/cov/cmdline/stream.h.gcov.html new file mode 100644 index 00000000..d252f63b --- /dev/null +++ b/cov/cmdline/stream.h.gcov.html @@ -0,0 +1,519 @@ + + + + + + + LCOV - lcov.info - cmdline/stream.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - stream.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:394390.7 %
Date:2015-05-12Functions:111291.7 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #ifndef __STREAM_H
+      19             : #define __STREAM_H
+      20             : 
+      21             : #include "util.h"
+      22             : 
+      23             : /****************************************************************************/
+      24             : /* stream */
+      25             : 
+      26             : /**
+      27             :  * Size of the buffer of the stream.
+      28             :  *
+      29             :  * It's not a constant for testing purpose.
+      30             :  */
+      31             : unsigned STREAM_SIZE;
+      32             : 
+      33             : #define STREAM_STATE_READ 0 /**< The stream is in a normal state of read. */
+      34             : #define STREAM_STATE_WRITE 1 /**< The stream is in a normal state of write. */
+      35             : #define STREAM_STATE_ERROR -1 /**< An error was encoutered. */
+      36             : #define STREAM_STATE_EOF 2 /**< The end of file was encoutered. */
+      37             : 
+      38             : struct stream_handle {
+      39             :         int f; /**< Handle of the file. */
+      40             :         char path[PATH_MAX]; /**< Path of the file. */
+      41             : };
+      42             : 
+      43             : struct stream {
+      44             :         unsigned char* buffer; /**< Buffer of the stream. */
+      45             :         unsigned char* pos; /**< Current position in the buffer. */
+      46             :         unsigned char* end; /**< End position of the buffer. */
+      47             :         int state; /**< State of the stream. One of STREAM_STATE. */
+      48             :         int state_index; /**< Index of the handle causing a state change. */
+      49             :         unsigned handle_size; /**< Number of handles. */
+      50             :         struct stream_handle* handle; /**< Set of handles. */
+      51             :         off_t offset; /**< Offset into the file. */
+      52             :         off_t offset_uncached; /**< Offset into the file excluding the cached data. */
+      53             : 
+      54             :         /**
+      55             :          * CRC of the data read or written in the file.
+      56             :          *
+      57             :          * If reading, it's the CRC of all data read from the file,
+      58             :          * including the one in the buffer.
+      59             :          * If writing it's all the data wrote to the file,
+      60             :          * excluding the one still in buffer yet to be written.
+      61             :          */
+      62             :         uint32_t crc;
+      63             : 
+      64             :         /**
+      65             :          * CRC of the file excluding the cached data in the buffer.
+      66             :          *
+      67             :          * If reading, it's the CRC of the data read from the file,
+      68             :          * excluding the one in the buffer.
+      69             :          * If writing it's all the data wrote to the file,
+      70             :          * excluding the one still in buffer yet to be written.
+      71             :          */
+      72             :         uint32_t crc_uncached;
+      73             : 
+      74             :         /**
+      75             :          * CRC of the data written to the stream.
+      76             :          *
+      77             :          * This is an extra check of the data that is written to
+      78             :          * file to ensure that it's consistent even in case
+      79             :          * of memory errors.
+      80             :          *
+      81             :          * This extra check takes about 2 seconds for each GB of
+      82             :          * content file with the Intel CRC instruction,
+      83             :          * and about 4 seconds without it.
+      84             :          * But usually this doesn't slow down the write process,
+      85             :          * as the disk is the bottle-neck.
+      86             :          *
+      87             :          * Note that this CRC doesn't have the IV processing.
+      88             :          *
+      89             :          * Not used in reading.
+      90             :          * In writing, it's all the data wrote calling sput() functions.
+      91             :          */
+      92             :         uint32_t crc_stream;
+      93             : };
+      94             : 
+      95             : /**
+      96             :  * Opaque STREAM type. Like ::FILE.
+      97             :  */
+      98             : typedef struct stream STREAM;
+      99             : 
+     100             : /**
+     101             :  * Opens a stream for reading. Like fopen("r").
+     102             :  */
+     103             : STREAM* sopen_read(const char* file);
+     104             : 
+     105             : /**
+     106             :  * Opens a stream for writing. Like fopen("w").
+     107             :  */
+     108             : STREAM* sopen_write(const char* file);
+     109             : 
+     110             : /**
+     111             :  * Opens a set of streams for writing. Like fopen("w").
+     112             :  */
+     113             : STREAM* sopen_multi_write(unsigned count);
+     114             : 
+     115             : /**
+     116             :  * Specifies the file to open.
+     117             :  */
+     118             : int sopen_multi_file(STREAM* s, unsigned i, const char* file);
+     119             : 
+     120             : /**
+     121             :  * Closes a stream. Like fclose().
+     122             :  */
+     123             : int sclose(STREAM* s);
+     124             : 
+     125             : /**
+     126             :  * Returns the handle of the file.
+     127             :  * In case of multi file, the first one is returned.
+     128             :  */
+     129             : int shandle(STREAM* s);
+     130             : 
+     131             : /**
+     132             :  * Fills the read stream buffer and read a char.
+     133             :  * \note Don't call this directly, but use sgetc().
+     134             :  * \return The char read, or EOF on error.
+     135             :  */
+     136             : int sfill(STREAM* s);
+     137             : 
+     138             : /**
+     139             :  * Flushes the write stream buffer.
+     140             :  * \return 0 on success, or EOF on error.
+     141             :  */
+     142             : int sflush(STREAM* s);
+     143             : 
+     144             : /**
+     145             :  * Gets the file pointer.
+     146             :  */
+     147             : int64_t stell(STREAM* s);
+     148             : 
+     149             : /**
+     150             :  * Gets the CRC of the processed data.
+     151             :  */
+     152             : uint32_t scrc(STREAM* s);
+     153             : 
+     154             : /**
+     155             :  * Gets the CRC of the processed data in put.
+     156             :  */
+     157             : uint32_t scrc_stream(STREAM* s);
+     158             : 
+     159             : /**
+     160             :  * Checks if the buffer has enough data loaded.
+     161             :  */
+     162    33382914 : static inline int sptrlookup(STREAM* s, int size)
+     163             : {
+     164    33382914 :         return s->pos + size <= s->end;
+     165             : }
+     166             : 
+     167             : /**
+     168             :  * Gets the current stream ptr.
+     169             :  */
+     170    33339678 : static inline unsigned char* sptrget(STREAM* s)
+     171             : {
+     172    33339678 :         return s->pos;
+     173             : }
+     174             : 
+     175             : /**
+     176             :  * Sets the current stream ptr.
+     177             :  */
+     178    33339678 : static inline void sptrset(STREAM* s, unsigned char* ptr)
+     179             : {
+     180    33339678 :         s->pos = ptr;
+     181    33339678 : }
+     182             : 
+     183             : /**
+     184             :  * Checks the error status. Like ferror().
+     185             :  */
+     186     3924482 : static inline int serror(STREAM* s)
+     187             : {
+     188     3924482 :         return s->state == STREAM_STATE_ERROR;
+     189             : }
+     190             : 
+     191             : /**
+     192             :  * Checks the eof status. Like feof().
+     193             :  */
+     194           1 : static inline int seof(STREAM* s)
+     195             : {
+     196           1 :         return s->state == STREAM_STATE_EOF;
+     197             : }
+     198             : 
+     199             : /**
+     200             :  * Gets the index of the handle that caused the error.
+     201             :  */
+     202             : static inline int serrorindex(STREAM* s)
+     203             : {
+     204             :         return s->state_index;
+     205             : }
+     206             : 
+     207             : /**
+     208             :  * Gets the path of the handle that caused the error.
+     209             :  */
+     210           0 : static inline const char* serrorfile(STREAM* s)
+     211             : {
+     212           0 :         return s->handle[s->state_index].path;
+     213             : }
+     214             : 
+     215             : /**
+     216             :  * Sync the stream. Like fsync().
+     217             :  */
+     218             : int ssync(STREAM* s);
+     219             : 
+     220             : /****************************************************************************/
+     221             : /* get */
+     222             : 
+     223             : /**
+     224             :  * Reads a char. Like fgetc().
+     225             :  */
+     226    90674228 : static inline int sgetc(STREAM* s)
+     227             : {
+     228    90674228 :         if (s->pos == s->end)
+     229      298684 :                 return sfill(s);
+     230    90375544 :         return *s->pos++;
+     231             : }
+     232             : 
+     233             : /**
+     234             :  * Unreads a char.
+     235             :  * Like ungetc() but you have to unget the same char read.
+     236             :  */
+     237     1215267 : static inline void sungetc(int c, STREAM* s)
+     238             : {
+     239     1215267 :         if (c != EOF)
+     240     1214552 :                 --s->pos;
+     241     1215267 : }
+     242             : 
+     243             : /**
+     244             :  * Reads a fixed amount of chars.
+     245             :  * Returns 0 on success, or -1 on error.
+     246             :  */
+     247             : int sread(STREAM* f, void* void_data, unsigned size);
+     248             : 
+     249             : /**
+     250             :  * Gets a char from a stream, ignoring one '\r'.
+     251             :  */
+     252      373075 : static inline int sgeteol(STREAM* f)
+     253             : {
+     254             :         int c;
+     255             : 
+     256      373075 :         c = sgetc(f);
+     257      373075 :         if (c == '\r')
+     258           0 :                 c = sgetc(f);
+     259             : 
+     260      373075 :         return c;
+     261             : }
+     262             : 
+     263             : /**
+     264             :  * Reads all the spaces and tabs.
+     265             :  * Returns the number of spaces and tabs read.
+     266             :  */
+     267       18303 : static inline int sgetspace(STREAM* f)
+     268             : {
+     269       18303 :         int count = 0;
+     270             :         int c;
+     271             : 
+     272       18303 :         c = sgetc(f);
+     273       43388 :         while (c == ' ' || c == '\t') {
+     274        6782 :                 ++count;
+     275        6782 :                 c = sgetc(f);
+     276             :         }
+     277             : 
+     278       18303 :         sungetc(c, f);
+     279       18303 :         return count;
+     280             : }
+     281             : 
+     282             : /**
+     283             :  * Reads until the first space or tab.
+     284             :  * Stops at the first ' ', '\t', '\n' or EOF.
+     285             :  * Returns <0 if the buffer is too small, or the number of chars read.
+     286             :  */
+     287             : int sgettok(STREAM* f, char* str, int size);
+     288             : 
+     289             : /**
+     290             :  * Reads until the end of line.
+     291             :  * Stops at the first '\n' or EOF. Note that '\n' is left in the stream.
+     292             :  * Returns <0 if the buffer is too small, or the number of chars read.
+     293             :  */
+     294             : int sgetline(STREAM* f, char* str, int size);
+     295             : 
+     296             : /**
+     297             :  * Like sgetline() but removes ' ' and '\t' at the end.
+     298             :  */
+     299             : int sgetlasttok(STREAM* f, char* str, int size);
+     300             : 
+     301             : /**
+     302             :  * Reads a 32 bit number.
+     303             :  * Stops at the first not digit char or EOF.
+     304             :  * Returns <0 if there isn't enough to read.
+     305             :  */
+     306             : int sgetu32(STREAM* f, uint32_t* value);
+     307             : 
+     308             : /**
+     309             :  * Reads a 64 bit number.
+     310             :  * Stops at the first not digit char.
+     311             :  * Returns <0 if there isn't enough to read.
+     312             :  */
+     313             : int sgetu64(STREAM* f, uint64_t* value);
+     314             : 
+     315             : /**
+     316             :  * Reads an hexadecimal string of fixed length.
+     317             :  * Returns <0 if there isn't enough to read.
+     318             :  */
+     319             : int sgethex(STREAM* f, void* data, int size);
+     320             : 
+     321             : /****************************************************************************/
+     322             : /* binary get */
+     323             : 
+     324             : /**
+     325             :  * Reads a binary 32 bit number in packet format.
+     326             :  * Returns <0 if there isn't enough to read.
+     327             :  */
+     328             : int sgetb32(STREAM* f, uint32_t* value);
+     329             : 
+     330             : /**
+     331             :  * Reads a binary 64 bit number in packet format.
+     332             :  * Returns <0 if there isn't enough to read.
+     333             :  */
+     334             : int sgetb64(STREAM* f, uint64_t* value);
+     335             : 
+     336             : /**
+     337             :  * Reads a binary 32 bit number in little endian format.
+     338             :  * Returns <0 if there isn't enough to read.
+     339             :  */
+     340             : int sgetble32(STREAM* f, uint32_t* value);
+     341             : 
+     342             : /**
+     343             :  * Reads a binary string.
+     344             :  * Returns -1 on error or if the buffer is too small, or the number of chars read.
+     345             :  */
+     346             : int sgetbs(STREAM* f, char* str, int size);
+     347             : 
+     348             : /****************************************************************************/
+     349             : /* put */
+     350             : 
+     351             : /**
+     352             :  * Writes a char. Like fputc().
+     353             :  * Returns 0 on success or -1 on error.
+     354             :  */
+     355     6554039 : static inline int sputc(int c, STREAM* s)
+     356             : {
+     357     6554039 :         if (s->pos == s->end) {
+     358       38695 :                 if (sflush(s) != 0)
+     359           0 :                         return -1;
+     360             :         }
+     361     6554039 :         s->crc_stream = crc32c_plain(s->crc_stream, c);
+     362     6554039 :         *s->pos++ = c;
+     363     6554039 :         return 0;
+     364             : }
+     365             : 
+     366             : /**
+     367             :  * Writes a end of line.
+     368             :  * Returns 0 on success or -1 on error.
+     369             :  */
+     370      386633 : static inline int sputeol(STREAM* s)
+     371             : {
+     372             : #ifdef _WIN32
+     373             :         if (sputc('\r', s) != 0)
+     374             :                 return -1;
+     375             : #endif
+     376      386633 :         return sputc('\n', s);
+     377             : }
+     378             : 
+     379             : /**
+     380             :  * Writes a string.
+     381             :  * Returns 0 on success or -1 on error.
+     382             :  */
+     383             : int sputs(const char* str, STREAM* f);
+     384             : 
+     385             : /**
+     386             :  * Write a sized string.
+     387             :  * Returns 0 on success or -1 on error.
+     388             :  */
+     389             : int swrite(const void* data, unsigned size, STREAM* f);
+     390             : 
+     391             : /**
+     392             :  * Write a string literal (constant string).
+     393             :  * Returns 0 on success or -1 on error.
+     394             :  */
+     395             : #define sputsl(str, f) swrite(str, sizeof(str) - 1, f)
+     396             : 
+     397             : /**
+     398             :  * Writes a 32 bit number.
+     399             :  * Returns 0 on success or -1 on error.
+     400             :  */
+     401             : int sputu32(uint32_t value, STREAM* s);
+     402             : 
+     403             : /**
+     404             :  * Writes a 64 bit number.
+     405             :  * Returns 0 on success or -1 on error.
+     406             :  */
+     407             : int sputu64(uint64_t value, STREAM* s);
+     408             : 
+     409             : /**
+     410             :  * Writes a hexadecimal string of fixed length.
+     411             :  * Returns 0 on success or -1 on error.
+     412             :  */
+     413             : int sputhex(const void* void_data, int size, STREAM* s);
+     414             : 
+     415             : /****************************************************************************/
+     416             : /* binary put */
+     417             : 
+     418             : /**
+     419             :  * Writes a binary 32 bit number in packed format.
+     420             :  * Returns 0 on success or -1 on error.
+     421             :  */
+     422             : int sputb32(uint32_t value, STREAM* s);
+     423             : 
+     424             : /**
+     425             :  * Writes a binary 64 bit number in packed format.
+     426             :  * Returns 0 on success or -1 on error.
+     427             :  */
+     428             : int sputb64(uint64_t value, STREAM* s);
+     429             : 
+     430             : /**
+     431             :  * Writes a binary 32 bit number in little endian format.
+     432             :  * Returns 0 on success or -1 on error.
+     433             :  */
+     434             : int sputble32(uint32_t value, STREAM* s);
+     435             : 
+     436             : /**
+     437             :  * Writes a binary string.
+     438             :  * Returns 0 on success or -1 on error.
+     439             :  */
+     440             : int sputbs(const char* str, STREAM* s);
+     441             : 
+     442             : #endif
+     443             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/support.c.func-sort-c.html b/cov/cmdline/support.c.func-sort-c.html new file mode 100644 index 00000000..032e5b59 --- /dev/null +++ b/cov/cmdline/support.c.func-sort-c.html @@ -0,0 +1,208 @@ + + + + + + + LCOV - lcov.info - cmdline/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - support.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:23230875.3 %
Date:2015-05-12Functions:293485.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
pathcmp49935952
pathprint49788380
malloc_nofail10377145
pathcpy6804242
strdup_nofail5657552
log_tag4036583
esc3589269
mkancestor794947
log_error725185
msg_info297699
msg_verbose126750
fmtime119773
pathexport17568
calloc_nofail13324
log_expected11738
pathimport8384
pathslash7165
msg_progress2807
log_flush1055
msg_bar917
log_fatal784
pathcatc780
msg_status544
malloc_counter426
msg_flush423
pathcat237
pathcut30
smartctl_attribute25
smartctl_flush12
polish0
smatch0
malloc_printn0
malloc_print0
malloc_fail0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/support.c.func.html b/cov/cmdline/support.c.func.html new file mode 100644 index 00000000..8e4f4a11 --- /dev/null +++ b/cov/cmdline/support.c.func.html @@ -0,0 +1,208 @@ + + + + + + + LCOV - lcov.info - cmdline/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - support.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:23230875.3 %
Date:2015-05-12Functions:293485.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
calloc_nofail13324
esc3589269
fmtime119773
log_error725185
log_expected11738
log_fatal784
log_flush1055
log_tag4036583
malloc_counter426
malloc_fail0
malloc_nofail10377145
malloc_print0
malloc_printn0
mkancestor794947
msg_bar917
msg_flush423
msg_info297699
msg_progress2807
msg_status544
msg_verbose126750
pathcat237
pathcatc780
pathcmp49935952
pathcpy6804242
pathcut30
pathexport17568
pathimport8384
pathprint49788380
pathslash7165
polish0
smartctl_attribute25
smartctl_flush12
smatch0
strdup_nofail5657552
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/support.c.gcov.html b/cov/cmdline/support.c.gcov.html new file mode 100644 index 00000000..050b8eec --- /dev/null +++ b/cov/cmdline/support.c.gcov.html @@ -0,0 +1,918 @@ + + + + + + + LCOV - lcov.info - cmdline/support.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - support.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:23230875.3 %
Date:2015-05-12Functions:293485.3 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : 
+      22             : /****************************************************************************/
+      23             : /* print */
+      24             : 
+      25             : int msg_level = 0;
+      26             : 
+      27             : /**
+      28             :  * Mutex used for printf.
+      29             :  *
+      30             :  * In Windows printf() is not atomic, and multiple threads
+      31             :  * will have output interleaved.
+      32             :  *
+      33             :  * Note that even defining __USE_MINGW_ANSI_STDIO the problem persists.
+      34             :  *
+      35             :  * See for example:
+      36             :  *
+      37             :  * Weird output when I use pthread and printf.
+      38             :  * http://stackoverflow.com/questions/13190254/weird-output-when-i-use-pthread-and-printf
+      39             :  *
+      40             :  * This is also required in other OS because we split output in stdlog in
+      41             :  * two fprintf calls.
+      42             :  */
+      43             : static pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER;
+      44             : 
+      45             : /*
+      46             :  * Note that in the following functions we always flush both
+      47             :  * stdout and stderr, because we want to ensure that they mixes
+      48             :  * well when redirected to files
+      49             :  *
+      50             :  * The buffering is similar at the "line buffered" one, that
+      51             :  * is not available on Windows, so we emulate it in this way.
+      52             :  *
+      53             :  * For stdlog flushing is limited. To ensure flushing the
+      54             :  * caller should use log_flush().
+      55             :  */
+      56             : 
+      57         784 : void log_fatal(const char* format, ...)
+      58             : {
+      59             :         va_list ap;
+      60             : 
+      61         784 :         pthread_mutex_lock(&msg_lock);
+      62             : 
+      63         784 :         if (stdlog) {
+      64          92 :                 va_start(ap, format);
+      65          92 :                 fprintf(stdlog, "msg:fatal: ");
+      66          92 :                 vfprintf(stdlog, format, ap);
+      67          92 :                 fflush(stdlog);
+      68          92 :                 va_end(ap);
+      69             :         }
+      70             : 
+      71         784 :         va_start(ap, format);
+      72         784 :         vfprintf(stderr, format, ap);
+      73         784 :         fflush(stderr);
+      74         784 :         va_end(ap);
+      75             : 
+      76         784 :         pthread_mutex_unlock(&msg_lock);
+      77         784 : }
+      78             : 
+      79      725185 : void log_error(const char* format, ...)
+      80             : {
+      81             :         va_list ap;
+      82             : 
+      83      725185 :         pthread_mutex_lock(&msg_lock);
+      84             : 
+      85      725185 :         if (stdlog) {
+      86      723277 :                 va_start(ap, format);
+      87      723277 :                 fprintf(stdlog, "msg:error: ");
+      88      723277 :                 vfprintf(stdlog, format, ap);
+      89      723277 :                 fflush(stdlog);
+      90      723277 :                 va_end(ap);
+      91             :         } else {
+      92        1908 :                 va_start(ap, format);
+      93        1908 :                 vfprintf(stderr, format, ap);
+      94        1908 :                 fflush(stderr);
+      95        1908 :                 va_end(ap);
+      96             :         }
+      97             : 
+      98      725185 :         pthread_mutex_unlock(&msg_lock);
+      99      725185 : }
+     100             : 
+     101       11738 : void log_expected(const char* format, ...)
+     102             : {
+     103             :         va_list ap;
+     104             : 
+     105       11738 :         pthread_mutex_lock(&msg_lock);
+     106             : 
+     107       11738 :         if (stdlog) {
+     108       11738 :                 va_start(ap, format);
+     109       11738 :                 fprintf(stdlog, "msg:expected: ");
+     110       11738 :                 vfprintf(stdlog, format, ap);
+     111       11738 :                 fflush(stdlog);
+     112       11738 :                 va_end(ap);
+     113             :         }
+     114             : 
+     115       11738 :         pthread_mutex_unlock(&msg_lock);
+     116       11738 : }
+     117             : 
+     118     4036583 : void log_tag(const char* format, ...)
+     119             : {
+     120             :         va_list ap;
+     121             : 
+     122     4036583 :         pthread_mutex_lock(&msg_lock);
+     123             : 
+     124     4036583 :         if (stdlog) {
+     125     2951533 :                 va_start(ap, format);
+     126     2951533 :                 vfprintf(stdlog, format, ap);
+     127             :                 /* here we intentionally don't flush */
+     128             :                 /* to make the output faster */
+     129     2951533 :                 va_end(ap);
+     130             :         }
+     131             : 
+     132     4036583 :         pthread_mutex_unlock(&msg_lock);
+     133     4036583 : }
+     134             : 
+     135        1055 : void log_flush(void)
+     136             : {
+     137        1055 :         pthread_mutex_lock(&msg_lock);
+     138             : 
+     139        1055 :         if (stdlog)
+     140         316 :                 fflush(stdlog);
+     141        1055 :         fflush(stdout);
+     142        1055 :         fflush(stderr);
+     143             : 
+     144        1055 :         pthread_mutex_unlock(&msg_lock);
+     145        1055 : }
+     146             : 
+     147         544 : void msg_status(const char* format, ...)
+     148             : {
+     149             :         va_list ap;
+     150             : 
+     151         544 :         pthread_mutex_lock(&msg_lock);
+     152             : 
+     153         544 :         if (stdlog) {
+     154         270 :                 va_start(ap, format);
+     155         270 :                 fprintf(stdlog, "msg:status: ");
+     156         270 :                 vfprintf(stdlog, format, ap);
+     157         270 :                 fflush(stdlog);
+     158         270 :                 va_end(ap);
+     159             :         }
+     160             : 
+     161         544 :         if (msg_level >= MSG_STATUS) {
+     162         544 :                 va_start(ap, format);
+     163         544 :                 vfprintf(stdout, format, ap);
+     164         544 :                 fflush(stdout);
+     165         544 :                 va_end(ap);
+     166             :         }
+     167             : 
+     168         544 :         pthread_mutex_unlock(&msg_lock);
+     169         544 : }
+     170             : 
+     171      297699 : void msg_info(const char* format, ...)
+     172             : {
+     173             :         va_list ap;
+     174             : 
+     175      297699 :         pthread_mutex_lock(&msg_lock);
+     176             : 
+     177             :         /* don't output in stdlog as these messages */
+     178             :         /* are always paired with a msg_tag() call */
+     179             : 
+     180      297699 :         if (msg_level >= MSG_INFO) {
+     181       28823 :                 va_start(ap, format);
+     182       28823 :                 vfprintf(stdout, format, ap);
+     183       28823 :                 fflush(stdout);
+     184       28823 :                 va_end(ap);
+     185             :         }
+     186             : 
+     187      297699 :         pthread_mutex_unlock(&msg_lock);
+     188      297699 : }
+     189             : 
+     190        2807 : void msg_progress(const char* format, ...)
+     191             : {
+     192             :         va_list ap;
+     193             : 
+     194        2807 :         pthread_mutex_lock(&msg_lock);
+     195             : 
+     196        2807 :         if (stdlog) {
+     197         713 :                 va_start(ap, format);
+     198         713 :                 fprintf(stdlog, "msg:progress: ");
+     199         713 :                 vfprintf(stdlog, format, ap);
+     200         713 :                 fflush(stdlog);
+     201         713 :                 va_end(ap);
+     202             :         }
+     203             : 
+     204        2807 :         if (msg_level >= MSG_PROGRESS) {
+     205         139 :                 va_start(ap, format);
+     206         139 :                 vfprintf(stdout, format, ap);
+     207         139 :                 fflush(stdout);
+     208         139 :                 va_end(ap);
+     209             :         }
+     210             : 
+     211        2807 :         pthread_mutex_unlock(&msg_lock);
+     212        2807 : }
+     213             : 
+     214         917 : void msg_bar(const char* format, ...)
+     215             : {
+     216             :         va_list ap;
+     217             : 
+     218         917 :         pthread_mutex_lock(&msg_lock);
+     219             : 
+     220             :         /* don't output in stdlog as these messages */
+     221             :         /* are intended for screen only */
+     222             :         /* also don't flush stdout as they are intended to be partial messages */
+     223             : 
+     224         917 :         if (msg_level >= MSG_BAR) {
+     225           0 :                 va_start(ap, format);
+     226           0 :                 vfprintf(stdout, format, ap);
+     227           0 :                 va_end(ap);
+     228             :         }
+     229             : 
+     230         917 :         pthread_mutex_unlock(&msg_lock);
+     231         917 : }
+     232             : 
+     233      126750 : void msg_verbose(const char* format, ...)
+     234             : {
+     235             :         va_list ap;
+     236             : 
+     237      126750 :         pthread_mutex_lock(&msg_lock);
+     238             : 
+     239      126750 :         if (stdlog) {
+     240      125246 :                 va_start(ap, format);
+     241      125246 :                 fprintf(stdlog, "msg:verbose: ");
+     242      125246 :                 vfprintf(stdlog, format, ap);
+     243      125246 :                 fflush(stdlog);
+     244      125246 :                 va_end(ap);
+     245             :         }
+     246             : 
+     247      126750 :         if (msg_level >= MSG_VERBOSE) {
+     248          83 :                 va_start(ap, format);
+     249          83 :                 vfprintf(stdout, format, ap);
+     250          83 :                 fflush(stdout);
+     251          83 :                 va_end(ap);
+     252             :         }
+     253             : 
+     254      126750 :         pthread_mutex_unlock(&msg_lock);
+     255      126750 : }
+     256             : 
+     257         423 : void msg_flush(void)
+     258             : {
+     259         423 :         pthread_mutex_lock(&msg_lock);
+     260             : 
+     261         423 :         fflush(stdout);
+     262         423 :         fflush(stderr);
+     263             : 
+     264         423 :         pthread_mutex_unlock(&msg_lock);
+     265         423 : }
+     266             : 
+     267             : /**
+     268             :  * Number of buffers for esc().
+     269             :  */
+     270             : #define ESC_MAX 4
+     271             : 
+     272             : /**
+     273             :  * Buffer table to allow multiple calls to esc().
+     274             :  */
+     275             : static char esc_table[ESC_MAX][PATH_MAX*2+1];
+     276             : 
+     277             : /**
+     278             :  * Next buffer to use.
+     279             :  */
+     280             : static unsigned esc_index = 0;
+     281             : 
+     282             : #define ESCAPE(from,to) \
+     283             :         case from : \
+     284             :                 if (p == end) \
+     285             :                         goto bail; \
+     286             :                 *p++ = '\\'; \
+     287             :                 if (p == end) \
+     288             :                         goto bail; \
+     289             :                 *p++ = to; \
+     290             :                 break
+     291             : 
+     292     3589269 : const char* esc(const char* str)
+     293             : {
+     294     3589269 :         char* begin = esc_table[esc_index];
+     295     3589269 :         char* end = begin + PATH_MAX;
+     296     3589269 :         char* p = begin;
+     297             : 
+     298             :         /* next call uses the next buffer */
+     299     3589269 :         esc_index = (esc_index + 1) % ESC_MAX;
+     300             : 
+     301             :         /* copy string with escaping */
+     302    53647568 :         while (*str) {
+     303    46469030 :                 char c = *str;
+     304             : 
+     305    46469030 :                 switch (c) {
+     306             : 
+     307           0 :                 ESCAPE('\n', 'n');
+     308           0 :                 ESCAPE('\r', 'r');
+     309           0 :                 ESCAPE(':', 'd');
+     310           0 :                 ESCAPE('\\', '\\');
+     311             : 
+     312             :                 default:
+     313    46469030 :                         if (p == end)
+     314           0 :                                 goto bail;
+     315    46469030 :                         *p++ = c;
+     316    46469030 :                         break;
+     317             :                 }
+     318             : 
+     319    46469030 :                 ++str;
+     320             :         }
+     321             : 
+     322             :         /* put final 0 */
+     323     3589269 :         if (p == end)
+     324           0 :                 goto bail;
+     325     3589269 :         *p = 0;
+     326             : 
+     327     7178538 :         return begin;
+     328             : 
+     329             : bail:
+     330             :         /* LCOV_EXCL_START */
+     331             :         log_fatal("Escape too long\n");
+     332             :         exit(EXIT_FAILURE);
+     333             :         /* LCOV_EXCL_STOP */
+     334             : }
+     335             : 
+     336           0 : char* polish(char* s)
+     337             : {
+     338           0 :         char* i = s;
+     339             : 
+     340           0 :         while (*i) {
+     341           0 :                 if (isspace(*i) || !isprint(*i))
+     342           0 :                         *i = ' ';
+     343           0 :                 ++i;
+     344             :         }
+     345             : 
+     346           0 :         return s;
+     347             : }
+     348             : 
+     349             : /****************************************************************************/
+     350             : /* path */
+     351             : 
+     352     6804242 : void pathcpy(char* dst, size_t size, const char* src)
+     353             : {
+     354     6804242 :         size_t len = strlen(src);
+     355             : 
+     356     6804242 :         if (len + 1 > size) {
+     357             :                 /* LCOV_EXCL_START */
+     358             :                 log_fatal("Path too long\n");
+     359             :                 exit(EXIT_FAILURE);
+     360             :                 /* LCOV_EXCL_STOP */
+     361             :         }
+     362             : 
+     363     6804242 :         memcpy(dst, src, len + 1);
+     364     6804242 : }
+     365             : 
+     366         237 : void pathcat(char* dst, size_t size, const char* src)
+     367             : {
+     368         237 :         size_t dst_len = strlen(dst);
+     369         237 :         size_t src_len = strlen(src);
+     370             : 
+     371         237 :         if (dst_len + src_len + 1 > size) {
+     372             :                 /* LCOV_EXCL_START */
+     373             :                 log_fatal("Path too long\n");
+     374             :                 exit(EXIT_FAILURE);
+     375             :                 /* LCOV_EXCL_STOP */
+     376             :         }
+     377             : 
+     378         237 :         memcpy(dst + dst_len, src, src_len + 1);
+     379         237 : }
+     380             : 
+     381         780 : void pathcatc(char* dst, size_t size, char c)
+     382             : {
+     383         780 :         size_t dst_len = strlen(dst);
+     384             : 
+     385         780 :         if (dst_len + 2 > size) {
+     386             :                 /* LCOV_EXCL_START */
+     387             :                 log_fatal("Path too long\n");
+     388             :                 exit(EXIT_FAILURE);
+     389             :                 /* LCOV_EXCL_STOP */
+     390             :         }
+     391             : 
+     392         780 :         dst[dst_len] = c;
+     393         780 :         dst[dst_len + 1] = 0;
+     394         780 : }
+     395             : 
+     396        8384 : void pathimport(char* dst, size_t size, const char* src)
+     397             : {
+     398        8384 :         pathcpy(dst, size, src);
+     399             : 
+     400             : #ifdef _WIN32
+     401             :         /* convert all Windows '\' to C '/' */
+     402             :         while (*dst) {
+     403             :                 if (*dst == '\\')
+     404             :                         *dst = '/';
+     405             :                 ++dst;
+     406             :         }
+     407             : #endif
+     408        8384 : }
+     409             : 
+     410       17568 : void pathexport(char* dst, size_t size, const char* src)
+     411             : {
+     412       17568 :         pathcpy(dst, size, src);
+     413             : 
+     414             : #ifdef _WIN32
+     415             :         /* convert all C '/' to Windows '\' */
+     416             :         while (*dst) {
+     417             :                 if (*dst == '/')
+     418             :                         *dst = '\\';
+     419             :                 ++dst;
+     420             :         }
+     421             : #endif
+     422       17568 : }
+     423             : 
+     424    49788380 : void pathprint(char* dst, size_t size, const char* format, ...)
+     425             : {
+     426             :         size_t len;
+     427             :         va_list ap;
+     428             : 
+     429    49788380 :         va_start(ap, format);
+     430    49788380 :         len = vsnprintf(dst, size, format, ap);
+     431    49788380 :         va_end(ap);
+     432             : 
+     433    49788380 :         if (len >= size) {
+     434             :                 /* LCOV_EXCL_START */
+     435             :                 log_fatal("Path too long\n");
+     436             :                 exit(EXIT_FAILURE);
+     437             :                 /* LCOV_EXCL_STOP */
+     438             :         }
+     439    49788380 : }
+     440             : 
+     441        7165 : void pathslash(char* dst, size_t size)
+     442             : {
+     443        7165 :         size_t len = strlen(dst);
+     444             : 
+     445        7165 :         if (len > 0 && dst[len - 1] != '/') {
+     446        5754 :                 if (len + 2 >= size) {
+     447             :                         /* LCOV_EXCL_START */
+     448             :                         log_fatal("Path too long\n");
+     449             :                         exit(EXIT_FAILURE);
+     450             :                         /* LCOV_EXCL_STOP */
+     451             :                 }
+     452             : 
+     453        5754 :                 dst[len] = '/';
+     454        5754 :                 dst[len + 1] = 0;
+     455             :         }
+     456        7165 : }
+     457             : 
+     458          30 : void pathcut(char* dst)
+     459             : {
+     460          30 :         char* slash = strrchr(dst, '/');
+     461          30 :         if (slash)
+     462          30 :                 slash[1] = 0;
+     463             :         else
+     464           0 :                 dst[0] = 0;
+     465          30 : }
+     466             : 
+     467    49935952 : int pathcmp(const char* a, const char* b)
+     468             : {
+     469             : #ifdef _WIN32
+     470             :         char ai[PATH_MAX];
+     471             :         char bi[PATH_MAX];
+     472             : 
+     473             :         /* import to convert \ to / */
+     474             :         pathimport(ai, sizeof(ai), a);
+     475             :         pathimport(bi, sizeof(bi), b);
+     476             : 
+     477             :         /* case insensitive compare in Windows */
+     478             :         return stricmp(ai, bi);
+     479             : #else
+     480    49935952 :         return strcmp(a, b);
+     481             : #endif
+     482             : }
+     483             : 
+     484             : /****************************************************************************/
+     485             : /* filesystem */
+     486             : 
+     487      794947 : int mkancestor(const char* file)
+     488             : {
+     489             :         char dir[PATH_MAX];
+     490             :         struct stat st;
+     491             :         char* c;
+     492             : 
+     493      794947 :         pathcpy(dir, sizeof(dir), file);
+     494             : 
+     495      794947 :         c = strrchr(dir, '/');
+     496      794947 :         if (!c) {
+     497             :                 /* no ancestor */
+     498           0 :                 return 0;
+     499             :         }
+     500             : 
+     501             :         /* clear the file */
+     502      794947 :         *c = 0;
+     503             : 
+     504             :         /* if it's the root dir */
+     505      794947 :         if (*dir == 0) {
+     506             :                 /* nothing more to do */
+     507           0 :                 return 0;
+     508             :         }
+     509             : 
+     510             : #ifdef _WIN32
+     511             :         /* if it's a drive specificaion like "C:" */
+     512             :         if (isalpha(dir[0]) && dir[1] == ':' && dir[2] == 0) {
+     513             :                 /* nothing more to do */
+     514             :                 return 0;
+     515             :         }
+     516             : #endif
+     517             : 
+     518             :         /*
+     519             :          * Check if the dir already exists using lstat().
+     520             :          *
+     521             :          * Note that in Windows when dealing with read-only media
+     522             :          * you cannot try to create the directory, and expecting
+     523             :          * the EEXIST error because the call will fail with ERROR_WRITE_PROTECTED.
+     524             :          *
+     525             :          * Also in Windows it's better to use lstat() than stat() because it
+     526             :          * doen't need to open the dir with CreateFile().
+     527             :          */
+     528      794947 :         if (lstat(dir, &st) == 0) {
+     529             :                 /* it already exists */
+     530      794867 :                 return 0;
+     531             :         }
+     532             : 
+     533             :         /* recursively create them all */
+     534          80 :         if (mkancestor(dir) != 0) {
+     535             :                 /* LCOV_EXCL_START */
+     536             :                 return -1;
+     537             :                 /* LCOV_EXCL_STOP */
+     538             :         }
+     539             : 
+     540             :         /* create it */
+     541          80 :         if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
+     542             :                 /* LCOV_EXCL_START */
+     543             :                 log_fatal("Error creating directory '%s'. %s.\n", dir, strerror(errno));
+     544             :                 return -1;
+     545             :                 /* LCOV_EXCL_STOP */
+     546             :         }
+     547             : 
+     548          80 :         return 0;
+     549             : }
+     550             : 
+     551      119773 : int fmtime(int f, int64_t mtime_sec, int mtime_nsec)
+     552             : {
+     553             : #if HAVE_FUTIMENS
+     554             :         struct timespec tv[2];
+     555             : #else
+     556             :         struct timeval tv[2];
+     557             : #endif
+     558             :         int ret;
+     559             : 
+     560             : #if HAVE_FUTIMENS /* futimens() is preferred because it gives nanosecond precision */
+     561      119773 :         tv[0].tv_sec = mtime_sec;
+     562      119773 :         if (mtime_nsec != STAT_NSEC_INVALID)
+     563      119773 :                 tv[0].tv_nsec = mtime_nsec;
+     564             :         else
+     565           0 :                 tv[0].tv_nsec = 0;
+     566      119773 :         tv[1].tv_sec = tv[0].tv_sec;
+     567      119773 :         tv[1].tv_nsec = tv[0].tv_nsec;
+     568             : 
+     569      119773 :         ret = futimens(f, tv);
+     570             : #elif HAVE_FUTIMES /* fallback to futimes() if nanosecond precision is not available */
+     571             :         tv[0].tv_sec = mtime_sec;
+     572             :         if (mtime_nsec != STAT_NSEC_INVALID)
+     573             :                 tv[0].tv_usec = mtime_nsec / 1000;
+     574             :         else
+     575             :                 tv[0].tv_usec = 0;
+     576             :         tv[1].tv_sec = tv[0].tv_sec;
+     577             :         tv[1].tv_usec = tv[0].tv_usec;
+     578             : 
+     579             :         ret = futimes(f, tv);
+     580             : #elif HAVE_FUTIMESAT /* fallback to futimesat() for Solaris, it only has futimesat() */
+     581             :         tv[0].tv_sec = mtime_sec;
+     582             :         if (mtime_nsec != STAT_NSEC_INVALID)
+     583             :                 tv[0].tv_usec = mtime_nsec / 1000;
+     584             :         else
+     585             :                 tv[0].tv_usec = 0;
+     586             :         tv[1].tv_sec = tv[0].tv_sec;
+     587             :         tv[1].tv_usec = tv[0].tv_usec;
+     588             : 
+     589             :         ret = futimesat(f, 0, tv);
+     590             : #else
+     591             : #error No function available to set file timestamps with sub-second precision
+     592             : #endif
+     593             : 
+     594      119773 :         return ret;
+     595             : }
+     596             : 
+     597             : /****************************************************************************/
+     598             : /* memory */
+     599             : 
+     600             : static size_t mcounter;
+     601             : 
+     602         426 : size_t malloc_counter(void)
+     603             : {
+     604         426 :         return mcounter;
+     605             : }
+     606             : 
+     607           0 : static ssize_t malloc_print(int f, const char* str)
+     608             : {
+     609           0 :         ssize_t len = 0;
+     610           0 :         while (str[len])
+     611           0 :                 ++len;
+     612           0 :         return write(f, str, len);
+     613             : }
+     614             : 
+     615           0 : static ssize_t malloc_printn(int f, size_t value)
+     616             : {
+     617             :         char buf[32];
+     618             :         int i;
+     619             : 
+     620           0 :         if (!value)
+     621           0 :                 return write(f, "0", 1);
+     622             : 
+     623           0 :         i = sizeof(buf);
+     624           0 :         while (value) {
+     625           0 :                 buf[--i] = (value % 10) + '0';
+     626           0 :                 value /= 10;
+     627             :         }
+     628             : 
+     629           0 :         return write(f, buf + i, sizeof(buf) - i);
+     630             : }
+     631             : 
+     632           0 : void malloc_fail(size_t size)
+     633             : {
+     634             :         /* don't use printf to avoid any possible extra allocation */
+     635             :         /* LCOV_EXCL_START */
+     636             :         int f = 2; /* stderr */
+     637             : 
+     638             :         malloc_print(f, "Failed for Low Memory!\n");
+     639             :         malloc_print(f, "Allocating ");
+     640             :         malloc_printn(f, size);
+     641             :         malloc_print(f, " bytes.\n");
+     642             :         malloc_print(f, "Already allocated ");
+     643             :         malloc_printn(f, malloc_counter());
+     644             :         malloc_print(f, " bytes.\n");
+     645             :         if (sizeof(void*) == 4) {
+     646             :                 malloc_print(f, "You are currently using a 32 bits executable.\n");
+     647             :                 malloc_print(f, "If you have more than 4GB of memory, please upgrade to a 64 bits one.\n");
+     648             :         }
+     649             :         /* LCOV_EXCL_STOP */
+     650           0 : }
+     651             : 
+     652    10377145 : void* malloc_nofail(size_t size)
+     653             : {
+     654    10377145 :         void* ptr = malloc(size);
+     655             : 
+     656    10377145 :         if (!ptr) {
+     657             :                 /* LCOV_EXCL_START */
+     658             :                 malloc_fail(size);
+     659             :                 exit(EXIT_FAILURE);
+     660             :                 /* LCOV_EXCL_STOP */
+     661             :         }
+     662             : 
+     663             : #ifndef CHECKER /* Don't preinitialize when running for valgrind */
+     664             :         /* Here we preinitialize the memory to ensure that the OS is really allocating it */
+     665             :         /* and not only reserving the addressable space. */
+     666             :         /* Otherwise we are risking that the OOM (Out Of Memory) killer in Linux will kill the process. */
+     667             :         /* Filling the memory doesn't ensure to disable OOM, but it increase a lot the chances to */
+     668             :         /* get a real error from malloc() instead than a process killed. */
+     669             :         /* Note that calloc() doesn't have the same effect. */
+     670    10377145 :         memset(ptr, 0xA5, size);
+     671             : #endif
+     672             : 
+     673    10377145 :         mcounter += size;
+     674             : 
+     675    10377145 :         return ptr;
+     676             : }
+     677             : 
+     678       13324 : void* calloc_nofail(size_t count, size_t size)
+     679             : {
+     680             :         void* ptr;
+     681             : 
+     682       13324 :         size *= count;
+     683             : 
+     684             :         /* see the note in malloc_nofail() of why we don't use calloc() */
+     685       13324 :         ptr = malloc(size);
+     686             : 
+     687       13324 :         if (!ptr) {
+     688             :                 /* LCOV_EXCL_START */
+     689             :                 malloc_fail(size);
+     690             :                 exit(EXIT_FAILURE);
+     691             :                 /* LCOV_EXCL_STOP */
+     692             :         }
+     693             : 
+     694       13324 :         memset(ptr, 0, size);
+     695             : 
+     696       13324 :         mcounter += size;
+     697             : 
+     698       13324 :         return ptr;
+     699             : }
+     700             : 
+     701     5657552 : char* strdup_nofail(const char* str)
+     702             : {
+     703             :         size_t size;
+     704             :         char* ptr;
+     705             : 
+     706     5657552 :         size = strlen(str) + 1;
+     707             : 
+     708     5657552 :         ptr = malloc(size);
+     709             : 
+     710     5657552 :         if (!ptr) {
+     711             :                 /* LCOV_EXCL_START */
+     712             :                 malloc_fail(size);
+     713             :                 exit(EXIT_FAILURE);
+     714             :                 /* LCOV_EXCL_STOP */
+     715             :         }
+     716             : 
+     717     5657552 :         memcpy(ptr, str, size);
+     718             : 
+     719     5657552 :         mcounter += size;
+     720             : 
+     721     5657552 :         return ptr;
+     722             : }
+     723             : 
+     724             : /****************************************************************************/
+     725             : /* smartctl */
+     726             : 
+     727             : /**
+     728             :  * Matches a string with the specified pattern.
+     729             :  * Like sscanf() a space match any sequence of spaces.
+     730             :  * Returns 0 if it matches.
+     731             :  */
+     732           0 : static int smatch(const char* str, const char* pattern)
+     733             : {
+     734           0 :         while (*pattern) {
+     735           0 :                 if (isspace(*pattern)) {
+     736           0 :                         ++pattern;
+     737           0 :                         while (isspace(*str))
+     738           0 :                                 ++str;
+     739           0 :                 } else if (*pattern == *str) {
+     740           0 :                         ++pattern;
+     741           0 :                         ++str;
+     742             :                 } else
+     743           0 :                         return -1;
+     744             :         }
+     745             : 
+     746           0 :         return 0;
+     747             : }
+     748             : 
+     749          25 : int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* smart, char* serial)
+     750             : {
+     751             :         unsigned i;
+     752             :         int inside;
+     753             : 
+     754             :         /* preclear attribute */
+     755          25 :         *serial = 0;
+     756        6525 :         for (i = 0; i < SMART_COUNT; ++i)
+     757        6500 :                 smart[i] = SMART_UNASSIGNED;
+     758             : 
+     759             :         /* read the file */
+     760          25 :         inside = 0;
+     761             :         while (1) {
+     762             :                 char buf[256];
+     763             :                 char attr[64];
+     764             :                 unsigned id;
+     765             :                 uint64_t raw;
+     766             :                 char* s;
+     767             : 
+     768          25 :                 s = fgets(buf, sizeof(buf), f);
+     769          25 :                 if (s == 0)
+     770          25 :                         break;
+     771             : 
+     772             :                 /* remove extraneous chars */
+     773           0 :                 s = polish(buf);
+     774             : 
+     775           0 :                 log_tag("smartctl:%s:%s:out: %s\n", file, name, s);
+     776             : 
+     777             :                 /* skip initial spaces */
+     778           0 :                 while (isspace(*s))
+     779           0 :                         ++s;
+     780             : 
+     781           0 :                 if (*s == 0) {
+     782           0 :                         inside = 0;
+     783           0 :                 } else if (smatch(s, "ID#") == 0) {
+     784           0 :                         inside = 1;
+     785           0 :                 } else if (smatch(s, "No Errors Logged") == 0) {
+     786           0 :                         smart[SMART_ERROR] = 0;
+     787           0 :                 } else if (sscanf(s, "ATA Error Count: %" SCNu64, &raw) == 1) {
+     788           0 :                         smart[SMART_ERROR] = raw;
+     789           0 :                 } else if (sscanf(s, "Serial Number: %63s", serial) == 1) {
+     790           0 :                 } else if (smatch(s, "Rotation Rate: Solid State") == 0) {
+     791           0 :                         smart[SMART_ROTATION_RATE] = 0;
+     792           0 :                 } else if (sscanf(s, "Rotation Rate: %" SCNu64, &smart[SMART_ROTATION_RATE]) == 1) {
+     793           0 :                 } else if (sscanf(s, "User Capacity: %63s", attr) == 1) {
+     794           0 :                         smart[SMART_SIZE] = 0;
+     795           0 :                         for (i = 0; attr[i]; ++i) {
+     796           0 :                                 if (isdigit(attr[i])) {
+     797           0 :                                         smart[SMART_SIZE] *= 10;
+     798           0 :                                         smart[SMART_SIZE] += attr[i] - '0';
+     799             :                                 }
+     800             :                         }
+     801           0 :                 } else if (inside) {
+     802           0 :                         if (sscanf(s, "%u %*s %*s %*s %*s %*s %*s %*s %*s %" SCNu64, &id, &raw) != 2) {
+     803             :                                 /* LCOV_EXCL_START */
+     804             :                                 log_fatal("Invalid smartctl line '%s'.\n", s);
+     805             :                                 return -1;
+     806             :                                 /* LCOV_EXCL_STOP */
+     807             :                         }
+     808             : 
+     809           0 :                         if (id >= 256) {
+     810             :                                 /* LCOV_EXCL_START */
+     811             :                                 log_fatal("Invalid SMART id '%u'.\n", id);
+     812             :                                 return -1;
+     813             :                                 /* LCOV_EXCL_STOP */
+     814             :                         }
+     815             : 
+     816           0 :                         smart[id] = raw;
+     817             :                 }
+     818           0 :         }
+     819             : 
+     820          25 :         return 0;
+     821             : }
+     822             : 
+     823          12 : int smartctl_flush(FILE* f, const char* file, const char* name)
+     824             : {
+     825             :         /* read the file */
+     826             :         while (1) {
+     827             :                 char buf[256];
+     828             :                 char* s;
+     829             : 
+     830          12 :                 s = fgets(buf, sizeof(buf), f);
+     831          12 :                 if (s == 0)
+     832          12 :                         break;
+     833             : 
+     834             :                 /* remove extraneous chars */
+     835           0 :                 s = polish(buf);
+     836             : 
+     837           0 :                 log_tag("smartctl:%s:%s:out: %s\n", file, name, s);
+     838           0 :         }
+     839             : 
+     840          24 :         return 0;
+     841             : }
+     842             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/sync.c.func-sort-c.html b/cov/cmdline/sync.c.func-sort-c.html new file mode 100644 index 00000000..a5040a6e --- /dev/null +++ b/cov/cmdline/sync.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/sync.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - sync.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:42645394.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled723482
state_sync63
state_sync_process62
state_hash_process6
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/sync.c.func.html b/cov/cmdline/sync.c.func.html new file mode 100644 index 00000000..f4e749c5 --- /dev/null +++ b/cov/cmdline/sync.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - cmdline/sync.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - sync.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:42645394.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
block_is_enabled723482
state_hash_process6
state_sync63
state_sync_process62
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/sync.c.gcov.html b/cov/cmdline/sync.c.gcov.html new file mode 100644 index 00000000..b7d461aa --- /dev/null +++ b/cov/cmdline/sync.c.gcov.html @@ -0,0 +1,1422 @@ + + + + + + + LCOV - lcov.info - cmdline/sync.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - sync.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:42645394.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "elem.h"
+      22             : #include "state.h"
+      23             : #include "parity.h"
+      24             : #include "handle.h"
+      25             : #include "raid/raid.h"
+      26             : 
+      27             : /****************************************************************************/
+      28             : /* hash */
+      29             : 
+      30           6 : static int state_hash_process(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, int* skip_sync)
+      31             : {
+      32             :         struct snapraid_handle* handle;
+      33             :         unsigned diskmax;
+      34             :         block_off_t i;
+      35             :         unsigned j;
+      36             :         void* buffer;
+      37             :         data_off_t countsize;
+      38             :         block_off_t countpos;
+      39             :         block_off_t countmax;
+      40             :         int ret;
+      41             :         unsigned error;
+      42             :         unsigned io_error;
+      43             : 
+      44             :         /* maps the disks to handles */
+      45           6 :         handle = handle_map(state, &diskmax);
+      46             : 
+      47             :         /* buffer for reading */
+      48           6 :         buffer = malloc_nofail(state->block_size);
+      49           6 :         if (!state->opt.skip_self)
+      50           0 :                 mtest_vector(1, state->block_size, &buffer);
+      51             : 
+      52           6 :         error = 0;
+      53           6 :         io_error = 0;
+      54             : 
+      55             :         /* first count the number of blocks to process */
+      56           6 :         countmax = 0;
+      57          42 :         for (j = 0; j < diskmax; ++j) {
+      58          36 :                 struct snapraid_disk* disk = handle[j].disk;
+      59             : 
+      60             :                 /* if no disk, nothing to check */
+      61          36 :                 if (!disk)
+      62           0 :                         continue;
+      63             : 
+      64      221700 :                 for (i = blockstart; i < blockmax; ++i) {
+      65             :                         struct snapraid_block* block;
+      66             : 
+      67      221664 :                         block = disk_block_get(disk, i);
+      68             : 
+      69             :                         /* if no file in this block, skip it */
+      70      221664 :                         if (!block_has_file(block))
+      71       15168 :                                 continue;
+      72             : 
+      73             :                         /* if the block already has a hash, skip it */
+      74      206496 :                         if (block_has_updated_hash(block))
+      75      193805 :                                 continue;
+      76             : 
+      77       12691 :                         ++countmax;
+      78             :                 }
+      79             :         }
+      80             : 
+      81             :         /* drop until now */
+      82           6 :         state_usage_waste(state);
+      83             : 
+      84           6 :         countsize = 0;
+      85           6 :         countpos = 0;
+      86           6 :         if (!state_progress_begin(state, blockstart, blockmax, countmax))
+      87           0 :                 goto end;
+      88             : 
+      89          42 :         for (j = 0; j < diskmax; ++j) {
+      90          36 :                 struct snapraid_disk* disk = handle[j].disk;
+      91             : 
+      92             :                 /* if no disk, nothing to check */
+      93          36 :                 if (!disk)
+      94           0 :                         continue;
+      95             : 
+      96      221700 :                 for (i = blockstart; i < blockmax; ++i) {
+      97             :                         snapraid_info info;
+      98             :                         int rehash;
+      99             :                         struct snapraid_block* block;
+     100             :                         int read_size;
+     101             :                         unsigned char hash[HASH_SIZE];
+     102             : 
+     103      221664 :                         block = disk_block_get(disk, i);
+     104             : 
+     105             :                         /* if no file in this block, skip it */
+     106      221664 :                         if (!block_has_file(block))
+     107      224150 :                                 continue;
+     108             : 
+     109             :                         /* if the block already has a hash, skip it */
+     110      206496 :                         if (block_has_updated_hash(block))
+     111      193805 :                                 continue;
+     112             : 
+     113             :                         /* here only CHG blocks are allowed */
+     114       12691 :                         assert(block_state_get(block) == BLOCK_STATE_CHG);
+     115             : 
+     116             :                         /* get block specific info */
+     117       12691 :                         info = info_get(&state->infoarr, i);
+     118             : 
+     119             :                         /* if we have to use the old hash */
+     120       12691 :                         rehash = info_get_rehash(info);
+     121             : 
+     122             :                         /* until now is CPU */
+     123       12691 :                         state_usage_cpu(state);
+     124             : 
+     125             :                         /* if the file is different than the current one, close it */
+     126       12691 :                         if (handle[j].file != 0 && handle[j].file != block_file_get(block)) {
+     127             :                                 /* keep a pointer at the file we are going to close for error reporting */
+     128        4710 :                                 struct snapraid_file* file = handle[j].file;
+     129        4710 :                                 ret = handle_close(&handle[j]);
+     130        4710 :                                 if (ret == -1) {
+     131             :                                         /* LCOV_EXCL_START */
+     132             :                                         /* This one is really an unexpected error, because we are only reading */
+     133             :                                         /* and closing a descriptor should never fail */
+     134             :                                         if (errno == EIO) {
+     135             :                                                 log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     136             :                                                 log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n");
+     137             :                                                 log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     138             :                                                 log_fatal("Stopping at block %u\n", i);
+     139             :                                                 ++io_error;
+     140             :                                                 goto bail;
+     141             :                                         }
+     142             : 
+     143             :                                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     144             :                                         log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n");
+     145             :                                         log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     146             :                                         log_fatal("Stopping at block %u\n", i);
+     147             :                                         ++error;
+     148             :                                         goto bail;
+     149             :                                         /* LCOV_EXCL_STOP */
+     150             :                                 }
+     151             :                         }
+     152             : 
+     153       12691 :                         ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0);
+     154       12691 :                         if (ret == -1) {
+     155             :                                 /* file we have tried to open for error reporting */
+     156           6 :                                 struct snapraid_file* file = block_file_get(block);
+     157           6 :                                 if (errno == EIO) {
+     158             :                                         /* LCOV_EXCL_START */
+     159             :                                         log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     160             :                                         log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n");
+     161             :                                         log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     162             :                                         log_fatal("Stopping at block %u\n", i);
+     163             :                                         ++io_error;
+     164             :                                         goto bail;
+     165             :                                         /* LCOV_EXCL_STOP */
+     166             :                                 }
+     167             : 
+     168           6 :                                 if (errno == ENOENT) {
+     169           2 :                                         log_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     170           2 :                                         log_error("Missing file '%s'.\n", handle[j].path);
+     171           2 :                                         log_error("WARNING! You cannot modify data disk during a sync.\n");
+     172           2 :                                         log_error("Rerun the sync command when finished.\n");
+     173           2 :                                         ++error;
+     174             :                                         /* if the file is missing, it means that it was removed during sync */
+     175             :                                         /* this isn't a serious error, so we skip this block, and continue with others */
+     176           2 :                                         continue;
+     177             :                                 }
+     178             : 
+     179           4 :                                 if (errno == EACCES) {
+     180           4 :                                         log_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     181           4 :                                         log_error("No access at file '%s'.\n", handle[j].path);
+     182           4 :                                         log_error("WARNING! Please fix the access permission in the data disk.\n");
+     183           4 :                                         log_error("Rerun the sync command when finished.\n");
+     184           4 :                                         ++error;
+     185             :                                         /* this isn't a serious error, so we skip this block, and continue with others */
+     186           4 :                                         continue;
+     187             :                                 }
+     188             : 
+     189             :                                 /* LCOV_EXCL_START */
+     190             :                                 log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     191             :                                 log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n");
+     192             :                                 log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     193             :                                 log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
+     194             :                                 ++error;
+     195             :                                 goto bail;
+     196             :                                 /* LCOV_EXCL_STOP */
+     197             :                         }
+     198             : 
+     199             :                         /* check if the file is changed */
+     200       12685 :                         if (handle[j].st.st_size != block_file_get(block)->size
+     201       12684 :                                 || handle[j].st.st_mtime != block_file_get(block)->mtime_sec
+     202       12683 :                                 || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec
+     203       12683 :                                 || handle[j].st.st_ino != block_file_get(block)->inode
+     204             :                         ) {
+     205             :                                 /* file we are processing for error reporting */
+     206           3 :                                 struct snapraid_file* file = block_file_get(block);
+     207           3 :                                 log_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub));
+     208           3 :                                 if (handle[j].st.st_size != file->size) {
+     209           1 :                                         log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size);
+     210           2 :                                 } else if (handle[j].st.st_mtime != file->mtime_sec
+     211           1 :                                         || STAT_NSEC(&handle[j].st) != file->mtime_nsec) {
+     212           1 :                                         log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st));
+     213             :                                 } else {
+     214           1 :                                         log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path);
+     215             :                                 }
+     216           3 :                                 log_error("WARNING! You cannot modify files during a sync.\n");
+     217           3 :                                 log_error("Rerun the sync command when finished.\n");
+     218           3 :                                 ++error;
+     219             :                                 /* if the file is changed, it means that it was modified during sync */
+     220             :                                 /* this isn't a serious error, so we skip this block, and continue with others */
+     221           3 :                                 continue;
+     222             :                         }
+     223             : 
+     224       12682 :                         read_size = handle_read(&handle[j], block, buffer, state->block_size, log_fatal, 0);
+     225       12682 :                         if (read_size == -1) {
+     226             :                                 /* LCOV_EXCL_START */
+     227             :                                 /* file we are processing for error reporting */
+     228             :                                 struct snapraid_file* file = block_file_get(block);
+     229             :                                 if (errno == EIO) {
+     230             :                                         log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     231             :                                         log_fatal("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n");
+     232             :                                         log_fatal("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path);
+     233             :                                         log_fatal("Stopping at block %u\n", i);
+     234             :                                         ++io_error;
+     235             :                                         goto bail;
+     236             :                                 }
+     237             : 
+     238             :                                 log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     239             :                                 log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n");
+     240             :                                 log_fatal("Ensure that file '%s' can be read.\n", handle[j].path);
+     241             :                                 log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
+     242             :                                 ++error;
+     243             :                                 goto bail;
+     244             :                                 /* LCOV_EXCL_STOP */
+     245             :                         }
+     246             : 
+     247             :                         /* until now is disk */
+     248       12682 :                         state_usage_disk(state, disk);
+     249             : 
+     250       12682 :                         countsize += read_size;
+     251             : 
+     252             :                         /* now compute the hash */
+     253       12682 :                         if (rehash) {
+     254           0 :                                 memhash(state->prevhash, state->prevhashseed, hash, buffer, read_size);
+     255             :                         } else {
+     256       12682 :                                 memhash(state->hash, state->hashseed, hash, buffer, read_size);
+     257             :                         }
+     258             : 
+     259             :                         /* copy the hash in the block */
+     260       12682 :                         memcpy(block->hash, hash, HASH_SIZE);
+     261             : 
+     262             :                         /* and mark the block as hashed */
+     263       12682 :                         block_state_set(block, BLOCK_STATE_REP);
+     264             : 
+     265             :                         /* mark the state as needing write */
+     266       12682 :                         state->need_write = 1;
+     267             : 
+     268             :                         /* count the number of processed block */
+     269       12682 :                         ++countpos;
+     270             : 
+     271             :                         /* progress */
+     272       12682 :                         if (state_progress(state, i, countpos, countmax, countsize)) {
+     273             :                                 /* LCOV_EXCL_START */
+     274             :                                 *skip_sync = 1; /* avoid to run the next sync */
+     275             :                                 break;
+     276             :                                 /* LCOV_EXCL_STOP */
+     277             :                         }
+     278             :                 }
+     279             : 
+     280             :                 /* close the last file in the disk */
+     281          36 :                 if (handle[j].file != 0) {
+     282             :                         /* keep a pointer at the file we are going to close for error reporting */
+     283           6 :                         struct snapraid_file* file = handle[j].file;
+     284           6 :                         ret = handle_close(&handle[j]);
+     285           6 :                         if (ret == -1) {
+     286             :                                 /* LCOV_EXCL_START */
+     287             :                                 /* This one is really an unexpected error, because we are only reading */
+     288             :                                 /* and closing a descriptor should never fail */
+     289             :                                 if (errno == EIO) {
+     290             :                                         log_tag("error:%u:%s:%s: Close EIO error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno));
+     291             :                                         log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n");
+     292             :                                         log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     293             :                                         log_fatal("Stopping at block %u\n", blockmax);
+     294             :                                         ++io_error;
+     295             :                                         goto bail;
+     296             :                                 }
+     297             : 
+     298             :                                 log_tag("error:%u:%s:%s: Close error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno));
+     299             :                                 log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n");
+     300             :                                 log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     301             :                                 log_fatal("Stopping at block %u\n", blockmax);
+     302             :                                 ++error;
+     303             :                                 goto bail;
+     304             :                                 /* LCOV_EXCL_STOP */
+     305             :                         }
+     306             :                 }
+     307             :         }
+     308             : 
+     309             : end:
+     310           6 :         state_progress_end(state, countpos, countmax, countsize);
+     311             : 
+     312             :         /* note that at this point no io_error is possible */
+     313             :         /* becasue at the first one we bail out */
+     314           6 :         assert(io_error == 0);
+     315             : 
+     316           6 :         if (error) {
+     317           5 :                 msg_status("\n");
+     318           5 :                 msg_status("%8u file errors\n", error);
+     319             :         } else {
+     320             :                 /* print the result only if processed something */
+     321           1 :                 if (countpos != 0)
+     322           1 :                         msg_status("Everything OK\n");
+     323             :         }
+     324             : 
+     325           6 :         if (error)
+     326           5 :                 log_fatal("WARNING! Unexpected file errors!\n");
+     327             : 
+     328           6 :         log_tag("hash_summary:error_file:%u\n", error);
+     329             : 
+     330             :         /* proceed without bailing out */
+     331           6 :         goto finish;
+     332             : 
+     333             : bail:
+     334             :         /* on bail, don't run the next sync */
+     335           0 :         *skip_sync = 1;
+     336             : 
+     337             :         /* close files left open */
+     338           0 :         for (j = 0; j < diskmax; ++j) {
+     339           0 :                 struct snapraid_file* file = handle[j].file;
+     340           0 :                 struct snapraid_disk* disk = handle[j].disk;
+     341           0 :                 ret = handle_close(&handle[j]);
+     342           0 :                 if (ret == -1) {
+     343           0 :                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     344           0 :                         log_fatal("DANGER! Unexpected close error in a data disk.\n");
+     345           0 :                         ++error;
+     346             :                         /* continue, as we are already exiting */
+     347             :                 }
+     348             :         }
+     349             : 
+     350             : finish:
+     351           6 :         free(handle);
+     352           6 :         free(buffer);
+     353             : 
+     354           6 :         if (error + io_error != 0)
+     355           5 :                 return -1;
+     356           1 :         return 0;
+     357             : }
+     358             : 
+     359             : /****************************************************************************/
+     360             : /* sync */
+     361             : 
+     362             : /**
+     363             :  * A block that failed the hash check, or that was deleted.
+     364             :  */
+     365             : struct failed_struct {
+     366             :         unsigned index; /**< Index of the failed block. */
+     367             :         unsigned size; /**< Size of the block. */
+     368             : 
+     369             :         struct snapraid_block* block; /**< The failed block, or BLOCK_DELETED for a deleted block */
+     370             : };
+     371             : 
+     372             : /**
+     373             :  * Buffer for storing the new hashes.
+     374             :  */
+     375             : struct snapraid_rehash {
+     376             :         unsigned char hash[HASH_SIZE];
+     377             :         struct snapraid_block* block;
+     378             : };
+     379             : 
+     380             : /**
+     381             :  * Check if we have to process the specified block index ::i.
+     382             :  */
+     383      723482 : static int block_is_enabled(block_off_t i, struct snapraid_handle* handle, unsigned diskmax)
+     384             : {
+     385             :         unsigned j;
+     386             :         int one_invalid;
+     387             :         int one_valid;
+     388             : 
+     389             :         /* for each disk */
+     390      723482 :         one_invalid = 0;
+     391      723482 :         one_valid = 0;
+     392     5064374 :         for (j = 0; j < diskmax; ++j) {
+     393             :                 struct snapraid_block* block;
+     394             : 
+     395             :                 /* if no disk, nothing to check */
+     396     4340892 :                 if (!handle[j].disk)
+     397        9342 :                         continue;
+     398             : 
+     399     4331550 :                 block = disk_block_get(handle[j].disk, i);
+     400             : 
+     401     4331550 :                 if (block_has_file(block))
+     402     4124374 :                         one_valid = 1;
+     403             : 
+     404     4331550 :                 if (block_has_invalid_parity(block))
+     405      356420 :                         one_invalid = 1;
+     406             :         }
+     407             : 
+     408             :         /* if none valid or none invalid, we don't need to update */
+     409      723482 :         if (!one_invalid || !one_valid)
+     410      563606 :                 return 0;
+     411             : 
+     412      159876 :         return 1;
+     413             : }
+     414             : 
+     415          62 : static int state_sync_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax)
+     416             : {
+     417             :         struct snapraid_handle* handle;
+     418             :         void* rehandle_alloc;
+     419             :         struct snapraid_rehash* rehandle;
+     420             :         unsigned diskmax;
+     421             :         block_off_t i;
+     422             :         unsigned j;
+     423             :         void* buffer_alloc;
+     424             :         void** buffer;
+     425             :         unsigned buffermax;
+     426             :         data_off_t countsize;
+     427             :         block_off_t countpos;
+     428             :         block_off_t countmax;
+     429             :         block_off_t autosavedone;
+     430             :         block_off_t autosavelimit;
+     431             :         block_off_t autosavemissing;
+     432             :         int ret;
+     433             :         unsigned error;
+     434             :         unsigned silent_error;
+     435             :         unsigned io_error;
+     436             :         time_t now;
+     437             :         struct failed_struct* failed;
+     438             :         int* failed_map;
+     439             :         unsigned l;
+     440             : 
+     441             :         /* the sync process assumes that all the hashes are correct */
+     442             :         /* including the ones from CHG and DELETED blocks */
+     443          62 :         assert(state->clear_past_hash != 0);
+     444             : 
+     445             :         /* get the present time */
+     446          62 :         now = time(0);
+     447             : 
+     448             :         /* maps the disks to handles */
+     449          62 :         handle = handle_map(state, &diskmax);
+     450             : 
+     451             :         /* rehash buffers */
+     452          62 :         rehandle = malloc_nofail_align(diskmax * sizeof(struct snapraid_rehash), &rehandle_alloc);
+     453             : 
+     454             :         /* we need 2 * data + 1 * parity + 1 * zero */
+     455          62 :         buffermax = 2 * diskmax + state->level + 1;
+     456             : 
+     457          62 :         buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc);
+     458          62 :         if (!state->opt.skip_self)
+     459           0 :                 mtest_vector(buffermax, state->block_size, buffer);
+     460             : 
+     461             :         /* fill up the zero buffer */
+     462          62 :         memset(buffer[buffermax - 1], 0, state->block_size);
+     463          62 :         raid_zero(buffer[buffermax - 1]);
+     464             : 
+     465          62 :         failed = malloc_nofail(diskmax * sizeof(struct failed_struct));
+     466          62 :         failed_map = malloc_nofail(diskmax * sizeof(unsigned));
+     467             : 
+     468          62 :         error = 0;
+     469          62 :         silent_error = 0;
+     470          62 :         io_error = 0;
+     471             : 
+     472             :         /* first count the number of blocks to process */
+     473          62 :         countmax = 0;
+     474      361803 :         for (i = blockstart; i < blockmax; ++i) {
+     475      361741 :                 if (!block_is_enabled(i, handle, diskmax))
+     476      281803 :                         continue;
+     477       79938 :                 ++countmax;
+     478             :         }
+     479             : 
+     480             :         /* compute the autosave size for all disk, even if not read */
+     481             :         /* this makes sense because the speed should be almost the same */
+     482             :         /* if the disks are read in parallel */
+     483          62 :         autosavelimit = state->autosave / (diskmax * state->block_size);
+     484          62 :         autosavemissing = countmax; /* blocks to do */
+     485          62 :         autosavedone = 0; /* blocks done */
+     486             : 
+     487             :         /* drop until now */
+     488          62 :         state_usage_waste(state);
+     489             : 
+     490          62 :         countsize = 0;
+     491          62 :         countpos = 0;
+     492          62 :         if (!state_progress_begin(state, blockstart, blockmax, countmax))
+     493           0 :                 goto end;
+     494             : 
+     495      361803 :         for (i = blockstart; i < blockmax; ++i) {
+     496             :                 unsigned failed_count;
+     497             :                 int error_on_this_block;
+     498             :                 int silent_error_on_this_block;
+     499             :                 int io_error_on_this_block;
+     500             :                 int fixed_error_on_this_block;
+     501             :                 int parity_needs_to_be_updated;
+     502             :                 snapraid_info info;
+     503             :                 int rehash;
+     504             : 
+     505      361741 :                 if (!block_is_enabled(i, handle, diskmax))
+     506      281803 :                         continue;
+     507             : 
+     508             :                 /* one more block processed for autosave */
+     509       79938 :                 ++autosavedone;
+     510       79938 :                 --autosavemissing;
+     511             : 
+     512             :                 /* by default process the block, and skip it if something go wrong */
+     513       79938 :                 error_on_this_block = 0;
+     514       79938 :                 silent_error_on_this_block = 0;
+     515       79938 :                 io_error_on_this_block = 0;
+     516       79938 :                 fixed_error_on_this_block = 0;
+     517             : 
+     518             :                 /* keep track of the number of failed blocks */
+     519       79938 :                 failed_count = 0;
+     520             : 
+     521             :                 /* get block specific info */
+     522       79938 :                 info = info_get(&state->infoarr, i);
+     523             : 
+     524             :                 /* if we have to use the old hash */
+     525       79938 :                 rehash = info_get_rehash(info);
+     526             : 
+     527             :                 /* it could happens that all the blocks are EMPTY/BLK and CHG but with the hash */
+     528             :                 /* still matching because the specific CHG block was not modified. */
+     529             :                 /* Note that CHG/DELETED blocks already present in the content file loaded */
+     530             :                 /* have the hash cleared (::clear_past_hash flag), and then they won't never match the hash. */
+     531             :                 /* We are treating only CHG blocks created at runtime. */
+     532             :                 /* In such case, we can avoid to update parity, because it would be the same as before */
+     533       79938 :                 parity_needs_to_be_updated = 0;
+     534             : 
+     535             :                 /* if the block is marked as bad, we force the parity update */
+     536             :                 /* because the bad block may be the result of a wrong parity */
+     537       79938 :                 if (info_get_bad(info))
+     538           0 :                         parity_needs_to_be_updated = 1;
+     539             : 
+     540             :                 /* for each disk, process the block */
+     541      559566 :                 for (j = 0; j < diskmax; ++j) {
+     542             :                         int read_size;
+     543             :                         unsigned char hash[HASH_SIZE];
+     544             :                         struct snapraid_block* block;
+     545             :                         unsigned block_state;
+     546      479628 :                         struct snapraid_disk* disk = handle[j].disk;
+     547             : 
+     548             :                         /* by default no rehash in case of "continue" */
+     549      479628 :                         rehandle[j].block = 0;
+     550             : 
+     551             :                         /* if the disk position is not used */
+     552      479628 :                         if (!disk) {
+     553             :                                 /* use an empty block */
+     554           0 :                                 memset(buffer[j], 0, state->block_size);
+     555       88530 :                                 continue;
+     556             :                         }
+     557             : 
+     558             :                         /* get the block */
+     559      479628 :                         block = disk_block_get(disk, i);
+     560             : 
+     561             :                         /* get the state of the block */
+     562      479628 :                         block_state = block_state_get(block);
+     563             : 
+     564             :                         /* if the block has invalid parity, */
+     565             :                         /* we have to take care of it in case of recover */
+     566      479628 :                         if (block_has_invalid_parity(block)) {
+     567             :                                 /* store it in the failed set, because */
+     568             :                                 /* the parity may be still computed with the previous content */
+     569      178210 :                                 failed[failed_count].index = j;
+     570      178210 :                                 failed[failed_count].size = state->block_size;
+     571      178210 :                                 failed[failed_count].block = block;
+     572      178210 :                                 ++failed_count;
+     573             : 
+     574             :                                 /* if the block has invalid parity, we have to update the parity */
+     575             :                                 /* to include this block change */
+     576             :                                 /* This also apply to CHG blocks, but we are going to handle */
+     577             :                                 /* later this case to do the updates only if really needed */
+     578      178210 :                                 if (block_state != BLOCK_STATE_CHG)
+     579       58416 :                                         parity_needs_to_be_updated = 1;
+     580             : 
+     581             :                                 /* note that DELETE blocks are skipped in the next check */
+     582             :                                 /* and we have to store them in the failed blocks */
+     583             :                                 /* before skipping */
+     584             : 
+     585             :                                 /* follow */
+     586             :                         }
+     587             : 
+     588             :                         /* if the block has no file, meanining that it's EMPTY or DELETED, */
+     589             :                         /* it doesn't partecipate in the new parity computation */
+     590      479628 :                         if (!block_has_file(block)) {
+     591             :                                 /* use an empty block */
+     592       87628 :                                 memset(buffer[j], 0, state->block_size);
+     593       87628 :                                 continue;
+     594             :                         }
+     595             : 
+     596             :                         /* until now is CPU */
+     597      392000 :                         state_usage_cpu(state);
+     598             : 
+     599             :                         /* if the file is different than the current one, close it */
+     600      392000 :                         if (handle[j].file != 0 && handle[j].file != block_file_get(block)) {
+     601             :                                 /* keep a pointer at the file we are going to close for error reporting */
+     602      163209 :                                 struct snapraid_file* file = handle[j].file;
+     603      163209 :                                 ret = handle_close(&handle[j]);
+     604      163209 :                                 if (ret == -1) {
+     605             :                                         /* LCOV_EXCL_START */
+     606             :                                         /* This one is really an unexpected error, because we are only reading */
+     607             :                                         /* and closing a descriptor should never fail */
+     608             :                                         if (errno == EIO) {
+     609             :                                                 log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     610             :                                                 log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n");
+     611             :                                                 log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     612             :                                                 log_fatal("Stopping at block %u\n", i);
+     613             :                                                 ++io_error;
+     614             :                                                 goto bail;
+     615             :                                         }
+     616             : 
+     617             :                                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     618             :                                         log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n");
+     619             :                                         log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     620             :                                         log_fatal("Stopping at block %u\n", i);
+     621             :                                         ++error;
+     622             :                                         goto bail;
+     623             :                                         /* LCOV_EXCL_STOP */
+     624             :                                 }
+     625             :                         }
+     626             : 
+     627      392000 :                         ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0);
+     628      392000 :                         if (ret == -1) {
+     629             :                                 /* file we have tried to open for error reporting */
+     630          12 :                                 struct snapraid_file* file = block_file_get(block);
+     631          12 :                                 if (errno == EIO) {
+     632             :                                         /* LCOV_EXCL_START */
+     633             :                                         log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     634             :                                         log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n");
+     635             :                                         log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
+     636             :                                         log_fatal("Stopping at block %u\n", i);
+     637             :                                         ++io_error;
+     638             :                                         goto bail;
+     639             :                                         /* LCOV_EXCL_STOP */
+     640             :                                 }
+     641             : 
+     642          12 :                                 if (errno == ENOENT) {
+     643           4 :                                         log_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     644           4 :                                         log_error("Missing file '%s'.\n", handle[j].path);
+     645           4 :                                         log_error("WARNING! You cannot modify data disk during a sync.\n");
+     646           4 :                                         log_error("Rerun the sync command when finished.\n");
+     647           4 :                                         ++error;
+     648             :                                         /* if the file is missing, it means that it was removed during sync */
+     649             :                                         /* this isn't a serious error, so we skip this block, and continue with others */
+     650           4 :                                         error_on_this_block = 1;
+     651           4 :                                         continue;
+     652             :                                 }
+     653             : 
+     654           8 :                                 if (errno == EACCES) {
+     655           8 :                                         log_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     656           8 :                                         log_error("No access at file '%s'.\n", handle[j].path);
+     657           8 :                                         log_error("WARNING! Please fix the access permission in the data disk.\n");
+     658           8 :                                         log_error("Rerun the sync command when finished.\n");
+     659           8 :                                         ++error;
+     660             :                                         /* this isn't a serious error, so we skip this block, and continue with others */
+     661           8 :                                         error_on_this_block = 1;
+     662           8 :                                         continue;
+     663             :                                 }
+     664             : 
+     665             :                                 /* LCOV_EXCL_START */
+     666             :                                 log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+     667             :                                 log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n");
+     668             :                                 log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
+     669             :                                 log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
+     670             :                                 ++error;
+     671             :                                 goto bail;
+     672             :                                 /* LCOV_EXCL_STOP */
+     673             :                         }
+     674             : 
+     675             :                         /* check if the file is changed */
+     676      391988 :                         if (handle[j].st.st_size != block_file_get(block)->size
+     677      391986 :                                 || handle[j].st.st_mtime != block_file_get(block)->mtime_sec
+     678      391984 :                                 || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec
+     679      391984 :                                 || handle[j].st.st_ino != block_file_get(block)->inode
+     680             :                         ) {
+     681             :                                 /* file we are processing for error reporting */
+     682           6 :                                 struct snapraid_file* file = block_file_get(block);
+     683           6 :                                 log_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub));
+     684           6 :                                 if (handle[j].st.st_size != file->size) {
+     685           2 :                                         log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size);
+     686           4 :                                 } else if (handle[j].st.st_mtime != file->mtime_sec
+     687           2 :                                         || STAT_NSEC(&handle[j].st) != file->mtime_nsec) {
+     688           2 :                                         log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st));
+     689             :                                 } else {
+     690           2 :                                         log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path);
+     691             :                                 }
+     692           6 :                                 log_error("WARNING! You cannot modify files during a sync.\n");
+     693           6 :                                 log_error("Rerun the sync command when finished.\n");
+     694           6 :                                 ++error;
+     695             :                                 /* if the file is changed, it means that it was modified during sync */
+     696             :                                 /* this isn't a serious error, so we skip this block, and continue with others */
+     697           6 :                                 error_on_this_block = 1;
+     698           6 :                                 continue;
+     699             :                         }
+     700             : 
+     701      391982 :                         read_size = handle_read(&handle[j], block, buffer[j], state->block_size, log_error, 0);
+     702      391982 :                         if (read_size == -1) {
+     703             :                                 /* LCOV_EXCL_START */
+     704             :                                 /* file we are processing for error reporting */
+     705             :                                 struct snapraid_file* file = block_file_get(block);
+     706             :                                 if (errno == EIO) {
+     707             :                                         log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     708             :                                         if (io_error >= state->opt.io_error_limit) {
+     709             :                                                 log_fatal("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n");
+     710             :                                                 log_fatal("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path);
+     711             :                                                 log_fatal("Stopping at block %u\n", i);
+     712             :                                                 ++io_error;
+     713             :                                                 goto bail;
+     714             :                                         }
+     715             : 
+     716             :                                         log_error("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
+     717             :                                         ++io_error;
+     718             :                                         io_error_on_this_block = 1;
+     719             :                                         continue;
+     720             :                                 }
+     721             : 
+     722             :                                 log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno));
+     723             :                                 log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n");
+     724             :                                 log_fatal("Ensure that file '%s' can be read.\n", handle[j].path);
+     725             :                                 log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
+     726             :                                 ++error;
+     727             :                                 goto bail;
+     728             :                                 /* LCOV_EXCL_STOP */
+     729             :                         }
+     730             : 
+     731             :                         /* until now is disk */
+     732      391982 :                         state_usage_disk(state, disk);
+     733             : 
+     734      391982 :                         countsize += read_size;
+     735             : 
+     736             :                         /* now compute the hash */
+     737      391982 :                         if (rehash) {
+     738       52257 :                                 memhash(state->prevhash, state->prevhashseed, hash, buffer[j], read_size);
+     739             : 
+     740             :                                 /* compute the new hash, and store it */
+     741       52257 :                                 rehandle[j].block = block;
+     742       52257 :                                 memhash(state->hash, state->hashseed, rehandle[j].hash, buffer[j], read_size);
+     743             :                         } else {
+     744      339725 :                                 memhash(state->hash, state->hashseed, hash, buffer[j], read_size);
+     745             :                         }
+     746             : 
+     747      391982 :                         if (block_has_updated_hash(block)) {
+     748             :                                 /* compare the hash */
+     749      272206 :                                 if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
+     750             :                                         /* file we are processing for error reporting */
+     751         884 :                                         struct snapraid_file* file = block_file_get(block);
+     752             : 
+     753             :                                         /* if the file has invalid parity, it's a REP changed during the sync */
+     754         884 :                                         if (block_has_invalid_parity(block)) {
+     755           1 :                                                 log_tag("error:%u:%s:%s: Unexpected data change\n", i, disk->name, esc(file->sub));
+     756           1 :                                                 log_error("Data change at file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
+     757           1 :                                                 log_error("WARNING! Unexpected data modification of a file without parity!\n");
+     758             : 
+     759           1 :                                                 if (file_flag_has(file, FILE_IS_COPY)) {
+     760           1 :                                                         log_error("This file was detected as a copy of another file with the same name, size,\n");
+     761           1 :                                                         log_error("and timestamp, but the file data isn't matching the assumed copy.\n");
+     762           1 :                                                         log_error("If this is a false positive, and the files are expected to be different,\n");
+     763           1 :                                                         log_error("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n");
+     764             :                                                 } else {
+     765           0 :                                                         log_error("Try removing the file from the array and rerun the 'sync' command!\n");
+     766             :                                                 }
+     767             : 
+     768           1 :                                                 ++error;
+     769             : 
+     770             :                                                 /* if the file is changed, it means that it was modified during sync */
+     771             :                                                 /* this isn't a serious error, so we skip this block, and continue with others */
+     772           1 :                                                 error_on_this_block = 1;
+     773           1 :                                                 continue;
+     774             :                                         } else { /* otherwise it's a BLK with silent error */
+     775         883 :                                                 log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
+     776         883 :                                                 log_error("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
+     777             : 
+     778             :                                                 /* save the failed block for the fix */
+     779         883 :                                                 failed[failed_count].index = j;
+     780         883 :                                                 failed[failed_count].size = read_size;
+     781         883 :                                                 failed[failed_count].block = block;
+     782         883 :                                                 ++failed_count;
+     783             : 
+     784             :                                                 /* silent errors are very rare, and are not a signal that a disk */
+     785             :                                                 /* is going to fail. So, we just continue marking the block as bad */
+     786             :                                                 /* just like in scrub */
+     787         883 :                                                 ++silent_error;
+     788         883 :                                                 silent_error_on_this_block = 1;
+     789         883 :                                                 continue;
+     790             :                                         }
+     791             :                                 }
+     792             :                         } else {
+     793             :                                 /* if until now the parity doesn't need to be updated */
+     794      119776 :                                 if (!parity_needs_to_be_updated) {
+     795             :                                         /* for sure it's a CHG block, because EMPTY are processed before with "continue" */
+     796             :                                         /* and BLK and REP have "block_has_updated_hash()" as 1, and all the others */
+     797             :                                         /* have "parity_needs_to_be_updated" already at 1 */
+     798       54370 :                                         assert(block_state_get(block) == BLOCK_STATE_CHG);
+     799             : 
+     800             :                                         /* if there is an hash */
+     801       54370 :                                         if (hash_is_real(block->hash)) {
+     802             :                                                 /* check if the hash is changed */
+     803       10710 :                                                 if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
+     804             :                                                         /* the block is different, and we must update parity */
+     805        9515 :                                                         parity_needs_to_be_updated = 1;
+     806             :                                                 }
+     807             :                                         } else {
+     808             :                                                 /* if the hash is already invalid, we update parity */
+     809       43660 :                                                 parity_needs_to_be_updated = 1;
+     810             :                                         }
+     811             :                                 }
+     812             : 
+     813             :                                 /* copy the hash in the block, but doesn't mark the block as hashed */
+     814             :                                 /* this allow in case of skipped block to do not save the failed computation */
+     815      119776 :                                 memcpy(block->hash, hash, HASH_SIZE);
+     816             : 
+     817             :                                 /* note that in case of rehash, this is the wrong hash, */
+     818             :                                 /* but it will be overwritten later */
+     819             :                         }
+     820             :                 }
+     821             : 
+     822             :                 /* if we have only silent errors we can try to fix them on-the-fly */
+     823             :                 /* note the the fix is not written to disk, but used only to */
+     824             :                 /* compute the new parity */
+     825       79938 :                 if (!error_on_this_block && !io_error_on_this_block && silent_error_on_this_block) {
+     826             :                         unsigned failed_mac;
+     827         883 :                         int something_to_recover = 0;
+     828             : 
+     829             :                         /* setup the blocks to recover */
+     830         883 :                         failed_mac = 0;
+     831        2649 :                         for (j = 0; j < failed_count; ++j) {
+     832        1766 :                                 unsigned char* block_buffer = buffer[failed[j].index];
+     833        1766 :                                 unsigned char* block_copy = buffer[diskmax + state->level + failed[j].index];
+     834        1766 :                                 unsigned block_state = block_state_get(failed[j].block);
+     835             : 
+     836             :                                 /* we try to recover only if at least one BLK is present */
+     837        1766 :                                 if (block_state == BLOCK_STATE_BLK)
+     838         883 :                                         something_to_recover = 1;
+     839             : 
+     840             :                                 /* save a copy of the content just read */
+     841             :                                 /* that it's going to be overwritten by the recovering function */
+     842        1766 :                                 memcpy(block_copy, block_buffer, state->block_size);
+     843             : 
+     844        1766 :                                 if (block_state == BLOCK_STATE_CHG
+     845         883 :                                         && hash_is_zero(failed[j].block->hash)
+     846             :                                 ) {
+     847             :                                         /* if the block was filled with 0, restore this state */
+     848             :                                         /* and avoid to recover it */
+     849           0 :                                         memset(block_buffer, 0, state->block_size);
+     850             :                                 } else {
+     851             :                                         /* if we have too many failures, we cannot recover */
+     852        1766 :                                         if (failed_mac >= state->level)
+     853           0 :                                                 break;
+     854             : 
+     855             :                                         /* otherwise it has to be recovered */
+     856        1766 :                                         failed_map[failed_mac++] = failed[j].index;
+     857             :                                 }
+     858             :                         }
+     859             : 
+     860             :                         /* if we have something to recover and enough parity */
+     861         883 :                         if (something_to_recover && j == failed_count) {
+     862             :                                 /* until now is CPU */
+     863         883 :                                 state_usage_cpu(state);
+     864             : 
+     865             :                                 /* read the parity */
+     866             :                                 /* we are sure that parity exists because */
+     867             :                                 /* we have at least one BLK block */
+     868        6181 :                                 for (l = 0; l < state->level; ++l) {
+     869        5298 :                                         ret = parity_read(parity[l], i, buffer[diskmax + l], state->block_size, log_error);
+     870        5298 :                                         if (ret == -1) {
+     871             :                                                 /* LCOV_EXCL_START */
+     872             :                                                 if (errno == EIO) {
+     873             :                                                         log_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno));
+     874             :                                                         if (io_error >= state->opt.io_error_limit) {
+     875             :                                                                 log_fatal("DANGER! Unexpected input/output read error in the %s disk, it isn't possible to sync.\n", lev_name(l));
+     876             :                                                                 log_fatal("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l));
+     877             :                                                                 log_fatal("Stopping at block %u\n", i);
+     878             :                                                                 ++io_error;
+     879             :                                                                 goto bail;
+     880             :                                                         }
+     881             : 
+     882             :                                                         log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i);
+     883             :                                                         ++io_error;
+     884             :                                                         io_error_on_this_block = 1;
+     885             :                                                         continue;
+     886             :                                                 }
+     887             : 
+     888             :                                                 log_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno));
+     889             :                                                 log_fatal("WARNING! Unexpected read error in the %s disk, it isn't possible to sync.\n", lev_name(l));
+     890             :                                                 log_fatal("Ensure that disk '%s' can be read.\n", lev_config_name(l));
+     891             :                                                 log_fatal("Stopping at block %u\n", i);
+     892             :                                                 ++error;
+     893             :                                                 goto bail;
+     894             :                                                 /* LCOV_EXCL_STOP */
+     895             :                                         }
+     896             : 
+     897             :                                         /* until now is parity */
+     898        5298 :                                         state_usage_parity(state, l);
+     899             :                                 }
+     900             : 
+     901             :                                 /* if no error in parity read */
+     902         883 :                                 if (!io_error_on_this_block) {
+     903             :                                         /* try to fix the data */
+     904             :                                         /* note that this is a simple fix algorithm, that doesn't take into */
+     905             :                                         /* account the case of a wrong parity */
+     906             :                                         /* only 'fix' supports the most advanced fixing */
+     907         883 :                                         raid_rec(failed_mac, failed_map, diskmax, state->level, state->block_size, buffer);
+     908             : 
+     909             :                                         /* check the result and prepare the data */
+     910        5298 :                                         for (j = 0; j < failed_count; ++j) {
+     911             :                                                 unsigned char hash[HASH_SIZE];
+     912        1766 :                                                 unsigned char* block_buffer = buffer[failed[j].index];
+     913        1766 :                                                 unsigned char* block_copy = buffer[diskmax + state->level + failed[j].index];
+     914        1766 :                                                 unsigned block_state = block_state_get(failed[j].block);
+     915             : 
+     916        1766 :                                                 if (block_state == BLOCK_STATE_BLK) {
+     917         883 :                                                         unsigned size = failed[j].size;
+     918             : 
+     919             :                                                         /* compute the hash of the recovered block */
+     920         883 :                                                         if (rehash) {
+     921           0 :                                                                 memhash(state->prevhash, state->prevhashseed, hash, block_buffer, size);
+     922             :                                                         } else {
+     923         883 :                                                                 memhash(state->hash, state->hashseed, hash, block_buffer, size);
+     924             :                                                         }
+     925             : 
+     926             :                                                         /* if the hash doesn't match */
+     927         883 :                                                         if (memcmp(hash, failed[j].block->hash, HASH_SIZE) != 0) {
+     928             :                                                                 /* we have not recovered */
+     929           0 :                                                                 break;
+     930             :                                                         }
+     931             : 
+     932             :                                                         /* pad with 0 if needed */
+     933         883 :                                                         if (size < state->block_size)
+     934         340 :                                                                 memset(block_buffer + size, 0, state->block_size - size);
+     935             :                                                 } else {
+     936             :                                                         /* otherwise restore the content */
+     937             :                                                         /* because we are not interested in the old state */
+     938             :                                                         /* that it's recovered for CHG, REP and DELETED blocks */
+     939         883 :                                                         memcpy(block_buffer, block_copy, state->block_size);
+     940             :                                                 }
+     941             :                                         }
+     942             : 
+     943             :                                         /* if all is processed, we have fixed it */
+     944         883 :                                         if (j == failed_count)
+     945         883 :                                                 fixed_error_on_this_block = 1;
+     946             :                                 }
+     947             :                         }
+     948             :                 }
+     949             : 
+     950             :                 /* if we have read all the data required and it's correct, proceed with the parity */
+     951       79938 :                 if (!error_on_this_block && !io_error_on_this_block
+     952       79919 :                         && (!silent_error_on_this_block || fixed_error_on_this_block)
+     953             :                 ) {
+     954             :                         /* updates the parity only if really needed */
+     955       79919 :                         if (parity_needs_to_be_updated) {
+     956             :                                 /* compute the parity */
+     957       78964 :                                 raid_gen(diskmax, state->level, state->block_size, buffer);
+     958             : 
+     959             :                                 /* until now is CPU */
+     960       78964 :                                 state_usage_cpu(state);
+     961             : 
+     962             :                                 /* write the parity */
+     963      516438 :                                 for (l = 0; l < state->level; ++l) {
+     964      437474 :                                         ret = parity_write(parity[l], i, buffer[diskmax + l], state->block_size);
+     965      437474 :                                         if (ret == -1) {
+     966             :                                                 /* LCOV_EXCL_START */
+     967             :                                                 if (errno == EIO) {
+     968             :                                                         log_tag("parity_error:%u:%s: Write EIO error. %s\n", i, lev_config_name(l), strerror(errno));
+     969             :                                                         if (io_error >= state->opt.io_error_limit) {
+     970             :                                                                 log_fatal("DANGER! Unexpected input/output write error in the %s disk, it isn't possible to sync.\n", lev_name(l));
+     971             :                                                                 log_fatal("Ensure that disk '%s' is sane and can be written.\n", lev_config_name(l));
+     972             :                                                                 log_fatal("Stopping at block %u\n", i);
+     973             :                                                                 ++io_error;
+     974             :                                                                 goto bail;
+     975             :                                                         }
+     976             : 
+     977             :                                                         log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i);
+     978             :                                                         ++io_error;
+     979             :                                                         io_error_on_this_block = 1;
+     980             :                                                         continue;
+     981             :                                                 }
+     982             : 
+     983             :                                                 log_tag("parity_error:%u:%s: Write error. %s\n", i, lev_config_name(l), strerror(errno));
+     984             :                                                 log_fatal("WARNING! Unexpected write error in the %s disk, it isn't possible to sync.\n", lev_name(l));
+     985             :                                                 log_fatal("Ensure that disk '%s' has some free space available.\n", lev_config_name(l));
+     986             :                                                 log_fatal("Stopping at block %u\n", i);
+     987             :                                                 ++error;
+     988             :                                                 goto bail;
+     989             :                                                 /* LCOV_EXCL_STOP */
+     990             :                                         }
+     991             : 
+     992             :                                         /* until now is parity */
+     993      437474 :                                         state_usage_parity(state, l);
+     994             :                                 }
+     995             :                         }
+     996             : 
+     997             :                         /* if no error in parity write */
+     998       79919 :                         if (!io_error_on_this_block) {
+     999             :                                 /* for each disk, mark the blocks as processed */
+    1000      559433 :                                 for (j = 0; j < diskmax; ++j) {
+    1001      479514 :                                         struct snapraid_block* block = BLOCK_EMPTY;
+    1002      479514 :                                         if (handle[j].disk)
+    1003      479514 :                                                 block = disk_block_get(handle[j].disk, i);
+    1004             : 
+    1005      479514 :                                         if (block == BLOCK_EMPTY) {
+    1006             :                                                 /* nothing to do */
+    1007       76559 :                                                 continue;
+    1008             :                                         }
+    1009             : 
+    1010             :                                         /* if it's a deleted block */
+    1011      402955 :                                         if (block_state_get(block) == BLOCK_STATE_DELETED) {
+    1012             :                                                 /* the parity is now updated without this block, so it's now empty */
+    1013       11067 :                                                 tommy_arrayblk_set(&handle[j].disk->blockarr, i, BLOCK_EMPTY);
+    1014       11067 :                                                 continue;
+    1015             :                                         }
+    1016             : 
+    1017             :                                         /* now all the blocks have the hash and the parity computed */
+    1018      391888 :                                         block_state_set(block, BLOCK_STATE_BLK);
+    1019             :                                 }
+    1020             :                         }
+    1021             : 
+    1022             :                         /* we update the info block only if we really have updated the parity */
+    1023             :                         /* because otherwise the time info would be misleading as we didn't */
+    1024             :                         /* wrote the parity at this time */
+    1025             :                         /* we also update the info block only if no silent error was found */
+    1026             :                         /* because has no sense to refresh the time for data that we know bad */
+    1027       79919 :                         if (parity_needs_to_be_updated
+    1028       78964 :                                 && !silent_error_on_this_block
+    1029       78081 :                                 && !io_error_on_this_block
+    1030             :                         ) {
+    1031             :                                 /* if rehash is neeed */
+    1032       78081 :                                 if (rehash) {
+    1033             :                                         /* store all the new hash already computed */
+    1034       64372 :                                         for (j = 0; j < diskmax; ++j) {
+    1035       55176 :                                                 if (rehandle[j].block)
+    1036       52257 :                                                         memcpy(rehandle[j].block->hash, rehandle[j].hash, HASH_SIZE);
+    1037             :                                         }
+    1038             :                                 }
+    1039             : 
+    1040             :                                 /* update the time info of the block */
+    1041             :                                 /* we are also clearing any previous bad and rehash flag */
+    1042       78081 :                                 info_set(&state->infoarr, i, info_make(now, 0, 0));
+    1043             :                         }
+    1044             :                 }
+    1045             : 
+    1046             :                 /* if a silent (even if corrected) or input/output error was found */
+    1047             :                 /* mark the block as bad to have check/fix to handle it */
+    1048             :                 /* because our correction is in memory only and not yet written */
+    1049       79938 :                 if (silent_error_on_this_block || io_error_on_this_block) {
+    1050             :                         /* set the error status keeping the other info */
+    1051         883 :                         info_set(&state->infoarr, i, info_set_bad(info));
+    1052             :                 }
+    1053             : 
+    1054             :                 /* mark the state as needing write */
+    1055       79938 :                 state->need_write = 1;
+    1056             : 
+    1057             :                 /* count the number of processed block */
+    1058       79938 :                 ++countpos;
+    1059             : 
+    1060             :                 /* progress */
+    1061       79938 :                 if (state_progress(state, i, countpos, countmax, countsize)) {
+    1062             :                         /* LCOV_EXCL_START */
+    1063             :                         break;
+    1064             :                         /* LCOV_EXCL_STOP */
+    1065             :                 }
+    1066             : 
+    1067             :                 /* autosave */
+    1068       79938 :                 if ((state->autosave != 0
+    1069        7262 :                         && autosavedone >= autosavelimit /* if we have reached the limit */
+    1070           0 :                         && autosavemissing >= autosavelimit) /* if we have at least a full step to do */
+    1071             :                         /* or if we have a forced autosave at the specified block */
+    1072       79938 :                         || (state->opt.force_autosave_at != 0 && state->opt.force_autosave_at == i)
+    1073             :                 ) {
+    1074           1 :                         autosavedone = 0; /* restart the counter */
+    1075             : 
+    1076             :                         /* until now is CPU */
+    1077           1 :                         state_usage_cpu(state);
+    1078             : 
+    1079           1 :                         state_progress_stop(state);
+    1080             : 
+    1081           1 :                         msg_progress("Autosaving...\n");
+    1082             : 
+    1083             :                         /* before writing the new content file we ensure that */
+    1084             :                         /* the parity is really written flushing the disk cache */
+    1085           7 :                         for (l = 0; l < state->level; ++l) {
+    1086           6 :                                 ret = parity_sync(parity[l]);
+    1087           6 :                                 if (ret == -1) {
+    1088             :                                         /* LCOV_EXCL_START */
+    1089             :                                         log_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l));
+    1090             :                                         log_fatal("DANGER! Unexpected sync error in %s disk.\n", lev_name(l));
+    1091             :                                         log_fatal("Ensure that disk '%s' is sane.\n", lev_config_name(l));
+    1092             :                                         log_fatal("Stopping at block %u\n", i);
+    1093             :                                         ++error;
+    1094             :                                         goto bail;
+    1095             :                                         /* LCOV_EXCL_STOP */
+    1096             :                                 }
+    1097             :                         }
+    1098             : 
+    1099             :                         /* now we can safely write the content file */
+    1100           1 :                         state_write(state);
+    1101             : 
+    1102           1 :                         state_progress_restart(state);
+    1103             : 
+    1104             :                         /* drop until now */
+    1105           1 :                         state_usage_waste(state);
+    1106             :                 }
+    1107             :         }
+    1108             : 
+    1109             : end:
+    1110          62 :         state_progress_end(state, countpos, countmax, countsize);
+    1111             : 
+    1112          62 :         state_usage_print(state);
+    1113             : 
+    1114             :         /* before returning we ensure that */
+    1115             :         /* the parity is really written flushing the disk cache */
+    1116         424 :         for (l = 0; l < state->level; ++l) {
+    1117         362 :                 ret = parity_sync(parity[l]);
+    1118         362 :                 if (ret == -1) {
+    1119             :                         /* LCOV_EXCL_START */
+    1120             :                         log_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l));
+    1121             :                         log_fatal("DANGER! Unexpected sync error in %s disk.\n", lev_name(l));
+    1122             :                         log_fatal("Ensure that disk '%s' is sane.\n", lev_config_name(l));
+    1123             :                         log_fatal("Stopping at block %u\n", i);
+    1124             :                         ++error;
+    1125             :                         goto bail;
+    1126             :                         /* LCOV_EXCL_STOP */
+    1127             :                 }
+    1128             :         }
+    1129             : 
+    1130          62 :         if (error || silent_error || io_error) {
+    1131          12 :                 msg_status("\n");
+    1132          12 :                 msg_status("%8u file errors\n", error);
+    1133          12 :                 msg_status("%8u io errors\n", io_error);
+    1134          12 :                 msg_status("%8u data errors\n", silent_error);
+    1135             :         } else {
+    1136             :                 /* print the result only if processed something */
+    1137          50 :                 if (countpos != 0)
+    1138          36 :                         msg_status("Everything OK\n");
+    1139             :         }
+    1140             : 
+    1141          62 :         if (error)
+    1142          11 :                 log_fatal("WARNING! Unexpected file errors!\n");
+    1143          62 :         if (io_error)
+    1144           0 :                 log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n");
+    1145          62 :         if (silent_error)
+    1146           1 :                 log_fatal("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n");
+    1147          62 :         if (io_error || silent_error) {
+    1148           1 :                 log_fatal("Use 'snapraid status' to list the bad blocks.\n");
+    1149           1 :                 log_fatal("Use 'snapraid -e fix' to recover.\n");
+    1150             :         }
+    1151             : 
+    1152          62 :         log_tag("summary:error_file:%u\n", error);
+    1153          62 :         log_tag("summary:error_io:%u\n", io_error);
+    1154          62 :         log_tag("summary:error_data:%u\n", silent_error);
+    1155          62 :         if (error + silent_error + io_error == 0)
+    1156          50 :                 log_tag("summary:exit:ok\n");
+    1157             :         else
+    1158          12 :                 log_tag("summary:exit:error\n");
+    1159          62 :         log_flush();
+    1160             : 
+    1161             : bail:
+    1162         434 :         for (j = 0; j < diskmax; ++j) {
+    1163         372 :                 struct snapraid_file* file = handle[j].file;
+    1164         372 :                 struct snapraid_disk* disk = handle[j].disk;
+    1165         372 :                 ret = handle_close(&handle[j]);
+    1166         372 :                 if (ret == -1) {
+    1167             :                         /* LCOV_EXCL_START */
+    1168             :                         log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
+    1169             :                         log_fatal("DANGER! Unexpected close error in a data disk.\n");
+    1170             :                         ++error;
+    1171             :                         /* continue, as we are already exiting */
+    1172             :                         /* LCOV_EXCL_STOP */
+    1173             :                 }
+    1174             :         }
+    1175             : 
+    1176          62 :         free(handle);
+    1177          62 :         free(buffer_alloc);
+    1178          62 :         free(buffer);
+    1179          62 :         free(rehandle_alloc);
+    1180          62 :         free(failed);
+    1181          62 :         free(failed_map);
+    1182             : 
+    1183          62 :         if (state->opt.expect_recoverable) {
+    1184           1 :                 if (error + silent_error + io_error == 0)
+    1185           0 :                         return -1;
+    1186             :         } else {
+    1187          61 :                 if (error + silent_error + io_error != 0)
+    1188          11 :                         return -1;
+    1189             :         }
+    1190          51 :         return 0;
+    1191             : }
+    1192             : 
+    1193          63 : int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount)
+    1194             : {
+    1195             :         block_off_t blockmax;
+    1196             :         block_off_t used_paritymax;
+    1197             :         block_off_t file_paritymax;
+    1198             :         data_off_t size;
+    1199             :         data_off_t out_size;
+    1200             :         int ret;
+    1201             :         struct snapraid_parity_handle parity[LEV_MAX];
+    1202             :         /* the following initialization is to avoid clang warnings about */
+    1203             :         /* potential state->level change, that never happens */
+    1204          63 :         struct snapraid_parity_handle* parity_ptr[LEV_MAX] = { 0 };
+    1205             :         unsigned unrecoverable_error;
+    1206             :         unsigned l;
+    1207          63 :         int skip_sync = 0;
+    1208             : 
+    1209          63 :         msg_progress("Initializing...\n");
+    1210             : 
+    1211          63 :         blockmax = parity_allocated_size(state);
+    1212          63 :         size = blockmax * (data_off_t)state->block_size;
+    1213             : 
+    1214             :         /* minum size of the parity files we expect */
+    1215          63 :         used_paritymax = parity_used_size(state);
+    1216             : 
+    1217             :         /* effective size of the parity files */
+    1218          63 :         file_paritymax = 0;
+    1219             : 
+    1220          63 :         if (blockstart > blockmax) {
+    1221             :                 /* LCOV_EXCL_START */
+    1222             :                 log_fatal("Error in the starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax);
+    1223             :                 exit(EXIT_FAILURE);
+    1224             :                 /* LCOV_EXCL_STOP */
+    1225             :         }
+    1226             : 
+    1227             :         /* adjust the number of block to process */
+    1228          63 :         if (blockcount != 0 && blockstart + blockcount < blockmax) {
+    1229           5 :                 blockmax = blockstart + blockcount;
+    1230             :         }
+    1231             : 
+    1232         431 :         for (l = 0; l < state->level; ++l) {
+    1233             :                 block_off_t parityblocks;
+    1234             : 
+    1235             :                 /* create the file and open for writing */
+    1236         368 :                 parity_ptr[l] = &parity[l];
+    1237         368 :                 ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode);
+    1238         368 :                 if (ret == -1) {
+    1239             :                         /* LCOV_EXCL_START */
+    1240             :                         log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
+    1241             :                         exit(EXIT_FAILURE);
+    1242             :                         /* LCOV_EXCL_STOP */
+    1243             :                 }
+    1244             : 
+    1245             :                 /* number of block in the parity file */
+    1246         368 :                 parityblocks = out_size / state->block_size;
+    1247             : 
+    1248             :                 /* if the file is too small */
+    1249         368 :                 if (parityblocks < used_paritymax) {
+    1250           0 :                         log_fatal("WARNING! The %s file %s has data only %u blocks instead of %u.\n", lev_name(l), state->parity[l].path, parityblocks, used_paritymax);
+    1251             :                 }
+    1252             : 
+    1253             :                 /* keep the smallest parity number of blocks */
+    1254         368 :                 if (l == 0 || file_paritymax > parityblocks)
+    1255          63 :                         file_paritymax = parityblocks;
+    1256             :         }
+    1257             : 
+    1258             :         /* if we do a full sync, having a wrong parity size is expected */
+    1259          63 :         if (!state->opt.force_full) {
+    1260             :                 /* if the parities are too small */
+    1261          62 :                 if (file_paritymax < used_paritymax) {
+    1262             :                         /* LCOV_EXCL_START */
+    1263             :                         log_fatal("DANGER! One or more the parity files are smaller than expected!\n");
+    1264             :                         if (file_paritymax != 0) {
+    1265             :                                 log_fatal("If this happens because you are using an old content file,\n");
+    1266             :                                 log_fatal("you can 'sync' anyway using 'snapraid --force-full sync'\n");
+    1267             :                                 log_fatal("to force a full rebuild of the parity.\n");
+    1268             :                         } else {
+    1269             :                                 log_fatal("It's possible that the parity disks are not mounted.\n");
+    1270             :                                 log_fatal("If instead you are adding a new parity level, you can 'sync' using\n");
+    1271             :                                 log_fatal("'snapraid --force-full sync' to force a full rebuild of the parity.\n");
+    1272             :                         }
+    1273             :                         exit(EXIT_FAILURE);
+    1274             :                         /* LCOV_EXCL_STOP */
+    1275             :                 }
+    1276             :         }
+    1277             : 
+    1278             :         /* now change the size of all parities */
+    1279         431 :         for (l = 0; l < state->level; ++l) {
+    1280             :                 /* change the size of the parity file, truncating or extending it */
+    1281             :                 /* from this point all the DELETED blocks after the end of the parity are invalid */
+    1282             :                 /* and they are automatically removed when we save the new content file */
+    1283         368 :                 ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate);
+    1284         368 :                 if (ret == -1) {
+    1285             :                         /* LCOV_EXCL_START */
+    1286             :                         parity_overflow(state, out_size);
+    1287             :                         log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
+    1288             :                         exit(EXIT_FAILURE);
+    1289             :                         /* LCOV_EXCL_STOP */
+    1290             :                 }
+    1291             :         }
+    1292             : 
+    1293             :         /* after resizing parity files, refresh again the free info */
+    1294          63 :         state_refresh(state);
+    1295             : 
+    1296          63 :         unrecoverable_error = 0;
+    1297             : 
+    1298          63 :         if (state->opt.prehash) {
+    1299           6 :                 msg_progress("Hashing...\n");
+    1300             : 
+    1301           6 :                 ret = state_hash_process(state, blockstart, blockmax, &skip_sync);
+    1302           6 :                 if (ret == -1) {
+    1303             :                         /* LCOV_EXCL_START */
+    1304             :                         ++unrecoverable_error;
+    1305             :                         /* continue, in case also doing the sync */
+    1306             :                         /* LCOV_EXCL_STOP */
+    1307             :                 }
+    1308             : 
+    1309           6 :                 if (state->need_write)
+    1310           3 :                         state_write(state);
+    1311             :         }
+    1312             : 
+    1313          63 :         if (!skip_sync) {
+    1314          63 :                 msg_progress("Syncing...\n");
+    1315             : 
+    1316             :                 /* skip degenerated cases of empty parity, or skipping all */
+    1317          63 :                 if (blockstart < blockmax) {
+    1318          62 :                         ret = state_sync_process(state, parity_ptr, blockstart, blockmax);
+    1319          62 :                         if (ret == -1) {
+    1320             :                                 /* LCOV_EXCL_START */
+    1321             :                                 ++unrecoverable_error;
+    1322             :                                 /* continue, as we are already exiting */
+    1323             :                                 /* LCOV_EXCL_STOP */
+    1324             :                         }
+    1325             :                 } else {
+    1326           1 :                         msg_status("Nothing to do\n");
+    1327             :                 }
+    1328             :         }
+    1329             : 
+    1330         431 :         for (l = 0; l < state->level; ++l) {
+    1331         368 :                 ret = parity_close(parity_ptr[l]);
+    1332         368 :                 if (ret == -1) {
+    1333             :                         /* LCOV_EXCL_START */
+    1334             :                         log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l));
+    1335             :                         ++unrecoverable_error;
+    1336             :                         /* continue, as we are already exiting */
+    1337             :                         /* LCOV_EXCL_STOP */
+    1338             :                 }
+    1339             :         }
+    1340             : 
+    1341             :         /* abort if required */
+    1342          63 :         if (unrecoverable_error != 0)
+    1343          11 :                 return -1;
+    1344          52 :         return 0;
+    1345             : }
+    1346             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/unix.c.func-sort-c.html b/cov/cmdline/unix.c.func-sort-c.html new file mode 100644 index 00000000..4d84cbbf --- /dev/null +++ b/cov/cmdline/unix.c.func-sort-c.html @@ -0,0 +1,164 @@ + + + + + + + LCOV - lcov.info - cmdline/unix.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - unix.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22728978.5 %
Date:2015-05-12Functions:212391.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tick1810494
open_noatime1721022
filephy11430
devuuid2129
fsinfo1903
randomize252
os_init240
os_done222
devresolve97
devread86
devtree72
tick_ms36
thread_smart25
devsmart25
thread_spindown12
devdown12
devup12
thread_spinup12
devquery4
device_thread3
devscan1
dirent_hidden0
stat_desc0
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/unix.c.func.html b/cov/cmdline/unix.c.func.html new file mode 100644 index 00000000..99e9f630 --- /dev/null +++ b/cov/cmdline/unix.c.func.html @@ -0,0 +1,164 @@ + + + + + + + LCOV - lcov.info - cmdline/unix.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - unix.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22728978.5 %
Date:2015-05-12Functions:212391.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
devdown12
device_thread3
devquery4
devread86
devresolve97
devscan1
devsmart25
devtree72
devup12
devuuid2129
dirent_hidden0
filephy11430
fsinfo1903
open_noatime1721022
os_done222
os_init240
randomize252
stat_desc0
thread_smart25
thread_spindown12
thread_spinup12
tick1810494
tick_ms36
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/unix.c.gcov.html b/cov/cmdline/unix.c.gcov.html new file mode 100644 index 00000000..46daea94 --- /dev/null +++ b/cov/cmdline/unix.c.gcov.html @@ -0,0 +1,1092 @@ + + + + + + + LCOV - lcov.info - cmdline/unix.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - unix.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:22728978.5 %
Date:2015-05-12Functions:212391.3 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #ifndef __MINGW32__ /* Only for Unix */
+      21             : 
+      22             : #include "support.h"
+      23             : 
+      24             : /**
+      25             :  * Exit codes.
+      26             :  */
+      27             : int exit_success = 0;
+      28             : int exit_failure = 1;
+      29             : int exit_sync_needed = 2;
+      30             : 
+      31     1721022 : int open_noatime(const char* file, int flags)
+      32             : {
+      33             : #ifdef O_NOATIME
+      34     1721022 :         int f = open(file, flags | O_NOATIME);
+      35             : 
+      36             :         /* only root is allowed to use O_NOATIME, in case retry without it */
+      37     1721022 :         if (f == -1 && errno == EPERM)
+      38           0 :                 f = open(file, flags);
+      39     1721022 :         return f;
+      40             : #else
+      41             :         return open(file, flags);
+      42             : #endif
+      43             : }
+      44             : 
+      45           0 : int dirent_hidden(struct dirent* dd)
+      46             : {
+      47           0 :         return dd->d_name[0] == '.';
+      48             : }
+      49             : 
+      50           0 : const char* stat_desc(struct stat* st)
+      51             : {
+      52           0 :         if (S_ISREG(st->st_mode))
+      53           0 :                 return "regular";
+      54           0 :         if (S_ISDIR(st->st_mode))
+      55           0 :                 return "directory";
+      56           0 :         if (S_ISCHR(st->st_mode))
+      57           0 :                 return "character";
+      58           0 :         if (S_ISBLK(st->st_mode))
+      59           0 :                 return "block-device";
+      60           0 :         if (S_ISFIFO(st->st_mode))
+      61           0 :                 return "fifo";
+      62           0 :         if (S_ISLNK(st->st_mode))
+      63           0 :                 return "link";
+      64           0 :         if (S_ISLNK(st->st_mode))
+      65           0 :                 return "symbolic-link";
+      66           0 :         if (S_ISSOCK(st->st_mode))
+      67           0 :                 return "socket";
+      68           0 :         return "unknown";
+      69             : }
+      70             : 
+      71             : #if HAVE_FSTATAT
+      72             : /**
+      73             :  * This function get the UUID using the /dev/disk/by-uuid/ links.
+      74             :  * Comparing with the libblkid library, it works also from not root processes.
+      75             :  */
+      76        2129 : int devuuid(uint64_t device, char* uuid, size_t uuid_size)
+      77             : {
+      78             :         int ret;
+      79             :         DIR* d;
+      80             :         struct dirent* dd;
+      81             :         struct stat st;
+      82             : 
+      83             :         /* scan the UUID directory searching for the device */
+      84        2129 :         d = opendir("/dev/disk/by-uuid");
+      85        2129 :         if (!d) {
+      86             :                 /* directory missing?, likely we are not in Linux */
+      87           0 :                 return -1;
+      88             :         }
+      89             : 
+      90       36193 :         while ((dd = readdir(d)) != 0) {
+      91             :                 /* skip "." and ".." files, UUIDs never start with '.' */
+      92       34064 :                 if (dd->d_name[0] == '.')
+      93        4258 :                         continue;
+      94             : 
+      95       29806 :                 ret = fstatat(dirfd(d), dd->d_name, &st, 0);
+      96       29806 :                 if (ret != 0) {
+      97             :                         /* generic error, ignore and continue the search */
+      98           0 :                         continue;
+      99             :                 }
+     100             : 
+     101             :                 /* if it matches, we have the uuid */
+     102       29806 :                 if (S_ISBLK(st.st_mode) && st.st_rdev == (dev_t)device) {
+     103             :                         /* found */
+     104        2129 :                         pathcpy(uuid, uuid_size, dd->d_name);
+     105        2129 :                         closedir(d);
+     106        2129 :                         return 0;
+     107             :                 }
+     108             :         }
+     109             : 
+     110             :         /* not found */
+     111           0 :         closedir(d);
+     112           0 :         return -1;
+     113             : }
+     114             : #else
+     115             : int devuuid(uint64_t device, char* uuid, size_t uuid_size)
+     116             : {
+     117             :         (void)device;
+     118             :         (void)uuid;
+     119             :         (void)uuid_size;
+     120             : 
+     121             :         /* not supported */
+     122             :         return -1;
+     123             : }
+     124             : #endif
+     125             : 
+     126       11430 : int filephy(const char* path, uint64_t size, uint64_t* physical)
+     127             : {
+     128             : #if HAVE_LINUX_FIEMAP_H
+     129             :         /* In Linux gets the real physical address of the file */
+     130             :         /* Note that FIEMAP doesn't require root permission */
+     131             :         int f;
+     132             :         struct {
+     133             :                 struct fiemap fiemap;
+     134             :                 struct fiemap_extent extent;
+     135             :         } fm;
+     136             :         unsigned int blknum;
+     137             : 
+     138       11430 :         f = open(path, O_RDONLY);
+     139       11430 :         if (f == -1) {
+     140           0 :                 return -1;
+     141             :         }
+     142             : 
+     143             :         /* first try with FIEMAP */
+     144             :         /* if works for ext2, ext3, ext4, xfs, btrfs */
+     145       11430 :         memset(&fm, 0, sizeof(fm));
+     146       11430 :         fm.fiemap.fm_start = 0;
+     147       11430 :         fm.fiemap.fm_length = ~0ULL;
+     148       11430 :         fm.fiemap.fm_flags = FIEMAP_FLAG_SYNC; /* required to ensure that just created files report a valid address and not 0 */
+     149       11430 :         fm.fiemap.fm_extent_count = 1; /* we are interested only at the first block */
+     150             : 
+     151       11430 :         if (ioctl(f, FS_IOC_FIEMAP, &fm) != -1) {
+     152       11430 :                 *physical = fm.fiemap.fm_extents[0].fe_physical + FILEPHY_REAL_OFFSET;
+     153       11430 :                 if (close(f) == -1)
+     154           0 :                         return -1;
+     155       11430 :                 return 0;
+     156             :         }
+     157             : 
+     158             :         /* if the file is empty, FIBMAP doesn't work, and we don't even try to use it */
+     159           0 :         if (size == 0) {
+     160           0 :                 *physical = FILEPHY_WITHOUT_OFFSET;
+     161           0 :                 if (close(f) == -1)
+     162           0 :                         return -1;
+     163           0 :                 return 0;
+     164             :         }
+     165             : 
+     166             :         /* then try with FIBMAP */
+     167             :         /* it works for jfs, reiserfs, ntfs-3g */
+     168             :         /* in exfat it always returns 0, that it's anyway better than the fake inodes */
+     169           0 :         blknum = 0; /* first block */
+     170           0 :         if (ioctl(f, FIBMAP, &blknum) != -1) {
+     171           0 :                 *physical = blknum + FILEPHY_REAL_OFFSET;
+     172           0 :                 if (close(f) == -1)
+     173           0 :                         return -1;
+     174           0 :                 return 0;
+     175             :         }
+     176             : 
+     177             :         /* otherwise don't use anything, and keep the directory traversal order */
+     178             :         /* at now this should happen only for vfat */
+     179             :         /* and it's surely better than using fake inodes */
+     180           0 :         *physical = FILEPHY_UNREPORTED_OFFSET;
+     181           0 :         if (close(f) == -1)
+     182           0 :                 return -1;
+     183             : #else
+     184             :         /* In a generic Unix use a dummy value for all the files */
+     185             :         /* We don't want to risk to use the inode without knowing */
+     186             :         /* if it really improves performance. */
+     187             :         /* In this way we keep them in the directory traversal order */
+     188             :         /* that at least keeps files in the same directory together. */
+     189             :         /* Note also that in newer filesystem with snapshot, like ZFS, */
+     190             :         /* the inode doesn't represent even less the disk position, because files */
+     191             :         /* are not overwritten in place, but rewritten in another location */
+     192             :         /* of the disk. */
+     193             :         *physical = FILEPHY_UNREPORTED_OFFSET;
+     194             : 
+     195             :         (void)path; /* not used here */
+     196             :         (void)size;
+     197             : #endif
+     198             : 
+     199           0 :         return 0;
+     200             : }
+     201             : 
+     202        1903 : int fsinfo(const char* path, int* has_persistent_inode, uint64_t* total_space, uint64_t* free_space)
+     203             : {
+     204             : #if HAVE_STATFS && HAVE_STRUCT_STATFS_F_TYPE
+     205             :         struct statfs st;
+     206             : 
+     207        1903 :         if (statfs(path, &st) != 0) {
+     208             :                 char dir[PATH_MAX];
+     209             :                 char* slash;
+     210             : 
+     211           6 :                 if (errno != ENOENT) {
+     212           0 :                         return -1;
+     213             :                 }
+     214             : 
+     215             :                 /* if it doesn't exist, we assume a file */
+     216             :                 /* and we check for the containing dir */
+     217           6 :                 if (strlen(path) + 1 > sizeof(dir)) {
+     218           0 :                         errno = ENAMETOOLONG;
+     219           0 :                         return -1;
+     220             :                 }
+     221             : 
+     222           6 :                 strcpy(dir, path);
+     223             : 
+     224           6 :                 slash = strrchr(dir, '/');
+     225           6 :                 if (!slash)
+     226           0 :                         return -1;
+     227             : 
+     228           6 :                 *slash = 0;
+     229           6 :                 if (statfs(dir, &st) != 0)
+     230           0 :                         return -1;
+     231             :         }
+     232             : 
+     233             :         /* to get the fs type check "man stat" or "stat -f -t FILE" */
+     234        1903 :         if (has_persistent_inode)
+     235         413 :                 switch (st.f_type) {
+     236             :                 case 0x65735546 : /* FUSE, "fuseblk" in the stat command */
+     237             :                 case 0x4d44 : /* VFAT, "msdos" in the stat command */
+     238           0 :                         *has_persistent_inode = 0;
+     239           0 :                         break;
+     240             :                 default :
+     241             :                         /* by default assume yes */
+     242         413 :                         *has_persistent_inode = 1;
+     243         413 :                         break;
+     244             :                 }
+     245             : 
+     246        1903 :         if (total_space)
+     247        1490 :                 *total_space = st.f_bsize * (uint64_t)st.f_blocks;
+     248        1903 :         if (free_space)
+     249        1490 :                 *free_space = st.f_bsize * (uint64_t)st.f_bfree;
+     250             : #else
+     251             :         (void)path;
+     252             : 
+     253             :         /* by default assume yes */
+     254             :         if (has_persistent_inode)
+     255             :                 *has_persistent_inode = 1;
+     256             :         if (total_space)
+     257             :                 *total_space = 0;
+     258             :         if (free_space)
+     259             :                 *free_space = 0;
+     260             : #endif
+     261             : 
+     262        1903 :         return 0;
+     263             : }
+     264             : 
+     265     1810494 : uint64_t tick(void)
+     266             : {
+     267             : #if HAVE_MACH_ABSOLUTE_TIME
+     268             :         /* for Mac OS X */
+     269             :         return mach_absolute_time();
+     270             : #elif HAVE_CLOCK_GETTIME && (defined(CLOCK_MONOTONIC) || defined(CLOCK_MONOTONIC_RAW))
+     271             :         /* for Linux */
+     272             :         struct timespec tv;
+     273             : 
+     274             :         /* nanosecond precision with clock_gettime() */
+     275             : #if defined(CLOCK_MONOTONIC_RAW)
+     276     1810494 :         if (clock_gettime(CLOCK_MONOTONIC_RAW, &tv) != 0) {
+     277             : #else
+     278             :         if (clock_gettime(CLOCK_MONOTONIC, &tv) != 0) {
+     279             : #endif
+     280           0 :                 return 0;
+     281             :         }
+     282             : 
+     283     1810494 :         return tv.tv_sec * 1000000000ULL + tv.tv_nsec;
+     284             : #else
+     285             :         /* other platforms */
+     286             :         struct timeval tv;
+     287             : 
+     288             :         /* microsecond precision with gettimeofday() */
+     289             :         if (gettimeofday(&tv, 0) != 0) {
+     290             :                 return 0;
+     291             :         }
+     292             : 
+     293             :         return tv.tv_sec * 1000000ULL + tv.tv_usec;
+     294             : #endif
+     295             : }
+     296             : 
+     297          36 : uint64_t tick_ms(void)
+     298             : {
+     299             :         struct timeval tv;
+     300             : 
+     301          36 :         if (gettimeofday(&tv, 0) != 0)
+     302           0 :                 return 0;
+     303             : 
+     304          36 :         return tv.tv_sec * 1000ULL + tv.tv_usec / 1000;
+     305             : }
+     306             : 
+     307         252 : int randomize(void* ptr, size_t size)
+     308             : {
+     309             :         int f;
+     310             :         ssize_t ret;
+     311             : 
+     312         252 :         f = open("/dev/urandom", O_RDONLY);
+     313         252 :         if (f == -1)
+     314           0 :                 return -1;
+     315             : 
+     316         252 :         ret = read(f, ptr, size);
+     317         252 :         if (ret < 0 || (size_t)ret != size) {
+     318           0 :                 close(f);
+     319           0 :                 return -1;
+     320             :         }
+     321             : 
+     322         252 :         if (close(f) != 0)
+     323           0 :                 return -1;
+     324             : 
+     325         252 :         return 0;
+     326             : }
+     327             : 
+     328             : /**
+     329             :  * Read a file extracting the contained device number in %u:%u format.
+     330             :  * Returns 0 on error.
+     331             :  */
+     332             : #if HAVE_LINUX_DEVICE
+     333          86 : static dev_t devread(const char* path)
+     334             : {
+     335             :         int f;
+     336             :         int ret;
+     337             :         char buf[64];
+     338             :         char* e;
+     339             :         unsigned ma;
+     340             :         unsigned mi;
+     341             : 
+     342          86 :         f = open(path, O_RDONLY);
+     343          86 :         if (f == -1) {
+     344             :                 /* LCOV_EXCL_START */
+     345             :                 log_fatal("Failed to open '%s'.\n", path);
+     346             :                 return 0;
+     347             :                 /* LCOV_EXCL_STOP */
+     348             :         }
+     349             : 
+     350          86 :         ret = read(f, buf, sizeof(buf));
+     351          86 :         if (ret < 0) {
+     352             :                 /* LCOV_EXCL_START */
+     353             :                 close(f);
+     354             :                 log_fatal("Failed to read '%s'.\n", path);
+     355             :                 return 0;
+     356             :                 /* LCOV_EXCL_STOP */
+     357             :         }
+     358          86 :         if (ret == sizeof(buf)) {
+     359             :                 /* LCOV_EXCL_START */
+     360             :                 close(f);
+     361             :                 log_fatal("Too long read '%s'.\n", path);
+     362             :                 return 0;
+     363             :                 /* LCOV_EXCL_STOP */
+     364             :         }
+     365             : 
+     366          86 :         buf[ret] = 0;
+     367             : 
+     368          86 :         ma = strtoul(buf, &e, 10);
+     369          86 :         if (*e != ':') {
+     370             :                 /* LCOV_EXCL_START */
+     371             :                 close(f);
+     372             :                 log_fatal("Invalid format in '%s' for '%s'.\n", path, buf);
+     373             :                 return 0;
+     374             :                 /* LCOV_EXCL_STOP */
+     375             :         }
+     376             : 
+     377          86 :         mi = strtoul(e+1, &e, 10);
+     378          86 :         if (*e != 0 && !isspace(*e)) {
+     379             :                 /* LCOV_EXCL_START */
+     380             :                 close(f);
+     381             :                 log_fatal("Invalid format in '%s' for '%s'.\n", path, buf);
+     382             :                 return 0;
+     383             :                 /* LCOV_EXCL_STOP */
+     384             :         }
+     385             : 
+     386          86 :         ret = close(f);
+     387          86 :         if (ret != 0) {
+     388             :                 /* LCOV_EXCL_START */
+     389             :                 log_fatal("Failed to close '%s'.\n", path);
+     390             :                 return 0;
+     391             :                 /* LCOV_EXCL_STOP */
+     392             :         }
+     393             : 
+     394          86 :         return makedev(ma, mi);
+     395             : }
+     396             : #endif
+     397             : 
+     398             : #if HAVE_LINUX_DEVICE
+     399             : /**
+     400             :  * Get the device file from the device number.
+     401             :  */
+     402          97 : static int devresolve(dev_t device, char* path, size_t path_size)
+     403             : {
+     404             :         struct stat st;
+     405             :         char buf[PATH_MAX];
+     406             :         int ret;
+     407             : 
+     408             :         /* default device path from device number */
+     409          97 :         pathprint(path, path_size, "/dev/block/%u:%u", major(device), minor(device));
+     410             : 
+     411             :         /* resolve the link from /dev/block */
+     412          97 :         ret = readlink(path, buf, sizeof(buf));
+     413          96 :         if (ret < 0) {
+     414             :                 /* LCOV_EXCL_START */
+     415             :                 log_fatal("Failed to readlink '%s'.\n", path);
+     416             :                 return -1;
+     417             :                 /* LCOV_EXCL_STOP */
+     418             :         }
+     419          96 :         if (ret == sizeof(buf)) {
+     420             :                 /* LCOV_EXCL_START */
+     421             :                 log_fatal("Too long readlink '%s'.\n", path);
+     422             :                 return -1;
+     423             :                 /* LCOV_EXCL_STOP */
+     424             :         }
+     425             : 
+     426          96 :         buf[ret] = 0;
+     427             : 
+     428          96 :         if (buf[0] != '.' || buf[1] != '.' || buf[2] != '/') {
+     429             :                 /* LCOV_EXCL_START */
+     430             :                 log_fatal("Unexpected link '%s' at '%s'.\n", buf, path);
+     431             :                 return -1;
+     432             :                 /* LCOV_EXCL_STOP */
+     433             :         }
+     434             : 
+     435             :         /* set the real device path */
+     436          97 :         pathprint(path, path_size, "/dev/%s", buf + 3);
+     437             : 
+     438             :         /* check the device */
+     439          97 :         if (stat(path, &st) != 0) {
+     440             :                 /* LCOV_EXCL_START */
+     441             :                 log_fatal("Failed to stat '%s'.\n", path);
+     442             :                 return -1;
+     443             :                 /* LCOV_EXCL_STOP */
+     444             :         }
+     445          96 :         if (st.st_rdev != device) {
+     446             :                 /* LCOV_EXCL_START */
+     447             :                 log_fatal("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path);
+     448             :                 return -1;
+     449             :                 /* LCOV_EXCL_STOP */
+     450             :         }
+     451             : 
+     452          96 :         return 0;
+     453             : }
+     454             : #endif
+     455             : 
+     456             : /**
+     457             :  * Read a device tree filling the specified list of disk_t entries.
+     458             :  */
+     459             : #if HAVE_LINUX_DEVICE
+     460          72 : static int devtree(const char* name, const char* custom, dev_t device, devinfo_t* parent, tommy_list* list)
+     461             : {
+     462             :         char path[PATH_MAX];
+     463             :         DIR* d;
+     464          72 :         int slaves = 0;
+     465             : 
+     466          72 :         pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/slaves", major(device), minor(device));
+     467             : 
+     468             :         /* check if there is a slaves list */
+     469          72 :         d = opendir(path);
+     470          72 :         if (d != 0) {
+     471             :                 struct dirent* dd;
+     472             : 
+     473         180 :                 while ((dd = readdir(d)) != 0) {
+     474         108 :                         if (dd->d_name[0] != '.') {
+     475             :                                 /* for each slave, expand the full potential tree */
+     476          36 :                                 pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/slaves/%s/dev", major(device), minor(device), dd->d_name);
+     477             : 
+     478          36 :                                 device = devread(path);
+     479          36 :                                 if (!device) {
+     480             :                                         /* LCOV_EXCL_START */
+     481             :                                         closedir(d);
+     482             :                                         return -1;
+     483             :                                         /* LCOV_EXCL_STOP */
+     484             :                                 }
+     485             : 
+     486          36 :                                 if (devtree(name, custom, device, parent, list) != 0) {
+     487             :                                         /* LCOV_EXCL_START */
+     488             :                                         closedir(d);
+     489             :                                         return -1;
+     490             :                                         /* LCOV_EXCL_STOP */
+     491             :                                 }
+     492             : 
+     493          36 :                                 ++slaves;
+     494             :                         }
+     495             :                 }
+     496             : 
+     497          36 :                 closedir(d);
+     498             :         }
+     499             : 
+     500             :         /* if no slaves found */
+     501          72 :         if (!slaves) {
+     502             :                 /* this is a raw device */
+     503             :                 devinfo_t* devinfo;
+     504             : 
+     505             :                 /* check if it's a real device */
+     506          36 :                 pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/device", major(device), minor(device));
+     507          36 :                 if (access(path, F_OK) != 0) {
+     508             :                         /* get the parent device */
+     509          36 :                         pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/../dev", major(device), minor(device));
+     510             : 
+     511          36 :                         device = devread(path);
+     512          36 :                         if (!device) {
+     513             :                                 /* LCOV_EXCL_START */
+     514             :                                 return -1;
+     515             :                                 /* LCOV_EXCL_STOP */
+     516             :                         }
+     517             :                 }
+     518             : 
+     519             :                 /* get the device file */
+     520          36 :                 if (devresolve(device, path, sizeof(path)) != 0) {
+     521             :                         /* LCOV_EXCL_START */
+     522             :                         return -1;
+     523             :                         /* LCOV_EXCL_STOP */
+     524             :                 }
+     525             : 
+     526          36 :                 devinfo = calloc_nofail(1, sizeof(devinfo_t));
+     527             : 
+     528          36 :                 devinfo->device = device;
+     529          36 :                 pathcpy(devinfo->name, sizeof(devinfo->name), name);
+     530          36 :                 pathcpy(devinfo->smartctl, sizeof(devinfo->smartctl), custom);
+     531          36 :                 pathcpy(devinfo->file, sizeof(devinfo->file), path);
+     532          36 :                 devinfo->parent = parent;
+     533             : 
+     534             :                 /* insert in the list */
+     535          36 :                 tommy_list_insert_tail(list, &devinfo->node, devinfo);
+     536             :         }
+     537             : 
+     538          72 :         return 0;
+     539             : }
+     540             : #endif
+     541             : 
+     542             : /**
+     543             :  * Scan all the devices.
+     544             :  *
+     545             :  * If a device is already in, it's not added again.
+     546             :  */
+     547             : #if HAVE_LINUX_DEVICE
+     548           1 : static int devscan(tommy_list* list)
+     549             : {
+     550             :         char dir[PATH_MAX];
+     551             :         DIR* d;
+     552             :         struct dirent* dd;
+     553             : 
+     554           1 :         pathprint(dir, sizeof(dir), "/sys/dev/block/");
+     555             : 
+     556             :         /* check if there is a slaves list */
+     557           1 :         d = opendir(dir);
+     558           1 :         if (d == 0) {
+     559             :                 /* LCOV_EXCL_START */
+     560             :                 log_fatal("Failed to open dir '%s'.\n", dir);
+     561             :                 return -1;
+     562             :                 /* LCOV_EXCL_STOP */
+     563             :         }
+     564             : 
+     565          75 :         while ((dd = readdir(d)) != 0) {
+     566          73 :                 if (dd->d_name[0] != '.') {
+     567             :                         char path[PATH_MAX];
+     568             : 
+     569          71 :                         pathprint(path, sizeof(path), "/sys/dev/block/%s/device", dd->d_name);
+     570             : 
+     571             :                         /* check if it's a real device */
+     572          71 :                         if (access(path, F_OK) == 0) {
+     573             :                                 tommy_node* i;
+     574             :                                 dev_t device;
+     575             : 
+     576          14 :                                 pathprint(path, sizeof(path), "/sys/dev/block/%s/dev", dd->d_name);
+     577             : 
+     578          14 :                                 device = devread(path);
+     579          14 :                                 if (!device) {
+     580             :                                         /* LCOV_EXCL_START */
+     581             :                                         closedir(d);
+     582             :                                         return -1;
+     583             :                                         /* LCOV_EXCL_STOP */
+     584             :                                 }
+     585             : 
+     586             :                                 /* check if already present */
+     587         248 :                                 for (i = tommy_list_head(list); i != 0; i = i->next) {
+     588         235 :                                         devinfo_t* devinfo = i->data;
+     589         235 :                                         if (devinfo->device == device)
+     590           1 :                                                 break;
+     591             :                                 }
+     592             : 
+     593             :                                 /* if not found */
+     594          14 :                                 if (i == 0) {
+     595             :                                         devinfo_t* devinfo;
+     596             : 
+     597             :                                         /* get the device file */
+     598          13 :                                         if (devresolve(device, path, sizeof(path)) != 0) {
+     599             :                                                 /* LCOV_EXCL_START */
+     600             :                                                 closedir(d);
+     601             :                                                 return -1;
+     602             :                                                 /* LCOV_EXCL_STOP */
+     603             :                                         }
+     604             : 
+     605          13 :                                         devinfo = calloc_nofail(1, sizeof(devinfo_t));
+     606             : 
+     607          13 :                                         devinfo->device = device;
+     608          13 :                                         pathcpy(devinfo->file, sizeof(devinfo->file), path);
+     609             : 
+     610             :                                         /* insert in the list */
+     611          13 :                                         tommy_list_insert_tail(list, &devinfo->node, devinfo);
+     612             :                                 }
+     613             :                         }
+     614             :                 }
+     615             :         }
+     616             : 
+     617           1 :         closedir(d);
+     618           1 :         return 0;
+     619             : }
+     620             : #endif
+     621             : 
+     622             : /**
+     623             :  * Gets SMART attributes.
+     624             :  */
+     625          25 : static int devsmart(dev_t device, const char* name, const char* custom, uint64_t* smart, char* serial)
+     626             : {
+     627             :         char cmd[128];
+     628             :         char file[128];
+     629             :         FILE* f;
+     630             :         int ret;
+     631             : 
+     632          25 :         snprintf(file, sizeof(file), "/dev/block/%u:%u", major(device), minor(device));
+     633             : 
+     634             :         /* if there is a custom command */
+     635          25 :         if (custom[0]) {
+     636             :                 char option[128];
+     637           2 :                 snprintf(option, sizeof(option), custom, file);
+     638           2 :                 snprintf(cmd, sizeof(cmd), "smartctl -a %s", option);
+     639             :         } else {
+     640          23 :                 snprintf(cmd, sizeof(cmd), "smartctl -a %s", file);
+     641             :         }
+     642             : 
+     643          25 :         log_tag("smartctl:%s:%s:run: %s\n", file, name, cmd);
+     644             : 
+     645          25 :         f = popen(cmd, "r");
+     646          25 :         if (!f) {
+     647             :                 /* LCOV_EXCL_START */
+     648             :                 log_fatal("Failed to run '%s' (from popen).\n", cmd);
+     649             :                 return -1;
+     650             :                 /* LCOV_EXCL_STOP */
+     651             :         }
+     652             : 
+     653          25 :         if (smartctl_attribute(f, file, name, smart, serial) != 0) {
+     654             :                 /* LCOV_EXCL_START */
+     655             :                 pclose(f);
+     656             :                 return -1;
+     657             :                 /* LCOV_EXCL_STOP */
+     658             :         }
+     659             : 
+     660          25 :         ret = pclose(f);
+     661             : 
+     662          25 :         log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret);
+     663             : 
+     664          25 :         if (!WIFEXITED(ret)) {
+     665             :                 /* LCOV_EXCL_START */
+     666             :                 log_fatal("Failed to run '%s' (not exited).\n", cmd);
+     667             :                 return -1;
+     668             :                 /* LCOV_EXCL_STOP */
+     669             :         }
+     670          25 :         if (WEXITSTATUS(ret) == 127) {
+     671             :                 /* LCOV_EXCL_START */
+     672             :                 log_fatal("Failed to run '%s' (from sh).\n", cmd);
+     673             :                 return -1;
+     674             :                 /* LCOV_EXCL_STOP */
+     675             :         }
+     676             : 
+     677             :         /* store the return smartctl return value */
+     678           0 :         smart[SMART_FLAGS] = WEXITSTATUS(ret);
+     679             : 
+     680           0 :         return 0;
+     681             : }
+     682             : 
+     683             : /**
+     684             :  * Spin down a specific device.
+     685             :  */
+     686             : #if HAVE_LINUX_DEVICE
+     687          12 : static int devdown(dev_t device, const char* name, const char* custom)
+     688             : {
+     689             :         char cmd[128];
+     690             :         char file[128];
+     691             :         FILE* f;
+     692             :         int ret;
+     693             : 
+     694          12 :         snprintf(file, sizeof(file), "/dev/block/%u:%u", major(device), minor(device));
+     695             : 
+     696             :         /* if there is a custom command */
+     697          12 :         if (custom[0]) {
+     698             :                 char option[128];
+     699           2 :                 snprintf(option, sizeof(option), custom, file);
+     700           2 :                 snprintf(cmd, sizeof(cmd), "smartctl -s standby,now %s", option);
+     701             :         } else {
+     702          10 :                 snprintf(cmd, sizeof(cmd), "smartctl -s standby,now %s", file);
+     703             :         }
+     704             : 
+     705          12 :         log_tag("smartctl:%s:%s:run: %s\n", file, name, cmd);
+     706             : 
+     707          12 :         f = popen(cmd, "r");
+     708          12 :         if (!f) {
+     709             :                 /* LCOV_EXCL_START */
+     710             :                 log_fatal("Failed to run '%s' (from popen).\n", cmd);
+     711             :                 return -1;
+     712             :                 /* LCOV_EXCL_STOP */
+     713             :         }
+     714             : 
+     715          12 :         if (smartctl_flush(f, file, name) != 0) {
+     716             :                 /* LCOV_EXCL_START */
+     717             :                 pclose(f);
+     718             :                 return -1;
+     719             :                 /* LCOV_EXCL_STOP */
+     720             :         }
+     721             : 
+     722          12 :         ret = pclose(f);
+     723             : 
+     724          12 :         log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret);
+     725             : 
+     726          12 :         if (!WIFEXITED(ret)) {
+     727             :                 /* LCOV_EXCL_START */
+     728             :                 log_fatal("Failed to run '%s' (not exited).\n", cmd);
+     729             :                 return -1;
+     730             :                 /* LCOV_EXCL_STOP */
+     731             :         }
+     732          12 :         if (WEXITSTATUS(ret) == 127) {
+     733             :                 /* LCOV_EXCL_START */
+     734             :                 log_fatal("Failed to run '%s' (from sh).\n", cmd);
+     735             :                 return -1;
+     736             :                 /* LCOV_EXCL_STOP */
+     737             :         }
+     738           0 :         if (WEXITSTATUS(ret) != 0) {
+     739             :                 /* LCOV_EXCL_START */
+     740             :                 log_fatal("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret));
+     741             :                 return -1;
+     742             :                 /* LCOV_EXCL_STOP */
+     743             :         }
+     744             : 
+     745           0 :         return 0;
+     746             : }
+     747             : #endif
+     748             : 
+     749             : /**
+     750             :  * Spin up a device.
+     751             :  *
+     752             :  * There isn't a defined way to spin up a device,
+     753             :  * so we just do a generic write.
+     754             :  */
+     755          12 : static int devup(const char* mount)
+     756             : {
+     757             :         int ret;
+     758             :         char path[PATH_MAX];
+     759             : 
+     760             :         /* add a temporary name used for writing */
+     761          12 :         pathprint(path, sizeof(path), "%s.snapraid-spinup", mount);
+     762             : 
+     763             :         /* do a generic write, and immediately undo it */
+     764          12 :         ret = mkdir(path, 0);
+     765          12 :         if (ret != 0 && errno != EEXIST) {
+     766             :                 /* LCOV_EXCL_START */
+     767             :                 log_fatal("Failed to create dir '%s'.\n", path);
+     768             :                 return -1;
+     769             :                 /* LCOV_EXCL_STOP */
+     770             :         }
+     771             : 
+     772             :         /* removes the just created dir */
+     773          12 :         rmdir(path);
+     774             : 
+     775          12 :         return 0;
+     776             : }
+     777             : 
+     778             : /**
+     779             :  * Thread for spinning up.
+     780             :  *
+     781             :  * Note that filling up the devinfo object is done inside this thread,
+     782             :  * to avoid to block the main thread if the device need to be spin up
+     783             :  * to handle stat/resolve requests.
+     784             :  */
+     785          12 : static void* thread_spinup(void* arg)
+     786             : {
+     787          12 :         devinfo_t* devinfo = arg;
+     788             :         struct stat st;
+     789             :         uint64_t start;
+     790             : 
+     791          12 :         start = tick_ms();
+     792             : 
+     793             :         /* first get the device number, this usually doesn't trigger a thread_spinup */
+     794          12 :         if (stat(devinfo->mount, &st) != 0) {
+     795             :                 /* LCOV_EXCL_START */
+     796             :                 log_fatal("Failed to stat device '%s'.\n", devinfo->mount);
+     797             :                 return (void*)-1;
+     798             :                 /* LCOV_EXCL_STOP */
+     799             :         }
+     800             : 
+     801             :         /* set the device number for printing */
+     802          12 :         devinfo->device = st.st_dev;
+     803             : 
+     804             : #if HAVE_LINUX_DEVICE
+     805             :         /* get the device file, but only in Linux and only for the message */
+     806          12 :         if (devresolve(devinfo->device, devinfo->file, sizeof(devinfo->file)) != 0) {
+     807             :                 /* LCOV_EXCL_START */
+     808             :                 return (void*)-1;
+     809             :                 /* LCOV_EXCL_STOP */
+     810             :         }
+     811             : #endif
+     812             : 
+     813          12 :         if (devup(devinfo->mount) != 0) {
+     814             :                 /* LCOV_EXCL_START */
+     815             :                 return (void*)-1;
+     816             :                 /* LCOV_EXCL_STOP */
+     817             :         }
+     818             : 
+     819             : #if HAVE_LINUX_DEVICE
+     820          12 :         msg_status("Spunup device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
+     821             : #else
+     822             :         msg_status("Spunup device '%u:%u' for disk '%s' in %" PRIu64 " ms.\n", major(devinfo->device), minor(devinfo->device), devinfo->name, tick_ms() - start);
+     823             : #endif
+     824             : 
+     825          12 :         return 0;
+     826             : }
+     827             : 
+     828             : /**
+     829             :  * Thread for spinning down.
+     830             :  */
+     831          12 : static void* thread_spindown(void* arg)
+     832             : {
+     833             : #if HAVE_LINUX_DEVICE
+     834          12 :         devinfo_t* devinfo = arg;
+     835             :         uint64_t start;
+     836             : 
+     837          12 :         start = tick_ms();
+     838             : 
+     839          12 :         if (devdown(devinfo->device, devinfo->name, devinfo->smartctl) != 0) {
+     840             :                 /* LCOV_EXCL_START */
+     841             :                 return (void*)-1;
+     842             :                 /* LCOV_EXCL_STOP */
+     843             :         }
+     844             : 
+     845           0 :         msg_status("Spundown device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
+     846             : 
+     847           0 :         return 0;
+     848             : #else
+     849             :         (void)arg;
+     850             :         return (void*)-1;
+     851             : #endif
+     852             : }
+     853             : 
+     854             : /**
+     855             :  * Thread for getting smart info.
+     856             :  */
+     857          25 : static void* thread_smart(void* arg)
+     858             : {
+     859          25 :         devinfo_t* devinfo = arg;
+     860             : 
+     861          25 :         if (devsmart(devinfo->device, devinfo->name, devinfo->smartctl, devinfo->smart, devinfo->smart_serial) != 0) {
+     862             :                 /* LCOV_EXCL_START */
+     863             :                 return (void*)-1;
+     864             :                 /* LCOV_EXCL_STOP */
+     865             :         }
+     866             : 
+     867           0 :         return 0;
+     868             : }
+     869             : 
+     870           3 : static int device_thread(tommy_list* list, void* (*func)(void* arg))
+     871             : {
+     872           3 :         int fail = 0;
+     873             :         tommy_node* i;
+     874             : 
+     875             : #if HAVE_PTHREAD_CREATE
+     876             :         /* starts all threads */
+     877          52 :         for (i = tommy_list_head(list); i != 0; i = i->next) {
+     878          49 :                 devinfo_t* devinfo = i->data;
+     879             : 
+     880          49 :                 if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) {
+     881             :                         /* LCOV_EXCL_START */
+     882             :                         log_fatal("Failed to create thread.\n");
+     883             :                         exit(EXIT_FAILURE);
+     884             :                         /* LCOV_EXCL_STOP */
+     885             :                 }
+     886             :         }
+     887             : 
+     888             :         /* joins all threads */
+     889          52 :         for (i = tommy_list_head(list); i != 0; i = i->next) {
+     890          49 :                 devinfo_t* devinfo = i->data;
+     891             :                 void* retval;
+     892             : 
+     893          49 :                 if (pthread_join(devinfo->thread, &retval) != 0) {
+     894             :                         /* LCOV_EXCL_START */
+     895             :                         log_fatal("Failed to join thread.\n");
+     896             :                         exit(EXIT_FAILURE);
+     897             :                         /* LCOV_EXCL_STOP */
+     898             :                 }
+     899             : 
+     900          49 :                 if (retval != 0)
+     901          37 :                         ++fail;
+     902             :         }
+     903             : #else
+     904             :         for (i = tommy_list_head(list); i != 0; i = i->next) {
+     905             :                 devinfo_t* devinfo = i->data;
+     906             : 
+     907             :                 if (func(devinfo) != 0)
+     908             :                         ++fail;
+     909             :         }
+     910             : #endif
+     911           3 :         if (fail != 0) {
+     912             :                 /* LCOV_EXCL_START */
+     913             :                 return -1;
+     914             :                 /* LCOV_EXCL_STOP */
+     915             :         }
+     916             : 
+     917           1 :         return 0;
+     918             : }
+     919             : 
+     920           4 : int devquery(tommy_list* high, tommy_list* low, int operation)
+     921             : {
+     922             :         tommy_node* i;
+     923           4 :         void* (*func)(void* arg) = 0;
+     924             : 
+     925             : #if HAVE_LINUX_DEVICE
+     926           4 :         if (operation != DEVICE_UP) {
+     927             :                 struct stat st;
+     928             :                 /* sysfs and devfs interfaces are required */
+     929           3 :                 if (stat("/sys/dev/block", &st) != 0) {
+     930             :                         /* LCOV_EXCL_START */
+     931             :                         log_fatal("Missing interface /sys/dev/block.\n");
+     932             :                         return -1;
+     933             :                         /* LCOV_EXCL_STOP */
+     934             :                 }
+     935           3 :                 if (stat("/dev/block", &st) != 0) {
+     936             :                         /* LCOV_EXCL_START */
+     937             :                         log_fatal("Missing interface /dev/block.\n");
+     938             :                         return -1;
+     939             :                         /* LCOV_EXCL_STOP */
+     940             :                 }
+     941             : 
+     942             :                 /* for each device */
+     943          39 :                 for (i = tommy_list_head(high); i != 0; i = i->next) {
+     944          36 :                         devinfo_t* devinfo = i->data;
+     945             : 
+     946             :                         /* get the device file */
+     947          36 :                         if (devresolve(devinfo->device, devinfo->file, sizeof(devinfo->file)) != 0) {
+     948             :                                 /* LCOV_EXCL_START */
+     949             :                                 log_fatal("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
+     950             :                                 return -1;
+     951             :                                 /* LCOV_EXCL_STOP */
+     952             :                         }
+     953             : 
+     954             :                         /* expand the tree of devices */
+     955          36 :                         if (devtree(devinfo->name, devinfo->smartctl, devinfo->device, devinfo, low) != 0) {
+     956             :                                 /* LCOV_EXCL_START */
+     957             :                                 log_fatal("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
+     958             :                                 return -1;
+     959             :                                 /* LCOV_EXCL_STOP */
+     960             :                         }
+     961             :                 }
+     962             :         }
+     963             : #endif
+     964             : 
+     965           4 :         if (operation == DEVICE_UP) {
+     966             :                 /* duplicate the high */
+     967          13 :                 for (i = tommy_list_head(high); i != 0; i = i->next) {
+     968          12 :                         devinfo_t* devinfo = i->data;
+     969             :                         devinfo_t* entry;
+     970             : 
+     971          12 :                         entry = calloc_nofail(1, sizeof(devinfo_t));
+     972             : 
+     973          12 :                         entry->device = devinfo->device;
+     974          12 :                         pathcpy(entry->name, sizeof(entry->name), devinfo->name);
+     975          12 :                         pathcpy(entry->mount, sizeof(entry->mount), devinfo->mount);
+     976             : 
+     977             :                         /* insert in the high */
+     978          12 :                         tommy_list_insert_tail(low, &entry->node, entry);
+     979             :                 }
+     980             :         }
+     981             : 
+     982             : #if HAVE_LINUX_DEVICE
+     983             :         /* add other devices */
+     984           4 :         if (operation == DEVICE_SMART) {
+     985           1 :                 if (devscan(low) != 0) {
+     986             :                         /* LCOV_EXCL_START */
+     987             :                         log_fatal("Failed to list other devices.\n");
+     988             :                         return -1;
+     989             :                         /* LCOV_EXCL_STOP */
+     990             :                 }
+     991             :         }
+     992             : #endif
+     993             : 
+     994           4 :         switch (operation) {
+     995           1 :         case DEVICE_UP : func = thread_spinup; break;
+     996           1 :         case DEVICE_DOWN : func = thread_spindown; break;
+     997           1 :         case DEVICE_SMART : func = thread_smart; break;
+     998             :         }
+     999             : 
+    1000           4 :         if (!func)
+    1001           1 :                 return 0;
+    1002             : 
+    1003           3 :         return device_thread(low, func);
+    1004             : }
+    1005             : 
+    1006         240 : void os_init(int opt)
+    1007             : {
+    1008             :         (void)opt;
+    1009         240 : }
+    1010             : 
+    1011         222 : void os_done(void)
+    1012             : {
+    1013         222 : }
+    1014             : 
+    1015             : #endif
+    1016             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.c.func-sort-c.html b/cov/cmdline/util.c.func-sort-c.html new file mode 100644 index 00000000..ce6c9cb6 --- /dev/null +++ b/cov/cmdline/util.c.func-sort-c.html @@ -0,0 +1,124 @@ + + + + + + + LCOV - lcov.info - cmdline/util.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:677095.7 %
Date:2015-05-12Functions:1313100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
util_rotl32893240076
util_rotl64461035788
memhash5646915
crc32c_x86337096
malloc_nofail_test723
mtest_vector723
crc32c_gen304
crc32c_init256
lock_lock232
lock_unlock215
malloc_nofail_vector_align193
malloc_nofail_align75
hash_config_name42
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.c.func.html b/cov/cmdline/util.c.func.html new file mode 100644 index 00000000..721a5ee1 --- /dev/null +++ b/cov/cmdline/util.c.func.html @@ -0,0 +1,124 @@ + + + + + + + LCOV - lcov.info - cmdline/util.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:677095.7 %
Date:2015-05-12Functions:1313100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
crc32c_gen304
crc32c_init256
crc32c_x86337096
hash_config_name42
lock_lock232
lock_unlock215
malloc_nofail_align75
malloc_nofail_test723
malloc_nofail_vector_align193
memhash5646915
mtest_vector723
util_rotl32893240076
util_rotl64461035788
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.c.gcov.html b/cov/cmdline/util.c.gcov.html new file mode 100644 index 00000000..e7e19780 --- /dev/null +++ b/cov/cmdline/util.c.gcov.html @@ -0,0 +1,635 @@ + + + + + + + LCOV - lcov.info - cmdline/util.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:677095.7 %
Date:2015-05-12Functions:1313100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #include "portable.h"
+      19             : 
+      20             : #include "support.h"
+      21             : #include "util.h"
+      22             : #include "raid/cpu.h"
+      23             : #include "raid/memory.h"
+      24             : 
+      25             : /****************************************************************************/
+      26             : /* memory */
+      27             : 
+      28          75 : void* malloc_nofail_align(size_t size, void** freeptr)
+      29             : {
+      30             :         void* ptr;
+      31             : 
+      32          75 :         ptr = raid_malloc_align(size, freeptr);
+      33             : 
+      34          75 :         if (!ptr) {
+      35             :                 /* LCOV_EXCL_START */
+      36             :                 malloc_fail(size);
+      37             :                 exit(EXIT_FAILURE);
+      38             :                 /* LCOV_EXCL_STOP */
+      39             :         }
+      40             : 
+      41          75 :         return ptr;
+      42             : }
+      43             : 
+      44         193 : void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr)
+      45             : {
+      46             :         void* ptr;
+      47             : 
+      48         193 :         ptr = raid_malloc_vector(nd, n, size, freeptr);
+      49             : 
+      50         193 :         if (!ptr) {
+      51             :                 /* LCOV_EXCL_START */
+      52             :                 malloc_fail(n * size);
+      53             :                 exit(EXIT_FAILURE);
+      54             :                 /* LCOV_EXCL_STOP */
+      55             :         }
+      56             : 
+      57         193 :         return ptr;
+      58             : }
+      59             : 
+      60         723 : void* malloc_nofail_test(size_t size)
+      61             : {
+      62             :         void* ptr;
+      63             : 
+      64         723 :         ptr = malloc_nofail(size);
+      65             : 
+      66         723 :         mtest_vector(1, size, &ptr);
+      67             : 
+      68         723 :         return ptr;
+      69             : }
+      70             : 
+      71         723 : void mtest_vector(int n, size_t size, void** vv)
+      72             : {
+      73         723 :         if (raid_mtest_vector(n, size, vv) != 0) {
+      74             :                 /* LCOV_EXCL_START */
+      75             :                 log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n");
+      76             :                 log_fatal("Try running a memory test like http://www.memtest86.com/\n");
+      77             :                 exit(EXIT_FAILURE);
+      78             :                 /* LCOV_EXCL_STOP */
+      79             :         }
+      80         723 : }
+      81             : 
+      82             : /****************************************************************************/
+      83             : /* crc */
+      84             : 
+      85             : uint32_t CRC32C_0[256] = {
+      86             :         0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4,
+      87             :         0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb,
+      88             :         0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b,
+      89             :         0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24,
+      90             :         0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b,
+      91             :         0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384,
+      92             :         0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54,
+      93             :         0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b,
+      94             :         0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a,
+      95             :         0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35,
+      96             :         0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5,
+      97             :         0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa,
+      98             :         0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45,
+      99             :         0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a,
+     100             :         0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a,
+     101             :         0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595,
+     102             :         0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48,
+     103             :         0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957,
+     104             :         0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687,
+     105             :         0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198,
+     106             :         0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927,
+     107             :         0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38,
+     108             :         0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8,
+     109             :         0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7,
+     110             :         0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096,
+     111             :         0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789,
+     112             :         0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859,
+     113             :         0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46,
+     114             :         0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9,
+     115             :         0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6,
+     116             :         0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36,
+     117             :         0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829,
+     118             :         0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c,
+     119             :         0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93,
+     120             :         0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043,
+     121             :         0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c,
+     122             :         0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3,
+     123             :         0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc,
+     124             :         0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c,
+     125             :         0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033,
+     126             :         0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652,
+     127             :         0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d,
+     128             :         0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d,
+     129             :         0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982,
+     130             :         0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d,
+     131             :         0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622,
+     132             :         0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2,
+     133             :         0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed,
+     134             :         0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530,
+     135             :         0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f,
+     136             :         0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff,
+     137             :         0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0,
+     138             :         0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f,
+     139             :         0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540,
+     140             :         0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90,
+     141             :         0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f,
+     142             :         0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee,
+     143             :         0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1,
+     144             :         0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321,
+     145             :         0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e,
+     146             :         0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81,
+     147             :         0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e,
+     148             :         0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e,
+     149             :         0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351
+     150             : };
+     151             : 
+     152             : uint32_t CRC32C_1[256] = {
+     153             :         0x00000000, 0x13a29877, 0x274530ee, 0x34e7a899,
+     154             :         0x4e8a61dc, 0x5d28f9ab, 0x69cf5132, 0x7a6dc945,
+     155             :         0x9d14c3b8, 0x8eb65bcf, 0xba51f356, 0xa9f36b21,
+     156             :         0xd39ea264, 0xc03c3a13, 0xf4db928a, 0xe7790afd,
+     157             :         0x3fc5f181, 0x2c6769f6, 0x1880c16f, 0x0b225918,
+     158             :         0x714f905d, 0x62ed082a, 0x560aa0b3, 0x45a838c4,
+     159             :         0xa2d13239, 0xb173aa4e, 0x859402d7, 0x96369aa0,
+     160             :         0xec5b53e5, 0xfff9cb92, 0xcb1e630b, 0xd8bcfb7c,
+     161             :         0x7f8be302, 0x6c297b75, 0x58ced3ec, 0x4b6c4b9b,
+     162             :         0x310182de, 0x22a31aa9, 0x1644b230, 0x05e62a47,
+     163             :         0xe29f20ba, 0xf13db8cd, 0xc5da1054, 0xd6788823,
+     164             :         0xac154166, 0xbfb7d911, 0x8b507188, 0x98f2e9ff,
+     165             :         0x404e1283, 0x53ec8af4, 0x670b226d, 0x74a9ba1a,
+     166             :         0x0ec4735f, 0x1d66eb28, 0x298143b1, 0x3a23dbc6,
+     167             :         0xdd5ad13b, 0xcef8494c, 0xfa1fe1d5, 0xe9bd79a2,
+     168             :         0x93d0b0e7, 0x80722890, 0xb4958009, 0xa737187e,
+     169             :         0xff17c604, 0xecb55e73, 0xd852f6ea, 0xcbf06e9d,
+     170             :         0xb19da7d8, 0xa23f3faf, 0x96d89736, 0x857a0f41,
+     171             :         0x620305bc, 0x71a19dcb, 0x45463552, 0x56e4ad25,
+     172             :         0x2c896460, 0x3f2bfc17, 0x0bcc548e, 0x186eccf9,
+     173             :         0xc0d23785, 0xd370aff2, 0xe797076b, 0xf4359f1c,
+     174             :         0x8e585659, 0x9dface2e, 0xa91d66b7, 0xbabffec0,
+     175             :         0x5dc6f43d, 0x4e646c4a, 0x7a83c4d3, 0x69215ca4,
+     176             :         0x134c95e1, 0x00ee0d96, 0x3409a50f, 0x27ab3d78,
+     177             :         0x809c2506, 0x933ebd71, 0xa7d915e8, 0xb47b8d9f,
+     178             :         0xce1644da, 0xddb4dcad, 0xe9537434, 0xfaf1ec43,
+     179             :         0x1d88e6be, 0x0e2a7ec9, 0x3acdd650, 0x296f4e27,
+     180             :         0x53028762, 0x40a01f15, 0x7447b78c, 0x67e52ffb,
+     181             :         0xbf59d487, 0xacfb4cf0, 0x981ce469, 0x8bbe7c1e,
+     182             :         0xf1d3b55b, 0xe2712d2c, 0xd69685b5, 0xc5341dc2,
+     183             :         0x224d173f, 0x31ef8f48, 0x050827d1, 0x16aabfa6,
+     184             :         0x6cc776e3, 0x7f65ee94, 0x4b82460d, 0x5820de7a,
+     185             :         0xfbc3faf9, 0xe861628e, 0xdc86ca17, 0xcf245260,
+     186             :         0xb5499b25, 0xa6eb0352, 0x920cabcb, 0x81ae33bc,
+     187             :         0x66d73941, 0x7575a136, 0x419209af, 0x523091d8,
+     188             :         0x285d589d, 0x3bffc0ea, 0x0f186873, 0x1cbaf004,
+     189             :         0xc4060b78, 0xd7a4930f, 0xe3433b96, 0xf0e1a3e1,
+     190             :         0x8a8c6aa4, 0x992ef2d3, 0xadc95a4a, 0xbe6bc23d,
+     191             :         0x5912c8c0, 0x4ab050b7, 0x7e57f82e, 0x6df56059,
+     192             :         0x1798a91c, 0x043a316b, 0x30dd99f2, 0x237f0185,
+     193             :         0x844819fb, 0x97ea818c, 0xa30d2915, 0xb0afb162,
+     194             :         0xcac27827, 0xd960e050, 0xed8748c9, 0xfe25d0be,
+     195             :         0x195cda43, 0x0afe4234, 0x3e19eaad, 0x2dbb72da,
+     196             :         0x57d6bb9f, 0x447423e8, 0x70938b71, 0x63311306,
+     197             :         0xbb8de87a, 0xa82f700d, 0x9cc8d894, 0x8f6a40e3,
+     198             :         0xf50789a6, 0xe6a511d1, 0xd242b948, 0xc1e0213f,
+     199             :         0x26992bc2, 0x353bb3b5, 0x01dc1b2c, 0x127e835b,
+     200             :         0x68134a1e, 0x7bb1d269, 0x4f567af0, 0x5cf4e287,
+     201             :         0x04d43cfd, 0x1776a48a, 0x23910c13, 0x30339464,
+     202             :         0x4a5e5d21, 0x59fcc556, 0x6d1b6dcf, 0x7eb9f5b8,
+     203             :         0x99c0ff45, 0x8a626732, 0xbe85cfab, 0xad2757dc,
+     204             :         0xd74a9e99, 0xc4e806ee, 0xf00fae77, 0xe3ad3600,
+     205             :         0x3b11cd7c, 0x28b3550b, 0x1c54fd92, 0x0ff665e5,
+     206             :         0x759baca0, 0x663934d7, 0x52de9c4e, 0x417c0439,
+     207             :         0xa6050ec4, 0xb5a796b3, 0x81403e2a, 0x92e2a65d,
+     208             :         0xe88f6f18, 0xfb2df76f, 0xcfca5ff6, 0xdc68c781,
+     209             :         0x7b5fdfff, 0x68fd4788, 0x5c1aef11, 0x4fb87766,
+     210             :         0x35d5be23, 0x26772654, 0x12908ecd, 0x013216ba,
+     211             :         0xe64b1c47, 0xf5e98430, 0xc10e2ca9, 0xd2acb4de,
+     212             :         0xa8c17d9b, 0xbb63e5ec, 0x8f844d75, 0x9c26d502,
+     213             :         0x449a2e7e, 0x5738b609, 0x63df1e90, 0x707d86e7,
+     214             :         0x0a104fa2, 0x19b2d7d5, 0x2d557f4c, 0x3ef7e73b,
+     215             :         0xd98eedc6, 0xca2c75b1, 0xfecbdd28, 0xed69455f,
+     216             :         0x97048c1a, 0x84a6146d, 0xb041bcf4, 0xa3e32483
+     217             : };
+     218             : 
+     219             : uint32_t CRC32C_2[256] = {
+     220             :         0x00000000, 0xa541927e, 0x4f6f520d, 0xea2ec073,
+     221             :         0x9edea41a, 0x3b9f3664, 0xd1b1f617, 0x74f06469,
+     222             :         0x38513ec5, 0x9d10acbb, 0x773e6cc8, 0xd27ffeb6,
+     223             :         0xa68f9adf, 0x03ce08a1, 0xe9e0c8d2, 0x4ca15aac,
+     224             :         0x70a27d8a, 0xd5e3eff4, 0x3fcd2f87, 0x9a8cbdf9,
+     225             :         0xee7cd990, 0x4b3d4bee, 0xa1138b9d, 0x045219e3,
+     226             :         0x48f3434f, 0xedb2d131, 0x079c1142, 0xa2dd833c,
+     227             :         0xd62de755, 0x736c752b, 0x9942b558, 0x3c032726,
+     228             :         0xe144fb14, 0x4405696a, 0xae2ba919, 0x0b6a3b67,
+     229             :         0x7f9a5f0e, 0xdadbcd70, 0x30f50d03, 0x95b49f7d,
+     230             :         0xd915c5d1, 0x7c5457af, 0x967a97dc, 0x333b05a2,
+     231             :         0x47cb61cb, 0xe28af3b5, 0x08a433c6, 0xade5a1b8,
+     232             :         0x91e6869e, 0x34a714e0, 0xde89d493, 0x7bc846ed,
+     233             :         0x0f382284, 0xaa79b0fa, 0x40577089, 0xe516e2f7,
+     234             :         0xa9b7b85b, 0x0cf62a25, 0xe6d8ea56, 0x43997828,
+     235             :         0x37691c41, 0x92288e3f, 0x78064e4c, 0xdd47dc32,
+     236             :         0xc76580d9, 0x622412a7, 0x880ad2d4, 0x2d4b40aa,
+     237             :         0x59bb24c3, 0xfcfab6bd, 0x16d476ce, 0xb395e4b0,
+     238             :         0xff34be1c, 0x5a752c62, 0xb05bec11, 0x151a7e6f,
+     239             :         0x61ea1a06, 0xc4ab8878, 0x2e85480b, 0x8bc4da75,
+     240             :         0xb7c7fd53, 0x12866f2d, 0xf8a8af5e, 0x5de93d20,
+     241             :         0x29195949, 0x8c58cb37, 0x66760b44, 0xc337993a,
+     242             :         0x8f96c396, 0x2ad751e8, 0xc0f9919b, 0x65b803e5,
+     243             :         0x1148678c, 0xb409f5f2, 0x5e273581, 0xfb66a7ff,
+     244             :         0x26217bcd, 0x8360e9b3, 0x694e29c0, 0xcc0fbbbe,
+     245             :         0xb8ffdfd7, 0x1dbe4da9, 0xf7908dda, 0x52d11fa4,
+     246             :         0x1e704508, 0xbb31d776, 0x511f1705, 0xf45e857b,
+     247             :         0x80aee112, 0x25ef736c, 0xcfc1b31f, 0x6a802161,
+     248             :         0x56830647, 0xf3c29439, 0x19ec544a, 0xbcadc634,
+     249             :         0xc85da25d, 0x6d1c3023, 0x8732f050, 0x2273622e,
+     250             :         0x6ed23882, 0xcb93aafc, 0x21bd6a8f, 0x84fcf8f1,
+     251             :         0xf00c9c98, 0x554d0ee6, 0xbf63ce95, 0x1a225ceb,
+     252             :         0x8b277743, 0x2e66e53d, 0xc448254e, 0x6109b730,
+     253             :         0x15f9d359, 0xb0b84127, 0x5a968154, 0xffd7132a,
+     254             :         0xb3764986, 0x1637dbf8, 0xfc191b8b, 0x595889f5,
+     255             :         0x2da8ed9c, 0x88e97fe2, 0x62c7bf91, 0xc7862def,
+     256             :         0xfb850ac9, 0x5ec498b7, 0xb4ea58c4, 0x11abcaba,
+     257             :         0x655baed3, 0xc01a3cad, 0x2a34fcde, 0x8f756ea0,
+     258             :         0xc3d4340c, 0x6695a672, 0x8cbb6601, 0x29faf47f,
+     259             :         0x5d0a9016, 0xf84b0268, 0x1265c21b, 0xb7245065,
+     260             :         0x6a638c57, 0xcf221e29, 0x250cde5a, 0x804d4c24,
+     261             :         0xf4bd284d, 0x51fcba33, 0xbbd27a40, 0x1e93e83e,
+     262             :         0x5232b292, 0xf77320ec, 0x1d5de09f, 0xb81c72e1,
+     263             :         0xccec1688, 0x69ad84f6, 0x83834485, 0x26c2d6fb,
+     264             :         0x1ac1f1dd, 0xbf8063a3, 0x55aea3d0, 0xf0ef31ae,
+     265             :         0x841f55c7, 0x215ec7b9, 0xcb7007ca, 0x6e3195b4,
+     266             :         0x2290cf18, 0x87d15d66, 0x6dff9d15, 0xc8be0f6b,
+     267             :         0xbc4e6b02, 0x190ff97c, 0xf321390f, 0x5660ab71,
+     268             :         0x4c42f79a, 0xe90365e4, 0x032da597, 0xa66c37e9,
+     269             :         0xd29c5380, 0x77ddc1fe, 0x9df3018d, 0x38b293f3,
+     270             :         0x7413c95f, 0xd1525b21, 0x3b7c9b52, 0x9e3d092c,
+     271             :         0xeacd6d45, 0x4f8cff3b, 0xa5a23f48, 0x00e3ad36,
+     272             :         0x3ce08a10, 0x99a1186e, 0x738fd81d, 0xd6ce4a63,
+     273             :         0xa23e2e0a, 0x077fbc74, 0xed517c07, 0x4810ee79,
+     274             :         0x04b1b4d5, 0xa1f026ab, 0x4bdee6d8, 0xee9f74a6,
+     275             :         0x9a6f10cf, 0x3f2e82b1, 0xd50042c2, 0x7041d0bc,
+     276             :         0xad060c8e, 0x08479ef0, 0xe2695e83, 0x4728ccfd,
+     277             :         0x33d8a894, 0x96993aea, 0x7cb7fa99, 0xd9f668e7,
+     278             :         0x9557324b, 0x3016a035, 0xda386046, 0x7f79f238,
+     279             :         0x0b899651, 0xaec8042f, 0x44e6c45c, 0xe1a75622,
+     280             :         0xdda47104, 0x78e5e37a, 0x92cb2309, 0x378ab177,
+     281             :         0x437ad51e, 0xe63b4760, 0x0c158713, 0xa954156d,
+     282             :         0xe5f54fc1, 0x40b4ddbf, 0xaa9a1dcc, 0x0fdb8fb2,
+     283             :         0x7b2bebdb, 0xde6a79a5, 0x3444b9d6, 0x91052ba8
+     284             : };
+     285             : 
+     286             : uint32_t CRC32C_3[256] = {
+     287             :         0x00000000, 0xdd45aab8, 0xbf672381, 0x62228939,
+     288             :         0x7b2231f3, 0xa6679b4b, 0xc4451272, 0x1900b8ca,
+     289             :         0xf64463e6, 0x2b01c95e, 0x49234067, 0x9466eadf,
+     290             :         0x8d665215, 0x5023f8ad, 0x32017194, 0xef44db2c,
+     291             :         0xe964b13d, 0x34211b85, 0x560392bc, 0x8b463804,
+     292             :         0x924680ce, 0x4f032a76, 0x2d21a34f, 0xf06409f7,
+     293             :         0x1f20d2db, 0xc2657863, 0xa047f15a, 0x7d025be2,
+     294             :         0x6402e328, 0xb9474990, 0xdb65c0a9, 0x06206a11,
+     295             :         0xd725148b, 0x0a60be33, 0x6842370a, 0xb5079db2,
+     296             :         0xac072578, 0x71428fc0, 0x136006f9, 0xce25ac41,
+     297             :         0x2161776d, 0xfc24ddd5, 0x9e0654ec, 0x4343fe54,
+     298             :         0x5a43469e, 0x8706ec26, 0xe524651f, 0x3861cfa7,
+     299             :         0x3e41a5b6, 0xe3040f0e, 0x81268637, 0x5c632c8f,
+     300             :         0x45639445, 0x98263efd, 0xfa04b7c4, 0x27411d7c,
+     301             :         0xc805c650, 0x15406ce8, 0x7762e5d1, 0xaa274f69,
+     302             :         0xb327f7a3, 0x6e625d1b, 0x0c40d422, 0xd1057e9a,
+     303             :         0xaba65fe7, 0x76e3f55f, 0x14c17c66, 0xc984d6de,
+     304             :         0xd0846e14, 0x0dc1c4ac, 0x6fe34d95, 0xb2a6e72d,
+     305             :         0x5de23c01, 0x80a796b9, 0xe2851f80, 0x3fc0b538,
+     306             :         0x26c00df2, 0xfb85a74a, 0x99a72e73, 0x44e284cb,
+     307             :         0x42c2eeda, 0x9f874462, 0xfda5cd5b, 0x20e067e3,
+     308             :         0x39e0df29, 0xe4a57591, 0x8687fca8, 0x5bc25610,
+     309             :         0xb4868d3c, 0x69c32784, 0x0be1aebd, 0xd6a40405,
+     310             :         0xcfa4bccf, 0x12e11677, 0x70c39f4e, 0xad8635f6,
+     311             :         0x7c834b6c, 0xa1c6e1d4, 0xc3e468ed, 0x1ea1c255,
+     312             :         0x07a17a9f, 0xdae4d027, 0xb8c6591e, 0x6583f3a6,
+     313             :         0x8ac7288a, 0x57828232, 0x35a00b0b, 0xe8e5a1b3,
+     314             :         0xf1e51979, 0x2ca0b3c1, 0x4e823af8, 0x93c79040,
+     315             :         0x95e7fa51, 0x48a250e9, 0x2a80d9d0, 0xf7c57368,
+     316             :         0xeec5cba2, 0x3380611a, 0x51a2e823, 0x8ce7429b,
+     317             :         0x63a399b7, 0xbee6330f, 0xdcc4ba36, 0x0181108e,
+     318             :         0x1881a844, 0xc5c402fc, 0xa7e68bc5, 0x7aa3217d,
+     319             :         0x52a0c93f, 0x8fe56387, 0xedc7eabe, 0x30824006,
+     320             :         0x2982f8cc, 0xf4c75274, 0x96e5db4d, 0x4ba071f5,
+     321             :         0xa4e4aad9, 0x79a10061, 0x1b838958, 0xc6c623e0,
+     322             :         0xdfc69b2a, 0x02833192, 0x60a1b8ab, 0xbde41213,
+     323             :         0xbbc47802, 0x6681d2ba, 0x04a35b83, 0xd9e6f13b,
+     324             :         0xc0e649f1, 0x1da3e349, 0x7f816a70, 0xa2c4c0c8,
+     325             :         0x4d801be4, 0x90c5b15c, 0xf2e73865, 0x2fa292dd,
+     326             :         0x36a22a17, 0xebe780af, 0x89c50996, 0x5480a32e,
+     327             :         0x8585ddb4, 0x58c0770c, 0x3ae2fe35, 0xe7a7548d,
+     328             :         0xfea7ec47, 0x23e246ff, 0x41c0cfc6, 0x9c85657e,
+     329             :         0x73c1be52, 0xae8414ea, 0xcca69dd3, 0x11e3376b,
+     330             :         0x08e38fa1, 0xd5a62519, 0xb784ac20, 0x6ac10698,
+     331             :         0x6ce16c89, 0xb1a4c631, 0xd3864f08, 0x0ec3e5b0,
+     332             :         0x17c35d7a, 0xca86f7c2, 0xa8a47efb, 0x75e1d443,
+     333             :         0x9aa50f6f, 0x47e0a5d7, 0x25c22cee, 0xf8878656,
+     334             :         0xe1873e9c, 0x3cc29424, 0x5ee01d1d, 0x83a5b7a5,
+     335             :         0xf90696d8, 0x24433c60, 0x4661b559, 0x9b241fe1,
+     336             :         0x8224a72b, 0x5f610d93, 0x3d4384aa, 0xe0062e12,
+     337             :         0x0f42f53e, 0xd2075f86, 0xb025d6bf, 0x6d607c07,
+     338             :         0x7460c4cd, 0xa9256e75, 0xcb07e74c, 0x16424df4,
+     339             :         0x106227e5, 0xcd278d5d, 0xaf050464, 0x7240aedc,
+     340             :         0x6b401616, 0xb605bcae, 0xd4273597, 0x09629f2f,
+     341             :         0xe6264403, 0x3b63eebb, 0x59416782, 0x8404cd3a,
+     342             :         0x9d0475f0, 0x4041df48, 0x22635671, 0xff26fcc9,
+     343             :         0x2e238253, 0xf36628eb, 0x9144a1d2, 0x4c010b6a,
+     344             :         0x5501b3a0, 0x88441918, 0xea669021, 0x37233a99,
+     345             :         0xd867e1b5, 0x05224b0d, 0x6700c234, 0xba45688c,
+     346             :         0xa345d046, 0x7e007afe, 0x1c22f3c7, 0xc167597f,
+     347             :         0xc747336e, 0x1a0299d6, 0x782010ef, 0xa565ba57,
+     348             :         0xbc65029d, 0x6120a825, 0x0302211c, 0xde478ba4,
+     349             :         0x31035088, 0xec46fa30, 0x8e647309, 0x5321d9b1,
+     350             :         0x4a21617b, 0x9764cbc3, 0xf54642fa, 0x2803e842
+     351             : };
+     352             : 
+     353         304 : uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size)
+     354             : {
+     355         304 :         crc ^= CRC_IV;
+     356             : 
+     357    19923552 :         while (size >= 4) {
+     358    19922944 :                 crc ^= ptr[0] | (uint32_t)ptr[1] << 8 | (uint32_t)ptr[2] << 16 | (uint32_t)ptr[3] << 24;
+     359    19922944 :                 crc = CRC32C_3[crc & 0xff] ^ CRC32C_2[(crc >> 8) & 0xff] ^ CRC32C_1[(crc >> 16) & 0xff] ^ CRC32C_0[crc >> 24];
+     360    19922944 :                 ptr += 4;
+     361    19922944 :                 size -= 4;
+     362             :         }
+     363             : 
+     364         608 :         while (size) {
+     365           0 :                 crc = CRC32C_0[(crc ^ *ptr) & 0xff] ^ (crc >> 8);
+     366           0 :                 ++ptr;
+     367           0 :                 --size;
+     368             :         }
+     369             : 
+     370         304 :         crc ^= CRC_IV;
+     371             : 
+     372         304 :         return crc;
+     373             : }
+     374             : 
+     375             : #if HAVE_SSE42
+     376      337096 : uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size)
+     377             : {
+     378             : #ifdef CONFIG_X86_64
+     379             :         uint64_t crc64;
+     380             : #endif
+     381             : 
+     382      337096 :         crc ^= CRC_IV;
+     383             : 
+     384             : #ifdef CONFIG_X86_64
+     385             :         crc64 = crc;
+     386             :         while (size >= 8) {
+     387             :                 asm("crc32q %1, %0\n" : "+r" (crc64) : "m" (*(const uint64_t*)ptr));
+     388             :                 ptr += 8;
+     389             :                 size -= 8;
+     390             :         }
+     391             :         crc = crc64;
+     392             : #else
+     393   132473808 :         while (size >= 4) {
+     394   131799616 :                 asm("crc32l %1, %0\n" : "+r" (crc) : "m" (*(const uint32_t*)ptr));
+     395   131799616 :                 ptr += 4;
+     396   131799616 :                 size -= 4;
+     397             :         }
+     398             : #endif
+     399             : 
+     400     1159207 :         while (size) {
+     401      485015 :                 asm("crc32b %1, %0\n" : "+r" (crc) : "m" (*ptr));
+     402      485015 :                 ++ptr;
+     403      485015 :                 --size;
+     404             :         }
+     405             : 
+     406      337096 :         crc ^= CRC_IV;
+     407             : 
+     408      337096 :         return crc;
+     409             : }
+     410             : #endif
+     411             : 
+     412             : uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, unsigned size);
+     413             : 
+     414             : #if HAVE_SSE42
+     415             : int crc_x86;
+     416             : #endif
+     417             : 
+     418         256 : void crc32c_init(void)
+     419             : {
+     420         256 :         crc32c = crc32c_gen;
+     421             : #if HAVE_SSE42
+     422         256 :         if (raid_cpu_has_crc32()) {
+     423         254 :                 crc_x86 = 1;
+     424         254 :                 crc32c = crc32c_x86;
+     425             :         }
+     426             : #endif
+     427         256 : }
+     428             : 
+     429             : /****************************************************************************/
+     430             : /* byte operations */
+     431             : 
+     432             : /*
+     433             :  * Rotate left.
+     434             :  * In x86/x64 they are optimized with a single assembler instruction.
+     435             :  */
+     436   893240076 : static inline uint32_t util_rotl32(uint32_t x, int8_t r)
+     437             : {
+     438   893240076 :         return (x << r) | (x >> (32 - r));
+     439             : }
+     440             : 
+     441   461035788 : static inline uint64_t util_rotl64(uint64_t x, int8_t r)
+     442             : {
+     443   461035788 :         return (x << r) | (x >> (64 - r));
+     444             : }
+     445             : 
+     446             : /**
+     447             :  * Swap endianess.
+     448             :  * They are needed only if BigEndian.
+     449             :  */
+     450             : #if defined(__GNUC__)
+     451             : 
+     452             : #define util_swap32(x) __builtin_bswap32(x)
+     453             : #define util_swap64(x) __builtin_bswap64(x)
+     454             : 
+     455             : #elif HAVE_BYTESWAP_H
+     456             : 
+     457             : #include <byteswap.h>
+     458             : 
+     459             : #define util_swap32(x) bswap_32(x)
+     460             : #define util_swap64(x) bswap_64(x)
+     461             : 
+     462             : #else
+     463             : static inline uint32_t util_swap32(uint32_t v)
+     464             : {
+     465             :         return (util_rotl32(v, 8) & 0x00ff00ff)
+     466             :                | (util_rotl32(v, 24) & 0xff00ff00);
+     467             : }
+     468             : 
+     469             : static inline uint64_t util_swap64(uint64_t v)
+     470             : {
+     471             :         return (util_rotl64(v, 8) & 0x000000ff000000ffULL)
+     472             :                | (util_rotl64(v, 24) & 0x0000ff000000ff00ULL)
+     473             :                | (util_rotl64(v, 40) & 0x00ff000000ff0000ULL)
+     474             :                | (util_rotl64(v, 56) & 0xff000000ff000000ULL);
+     475             : }
+     476             : #endif
+     477             : 
+     478             : /****************************************************************************/
+     479             : /* hash */
+     480             : 
+     481             : #include "murmur3.c"
+     482             : #include "spooky2.c"
+     483             : 
+     484     5646915 : void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* src, unsigned size)
+     485             : {
+     486     5646915 :         switch (kind) {
+     487             :         case HASH_MURMUR3 :
+     488     2174927 :                 MurmurHash3_x86_128(src, size, seed, digest);
+     489     2174927 :                 break;
+     490             :         case HASH_SPOOKY2 :
+     491     3471988 :                 SpookyHash128(src, size, seed, digest);
+     492     3471988 :                 break;
+     493             :         default :
+     494             :                 /* LCOV_EXCL_START */
+     495             :                 log_fatal("Internal inconsistency in hash function %u\n", kind);
+     496             :                 exit(EXIT_FAILURE);
+     497             :                 break;
+     498             :                 /* LCOV_EXCL_STOP */
+     499             :         }
+     500     5646915 : }
+     501             : 
+     502          42 : const char* hash_config_name(unsigned kind)
+     503             : {
+     504          42 :         switch (kind) {
+     505          13 :         case HASH_UNDEFINED : return "undefined";
+     506          28 :         case HASH_MURMUR3 : return "murmur3";
+     507           1 :         case HASH_SPOOKY2 : return "spooky2";
+     508             :         default :
+     509             :                 /* LCOV_EXCL_START */
+     510             :                 return "unknown";
+     511             :                 /* LCOV_EXCL_STOP */
+     512             :         }
+     513             : }
+     514             : 
+     515             : /****************************************************************************/
+     516             : /* lock */
+     517             : 
+     518             : #if HAVE_LOCKFILE
+     519         232 : int lock_lock(const char* file)
+     520             : {
+     521             :         int f;
+     522             : 
+     523         232 :         f = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600);
+     524         232 :         if (f == -1) {
+     525             :                 /* LCOV_EXCL_START */
+     526             :                 return -1;
+     527             :                 /* LCOV_EXCL_STOP */
+     528             :         }
+     529             : 
+     530             :         /* exclusive lock, not blocking */
+     531         232 :         if (flock(f, LOCK_EX | LOCK_NB) == -1) {
+     532             :                 /* LCOV_EXCL_START */
+     533             :                 close(f);
+     534             :                 return -1;
+     535             :                 /* LCOV_EXCL_STOP */
+     536             :         }
+     537             : 
+     538         232 :         return f;
+     539             : }
+     540             : #endif
+     541             : 
+     542             : #if HAVE_LOCKFILE
+     543         215 : int lock_unlock(int f)
+     544             : {
+     545             :         /*
+     546             :          * Intentionally don't remove the lock file.
+     547             :          * Removing it just introduces race course with other process
+     548             :          * that could have already opened it.
+     549             :          */
+     550         215 :         if (close(f) == -1) {
+     551             :                 /* LCOV_EXCL_START */
+     552             :                 return -1;
+     553             :                 /* LCOV_EXCL_STOP */
+     554             :         }
+     555             : 
+     556         215 :         return 0;
+     557             : }
+     558             : #endif
+     559             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.h.func-sort-c.html b/cov/cmdline/util.h.func-sort-c.html new file mode 100644 index 00000000..1c45c231 --- /dev/null +++ b/cov/cmdline/util.h.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/util.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:4580.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
crc32c_plain134187612
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.h.func.html b/cov/cmdline/util.h.func.html new file mode 100644 index 00000000..c51f2874 --- /dev/null +++ b/cov/cmdline/util.h.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - cmdline/util.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:4580.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
crc32c_plain134187612
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/cmdline/util.h.gcov.html b/cov/cmdline/util.h.gcov.html new file mode 100644 index 00000000..27968763 --- /dev/null +++ b/cov/cmdline/util.h.gcov.html @@ -0,0 +1,218 @@ + + + + + + + LCOV - lcov.info - cmdline/util.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - cmdline - util.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:4580.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2011 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 3 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  *
+      14             :  * You should have received a copy of the GNU General Public License
+      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      16             :  */
+      17             : 
+      18             : #ifndef __UTIL_H
+      19             : #define __UTIL_H
+      20             : 
+      21             : /****************************************************************************/
+      22             : /* memory */
+      23             : 
+      24             : /**
+      25             :  * Safe aligned malloc.
+      26             :  * If no memory is available, it aborts.
+      27             :  */
+      28             : void* malloc_nofail_align(size_t size, void** freeptr);
+      29             : 
+      30             : /**
+      31             :  * Safe aligned vector allocation.
+      32             :  * If no memory is available, it aborts.
+      33             :  */
+      34             : void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr);
+      35             : 
+      36             : /**
+      37             :  * Safe allocation with memory test.
+      38             :  */
+      39             : void* malloc_nofail_test(size_t size);
+      40             : 
+      41             : /**
+      42             :  * Tests the memory vector for RAM problems.
+      43             :  * If a problem is found, it crashes.
+      44             :  */
+      45             : void mtest_vector(int n, size_t size, void** vv);
+      46             : 
+      47             : /****************************************************************************/
+      48             : /* crc */
+      49             : 
+      50             : /**
+      51             :  * CRC initial value.
+      52             :  * Using a not zero value allows to detect a leading run of zeros.
+      53             :  */
+      54             : #define CRC_IV 0xffffffffU
+      55             : 
+      56             : /**
+      57             :  * CRC-32 (Castagnoli) table.
+      58             :  */
+      59             : extern uint32_t CRC32C_0[256];
+      60             : extern uint32_t CRC32C_1[256];
+      61             : extern uint32_t CRC32C_2[256];
+      62             : extern uint32_t CRC32C_3[256];
+      63             : 
+      64             : #if HAVE_SSE42
+      65             : /**
+      66             :  * If the CPU support the CRC instructions.
+      67             :  */
+      68             : extern int crc_x86;
+      69             : #endif
+      70             : 
+      71             : /**
+      72             :  * Computes CRC-32 (Castagnoli) for a single byte without IV.
+      73             :  */
+      74   134187612 : static inline uint32_t crc32c_plain(uint32_t crc, unsigned char c)
+      75             : {
+      76             : #if HAVE_SSE42
+      77   134187612 :         if (tommy_likely(crc_x86)) {
+      78   134187612 :                 asm("crc32b %1, %0\n" : "+r" (crc) : "m" (c));
+      79   134187612 :                 return crc;
+      80             :         } else
+      81             : #endif
+      82             :         {
+      83           0 :                 return CRC32C_0[(crc ^ c) & 0xff] ^ (crc >> 8);
+      84             :         }
+      85             : }
+      86             : 
+      87             : /**
+      88             :  * Computes the CRC-32 (Castagnoli)
+      89             :  */
+      90             : uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, unsigned size);
+      91             : uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size);
+      92             : uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size);
+      93             : 
+      94             : /**
+      95             :  * Initializes the CRC-32 (Castagnoli) support.
+      96             :  */
+      97             : void crc32c_init(void);
+      98             : 
+      99             : /****************************************************************************/
+     100             : /* hash */
+     101             : 
+     102             : /**
+     103             :  * Size of the hash.
+     104             :  */
+     105             : 
+     106             : #define HASH_SIZE 16
+     107             : 
+     108             : /**
+     109             :  * Hash kinds.
+     110             :  */
+     111             : #define HASH_UNDEFINED 0
+     112             : #define HASH_MURMUR3 1
+     113             : #define HASH_SPOOKY2 2
+     114             : 
+     115             : /**
+     116             :  * Computes the HASH of a memory block.
+     117             :  * Seed is a 128 bit vector.
+     118             :  */
+     119             : void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* src, unsigned size);
+     120             : 
+     121             : /**
+     122             :  * Return the hash name.
+     123             :  */
+     124             : const char* hash_config_name(unsigned kind);
+     125             : 
+     126             : /****************************************************************************/
+     127             : /* lock */
+     128             : 
+     129             : /**
+     130             :  * Creates and locks the lock file.
+     131             :  * Returns -1 on error, otherwise it's the file handle to pass to lock_unlock().
+     132             :  */
+     133             : int lock_lock(const char* file);
+     134             : 
+     135             : /**
+     136             :  * Unlocks the lock file.
+     137             :  * Returns -1 on error.
+     138             :  */
+     139             : int lock_unlock(int f);
+     140             : 
+     141             : #endif
+     142             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/emerald.png b/cov/emerald.png new file mode 100644 index 00000000..38ad4f40 Binary files /dev/null and b/cov/emerald.png differ diff --git a/cov/gcov.css b/cov/gcov.css new file mode 100644 index 00000000..bfd0a83e --- /dev/null +++ b/cov/gcov.css @@ -0,0 +1,519 @@ +/* All views: initial background and text color */ +body +{ + color: #000000; + background-color: #FFFFFF; +} + +/* All views: standard link format*/ +a:link +{ + color: #284FA8; + text-decoration: underline; +} + +/* All views: standard link - visited format */ +a:visited +{ + color: #00CB40; + text-decoration: underline; +} + +/* All views: standard link - activated format */ +a:active +{ + color: #FF0040; + text-decoration: underline; +} + +/* All views: main title format */ +td.title +{ + text-align: center; + padding-bottom: 10px; + font-family: sans-serif; + font-size: 20pt; + font-style: italic; + font-weight: bold; +} + +/* All views: header item format */ +td.headerItem +{ + text-align: right; + padding-right: 6px; + font-family: sans-serif; + font-weight: bold; + vertical-align: top; + white-space: nowrap; +} + +/* All views: header item value format */ +td.headerValue +{ + text-align: left; + color: #284FA8; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; +} + +/* All views: header item coverage table heading */ +td.headerCovTableHead +{ + text-align: center; + padding-right: 6px; + padding-left: 6px; + padding-bottom: 0px; + font-family: sans-serif; + font-size: 80%; + white-space: nowrap; +} + +/* All views: header item coverage table entry */ +td.headerCovTableEntry +{ + text-align: right; + color: #284FA8; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #DAE7FE; +} + +/* All views: header item coverage table entry for high coverage rate */ +td.headerCovTableEntryHi +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #A7FC9D; +} + +/* All views: header item coverage table entry for medium coverage rate */ +td.headerCovTableEntryMed +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #FFEA20; +} + +/* All views: header item coverage table entry for ow coverage rate */ +td.headerCovTableEntryLo +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #FF0000; +} + +/* All views: header legend value for legend entry */ +td.headerValueLeg +{ + text-align: left; + color: #000000; + font-family: sans-serif; + font-size: 80%; + white-space: nowrap; + padding-top: 4px; +} + +/* All views: color of horizontal ruler */ +td.ruler +{ + background-color: #6688D4; +} + +/* All views: version string format */ +td.versionInfo +{ + text-align: center; + padding-top: 2px; + font-family: sans-serif; + font-style: italic; +} + +/* Directory view/File view (all)/Test case descriptions: + table headline format */ +td.tableHead +{ + text-align: center; + color: #FFFFFF; + background-color: #6688D4; + font-family: sans-serif; + font-size: 120%; + font-weight: bold; + white-space: nowrap; + padding-left: 4px; + padding-right: 4px; +} + +span.tableHeadSort +{ + padding-right: 4px; +} + +/* Directory view/File view (all): filename entry format */ +td.coverFile +{ + text-align: left; + padding-left: 10px; + padding-right: 20px; + color: #284FA8; + background-color: #DAE7FE; + font-family: monospace; +} + +/* Directory view/File view (all): bar-graph entry format*/ +td.coverBar +{ + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; +} + +/* Directory view/File view (all): bar-graph outline color */ +td.coverBarOutline +{ + background-color: #000000; +} + +/* Directory view/File view (all): percentage entry for files with + high coverage rate */ +td.coverPerHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #A7FC9D; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + high coverage rate */ +td.coverNumHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #A7FC9D; + white-space: nowrap; + font-family: sans-serif; +} + +/* Directory view/File view (all): percentage entry for files with + medium coverage rate */ +td.coverPerMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FFEA20; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + medium coverage rate */ +td.coverNumMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FFEA20; + white-space: nowrap; + font-family: sans-serif; +} + +/* Directory view/File view (all): percentage entry for files with + low coverage rate */ +td.coverPerLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + low coverage rate */ +td.coverNumLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + white-space: nowrap; + font-family: sans-serif; +} + +/* File view (all): "show/hide details" link format */ +a.detail:link +{ + color: #B8D0FF; + font-size:80%; +} + +/* File view (all): "show/hide details" link - visited format */ +a.detail:visited +{ + color: #B8D0FF; + font-size:80%; +} + +/* File view (all): "show/hide details" link - activated format */ +a.detail:active +{ + color: #FFFFFF; + font-size:80%; +} + +/* File view (detail): test name entry */ +td.testName +{ + text-align: right; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* File view (detail): test percentage entry */ +td.testPer +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* File view (detail): test lines count entry */ +td.testNum +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* Test case descriptions: test name format*/ +dt +{ + font-family: sans-serif; + font-weight: bold; +} + +/* Test case descriptions: description table body */ +td.testDescription +{ + padding-top: 10px; + padding-left: 30px; + padding-bottom: 10px; + padding-right: 30px; + background-color: #DAE7FE; +} + +/* Source code view: function entry */ +td.coverFn +{ + text-align: left; + padding-left: 10px; + padding-right: 20px; + color: #284FA8; + background-color: #DAE7FE; + font-family: monospace; +} + +/* Source code view: function entry zero count*/ +td.coverFnLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + font-weight: bold; + font-family: sans-serif; +} + +/* Source code view: function entry nonzero count*/ +td.coverFnHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-weight: bold; + font-family: sans-serif; +} + +/* Source code view: source code format */ +pre.source +{ + font-family: monospace; + white-space: pre; + margin-top: 2px; +} + +/* Source code view: line number format */ +span.lineNum +{ + background-color: #EFE383; +} + +/* Source code view: format for lines which were executed */ +td.lineCov, +span.lineCov +{ + background-color: #CAD7FE; +} + +/* Source code view: format for Cov legend */ +span.coverLegendCov +{ + padding-left: 10px; + padding-right: 10px; + padding-bottom: 2px; + background-color: #CAD7FE; +} + +/* Source code view: format for lines which were not executed */ +td.lineNoCov, +span.lineNoCov +{ + background-color: #FF6230; +} + +/* Source code view: format for NoCov legend */ +span.coverLegendNoCov +{ + padding-left: 10px; + padding-right: 10px; + padding-bottom: 2px; + background-color: #FF6230; +} + +/* Source code view (function table): standard link - visited format */ +td.lineNoCov > a:visited, +td.lineCov > a:visited +{ + color: black; + text-decoration: underline; +} + +/* Source code view: format for lines which were executed only in a + previous version */ +span.lineDiffCov +{ + background-color: #B5F7AF; +} + +/* Source code view: format for branches which were executed + * and taken */ +span.branchCov +{ + background-color: #CAD7FE; +} + +/* Source code view: format for branches which were executed + * but not taken */ +span.branchNoCov +{ + background-color: #FF6230; +} + +/* Source code view: format for branches which were not executed */ +span.branchNoExec +{ + background-color: #FF6230; +} + +/* Source code view: format for the source code heading line */ +pre.sourceHeading +{ + white-space: pre; + font-family: monospace; + font-weight: bold; + margin: 0px; +} + +/* All views: header legend value for low rate */ +td.headerValueLegL +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 4px; + padding-right: 2px; + background-color: #FF0000; + font-size: 80%; +} + +/* All views: header legend value for med rate */ +td.headerValueLegM +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 2px; + padding-right: 2px; + background-color: #FFEA20; + font-size: 80%; +} + +/* All views: header legend value for hi rate */ +td.headerValueLegH +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 2px; + padding-right: 4px; + background-color: #A7FC9D; + font-size: 80%; +} + +/* All views except source code view: legend format for low coverage */ +span.coverLegendCovLo +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #FF0000; +} + +/* All views except source code view: legend format for med coverage */ +span.coverLegendCovMed +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #FFEA20; +} + +/* All views except source code view: legend format for hi coverage */ +span.coverLegendCovHi +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #A7FC9D; +} diff --git a/cov/glass.png b/cov/glass.png new file mode 100644 index 00000000..e1abc006 Binary files /dev/null and b/cov/glass.png differ diff --git a/cov/index-sort-f.html b/cov/index-sort-f.html new file mode 100644 index 00000000..d868ea8c --- /dev/null +++ b/cov/index-sort-f.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - lcov.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:lcov.infoLines:94791026592.3 %
Date:2015-05-12Functions:50752097.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
cmdline +
90.4%90.4%
+
90.4 %7292 / 806796.5 %362 / 375
tommyds +
100.0%
+
100.0 %450 / 450100.0 %63 / 63
raid +
99.4%99.4%
+
99.4 %1737 / 1748100.0 %82 / 82
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/index-sort-l.html b/cov/index-sort-l.html new file mode 100644 index 00000000..4683d70d --- /dev/null +++ b/cov/index-sort-l.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - lcov.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:lcov.infoLines:94791026592.3 %
Date:2015-05-12Functions:50752097.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
cmdline +
90.4%90.4%
+
90.4 %7292 / 806796.5 %362 / 375
raid +
99.4%99.4%
+
99.4 %1737 / 1748100.0 %82 / 82
tommyds +
100.0%
+
100.0 %450 / 450100.0 %63 / 63
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/index.html b/cov/index.html new file mode 100644 index 00000000..205a2893 --- /dev/null +++ b/cov/index.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - lcov.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:lcov.infoLines:94791026592.3 %
Date:2015-05-12Functions:50752097.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
cmdline +
90.4%90.4%
+
90.4 %7292 / 806796.5 %362 / 375
raid +
99.4%99.4%
+
99.4 %1737 / 1748100.0 %82 / 82
tommyds +
100.0%
+
100.0 %450 / 450100.0 %63 / 63
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/check.c.func-sort-c.html b/cov/raid/check.c.func-sort-c.html new file mode 100644 index 00000000..0871edcc --- /dev/null +++ b/cov/raid/check.c.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - raid/check.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6060100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_check11255
raid_validate11255
raid_scan7
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/check.c.func.html b/cov/raid/check.c.func.html new file mode 100644 index 00000000..2b91f987 --- /dev/null +++ b/cov/raid/check.c.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - raid/check.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6060100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_check11255
raid_scan7
raid_validate11255
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/check.c.gcov.html b/cov/raid/check.c.gcov.html new file mode 100644 index 00000000..9420b142 --- /dev/null +++ b/cov/raid/check.c.gcov.html @@ -0,0 +1,261 @@ + + + + + + + LCOV - lcov.info - raid/check.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - check.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6060100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2015 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "combo.h"
+      17             : #include "gf.h"
+      18             : 
+      19             : /**
+      20             :  * Validate the provided failed blocks.
+      21             :  *
+      22             :  * This function checks if the specified failed blocks satisfy the redundancy
+      23             :  * information using the data from the known valid parity blocks.
+      24             :  *
+      25             :  * It's similar at raid_check(), just with a different format for arguments.
+      26             :  *
+      27             :  * The number of failed blocks @nr must be strictly less than the number of
+      28             :  * parities @nv, because you need one more parity to validate the recovering.
+      29             :  *
+      30             :  * No data or parity blocks are modified.
+      31             :  *
+      32             :  * @nr Number of failed data blocks.
+      33             :  * @id[] Vector of @nr indexes of the failed data blocks.
+      34             :  *   The indexes start from 0. They must be in order.
+      35             :  * @nv Number of valid parity blocks.
+      36             :  * @ip[] Vector of @nv indexes of the valid parity blocks.
+      37             :  *   The indexes start from 0. They must be in order.
+      38             :  * @nd Number of data blocks.
+      39             :  * @size Size of the blocks pointed by @v. It must be a multipler of 64.
+      40             :  * @v Vector of pointers to the blocks of data and parity.
+      41             :  *   It has (@nd + @ip[@nv - 1] + 1) elements. The starting elements are the
+      42             :  *   blocks for data, following with the parity blocks.
+      43             :  *   Each block has @size bytes. 
+      44             :  * @return 0 if the check is satisfied. -1 otherwise.
+      45             :  */
+      46       11255 : static int raid_validate(int nr, int *id, int nv, int *ip, int nd, size_t size, void **vv)
+      47             : {
+      48       11255 :         uint8_t **v = (uint8_t **)vv;
+      49             :         const uint8_t *T[RAID_PARITY_MAX][RAID_PARITY_MAX];
+      50             :         uint8_t G[RAID_PARITY_MAX * RAID_PARITY_MAX];
+      51             :         uint8_t V[RAID_PARITY_MAX * RAID_PARITY_MAX];
+      52             :         size_t i;
+      53             :         int j, k, l;
+      54             : 
+      55       11255 :         BUG_ON(nr >= nv);
+      56             : 
+      57             :         /* setup the coefficients matrix */
+      58       41316 :         for (j = 0; j < nr; ++j)
+      59      119934 :                 for (k = 0; k < nr; ++k)
+      60      179746 :                         G[j * nr + k] = A(ip[j], id[k]);
+      61             : 
+      62             :         /* invert it to solve the system of linear equations */
+      63       11255 :         raid_invert(G, V, nr);
+      64             : 
+      65             :         /* get multiplication tables */
+      66       41316 :         for (j = 0; j < nr; ++j)
+      67      119934 :                 for (k = 0; k < nr; ++k)
+      68      179746 :                         T[j][k] = table(V[j * nr + k]);
+      69             : 
+      70             :         /* check all positions */
+      71       35831 :         for (i = 0; i < size; ++i) {
+      72             :                 uint8_t p[RAID_PARITY_MAX];
+      73             : 
+      74             :                 /* get parity */
+      75      151819 :                 for (j = 0; j < nv; ++j)
+      76      115994 :                         p[j] = v[nd + ip[j]][i];
+      77             : 
+      78             :                 /* compute delta parity, skipping broken disks */
+      79      609025 :                 for (j = 0, k = 0; j < nd; ++j) {
+      80             :                         uint8_t b;
+      81             : 
+      82             :                         /* skip broken disks */
+      83      573200 :                         if (k < nr && id[k] == j) {
+      84       66916 :                                 ++k;
+      85       66916 :                                 continue;
+      86             :                         }
+      87             : 
+      88      506284 :                         b = v[j][i];
+      89     2094442 :                         for (l = 0; l < nv; ++l)
+      90     1588158 :                                 p[l] ^= gfmul[b][gfgen[ip[l]][j]];
+      91             :                 }
+      92             : 
+      93             :                 /* reconstruct data */
+      94      102741 :                 for (j = 0; j < nr; ++j) {
+      95       66916 :                         uint8_t b = 0;
+      96       66916 :                         int idj = id[j];
+      97             : 
+      98             :                         /* recompute the data */
+      99      234594 :                         for (k = 0; k < nr; ++k)
+     100      167678 :                                 b ^= T[j][k][p[k]];
+     101             : 
+     102             :                         /* add the parity contribution of the reconstructed data */
+     103      166984 :                         for (l = nr; l < nv; ++l)
+     104      100068 :                                 p[l] ^= gfmul[b][gfgen[ip[l]][idj]];
+     105             :                 }
+     106             : 
+     107             :                 /* check that the final parity is 0 */
+     108       60482 :                 for (l = nr; l < nv; ++l)
+     109       35906 :                         if (p[l] != 0)
+     110       11249 :                                 return -1;
+     111             :         }
+     112             : 
+     113           6 :         return 0;
+     114             : }
+     115             : 
+     116       11255 : int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v)
+     117             : {
+     118             :         /* valid parity index */
+     119             :         int ip[RAID_PARITY_MAX];
+     120             :         int vp;
+     121             :         int rd;
+     122             :         int i, j;
+     123             : 
+     124             :         /* enforce limit on size */
+     125       11255 :         BUG_ON(size % 64 != 0);
+     126             : 
+     127             :         /* enforce limit on number of failures */
+     128       11255 :         BUG_ON(nr >= np); /* >= because we check with extra parity */
+     129       11255 :         BUG_ON(np > RAID_PARITY_MAX);
+     130             : 
+     131             :         /* enforce order in index vector */
+     132       11255 :         BUG_ON(nr >= 2 && ir[0] >= ir[1]);
+     133       11255 :         BUG_ON(nr >= 3 && ir[1] >= ir[2]);
+     134       11255 :         BUG_ON(nr >= 4 && ir[2] >= ir[3]);
+     135       11255 :         BUG_ON(nr >= 5 && ir[3] >= ir[4]);
+     136       11255 :         BUG_ON(nr >= 6 && ir[4] >= ir[5]);
+     137             : 
+     138             :         /* enforce limit on index vector */
+     139       11255 :         BUG_ON(nr > 0 && ir[nr-1] >= nd + np);
+     140             : 
+     141             :         /* count failed data disk */
+     142       11255 :         rd = 0;
+     143       52571 :         while (rd < nr && ir[rd] < nd)
+     144       30061 :                 ++rd;
+     145             : 
+     146             :         /* put valid parities into ip[] */
+     147       11255 :         vp = 0;
+     148       76488 :         for (i = rd, j = 0; j < np; ++j) {
+     149             :                 /* if parity is failed */
+     150       65233 :                 if (i < nr && ir[i] == nd + j) {
+     151             :                         /* skip broken parity */
+     152       10664 :                         ++i;
+     153             :                 } else {
+     154             :                         /* store valid parity */
+     155       54569 :                         ip[vp] = j;
+     156       54569 :                         ++vp;
+     157             :                 }
+     158             :         }
+     159             : 
+     160       11255 :         return raid_validate(rd, ir, vp, ip, nd, size, v);
+     161             : }
+     162             : 
+     163           7 : int raid_scan(int *ir, int nd, int np, size_t size, void **v)
+     164             : {
+     165             :         int r;
+     166             : 
+     167             :         /* check the special case of no failure */
+     168           7 :         if (np != 0 && raid_check(0, 0, nd, np, size, v) == 0)
+     169           1 :                 return 0;
+     170             : 
+     171             :         /* for each number of possible failures */
+     172          16 :         for (r = 1; r < np; ++r) {
+     173             :                 /* try all combinations of r failures on n disks */
+     174          15 :                 combination_first(r, nd + np, ir);
+     175             :                 do {
+     176             :                         /* verify if the combination is a valid one */
+     177       11249 :                         if (raid_check(r, ir, nd, np, size, v) == 0)
+     178           5 :                                 return r;
+     179       22488 :                 } while (combination_next(r, nd + np, ir));
+     180             :         }
+     181             : 
+     182             :         /* no solution found */
+     183           1 :         return -1;
+     184             : }
+     185             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/combo.h.func-sort-c.html b/cov/raid/combo.h.func-sort-c.html new file mode 100644 index 00000000..fd39e790 --- /dev/null +++ b/cov/raid/combo.h.func-sort-c.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/combo.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - combo.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:3030100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/combo.h.func.html b/cov/raid/combo.h.func.html new file mode 100644 index 00000000..619ca74b --- /dev/null +++ b/cov/raid/combo.h.func.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/combo.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - combo.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:3030100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/combo.h.gcov.html b/cov/raid/combo.h.gcov.html new file mode 100644 index 00000000..9334dd99 --- /dev/null +++ b/cov/raid/combo.h.gcov.html @@ -0,0 +1,231 @@ + + + + + + + LCOV - lcov.info - raid/combo.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - combo.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:3030100.0 %
Date:2015-05-12Functions:00-
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #ifndef __RAID_COMBO_H
+      16             : #define __RAID_COMBO_H
+      17             : 
+      18             : #include <assert.h>
+      19             : 
+      20             : /**
+      21             :  * Get the first permutation with repetition of r of n elements.
+      22             :  *
+      23             :  * Typical use is with permutation_next() in the form :
+      24             :  *
+      25             :  * int i[R];
+      26             :  * permutation_first(R, N, i);
+      27             :  * do {
+      28             :  *    code using i[0], i[1], ..., i[R-1]
+      29             :  * } while (permutation_next(R, N, i));
+      30             :  *
+      31             :  * It's equivalent at the code :
+      32             :  *
+      33             :  * for(i[0]=0;i[0]<N;++i[0])
+      34             :  *     for(i[1]=0;i[1]<N;++i[1])
+      35             :  *        ...
+      36             :  *            for(i[R-2]=0;i[R-2]<N;++i[R-2])
+      37             :  *                for(i[R-1]=0;i[R-1]<N;++i[R-1])
+      38             :  *                    code using i[0], i[1], ..., i[R-1]
+      39             :  */
+      40             : static __always_inline void permutation_first(int r, int n, int *c)
+      41             : {
+      42             :         int i;
+      43             : 
+      44             :         (void)n; /* unused, but kept for clarity */
+      45          18 :         assert(0 < r && r <= n);
+      46             : 
+      47          81 :         for (i = 0; i < r; ++i)
+      48          63 :                 c[i] = 0;
+      49             : }
+      50             : 
+      51             : /**
+      52             :  * Get the next permutation with repetition of r of n elements.
+      53             :  * Return ==0 when finished.
+      54             :  */
+      55             : static __always_inline int permutation_next(int r, int n, int *c)
+      56             : {
+      57      167958 :         int i = r - 1; /* present position */
+      58             : 
+      59             : recurse:
+      60             :         /* next element at position i */
+      61      201528 :         ++c[i];
+      62             : 
+      63             :         /* if the position has reached the max */
+      64      201528 :         if (c[i] >= n) {
+      65             : 
+      66             :                 /* if we are at the first level, we have finished */
+      67       33588 :                 if (i == 0)
+      68          18 :                         return 0;
+      69             : 
+      70             :                 /* increase the previous position */
+      71       33570 :                 --i;
+      72             :                 goto recurse;
+      73             :         }
+      74             : 
+      75      167940 :         ++i;
+      76             : 
+      77             :         /* initialize all the next positions, if any */
+      78      201465 :         while (i < r) {
+      79       33525 :                 c[i] = 0;
+      80       33525 :                 ++i;
+      81             :         }
+      82             : 
+      83      167940 :         return 1;
+      84             : }
+      85             : 
+      86             : /**
+      87             :  * Get the first combination without repetition of r of n elements.
+      88             :  *
+      89             :  * Typical use is with combination_next() in the form :
+      90             :  *
+      91             :  * int i[R];
+      92             :  * combination_first(R, N, i);
+      93             :  * do {
+      94             :  *    code using i[0], i[1], ..., i[R-1]
+      95             :  * } while (combination_next(R, N, i));
+      96             :  *
+      97             :  * It's equivalent at the code :
+      98             :  *
+      99             :  * for(i[0]=0;i[0]<N-(R-1);++i[0])
+     100             :  *     for(i[1]=i[0]+1;i[1]<N-(R-2);++i[1])
+     101             :  *        ...
+     102             :  *            for(i[R-2]=i[R-3]+1;i[R-2]<N-1;++i[R-2])
+     103             :  *                for(i[R-1]=i[R-2]+1;i[R-1]<N;++i[R-1])
+     104             :  *                    code using i[0], i[1], ..., i[R-1]
+     105             :  */
+     106             : static __always_inline void combination_first(int r, int n, int *c)
+     107             : {
+     108             :         int i;
+     109             : 
+     110             :         (void)n; /* unused, but kept for clarity */
+     111      211353 :         assert(0 < r && r <= n);
+     112             : 
+     113      704541 :         for (i = 0; i < r; ++i)
+     114      493188 :                 c[i] = i;
+     115             : }
+     116             : 
+     117             : /**
+     118             :  * Get the next combination without repetition of r of n elements.
+     119             :  * Return ==0 when finished.
+     120             :  */
+     121             : static __always_inline int combination_next(int r, int n, int *c)
+     122             : {
+     123       51703 :         int i = r - 1; /* present position */
+     124       51703 :         int h = n; /* high limit for this position */
+     125             : 
+     126             : recurse:
+     127             :         /* next element at position i */
+     128       84576 :         ++c[i];
+     129             : 
+     130             :         /* if the position has reached the max */
+     131       84576 :         if (c[i] >= h) {
+     132             : 
+     133             :                 /* if we are at the first level, we have finished */
+     134       44868 :                 if (i == 0)
+     135       11995 :                         return 0;
+     136             : 
+     137             :                 /* increase the previous position */
+     138       32873 :                 --i;
+     139       32873 :                 --h;
+     140             :                 goto recurse;
+     141             :         }
+     142             : 
+     143       39708 :         ++i;
+     144             : 
+     145             :         /* initialize all the next positions, if any */
+     146       62253 :         while (i < r) {
+     147             :                 /* each position start at the next value of the previous one */
+     148       22545 :                 c[i] = c[i - 1] + 1;
+     149       22545 :                 ++i;
+     150             :         }
+     151             : 
+     152       39708 :         return 1;
+     153             : }
+     154             : #endif
+     155             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/cpu.h.func-sort-c.html b/cov/raid/cpu.h.func-sort-c.html new file mode 100644 index 00000000..0dd3307f --- /dev/null +++ b/cov/raid/cpu.h.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/cpu.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - cpu.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:556683.3 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_cpuid1879
raid_cpu_match_sse1070
raid_cpu_has_ssse3530
raid_cpu_match_avx288
raid_cpu_has_avx2288
raid_cpu_has_sse2276
raid_cpu_has_crc32264
raid_cpu_info249
raid_cpu_has_slowmult241
raid_xgetbv23
raid_cpu_has_slowextendedreg4
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/cpu.h.func.html b/cov/raid/cpu.h.func.html new file mode 100644 index 00000000..a48d4784 --- /dev/null +++ b/cov/raid/cpu.h.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/cpu.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - cpu.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:556683.3 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_cpu_has_avx2288
raid_cpu_has_crc32264
raid_cpu_has_slowextendedreg4
raid_cpu_has_slowmult241
raid_cpu_has_sse2276
raid_cpu_has_ssse3530
raid_cpu_info249
raid_cpu_match_avx288
raid_cpu_match_sse1070
raid_cpuid1879
raid_xgetbv23
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/cpu.h.gcov.html b/cov/raid/cpu.h.gcov.html new file mode 100644 index 00000000..7b0d8d9b --- /dev/null +++ b/cov/raid/cpu.h.gcov.html @@ -0,0 +1,345 @@ + + + + + + + LCOV - lcov.info - raid/cpu.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - cpu.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:556683.3 %
Date:2015-05-12Functions:1111100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #ifndef __RAID_CPU_H
+      16             : #define __RAID_CPU_H
+      17             : 
+      18             : #ifdef CONFIG_X86
+      19             : 
+      20        1879 : static inline void raid_cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t *reg)
+      21             : {
+      22        1879 :         asm volatile (
+      23             : #if defined(__i386__) && defined(__PIC__)
+      24             :                 /* allow compilation in PIC mode saving ebx */
+      25             :                 "xchgl %%ebx, %1\n"
+      26             :                 "cpuid\n"
+      27             :                 "xchgl %%ebx, %1\n"
+      28             :                 : "=a" (reg[0]), "=r" (reg[1]), "=c" (reg[2]), "=d" (reg[3])
+      29             :                 : "0" (func_eax), "2" (sub_ecx)
+      30             : #else
+      31             :                 "cpuid\n"
+      32        1879 :                 : "=a" (reg[0]), "=b" (reg[1]), "=c" (reg[2]), "=d" (reg[3])
+      33             :                 : "0" (func_eax), "2" (sub_ecx)
+      34             : #endif
+      35             :         );
+      36        1879 : }
+      37             : 
+      38          23 : static inline void raid_xgetbv(uint32_t* reg)
+      39             : {
+      40             :         /* get the value of the Extended Control Register ecx=0 */
+      41          23 :         asm volatile (
+      42             :                 /* uses a direct encoding of the XGETBV instruction as only recent */
+      43             :                 /* assemblers support it. */
+      44             :                 /* the next line is equivalent at: "xgetbv\n" */
+      45             :                 ".byte 0x0f, 0x01, 0xd0\n"
+      46          23 :                 : "=a" (reg[0]), "=d" (reg[3])
+      47             :                 : "c" (0)
+      48             :         );
+      49          23 : }
+      50             : 
+      51             : #define CPU_VENDOR_MAX 13
+      52             : 
+      53         249 : static inline void raid_cpu_info(char *vendor, unsigned *family, unsigned *model)
+      54             : {
+      55             :         uint32_t reg[4];
+      56             :         unsigned f, ef, m, em;
+      57             : 
+      58         249 :         raid_cpuid(0, 0, reg);
+      59             : 
+      60         249 :         ((uint32_t*)vendor)[0] = reg[1];
+      61         249 :         ((uint32_t*)vendor)[1] = reg[3];
+      62         249 :         ((uint32_t*)vendor)[2] = reg[2];
+      63         249 :         vendor[12] = 0;
+      64             : 
+      65         249 :         raid_cpuid(1, 0, reg);
+      66             : 
+      67         249 :         f = (reg[0] >> 8) & 0xF;
+      68         249 :         ef = (reg[0] >> 20) & 0xFF;
+      69         249 :         m = (reg[0] >> 4) & 0xF;
+      70         249 :         em = (reg[0] >> 16) & 0xF;
+      71             : 
+      72         249 :         if (strcmp(vendor, "AuthenticAMD") == 0) {
+      73           0 :                 if (f < 15) {
+      74           0 :                         *family = f;
+      75           0 :                         *model = m;
+      76             :                 } else {
+      77           0 :                         *family = f + ef;
+      78           0 :                         *model = m + (em << 4);
+      79             :                 }
+      80             :         } else {
+      81         249 :                 *family = f + ef;
+      82         249 :                 *model = m + (em << 4);
+      83             :         }
+      84         249 : }
+      85             : 
+      86        1070 : static inline int raid_cpu_match_sse(uint32_t cpuid_1_ecx, uint32_t cpuid_1_edx)
+      87             : {
+      88             :         uint32_t reg[4];
+      89             : 
+      90        1070 :         raid_cpuid(1, 0, reg);
+      91        1070 :         if ((reg[2] & cpuid_1_ecx) != cpuid_1_ecx)
+      92          18 :                 return 0;
+      93        1052 :         if ((reg[3] & cpuid_1_edx) != cpuid_1_edx)
+      94           0 :                 return 0;
+      95             : 
+      96        1052 :         return 1;
+      97             : }
+      98             : 
+      99         288 : static inline int raid_cpu_match_avx(uint32_t cpuid_1_ecx, uint32_t cpuid_7_ebx, uint32_t xcr0)
+     100             : {
+     101             :         uint32_t reg[4];
+     102             : 
+     103         288 :         raid_cpuid(1, 0, reg);
+     104         288 :         if ((reg[2] & cpuid_1_ecx) != cpuid_1_ecx)
+     105         265 :                 return 0;
+     106             : 
+     107          23 :         raid_xgetbv(reg);
+     108          23 :         if ((reg[0] & xcr0) != xcr0)
+     109           0 :                 return 0;
+     110             : 
+     111          23 :         raid_cpuid(7, 0, reg);
+     112          23 :         if ((reg[1] & cpuid_7_ebx) != cpuid_7_ebx)
+     113           0 :                 return 0;
+     114             : 
+     115          23 :         return 1;
+     116             : }
+     117             : 
+     118         276 : static inline int raid_cpu_has_sse2(void)
+     119             : {
+     120             :         /*
+     121             :          * Intel® 64 and IA-32 Architectures Software Developer's Manual
+     122             :          * 325462-048US September 2013
+     123             :          *
+     124             :          * 11.6.2 Checking for SSE/SSE2 Support
+     125             :          * Before an application attempts to use the SSE and/or SSE2 extensions, it should check
+     126             :          * that they are present on the processor:
+     127             :          * 1. Check that the processor supports the CPUID instruction. Bit 21 of the EFLAGS
+     128             :          * register can be used to check processor's support the CPUID instruction.
+     129             :          * 2. Check that the processor supports the SSE and/or SSE2 extensions (true if
+     130             :          * CPUID.01H:EDX.SSE[bit 25] = 1 and/or CPUID.01H:EDX.SSE2[bit 26] = 1).
+     131             :          */
+     132         276 :         return raid_cpu_match_sse(
+     133             :                 0,
+     134             :                 1 << 26); /* SSE2 */
+     135             : }
+     136             : 
+     137         530 : static inline int raid_cpu_has_ssse3(void)
+     138             : {
+     139             :         /*
+     140             :          * Intel® 64 and IA-32 Architectures Software Developer's Manual
+     141             :          * 325462-048US September 2013
+     142             :          *
+     143             :          * 12.7.2 Checking for SSSE3 Support
+     144             :          * Before an application attempts to use the SSSE3 extensions, the application should
+     145             :          * follow the steps illustrated in Section 11.6.2, "Checking for SSE/SSE2 Support."
+     146             :          * Next, use the additional step provided below:
+     147             :          * Check that the processor supports SSSE3 (if CPUID.01H:ECX.SSSE3[bit 9] = 1).
+     148             :          */
+     149         530 :         return raid_cpu_match_sse(
+     150             :                 1 << 9, /* SSSE3 */
+     151             :                 1 << 26); /* SSE2 */
+     152             : }
+     153             : 
+     154         264 : static inline int raid_cpu_has_crc32(void)
+     155             : {
+     156             :         /*
+     157             :          * Intel® 64 and IA-32 Architectures Software Developer's Manual
+     158             :          * 325462-048US September 2013
+     159             :          *
+     160             :          * 12.12.3 Checking for SSE4.2 Support
+     161             :          * ...
+     162             :          * Before an application attempts to use the CRC32 instruction, it must check
+     163             :          * that the processor supports SSE4.2 (if CPUID.01H:ECX.SSE4_2[bit 20] = 1).
+     164             :          */
+     165         264 :         return raid_cpu_match_sse(
+     166             :                 1 << 20, /* CRC32 */
+     167             :                 0);
+     168             : }
+     169             : 
+     170         288 : static inline int raid_cpu_has_avx2(void)
+     171             : {
+     172             :         /*
+     173             :          * Intel Architecture Instruction Set Extensions Programming Reference
+     174             :          * 319433-022 October 2014
+     175             :          *
+     176             :          * 14.3 Detection of AVX instructions
+     177             :          * 1) Detect CPUID.1:ECX.OSXSAVE[bit 27] = 1 (XGETBV enabled for application use1)
+     178             :          * 2) Issue XGETBV and verify that XCR0[2:1] = `11b' (XMM state and YMM state are enabled by OS).
+     179             :          * 3) detect CPUID.1:ECX.AVX[bit 28] = 1 (AVX instructions supported).
+     180             :          * (Step 3 can be done in any order relative to 1 and 2)
+     181             :          *
+     182             :          * 14.7.1 Detection of AVX2
+     183             :          * Hardware support for AVX2 is indicated by CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]=1.
+     184             :          * Application Software must identify that hardware supports AVX, after that it must
+     185             :          * also detect support for AVX2 by checking CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5].
+     186             :          */
+     187         288 :         return raid_cpu_match_avx(
+     188             :                 (1 << 27) | (1 << 28), /* OSXSAVE and AVX */
+     189             :                 1 << 5, /* AVX2 */
+     190             :                 3 << 1); /* OS saves XMM and YMM registers */
+     191             : }
+     192             : 
+     193             : static inline int raid_cpu_has_avx512bw(void)
+     194             : {
+     195             :         /*
+     196             :          * Intel Architecture Instruction Set Extensions Programming Reference
+     197             :          * 319433-022 October 2014
+     198             :          *
+     199             :          * 2.2 Detection of 512-bit Instruction Groups of Intel AVX-512 Family
+     200             :          * 1) Detect CPUID.1:ECX.OSXSAVE[bit 27] = 1 (XGETBV enabled for application use)
+     201             :          * 2) Execute XGETBV and verify that XCR0[7:5] = `111b' (OPMASK state, upper 256-bit of
+     202             :          * ZMM0-ZMM15 and ZMM16-ZMM31 state are enabled by OS) and that XCR0[2:1] = `11b'
+     203             :          * (XMM state and YMM state are enabled by OS).
+     204             :          * 3) Verify both CPUID.0x7.0:EBX.AVX512F[bit 16] = 1, CPUID.0x7.0:EBX.AVX512BW[bit 30] = 1.
+     205             :          */
+     206             : 
+     207             :         /* note that intentionally we don't check for AVX and AVX2 */
+     208             :         /* because the documentation doesn't require that */
+     209             :         return raid_cpu_match_avx(
+     210             :                 1 << 27, /* XSAVE/XGETBV */
+     211             :                 (1 << 16) | (1 << 30), /* AVX512F and AVX512BW */
+     212             :                 (3 << 1) | (7 << 5)); /* OS saves XMM, YMM and ZMM registers */
+     213             : }
+     214             : 
+     215             : /**
+     216             :  * Check if the processor has a slow MULT implementation.
+     217             :  * If yes, it's better to use a hash not based on multiplication.
+     218             :  */
+     219         241 : static inline int raid_cpu_has_slowmult(void)
+     220             : {
+     221             :         char vendor[CPU_VENDOR_MAX];
+     222             :         unsigned family;
+     223             :         unsigned model;
+     224             : 
+     225         241 :         raid_cpu_info(vendor, &family, &model);
+     226             : 
+     227         241 :         if (strcmp(vendor, "GenuineIntel") == 0) {
+     228             :                 /*
+     229             :                  * Intel Atom
+     230             :                  * Murmur3 based on MUL instruction, is a lot slower
+     231             :                  * than Spooky2 based on SHIFTs.
+     232             :                  * Like: 378 MB/s vs 3413 MB/s
+     233             :                  */
+     234         241 :                 if (family == 6 && model == 28)
+     235           0 :                         return 1;
+     236             :         }
+     237             : 
+     238         241 :         return 0;
+     239             : }
+     240             : 
+     241             : /**
+     242             :  * Check if the processor has a slow extended set of SSE registers.
+     243             :  * If yes, it's better to limit the unroll to the firsrt 8 registers.
+     244             :  */
+     245           4 : static inline int raid_cpu_has_slowextendedreg(void)
+     246             : {
+     247             :         char vendor[CPU_VENDOR_MAX];
+     248             :         unsigned family;
+     249             :         unsigned model;
+     250             : 
+     251           4 :         raid_cpu_info(vendor, &family, &model);
+     252             : 
+     253           4 :         if (strcmp(vendor, "AuthenticAMD") == 0) {
+     254             :                 /*
+     255             :                  * AMD Bulldozer
+     256             :                  * PAR1/PAR2 implementations using 16 SSE registers are slower
+     257             :                  * than ones using only the first 8 registers.
+     258             :                  * Like: 4465 MB/s vs 4922 MB/s.
+     259             :                  */
+     260           0 :                 if (family == 21)
+     261           0 :                         return 1;
+     262             :         }
+     263             : 
+     264           4 :         return 0;
+     265             : }
+     266             : #endif
+     267             : 
+     268             : #endif
+     269             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/gf.h.func-sort-c.html b/cov/raid/gf.h.func-sort-c.html new file mode 100644 index 00000000..c0e88f22 --- /dev/null +++ b/cov/raid/gf.h.func-sort-c.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/gf.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - gf.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2727100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/gf.h.func.html b/cov/raid/gf.h.func.html new file mode 100644 index 00000000..aec8427d --- /dev/null +++ b/cov/raid/gf.h.func.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/gf.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - gf.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2727100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/gf.h.gcov.html b/cov/raid/gf.h.gcov.html new file mode 100644 index 00000000..eb684d86 --- /dev/null +++ b/cov/raid/gf.h.gcov.html @@ -0,0 +1,213 @@ + + + + + + + LCOV - lcov.info - raid/gf.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - gf.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:2727100.0 %
Date:2015-05-12Functions:00-
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #ifndef __RAID_GF_H
+      16             : #define __RAID_GF_H
+      17             : 
+      18             : /*
+      19             :  * Galois field operations.
+      20             :  *
+      21             :  * Basic range checks are implemented using BUG_ON().
+      22             :  */
+      23             : 
+      24             : /*
+      25             :  * GF a*b.
+      26             :  */
+      27             : static __always_inline uint8_t mul(uint8_t a, uint8_t b)
+      28             : {
+      29    23811482 :         return gfmul[a][b];
+      30             : }
+      31             : 
+      32             : /*
+      33             :  * GF 1/a.
+      34             :  * Not defined for a == 0.
+      35             :  */
+      36             : static __always_inline uint8_t inv(uint8_t v)
+      37             : {
+      38      635202 :         BUG_ON(v == 0); /* division by zero */
+      39             : 
+      40      635202 :         return gfinv[v];
+      41             : }
+      42             : 
+      43             : /*
+      44             :  * GF 2^a.
+      45             :  */
+      46             : static __always_inline uint8_t pow2(int v)
+      47             : {
+      48         396 :         BUG_ON(v < 0 || v > 254); /* invalid exponent */
+      49             : 
+      50         396 :         return gfexp[v];
+      51             : }
+      52             : 
+      53             : /*
+      54             :  * Gets the multiplication table for a specified value.
+      55             :  */
+      56             : static __always_inline const uint8_t *table(uint8_t v)
+      57             : {
+      58      409825 :         return gfmul[v];
+      59             : }
+      60             : 
+      61             : /*
+      62             :  * Gets the generator matrix coefficient for parity 'p' and disk 'd'.
+      63             :  */
+      64             : static __always_inline uint8_t A(int p, int d)
+      65             : {
+      66     2605268 :         return gfgen[p][d];
+      67             : }
+      68             : 
+      69             : /*
+      70             :  * Dereference as uint8_t
+      71             :  */
+      72             : #define v_8(p) (*(uint8_t *)&(p))
+      73             : 
+      74             : /*
+      75             :  * Dereference as uint32_t
+      76             :  */
+      77             : #define v_32(p) (*(uint32_t *)&(p))
+      78             : 
+      79             : /*
+      80             :  * Dereference as uint64_t
+      81             :  */
+      82             : #define v_64(p) (*(uint64_t *)&(p))
+      83             : 
+      84             : /*
+      85             :  * Multiply each byte of a uint32 by 2 in the GF(2^8).
+      86             :  */
+      87             : static __always_inline uint32_t x2_32(uint32_t v)
+      88             : {
+      89    33036096 :         uint32_t mask = v & 0x80808080U;
+      90             : 
+      91    33036096 :         mask = (mask << 1) - (mask >> 7);
+      92    33036096 :         v = (v << 1) & 0xfefefefeU;
+      93    33036096 :         v ^= mask & 0x1d1d1d1dU;
+      94    33036096 :         return v;
+      95             : }
+      96             : 
+      97             : /*
+      98             :  * Multiply each byte of a uint64 by 2 in the GF(2^8).
+      99             :  */
+     100             : static __always_inline uint64_t x2_64(uint64_t v)
+     101             : {
+     102    16518048 :         uint64_t mask = v & 0x8080808080808080ULL;
+     103             : 
+     104    16518048 :         mask = (mask << 1) - (mask >> 7);
+     105    16518048 :         v = (v << 1) & 0xfefefefefefefefeULL;
+     106    16518048 :         v ^= mask & 0x1d1d1d1d1d1d1d1dULL;
+     107    16518048 :         return v;
+     108             : }
+     109             : 
+     110             : /*
+     111             :  * Divide each byte of a uint32 by 2 in the GF(2^8).
+     112             :  */
+     113             : static __always_inline uint32_t d2_32(uint32_t v)
+     114             : {
+     115    12847040 :         uint32_t mask = v & 0x01010101U;
+     116             : 
+     117    12847040 :         mask = (mask << 8) - mask;
+     118    12847040 :         v = (v >> 1) & 0x7f7f7f7fU;
+     119    12847040 :         v ^= mask & 0x8e8e8e8eU;
+     120    12847040 :         return v;
+     121             : }
+     122             : 
+     123             : /*
+     124             :  * Divide each byte of a uint64 by 2 in the GF(2^8).
+     125             :  */
+     126             : static __always_inline uint64_t d2_64(uint64_t v)
+     127             : {
+     128     6423520 :         uint64_t mask = v & 0x0101010101010101ULL;
+     129             : 
+     130     6423520 :         mask = (mask << 8) - mask;
+     131     6423520 :         v = (v >> 1) & 0x7f7f7f7f7f7f7f7fULL;
+     132     6423520 :         v ^= mask & 0x8e8e8e8e8e8e8e8eULL;
+     133     6423520 :         return v;
+     134             : }
+     135             : 
+     136             : #endif
+     137             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/helper.c.func-sort-c.html b/cov/raid/helper.c.func-sort-c.html new file mode 100644 index 00000000..5167da02 --- /dev/null +++ b/cov/raid/helper.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - raid/helper.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - helper.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4646100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_insert324726
raid_sort55986
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/helper.c.func.html b/cov/raid/helper.c.func.html new file mode 100644 index 00000000..c7cd965e --- /dev/null +++ b/cov/raid/helper.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - raid/helper.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - helper.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4646100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_insert324726
raid_sort55986
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/helper.c.gcov.html b/cov/raid/helper.c.gcov.html new file mode 100644 index 00000000..72b8efd5 --- /dev/null +++ b/cov/raid/helper.c.gcov.html @@ -0,0 +1,170 @@ + + + + + + + LCOV - lcov.info - raid/helper.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - helper.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4646100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : 
+      17             : #define RAID_SWAP(a, b) \
+      18             :         do { \
+      19             :                 if (v[a] > v[b]) { \
+      20             :                         int t = v[a]; \
+      21             :                         v[a] = v[b]; \
+      22             :                         v[b] = t; \
+      23             :                 } \
+      24             :         } while (0)
+      25             : 
+      26       55986 : void raid_sort(int n, int *v)
+      27             : {
+      28             :         /* sorting networks generated with Batcher's Merge-Exchange */
+      29       55986 :         switch (n) {
+      30             :         case 2:
+      31          36 :                 RAID_SWAP(0, 1);
+      32          36 :                 break;
+      33             :         case 3:
+      34         216 :                 RAID_SWAP(0, 2);
+      35         216 :                 RAID_SWAP(0, 1);
+      36         216 :                 RAID_SWAP(1, 2);
+      37         216 :                 break;
+      38             :         case 4:
+      39        1296 :                 RAID_SWAP(0, 2);
+      40        1296 :                 RAID_SWAP(1, 3);
+      41        1296 :                 RAID_SWAP(0, 1);
+      42        1296 :                 RAID_SWAP(2, 3);
+      43        1296 :                 RAID_SWAP(1, 2);
+      44        1296 :                 break;
+      45             :         case 5:
+      46        7776 :                 RAID_SWAP(0, 4);
+      47        7776 :                 RAID_SWAP(0, 2);
+      48        7776 :                 RAID_SWAP(1, 3);
+      49        7776 :                 RAID_SWAP(2, 4);
+      50        7776 :                 RAID_SWAP(0, 1);
+      51        7776 :                 RAID_SWAP(2, 3);
+      52        7776 :                 RAID_SWAP(1, 4);
+      53        7776 :                 RAID_SWAP(1, 2);
+      54        7776 :                 RAID_SWAP(3, 4);
+      55        7776 :                 break;
+      56             :         case 6:
+      57       46656 :                 RAID_SWAP(0, 4);
+      58       46656 :                 RAID_SWAP(1, 5);
+      59       46656 :                 RAID_SWAP(0, 2);
+      60       46656 :                 RAID_SWAP(1, 3);
+      61       46656 :                 RAID_SWAP(2, 4);
+      62       46656 :                 RAID_SWAP(3, 5);
+      63       46656 :                 RAID_SWAP(0, 1);
+      64       46656 :                 RAID_SWAP(2, 3);
+      65       46656 :                 RAID_SWAP(4, 5);
+      66       46656 :                 RAID_SWAP(1, 4);
+      67       46656 :                 RAID_SWAP(1, 2);
+      68       46656 :                 RAID_SWAP(3, 4);
+      69       46656 :                 break;
+      70             :         }
+      71       55986 : }
+      72             : 
+      73      324726 : void raid_insert(int n, int *v, int i)
+      74             : {
+      75             :         /* we don't use binary search because this is intended */
+      76             :         /* for very small vectors and we want to optimize the case */
+      77             :         /* of elements inserted already in order */
+      78             : 
+      79             :         /* insert at the end */
+      80      324726 :         v[n] = i;
+      81             : 
+      82             :         /* swap until in the correct position */
+      83      976977 :         while (n > 0 && v[n - 1] > v[n]) {
+      84             :                 /* swap */
+      85      327525 :                 int t = v[n - 1];
+      86             : 
+      87      327525 :                 v[n - 1] = v[n];
+      88      327525 :                 v[n] = t;
+      89             : 
+      90             :                 /* previous position */
+      91      327525 :                 --n;
+      92             :         }
+      93      324726 : }
+      94             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/index-sort-f.html b/cov/raid/index-sort-f.html new file mode 100644 index 00000000..aa8caae5 --- /dev/null +++ b/cov/raid/index-sort-f.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - lcov.info - raid + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raidHitTotalCoverage
Test:lcov.infoLines:1737174899.4 %
Date:2015-05-12Functions:8282100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
internal.h +
100.0%
+
100.0 %5 / 5-0 / 0
gf.h +
100.0%
+
100.0 %27 / 27-0 / 0
combo.h +
100.0%
+
100.0 %30 / 30-0 / 0
x86z.c +
100.0%
+
100.0 %35 / 35100.0 %1 / 1
intz.c +
100.0%
+
100.0 %58 / 58100.0 %2 / 2
helper.c +
100.0%
+
100.0 %46 / 46100.0 %2 / 2
check.c +
100.0%
+
100.0 %60 / 60100.0 %3 / 3
memory.c +
100.0%
+
100.0 %49 / 49100.0 %4 / 4
module.c +
100.0%
+
100.0 %159 / 159100.0 %7 / 7
test.c +
100.0%
+
100.0 %140 / 140100.0 %7 / 7
raid.c +
100.0%
+
100.0 %123 / 123100.0 %9 / 9
cpu.h +
83.3%83.3%
+
83.3 %55 / 66100.0 %11 / 11
tag.c +
100.0%
+
100.0 %26 / 26100.0 %11 / 11
int.c +
100.0%
+
100.0 %240 / 240100.0 %11 / 11
x86.c +
100.0%
+
100.0 %684 / 684100.0 %14 / 14
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/index-sort-l.html b/cov/raid/index-sort-l.html new file mode 100644 index 00000000..9f833ebf --- /dev/null +++ b/cov/raid/index-sort-l.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - lcov.info - raid + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raidHitTotalCoverage
Test:lcov.infoLines:1737174899.4 %
Date:2015-05-12Functions:8282100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
cpu.h +
83.3%83.3%
+
83.3 %55 / 66100.0 %11 / 11
internal.h +
100.0%
+
100.0 %5 / 5-0 / 0
tag.c +
100.0%
+
100.0 %26 / 26100.0 %11 / 11
gf.h +
100.0%
+
100.0 %27 / 27-0 / 0
combo.h +
100.0%
+
100.0 %30 / 30-0 / 0
x86z.c +
100.0%
+
100.0 %35 / 35100.0 %1 / 1
helper.c +
100.0%
+
100.0 %46 / 46100.0 %2 / 2
memory.c +
100.0%
+
100.0 %49 / 49100.0 %4 / 4
intz.c +
100.0%
+
100.0 %58 / 58100.0 %2 / 2
check.c +
100.0%
+
100.0 %60 / 60100.0 %3 / 3
raid.c +
100.0%
+
100.0 %123 / 123100.0 %9 / 9
test.c +
100.0%
+
100.0 %140 / 140100.0 %7 / 7
module.c +
100.0%
+
100.0 %159 / 159100.0 %7 / 7
int.c +
100.0%
+
100.0 %240 / 240100.0 %11 / 11
x86.c +
100.0%
+
100.0 %684 / 684100.0 %14 / 14
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/index.html b/cov/raid/index.html new file mode 100644 index 00000000..c44f3c7c --- /dev/null +++ b/cov/raid/index.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - lcov.info - raid + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raidHitTotalCoverage
Test:lcov.infoLines:1737174899.4 %
Date:2015-05-12Functions:8282100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
check.c +
100.0%
+
100.0 %60 / 60100.0 %3 / 3
combo.h +
100.0%
+
100.0 %30 / 30-0 / 0
cpu.h +
83.3%83.3%
+
83.3 %55 / 66100.0 %11 / 11
gf.h +
100.0%
+
100.0 %27 / 27-0 / 0
helper.c +
100.0%
+
100.0 %46 / 46100.0 %2 / 2
int.c +
100.0%
+
100.0 %240 / 240100.0 %11 / 11
internal.h +
100.0%
+
100.0 %5 / 5-0 / 0
intz.c +
100.0%
+
100.0 %58 / 58100.0 %2 / 2
memory.c +
100.0%
+
100.0 %49 / 49100.0 %4 / 4
module.c +
100.0%
+
100.0 %159 / 159100.0 %7 / 7
raid.c +
100.0%
+
100.0 %123 / 123100.0 %9 / 9
tag.c +
100.0%
+
100.0 %26 / 26100.0 %11 / 11
test.c +
100.0%
+
100.0 %140 / 140100.0 %7 / 7
x86.c +
100.0%
+
100.0 %684 / 684100.0 %14 / 14
x86z.c +
100.0%
+
100.0 %35 / 35100.0 %1 / 1
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/int.c.func-sort-c.html b/cov/raid/int.c.func-sort-c.html new file mode 100644 index 00000000..400667c3 --- /dev/null +++ b/cov/raid/int.c.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/int.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - int.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:240240100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_recX_int817849
raid_rec2_int81220
raid_gen1_int64187
raid_rec1_int8164
raid_gen1_int32116
raid_gen2_int6447
raid_gen2_int3247
raid_gen3_int826
raid_gen4_int818
raid_gen5_int818
raid_gen6_int815
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/int.c.func.html b/cov/raid/int.c.func.html new file mode 100644 index 00000000..a060fa1b --- /dev/null +++ b/cov/raid/int.c.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/int.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - int.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:240240100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen1_int32116
raid_gen1_int64187
raid_gen2_int3247
raid_gen2_int6447
raid_gen3_int826
raid_gen4_int818
raid_gen5_int818
raid_gen6_int815
raid_rec1_int8164
raid_rec2_int81220
raid_recX_int817849
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/int.c.gcov.html b/cov/raid/int.c.gcov.html new file mode 100644 index 00000000..5bf22327 --- /dev/null +++ b/cov/raid/int.c.gcov.html @@ -0,0 +1,632 @@ + + + + + + + LCOV - lcov.info - raid/int.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - int.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:240240100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "gf.h"
+      17             : 
+      18             : /*
+      19             :  * GEN1 (RAID5 with xor) 32bit C implementation
+      20             :  */
+      21         116 : void raid_gen1_int32(int nd, size_t size, void **vv)
+      22             : {
+      23         116 :         uint8_t **v = (uint8_t **)vv;
+      24             :         uint8_t *p;
+      25             :         int d, l;
+      26             :         size_t i;
+      27             : 
+      28             :         uint32_t p0;
+      29             :         uint32_t p1;
+      30             : 
+      31         116 :         l = nd - 1;
+      32         116 :         p = v[nd];
+      33             : 
+      34     3702996 :         for (i = 0; i < size; i += 8) {
+      35     3702880 :                 p0 = v_32(v[l][i]);
+      36     3702880 :                 p1 = v_32(v[l][i + 4]);
+      37    29624352 :                 for (d = l - 1; d >= 0; --d) {
+      38    25921472 :                         p0 ^= v_32(v[d][i]);
+      39    25921472 :                         p1 ^= v_32(v[d][i + 4]);
+      40             :                 }
+      41     3702880 :                 v_32(p[i]) = p0;
+      42     3702880 :                 v_32(p[i + 4]) = p1;
+      43             :         }
+      44         116 : }
+      45             : 
+      46             : /*
+      47             :  * GEN1 (RAID5 with xor) 64bit C implementation
+      48             :  */
+      49         187 : void raid_gen1_int64(int nd, size_t size, void **vv)
+      50             : {
+      51         187 :         uint8_t **v = (uint8_t **)vv;
+      52             :         uint8_t *p;
+      53             :         int d, l;
+      54             :         size_t i;
+      55             : 
+      56             :         uint64_t p0;
+      57             :         uint64_t p1;
+      58             : 
+      59         187 :         l = nd - 1;
+      60         187 :         p = v[nd];
+      61             : 
+      62     3014891 :         for (i = 0; i < size; i += 16) {
+      63     3014704 :                 p0 = v_64(v[l][i]);
+      64     3014704 :                 p1 = v_64(v[l][i + 8]);
+      65    24118288 :                 for (d = l - 1; d >= 0; --d) {
+      66    21103584 :                         p0 ^= v_64(v[d][i]);
+      67    21103584 :                         p1 ^= v_64(v[d][i + 8]);
+      68             :                 }
+      69     3014704 :                 v_64(p[i]) = p0;
+      70     3014704 :                 v_64(p[i + 8]) = p1;
+      71             :         }
+      72         187 : }
+      73             : 
+      74             : /*
+      75             :  * GEN2 (RAID6 with powers of 2) 32bit C implementation
+      76             :  */
+      77          47 : void raid_gen2_int32(int nd, size_t size, void **vv)
+      78             : {
+      79          47 :         uint8_t **v = (uint8_t **)vv;
+      80             :         uint8_t *p;
+      81             :         uint8_t *q;
+      82             :         int d, l;
+      83             :         size_t i;
+      84             : 
+      85             :         uint32_t d0, q0, p0;
+      86             :         uint32_t d1, q1, p1;
+      87             : 
+      88          47 :         l = nd - 1;
+      89          47 :         p = v[nd];
+      90          47 :         q = v[nd + 1];
+      91             : 
+      92     1441935 :         for (i = 0; i < size; i += 8) {
+      93     1441888 :                 q0 = p0 = v_32(v[l][i]);
+      94     1441888 :                 q1 = p1 = v_32(v[l][i + 4]);
+      95    11536416 :                 for (d = l - 1; d >= 0; --d) {
+      96    10094528 :                         d0 = v_32(v[d][i]);
+      97    10094528 :                         d1 = v_32(v[d][i + 4]);
+      98             : 
+      99    10094528 :                         p0 ^= d0;
+     100    10094528 :                         p1 ^= d1;
+     101             : 
+     102    10094528 :                         q0 = x2_32(q0);
+     103    10094528 :                         q1 = x2_32(q1);
+     104             : 
+     105    10094528 :                         q0 ^= d0;
+     106    10094528 :                         q1 ^= d1;
+     107             :                 }
+     108     1441888 :                 v_32(p[i]) = p0;
+     109     1441888 :                 v_32(p[i + 4]) = p1;
+     110     1441888 :                 v_32(q[i]) = q0;
+     111     1441888 :                 v_32(q[i + 4]) = q1;
+     112             :         }
+     113          47 : }
+     114             : 
+     115             : /*
+     116             :  * GEN2 (RAID6 with powers of 2) 64bit C implementation
+     117             :  */
+     118          47 : void raid_gen2_int64(int nd, size_t size, void **vv)
+     119             : {
+     120          47 :         uint8_t **v = (uint8_t **)vv;
+     121             :         uint8_t *p;
+     122             :         uint8_t *q;
+     123             :         int d, l;
+     124             :         size_t i;
+     125             : 
+     126             :         uint64_t d0, q0, p0;
+     127             :         uint64_t d1, q1, p1;
+     128             : 
+     129          47 :         l = nd - 1;
+     130          47 :         p = v[nd];
+     131          47 :         q = v[nd + 1];
+     132             : 
+     133      720991 :         for (i = 0; i < size; i += 16) {
+     134      720944 :                 q0 = p0 = v_64(v[l][i]);
+     135      720944 :                 q1 = p1 = v_64(v[l][i + 8]);
+     136     5768208 :                 for (d = l - 1; d >= 0; --d) {
+     137     5047264 :                         d0 = v_64(v[d][i]);
+     138     5047264 :                         d1 = v_64(v[d][i + 8]);
+     139             : 
+     140     5047264 :                         p0 ^= d0;
+     141     5047264 :                         p1 ^= d1;
+     142             : 
+     143     5047264 :                         q0 = x2_64(q0);
+     144     5047264 :                         q1 = x2_64(q1);
+     145             : 
+     146     5047264 :                         q0 ^= d0;
+     147     5047264 :                         q1 ^= d1;
+     148             :                 }
+     149      720944 :                 v_64(p[i]) = p0;
+     150      720944 :                 v_64(p[i + 8]) = p1;
+     151      720944 :                 v_64(q[i]) = q0;
+     152      720944 :                 v_64(q[i + 8]) = q1;
+     153             :         }
+     154          47 : }
+     155             : 
+     156             : /*
+     157             :  * GEN3 (triple parity with Cauchy matrix) 8bit C implementation
+     158             :  *
+     159             :  * Note that instead of a generic multiplication table, likely resulting
+     160             :  * in multiple cache misses, a precomputed table could be used.
+     161             :  * But this is only a kind of reference function, and we are not really
+     162             :  * interested in speed.
+     163             :  */
+     164          26 : void raid_gen3_int8(int nd, size_t size, void **vv)
+     165             : {
+     166          26 :         uint8_t **v = (uint8_t **)vv;
+     167             :         uint8_t *p;
+     168             :         uint8_t *q;
+     169             :         uint8_t *r;
+     170             :         int d, l;
+     171             :         size_t i;
+     172             : 
+     173             :         uint8_t d0, r0, q0, p0;
+     174             : 
+     175          26 :         l = nd - 1;
+     176          26 :         p = v[nd];
+     177          26 :         q = v[nd + 1];
+     178          26 :         r = v[nd + 2];
+     179             : 
+     180     6291994 :         for (i = 0; i < size; i += 1) {
+     181     6291968 :                 p0 = q0 = r0 = 0;
+     182    50340096 :                 for (d = l; d > 0; --d) {
+     183    44048128 :                         d0 = v_8(v[d][i]);
+     184             : 
+     185    44048128 :                         p0 ^= d0;
+     186    44048128 :                         q0 ^= gfmul[d0][gfgen[1][d]];
+     187    44048128 :                         r0 ^= gfmul[d0][gfgen[2][d]];
+     188             :                 }
+     189             : 
+     190             :                 /* first disk with all coefficients at 1 */
+     191     6291968 :                 d0 = v_8(v[0][i]);
+     192             : 
+     193     6291968 :                 p0 ^= d0;
+     194     6291968 :                 q0 ^= d0;
+     195     6291968 :                 r0 ^= d0;
+     196             : 
+     197     6291968 :                 v_8(p[i]) = p0;
+     198     6291968 :                 v_8(q[i]) = q0;
+     199     6291968 :                 v_8(r[i]) = r0;
+     200             :         }
+     201          26 : }
+     202             : 
+     203             : /*
+     204             :  * GEN4 (quad parity with Cauchy matrix) 8bit C implementation
+     205             :  *
+     206             :  * Note that instead of a generic multiplication table, likely resulting
+     207             :  * in multiple cache misses, a precomputed table could be used.
+     208             :  * But this is only a kind of reference function, and we are not really
+     209             :  * interested in speed.
+     210             :  */
+     211          18 : void raid_gen4_int8(int nd, size_t size, void **vv)
+     212             : {
+     213          18 :         uint8_t **v = (uint8_t **)vv;
+     214             :         uint8_t *p;
+     215             :         uint8_t *q;
+     216             :         uint8_t *r;
+     217             :         uint8_t *s;
+     218             :         int d, l;
+     219             :         size_t i;
+     220             : 
+     221             :         uint8_t d0, s0, r0, q0, p0;
+     222             : 
+     223          18 :         l = nd - 1;
+     224          18 :         p = v[nd];
+     225          18 :         q = v[nd + 1];
+     226          18 :         r = v[nd + 2];
+     227          18 :         s = v[nd + 3];
+     228             : 
+     229     4194834 :         for (i = 0; i < size; i += 1) {
+     230     4194816 :                 p0 = q0 = r0 = s0 = 0;
+     231    33562880 :                 for (d = l; d > 0; --d) {
+     232    29368064 :                         d0 = v_8(v[d][i]);
+     233             : 
+     234    29368064 :                         p0 ^= d0;
+     235    29368064 :                         q0 ^= gfmul[d0][gfgen[1][d]];
+     236    29368064 :                         r0 ^= gfmul[d0][gfgen[2][d]];
+     237    29368064 :                         s0 ^= gfmul[d0][gfgen[3][d]];
+     238             :                 }
+     239             : 
+     240             :                 /* first disk with all coefficients at 1 */
+     241     4194816 :                 d0 = v_8(v[0][i]);
+     242             : 
+     243     4194816 :                 p0 ^= d0;
+     244     4194816 :                 q0 ^= d0;
+     245     4194816 :                 r0 ^= d0;
+     246     4194816 :                 s0 ^= d0;
+     247             : 
+     248     4194816 :                 v_8(p[i]) = p0;
+     249     4194816 :                 v_8(q[i]) = q0;
+     250     4194816 :                 v_8(r[i]) = r0;
+     251     4194816 :                 v_8(s[i]) = s0;
+     252             :         }
+     253          18 : }
+     254             : 
+     255             : /*
+     256             :  * GEN5 (penta parity with Cauchy matrix) 8bit C implementation
+     257             :  *
+     258             :  * Note that instead of a generic multiplication table, likely resulting
+     259             :  * in multiple cache misses, a precomputed table could be used.
+     260             :  * But this is only a kind of reference function, and we are not really
+     261             :  * interested in speed.
+     262             :  */
+     263          18 : void raid_gen5_int8(int nd, size_t size, void **vv)
+     264             : {
+     265          18 :         uint8_t **v = (uint8_t **)vv;
+     266             :         uint8_t *p;
+     267             :         uint8_t *q;
+     268             :         uint8_t *r;
+     269             :         uint8_t *s;
+     270             :         uint8_t *t;
+     271             :         int d, l;
+     272             :         size_t i;
+     273             : 
+     274             :         uint8_t d0, t0, s0, r0, q0, p0;
+     275             : 
+     276          18 :         l = nd - 1;
+     277          18 :         p = v[nd];
+     278          18 :         q = v[nd + 1];
+     279          18 :         r = v[nd + 2];
+     280          18 :         s = v[nd + 3];
+     281          18 :         t = v[nd + 4];
+     282             : 
+     283     4194834 :         for (i = 0; i < size; i += 1) {
+     284     4194816 :                 p0 = q0 = r0 = s0 = t0 = 0;
+     285    33562880 :                 for (d = l; d > 0; --d) {
+     286    29368064 :                         d0 = v_8(v[d][i]);
+     287             : 
+     288    29368064 :                         p0 ^= d0;
+     289    29368064 :                         q0 ^= gfmul[d0][gfgen[1][d]];
+     290    29368064 :                         r0 ^= gfmul[d0][gfgen[2][d]];
+     291    29368064 :                         s0 ^= gfmul[d0][gfgen[3][d]];
+     292    29368064 :                         t0 ^= gfmul[d0][gfgen[4][d]];
+     293             :                 }
+     294             : 
+     295             :                 /* first disk with all coefficients at 1 */
+     296     4194816 :                 d0 = v_8(v[0][i]);
+     297             : 
+     298     4194816 :                 p0 ^= d0;
+     299     4194816 :                 q0 ^= d0;
+     300     4194816 :                 r0 ^= d0;
+     301     4194816 :                 s0 ^= d0;
+     302     4194816 :                 t0 ^= d0;
+     303             : 
+     304     4194816 :                 v_8(p[i]) = p0;
+     305     4194816 :                 v_8(q[i]) = q0;
+     306     4194816 :                 v_8(r[i]) = r0;
+     307     4194816 :                 v_8(s[i]) = s0;
+     308     4194816 :                 v_8(t[i]) = t0;
+     309             :         }
+     310          18 : }
+     311             : 
+     312             : /*
+     313             :  * GEN6 (hexa parity with Cauchy matrix) 8bit C implementation
+     314             :  *
+     315             :  * Note that instead of a generic multiplication table, likely resulting
+     316             :  * in multiple cache misses, a precomputed table could be used.
+     317             :  * But this is only a kind of reference function, and we are not really
+     318             :  * interested in speed.
+     319             :  */
+     320          15 : void raid_gen6_int8(int nd, size_t size, void **vv)
+     321             : {
+     322          15 :         uint8_t **v = (uint8_t **)vv;
+     323             :         uint8_t *p;
+     324             :         uint8_t *q;
+     325             :         uint8_t *r;
+     326             :         uint8_t *s;
+     327             :         uint8_t *t;
+     328             :         uint8_t *u;
+     329             :         int d, l;
+     330             :         size_t i;
+     331             : 
+     332             :         uint8_t d0, u0, t0, s0, r0, q0, p0;
+     333             : 
+     334          15 :         l = nd - 1;
+     335          15 :         p = v[nd];
+     336          15 :         q = v[nd + 1];
+     337          15 :         r = v[nd + 2];
+     338          15 :         s = v[nd + 3];
+     339          15 :         t = v[nd + 4];
+     340          15 :         u = v[nd + 5];
+     341             : 
+     342     3408399 :         for (i = 0; i < size; i += 1) {
+     343     3408384 :                 p0 = q0 = r0 = s0 = t0 = u0 = 0;
+     344    27271424 :                 for (d = l; d > 0; --d) {
+     345    23863040 :                         d0 = v_8(v[d][i]);
+     346             : 
+     347    23863040 :                         p0 ^= d0;
+     348    23863040 :                         q0 ^= gfmul[d0][gfgen[1][d]];
+     349    23863040 :                         r0 ^= gfmul[d0][gfgen[2][d]];
+     350    23863040 :                         s0 ^= gfmul[d0][gfgen[3][d]];
+     351    23863040 :                         t0 ^= gfmul[d0][gfgen[4][d]];
+     352    23863040 :                         u0 ^= gfmul[d0][gfgen[5][d]];
+     353             :                 }
+     354             : 
+     355             :                 /* first disk with all coefficients at 1 */
+     356     3408384 :                 d0 = v_8(v[0][i]);
+     357             : 
+     358     3408384 :                 p0 ^= d0;
+     359     3408384 :                 q0 ^= d0;
+     360     3408384 :                 r0 ^= d0;
+     361     3408384 :                 s0 ^= d0;
+     362     3408384 :                 t0 ^= d0;
+     363     3408384 :                 u0 ^= d0;
+     364             : 
+     365     3408384 :                 v_8(p[i]) = p0;
+     366     3408384 :                 v_8(q[i]) = q0;
+     367     3408384 :                 v_8(r[i]) = r0;
+     368     3408384 :                 v_8(s[i]) = s0;
+     369     3408384 :                 v_8(t[i]) = t0;
+     370     3408384 :                 v_8(u[i]) = u0;
+     371             :         }
+     372          15 : }
+     373             : 
+     374             : /*
+     375             :  * Recover failure of one data block at index id[0] using parity at index
+     376             :  * ip[0] for any RAID level.
+     377             :  *
+     378             :  * Starting from the equation:
+     379             :  *
+     380             :  * Pd = A[ip[0],id[0]] * Dx
+     381             :  *
+     382             :  * and solving we get:
+     383             :  *
+     384             :  * Dx = A[ip[0],id[0]]^-1 * Pd
+     385             :  */
+     386         164 : void raid_rec1_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+     387             : {
+     388         164 :         uint8_t **v = (uint8_t **)vv;
+     389             :         uint8_t *p;
+     390             :         uint8_t *pa;
+     391             :         const uint8_t *T;
+     392             :         uint8_t G;
+     393             :         uint8_t V;
+     394             :         size_t i;
+     395             : 
+     396             :         (void)nr; /* unused, it's always 1 */
+     397             : 
+     398             :         /* if it's RAID5 uses the faster function */
+     399         164 :         if (ip[0] == 0) {
+     400          24 :                 raid_rec1of1(id, nd, size, vv);
+     401         188 :                 return;
+     402             :         }
+     403             : 
+     404             :         /* setup the coefficients matrix */
+     405         280 :         G = A(ip[0], id[0]);
+     406             : 
+     407             :         /* invert it to solve the system of linear equations */
+     408         280 :         V = inv(G);
+     409             : 
+     410             :         /* get multiplication tables */
+     411         280 :         T = table(V);
+     412             : 
+     413             :         /* compute delta parity */
+     414         140 :         raid_delta_gen(1, id, ip, nd, size, vv);
+     415             : 
+     416         140 :         p = v[nd + ip[0]];
+     417         140 :         pa = v[id[0]];
+     418             : 
+     419    14701708 :         for (i = 0; i < size; ++i) {
+     420             :                 /* delta */
+     421    14701568 :                 uint8_t Pd = p[i] ^ pa[i];
+     422             : 
+     423             :                 /* reconstruct */
+     424    14701568 :                 pa[i] = T[Pd];
+     425             :         }
+     426             : }
+     427             : 
+     428             : /*
+     429             :  * Recover failure of two data blocks at indexes id[0],id[1] using parity at
+     430             :  * indexes ip[0],ip[1] for any RAID level.
+     431             :  *
+     432             :  * Starting from the equations:
+     433             :  *
+     434             :  * Pd = A[ip[0],id[0]] * Dx + A[ip[0],id[1]] * Dy
+     435             :  * Qd = A[ip[1],id[0]] * Dx + A[ip[1],id[1]] * Dy
+     436             :  *
+     437             :  * we solve inverting the coefficients matrix.
+     438             :  */
+     439        1220 : void raid_rec2_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+     440             : {
+     441        1220 :         uint8_t **v = (uint8_t **)vv;
+     442             :         uint8_t *p;
+     443             :         uint8_t *pa;
+     444             :         uint8_t *q;
+     445             :         uint8_t *qa;
+     446        1220 :         const int N = 2;
+     447        1220 :         const uint8_t *T[N][N];
+     448        1220 :         uint8_t G[N * N];
+     449        1220 :         uint8_t V[N * N];
+     450             :         size_t i;
+     451             :         int j, k;
+     452             : 
+     453             :         (void)nr; /* unused, it's always 2 */
+     454             : 
+     455             :         /* if it's RAID6 recovering with P and Q uses the faster function */
+     456        1220 :         if (ip[0] == 0 && ip[1] == 1) {
+     457         132 :                 raid_rec2of2_int8(id, ip, nd, size, vv);
+     458        1352 :                 return;
+     459             :         }
+     460             : 
+     461             :         /* setup the coefficients matrix */
+     462        3264 :         for (j = 0; j < N; ++j)
+     463        6528 :                 for (k = 0; k < N; ++k)
+     464        8704 :                         G[j * N + k] = A(ip[j], id[k]);
+     465             : 
+     466             :         /* invert it to solve the system of linear equations */
+     467        1088 :         raid_invert(G, V, N);
+     468             : 
+     469             :         /* get multiplication tables */
+     470        3264 :         for (j = 0; j < N; ++j)
+     471        6528 :                 for (k = 0; k < N; ++k)
+     472        8704 :                         T[j][k] = table(V[j * N + k]);
+     473             : 
+     474             :         /* compute delta parity */
+     475        1088 :         raid_delta_gen(2, id, ip, nd, size, vv);
+     476             : 
+     477        1088 :         p = v[nd + ip[0]];
+     478        1088 :         q = v[nd + ip[1]];
+     479        1088 :         pa = v[id[0]];
+     480        1088 :         qa = v[id[1]];
+     481             : 
+     482     8660032 :         for (i = 0; i < size; ++i) {
+     483             :                 /* delta */
+     484     8658944 :                 uint8_t Pd = p[i] ^ pa[i];
+     485     8658944 :                 uint8_t Qd = q[i] ^ qa[i];
+     486             : 
+     487             :                 /* reconstruct */
+     488     8658944 :                 pa[i] = T[0][0][Pd] ^ T[0][1][Qd];
+     489     8658944 :                 qa[i] = T[1][0][Pd] ^ T[1][1][Qd];
+     490             :         }
+     491             : }
+     492             : 
+     493             : /*
+     494             :  * Recover failure of N data blocks at indexes id[N] using parity at indexes
+     495             :  * ip[N] for any RAID level.
+     496             :  *
+     497             :  * Starting from the N equations, with 0<=i<N :
+     498             :  *
+     499             :  * PD[i] = sum(A[ip[i],id[j]] * D[i]) 0<=j<N
+     500             :  *
+     501             :  * we solve inverting the coefficients matrix.
+     502             :  *
+     503             :  * Note that referring at previous equations you have:
+     504             :  * PD[0] = Pd, PD[1] = Qd, PD[2] = Rd, ...
+     505             :  * D[0] = Dx, D[1] = Dy, D[2] = Dz, ...
+     506             :  */
+     507       17849 : void raid_recX_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+     508             : {
+     509       17849 :         uint8_t **v = (uint8_t **)vv;
+     510             :         uint8_t *p[RAID_PARITY_MAX];
+     511             :         uint8_t *pa[RAID_PARITY_MAX];
+     512             :         const uint8_t *T[RAID_PARITY_MAX][RAID_PARITY_MAX];
+     513             :         uint8_t G[RAID_PARITY_MAX * RAID_PARITY_MAX];
+     514             :         uint8_t V[RAID_PARITY_MAX * RAID_PARITY_MAX];
+     515             :         size_t i;
+     516             :         int j, k;
+     517             : 
+     518             :         /* setup the coefficients matrix */
+     519       91289 :         for (j = 0; j < nr; ++j)
+     520      388636 :                 for (k = 0; k < nr; ++k)
+     521      630392 :                         G[j * nr + k] = A(ip[j], id[k]);
+     522             : 
+     523             :         /* invert it to solve the system of linear equations */
+     524       17849 :         raid_invert(G, V, nr);
+     525             : 
+     526             :         /* get multiplication tables */
+     527       91289 :         for (j = 0; j < nr; ++j)
+     528      388636 :                 for (k = 0; k < nr; ++k)
+     529      630392 :                         T[j][k] = table(V[j * nr + k]);
+     530             : 
+     531             :         /* compute delta parity */
+     532       17849 :         raid_delta_gen(nr, id, ip, nd, size, vv);
+     533             : 
+     534       91289 :         for (j = 0; j < nr; ++j) {
+     535       73440 :                 p[j] = v[nd + ip[j]];
+     536       73440 :                 pa[j] = v[id[j]];
+     537             :         }
+     538             : 
+     539    38108857 :         for (i = 0; i < size; ++i) {
+     540             :                 uint8_t PD[RAID_PARITY_MAX];
+     541             : 
+     542             :                 /* delta */
+     543   207739136 :                 for (j = 0; j < nr; ++j)
+     544   169648128 :                         PD[j] = p[j][i] ^ pa[j][i];
+     545             : 
+     546             :                 /* reconstruct */
+     547   207739136 :                 for (j = 0; j < nr; ++j) {
+     548   169648128 :                         uint8_t b = 0;
+     549             : 
+     550   971054080 :                         for (k = 0; k < nr; ++k)
+     551   801405952 :                                 b ^= T[j][k][PD[k]];
+     552   169648128 :                         pa[j][i] = b;
+     553             :                 }
+     554             :         }
+     555       17849 : }
+     556             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/internal.h.func-sort-c.html b/cov/raid/internal.h.func-sort-c.html new file mode 100644 index 00000000..6369bba4 --- /dev/null +++ b/cov/raid/internal.h.func-sort-c.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/internal.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - internal.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:55100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/internal.h.func.html b/cov/raid/internal.h.func.html new file mode 100644 index 00000000..6bbdd896 --- /dev/null +++ b/cov/raid/internal.h.func.html @@ -0,0 +1,72 @@ + + + + + + + LCOV - lcov.info - raid/internal.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - internal.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:55100.0 %
Date:2015-05-12Functions:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/internal.h.gcov.html b/cov/raid/internal.h.gcov.html new file mode 100644 index 00000000..0578cc97 --- /dev/null +++ b/cov/raid/internal.h.gcov.html @@ -0,0 +1,340 @@ + + + + + + + LCOV - lcov.info - raid/internal.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - internal.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:55100.0 %
Date:2015-05-12Functions:00-
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #ifndef __RAID_INTERNAL_H
+      16             : #define __RAID_INTERNAL_H
+      17             : 
+      18             : /*
+      19             :  * Supported architecture.
+      20             :  *
+      21             :  * Detect the target architecture directly from the compiler.
+      22             :  */
+      23             : #if defined(__i386__)
+      24             : #define CONFIG_X86 1
+      25             : #define CONFIG_X86_32 1
+      26             : #endif
+      27             : 
+      28             : #if defined(__x86_64__)
+      29             : #define CONFIG_X86 1
+      30             : #define CONFIG_X86_64 1
+      31             : #endif
+      32             : 
+      33             : /*
+      34             :  * Supported instruction sets.
+      35             :  *
+      36             :  * It may happen that the assembler is too old to support
+      37             :  * all instructions, even if the architecture supports them.
+      38             :  * These defines allow to exclude from the build the not supported ones.
+      39             :  *
+      40             :  * If in your project you use a predefined assembler, you can define them
+      41             :  * using fixed values, instead of using the HAVE_* defines.
+      42             :  */
+      43             : #if HAVE_CONFIG_H
+      44             : 
+      45             : /* Includes the project configuration for HAVE_* defines */
+      46             : #include "config.h"
+      47             : 
+      48             : #if HAVE_SSE2 /* Enables SSE2 only if the assembler supports it */
+      49             : #define CONFIG_SSE2 1
+      50             : #endif
+      51             : 
+      52             : #if HAVE_SSSE3 /* Enables SSSE3 only if the assembler supports it */
+      53             : #define CONFIG_SSSE3 1
+      54             : #endif
+      55             : 
+      56             : #if HAVE_AVX2 /* Enables AVX2 only if the assembler supports it */
+      57             : #define CONFIG_AVX2 1
+      58             : #endif
+      59             : #else
+      60             : /* If no config file, assumes the assembler supports everything in x86 */
+      61             : #ifdef CONFIG_X86
+      62             : #define CONFIG_SSE2 1
+      63             : #define CONFIG_SSSE3 1
+      64             : #define CONFIG_AVX2 1
+      65             : #endif
+      66             : #endif
+      67             : 
+      68             : /*
+      69             :  * Includes anything required for compatibility.
+      70             :  */
+      71             : #include <assert.h>
+      72             : #include <stdint.h>
+      73             : #include <stdlib.h>
+      74             : #include <string.h>
+      75             : 
+      76             : /*
+      77             :  * Inverse assert.
+      78             :  */
+      79             : #define BUG_ON(a) assert(!(a))
+      80             : 
+      81             : /*
+      82             :  * Forced inline.
+      83             :  */
+      84             : #ifndef __always_inline
+      85             : #define __always_inline inline __attribute__((always_inline))
+      86             : #endif
+      87             : 
+      88             : /*
+      89             :  * Forced alignment.
+      90             :  */
+      91             : #ifndef __aligned
+      92             : #define __aligned(a) __attribute__((aligned(a)))
+      93             : #endif
+      94             : 
+      95             : /*
+      96             :  * Align a pointer at the specified size.
+      97             :  */
+      98             : static __always_inline void *__align_ptr(void *ptr, uintptr_t size)
+      99             : {
+     100      680589 :         uintptr_t offset = (uintptr_t)ptr;
+     101             : 
+     102      680589 :         offset = (offset + size - 1U) & ~(size - 1U);
+     103             : 
+     104      680589 :         return (void *)offset;
+     105             : }
+     106             : 
+     107             : /*
+     108             :  * Includes the main interface headers.
+     109             :  */
+     110             : #include "raid.h"
+     111             : #include "helper.h"
+     112             : 
+     113             : /*
+     114             :  * Internal functions.
+     115             :  *
+     116             :  * These are intended to provide access for testing.
+     117             :  */
+     118             : int raid_selftest(void);
+     119             : void raid_gen_ref(int nd, int np, size_t size, void **vv);
+     120             : void raid_invert(uint8_t *M, uint8_t *V, int n);
+     121             : void raid_delta_gen(int nr, int *id, int *ip, int nd, size_t size, void **v);
+     122             : void raid_rec1of1(int *id, int nd, size_t size, void **v);
+     123             : void raid_rec2of2_int8(int *id, int *ip, int nd, size_t size, void **vv);
+     124             : void raid_gen1_int32(int nd, size_t size, void **vv);
+     125             : void raid_gen1_int64(int nd, size_t size, void **vv);
+     126             : void raid_gen1_sse2(int nd, size_t size, void **vv);
+     127             : void raid_gen1_avx2(int nd, size_t size, void **vv);
+     128             : void raid_gen2_int32(int nd, size_t size, void **vv);
+     129             : void raid_gen2_int64(int nd, size_t size, void **vv);
+     130             : void raid_gen2_sse2(int nd, size_t size, void **vv);
+     131             : void raid_gen2_avx2(int nd, size_t size, void **vv);
+     132             : void raid_gen2_sse2ext(int nd, size_t size, void **vv);
+     133             : void raid_genz_int32(int nd, size_t size, void **vv);
+     134             : void raid_genz_int64(int nd, size_t size, void **vv);
+     135             : void raid_genz_sse2(int nd, size_t size, void **vv);
+     136             : void raid_genz_sse2ext(int nd, size_t size, void **vv);
+     137             : void raid_genz_avx2ext(int nd, size_t size, void **vv);
+     138             : void raid_gen3_int8(int nd, size_t size, void **vv);
+     139             : void raid_gen3_ssse3(int nd, size_t size, void **vv);
+     140             : void raid_gen3_ssse3ext(int nd, size_t size, void **vv);
+     141             : void raid_gen3_avx2ext(int nd, size_t size, void **vv);
+     142             : void raid_gen4_int8(int nd, size_t size, void **vv);
+     143             : void raid_gen4_ssse3(int nd, size_t size, void **vv);
+     144             : void raid_gen4_ssse3ext(int nd, size_t size, void **vv);
+     145             : void raid_gen4_avx2ext(int nd, size_t size, void **vv);
+     146             : void raid_gen5_int8(int nd, size_t size, void **vv);
+     147             : void raid_gen5_ssse3(int nd, size_t size, void **vv);
+     148             : void raid_gen5_ssse3ext(int nd, size_t size, void **vv);
+     149             : void raid_gen5_avx2ext(int nd, size_t size, void **vv);
+     150             : void raid_gen6_int8(int nd, size_t size, void **vv);
+     151             : void raid_gen6_ssse3(int nd, size_t size, void **vv);
+     152             : void raid_gen6_ssse3ext(int nd, size_t size, void **vv);
+     153             : void raid_gen6_avx2ext(int nd, size_t size, void **vv);
+     154             : void raid_rec1_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     155             : void raid_rec2_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     156             : void raid_recX_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     157             : void raid_rec1_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     158             : void raid_rec2_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     159             : void raid_recX_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     160             : void raid_rec1_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     161             : void raid_rec2_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     162             : void raid_recX_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     163             : 
+     164             : /*
+     165             :  * Internal naming.
+     166             :  *
+     167             :  * These are intented to provide access for testing.
+     168             :  */
+     169             : const char *raid_gen1_tag(void);
+     170             : const char *raid_gen2_tag(void);
+     171             : const char *raid_genz_tag(void);
+     172             : const char *raid_gen3_tag(void);
+     173             : const char *raid_gen4_tag(void);
+     174             : const char *raid_gen5_tag(void);
+     175             : const char *raid_gen6_tag(void);
+     176             : const char *raid_rec1_tag(void);
+     177             : const char *raid_rec2_tag(void);
+     178             : const char *raid_recX_tag(void);
+     179             : 
+     180             : /*
+     181             :  * Internal forwarders.
+     182             :  */
+     183             : extern void (*raid_gen3_ptr)(int nd, size_t size, void **vv);
+     184             : extern void (*raid_genz_ptr)(int nd, size_t size, void **vv);
+     185             : extern void (*raid_gen_ptr[RAID_PARITY_MAX])(
+     186             :         int nd, size_t size, void **vv);
+     187             : extern void (*raid_rec_ptr[RAID_PARITY_MAX])(
+     188             :         int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     189             : 
+     190             : /*
+     191             :  * Tables.
+     192             :  */
+     193             : extern const uint8_t raid_gfmul[256][256] __aligned(256);
+     194             : extern const uint8_t raid_gfexp[256] __aligned(256);
+     195             : extern const uint8_t raid_gfinv[256] __aligned(256);
+     196             : extern const uint8_t raid_gfvandermonde[3][256] __aligned(256);
+     197             : extern const uint8_t raid_gfcauchy[6][256] __aligned(256);
+     198             : extern const uint8_t raid_gfcauchypshufb[251][4][2][16] __aligned(256);
+     199             : extern const uint8_t raid_gfmulpshufb[256][2][16] __aligned(256);
+     200             : extern const uint8_t (*raid_gfgen)[256];
+     201             : #define gfmul raid_gfmul
+     202             : #define gfexp raid_gfexp
+     203             : #define gfinv raid_gfinv
+     204             : #define gfvandermonde raid_gfvandermonde
+     205             : #define gfcauchy raid_gfcauchy
+     206             : #define gfgenpshufb raid_gfcauchypshufb
+     207             : #define gfmulpshufb raid_gfmulpshufb
+     208             : #define gfgen raid_gfgen
+     209             : 
+     210             : /*
+     211             :  * Assembler blocks.
+     212             :  */
+     213             : #ifdef CONFIG_X86
+     214             : #ifdef CONFIG_SSE2
+     215             : static __always_inline void raid_sse_begin(void)
+     216             : {
+     217             : }
+     218             : 
+     219             : static __always_inline void raid_sse_end(void)
+     220             : {
+     221             :         /* SSE and AVX code uses non-temporal writes, like MOVNTDQ, */
+     222             :         /* that use a weak memory model. To ensure that other processors */
+     223             :         /* see correctly the data written, we use a store-store memory */
+     224             :         /* barrier at the end of the asm code */
+     225     1349399 :         asm volatile ("sfence" : : : "memory");
+     226             : 
+     227             :         /* clobbers registers used in the asm code */
+     228             :         /* this is required because in the Windows ABI, */
+     229             :         /* registers xmm6-xmm15 should be kept by the callee. */
+     230             :         /* this clobber list force the compiler to save any */
+     231             :         /* register that needs to be saved */
+     232             :         /* we check for __SSE2_ because we require that the */
+     233             :         /* compiler supports SSE2 registers in the clobber list */
+     234             : #ifdef __SSE2__
+     235             :         asm volatile ("" : : : "%xmm0", "%xmm1", "%xmm2", "%xmm3");
+     236             :         asm volatile ("" : : : "%xmm4", "%xmm5", "%xmm6", "%xmm7");
+     237             : #ifdef CONFIG_X86_64
+     238             :         asm volatile ("" : : : "%xmm8", "%xmm9", "%xmm10", "%xmm11");
+     239             :         asm volatile ("" : : : "%xmm12", "%xmm13", "%xmm14", "%xmm15");
+     240             : #endif
+     241             : #endif
+     242             : }
+     243             : #endif
+     244             : 
+     245             : #ifdef CONFIG_AVX2
+     246             : static __always_inline void raid_avx_begin(void)
+     247             : {
+     248             :         raid_sse_begin();
+     249             : }
+     250             : 
+     251             : static __always_inline void raid_avx_end(void)
+     252             : {
+     253             :         raid_sse_end();
+     254             : 
+     255             :         /* reset the upper part of the ymm registers */
+     256             :         /* to avoid the 70 clocks penality on the next */
+     257             :         /* xmm register use */
+     258       19675 :         asm volatile ("vzeroupper" : : : "memory");
+     259             : }
+     260             : #endif
+     261             : #endif /* CONFIG_X86 */
+     262             : 
+     263             : #endif
+     264             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/intz.c.func-sort-c.html b/cov/raid/intz.c.func-sort-c.html new file mode 100644 index 00000000..5ff87436 --- /dev/null +++ b/cov/raid/intz.c.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - raid/intz.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - intz.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5858100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_genz_int6429
raid_genz_int3229
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/intz.c.func.html b/cov/raid/intz.c.func.html new file mode 100644 index 00000000..ee68effe --- /dev/null +++ b/cov/raid/intz.c.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - raid/intz.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - intz.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5858100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_genz_int3229
raid_genz_int6429
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/intz.c.gcov.html b/cov/raid/intz.c.gcov.html new file mode 100644 index 00000000..13cc3e94 --- /dev/null +++ b/cov/raid/intz.c.gcov.html @@ -0,0 +1,195 @@ + + + + + + + LCOV - lcov.info - raid/intz.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - intz.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:5858100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "gf.h"
+      17             : 
+      18             : /*
+      19             :  * GENz (triple parity with powers of 2^-1) 32bit C implementation
+      20             :  */
+      21          29 : void raid_genz_int32(int nd, size_t size, void **vv)
+      22             : {
+      23          29 :         uint8_t **v = (uint8_t**)vv;
+      24             :         uint8_t *p;
+      25             :         uint8_t *q;
+      26             :         uint8_t *r;
+      27             :         int d, l;
+      28             :         size_t i;
+      29             : 
+      30             :         uint32_t d0, r0, q0, p0;
+      31             :         uint32_t d1, r1, q1, p1;
+      32             : 
+      33          29 :         l = nd - 1;
+      34          29 :         p = v[nd];
+      35          29 :         q = v[nd + 1];
+      36          29 :         r = v[nd + 2];
+      37             : 
+      38      917565 :         for (i = 0; i < size; i += 8) {
+      39      917536 :                 r0 = q0 = p0 = v_32(v[l][i]);
+      40      917536 :                 r1 = q1 = p1 = v_32(v[l][i + 4]);
+      41     7341056 :                 for (d = l - 1; d >= 0; --d) {
+      42     6423520 :                         d0 = v_32(v[d][i]);
+      43     6423520 :                         d1 = v_32(v[d][i + 4]);
+      44             : 
+      45     6423520 :                         p0 ^= d0;
+      46     6423520 :                         p1 ^= d1;
+      47             : 
+      48     6423520 :                         q0 = x2_32(q0);
+      49     6423520 :                         q1 = x2_32(q1);
+      50             : 
+      51     6423520 :                         q0 ^= d0;
+      52     6423520 :                         q1 ^= d1;
+      53             : 
+      54     6423520 :                         r0 = d2_32(r0);
+      55     6423520 :                         r1 = d2_32(r1);
+      56             : 
+      57     6423520 :                         r0 ^= d0;
+      58     6423520 :                         r1 ^= d1;
+      59             :                 }
+      60      917536 :                 v_32(p[i]) = p0;
+      61      917536 :                 v_32(p[i + 4]) = p1;
+      62      917536 :                 v_32(q[i]) = q0;
+      63      917536 :                 v_32(q[i + 4]) = q1;
+      64      917536 :                 v_32(r[i]) = r0;
+      65      917536 :                 v_32(r[i + 4]) = r1;
+      66             :         }
+      67          29 : }
+      68             : 
+      69             : /*
+      70             :  * GENz (triple parity with powers of 2^-1) 64bit C implementation
+      71             :  */
+      72          29 : void raid_genz_int64(int nd, size_t size, void **vv)
+      73             : {
+      74          29 :         uint8_t **v = (uint8_t**)vv;
+      75             :         uint8_t *p;
+      76             :         uint8_t *q;
+      77             :         uint8_t *r;
+      78             :         int d, l;
+      79             :         size_t i;
+      80             : 
+      81             :         uint64_t d0, r0, q0, p0;
+      82             :         uint64_t d1, r1, q1, p1;
+      83             : 
+      84          29 :         l = nd - 1;
+      85          29 :         p = v[nd];
+      86          29 :         q = v[nd + 1];
+      87          29 :         r = v[nd + 2];
+      88             : 
+      89      458797 :         for (i = 0; i < size; i += 16) {
+      90      458768 :                 r0 = q0 = p0 = v_64(v[l][i]);
+      91      458768 :                 r1 = q1 = p1 = v_64(v[l][i + 8]);
+      92     3670528 :                 for (d = l - 1; d >= 0; --d) {
+      93     3211760 :                         d0 = v_64(v[d][i]);
+      94     3211760 :                         d1 = v_64(v[d][i + 8]);
+      95             : 
+      96     3211760 :                         p0 ^= d0;
+      97     3211760 :                         p1 ^= d1;
+      98             : 
+      99     3211760 :                         q0 = x2_64(q0);
+     100     3211760 :                         q1 = x2_64(q1);
+     101             : 
+     102     3211760 :                         q0 ^= d0;
+     103     3211760 :                         q1 ^= d1;
+     104             : 
+     105     3211760 :                         r0 = d2_64(r0);
+     106     3211760 :                         r1 = d2_64(r1);
+     107             : 
+     108     3211760 :                         r0 ^= d0;
+     109     3211760 :                         r1 ^= d1;
+     110             :                 }
+     111      458768 :                 v_64(p[i]) = p0;
+     112      458768 :                 v_64(p[i + 8]) = p1;
+     113      458768 :                 v_64(q[i]) = q0;
+     114      458768 :                 v_64(q[i + 8]) = q1;
+     115      458768 :                 v_64(r[i]) = r0;
+     116      458768 :                 v_64(r[i + 8]) = r1;
+     117             :         }
+     118          29 : }
+     119             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/memory.c.func-sort-c.html b/cov/raid/memory.c.func-sort-c.html new file mode 100644 index 00000000..f440b020 --- /dev/null +++ b/cov/raid/memory.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - raid/memory.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - memory.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4949100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_mtest_vector726
raid_malloc_align274
raid_malloc_vector199
raid_mrand_vector5
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/memory.c.func.html b/cov/raid/memory.c.func.html new file mode 100644 index 00000000..4e25a57a --- /dev/null +++ b/cov/raid/memory.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - raid/memory.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - memory.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4949100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_malloc_align274
raid_malloc_vector199
raid_mrand_vector5
raid_mtest_vector726
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/memory.c.gcov.html b/cov/raid/memory.c.gcov.html new file mode 100644 index 00000000..6ce5e66e --- /dev/null +++ b/cov/raid/memory.c.gcov.html @@ -0,0 +1,220 @@ + + + + + + + LCOV - lcov.info - raid/memory.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - memory.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:4949100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "memory.h"
+      17             : 
+      18         274 : void *raid_malloc_align(size_t size, void **freeptr)
+      19             : {
+      20             :         unsigned char *ptr;
+      21             :         uintptr_t offset;
+      22             : 
+      23         274 :         ptr = malloc(size + RAID_MALLOC_ALIGN);
+      24         274 :         if (!ptr) {
+      25             :                 /* LCOV_EXCL_START */
+      26             :                 return 0;
+      27             :                 /* LCOV_EXCL_STOP */
+      28             :         }
+      29             : 
+      30         274 :         *freeptr = ptr;
+      31             : 
+      32         274 :         offset = ((uintptr_t)ptr) % RAID_MALLOC_ALIGN;
+      33             : 
+      34         274 :         if (offset != 0)
+      35         268 :                 ptr += RAID_MALLOC_ALIGN - offset;
+      36             : 
+      37         274 :         return ptr;
+      38             : }
+      39             : 
+      40         199 : void **raid_malloc_vector(int nd, int n, size_t size, void **freeptr)
+      41             : {
+      42             :         void **v;
+      43             :         unsigned char *va;
+      44             :         int i;
+      45             : 
+      46         199 :         BUG_ON(n <= 0 || nd < 0);
+      47             : 
+      48         199 :         v = malloc(n * sizeof(void *));
+      49         199 :         if (!v) {
+      50             :                 /* LCOV_EXCL_START */
+      51             :                 return 0;
+      52             :                 /* LCOV_EXCL_STOP */
+      53             :         }
+      54             : 
+      55         199 :         va = raid_malloc_align(n * (size + RAID_MALLOC_DISPLACEMENT), freeptr);
+      56         199 :         if (!va) {
+      57             :                 /* LCOV_EXCL_START */
+      58             :                 free(v);
+      59             :                 return 0;
+      60             :                 /* LCOV_EXCL_STOP */
+      61             :         }
+      62             : 
+      63        3513 :         for (i = 0; i < n; ++i) {
+      64        3314 :                 v[i] = va;
+      65        3314 :                 va += size + RAID_MALLOC_DISPLACEMENT;
+      66             :         }
+      67             : 
+      68             :         /* reverse order of the data blocks */
+      69             :         /* because they are usually accessed from the last one */
+      70         834 :         for (i = 0; i < nd / 2; ++i) {
+      71         635 :                 void *ptr = v[i];
+      72             : 
+      73         635 :                 v[i] = v[nd - 1 - i];
+      74         635 :                 v[nd - 1 - i] = ptr;
+      75             :         }
+      76             : 
+      77         199 :         return v;
+      78             : }
+      79             : 
+      80           5 : void raid_mrand_vector(unsigned seed, int n, size_t size, void **vv)
+      81             : {
+      82           5 :         unsigned char **v = (unsigned char **)vv;
+      83             :         int i;
+      84             :         size_t j;
+      85             : 
+      86         124 :         for (i = 0; i < n; ++i)
+      87       30583 :                 for (j = 0; j < size; ++j) {
+      88             :                         /* basic C99/C11 linear congruential generator */
+      89       30464 :                         seed = seed * 1103515245U + 12345U;
+      90             : 
+      91       30464 :                         v[i][j] = seed >> 16;
+      92             :                 }
+      93           5 : }
+      94             : 
+      95         726 : int raid_mtest_vector(int n, size_t size, void **vv)
+      96             : {
+      97         726 :         unsigned char **v = (unsigned char **)vv;
+      98             :         int i;
+      99             :         size_t j;
+     100             :         unsigned k;
+     101             :         unsigned char d;
+     102             :         unsigned char p;
+     103             : 
+     104             :         /* fill with 0 */
+     105         726 :         d = 0;
+     106        1544 :         for (i = 0; i < n; ++i)
+     107    37971706 :                 for (j = 0; j < size; ++j)
+     108    37970888 :                         v[i][j] = d;
+     109             : 
+     110             :         /* test with all the byte patterns */
+     111      185856 :         for (k = 1; k < 256; ++k) {
+     112      185130 :                 p = d;
+     113      185130 :                 d = k;
+     114             : 
+     115             :                 /* forward fill */
+     116      393720 :                 for (i = 0; i < n; ++i) {
+     117  9682785030 :                         for (j = 0; j < size; ++j) {
+     118  9682576440 :                                 if (v[i][j] != p) {
+     119             :                                         /* LCOV_EXCL_START */
+     120             :                                         return -1;
+     121             :                                         /* LCOV_EXCL_STOP */
+     122             :                                 }
+     123  9682576440 :                                 v[i][j] = d;
+     124             :                         }
+     125             :                 }
+     126             : 
+     127      185130 :                 p = d;
+     128      185130 :                 d = ~p;
+     129             :                 /* backward fill with complement */
+     130      393720 :                 for (i = 0; i < n; ++i) {
+     131  9682785030 :                         for (j = size; j > 0; --j) {
+     132  9682576440 :                                 if (v[i][j - 1] != p) {
+     133             :                                         /* LCOV_EXCL_START */
+     134             :                                         return -1;
+     135             :                                         /* LCOV_EXCL_STOP */
+     136             :                                 }
+     137  9682576440 :                                 v[i][j - 1] = d;
+     138             :                         }
+     139             :                 }
+     140             :         }
+     141             : 
+     142         726 :         return 0;
+     143             : }
+     144             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/module.c.func-sort-c.html b/cov/raid/module.c.func-sort-c.html new file mode 100644 index 00000000..e39af29d --- /dev/null +++ b/cov/raid/module.c.func-sort-c.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - raid/module.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - module.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:159159100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_init240
raid_test_rec18
raid_test_data18
raid_test_scan7
raid_gen_ref6
raid_test_par6
raid_selftest1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/module.c.func.html b/cov/raid/module.c.func.html new file mode 100644 index 00000000..0e247509 --- /dev/null +++ b/cov/raid/module.c.func.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - raid/module.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - module.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:159159100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen_ref6
raid_init240
raid_selftest1
raid_test_data18
raid_test_par6
raid_test_rec18
raid_test_scan7
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/module.c.gcov.html b/cov/raid/module.c.gcov.html new file mode 100644 index 00000000..fa59cc8b --- /dev/null +++ b/cov/raid/module.c.gcov.html @@ -0,0 +1,542 @@ + + + + + + + LCOV - lcov.info - raid/module.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - module.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:159159100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "memory.h"
+      17             : #include "cpu.h"
+      18             : 
+      19             : /*
+      20             :  * Initializes and selects the best algorithm.
+      21             :  */
+      22         240 : void raid_init(void)
+      23             : {
+      24         240 :         raid_gen3_ptr = raid_gen3_int8;
+      25         240 :         raid_gen_ptr[3] = raid_gen4_int8;
+      26         240 :         raid_gen_ptr[4] = raid_gen5_int8;
+      27         240 :         raid_gen_ptr[5] = raid_gen6_int8;
+      28             : 
+      29             :         if (sizeof(void *) == 4) {
+      30         240 :                 raid_gen_ptr[0] = raid_gen1_int32;
+      31         240 :                 raid_gen_ptr[1] = raid_gen2_int32;
+      32         240 :                 raid_genz_ptr = raid_genz_int32;
+      33             :         } else {
+      34             :                 raid_gen_ptr[0] = raid_gen1_int64;
+      35             :                 raid_gen_ptr[1] = raid_gen2_int64;
+      36             :                 raid_genz_ptr = raid_genz_int64;
+      37             :         }
+      38             : 
+      39         240 :         raid_rec_ptr[0] = raid_rec1_int8;
+      40         240 :         raid_rec_ptr[1] = raid_rec2_int8;
+      41         240 :         raid_rec_ptr[2] = raid_recX_int8;
+      42         240 :         raid_rec_ptr[3] = raid_recX_int8;
+      43         240 :         raid_rec_ptr[4] = raid_recX_int8;
+      44         240 :         raid_rec_ptr[5] = raid_recX_int8;
+      45             : 
+      46             : #ifdef CONFIG_X86
+      47             : #ifdef CONFIG_SSE2
+      48         240 :         if (raid_cpu_has_sse2()) {
+      49         240 :                 raid_gen_ptr[0] = raid_gen1_sse2;
+      50             : #ifdef CONFIG_X86_64
+      51             :                 if (raid_cpu_has_slowextendedreg()) {
+      52             :                         raid_gen_ptr[1] = raid_gen2_sse2;
+      53             :                         raid_genz_ptr = raid_genz_sse2;
+      54             :                 } else {
+      55             :                         raid_gen_ptr[1] = raid_gen2_sse2ext;
+      56             :                         raid_genz_ptr = raid_genz_sse2ext;
+      57             :                 }
+      58             : #else
+      59         240 :                 raid_gen_ptr[1] = raid_gen2_sse2;
+      60         240 :                 raid_genz_ptr = raid_genz_sse2;
+      61             : #endif
+      62             :         }
+      63             : #endif
+      64             : 
+      65             : #ifdef CONFIG_SSSE3
+      66         240 :         if (raid_cpu_has_ssse3()) {
+      67             : #ifdef CONFIG_X86_64
+      68             :                 raid_gen3_ptr = raid_gen3_ssse3ext;
+      69             :                 raid_gen_ptr[3] = raid_gen4_ssse3ext;
+      70             :                 raid_gen_ptr[4] = raid_gen5_ssse3ext;
+      71             :                 raid_gen_ptr[5] = raid_gen6_ssse3ext;
+      72             : #else
+      73         239 :                 raid_gen3_ptr = raid_gen3_ssse3;
+      74         239 :                 raid_gen_ptr[3] = raid_gen4_ssse3;
+      75         239 :                 raid_gen_ptr[4] = raid_gen5_ssse3;
+      76         239 :                 raid_gen_ptr[5] = raid_gen6_ssse3;
+      77             : #endif
+      78         239 :                 raid_rec_ptr[0] = raid_rec1_ssse3;
+      79         239 :                 raid_rec_ptr[1] = raid_rec2_ssse3;
+      80         239 :                 raid_rec_ptr[2] = raid_recX_ssse3;
+      81         239 :                 raid_rec_ptr[3] = raid_recX_ssse3;
+      82         239 :                 raid_rec_ptr[4] = raid_recX_ssse3;
+      83         239 :                 raid_rec_ptr[5] = raid_recX_ssse3;
+      84             :         }
+      85             : #endif
+      86             : 
+      87             : #ifdef CONFIG_AVX2
+      88         240 :         if (raid_cpu_has_avx2()) {
+      89           2 :                 raid_gen_ptr[0] = raid_gen1_avx2;
+      90           2 :                 raid_gen_ptr[1] = raid_gen2_avx2;
+      91             : #ifdef CONFIG_X86_64
+      92             :                 raid_gen3_ptr = raid_gen3_avx2ext;
+      93             :                 raid_genz_ptr = raid_genz_avx2ext;
+      94             :                 raid_gen_ptr[3] = raid_gen4_avx2ext;
+      95             :                 raid_gen_ptr[4] = raid_gen5_avx2ext;
+      96             :                 raid_gen_ptr[5] = raid_gen6_avx2ext;
+      97             : #endif
+      98           2 :                 raid_rec_ptr[0] = raid_rec1_avx2;
+      99           2 :                 raid_rec_ptr[1] = raid_rec2_avx2;
+     100           2 :                 raid_rec_ptr[2] = raid_recX_avx2;
+     101           2 :                 raid_rec_ptr[3] = raid_recX_avx2;
+     102           2 :                 raid_rec_ptr[4] = raid_recX_avx2;
+     103           2 :                 raid_rec_ptr[5] = raid_recX_avx2;
+     104             :         }
+     105             : #endif
+     106             : #endif /* CONFIG_X86 */
+     107             : 
+     108             :         /* set the default mode */
+     109         240 :         raid_mode(RAID_MODE_CAUCHY);
+     110         240 : }
+     111             : 
+     112             : /*
+     113             :  * Reference parity computation.
+     114             :  */
+     115           6 : void raid_gen_ref(int nd, int np, size_t size, void **vv)
+     116             : {
+     117           6 :         uint8_t **v = (uint8_t **)vv;
+     118             :         size_t i;
+     119             : 
+     120        5382 :         for (i = 0; i < size; ++i) {
+     121             :                 uint8_t p[RAID_PARITY_MAX];
+     122             :                 int j, d;
+     123             : 
+     124       36096 :                 for (j = 0; j < np; ++j)
+     125       30720 :                         p[j] = 0;
+     126             : 
+     127       93696 :                 for (d = 0; d < nd; ++d) {
+     128       88320 :                         uint8_t b = v[d][i];
+     129             : 
+     130      584448 :                         for (j = 0; j < np; ++j)
+     131      496128 :                                 p[j] ^= gfmul[b][gfgen[j][d]];
+     132             :                 }
+     133             : 
+     134       36096 :                 for (j = 0; j < np; ++j)
+     135       30720 :                         v[nd + j][i] = p[j];
+     136             :         }
+     137           6 : }
+     138             : 
+     139             : /*
+     140             :  * Size of the blocks to test.
+     141             :  */
+     142             : #define TEST_SIZE 4096
+     143             : 
+     144             : /*
+     145             :  * Number of data blocks to test.
+     146             :  */
+     147             : #define TEST_COUNT (65536 / TEST_SIZE)
+     148             : 
+     149             : /*
+     150             :  * Parity generation test.
+     151             :  */
+     152           6 : static int raid_test_par(int nd, int np, size_t size, void **v, void **ref)
+     153             : {
+     154             :         int i;
+     155             :         void *t[TEST_COUNT + RAID_PARITY_MAX];
+     156             : 
+     157             :         /* setup data */
+     158         102 :         for (i = 0; i < nd; ++i)
+     159          96 :                 t[i] = ref[i];
+     160             : 
+     161             :         /* setup parity */
+     162          27 :         for (i = 0; i < np; ++i)
+     163          21 :                 t[nd + i] = v[nd + i];
+     164             : 
+     165           6 :         raid_gen(nd, np, size, t);
+     166             : 
+     167             :         /* compare parity */
+     168          27 :         for (i = 0; i < np; ++i) {
+     169          21 :                 if (memcmp(t[nd + i], ref[nd + i], size) != 0) {
+     170             :                         /* LCOV_EXCL_START */
+     171             :                         return -1;
+     172             :                         /* LCOV_EXCL_STOP */
+     173             :                 }
+     174             :         }
+     175             : 
+     176           6 :         return 0;
+     177             : }
+     178             : 
+     179             : /*
+     180             :  * Recovering test.
+     181             :  */
+     182          18 : static int raid_test_rec(int nr, int *ir, int nd, int np, size_t size, void **v, void **ref)
+     183             : {
+     184             :         int i, j;
+     185             :         void *t[TEST_COUNT + RAID_PARITY_MAX];
+     186             : 
+     187             :         /* setup data and parity vector */
+     188         369 :         for (i = 0, j = 0; i < nd + np; ++i) {
+     189         351 :                 if (j < nr && ir[j] == i) {
+     190             :                         /* this block has to be recovered */
+     191          63 :                         t[i] = v[i];
+     192          63 :                         ++j;
+     193             :                 } else {
+     194             :                         /* this block is used for recovering */
+     195         288 :                         t[i] = ref[i];
+     196             :                 }
+     197             :         }
+     198             : 
+     199          18 :         raid_rec(nr, ir, nd, np, size, t);
+     200             : 
+     201             :         /* compare all data and parity */
+     202         369 :         for (i = 0; i < nd + np; ++i) {
+     203         351 :                 if (t[i] != ref[i]
+     204          63 :                         && memcmp(t[i], ref[i], size) != 0) {
+     205             :                         /* LCOV_EXCL_START */
+     206             :                         return -1;
+     207             :                         /* LCOV_EXCL_STOP */
+     208             :                 }
+     209             :         }
+     210             : 
+     211          18 :         return 0;
+     212             : }
+     213             : 
+     214             : /*
+     215             :  * Recovering test for data.
+     216             :  */
+     217          18 : static int raid_test_data(int nr, int *id, int *ip, int nd, int np, size_t size, void **v, void **ref)
+     218             : {
+     219             :         int i, j;
+     220             :         void *t[TEST_COUNT + RAID_PARITY_MAX];
+     221             : 
+     222             :         /* setup data vector */
+     223         306 :         for (i = 0, j = 0; i < nd; ++i) {
+     224         288 :                 if (j < nr && id[j] == i) {
+     225             :                         /* this block has to be recovered */
+     226          39 :                         t[i] = v[i];
+     227          39 :                         ++j;
+     228             :                 } else {
+     229             :                         /* this block is left unchanged */
+     230         249 :                         t[i] = ref[i];
+     231             :                 }
+     232             :         }
+     233             : 
+     234             :         /* setup parity vector */
+     235          81 :         for (i = 0, j = 0; i < np; ++i) {
+     236          63 :                 if (j < nr && ip[j] == i) {
+     237             :                         /* this block is used for recovering */
+     238          39 :                         t[nd + i] = ref[nd + i];
+     239          39 :                         ++j;
+     240             :                 } else {
+     241             :                         /* this block should not be read or written */
+     242          24 :                         t[nd + i] = 0;
+     243             :                 }
+     244             :         }
+     245             : 
+     246          18 :         raid_data(nr, id, ip, nd, size, t);
+     247             : 
+     248             :         /* compare all data and parity */
+     249         306 :         for (i = 0; i < nd; ++i) {
+     250         288 :                 if (t[i] != ref[i]
+     251          39 :                         && t[i] != 0
+     252          39 :                         && memcmp(t[i], ref[i], size) != 0) {
+     253             :                         /* LCOV_EXCL_START */
+     254             :                         return -1;
+     255             :                         /* LCOV_EXCL_STOP */
+     256             :                 }
+     257             :         }
+     258             : 
+     259          18 :         return 0;
+     260             : }
+     261             : 
+     262             : /*
+     263             :  * Scan test.
+     264             :  */
+     265           7 : static int raid_test_scan(int nr, int *ir, int nd, int np, size_t size, void **v, void **ref)
+     266             : {
+     267             :         int i, j, ret;
+     268             :         void *t[TEST_COUNT + RAID_PARITY_MAX];
+     269             :         int is[RAID_PARITY_MAX];
+     270             : 
+     271             :         /* setup data and parity vector */
+     272         140 :         for (i = 0, j = 0; i < nd + np; ++i) {
+     273         133 :                 if (j < nr && ir[j] == i) {
+     274             :                         /* this block is bad */
+     275          15 :                         t[i] = v[i];
+     276          15 :                         ++j;
+     277             :                 } else {
+     278             :                         /* this block is used for recovering */
+     279         118 :                         t[i] = ref[i];
+     280             :                 }
+     281             :         }
+     282             : 
+     283           7 :         ret = raid_scan(is, nd, np, size, t);
+     284             : 
+     285             :         /* compare identified bad blocks */
+     286           7 :         if (ret != nr)
+     287           1 :                 return -1;
+     288          21 :         for (i = 0; i < nr; ++i) {
+     289          15 :                 if (ir[i] != is[i]) {
+     290             :                         /* LCOV_EXCL_START */
+     291             :                         return -1;
+     292             :                         /* LCOV_EXCL_STOP */
+     293             :                 }
+     294             :         }
+     295             : 
+     296           6 :         return 0;
+     297             : }
+     298             : 
+     299             : /*
+     300             :  * Basic functionality self test.
+     301             :  */
+     302           1 : int raid_selftest(void)
+     303             : {
+     304           1 :         const int nd = TEST_COUNT;
+     305           1 :         const size_t size = TEST_SIZE;
+     306           1 :         const int nv = nd + RAID_PARITY_MAX * 2 + 1;
+     307             :         void *v_alloc;
+     308             :         void **v;
+     309           1 :         void *ref[nd + RAID_PARITY_MAX];
+     310             :         int ir[RAID_PARITY_MAX];
+     311             :         int ip[RAID_PARITY_MAX];
+     312             :         int i, np;
+     313           1 :         int ret = 0;
+     314             : 
+     315             :         /* ensure to have enough space for data */
+     316           1 :         BUG_ON(nd * size > 65536);
+     317             : 
+     318           1 :         v = raid_malloc_vector(nd, nv, size, &v_alloc);
+     319           1 :         if (!v) {
+     320             :                 /* LCOV_EXCL_START */
+     321             :                 return -1;
+     322             :                 /* LCOV_EXCL_STOP */
+     323             :         }
+     324             : 
+     325           1 :         memset(v[nv - 1], 0, size);
+     326           1 :         raid_zero(v[nv - 1]);
+     327             : 
+     328             :         /* use the multiplication table as data */
+     329          17 :         for (i = 0; i < nd; ++i)
+     330          16 :                 ref[i] = ((uint8_t *)gfmul) + size * i;
+     331             : 
+     332             :         /* setup reference parity */
+     333           7 :         for (i = 0; i < RAID_PARITY_MAX; ++i)
+     334           6 :                 ref[nd + i] = v[nd + RAID_PARITY_MAX + i];
+     335             : 
+     336             :         /* compute reference parity */
+     337           1 :         raid_gen_ref(nd, RAID_PARITY_MAX, size, ref);
+     338             : 
+     339             :         /* test for each parity level */
+     340           7 :         for (np = 1; np <= RAID_PARITY_MAX; ++np) {
+     341             :                 /* test parity generation */
+     342           6 :                 ret = raid_test_par(nd, np, size, v, ref);
+     343           6 :                 if (ret != 0) {
+     344             :                         /* LCOV_EXCL_START */
+     345             :                         goto bail;
+     346             :                         /* LCOV_EXCL_STOP */
+     347             :                 }
+     348             : 
+     349             :                 /* test recovering with broken ending data disks */
+     350          27 :                 for (i = 0; i < np; ++i) {
+     351             :                         /* bad data */
+     352          21 :                         ir[i] = nd - np + i;
+     353             : 
+     354             :                         /* good parity */
+     355          21 :                         ip[i] = i;
+     356             :                 }
+     357             : 
+     358           6 :                 ret = raid_test_rec(np, ir, nd, np, size, v, ref);
+     359           6 :                 if (ret != 0) {
+     360             :                         /* LCOV_EXCL_START */
+     361             :                         goto bail;
+     362             :                         /* LCOV_EXCL_STOP */
+     363             :                 }
+     364             : 
+     365           6 :                 ret = raid_test_data(np, ir, ip, nd, np, size, v, ref);
+     366           6 :                 if (ret != 0) {
+     367             :                         /* LCOV_EXCL_START */
+     368             :                         goto bail;
+     369             :                         /* LCOV_EXCL_STOP */
+     370             :                 }
+     371             : 
+     372             :                 /* test recovering with broken leading data and broken leading parity */
+     373          15 :                 for (i = 0; i < np / 2; ++i) {
+     374             :                         /* bad data */
+     375           9 :                         ir[i] = i;
+     376             : 
+     377             :                         /* good parity */
+     378           9 :                         ip[i] = (np + 1) / 2 + i;
+     379             :                 }
+     380             : 
+     381             :                 /* bad parity */
+     382          18 :                 for (i = 0; i < (np + 1) / 2; ++i)
+     383          12 :                         ir[np / 2 + i] = nd + i;
+     384             : 
+     385           6 :                 ret = raid_test_rec(np, ir, nd, np, size, v, ref);
+     386           6 :                 if (ret != 0) {
+     387             :                         /* LCOV_EXCL_START */
+     388             :                         goto bail;
+     389             :                         /* LCOV_EXCL_STOP */
+     390             :                 }
+     391             : 
+     392           6 :                 ret = raid_test_data(np / 2, ir, ip, nd, np, size, v, ref);
+     393           6 :                 if (ret != 0) {
+     394             :                         /* LCOV_EXCL_START */
+     395             :                         goto bail;
+     396             :                         /* LCOV_EXCL_STOP */
+     397             :                 }
+     398             : 
+     399             :                 /* test recovering with broken leading data and broken ending parity */
+     400          15 :                 for (i = 0; i < np / 2; ++i) {
+     401             :                         /* bad data */
+     402           9 :                         ir[i] = i;
+     403             : 
+     404             :                         /* good parity */
+     405           9 :                         ip[i] = i;
+     406             :                 }
+     407             : 
+     408             :                 /* bad parity */
+     409          18 :                 for (i = 0; i < (np + 1) / 2; ++i)
+     410          12 :                         ir[np / 2 + i] = nd + np - (np + 1) / 2 + i;
+     411             : 
+     412           6 :                 ret = raid_test_rec(np, ir, nd, np, size, v, ref);
+     413           6 :                 if (ret != 0) {
+     414             :                         /* LCOV_EXCL_START */
+     415             :                         goto bail;
+     416             :                         /* LCOV_EXCL_STOP */
+     417             :                 }
+     418             : 
+     419           6 :                 ret = raid_test_data(np / 2, ir, ip, nd, np, size, v, ref);
+     420           6 :                 if (ret != 0) {
+     421             :                         /* LCOV_EXCL_START */
+     422             :                         goto bail;
+     423             :                         /* LCOV_EXCL_STOP */
+     424             :                 }
+     425             : 
+     426             :                 /* scan test with broken data and parity */
+     427          15 :                 for (i = 0; i < np / 2; ++i) {
+     428             :                         /* bad data */
+     429           9 :                         ir[i] = i;
+     430             :                 }
+     431          12 :                 for (i = 0; i < (np - 1) / 2; ++i) {
+     432             :                         /* bad parity */
+     433           6 :                         ir[np / 2 + i] = nd + i;
+     434             :                 }
+     435          21 :                 for (i = 0; i < np - 1; ++i) {
+     436             :                         /* make blocks bad */
+     437             :                         /* we cannot fill them with 0, because the original */
+     438             :                         /* data may be already filled with 0 */
+     439          15 :                         memset(v[ir[i]], 0x55, size);
+     440             :                 }
+     441             : 
+     442           6 :                 ret = raid_test_scan(np - 1, ir, nd, np, size, v, ref);
+     443           6 :                 if (ret != 0) {
+     444             :                         /* LCOV_EXCL_START */
+     445             :                         goto bail;
+     446             :                         /* LCOV_EXCL_STOP */
+     447             :                 }
+     448             :         }
+     449             : 
+     450             :         /* scan test with no parity */
+     451           1 :         ret = raid_test_scan(0, 0, nd, 0, size, v, ref);
+     452           1 :         if (ret != -1) {
+     453             :                 /* LCOV_EXCL_START */
+     454             :                 goto bail;
+     455             :                 /* LCOV_EXCL_STOP */
+     456             :         }
+     457             : 
+     458           1 :         ret = 0;
+     459             : 
+     460             : bail:
+     461           1 :         free(v);
+     462           1 :         free(v_alloc);
+     463             : 
+     464           1 :         return ret;
+     465             : }
+     466             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/raid.c.func-sort-c.html b/cov/raid/raid.c.func-sort-c.html new file mode 100644 index 00000000..c34dcfa2 --- /dev/null +++ b/cov/raid/raid.c.func-sort-c.html @@ -0,0 +1,108 @@ + + + + + + + LCOV - lcov.info - raid/raid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - raid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:123123100.0 %
Date:2015-05-12Functions:99100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen1196804
raid_data213294
raid_invert172492
raid_delta_gen171154
raid_rec1of1100552
raid_rec901
raid_mode480
raid_zero187
raid_rec2of2_int8132
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/raid.c.func.html b/cov/raid/raid.c.func.html new file mode 100644 index 00000000..77b7d4a7 --- /dev/null +++ b/cov/raid/raid.c.func.html @@ -0,0 +1,108 @@ + + + + + + + LCOV - lcov.info - raid/raid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - raid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:123123100.0 %
Date:2015-05-12Functions:99100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_data213294
raid_delta_gen171154
raid_gen1196804
raid_invert172492
raid_mode480
raid_rec901
raid_rec1of1100552
raid_rec2of2_int8132
raid_zero187
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/raid.c.gcov.html b/cov/raid/raid.c.gcov.html new file mode 100644 index 00000000..c6c87204 --- /dev/null +++ b/cov/raid/raid.c.gcov.html @@ -0,0 +1,662 @@ + + + + + + + LCOV - lcov.info - raid/raid.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - raid.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:123123100.0 %
Date:2015-05-12Functions:99100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "gf.h"
+      17             : 
+      18             : /*
+      19             :  * This is a RAID implementation working in the Galois Field GF(2^8) with
+      20             :  * the primitive polynomial x^8 + x^4 + x^3 + x^2 + 1 (285 decimal), and
+      21             :  * supporting up to six parity levels.
+      22             :  *
+      23             :  * For RAID5 and RAID6 it works as as described in the H. Peter Anvin's
+      24             :  * paper "The mathematics of RAID-6" [1]. Please refer to this paper for a
+      25             :  * complete explanation.
+      26             :  *
+      27             :  * To support triple parity, it was first evaluated and then dropped, an
+      28             :  * extension of the same approach, with additional parity coefficients set
+      29             :  * as powers of 2^-1, with equations:
+      30             :  *
+      31             :  * P = sum(Di)
+      32             :  * Q = sum(2^i * Di)
+      33             :  * R = sum(2^-i * Di) with 0<=i<N
+      34             :  *
+      35             :  * This approach works well for triple parity and it's very efficient,
+      36             :  * because we can implement very fast parallel multiplications and
+      37             :  * divisions by 2 in GF(2^8).
+      38             :  *
+      39             :  * It's also similar at the approach used by ZFS RAIDZ3, with the
+      40             :  * difference that ZFS uses powers of 4 instead of 2^-1.
+      41             :  *
+      42             :  * Unfortunately it doesn't work beyond triple parity, because whatever
+      43             :  * value we choose to generate the power coefficients to compute other
+      44             :  * parities, the resulting equations are not solvable for some
+      45             :  * combinations of missing disks.
+      46             :  *
+      47             :  * This is expected, because the Vandermonde matrix used to compute the
+      48             :  * parity has no guarantee to have all submatrices not singular
+      49             :  * [2, Chap 11, Problem 7] and this is a requirement to have
+      50             :  * a MDS (Maximum Distance Separable) code [2, Chap 11, Theorem 8].
+      51             :  *
+      52             :  * To overcome this limitation, we use a Cauchy matrix [3][4] to compute
+      53             :  * the parity. A Cauchy matrix has the property to have all the square
+      54             :  * submatrices not singular, resulting in always solvable equations,
+      55             :  * for any combination of missing disks.
+      56             :  *
+      57             :  * The problem of this approach is that it requires the use of
+      58             :  * generic multiplications, and not only by 2 or 2^-1, potentially
+      59             :  * affecting badly the performance.
+      60             :  *
+      61             :  * Hopefully there is a method to implement parallel multiplications
+      62             :  * using SSSE3 or AVX2 instructions [1][5]. Method competitive with the
+      63             :  * computation of triple parity using power coefficients.
+      64             :  *
+      65             :  * Another important property of the Cauchy matrix is that we can setup
+      66             :  * the first two rows with coeffients equal at the RAID5 and RAID6 approach
+      67             :  * decribed, resulting in a compatible extension, and requiring SSSE3
+      68             :  * or AVX2 instructions only if triple parity or beyond is used.
+      69             :  *
+      70             :  * The matrix is also adjusted, multipling each row by a constant factor
+      71             :  * to make the first column of all 1, to optimize the computation for
+      72             :  * the first disk.
+      73             :  *
+      74             :  * This results in the matrix A[row,col] defined as:
+      75             :  *
+      76             :  * 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01...
+      77             :  * 01 02 04 08 10 20 40 80 1d 3a 74 e8 cd 87 13 26 4c 98 2d 5a b4 75...
+      78             :  * 01 f5 d2 c4 9a 71 f1 7f fc 87 c1 c6 19 2f 40 55 3d ba 53 04 9c 61...
+      79             :  * 01 bb a6 d7 c7 07 ce 82 4a 2f a5 9b b6 60 f1 ad e7 f4 06 d2 df 2e...
+      80             :  * 01 97 7f 9c 7c 18 bd a2 58 1a da 74 70 a3 e5 47 29 07 f5 80 23 e9...
+      81             :  * 01 2b 3f cf 73 2c d6 ed cb 74 15 78 8a c1 17 c9 89 68 21 ab 76 3b...
+      82             :  *
+      83             :  * This matrix supports 6 level of parity, one for each row, for up to 251
+      84             :  * data disks, one for each column, with all the 377,342,351,231 square
+      85             :  * submatrices not singular, verified also with brute-force.
+      86             :  *
+      87             :  * This matrix can be extended to support any number of parities, just
+      88             :  * adding additional rows, and removing one column for each new row.
+      89             :  * (see mktables.c for more details in how the matrix is generated)
+      90             :  *
+      91             :  * In details, parity is computed as:
+      92             :  *
+      93             :  * P = sum(Di)
+      94             :  * Q = sum(2^i *  Di)
+      95             :  * R = sum(A[2,i] * Di)
+      96             :  * S = sum(A[3,i] * Di)
+      97             :  * T = sum(A[4,i] * Di)
+      98             :  * U = sum(A[5,i] * Di) with 0<=i<N
+      99             :  *
+     100             :  * To recover from a failure of six disks at indexes x,y,z,h,v,w,
+     101             :  * with 0<=x<y<z<h<v<w<N, we compute the parity of the available N-6
+     102             :  * disks as:
+     103             :  *
+     104             :  * Pa = sum(Di)
+     105             :  * Qa = sum(2^i * Di)
+     106             :  * Ra = sum(A[2,i] * Di)
+     107             :  * Sa = sum(A[3,i] * Di)
+     108             :  * Ta = sum(A[4,i] * Di)
+     109             :  * Ua = sum(A[5,i] * Di) with 0<=i<N,i!=x,i!=y,i!=z,i!=h,i!=v,i!=w.
+     110             :  *
+     111             :  * And if we define:
+     112             :  *
+     113             :  * Pd = Pa + P
+     114             :  * Qd = Qa + Q
+     115             :  * Rd = Ra + R
+     116             :  * Sd = Sa + S
+     117             :  * Td = Ta + T
+     118             :  * Ud = Ua + U
+     119             :  *
+     120             :  * we can sum these two sets of equations, obtaining:
+     121             :  *
+     122             :  * Pd =          Dx +          Dy +          Dz +          Dh +          Dv +          Dw
+     123             :  * Qd =    2^x * Dx +    2^y * Dy +    2^z * Dz +    2^h * Dh +    2^v * Dv +    2^w * Dw
+     124             :  * Rd = A[2,x] * Dx + A[2,y] * Dy + A[2,z] * Dz + A[2,h] * Dh + A[2,v] * Dv + A[2,w] * Dw
+     125             :  * Sd = A[3,x] * Dx + A[3,y] * Dy + A[3,z] * Dz + A[3,h] * Dh + A[3,v] * Dv + A[3,w] * Dw
+     126             :  * Td = A[4,x] * Dx + A[4,y] * Dy + A[4,z] * Dz + A[4,h] * Dh + A[4,v] * Dv + A[4,w] * Dw
+     127             :  * Ud = A[5,x] * Dx + A[5,y] * Dy + A[5,z] * Dz + A[5,h] * Dh + A[5,v] * Dv + A[5,w] * Dw
+     128             :  *
+     129             :  * A linear system always solvable because the coefficients matrix is
+     130             :  * always not singular due the properties of the matrix A[].
+     131             :  *
+     132             :  * Resulting speed in x64, with 8 data disks, using a stripe of 256 KiB,
+     133             :  * for a Core i5-4670K Haswell Quad-Core 3.4GHz is:
+     134             :  *
+     135             :  *             int8   int32   int64    sse2   ssse3    avx2
+     136             :  *   gen1             13339   25438   45438           50588
+     137             :  *   gen2              4115    6514   21840           32201
+     138             :  *   gen3       814                           10154   18613
+     139             :  *   gen4       620                            7569   14229
+     140             :  *   gen5       496                            5149   10051
+     141             :  *   gen6       413                            4239    8190
+     142             :  *
+     143             :  * Values are in MiB/s of data processed by a single thread, not counting
+     144             :  * generated parity.
+     145             :  *
+     146             :  * You can replicate these results in your machine using the
+     147             :  * "raid/test/speedtest.c" program.
+     148             :  *
+     149             :  * For comparison, the triple parity computation using the power
+     150             :  * coeffients "1,2,2^-1" is only a little faster than the one based on
+     151             :  * the Cauchy matrix if SSSE3 or AVX2 is present.
+     152             :  *
+     153             :  *             int8   int32   int64    sse2   ssse3    avx2
+     154             :  *   genz              2337    2874   10920           18944
+     155             :  *
+     156             :  * In conclusion, the use of power coefficients, and specifically powers
+     157             :  * of 1,2,2^-1, is the best option to implement triple parity in CPUs
+     158             :  * without SSSE3 and AVX2.
+     159             :  * But if a modern CPU with SSSE3 or AVX2 is available, the Cauchy
+     160             :  * matrix is the best option because it provides a fast and general
+     161             :  * approach working for any number of parities.
+     162             :  *
+     163             :  * References:
+     164             :  * [1] Anvin, "The mathematics of RAID-6", 2004
+     165             :  * [2] MacWilliams, Sloane, "The Theory of Error-Correcting Codes", 1977
+     166             :  * [3] Blomer, "An XOR-Based Erasure-Resilient Coding Scheme", 1995
+     167             :  * [4] Roth, "Introduction to Coding Theory", 2006
+     168             :  * [5] Plank, "Screaming Fast Galois Field Arithmetic Using Intel SIMD Instructions", 2013
+     169             :  */
+     170             : 
+     171             : /**
+     172             :  * Generator matrix currently used.
+     173             :  */
+     174             : const uint8_t (*raid_gfgen)[256];
+     175             : 
+     176         480 : void raid_mode(int mode)
+     177             : {
+     178         480 :         if (mode == RAID_MODE_VANDERMONDE) {
+     179           2 :                 raid_gen_ptr[2] = raid_genz_ptr;
+     180           2 :                 raid_gfgen = gfvandermonde;
+     181             :         } else {
+     182         478 :                 raid_gen_ptr[2] = raid_gen3_ptr;
+     183         478 :                 raid_gfgen = gfcauchy;
+     184             :         }
+     185         480 : }
+     186             : 
+     187             : /**
+     188             :  * Buffer filled with 0 used in recovering.
+     189             :  */
+     190             : static void *raid_zero_block;
+     191             : 
+     192         187 : void raid_zero(void *zero)
+     193             : {
+     194         187 :         raid_zero_block = zero;
+     195         187 : }
+     196             : 
+     197             : /*
+     198             :  * Forwarders for parity computation.
+     199             :  *
+     200             :  * These functions compute the parity blocks from the provided data.
+     201             :  *
+     202             :  * The number of parities to compute is implicit in the position in the
+     203             :  * forwarder vector. Position at index #i, computes (#i+1) parities.
+     204             :  *
+     205             :  * All these functions give the guarantee that parities are written
+     206             :  * in order. First parity P, then parity Q, and so on.
+     207             :  * This allows to specify the same memory buffer for multiple parities
+     208             :  * knowning that you'll get the latest written one.
+     209             :  * This characteristic is used by the raid_delta_gen() function to
+     210             :  * avoid to damage unused parities in recovering.
+     211             :  *
+     212             :  * @nd Number of data blocks
+     213             :  * @size Size of the blocks pointed by @v. It must be a multipler of 64.
+     214             :  * @v Vector of pointers to the blocks of data and parity.
+     215             :  *   It has (@nd + #parities) elements. The starting elements are the blocks
+     216             :  *   for data, following with the parity blocks.
+     217             :  *   Each block has @size bytes.
+     218             :  */
+     219             : void (*raid_gen_ptr[RAID_PARITY_MAX])(int nd, size_t size, void **vv);
+     220             : void (*raid_gen3_ptr)(int nd, size_t size, void **vv);
+     221             : void (*raid_genz_ptr)(int nd, size_t size, void **vv);
+     222             : 
+     223     1196804 : void raid_gen(int nd, int np, size_t size, void **v)
+     224             : {
+     225             :         /* enforce limit on size */
+     226     1196804 :         BUG_ON(size % 64 != 0);
+     227             : 
+     228             :         /* enforce limit on number of failures */
+     229     1196804 :         BUG_ON(np < 1);
+     230     1196804 :         BUG_ON(np > RAID_PARITY_MAX);
+     231             : 
+     232     1196804 :         raid_gen_ptr[np - 1](nd, size, v);
+     233     1196804 : }
+     234             : 
+     235             : /**
+     236             :  * Inverts the square matrix M of size nxn into V.
+     237             :  *
+     238             :  * This is not a general matrix inversion because we assume the matrix M
+     239             :  * to have all the square submatrix not singular.
+     240             :  * We use Gauss elimination to invert.
+     241             :  *
+     242             :  * @M Matrix to invert with @n rows and @n columns.
+     243             :  * @V Destination matrix where the result is put.
+     244             :  * @n Number of rows and columns of the matrix.
+     245             :  */
+     246      172492 : void raid_invert(uint8_t *M, uint8_t *V, int n)
+     247             : {
+     248             :         int i, j, k;
+     249             : 
+     250             :         /* set the identity matrix in V */
+     251      797645 :         for (i = 0; i < n; ++i)
+     252     3220636 :                 for (j = 0; j < n; ++j)
+     253     2595483 :                         V[i * n + j] = i == j;
+     254             : 
+     255             :         /* for each element in the diagonal */
+     256      797645 :         for (k = 0; k < n; ++k) {
+     257             :                 uint8_t f;
+     258             : 
+     259             :                 /* the diagonal element cannot be 0 because */
+     260             :                 /* we are inverting matrices with all the square */
+     261             :                 /* submatrices not singular */
+     262      625153 :                 BUG_ON(M[k * n + k] == 0);
+     263             : 
+     264             :                 /* make the diagonal element to be 1 */
+     265     1250306 :                 f = inv(M[k * n + k]);
+     266     3220636 :                 for (j = 0; j < n; ++j) {
+     267     5190966 :                         M[k * n + j] = mul(f, M[k * n + j]);
+     268     5190966 :                         V[k * n + j] = mul(f, V[k * n + j]);
+     269             :                 }
+     270             : 
+     271             :                 /* make all the elements over and under the diagonal */
+     272             :                 /* to be zero */
+     273     3220636 :                 for (i = 0; i < n; ++i) {
+     274     2595483 :                         if (i == k)
+     275      625153 :                                 continue;
+     276     1970330 :                         f = M[i * n + k];
+     277    11280588 :                         for (j = 0; j < n; ++j) {
+     278    18620516 :                                 M[i * n + j] ^= mul(f, M[k * n + j]);
+     279    18620516 :                                 V[i * n + j] ^= mul(f, V[k * n + j]);
+     280             :                         }
+     281             :                 }
+     282             :         }
+     283      172492 : }
+     284             : 
+     285             : /**
+     286             :  * Computes the parity without the missing data blocks
+     287             :  * and store it in the buffers of such data blocks.
+     288             :  *
+     289             :  * This is the parity expressed as Pa,Qa,Ra,Sa,Ta,Ua in the equations.
+     290             :  */
+     291      171154 : void raid_delta_gen(int nr, int *id, int *ip, int nd, size_t size, void **v)
+     292             : {
+     293             :         void *p[RAID_PARITY_MAX];
+     294             :         void *pa[RAID_PARITY_MAX];
+     295             :         int i, j;
+     296             :         int np;
+     297             :         void *latest;
+     298             : 
+     299             :         /* total number of parities we are going to process */
+     300             :         /* they are both the used and the unused ones */
+     301      171154 :         np = ip[nr - 1] + 1;
+     302             : 
+     303             :         /* latest missing data block */
+     304      171154 :         latest = v[id[nr - 1]];
+     305             : 
+     306             :         /* setup pointers for delta computation */
+     307      872118 :         for (i = 0, j = 0; i < np; ++i) {
+     308             :                 /* keep a copy of the original parity vector */
+     309      700964 :                 p[i] = v[nd + i];
+     310             : 
+     311      700964 :                 if (ip[j] == i) {
+     312             :                         /*
+     313             :                          * Set used parities to point to the missing
+     314             :                          * data blocks.
+     315             :                          *
+     316             :                          * The related data blocks are instead set
+     317             :                          * to point to the "zero" buffer.
+     318             :                          */
+     319             : 
+     320             :                         /* the latest parity to use ends the for loop and */
+     321             :                         /* then it cannot happen to process more of them */
+     322      605141 :                         BUG_ON(j >= nr);
+     323             : 
+     324             :                         /* buffer for missing data blocks */
+     325      605141 :                         pa[j] = v[id[j]];
+     326             : 
+     327             :                         /* set at zero the missing data blocks */
+     328      605141 :                         v[id[j]] = raid_zero_block;
+     329             : 
+     330             :                         /* compute the parity over the missing data blocks */
+     331      605141 :                         v[nd + i] = pa[j];
+     332             : 
+     333             :                         /* check for the next used entry */
+     334      605141 :                         ++j;
+     335             :                 } else {
+     336             :                         /*
+     337             :                          * Unused parities are going to be rewritten with
+     338             :                          * not significative data, becase we don't have
+     339             :                          * functions able to compute only a subset of
+     340             :                          * parities.
+     341             :                          *
+     342             :                          * To avoid this, we reuse parity buffers,
+     343             :                          * assuming that all the parity functions write
+     344             :                          * parities in order.
+     345             :                          *
+     346             :                          * We assign the unused parity block to the same
+     347             :                          * block of the latest used parity that we know it
+     348             :                          * will be written.
+     349             :                          *
+     350             :                          * This means that this block will be written
+     351             :                          * multiple times and only the latest write will
+     352             :                          * contain the correct data.
+     353             :                          */
+     354       95823 :                         v[nd + i] = latest;
+     355             :                 }
+     356             :         }
+     357             : 
+     358             :         /* all the parities have to be processed */
+     359      171154 :         BUG_ON(j != nr);
+     360             : 
+     361             :         /* recompute the parity, note that np may be smaller than the */
+     362             :         /* total number of parities available */
+     363      171154 :         raid_gen(nd, np, size, v);
+     364             : 
+     365             :         /* restore data buffers as before */
+     366      776295 :         for (j = 0; j < nr; ++j)
+     367      605141 :                 v[id[j]] = pa[j];
+     368             : 
+     369             :         /* restore parity buffers as before */
+     370      872118 :         for (i = 0; i < np; ++i)
+     371      700964 :                 v[nd + i] = p[i];
+     372      171154 : }
+     373             : 
+     374             : /**
+     375             :  * Recover failure of one data block for PAR1.
+     376             :  *
+     377             :  * Starting from the equation:
+     378             :  *
+     379             :  * Pd = Dx
+     380             :  *
+     381             :  * and solving we get:
+     382             :  *
+     383             :  * Dx = Pd
+     384             :  */
+     385      100552 : void raid_rec1of1(int *id, int nd, size_t size, void **v)
+     386             : {
+     387             :         void *p;
+     388             :         void *pa;
+     389             : 
+     390             :         /* for PAR1 we can directly compute the missing block */
+     391             :         /* and we don't need to use the zero buffer */
+     392      100552 :         p = v[nd];
+     393      100552 :         pa = v[id[0]];
+     394             : 
+     395             :         /* use the parity as missing data block */
+     396      100552 :         v[id[0]] = p;
+     397             : 
+     398             :         /* compute the parity over the missing data block */
+     399      100552 :         v[nd] = pa;
+     400             : 
+     401             :         /* compute */
+     402      100552 :         raid_gen(nd, 1, size, v);
+     403             : 
+     404             :         /* restore as before */
+     405      100552 :         v[id[0]] = pa;
+     406      100552 :         v[nd] = p;
+     407      100552 : }
+     408             : 
+     409             : /**
+     410             :  * Recover failure of two data blocks for PAR2.
+     411             :  *
+     412             :  * Starting from the equations:
+     413             :  *
+     414             :  * Pd = Dx + Dy
+     415             :  * Qd = 2^id[0] * Dx + 2^id[1] * Dy
+     416             :  *
+     417             :  * and solving we get:
+     418             :  *
+     419             :  *               1                     2^(-id[0])
+     420             :  * Dy = ------------------- * Pd + ------------------- * Qd
+     421             :  *      2^(id[1]-id[0]) + 1        2^(id[1]-id[0]) + 1
+     422             :  *
+     423             :  * Dx = Dy + Pd
+     424             :  *
+     425             :  * with conditions:
+     426             :  *
+     427             :  * 2^id[0] != 0
+     428             :  * 2^(id[1]-id[0]) + 1 != 0
+     429             :  *
+     430             :  * That are always satisfied for any 0<=id[0]<id[1]<255.
+     431             :  */
+     432         132 : void raid_rec2of2_int8(int *id, int *ip, int nd, size_t size, void **vv)
+     433             : {
+     434         132 :         uint8_t **v = (uint8_t **)vv;
+     435             :         size_t i;
+     436             :         uint8_t *p;
+     437             :         uint8_t *pa;
+     438             :         uint8_t *q;
+     439             :         uint8_t *qa;
+     440             :         const uint8_t *T[2];
+     441             : 
+     442             :         /* get multiplication tables */
+     443         528 :         T[0] = table(inv(pow2(id[1] - id[0]) ^ 1));
+     444         660 :         T[1] = table(inv(pow2(id[0]) ^ pow2(id[1])));
+     445             : 
+     446             :         /* compute delta parity */
+     447         132 :         raid_delta_gen(2, id, ip, nd, size, vv);
+     448             : 
+     449         132 :         p = v[nd];
+     450         132 :         q = v[nd + 1];
+     451         132 :         pa = v[id[0]];
+     452         132 :         qa = v[id[1]];
+     453             : 
+     454       33924 :         for (i = 0; i < size; ++i) {
+     455             :                 /* delta */
+     456       33792 :                 uint8_t Pd = p[i] ^ pa[i];
+     457       33792 :                 uint8_t Qd = q[i] ^ qa[i];
+     458             : 
+     459             :                 /* reconstruct */
+     460       33792 :                 uint8_t Dy = T[0][Pd] ^ T[1][Qd];
+     461       33792 :                 uint8_t Dx = Pd ^ Dy;
+     462             : 
+     463             :                 /* set */
+     464       33792 :                 pa[i] = Dx;
+     465       33792 :                 qa[i] = Dy;
+     466             :         }
+     467         132 : }
+     468             : 
+     469             : /*
+     470             :  * Forwarders for data recovery.
+     471             :  *
+     472             :  * These functions recover data blocks using the specified parity
+     473             :  * to recompute the missing data.
+     474             :  *
+     475             :  * Note that the format of vectors @id/@ip is different than raid_rec().
+     476             :  * For example, in the vector @ip the first parity is represented with the
+     477             :  * value 0 and not @nd.
+     478             :  *
+     479             :  * @nr Number of failed data blocks to recover.
+     480             :  * @id[] Vector of @nr indexes of the data blocks to recover.
+     481             :  *   The indexes start from 0. They must be in order.
+     482             :  * @ip[] Vector of @nr indexes of the parity blocks to use in the recovering.
+     483             :  *   The indexes start from 0. They must be in order.
+     484             :  * @nd Number of data blocks.
+     485             :  * @np Number of parity blocks.
+     486             :  * @size Size of the blocks pointed by @v. It must be a multipler of 64.
+     487             :  * @v Vector of pointers to the blocks of data and parity.
+     488             :  *   It has (@nd + @np) elements. The starting elements are the blocks
+     489             :  *   for data, following with the parity blocks.
+     490             :  *   Each block has @size bytes.
+     491             :  */
+     492             : void (*raid_rec_ptr[RAID_PARITY_MAX])(
+     493             :         int nr, int *id, int *ip, int nd, size_t size, void **vv);
+     494             : 
+     495         901 : void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v)
+     496             : {
+     497             :         int nrd; /* number of data blocks to recover */
+     498             :         int nrp; /* number of parity blocks to recover */
+     499             : 
+     500             :         /* enforce limit on size */
+     501         901 :         BUG_ON(size % 64 != 0);
+     502             : 
+     503             :         /* enforce limit on number of failures */
+     504         901 :         BUG_ON(nr > np);
+     505         901 :         BUG_ON(np > RAID_PARITY_MAX);
+     506             : 
+     507             :         /* enforce order in index vector */
+     508         901 :         BUG_ON(nr >= 2 && ir[0] >= ir[1]);
+     509         901 :         BUG_ON(nr >= 3 && ir[1] >= ir[2]);
+     510         901 :         BUG_ON(nr >= 4 && ir[2] >= ir[3]);
+     511         901 :         BUG_ON(nr >= 5 && ir[3] >= ir[4]);
+     512         901 :         BUG_ON(nr >= 6 && ir[4] >= ir[5]);
+     513             : 
+     514             :         /* enforce limit on index vector */
+     515         901 :         BUG_ON(nr > 0 && ir[nr-1] >= nd + np);
+     516             : 
+     517             :         /* count the number of data blocks to recover */
+     518         901 :         nrd = 0;
+     519        3607 :         while (nrd < nr && ir[nrd] < nd)
+     520        1805 :                 ++nrd;
+     521             : 
+     522             :         /* all the remaining are parity */
+     523         901 :         nrp = nr - nrd;
+     524             : 
+     525             :         /* enforce limit on number of failures */
+     526         901 :         BUG_ON(nrd > nd);
+     527         901 :         BUG_ON(nrp > np);
+     528             : 
+     529             :         /* if failed data is present */
+     530         901 :         if (nrd != 0) {
+     531             :                 int ip[RAID_PARITY_MAX];
+     532             :                 int i, j, k;
+     533             : 
+     534             :                 /* setup the vector of parities to use */
+     535        6258 :                 for (i = 0, j = 0, k = 0; i < np; ++i) {
+     536        5359 :                         if (j < nrp && ir[nrd + j] == nd + i) {
+     537             :                                 /* this parity has to be recovered */
+     538          22 :                                 ++j;
+     539             :                         } else {
+     540             :                                 /* this parity is used for recovering */
+     541        5337 :                                 ip[k] = i;
+     542        5337 :                                 ++k;
+     543             :                         }
+     544             :                 }
+     545             : 
+     546             :                 /* recover the nrd data blocks specified in ir[], */
+     547             :                 /* using the first nrd parity in ip[] for recovering */
+     548         899 :                 raid_rec_ptr[nrd - 1](nrd, ir, ip, nd, size, v);
+     549             :         }
+     550             : 
+     551             :         /* recompute all the parities up to the last bad one */
+     552         901 :         if (nrp != 0)
+     553          12 :                 raid_gen(nd, ir[nr - 1] - nd + 1, size, v);
+     554         901 : }
+     555             : 
+     556      213294 : void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v)
+     557             : {
+     558             :         /* enforce limit on size */
+     559      213294 :         BUG_ON(size % 64 != 0);
+     560             : 
+     561             :         /* enforce limit on number of failures */
+     562      213294 :         BUG_ON(nr > nd);
+     563      213294 :         BUG_ON(nr > RAID_PARITY_MAX);
+     564             : 
+     565             :         /* enforce order in index vector for data */
+     566      213294 :         BUG_ON(nr >= 2 && id[0] >= id[1]);
+     567      213294 :         BUG_ON(nr >= 3 && id[1] >= id[2]);
+     568      213294 :         BUG_ON(nr >= 4 && id[2] >= id[3]);
+     569      213294 :         BUG_ON(nr >= 5 && id[3] >= id[4]);
+     570      213294 :         BUG_ON(nr >= 6 && id[4] >= id[5]);
+     571             : 
+     572             :         /* enforce limit on index vector for data */
+     573      213294 :         BUG_ON(nr > 0 && id[nr-1] >= nd);
+     574             : 
+     575             :         /* enforce order in index vector for parity */
+     576      213294 :         BUG_ON(nr >= 2 && ip[0] >= ip[1]);
+     577      213294 :         BUG_ON(nr >= 3 && ip[1] >= ip[2]);
+     578      213294 :         BUG_ON(nr >= 4 && ip[2] >= ip[3]);
+     579      213294 :         BUG_ON(nr >= 5 && ip[3] >= ip[4]);
+     580      213294 :         BUG_ON(nr >= 6 && ip[4] >= ip[5]);
+     581             : 
+     582             :         /* if failed data is present */
+     583      213294 :         if (nr != 0)
+     584      213292 :                 raid_rec_ptr[nr - 1](nr, id, ip, nd, size, v);
+     585      213294 : }
+     586             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/tag.c.func-sort-c.html b/cov/raid/tag.c.func-sort-c.html new file mode 100644 index 00000000..d7de725c --- /dev/null +++ b/cov/raid/tag.c.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/tag.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - tag.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_tag52
raid_recX_tag16
raid_gen2_tag4
raid_gen4_tag4
raid_rec2_tag4
raid_genz_tag4
raid_rec1_tag4
raid_gen3_tag4
raid_gen1_tag4
raid_gen6_tag4
raid_gen5_tag4
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/tag.c.func.html b/cov/raid/tag.c.func.html new file mode 100644 index 00000000..e491c933 --- /dev/null +++ b/cov/raid/tag.c.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - raid/tag.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - tag.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen1_tag4
raid_gen2_tag4
raid_gen3_tag4
raid_gen4_tag4
raid_gen5_tag4
raid_gen6_tag4
raid_genz_tag4
raid_rec1_tag4
raid_rec2_tag4
raid_recX_tag16
raid_tag52
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/tag.c.gcov.html b/cov/raid/tag.c.gcov.html new file mode 100644 index 00000000..80c3bfc5 --- /dev/null +++ b/cov/raid/tag.c.gcov.html @@ -0,0 +1,221 @@ + + + + + + + LCOV - lcov.info - raid/tag.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - tag.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2626100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : 
+      17             : static struct raid_func {
+      18             :         const char *name;
+      19             :         void *p;
+      20             : } RAID_FUNC[] = {
+      21             :         { "int8", raid_gen3_int8 },
+      22             :         { "int8", raid_gen4_int8 },
+      23             :         { "int8", raid_gen5_int8 },
+      24             :         { "int8", raid_gen6_int8 },
+      25             :         { "int32", raid_gen1_int32 },
+      26             :         { "int64", raid_gen1_int64 },
+      27             :         { "int32", raid_gen2_int32 },
+      28             :         { "int64", raid_gen2_int64 },
+      29             :         { "int32", raid_genz_int32 },
+      30             :         { "int64", raid_genz_int64 },
+      31             :         { "int8", raid_rec1_int8 },
+      32             :         { "int8", raid_rec2_int8 },
+      33             :         { "int8", raid_recX_int8 },
+      34             : 
+      35             : #ifdef CONFIG_X86
+      36             : #ifdef CONFIG_SSE2
+      37             :         { "sse2", raid_gen1_sse2 },
+      38             :         { "sse2", raid_gen2_sse2 },
+      39             :         { "sse2", raid_genz_sse2 },
+      40             : #endif
+      41             : #ifdef CONFIG_SSSE3
+      42             :         { "ssse3", raid_gen3_ssse3 },
+      43             :         { "ssse3", raid_gen4_ssse3 },
+      44             :         { "ssse3", raid_gen5_ssse3 },
+      45             :         { "ssse3", raid_gen6_ssse3 },
+      46             :         { "ssse3", raid_rec1_ssse3 },
+      47             :         { "ssse3", raid_rec2_ssse3 },
+      48             :         { "ssse3", raid_recX_ssse3 },
+      49             : #endif
+      50             : #ifdef CONFIG_AVX2
+      51             :         { "avx2", raid_gen1_avx2 },
+      52             :         { "avx2", raid_gen2_avx2 },
+      53             :         { "avx2", raid_rec1_avx2 },
+      54             :         { "avx2", raid_rec2_avx2 },
+      55             :         { "avx2", raid_recX_avx2 },
+      56             : #endif
+      57             : #endif
+      58             : 
+      59             : #ifdef CONFIG_X86_64
+      60             : #ifdef CONFIG_SSE2
+      61             :         { "sse2e", raid_gen2_sse2ext },
+      62             :         { "sse2e", raid_genz_sse2ext },
+      63             : #endif
+      64             : #ifdef CONFIG_SSSE3
+      65             :         { "ssse3e", raid_gen3_ssse3ext },
+      66             :         { "ssse3e", raid_gen4_ssse3ext },
+      67             :         { "ssse3e", raid_gen5_ssse3ext },
+      68             :         { "ssse3e", raid_gen6_ssse3ext },
+      69             : #endif
+      70             : #ifdef CONFIG_AVX2
+      71             :         { "avx2e", raid_gen3_avx2ext },
+      72             :         { "avx2e", raid_genz_avx2ext },
+      73             :         { "avx2e", raid_gen4_avx2ext },
+      74             :         { "avx2e", raid_gen5_avx2ext },
+      75             :         { "avx2e", raid_gen6_avx2ext },
+      76             : #endif
+      77             : #endif
+      78             :         { 0, 0 }
+      79             : };
+      80             : 
+      81          52 : static const char *raid_tag(void *func)
+      82             : {
+      83          52 :         struct raid_func *i = RAID_FUNC;
+      84             : 
+      85         994 :         while (i->name != 0) {
+      86         942 :                 if (i->p == func)
+      87          52 :                         return i->name;
+      88         890 :                 ++i;
+      89             :         }
+      90             : 
+      91             :         /* LCOV_EXCL_START */
+      92             :         return "unknown";
+      93             :         /* LCOV_EXCL_STOP */
+      94             : }
+      95             : 
+      96           4 : const char *raid_gen1_tag(void)
+      97             : {
+      98           4 :         return raid_tag(raid_gen_ptr[0]);
+      99             : }
+     100             : 
+     101           4 : const char *raid_gen2_tag(void)
+     102             : {
+     103           4 :         return raid_tag(raid_gen_ptr[1]);
+     104             : }
+     105             : 
+     106           4 : const char *raid_genz_tag(void)
+     107             : {
+     108           4 :         return raid_tag(raid_genz_ptr);
+     109             : }
+     110             : 
+     111           4 : const char *raid_gen3_tag(void)
+     112             : {
+     113           4 :         return raid_tag(raid_gen_ptr[2]);
+     114             : }
+     115             : 
+     116           4 : const char *raid_gen4_tag(void)
+     117             : {
+     118           4 :         return raid_tag(raid_gen_ptr[3]);
+     119             : }
+     120             : 
+     121           4 : const char *raid_gen5_tag(void)
+     122             : {
+     123           4 :         return raid_tag(raid_gen_ptr[4]);
+     124             : }
+     125             : 
+     126           4 : const char *raid_gen6_tag(void)
+     127             : {
+     128           4 :         return raid_tag(raid_gen_ptr[5]);
+     129             : }
+     130             : 
+     131           4 : const char *raid_rec1_tag(void)
+     132             : {
+     133           4 :         return raid_tag(raid_rec_ptr[0]);
+     134             : }
+     135             : 
+     136           4 : const char *raid_rec2_tag(void)
+     137             : {
+     138           4 :         return raid_tag(raid_rec_ptr[1]);
+     139             : }
+     140             : 
+     141          16 : const char *raid_recX_tag(void)
+     142             : {
+     143          16 :         return raid_tag(raid_rec_ptr[2]);
+     144             : }
+     145             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/test.c.func-sort-c.html b/cov/raid/test.c.func-sort-c.html new file mode 100644 index 00000000..f1b5f3b5 --- /dev/null +++ b/cov/raid/test.c.func-sort-c.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - raid/test.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - test.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:140140100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ibc120
ipow6
raid_test_par3
raid_test_rec2
raid_test_sort1
raid_test_combo1
raid_test_insert1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/test.c.func.html b/cov/raid/test.c.func.html new file mode 100644 index 00000000..9c9d0ab3 --- /dev/null +++ b/cov/raid/test.c.func.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - lcov.info - raid/test.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - test.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:140140100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ibc120
ipow6
raid_test_combo1
raid_test_insert1
raid_test_par3
raid_test_rec2
raid_test_sort1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/test.c.gcov.html b/cov/raid/test.c.gcov.html new file mode 100644 index 00000000..c90058ad --- /dev/null +++ b/cov/raid/test.c.gcov.html @@ -0,0 +1,528 @@ + + + + + + + LCOV - lcov.info - raid/test.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - test.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:140140100.0 %
Date:2015-05-12Functions:77100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "cpu.h"
+      17             : #include "combo.h"
+      18             : #include "memory.h"
+      19             : 
+      20             : /**
+      21             :  * Binomial coefficient of n over r.
+      22             :  */
+      23         120 : static int ibc(int n, int r)
+      24             : {
+      25         120 :         if (r == 0 || n == r)
+      26          63 :                 return 1;
+      27             :         else
+      28          57 :                 return ibc(n - 1, r - 1) + ibc(n - 1, r);
+      29             : }
+      30             : 
+      31             : /**
+      32             :  * Power n ^ r;
+      33             :  */
+      34           6 : static int ipow(int n, int r)
+      35             : {
+      36           6 :         int v = 1;
+      37             : 
+      38          33 :         while (r) {
+      39          21 :                 v *= n;
+      40          21 :                 --r;
+      41             :         }
+      42           6 :         return v;
+      43             : }
+      44             : 
+      45           1 : int raid_test_combo(void)
+      46             : {
+      47             :         int r;
+      48             :         int count;
+      49             :         int p[RAID_PARITY_MAX];
+      50             : 
+      51           7 :         for (r = 1; r <= RAID_PARITY_MAX; ++r) {
+      52             :                 /* count combination (r of RAID_PARITY_MAX) elements */
+      53           6 :                 count = 0;
+      54             :                 combination_first(r, RAID_PARITY_MAX, p);
+      55             : 
+      56             :                 do {
+      57          63 :                         ++count;
+      58          63 :                 } while (combination_next(r, RAID_PARITY_MAX, p));
+      59             : 
+      60           6 :                 if (count != ibc(RAID_PARITY_MAX, r)) {
+      61             :                         /* LCOV_EXCL_START */
+      62             :                         return -1;
+      63             :                         /* LCOV_EXCL_STOP */
+      64             :                 }
+      65             :         }
+      66             : 
+      67           7 :         for (r = 1; r <= RAID_PARITY_MAX; ++r) {
+      68             :                 /* count permutation (r of RAID_PARITY_MAX) elements */
+      69           6 :                 count = 0;
+      70             :                 permutation_first(r, RAID_PARITY_MAX, p);
+      71             : 
+      72             :                 do {
+      73       55986 :                         ++count;
+      74       55986 :                 } while (permutation_next(r, RAID_PARITY_MAX, p));
+      75             : 
+      76           6 :                 if (count != ipow(RAID_PARITY_MAX, r)) {
+      77             :                         /* LCOV_EXCL_START */
+      78             :                         return -1;
+      79             :                         /* LCOV_EXCL_STOP */
+      80             :                 }
+      81             :         }
+      82             : 
+      83           1 :         return 0;
+      84             : }
+      85             : 
+      86           1 : int raid_test_insert(void)
+      87             : {
+      88             :         int p[RAID_PARITY_MAX];
+      89             :         int r;
+      90             : 
+      91           7 :         for (r = 1; r <= RAID_PARITY_MAX; ++r) {
+      92             :                 permutation_first(r, RAID_PARITY_MAX, p);
+      93             :                 do {
+      94             :                         int i[RAID_PARITY_MAX];
+      95             :                         int j;
+      96             : 
+      97             :                         /* insert in order */
+      98      380712 :                         for (j = 0; j < r; ++j)
+      99      324726 :                                 raid_insert(j, i, p[j]);
+     100             : 
+     101             :                         /* check order */
+     102      324726 :                         for (j = 1; j < r; ++j) {
+     103      268740 :                                 if (i[j - 1] > i[j]) {
+     104             :                                         /* LCOV_EXCL_START */
+     105             :                                         return -1;
+     106             :                                         /* LCOV_EXCL_STOP */
+     107             :                                 }
+     108             :                         }
+     109       55986 :                 } while (permutation_next(r, RAID_PARITY_MAX, p));
+     110             :         }
+     111             : 
+     112           1 :         return 0;
+     113             : }
+     114             : 
+     115           1 : int raid_test_sort(void)
+     116             : {
+     117             :         int p[RAID_PARITY_MAX];
+     118             :         int r;
+     119             : 
+     120           7 :         for (r = 1; r <= RAID_PARITY_MAX; ++r) {
+     121             :                 permutation_first(r, RAID_PARITY_MAX, p);
+     122             :                 do {
+     123             :                         int i[RAID_PARITY_MAX];
+     124             :                         int j;
+     125             : 
+     126             :                         /* make a copy */
+     127      380712 :                         for (j = 0; j < r; ++j)
+     128      324726 :                                 i[j] = p[j];
+     129             : 
+     130       55986 :                         raid_sort(r, i);
+     131             : 
+     132             :                         /* check order */
+     133      324726 :                         for (j = 1; j < r; ++j) {
+     134      268740 :                                 if (i[j - 1] > i[j]) {
+     135             :                                         /* LCOV_EXCL_START */
+     136             :                                         return -1;
+     137             :                                         /* LCOV_EXCL_STOP */
+     138             :                                 }
+     139             :                         }
+     140       55986 :                 } while (permutation_next(r, RAID_PARITY_MAX, p));
+     141             :         }
+     142             : 
+     143           1 :         return 0;
+     144             : }
+     145             : 
+     146           2 : int raid_test_rec(int mode, int nd, size_t size)
+     147             : {
+     148             :         void (*f[RAID_PARITY_MAX][4])(
+     149             :                 int nr, int *id, int *ip, int nd, size_t size, void **vbuf);
+     150             :         void *v_alloc;
+     151             :         void **v;
+     152             :         void **data;
+     153             :         void **parity;
+     154             :         void **test;
+     155             :         void *data_save[RAID_PARITY_MAX];
+     156             :         void *parity_save[RAID_PARITY_MAX];
+     157             :         void *waste;
+     158             :         int nv;
+     159             :         int id[RAID_PARITY_MAX];
+     160             :         int ip[RAID_PARITY_MAX];
+     161             :         int i;
+     162             :         int j;
+     163             :         int nr;
+     164             :         int nf[RAID_PARITY_MAX];
+     165             :         int np;
+     166             : 
+     167           2 :         raid_mode(mode);
+     168           2 :         if (mode == RAID_MODE_CAUCHY)
+     169           1 :                 np = RAID_PARITY_MAX;
+     170             :         else
+     171           1 :                 np = 3;
+     172             : 
+     173           2 :         nv = nd + np * 2 + 2;
+     174             : 
+     175           2 :         v = raid_malloc_vector(nd, nv, size, &v_alloc);
+     176           2 :         if (!v) {
+     177             :                 /* LCOV_EXCL_START */
+     178             :                 return -1;
+     179             :                 /* LCOV_EXCL_STOP */
+     180             :         }
+     181             : 
+     182           2 :         data = v;
+     183           2 :         parity = v + nd;
+     184           2 :         test = v + nd + np;
+     185             : 
+     186          11 :         for (i = 0; i < np; ++i)
+     187           9 :                 parity_save[i] = parity[i];
+     188             : 
+     189           2 :         memset(v[nv - 2], 0, size);
+     190           2 :         raid_zero(v[nv - 2]);
+     191             : 
+     192           2 :         waste = v[nv - 1];
+     193             : 
+     194             :         /* fill with pseudo-random data with the arbitrary seed "1" */
+     195           2 :         raid_mrand_vector(1, nd, size, v);
+     196             : 
+     197             :         /* setup recov functions */
+     198          11 :         for (i = 0; i < np; ++i) {
+     199           9 :                 nf[i] = 0;
+     200           9 :                 if (i == 0) {
+     201           2 :                         f[i][nf[i]++] = raid_rec1_int8;
+     202             : #ifdef CONFIG_X86
+     203             : #ifdef CONFIG_SSSE3
+     204           2 :                         if (raid_cpu_has_ssse3())
+     205           2 :                                 f[i][nf[i]++] = raid_rec1_ssse3;
+     206             : #endif
+     207             : #ifdef CONFIG_AVX2
+     208           2 :                         if (raid_cpu_has_avx2())
+     209           2 :                                 f[i][nf[i]++] = raid_rec1_avx2;
+     210             : #endif
+     211             : #endif
+     212           7 :                 } else if (i == 1) {
+     213           2 :                         f[i][nf[i]++] = raid_rec2_int8;
+     214             : #ifdef CONFIG_X86
+     215             : #ifdef CONFIG_SSSE3
+     216           2 :                         if (raid_cpu_has_ssse3())
+     217           2 :                                 f[i][nf[i]++] = raid_rec2_ssse3;
+     218             : #endif
+     219             : #ifdef CONFIG_AVX2
+     220           2 :                         if (raid_cpu_has_avx2())
+     221           2 :                                 f[i][nf[i]++] = raid_rec2_avx2;
+     222             : #endif
+     223             : #endif
+     224             :                 } else {
+     225           5 :                         f[i][nf[i]++] = raid_recX_int8;
+     226             : #ifdef CONFIG_X86
+     227             : #ifdef CONFIG_SSSE3
+     228           5 :                         if (raid_cpu_has_ssse3())
+     229           5 :                                 f[i][nf[i]++] = raid_recX_ssse3;
+     230             : #endif
+     231             : #ifdef CONFIG_AVX2
+     232           5 :                         if (raid_cpu_has_avx2())
+     233           5 :                                 f[i][nf[i]++] = raid_recX_avx2;
+     234             : #endif
+     235             : #endif
+     236             :                 }
+     237             :         }
+     238             : 
+     239             :         /* compute the parity */
+     240           2 :         raid_gen_ref(nd, np, size, v);
+     241             : 
+     242             :         /* set all the parity to the waste v */
+     243          11 :         for (i = 0; i < np; ++i)
+     244           9 :                 parity[i] = waste;
+     245             : 
+     246             :         /* all parity levels */
+     247          11 :         for (nr = 1; nr <= np; ++nr) {
+     248             :                 /* all combinations (nr of nd) disks */
+     249             :                 combination_first(nr, nd, id);
+     250             :                 do {
+     251             :                         /* all combinations (nr of np) parities */
+     252             :                         combination_first(nr, np, ip);
+     253             :                         do {
+     254             :                                 /* for each recover function */
+     255       76068 :                                 for (j = 0; j < nf[nr - 1]; ++j) {
+     256             :                                         /* set */
+     257      283095 :                                         for (i = 0; i < nr; ++i) {
+     258             :                                                 /* remove the missing data */
+     259      226044 :                                                 data_save[i] = data[id[i]];
+     260      226044 :                                                 data[id[i]] = test[i];
+     261             :                                                 /* set the parity to use */
+     262      226044 :                                                 parity[ip[i]] = parity_save[ip[i]];
+     263             :                                         }
+     264             : 
+     265             :                                         /* recover */
+     266       57051 :                                         f[nr - 1][j](nr, id, ip, nd, size, v);
+     267             : 
+     268             :                                         /* check */
+     269      283095 :                                         for (i = 0; i < nr; ++i) {
+     270      226044 :                                                 if (memcmp(test[i], data_save[i], size) != 0) {
+     271             :                                                         /* LCOV_EXCL_START */
+     272             :                                                         goto bail;
+     273             :                                                         /* LCOV_EXCL_STOP */
+     274             :                                                 }
+     275             :                                         }
+     276             : 
+     277             :                                         /* restore */
+     278      283095 :                                         for (i = 0; i < nr; ++i) {
+     279             :                                                 /* restore the data */
+     280      226044 :                                                 data[id[i]] = data_save[i];
+     281             :                                                 /* restore the parity */
+     282      226044 :                                                 parity[ip[i]] = waste;
+     283             :                                         }
+     284             :                                 }
+     285       19017 :                         } while (combination_next(nr, np, ip));
+     286        2807 :                 } while (combination_next(nr, nd, id));
+     287             :         }
+     288             : 
+     289           2 :         free(v_alloc);
+     290           2 :         free(v);
+     291           2 :         return 0;
+     292             : 
+     293             : bail:
+     294             :         /* LCOV_EXCL_START */
+     295             :         free(v_alloc);
+     296             :         free(v);
+     297             :         return -1;
+     298             :         /* LCOV_EXCL_STOP */
+     299             : }
+     300             : 
+     301           3 : int raid_test_par(int mode, int nd, size_t size)
+     302             : {
+     303             :         void (*f[64])(int nd, size_t size, void **vbuf);
+     304             :         void *v_alloc;
+     305             :         void **v;
+     306             :         int nv;
+     307             :         int i, j;
+     308             :         int nf;
+     309             :         int np;
+     310             : 
+     311           3 :         raid_mode(mode);
+     312           3 :         if (mode == RAID_MODE_CAUCHY)
+     313           2 :                 np = RAID_PARITY_MAX;
+     314             :         else
+     315           1 :                 np = 3;
+     316             : 
+     317           3 :         nv = nd + np * 2;
+     318             : 
+     319           3 :         v = raid_malloc_vector(nd, nv, size, &v_alloc);
+     320           3 :         if (!v) {
+     321             :                 /* LCOV_EXCL_START */
+     322             :                 return -1;
+     323             :                 /* LCOV_EXCL_STOP */
+     324             :         }
+     325             : 
+     326             :         /* check memory */
+     327           3 :         if (raid_mtest_vector(nv, size, v) != 0) {
+     328             :                 /* LCOV_EXCL_START */
+     329             :                 goto bail;
+     330             :                 /* LCOV_EXCL_STOP */
+     331             :         }
+     332             : 
+     333             :         /* fill with pseudo-random data with the arbitrary seed "2" */
+     334           3 :         raid_mrand_vector(2, nv, size, v);
+     335             : 
+     336             :         /* compute the parity */
+     337           3 :         raid_gen_ref(nd, np, size, v);
+     338             : 
+     339             :         /* copy in back buffers */
+     340          18 :         for (i = 0; i < np; ++i)
+     341          15 :                 memcpy(v[nd + np + i], v[nd + i], size);
+     342             : 
+     343             :         /* load all the available functions */
+     344           3 :         nf = 0;
+     345             : 
+     346           3 :         f[nf++] = raid_gen1_int32;
+     347           3 :         f[nf++] = raid_gen1_int64;
+     348           3 :         f[nf++] = raid_gen2_int32;
+     349           3 :         f[nf++] = raid_gen2_int64;
+     350             : 
+     351             : #ifdef CONFIG_X86
+     352             : #ifdef CONFIG_SSE2
+     353           3 :         if (raid_cpu_has_sse2()) {
+     354           3 :                 f[nf++] = raid_gen1_sse2;
+     355           3 :                 f[nf++] = raid_gen2_sse2;
+     356             : #ifdef CONFIG_X86_64
+     357             :                 f[nf++] = raid_gen2_sse2ext;
+     358             : #endif
+     359             :         }
+     360             : #endif
+     361             : 
+     362             : #ifdef CONFIG_AVX2
+     363           3 :         if (raid_cpu_has_avx2()) {
+     364           3 :                 f[nf++] = raid_gen1_avx2;
+     365           3 :                 f[nf++] = raid_gen2_avx2;
+     366             :         }
+     367             : #endif
+     368             : #endif /* CONFIG_X86 */
+     369             : 
+     370           3 :         if (mode == RAID_MODE_CAUCHY) {
+     371           2 :                 f[nf++] = raid_gen3_int8;
+     372           2 :                 f[nf++] = raid_gen4_int8;
+     373           2 :                 f[nf++] = raid_gen5_int8;
+     374           2 :                 f[nf++] = raid_gen6_int8;
+     375             : 
+     376             : #ifdef CONFIG_X86
+     377             : #ifdef CONFIG_SSSE3
+     378           2 :                 if (raid_cpu_has_ssse3()) {
+     379           2 :                         f[nf++] = raid_gen3_ssse3;
+     380           2 :                         f[nf++] = raid_gen4_ssse3;
+     381           2 :                         f[nf++] = raid_gen5_ssse3;
+     382           2 :                         f[nf++] = raid_gen6_ssse3;
+     383             : #ifdef CONFIG_X86_64
+     384             :                         f[nf++] = raid_gen3_ssse3ext;
+     385             :                         f[nf++] = raid_gen4_ssse3ext;
+     386             :                         f[nf++] = raid_gen5_ssse3ext;
+     387             :                         f[nf++] = raid_gen6_ssse3ext;
+     388             : #endif
+     389             :                 }
+     390             : #endif
+     391             : 
+     392             : #ifdef CONFIG_AVX2
+     393             : #ifdef CONFIG_X86_64
+     394             :                 if (raid_cpu_has_avx2()) {
+     395             :                         f[nf++] = raid_gen3_avx2ext;
+     396             :                         f[nf++] = raid_gen4_avx2ext;
+     397             :                         f[nf++] = raid_gen5_avx2ext;
+     398             :                         f[nf++] = raid_gen6_avx2ext;
+     399             :                 }
+     400             : #endif
+     401             : #endif
+     402             : #endif /* CONFIG_X86 */
+     403             :         } else {
+     404           1 :                 f[nf++] = raid_genz_int32;
+     405           1 :                 f[nf++] = raid_genz_int64;
+     406             : 
+     407             : #ifdef CONFIG_X86
+     408             : #ifdef CONFIG_SSE2
+     409           1 :                 if (raid_cpu_has_sse2()) {
+     410           1 :                         f[nf++] = raid_genz_sse2;
+     411             : #ifdef CONFIG_X86_64
+     412             :                         f[nf++] = raid_genz_sse2ext;
+     413             : #endif
+     414             :                 }
+     415             : #endif
+     416             : 
+     417             : #ifdef CONFIG_AVX2
+     418             : #ifdef CONFIG_X86_64
+     419             :                 if (raid_cpu_has_avx2())
+     420             :                         f[nf++] = raid_genz_avx2ext;
+     421             : #endif
+     422             : #endif
+     423             : #endif /* CONFIG_X86 */
+     424             :         }
+     425             : 
+     426             :         /* check all the functions */
+     427          46 :         for (j = 0; j < nf; ++j) {
+     428             :                 /* compute parity */
+     429          43 :                 f[j](nd, size, v);
+     430             : 
+     431             :                 /* check it */
+     432         268 :                 for (i = 0; i < np; ++i) {
+     433         225 :                         if (memcmp(v[nd + np + i], v[nd + i], size) != 0) {
+     434             :                                 /* LCOV_EXCL_START */
+     435             :                                 goto bail;
+     436             :                                 /* LCOV_EXCL_STOP */
+     437             :                         }
+     438             :                 }
+     439             :         }
+     440             : 
+     441           3 :         free(v_alloc);
+     442           3 :         free(v);
+     443           3 :         return 0;
+     444             : 
+     445             : bail:
+     446             :         /* LCOV_EXCL_START */
+     447             :         free(v_alloc);
+     448             :         free(v);
+     449             :         return -1;
+     450             :         /* LCOV_EXCL_STOP */
+     451             : }
+     452             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86.c.func-sort-c.html b/cov/raid/x86.c.func-sort-c.html new file mode 100644 index 00000000..0f2b9ca9 --- /dev/null +++ b/cov/raid/x86.c.func-sort-c.html @@ -0,0 +1,128 @@ + + + + + + + LCOV - lcov.info - raid/x86.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:684684100.0 %
Date:2015-05-12Functions:1414100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen6_ssse3533272
raid_gen2_sse2276362
raid_gen1_sse2273722
raid_rec1_ssse3110047
raid_recX_ssse379300
raid_gen5_ssse350252
raid_rec2_ssse344029
raid_gen4_ssse332625
raid_gen3_ssse329442
raid_recX_avx217765
raid_rec2_avx21206
raid_gen2_avx2510
raid_rec1_avx2126
raid_gen1_avx298
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86.c.func.html b/cov/raid/x86.c.func.html new file mode 100644 index 00000000..90177951 --- /dev/null +++ b/cov/raid/x86.c.func.html @@ -0,0 +1,128 @@ + + + + + + + LCOV - lcov.info - raid/x86.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:684684100.0 %
Date:2015-05-12Functions:1414100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_gen1_avx298
raid_gen1_sse2273722
raid_gen2_avx2510
raid_gen2_sse2276362
raid_gen3_ssse329442
raid_gen4_ssse332625
raid_gen5_ssse350252
raid_gen6_ssse3533272
raid_rec1_avx2126
raid_rec1_ssse3110047
raid_rec2_avx21206
raid_rec2_ssse344029
raid_recX_avx217765
raid_recX_ssse379300
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86.c.gcov.html b/cov/raid/x86.c.gcov.html new file mode 100644 index 00000000..c9ba2f7e --- /dev/null +++ b/cov/raid/x86.c.gcov.html @@ -0,0 +1,2518 @@ + + + + + + + LCOV - lcov.info - raid/x86.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:684684100.0 %
Date:2015-05-12Functions:1414100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : #include "gf.h"
+      17             : 
+      18             : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
+      19             : /*
+      20             :  * GEN1 (RAID5 with xor) SSE2 implementation
+      21             :  *
+      22             :  * Intentionally don't process more than 64 bytes because 64 is the typical
+      23             :  * cache block, and processing 128 bytes doesn't increase performance, and in
+      24             :  * some cases it even decreases it.
+      25             :  */
+      26      273722 : void raid_gen1_sse2(int nd, size_t size, void **vv)
+      27             : {
+      28      273722 :         uint8_t **v = (uint8_t **)vv;
+      29             :         uint8_t *p;
+      30             :         int d, l;
+      31             :         size_t i;
+      32             : 
+      33      273722 :         l = nd - 1;
+      34      273722 :         p = v[nd];
+      35             : 
+      36             :         raid_sse_begin();
+      37             : 
+      38     5922118 :         for (i = 0; i < size; i += 64) {
+      39     5648396 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
+      40     5648396 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (v[l][i + 16]));
+      41     5648396 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (v[l][i + 32]));
+      42     5648396 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (v[l][i + 48]));
+      43    36438276 :                 for (d = l - 1; d >= 0; --d) {
+      44    30789880 :                         asm volatile ("pxor %0,%%xmm0" : : "m" (v[d][i]));
+      45    30789880 :                         asm volatile ("pxor %0,%%xmm1" : : "m" (v[d][i + 16]));
+      46    30789880 :                         asm volatile ("pxor %0,%%xmm2" : : "m" (v[d][i + 32]));
+      47    30789880 :                         asm volatile ("pxor %0,%%xmm3" : : "m" (v[d][i + 48]));
+      48             :                 }
+      49     5648396 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+      50     5648396 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (p[i + 16]));
+      51     5648396 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (p[i + 32]));
+      52     5648396 :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (p[i + 48]));
+      53             :         }
+      54             : 
+      55             :         raid_sse_end();
+      56      273722 : }
+      57             : #endif
+      58             : 
+      59             : #if defined(CONFIG_X86) && defined(CONFIG_AVX2)
+      60             : /*
+      61             :  * GEN1 (RAID5 with xor) AVX2 implementation
+      62             :  *
+      63             :  * Intentionally don't process more than 64 bytes because 64 is the typical
+      64             :  * cache block, and processing 128 bytes doesn't increase performance, and in
+      65             :  * some cases it even decreases it.
+      66             :  */
+      67          98 : void raid_gen1_avx2(int nd, size_t size, void **vv)
+      68             : {
+      69          98 :         uint8_t **v = (uint8_t **)vv;
+      70             :         uint8_t *p;
+      71             :         int d, l;
+      72             :         size_t i;
+      73             : 
+      74          98 :         l = nd - 1;
+      75          98 :         p = v[nd];
+      76             : 
+      77             :         raid_avx_begin();
+      78             : 
+      79       54286 :         for (i = 0; i < size; i += 64) {
+      80       54188 :                 asm volatile ("vmovdqa %0,%%ymm0" : : "m" (v[l][i]));
+      81       54188 :                 asm volatile ("vmovdqa %0,%%ymm1" : : "m" (v[l][i + 32]));
+      82      439940 :                 for (d = l - 1; d >= 0; --d) {
+      83      385752 :                         asm volatile ("vpxor %0,%%ymm0,%%ymm0" : : "m" (v[d][i]));
+      84      385752 :                         asm volatile ("vpxor %0,%%ymm1,%%ymm1" : : "m" (v[d][i + 32]));
+      85             :                 }
+      86       54188 :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+      87       54188 :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (p[i + 32]));
+      88             :         }
+      89             : 
+      90             :         raid_avx_end();
+      91          98 : }
+      92             : #endif
+      93             : 
+      94             : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
+      95             : static const struct gfconst16 {
+      96             :         uint8_t poly[16];
+      97             :         uint8_t low4[16];
+      98             : } gfconst16 __aligned(32) = {
+      99             :         {
+     100             :                 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
+     101             :                 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d
+     102             :         },
+     103             :         {
+     104             :                 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
+     105             :                 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
+     106             :         },
+     107             : };
+     108             : #endif
+     109             : 
+     110             : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
+     111             : /*
+     112             :  * GEN2 (RAID6 with powers of 2) SSE2 implementation
+     113             :  */
+     114      276362 : void raid_gen2_sse2(int nd, size_t size, void **vv)
+     115             : {
+     116      276362 :         uint8_t **v = (uint8_t **)vv;
+     117             :         uint8_t *p;
+     118             :         uint8_t *q;
+     119             :         int d, l;
+     120             :         size_t i;
+     121             : 
+     122      276362 :         l = nd - 1;
+     123      276362 :         p = v[nd];
+     124      276362 :         q = v[nd + 1];
+     125             : 
+     126             :         raid_sse_begin();
+     127             : 
+     128      276362 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+     129             : 
+     130    11061954 :         for (i = 0; i < size; i += 32) {
+     131    10785592 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
+     132    10785592 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (v[l][i + 16]));
+     133    10785592 :                 asm volatile ("movdqa %xmm0,%xmm2");
+     134    10785592 :                 asm volatile ("movdqa %xmm1,%xmm3");
+     135    68613320 :                 for (d = l - 1; d >= 0; --d) {
+     136    57827728 :                         asm volatile ("pxor %xmm4,%xmm4");
+     137    57827728 :                         asm volatile ("pxor %xmm5,%xmm5");
+     138    57827728 :                         asm volatile ("pcmpgtb %xmm2,%xmm4");
+     139    57827728 :                         asm volatile ("pcmpgtb %xmm3,%xmm5");
+     140    57827728 :                         asm volatile ("paddb %xmm2,%xmm2");
+     141    57827728 :                         asm volatile ("paddb %xmm3,%xmm3");
+     142    57827728 :                         asm volatile ("pand %xmm7,%xmm4");
+     143    57827728 :                         asm volatile ("pand %xmm7,%xmm5");
+     144    57827728 :                         asm volatile ("pxor %xmm4,%xmm2");
+     145    57827728 :                         asm volatile ("pxor %xmm5,%xmm3");
+     146             : 
+     147    57827728 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     148    57827728 :                         asm volatile ("movdqa %0,%%xmm5" : : "m" (v[d][i + 16]));
+     149    57827728 :                         asm volatile ("pxor %xmm4,%xmm0");
+     150    57827728 :                         asm volatile ("pxor %xmm5,%xmm1");
+     151    57827728 :                         asm volatile ("pxor %xmm4,%xmm2");
+     152    57827728 :                         asm volatile ("pxor %xmm5,%xmm3");
+     153             :                 }
+     154    10785592 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     155    10785592 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (p[i + 16]));
+     156    10785592 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (q[i]));
+     157    10785592 :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (q[i + 16]));
+     158             :         }
+     159             : 
+     160             :         raid_sse_end();
+     161      276362 : }
+     162             : #endif
+     163             : 
+     164             : #if defined(CONFIG_X86) && defined(CONFIG_AVX2)
+     165             : /*
+     166             :  * GEN2 (RAID6 with powers of 2) AVX2 implementation
+     167             :  */
+     168         510 : void raid_gen2_avx2(int nd, size_t size, void **vv)
+     169             : {
+     170         510 :         uint8_t **v = (uint8_t **)vv;
+     171             :         uint8_t *p;
+     172             :         uint8_t *q;
+     173             :         int d, l;
+     174             :         size_t i;
+     175             : 
+     176         510 :         l = nd - 1;
+     177         510 :         p = v[nd];
+     178         510 :         q = v[nd + 1];
+     179             : 
+     180             :         raid_avx_begin();
+     181             : 
+     182         510 :         asm volatile ("vbroadcasti128 %0, %%ymm7" : : "m" (gfconst16.poly[0]));
+     183         510 :         asm volatile ("vpxor %ymm6,%ymm6,%ymm6");
+     184             : 
+     185      113754 :         for (i = 0; i < size; i += 64) {
+     186      113244 :                 asm volatile ("vmovdqa %0,%%ymm0" : : "m" (v[l][i]));
+     187      113244 :                 asm volatile ("vmovdqa %0,%%ymm1" : : "m" (v[l][i + 32]));
+     188      113244 :                 asm volatile ("vmovdqa %ymm0,%ymm2");
+     189      113244 :                 asm volatile ("vmovdqa %ymm1,%ymm3");
+     190      919748 :                 for (d = l - 1; d >= 0; --d) {
+     191      806504 :                         asm volatile ("vpcmpgtb %ymm2,%ymm6,%ymm4");
+     192      806504 :                         asm volatile ("vpcmpgtb %ymm3,%ymm6,%ymm5");
+     193      806504 :                         asm volatile ("vpaddb %ymm2,%ymm2,%ymm2");
+     194      806504 :                         asm volatile ("vpaddb %ymm3,%ymm3,%ymm3");
+     195      806504 :                         asm volatile ("vpand %ymm7,%ymm4,%ymm4");
+     196      806504 :                         asm volatile ("vpand %ymm7,%ymm5,%ymm5");
+     197      806504 :                         asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
+     198      806504 :                         asm volatile ("vpxor %ymm5,%ymm3,%ymm3");
+     199             : 
+     200      806504 :                         asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[d][i]));
+     201      806504 :                         asm volatile ("vmovdqa %0,%%ymm5" : : "m" (v[d][i + 32]));
+     202      806504 :                         asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+     203      806504 :                         asm volatile ("vpxor %ymm5,%ymm1,%ymm1");
+     204      806504 :                         asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
+     205      806504 :                         asm volatile ("vpxor %ymm5,%ymm3,%ymm3");
+     206             :                 }
+     207      113244 :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+     208      113244 :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (p[i + 32]));
+     209      113244 :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (q[i]));
+     210      113244 :                 asm volatile ("vmovntdq %%ymm3,%0" : "=m" (q[i + 32]));
+     211             :         }
+     212             : 
+     213             :         raid_avx_end();
+     214         510 : }
+     215             : #endif
+     216             : 
+     217             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSE2)
+     218             : /*
+     219             :  * GEN2 (RAID6 with powers of 2) SSE2 implementation
+     220             :  *
+     221             :  * Note that it uses 16 registers, meaning that x64 is required.
+     222             :  */
+     223             : void raid_gen2_sse2ext(int nd, size_t size, void **vv)
+     224             : {
+     225             :         uint8_t **v = (uint8_t **)vv;
+     226             :         uint8_t *p;
+     227             :         uint8_t *q;
+     228             :         int d, l;
+     229             :         size_t i;
+     230             : 
+     231             :         l = nd - 1;
+     232             :         p = v[nd];
+     233             :         q = v[nd + 1];
+     234             : 
+     235             :         raid_sse_begin();
+     236             : 
+     237             :         asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.poly[0]));
+     238             : 
+     239             :         for (i = 0; i < size; i += 64) {
+     240             :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
+     241             :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (v[l][i + 16]));
+     242             :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (v[l][i + 32]));
+     243             :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (v[l][i + 48]));
+     244             :                 asm volatile ("movdqa %xmm0,%xmm4");
+     245             :                 asm volatile ("movdqa %xmm1,%xmm5");
+     246             :                 asm volatile ("movdqa %xmm2,%xmm6");
+     247             :                 asm volatile ("movdqa %xmm3,%xmm7");
+     248             :                 for (d = l - 1; d >= 0; --d) {
+     249             :                         asm volatile ("pxor %xmm8,%xmm8");
+     250             :                         asm volatile ("pxor %xmm9,%xmm9");
+     251             :                         asm volatile ("pxor %xmm10,%xmm10");
+     252             :                         asm volatile ("pxor %xmm11,%xmm11");
+     253             :                         asm volatile ("pcmpgtb %xmm4,%xmm8");
+     254             :                         asm volatile ("pcmpgtb %xmm5,%xmm9");
+     255             :                         asm volatile ("pcmpgtb %xmm6,%xmm10");
+     256             :                         asm volatile ("pcmpgtb %xmm7,%xmm11");
+     257             :                         asm volatile ("paddb %xmm4,%xmm4");
+     258             :                         asm volatile ("paddb %xmm5,%xmm5");
+     259             :                         asm volatile ("paddb %xmm6,%xmm6");
+     260             :                         asm volatile ("paddb %xmm7,%xmm7");
+     261             :                         asm volatile ("pand %xmm15,%xmm8");
+     262             :                         asm volatile ("pand %xmm15,%xmm9");
+     263             :                         asm volatile ("pand %xmm15,%xmm10");
+     264             :                         asm volatile ("pand %xmm15,%xmm11");
+     265             :                         asm volatile ("pxor %xmm8,%xmm4");
+     266             :                         asm volatile ("pxor %xmm9,%xmm5");
+     267             :                         asm volatile ("pxor %xmm10,%xmm6");
+     268             :                         asm volatile ("pxor %xmm11,%xmm7");
+     269             : 
+     270             :                         asm volatile ("movdqa %0,%%xmm8" : : "m" (v[d][i]));
+     271             :                         asm volatile ("movdqa %0,%%xmm9" : : "m" (v[d][i + 16]));
+     272             :                         asm volatile ("movdqa %0,%%xmm10" : : "m" (v[d][i + 32]));
+     273             :                         asm volatile ("movdqa %0,%%xmm11" : : "m" (v[d][i + 48]));
+     274             :                         asm volatile ("pxor %xmm8,%xmm0");
+     275             :                         asm volatile ("pxor %xmm9,%xmm1");
+     276             :                         asm volatile ("pxor %xmm10,%xmm2");
+     277             :                         asm volatile ("pxor %xmm11,%xmm3");
+     278             :                         asm volatile ("pxor %xmm8,%xmm4");
+     279             :                         asm volatile ("pxor %xmm9,%xmm5");
+     280             :                         asm volatile ("pxor %xmm10,%xmm6");
+     281             :                         asm volatile ("pxor %xmm11,%xmm7");
+     282             :                 }
+     283             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     284             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (p[i + 16]));
+     285             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (p[i + 32]));
+     286             :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (p[i + 48]));
+     287             :                 asm volatile ("movntdq %%xmm4,%0" : "=m" (q[i]));
+     288             :                 asm volatile ("movntdq %%xmm5,%0" : "=m" (q[i + 16]));
+     289             :                 asm volatile ("movntdq %%xmm6,%0" : "=m" (q[i + 32]));
+     290             :                 asm volatile ("movntdq %%xmm7,%0" : "=m" (q[i + 48]));
+     291             :         }
+     292             : 
+     293             :         raid_sse_end();
+     294             : }
+     295             : #endif
+     296             : 
+     297             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+     298             : /*
+     299             :  * GEN3 (triple parity with Cauchy matrix) SSSE3 implementation
+     300             :  */
+     301       29442 : void raid_gen3_ssse3(int nd, size_t size, void **vv)
+     302             : {
+     303       29442 :         uint8_t **v = (uint8_t **)vv;
+     304             :         uint8_t *p;
+     305             :         uint8_t *q;
+     306             :         uint8_t *r;
+     307             :         int d, l;
+     308             :         size_t i;
+     309             : 
+     310       29442 :         l = nd - 1;
+     311       29442 :         p = v[nd];
+     312       29442 :         q = v[nd + 1];
+     313       29442 :         r = v[nd + 2];
+     314             : 
+     315             :         /* special case with only one data disk */
+     316       29442 :         if (l == 0) {
+     317           4 :                 for (i = 0; i < 3; ++i)
+     318           3 :                         memcpy(v[1 + i], v[0], size);
+     319       29443 :                 return;
+     320             :         }
+     321             : 
+     322             :         raid_sse_begin();
+     323             : 
+     324             :         /* generic case with at least two data disks */
+     325       29441 :         asm volatile ("movdqa %0,%%xmm3" : : "m" (gfconst16.poly[0]));
+     326       29441 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+     327             : 
+     328     4898641 :         for (i = 0; i < size; i += 16) {
+     329             :                 /* last disk without the by two multiplication */
+     330     4869200 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+     331             : 
+     332     4869200 :                 asm volatile ("movdqa %xmm4,%xmm0");
+     333     4869200 :                 asm volatile ("movdqa %xmm4,%xmm1");
+     334             : 
+     335     4869200 :                 asm volatile ("movdqa %xmm4,%xmm5");
+     336     4869200 :                 asm volatile ("psrlw  $4,%xmm5");
+     337     4869200 :                 asm volatile ("pand   %xmm7,%xmm4");
+     338     4869200 :                 asm volatile ("pand   %xmm7,%xmm5");
+     339             : 
+     340     4869200 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+     341     4869200 :                 asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[l][0][1][0]));
+     342     4869200 :                 asm volatile ("pshufb %xmm4,%xmm2");
+     343     4869200 :                 asm volatile ("pshufb %xmm5,%xmm6");
+     344     4869200 :                 asm volatile ("pxor   %xmm6,%xmm2");
+     345             : 
+     346             :                 /* intermediate disks */
+     347    30571696 :                 for (d = l - 1; d > 0; --d) {
+     348    25702496 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     349             : 
+     350    25702496 :                         asm volatile ("pxor %xmm5,%xmm5");
+     351    25702496 :                         asm volatile ("pcmpgtb %xmm1,%xmm5");
+     352    25702496 :                         asm volatile ("paddb %xmm1,%xmm1");
+     353    25702496 :                         asm volatile ("pand %xmm3,%xmm5");
+     354    25702496 :                         asm volatile ("pxor %xmm5,%xmm1");
+     355             : 
+     356    25702496 :                         asm volatile ("pxor %xmm4,%xmm0");
+     357    25702496 :                         asm volatile ("pxor %xmm4,%xmm1");
+     358             : 
+     359    25702496 :                         asm volatile ("movdqa %xmm4,%xmm5");
+     360    25702496 :                         asm volatile ("psrlw  $4,%xmm5");
+     361    25702496 :                         asm volatile ("pand   %xmm7,%xmm4");
+     362    25702496 :                         asm volatile ("pand   %xmm7,%xmm5");
+     363             : 
+     364    25702496 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+     365    25702496 :                         asm volatile ("pshufb %xmm4,%xmm6");
+     366    25702496 :                         asm volatile ("pxor   %xmm6,%xmm2");
+     367    25702496 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][1][0]));
+     368    25702496 :                         asm volatile ("pshufb %xmm5,%xmm6");
+     369    25702496 :                         asm volatile ("pxor   %xmm6,%xmm2");
+     370             :                 }
+     371             : 
+     372             :                 /* first disk with all coefficients at 1 */
+     373     4869200 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+     374             : 
+     375     4869200 :                 asm volatile ("pxor %xmm5,%xmm5");
+     376     4869200 :                 asm volatile ("pcmpgtb %xmm1,%xmm5");
+     377     4869200 :                 asm volatile ("paddb %xmm1,%xmm1");
+     378     4869200 :                 asm volatile ("pand %xmm3,%xmm5");
+     379     4869200 :                 asm volatile ("pxor %xmm5,%xmm1");
+     380             : 
+     381     4869200 :                 asm volatile ("pxor %xmm4,%xmm0");
+     382     4869200 :                 asm volatile ("pxor %xmm4,%xmm1");
+     383     4869200 :                 asm volatile ("pxor %xmm4,%xmm2");
+     384             : 
+     385     4869200 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     386     4869200 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+     387     4869200 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+     388             :         }
+     389             : 
+     390             :         raid_sse_end();
+     391             : }
+     392             : #endif
+     393             : 
+     394             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSSE3)
+     395             : /*
+     396             :  * GEN3 (triple parity with Cauchy matrix) SSSE3 implementation
+     397             :  *
+     398             :  * Note that it uses 16 registers, meaning that x64 is required.
+     399             :  */
+     400             : void raid_gen3_ssse3ext(int nd, size_t size, void **vv)
+     401             : {
+     402             :         uint8_t **v = (uint8_t **)vv;
+     403             :         uint8_t *p;
+     404             :         uint8_t *q;
+     405             :         uint8_t *r;
+     406             :         int d, l;
+     407             :         size_t i;
+     408             : 
+     409             :         l = nd - 1;
+     410             :         p = v[nd];
+     411             :         q = v[nd + 1];
+     412             :         r = v[nd + 2];
+     413             : 
+     414             :         /* special case with only one data disk */
+     415             :         if (l == 0) {
+     416             :                 for (i = 0; i < 3; ++i)
+     417             :                         memcpy(v[1 + i], v[0], size);
+     418             :                 return;
+     419             :         }
+     420             : 
+     421             :         raid_sse_begin();
+     422             : 
+     423             :         /* generic case with at least two data disks */
+     424             :         asm volatile ("movdqa %0,%%xmm3" : : "m" (gfconst16.poly[0]));
+     425             :         asm volatile ("movdqa %0,%%xmm11" : : "m" (gfconst16.low4[0]));
+     426             : 
+     427             :         for (i = 0; i < size; i += 32) {
+     428             :                 /* last disk without the by two multiplication */
+     429             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+     430             :                 asm volatile ("movdqa %0,%%xmm12" : : "m" (v[l][i + 16]));
+     431             : 
+     432             :                 asm volatile ("movdqa %xmm4,%xmm0");
+     433             :                 asm volatile ("movdqa %xmm4,%xmm1");
+     434             :                 asm volatile ("movdqa %xmm12,%xmm8");
+     435             :                 asm volatile ("movdqa %xmm12,%xmm9");
+     436             : 
+     437             :                 asm volatile ("movdqa %xmm4,%xmm5");
+     438             :                 asm volatile ("movdqa %xmm12,%xmm13");
+     439             :                 asm volatile ("psrlw  $4,%xmm5");
+     440             :                 asm volatile ("psrlw  $4,%xmm13");
+     441             :                 asm volatile ("pand   %xmm11,%xmm4");
+     442             :                 asm volatile ("pand   %xmm11,%xmm12");
+     443             :                 asm volatile ("pand   %xmm11,%xmm5");
+     444             :                 asm volatile ("pand   %xmm11,%xmm13");
+     445             : 
+     446             :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+     447             :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][0][1][0]));
+     448             :                 asm volatile ("movdqa %xmm2,%xmm10");
+     449             :                 asm volatile ("movdqa %xmm7,%xmm15");
+     450             :                 asm volatile ("pshufb %xmm4,%xmm2");
+     451             :                 asm volatile ("pshufb %xmm12,%xmm10");
+     452             :                 asm volatile ("pshufb %xmm5,%xmm7");
+     453             :                 asm volatile ("pshufb %xmm13,%xmm15");
+     454             :                 asm volatile ("pxor   %xmm7,%xmm2");
+     455             :                 asm volatile ("pxor   %xmm15,%xmm10");
+     456             : 
+     457             :                 /* intermediate disks */
+     458             :                 for (d = l - 1; d > 0; --d) {
+     459             :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     460             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (v[d][i + 16]));
+     461             : 
+     462             :                         asm volatile ("pxor %xmm5,%xmm5");
+     463             :                         asm volatile ("pxor %xmm13,%xmm13");
+     464             :                         asm volatile ("pcmpgtb %xmm1,%xmm5");
+     465             :                         asm volatile ("pcmpgtb %xmm9,%xmm13");
+     466             :                         asm volatile ("paddb %xmm1,%xmm1");
+     467             :                         asm volatile ("paddb %xmm9,%xmm9");
+     468             :                         asm volatile ("pand %xmm3,%xmm5");
+     469             :                         asm volatile ("pand %xmm3,%xmm13");
+     470             :                         asm volatile ("pxor %xmm5,%xmm1");
+     471             :                         asm volatile ("pxor %xmm13,%xmm9");
+     472             : 
+     473             :                         asm volatile ("pxor %xmm4,%xmm0");
+     474             :                         asm volatile ("pxor %xmm4,%xmm1");
+     475             :                         asm volatile ("pxor %xmm12,%xmm8");
+     476             :                         asm volatile ("pxor %xmm12,%xmm9");
+     477             : 
+     478             :                         asm volatile ("movdqa %xmm4,%xmm5");
+     479             :                         asm volatile ("movdqa %xmm12,%xmm13");
+     480             :                         asm volatile ("psrlw  $4,%xmm5");
+     481             :                         asm volatile ("psrlw  $4,%xmm13");
+     482             :                         asm volatile ("pand   %xmm11,%xmm4");
+     483             :                         asm volatile ("pand   %xmm11,%xmm12");
+     484             :                         asm volatile ("pand   %xmm11,%xmm5");
+     485             :                         asm volatile ("pand   %xmm11,%xmm13");
+     486             : 
+     487             :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+     488             :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][0][1][0]));
+     489             :                         asm volatile ("movdqa %xmm6,%xmm14");
+     490             :                         asm volatile ("movdqa %xmm7,%xmm15");
+     491             :                         asm volatile ("pshufb %xmm4,%xmm6");
+     492             :                         asm volatile ("pshufb %xmm12,%xmm14");
+     493             :                         asm volatile ("pshufb %xmm5,%xmm7");
+     494             :                         asm volatile ("pshufb %xmm13,%xmm15");
+     495             :                         asm volatile ("pxor   %xmm6,%xmm2");
+     496             :                         asm volatile ("pxor   %xmm14,%xmm10");
+     497             :                         asm volatile ("pxor   %xmm7,%xmm2");
+     498             :                         asm volatile ("pxor   %xmm15,%xmm10");
+     499             :                 }
+     500             : 
+     501             :                 /* first disk with all coefficients at 1 */
+     502             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+     503             :                 asm volatile ("movdqa %0,%%xmm12" : : "m" (v[0][i + 16]));
+     504             : 
+     505             :                 asm volatile ("pxor %xmm5,%xmm5");
+     506             :                 asm volatile ("pxor %xmm13,%xmm13");
+     507             :                 asm volatile ("pcmpgtb %xmm1,%xmm5");
+     508             :                 asm volatile ("pcmpgtb %xmm9,%xmm13");
+     509             :                 asm volatile ("paddb %xmm1,%xmm1");
+     510             :                 asm volatile ("paddb %xmm9,%xmm9");
+     511             :                 asm volatile ("pand %xmm3,%xmm5");
+     512             :                 asm volatile ("pand %xmm3,%xmm13");
+     513             :                 asm volatile ("pxor %xmm5,%xmm1");
+     514             :                 asm volatile ("pxor %xmm13,%xmm9");
+     515             : 
+     516             :                 asm volatile ("pxor %xmm4,%xmm0");
+     517             :                 asm volatile ("pxor %xmm4,%xmm1");
+     518             :                 asm volatile ("pxor %xmm4,%xmm2");
+     519             :                 asm volatile ("pxor %xmm12,%xmm8");
+     520             :                 asm volatile ("pxor %xmm12,%xmm9");
+     521             :                 asm volatile ("pxor %xmm12,%xmm10");
+     522             : 
+     523             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     524             :                 asm volatile ("movntdq %%xmm8,%0" : "=m" (p[i + 16]));
+     525             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+     526             :                 asm volatile ("movntdq %%xmm9,%0" : "=m" (q[i + 16]));
+     527             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+     528             :                 asm volatile ("movntdq %%xmm10,%0" : "=m" (r[i + 16]));
+     529             :         }
+     530             : 
+     531             :         raid_sse_end();
+     532             : }
+     533             : #endif
+     534             : 
+     535             : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
+     536             : /*
+     537             :  * GEN3 (triple parity with Cauchy matrix) AVX2 implementation
+     538             :  *
+     539             :  * Note that it uses 16 registers, meaning that x64 is required.
+     540             :  */
+     541             : void raid_gen3_avx2ext(int nd, size_t size, void **vv)
+     542             : {
+     543             :         uint8_t **v = (uint8_t **)vv;
+     544             :         uint8_t *p;
+     545             :         uint8_t *q;
+     546             :         uint8_t *r;
+     547             :         int d, l;
+     548             :         size_t i;
+     549             : 
+     550             :         l = nd - 1;
+     551             :         p = v[nd];
+     552             :         q = v[nd + 1];
+     553             :         r = v[nd + 2];
+     554             : 
+     555             :         /* special case with only one data disk */
+     556             :         if (l == 0) {
+     557             :                 for (i = 0; i < 3; ++i)
+     558             :                         memcpy(v[1 + i], v[0], size);
+     559             :                 return;
+     560             :         }
+     561             : 
+     562             :         raid_avx_begin();
+     563             : 
+     564             :         /* generic case with at least two data disks */
+     565             :         asm volatile ("vbroadcasti128 %0, %%ymm3" : : "m" (gfconst16.poly[0]));
+     566             :         asm volatile ("vbroadcasti128 %0, %%ymm11" : : "m" (gfconst16.low4[0]));
+     567             : 
+     568             :         for (i = 0; i < size; i += 64) {
+     569             :                 /* last disk without the by two multiplication */
+     570             :                 asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[l][i]));
+     571             :                 asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[l][i + 32]));
+     572             : 
+     573             :                 asm volatile ("vmovdqa %ymm4,%ymm0");
+     574             :                 asm volatile ("vmovdqa %ymm4,%ymm1");
+     575             :                 asm volatile ("vmovdqa %ymm12,%ymm8");
+     576             :                 asm volatile ("vmovdqa %ymm12,%ymm9");
+     577             : 
+     578             :                 asm volatile ("vpsrlw  $4,%ymm4,%ymm5");
+     579             :                 asm volatile ("vpsrlw  $4,%ymm12,%ymm13");
+     580             :                 asm volatile ("vpand   %ymm11,%ymm4,%ymm4");
+     581             :                 asm volatile ("vpand   %ymm11,%ymm12,%ymm12");
+     582             :                 asm volatile ("vpand   %ymm11,%ymm5,%ymm5");
+     583             :                 asm volatile ("vpand   %ymm11,%ymm13,%ymm13");
+     584             : 
+     585             :                 asm volatile ("vbroadcasti128 %0,%%ymm10" : : "m" (gfgenpshufb[l][0][0][0]));
+     586             :                 asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[l][0][1][0]));
+     587             :                 asm volatile ("vpshufb %ymm4,%ymm10,%ymm2");
+     588             :                 asm volatile ("vpshufb %ymm12,%ymm10,%ymm10");
+     589             :                 asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+     590             :                 asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+     591             :                 asm volatile ("vpxor   %ymm7,%ymm2,%ymm2");
+     592             :                 asm volatile ("vpxor   %ymm15,%ymm10,%ymm10");
+     593             : 
+     594             :                 /* intermediate disks */
+     595             :                 for (d = l - 1; d > 0; --d) {
+     596             :                         asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[d][i]));
+     597             :                         asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[d][i + 32]));
+     598             : 
+     599             :                         asm volatile ("vpxor %ymm5,%ymm5,%ymm5");
+     600             :                         asm volatile ("vpxor %ymm13,%ymm13,%ymm13");
+     601             :                         asm volatile ("vpcmpgtb %ymm1,%ymm5,%ymm5");
+     602             :                         asm volatile ("vpcmpgtb %ymm9,%ymm13,%ymm13");
+     603             :                         asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+     604             :                         asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
+     605             :                         asm volatile ("vpand %ymm3,%ymm5,%ymm5");
+     606             :                         asm volatile ("vpand %ymm3,%ymm13,%ymm13");
+     607             :                         asm volatile ("vpxor %ymm5,%ymm1,%ymm1");
+     608             :                         asm volatile ("vpxor %ymm13,%ymm9,%ymm9");
+     609             : 
+     610             :                         asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+     611             :                         asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+     612             :                         asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
+     613             :                         asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+     614             : 
+     615             :                         asm volatile ("vpsrlw  $4,%ymm4,%ymm5");
+     616             :                         asm volatile ("vpsrlw  $4,%ymm12,%ymm13");
+     617             :                         asm volatile ("vpand   %ymm11,%ymm4,%ymm4");
+     618             :                         asm volatile ("vpand   %ymm11,%ymm12,%ymm12");
+     619             :                         asm volatile ("vpand   %ymm11,%ymm5,%ymm5");
+     620             :                         asm volatile ("vpand   %ymm11,%ymm13,%ymm13");
+     621             : 
+     622             :                         asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (gfgenpshufb[d][0][0][0]));
+     623             :                         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[d][0][1][0]));
+     624             :                         asm volatile ("vpshufb %ymm4,%ymm14,%ymm6");
+     625             :                         asm volatile ("vpshufb %ymm12,%ymm14,%ymm14");
+     626             :                         asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+     627             :                         asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+     628             :                         asm volatile ("vpxor   %ymm6,%ymm2,%ymm2");
+     629             :                         asm volatile ("vpxor   %ymm14,%ymm10,%ymm10");
+     630             :                         asm volatile ("vpxor   %ymm7,%ymm2,%ymm2");
+     631             :                         asm volatile ("vpxor   %ymm15,%ymm10,%ymm10");
+     632             :                 }
+     633             : 
+     634             :                 /* first disk with all coefficients at 1 */
+     635             :                 asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[0][i]));
+     636             :                 asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[0][i + 32]));
+     637             : 
+     638             :                 asm volatile ("vpxor %ymm5,%ymm5,%ymm5");
+     639             :                 asm volatile ("vpxor %ymm13,%ymm13,%ymm13");
+     640             :                 asm volatile ("vpcmpgtb %ymm1,%ymm5,%ymm5");
+     641             :                 asm volatile ("vpcmpgtb %ymm9,%ymm13,%ymm13");
+     642             :                 asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+     643             :                 asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
+     644             :                 asm volatile ("vpand %ymm3,%ymm5,%ymm5");
+     645             :                 asm volatile ("vpand %ymm3,%ymm13,%ymm13");
+     646             :                 asm volatile ("vpxor %ymm5,%ymm1,%ymm1");
+     647             :                 asm volatile ("vpxor %ymm13,%ymm9,%ymm9");
+     648             : 
+     649             :                 asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+     650             :                 asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+     651             :                 asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
+     652             :                 asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
+     653             :                 asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+     654             :                 asm volatile ("vpxor %ymm12,%ymm10,%ymm10");
+     655             : 
+     656             :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+     657             :                 asm volatile ("vmovntdq %%ymm8,%0" : "=m" (p[i + 32]));
+     658             :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
+     659             :                 asm volatile ("vmovntdq %%ymm9,%0" : "=m" (q[i + 32]));
+     660             :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
+     661             :                 asm volatile ("vmovntdq %%ymm10,%0" : "=m" (r[i + 32]));
+     662             :         }
+     663             : 
+     664             :         raid_avx_end();
+     665             : }
+     666             : #endif
+     667             : 
+     668             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+     669             : /*
+     670             :  * GEN4 (quad parity with Cauchy matrix) SSSE3 implementation
+     671             :  */
+     672       32625 : void raid_gen4_ssse3(int nd, size_t size, void **vv)
+     673             : {
+     674       32625 :         uint8_t **v = (uint8_t **)vv;
+     675             :         uint8_t *p;
+     676             :         uint8_t *q;
+     677             :         uint8_t *r;
+     678             :         uint8_t *s;
+     679             :         int d, l;
+     680             :         size_t i;
+     681             : 
+     682       32625 :         l = nd - 1;
+     683       32625 :         p = v[nd];
+     684       32625 :         q = v[nd + 1];
+     685       32625 :         r = v[nd + 2];
+     686       32625 :         s = v[nd + 3];
+     687             : 
+     688             :         /* special case with only one data disk */
+     689       32625 :         if (l == 0) {
+     690           5 :                 for (i = 0; i < 4; ++i)
+     691           4 :                         memcpy(v[1 + i], v[0], size);
+     692       32626 :                 return;
+     693             :         }
+     694             : 
+     695             :         raid_sse_begin();
+     696             : 
+     697             :         /* generic case with at least two data disks */
+     698     3361264 :         for (i = 0; i < size; i += 16) {
+     699             :                 /* last disk without the by two multiplication */
+     700     3328640 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+     701     3328640 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+     702             : 
+     703     3328640 :                 asm volatile ("movdqa %xmm4,%xmm0");
+     704     3328640 :                 asm volatile ("movdqa %xmm4,%xmm1");
+     705             : 
+     706     3328640 :                 asm volatile ("movdqa %xmm4,%xmm5");
+     707     3328640 :                 asm volatile ("psrlw  $4,%xmm5");
+     708     3328640 :                 asm volatile ("pand   %xmm7,%xmm4");
+     709     3328640 :                 asm volatile ("pand   %xmm7,%xmm5");
+     710             : 
+     711     3328640 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+     712     3328640 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][0][1][0]));
+     713     3328640 :                 asm volatile ("pshufb %xmm4,%xmm2");
+     714     3328640 :                 asm volatile ("pshufb %xmm5,%xmm7");
+     715     3328640 :                 asm volatile ("pxor   %xmm7,%xmm2");
+     716             : 
+     717     3328640 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][1][0][0]));
+     718     3328640 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][1][1][0]));
+     719     3328640 :                 asm volatile ("pshufb %xmm4,%xmm3");
+     720     3328640 :                 asm volatile ("pshufb %xmm5,%xmm7");
+     721     3328640 :                 asm volatile ("pxor   %xmm7,%xmm3");
+     722             : 
+     723             :                 /* intermediate disks */
+     724    19935680 :                 for (d = l - 1; d > 0; --d) {
+     725    16607040 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+     726    16607040 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     727             : 
+     728    16607040 :                         asm volatile ("pxor %xmm5,%xmm5");
+     729    16607040 :                         asm volatile ("pcmpgtb %xmm1,%xmm5");
+     730    16607040 :                         asm volatile ("paddb %xmm1,%xmm1");
+     731    16607040 :                         asm volatile ("pand %xmm7,%xmm5");
+     732    16607040 :                         asm volatile ("pxor %xmm5,%xmm1");
+     733             : 
+     734    16607040 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+     735             : 
+     736    16607040 :                         asm volatile ("pxor %xmm4,%xmm0");
+     737    16607040 :                         asm volatile ("pxor %xmm4,%xmm1");
+     738             : 
+     739    16607040 :                         asm volatile ("movdqa %xmm4,%xmm5");
+     740    16607040 :                         asm volatile ("psrlw  $4,%xmm5");
+     741    16607040 :                         asm volatile ("pand   %xmm7,%xmm4");
+     742    16607040 :                         asm volatile ("pand   %xmm7,%xmm5");
+     743             : 
+     744    16607040 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+     745    16607040 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][0][1][0]));
+     746    16607040 :                         asm volatile ("pshufb %xmm4,%xmm6");
+     747    16607040 :                         asm volatile ("pshufb %xmm5,%xmm7");
+     748    16607040 :                         asm volatile ("pxor   %xmm6,%xmm2");
+     749    16607040 :                         asm volatile ("pxor   %xmm7,%xmm2");
+     750             : 
+     751    16607040 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][1][0][0]));
+     752    16607040 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][1][1][0]));
+     753    16607040 :                         asm volatile ("pshufb %xmm4,%xmm6");
+     754    16607040 :                         asm volatile ("pshufb %xmm5,%xmm7");
+     755    16607040 :                         asm volatile ("pxor   %xmm6,%xmm3");
+     756    16607040 :                         asm volatile ("pxor   %xmm7,%xmm3");
+     757             :                 }
+     758             : 
+     759             :                 /* first disk with all coefficients at 1 */
+     760     3328640 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+     761     3328640 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+     762             : 
+     763     3328640 :                 asm volatile ("pxor %xmm5,%xmm5");
+     764     3328640 :                 asm volatile ("pcmpgtb %xmm1,%xmm5");
+     765     3328640 :                 asm volatile ("paddb %xmm1,%xmm1");
+     766     3328640 :                 asm volatile ("pand %xmm7,%xmm5");
+     767     3328640 :                 asm volatile ("pxor %xmm5,%xmm1");
+     768             : 
+     769     3328640 :                 asm volatile ("pxor %xmm4,%xmm0");
+     770     3328640 :                 asm volatile ("pxor %xmm4,%xmm1");
+     771     3328640 :                 asm volatile ("pxor %xmm4,%xmm2");
+     772     3328640 :                 asm volatile ("pxor %xmm4,%xmm3");
+     773             : 
+     774     3328640 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     775     3328640 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+     776     3328640 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+     777     3328640 :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (s[i]));
+     778             :         }
+     779             : 
+     780             :         raid_sse_end();
+     781             : }
+     782             : #endif
+     783             : 
+     784             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSSE3)
+     785             : /*
+     786             :  * GEN4 (quad parity with Cauchy matrix) SSSE3 implementation
+     787             :  *
+     788             :  * Note that it uses 16 registers, meaning that x64 is required.
+     789             :  */
+     790             : void raid_gen4_ssse3ext(int nd, size_t size, void **vv)
+     791             : {
+     792             :         uint8_t **v = (uint8_t **)vv;
+     793             :         uint8_t *p;
+     794             :         uint8_t *q;
+     795             :         uint8_t *r;
+     796             :         uint8_t *s;
+     797             :         int d, l;
+     798             :         size_t i;
+     799             : 
+     800             :         l = nd - 1;
+     801             :         p = v[nd];
+     802             :         q = v[nd + 1];
+     803             :         r = v[nd + 2];
+     804             :         s = v[nd + 3];
+     805             : 
+     806             :         /* special case with only one data disk */
+     807             :         if (l == 0) {
+     808             :                 for (i = 0; i < 4; ++i)
+     809             :                         memcpy(v[1 + i], v[0], size);
+     810             :                 return;
+     811             :         }
+     812             : 
+     813             :         raid_sse_begin();
+     814             : 
+     815             :         /* generic case with at least two data disks */
+     816             :         for (i = 0; i < size; i += 32) {
+     817             :                 /* last disk without the by two multiplication */
+     818             :                 asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0]));
+     819             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+     820             :                 asm volatile ("movdqa %0,%%xmm12" : : "m" (v[l][i + 16]));
+     821             : 
+     822             :                 asm volatile ("movdqa %xmm4,%xmm0");
+     823             :                 asm volatile ("movdqa %xmm4,%xmm1");
+     824             :                 asm volatile ("movdqa %xmm12,%xmm8");
+     825             :                 asm volatile ("movdqa %xmm12,%xmm9");
+     826             : 
+     827             :                 asm volatile ("movdqa %xmm4,%xmm5");
+     828             :                 asm volatile ("movdqa %xmm12,%xmm13");
+     829             :                 asm volatile ("psrlw  $4,%xmm5");
+     830             :                 asm volatile ("psrlw  $4,%xmm13");
+     831             :                 asm volatile ("pand   %xmm15,%xmm4");
+     832             :                 asm volatile ("pand   %xmm15,%xmm12");
+     833             :                 asm volatile ("pand   %xmm15,%xmm5");
+     834             :                 asm volatile ("pand   %xmm15,%xmm13");
+     835             : 
+     836             :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+     837             :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][0][1][0]));
+     838             :                 asm volatile ("movdqa %xmm2,%xmm10");
+     839             :                 asm volatile ("movdqa %xmm7,%xmm15");
+     840             :                 asm volatile ("pshufb %xmm4,%xmm2");
+     841             :                 asm volatile ("pshufb %xmm12,%xmm10");
+     842             :                 asm volatile ("pshufb %xmm5,%xmm7");
+     843             :                 asm volatile ("pshufb %xmm13,%xmm15");
+     844             :                 asm volatile ("pxor   %xmm7,%xmm2");
+     845             :                 asm volatile ("pxor   %xmm15,%xmm10");
+     846             : 
+     847             :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][1][0][0]));
+     848             :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][1][1][0]));
+     849             :                 asm volatile ("movdqa %xmm3,%xmm11");
+     850             :                 asm volatile ("movdqa %xmm7,%xmm15");
+     851             :                 asm volatile ("pshufb %xmm4,%xmm3");
+     852             :                 asm volatile ("pshufb %xmm12,%xmm11");
+     853             :                 asm volatile ("pshufb %xmm5,%xmm7");
+     854             :                 asm volatile ("pshufb %xmm13,%xmm15");
+     855             :                 asm volatile ("pxor   %xmm7,%xmm3");
+     856             :                 asm volatile ("pxor   %xmm15,%xmm11");
+     857             : 
+     858             :                 /* intermediate disks */
+     859             :                 for (d = l - 1; d > 0; --d) {
+     860             :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+     861             :                         asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0]));
+     862             :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     863             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (v[d][i + 16]));
+     864             : 
+     865             :                         asm volatile ("pxor %xmm5,%xmm5");
+     866             :                         asm volatile ("pxor %xmm13,%xmm13");
+     867             :                         asm volatile ("pcmpgtb %xmm1,%xmm5");
+     868             :                         asm volatile ("pcmpgtb %xmm9,%xmm13");
+     869             :                         asm volatile ("paddb %xmm1,%xmm1");
+     870             :                         asm volatile ("paddb %xmm9,%xmm9");
+     871             :                         asm volatile ("pand %xmm7,%xmm5");
+     872             :                         asm volatile ("pand %xmm7,%xmm13");
+     873             :                         asm volatile ("pxor %xmm5,%xmm1");
+     874             :                         asm volatile ("pxor %xmm13,%xmm9");
+     875             : 
+     876             :                         asm volatile ("pxor %xmm4,%xmm0");
+     877             :                         asm volatile ("pxor %xmm4,%xmm1");
+     878             :                         asm volatile ("pxor %xmm12,%xmm8");
+     879             :                         asm volatile ("pxor %xmm12,%xmm9");
+     880             : 
+     881             :                         asm volatile ("movdqa %xmm4,%xmm5");
+     882             :                         asm volatile ("movdqa %xmm12,%xmm13");
+     883             :                         asm volatile ("psrlw  $4,%xmm5");
+     884             :                         asm volatile ("psrlw  $4,%xmm13");
+     885             :                         asm volatile ("pand   %xmm15,%xmm4");
+     886             :                         asm volatile ("pand   %xmm15,%xmm12");
+     887             :                         asm volatile ("pand   %xmm15,%xmm5");
+     888             :                         asm volatile ("pand   %xmm15,%xmm13");
+     889             : 
+     890             :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+     891             :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][0][1][0]));
+     892             :                         asm volatile ("movdqa %xmm6,%xmm14");
+     893             :                         asm volatile ("movdqa %xmm7,%xmm15");
+     894             :                         asm volatile ("pshufb %xmm4,%xmm6");
+     895             :                         asm volatile ("pshufb %xmm12,%xmm14");
+     896             :                         asm volatile ("pshufb %xmm5,%xmm7");
+     897             :                         asm volatile ("pshufb %xmm13,%xmm15");
+     898             :                         asm volatile ("pxor   %xmm6,%xmm2");
+     899             :                         asm volatile ("pxor   %xmm14,%xmm10");
+     900             :                         asm volatile ("pxor   %xmm7,%xmm2");
+     901             :                         asm volatile ("pxor   %xmm15,%xmm10");
+     902             : 
+     903             :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][1][0][0]));
+     904             :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][1][1][0]));
+     905             :                         asm volatile ("movdqa %xmm6,%xmm14");
+     906             :                         asm volatile ("movdqa %xmm7,%xmm15");
+     907             :                         asm volatile ("pshufb %xmm4,%xmm6");
+     908             :                         asm volatile ("pshufb %xmm12,%xmm14");
+     909             :                         asm volatile ("pshufb %xmm5,%xmm7");
+     910             :                         asm volatile ("pshufb %xmm13,%xmm15");
+     911             :                         asm volatile ("pxor   %xmm6,%xmm3");
+     912             :                         asm volatile ("pxor   %xmm14,%xmm11");
+     913             :                         asm volatile ("pxor   %xmm7,%xmm3");
+     914             :                         asm volatile ("pxor   %xmm15,%xmm11");
+     915             :                 }
+     916             : 
+     917             :                 /* first disk with all coefficients at 1 */
+     918             :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+     919             :                 asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0]));
+     920             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+     921             :                 asm volatile ("movdqa %0,%%xmm12" : : "m" (v[0][i + 16]));
+     922             : 
+     923             :                 asm volatile ("pxor %xmm5,%xmm5");
+     924             :                 asm volatile ("pxor %xmm13,%xmm13");
+     925             :                 asm volatile ("pcmpgtb %xmm1,%xmm5");
+     926             :                 asm volatile ("pcmpgtb %xmm9,%xmm13");
+     927             :                 asm volatile ("paddb %xmm1,%xmm1");
+     928             :                 asm volatile ("paddb %xmm9,%xmm9");
+     929             :                 asm volatile ("pand %xmm7,%xmm5");
+     930             :                 asm volatile ("pand %xmm7,%xmm13");
+     931             :                 asm volatile ("pxor %xmm5,%xmm1");
+     932             :                 asm volatile ("pxor %xmm13,%xmm9");
+     933             : 
+     934             :                 asm volatile ("pxor %xmm4,%xmm0");
+     935             :                 asm volatile ("pxor %xmm4,%xmm1");
+     936             :                 asm volatile ("pxor %xmm4,%xmm2");
+     937             :                 asm volatile ("pxor %xmm4,%xmm3");
+     938             :                 asm volatile ("pxor %xmm12,%xmm8");
+     939             :                 asm volatile ("pxor %xmm12,%xmm9");
+     940             :                 asm volatile ("pxor %xmm12,%xmm10");
+     941             :                 asm volatile ("pxor %xmm12,%xmm11");
+     942             : 
+     943             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     944             :                 asm volatile ("movntdq %%xmm8,%0" : "=m" (p[i + 16]));
+     945             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+     946             :                 asm volatile ("movntdq %%xmm9,%0" : "=m" (q[i + 16]));
+     947             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+     948             :                 asm volatile ("movntdq %%xmm10,%0" : "=m" (r[i + 16]));
+     949             :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (s[i]));
+     950             :                 asm volatile ("movntdq %%xmm11,%0" : "=m" (s[i + 16]));
+     951             :         }
+     952             : 
+     953             :         raid_sse_end();
+     954             : }
+     955             : #endif
+     956             : 
+     957             : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
+     958             : /*
+     959             :  * GEN4 (quad parity with Cauchy matrix) AVX2 implementation
+     960             :  *
+     961             :  * Note that it uses 16 registers, meaning that x64 is required.
+     962             :  */
+     963             : void raid_gen4_avx2ext(int nd, size_t size, void **vv)
+     964             : {
+     965             :         uint8_t **v = (uint8_t **)vv;
+     966             :         uint8_t *p;
+     967             :         uint8_t *q;
+     968             :         uint8_t *r;
+     969             :         uint8_t *s;
+     970             :         int d, l;
+     971             :         size_t i;
+     972             : 
+     973             :         l = nd - 1;
+     974             :         p = v[nd];
+     975             :         q = v[nd + 1];
+     976             :         r = v[nd + 2];
+     977             :         s = v[nd + 3];
+     978             : 
+     979             :         /* special case with only one data disk */
+     980             :         if (l == 0) {
+     981             :                 for (i = 0; i < 4; ++i)
+     982             :                         memcpy(v[1 + i], v[0], size);
+     983             :                 return;
+     984             :         }
+     985             : 
+     986             :         raid_avx_begin();
+     987             : 
+     988             :         /* generic case with at least two data disks */
+     989             :         for (i = 0; i < size; i += 64) {
+     990             :                 /* last disk without the by two multiplication */
+     991             :                 asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfconst16.low4[0]));
+     992             :                 asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[l][i]));
+     993             :                 asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[l][i + 32]));
+     994             : 
+     995             :                 asm volatile ("vmovdqa %ymm4,%ymm0");
+     996             :                 asm volatile ("vmovdqa %ymm4,%ymm1");
+     997             :                 asm volatile ("vmovdqa %ymm12,%ymm8");
+     998             :                 asm volatile ("vmovdqa %ymm12,%ymm9");
+     999             : 
+    1000             :                 asm volatile ("vpsrlw  $4,%ymm4,%ymm5");
+    1001             :                 asm volatile ("vpsrlw  $4,%ymm12,%ymm13");
+    1002             :                 asm volatile ("vpand   %ymm15,%ymm4,%ymm4");
+    1003             :                 asm volatile ("vpand   %ymm15,%ymm12,%ymm12");
+    1004             :                 asm volatile ("vpand   %ymm15,%ymm5,%ymm5");
+    1005             :                 asm volatile ("vpand   %ymm15,%ymm13,%ymm13");
+    1006             : 
+    1007             :                 asm volatile ("vbroadcasti128 %0,%%ymm10" : : "m" (gfgenpshufb[l][0][0][0]));
+    1008             :                 asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[l][0][1][0]));
+    1009             :                 asm volatile ("vpshufb %ymm4,%ymm10,%ymm2");
+    1010             :                 asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+    1011             :                 asm volatile ("vpshufb %ymm12,%ymm10,%ymm10");
+    1012             :                 asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+    1013             :                 asm volatile ("vpxor   %ymm7,%ymm2,%ymm2");
+    1014             :                 asm volatile ("vpxor   %ymm15,%ymm10,%ymm10");
+    1015             : 
+    1016             :                 asm volatile ("vbroadcasti128 %0,%%ymm11" : : "m" (gfgenpshufb[l][1][0][0]));
+    1017             :                 asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[l][1][1][0]));
+    1018             :                 asm volatile ("vpshufb %ymm4,%ymm11,%ymm3");
+    1019             :                 asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+    1020             :                 asm volatile ("vpshufb %ymm12,%ymm11,%ymm11");
+    1021             :                 asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+    1022             :                 asm volatile ("vpxor   %ymm7,%ymm3,%ymm3");
+    1023             :                 asm volatile ("vpxor   %ymm15,%ymm11,%ymm11");
+    1024             : 
+    1025             :                 /* intermediate disks */
+    1026             :                 for (d = l - 1; d > 0; --d) {
+    1027             :                         asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfconst16.poly[0]));
+    1028             :                         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfconst16.low4[0]));
+    1029             :                         asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[d][i]));
+    1030             :                         asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[d][i + 32]));
+    1031             : 
+    1032             :                         asm volatile ("vpxor %ymm5,%ymm5,%ymm5");
+    1033             :                         asm volatile ("vpxor %ymm13,%ymm13,%ymm13");
+    1034             :                         asm volatile ("vpcmpgtb %ymm1,%ymm5,%ymm5");
+    1035             :                         asm volatile ("vpcmpgtb %ymm9,%ymm13,%ymm13");
+    1036             :                         asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1037             :                         asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
+    1038             :                         asm volatile ("vpand %ymm7,%ymm5,%ymm5");
+    1039             :                         asm volatile ("vpand %ymm7,%ymm13,%ymm13");
+    1040             :                         asm volatile ("vpxor %ymm5,%ymm1,%ymm1");
+    1041             :                         asm volatile ("vpxor %ymm13,%ymm9,%ymm9");
+    1042             : 
+    1043             :                         asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+    1044             :                         asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+    1045             :                         asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
+    1046             :                         asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+    1047             : 
+    1048             :                         asm volatile ("vpsrlw  $4,%ymm4,%ymm5");
+    1049             :                         asm volatile ("vpsrlw  $4,%ymm12,%ymm13");
+    1050             :                         asm volatile ("vpand   %ymm15,%ymm4,%ymm4");
+    1051             :                         asm volatile ("vpand   %ymm15,%ymm12,%ymm12");
+    1052             :                         asm volatile ("vpand   %ymm15,%ymm5,%ymm5");
+    1053             :                         asm volatile ("vpand   %ymm15,%ymm13,%ymm13");
+    1054             : 
+    1055             :                         asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (gfgenpshufb[d][0][0][0]));
+    1056             :                         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[d][0][1][0]));
+    1057             :                         asm volatile ("vpshufb %ymm4,%ymm14,%ymm6");
+    1058             :                         asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+    1059             :                         asm volatile ("vpshufb %ymm12,%ymm14,%ymm14");
+    1060             :                         asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+    1061             :                         asm volatile ("vpxor   %ymm6,%ymm2,%ymm2");
+    1062             :                         asm volatile ("vpxor   %ymm14,%ymm10,%ymm10");
+    1063             :                         asm volatile ("vpxor   %ymm7,%ymm2,%ymm2");
+    1064             :                         asm volatile ("vpxor   %ymm15,%ymm10,%ymm10");
+    1065             : 
+    1066             :                         asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (gfgenpshufb[d][1][0][0]));
+    1067             :                         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfgenpshufb[d][1][1][0]));
+    1068             :                         asm volatile ("vpshufb %ymm4,%ymm14,%ymm6");
+    1069             :                         asm volatile ("vpshufb %ymm5,%ymm15,%ymm7");
+    1070             :                         asm volatile ("vpshufb %ymm12,%ymm14,%ymm14");
+    1071             :                         asm volatile ("vpshufb %ymm13,%ymm15,%ymm15");
+    1072             :                         asm volatile ("vpxor   %ymm6,%ymm3,%ymm3");
+    1073             :                         asm volatile ("vpxor   %ymm14,%ymm11,%ymm11");
+    1074             :                         asm volatile ("vpxor   %ymm7,%ymm3,%ymm3");
+    1075             :                         asm volatile ("vpxor   %ymm15,%ymm11,%ymm11");
+    1076             :                 }
+    1077             : 
+    1078             :                 /* first disk with all coefficients at 1 */
+    1079             :                 asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfconst16.poly[0]));
+    1080             :                 asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfconst16.low4[0]));
+    1081             :                 asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[0][i]));
+    1082             :                 asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[0][i + 32]));
+    1083             : 
+    1084             :                 asm volatile ("vpxor %ymm5,%ymm5,%ymm5");
+    1085             :                 asm volatile ("vpxor %ymm13,%ymm13,%ymm13");
+    1086             :                 asm volatile ("vpcmpgtb %ymm1,%ymm5,%ymm5");
+    1087             :                 asm volatile ("vpcmpgtb %ymm9,%ymm13,%ymm13");
+    1088             :                 asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1089             :                 asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
+    1090             :                 asm volatile ("vpand %ymm7,%ymm5,%ymm5");
+    1091             :                 asm volatile ("vpand %ymm7,%ymm13,%ymm13");
+    1092             :                 asm volatile ("vpxor %ymm5,%ymm1,%ymm1");
+    1093             :                 asm volatile ("vpxor %ymm13,%ymm9,%ymm9");
+    1094             : 
+    1095             :                 asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+    1096             :                 asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+    1097             :                 asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
+    1098             :                 asm volatile ("vpxor %ymm4,%ymm3,%ymm3");
+    1099             :                 asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
+    1100             :                 asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+    1101             :                 asm volatile ("vpxor %ymm12,%ymm10,%ymm10");
+    1102             :                 asm volatile ("vpxor %ymm12,%ymm11,%ymm11");
+    1103             : 
+    1104             :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+    1105             :                 asm volatile ("vmovntdq %%ymm8,%0" : "=m" (p[i + 32]));
+    1106             :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
+    1107             :                 asm volatile ("vmovntdq %%ymm9,%0" : "=m" (q[i + 32]));
+    1108             :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
+    1109             :                 asm volatile ("vmovntdq %%ymm10,%0" : "=m" (r[i + 32]));
+    1110             :                 asm volatile ("vmovntdq %%ymm3,%0" : "=m" (s[i]));
+    1111             :                 asm volatile ("vmovntdq %%ymm11,%0" : "=m" (s[i + 32]));
+    1112             :         }
+    1113             : 
+    1114             :         raid_avx_end();
+    1115             : }
+    1116             : #endif
+    1117             : 
+    1118             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+    1119             : /*
+    1120             :  * GEN5 (penta parity with Cauchy matrix) SSSE3 implementation
+    1121             :  */
+    1122       50252 : void raid_gen5_ssse3(int nd, size_t size, void **vv)
+    1123             : {
+    1124       50252 :         uint8_t **v = (uint8_t **)vv;
+    1125             :         uint8_t *p;
+    1126             :         uint8_t *q;
+    1127             :         uint8_t *r;
+    1128             :         uint8_t *s;
+    1129             :         uint8_t *t;
+    1130             :         int d, l;
+    1131             :         size_t i;
+    1132             :         uint8_t buffer[16+16];
+    1133       50252 :         uint8_t *pd = __align_ptr(buffer, 16);
+    1134             : 
+    1135       50252 :         l = nd - 1;
+    1136       50252 :         p = v[nd];
+    1137       50252 :         q = v[nd + 1];
+    1138       50252 :         r = v[nd + 2];
+    1139       50252 :         s = v[nd + 3];
+    1140       50252 :         t = v[nd + 4];
+    1141             : 
+    1142             :         /* special case with only one data disk */
+    1143       50252 :         if (l == 0) {
+    1144           6 :                 for (i = 0; i < 5; ++i)
+    1145           5 :                         memcpy(v[1 + i], v[0], size);
+    1146       50253 :                 return;
+    1147             :         }
+    1148             : 
+    1149             :         raid_sse_begin();
+    1150             : 
+    1151             :         /* generic case with at least two data disks */
+    1152     3927707 :         for (i = 0; i < size; i += 16) {
+    1153             :                 /* last disk without the by two multiplication */
+    1154     3877456 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+    1155             : 
+    1156     3877456 :                 asm volatile ("movdqa %xmm4,%xmm0");
+    1157     3877456 :                 asm volatile ("movdqa %%xmm4,%0" : "=m" (pd[0]));
+    1158             : 
+    1159     3877456 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    1160     3877456 :                 asm volatile ("movdqa %xmm4,%xmm5");
+    1161     3877456 :                 asm volatile ("psrlw  $4,%xmm5");
+    1162     3877456 :                 asm volatile ("pand   %xmm7,%xmm4");
+    1163     3877456 :                 asm volatile ("pand   %xmm7,%xmm5");
+    1164             : 
+    1165     3877456 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (gfgenpshufb[l][0][0][0]));
+    1166     3877456 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][0][1][0]));
+    1167     3877456 :                 asm volatile ("pshufb %xmm4,%xmm1");
+    1168     3877456 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1169     3877456 :                 asm volatile ("pxor   %xmm7,%xmm1");
+    1170             : 
+    1171     3877456 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][1][0][0]));
+    1172     3877456 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][1][1][0]));
+    1173     3877456 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    1174     3877456 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1175     3877456 :                 asm volatile ("pxor   %xmm7,%xmm2");
+    1176             : 
+    1177     3877456 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][2][0][0]));
+    1178     3877456 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][2][1][0]));
+    1179     3877456 :                 asm volatile ("pshufb %xmm4,%xmm3");
+    1180     3877456 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1181     3877456 :                 asm volatile ("pxor   %xmm7,%xmm3");
+    1182             : 
+    1183             :                 /* intermediate disks */
+    1184    23249712 :                 for (d = l - 1; d > 0; --d) {
+    1185    19372256 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+    1186    19372256 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (pd[0]));
+    1187    19372256 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+    1188             : 
+    1189    19372256 :                         asm volatile ("pxor %xmm5,%xmm5");
+    1190    19372256 :                         asm volatile ("pcmpgtb %xmm0,%xmm5");
+    1191    19372256 :                         asm volatile ("paddb %xmm0,%xmm0");
+    1192    19372256 :                         asm volatile ("pand %xmm7,%xmm5");
+    1193    19372256 :                         asm volatile ("pxor %xmm5,%xmm0");
+    1194             : 
+    1195    19372256 :                         asm volatile ("pxor %xmm4,%xmm0");
+    1196    19372256 :                         asm volatile ("pxor %xmm4,%xmm6");
+    1197    19372256 :                         asm volatile ("movdqa %%xmm6,%0" : "=m" (pd[0]));
+    1198             : 
+    1199    19372256 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    1200    19372256 :                         asm volatile ("movdqa %xmm4,%xmm5");
+    1201    19372256 :                         asm volatile ("psrlw  $4,%xmm5");
+    1202    19372256 :                         asm volatile ("pand   %xmm7,%xmm4");
+    1203    19372256 :                         asm volatile ("pand   %xmm7,%xmm5");
+    1204             : 
+    1205    19372256 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+    1206    19372256 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][0][1][0]));
+    1207    19372256 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1208    19372256 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1209    19372256 :                         asm volatile ("pxor   %xmm6,%xmm1");
+    1210    19372256 :                         asm volatile ("pxor   %xmm7,%xmm1");
+    1211             : 
+    1212    19372256 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][1][0][0]));
+    1213    19372256 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][1][1][0]));
+    1214    19372256 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1215    19372256 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1216    19372256 :                         asm volatile ("pxor   %xmm6,%xmm2");
+    1217    19372256 :                         asm volatile ("pxor   %xmm7,%xmm2");
+    1218             : 
+    1219    19372256 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][2][0][0]));
+    1220    19372256 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][2][1][0]));
+    1221    19372256 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1222    19372256 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1223    19372256 :                         asm volatile ("pxor   %xmm6,%xmm3");
+    1224    19372256 :                         asm volatile ("pxor   %xmm7,%xmm3");
+    1225             :                 }
+    1226             : 
+    1227             :                 /* first disk with all coefficients at 1 */
+    1228     3877456 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+    1229     3877456 :                 asm volatile ("movdqa %0,%%xmm6" : : "m" (pd[0]));
+    1230     3877456 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+    1231             : 
+    1232     3877456 :                 asm volatile ("pxor %xmm5,%xmm5");
+    1233     3877456 :                 asm volatile ("pcmpgtb %xmm0,%xmm5");
+    1234     3877456 :                 asm volatile ("paddb %xmm0,%xmm0");
+    1235     3877456 :                 asm volatile ("pand %xmm7,%xmm5");
+    1236     3877456 :                 asm volatile ("pxor %xmm5,%xmm0");
+    1237             : 
+    1238     3877456 :                 asm volatile ("pxor %xmm4,%xmm0");
+    1239     3877456 :                 asm volatile ("pxor %xmm4,%xmm1");
+    1240     3877456 :                 asm volatile ("pxor %xmm4,%xmm2");
+    1241     3877456 :                 asm volatile ("pxor %xmm4,%xmm3");
+    1242     3877456 :                 asm volatile ("pxor %xmm4,%xmm6");
+    1243             : 
+    1244     3877456 :                 asm volatile ("movntdq %%xmm6,%0" : "=m" (p[i]));
+    1245     3877456 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (q[i]));
+    1246     3877456 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (r[i]));
+    1247     3877456 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (s[i]));
+    1248     3877456 :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (t[i]));
+    1249             :         }
+    1250             : 
+    1251             :         raid_sse_end();
+    1252             : }
+    1253             : #endif
+    1254             : 
+    1255             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSSE3)
+    1256             : /*
+    1257             :  * GEN5 (penta parity with Cauchy matrix) SSSE3 implementation
+    1258             :  *
+    1259             :  * Note that it uses 16 registers, meaning that x64 is required.
+    1260             :  */
+    1261             : void raid_gen5_ssse3ext(int nd, size_t size, void **vv)
+    1262             : {
+    1263             :         uint8_t **v = (uint8_t **)vv;
+    1264             :         uint8_t *p;
+    1265             :         uint8_t *q;
+    1266             :         uint8_t *r;
+    1267             :         uint8_t *s;
+    1268             :         uint8_t *t;
+    1269             :         int d, l;
+    1270             :         size_t i;
+    1271             : 
+    1272             :         l = nd - 1;
+    1273             :         p = v[nd];
+    1274             :         q = v[nd + 1];
+    1275             :         r = v[nd + 2];
+    1276             :         s = v[nd + 3];
+    1277             :         t = v[nd + 4];
+    1278             : 
+    1279             :         /* special case with only one data disk */
+    1280             :         if (l == 0) {
+    1281             :                 for (i = 0; i < 5; ++i)
+    1282             :                         memcpy(v[1 + i], v[0], size);
+    1283             :                 return;
+    1284             :         }
+    1285             : 
+    1286             :         raid_sse_begin();
+    1287             : 
+    1288             :         /* generic case with at least two data disks */
+    1289             :         asm volatile ("movdqa %0,%%xmm14" : : "m" (gfconst16.poly[0]));
+    1290             :         asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0]));
+    1291             : 
+    1292             :         for (i = 0; i < size; i += 16) {
+    1293             :                 /* last disk without the by two multiplication */
+    1294             :                 asm volatile ("movdqa %0,%%xmm10" : : "m" (v[l][i]));
+    1295             : 
+    1296             :                 asm volatile ("movdqa %xmm10,%xmm0");
+    1297             :                 asm volatile ("movdqa %xmm10,%xmm1");
+    1298             : 
+    1299             :                 asm volatile ("movdqa %xmm10,%xmm11");
+    1300             :                 asm volatile ("psrlw  $4,%xmm11");
+    1301             :                 asm volatile ("pand   %xmm15,%xmm10");
+    1302             :                 asm volatile ("pand   %xmm15,%xmm11");
+    1303             : 
+    1304             :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+    1305             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][0][1][0]));
+    1306             :                 asm volatile ("pshufb %xmm10,%xmm2");
+    1307             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1308             :                 asm volatile ("pxor   %xmm13,%xmm2");
+    1309             : 
+    1310             :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][1][0][0]));
+    1311             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][1][1][0]));
+    1312             :                 asm volatile ("pshufb %xmm10,%xmm3");
+    1313             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1314             :                 asm volatile ("pxor   %xmm13,%xmm3");
+    1315             : 
+    1316             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (gfgenpshufb[l][2][0][0]));
+    1317             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][2][1][0]));
+    1318             :                 asm volatile ("pshufb %xmm10,%xmm4");
+    1319             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1320             :                 asm volatile ("pxor   %xmm13,%xmm4");
+    1321             : 
+    1322             :                 /* intermediate disks */
+    1323             :                 for (d = l - 1; d > 0; --d) {
+    1324             :                         asm volatile ("movdqa %0,%%xmm10" : : "m" (v[d][i]));
+    1325             : 
+    1326             :                         asm volatile ("pxor %xmm11,%xmm11");
+    1327             :                         asm volatile ("pcmpgtb %xmm1,%xmm11");
+    1328             :                         asm volatile ("paddb %xmm1,%xmm1");
+    1329             :                         asm volatile ("pand %xmm14,%xmm11");
+    1330             :                         asm volatile ("pxor %xmm11,%xmm1");
+    1331             : 
+    1332             :                         asm volatile ("pxor %xmm10,%xmm0");
+    1333             :                         asm volatile ("pxor %xmm10,%xmm1");
+    1334             : 
+    1335             :                         asm volatile ("movdqa %xmm10,%xmm11");
+    1336             :                         asm volatile ("psrlw  $4,%xmm11");
+    1337             :                         asm volatile ("pand   %xmm15,%xmm10");
+    1338             :                         asm volatile ("pand   %xmm15,%xmm11");
+    1339             : 
+    1340             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][0][0][0]));
+    1341             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][0][1][0]));
+    1342             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1343             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1344             :                         asm volatile ("pxor   %xmm12,%xmm2");
+    1345             :                         asm volatile ("pxor   %xmm13,%xmm2");
+    1346             : 
+    1347             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][1][0][0]));
+    1348             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][1][1][0]));
+    1349             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1350             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1351             :                         asm volatile ("pxor   %xmm12,%xmm3");
+    1352             :                         asm volatile ("pxor   %xmm13,%xmm3");
+    1353             : 
+    1354             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][2][0][0]));
+    1355             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][2][1][0]));
+    1356             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1357             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1358             :                         asm volatile ("pxor   %xmm12,%xmm4");
+    1359             :                         asm volatile ("pxor   %xmm13,%xmm4");
+    1360             :                 }
+    1361             : 
+    1362             :                 /* first disk with all coefficients at 1 */
+    1363             :                 asm volatile ("movdqa %0,%%xmm10" : : "m" (v[0][i]));
+    1364             : 
+    1365             :                 asm volatile ("pxor %xmm11,%xmm11");
+    1366             :                 asm volatile ("pcmpgtb %xmm1,%xmm11");
+    1367             :                 asm volatile ("paddb %xmm1,%xmm1");
+    1368             :                 asm volatile ("pand %xmm14,%xmm11");
+    1369             :                 asm volatile ("pxor %xmm11,%xmm1");
+    1370             : 
+    1371             :                 asm volatile ("pxor %xmm10,%xmm0");
+    1372             :                 asm volatile ("pxor %xmm10,%xmm1");
+    1373             :                 asm volatile ("pxor %xmm10,%xmm2");
+    1374             :                 asm volatile ("pxor %xmm10,%xmm3");
+    1375             :                 asm volatile ("pxor %xmm10,%xmm4");
+    1376             : 
+    1377             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+    1378             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+    1379             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+    1380             :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (s[i]));
+    1381             :                 asm volatile ("movntdq %%xmm4,%0" : "=m" (t[i]));
+    1382             :         }
+    1383             : 
+    1384             :         raid_sse_end();
+    1385             : }
+    1386             : #endif
+    1387             : 
+    1388             : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
+    1389             : /*
+    1390             :  * GEN5 (penta parity with Cauchy matrix) AVX2 implementation
+    1391             :  *
+    1392             :  * Note that it uses 16 registers, meaning that x64 is required.
+    1393             :  */
+    1394             : void raid_gen5_avx2ext(int nd, size_t size, void **vv)
+    1395             : {
+    1396             :         uint8_t **v = (uint8_t **)vv;
+    1397             :         uint8_t *p;
+    1398             :         uint8_t *q;
+    1399             :         uint8_t *r;
+    1400             :         uint8_t *s;
+    1401             :         uint8_t *t;
+    1402             :         int d, l;
+    1403             :         size_t i;
+    1404             : 
+    1405             :         l = nd - 1;
+    1406             :         p = v[nd];
+    1407             :         q = v[nd + 1];
+    1408             :         r = v[nd + 2];
+    1409             :         s = v[nd + 3];
+    1410             :         t = v[nd + 4];
+    1411             : 
+    1412             :         /* special case with only one data disk */
+    1413             :         if (l == 0) {
+    1414             :                 for (i = 0; i < 5; ++i)
+    1415             :                         memcpy(v[1 + i], v[0], size);
+    1416             :                 return;
+    1417             :         }
+    1418             : 
+    1419             :         raid_avx_begin();
+    1420             : 
+    1421             :         /* generic case with at least two data disks */
+    1422             :         asm volatile ("vpxor %ymm8,%ymm8,%ymm8");
+    1423             :         asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (gfconst16.poly[0]));
+    1424             :         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfconst16.low4[0]));
+    1425             : 
+    1426             :         for (i = 0; i < size; i += 32) {
+    1427             :                 /* last disk without the by two multiplication */
+    1428             :                 asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[l][i]));
+    1429             : 
+    1430             :                 asm volatile ("vmovdqa %ymm10,%ymm0");
+    1431             :                 asm volatile ("vmovdqa %ymm10,%ymm1");
+    1432             : 
+    1433             :                 asm volatile ("vpsrlw  $4,%ymm10,%ymm11");
+    1434             :                 asm volatile ("vpand   %ymm15,%ymm10,%ymm10");
+    1435             :                 asm volatile ("vpand   %ymm15,%ymm11,%ymm11");
+    1436             : 
+    1437             :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfgenpshufb[l][0][0][0]));
+    1438             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][0][1][0]));
+    1439             :                 asm volatile ("vpshufb %ymm10,%ymm2,%ymm2");
+    1440             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1441             :                 asm volatile ("vpxor   %ymm13,%ymm2,%ymm2");
+    1442             : 
+    1443             :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfgenpshufb[l][1][0][0]));
+    1444             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][1][1][0]));
+    1445             :                 asm volatile ("vpshufb %ymm10,%ymm3,%ymm3");
+    1446             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1447             :                 asm volatile ("vpxor   %ymm13,%ymm3,%ymm3");
+    1448             : 
+    1449             :                 asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (gfgenpshufb[l][2][0][0]));
+    1450             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][2][1][0]));
+    1451             :                 asm volatile ("vpshufb %ymm10,%ymm4,%ymm4");
+    1452             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1453             :                 asm volatile ("vpxor   %ymm13,%ymm4,%ymm4");
+    1454             : 
+    1455             :                 /* intermediate disks */
+    1456             :                 for (d = l - 1; d > 0; --d) {
+    1457             :                         asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[d][i]));
+    1458             : 
+    1459             :                         asm volatile ("vpcmpgtb %ymm1,%ymm8,%ymm11");
+    1460             :                         asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1461             :                         asm volatile ("vpand %ymm14,%ymm11,%ymm11");
+    1462             :                         asm volatile ("vpxor %ymm11,%ymm1,%ymm1");
+    1463             : 
+    1464             :                         asm volatile ("vpxor %ymm10,%ymm0,%ymm0");
+    1465             :                         asm volatile ("vpxor %ymm10,%ymm1,%ymm1");
+    1466             : 
+    1467             :                         asm volatile ("vpsrlw  $4,%ymm10,%ymm11");
+    1468             :                         asm volatile ("vpand   %ymm15,%ymm10,%ymm10");
+    1469             :                         asm volatile ("vpand   %ymm15,%ymm11,%ymm11");
+    1470             : 
+    1471             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][0][0][0]));
+    1472             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][0][1][0]));
+    1473             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1474             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1475             :                         asm volatile ("vpxor   %ymm12,%ymm2,%ymm2");
+    1476             :                         asm volatile ("vpxor   %ymm13,%ymm2,%ymm2");
+    1477             : 
+    1478             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][1][0][0]));
+    1479             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][1][1][0]));
+    1480             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1481             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1482             :                         asm volatile ("vpxor   %ymm12,%ymm3,%ymm3");
+    1483             :                         asm volatile ("vpxor   %ymm13,%ymm3,%ymm3");
+    1484             : 
+    1485             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][2][0][0]));
+    1486             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][2][1][0]));
+    1487             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1488             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1489             :                         asm volatile ("vpxor   %ymm12,%ymm4,%ymm4");
+    1490             :                         asm volatile ("vpxor   %ymm13,%ymm4,%ymm4");
+    1491             :                 }
+    1492             : 
+    1493             :                 /* first disk with all coefficients at 1 */
+    1494             :                 asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[0][i]));
+    1495             : 
+    1496             :                 asm volatile ("vpcmpgtb %ymm1,%ymm8,%ymm11");
+    1497             :                 asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1498             :                 asm volatile ("vpand %ymm14,%ymm11,%ymm11");
+    1499             :                 asm volatile ("vpxor %ymm11,%ymm1,%ymm1");
+    1500             : 
+    1501             :                 asm volatile ("vpxor %ymm10,%ymm0,%ymm0");
+    1502             :                 asm volatile ("vpxor %ymm10,%ymm1,%ymm1");
+    1503             :                 asm volatile ("vpxor %ymm10,%ymm2,%ymm2");
+    1504             :                 asm volatile ("vpxor %ymm10,%ymm3,%ymm3");
+    1505             :                 asm volatile ("vpxor %ymm10,%ymm4,%ymm4");
+    1506             : 
+    1507             :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+    1508             :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
+    1509             :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
+    1510             :                 asm volatile ("vmovntdq %%ymm3,%0" : "=m" (s[i]));
+    1511             :                 asm volatile ("vmovntdq %%ymm4,%0" : "=m" (t[i]));
+    1512             :         }
+    1513             : 
+    1514             :         raid_avx_end();
+    1515             : }
+    1516             : #endif
+    1517             : 
+    1518             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+    1519             : /*
+    1520             :  * GEN6 (hexa parity with Cauchy matrix) SSSE3 implementation
+    1521             :  */
+    1522      533272 : void raid_gen6_ssse3(int nd, size_t size, void **vv)
+    1523             : {
+    1524      533272 :         uint8_t **v = (uint8_t **)vv;
+    1525             :         uint8_t *p;
+    1526             :         uint8_t *q;
+    1527             :         uint8_t *r;
+    1528             :         uint8_t *s;
+    1529             :         uint8_t *t;
+    1530             :         uint8_t *u;
+    1531             :         int d, l;
+    1532             :         size_t i;
+    1533             :         uint8_t buffer[2*16+16];
+    1534      533272 :         uint8_t *pd = __align_ptr(buffer, 16);
+    1535             : 
+    1536      533272 :         l = nd - 1;
+    1537      533272 :         p = v[nd];
+    1538      533272 :         q = v[nd + 1];
+    1539      533272 :         r = v[nd + 2];
+    1540      533272 :         s = v[nd + 3];
+    1541      533272 :         t = v[nd + 4];
+    1542      533272 :         u = v[nd + 5];
+    1543             : 
+    1544             :         /* special case with only one data disk */
+    1545      533272 :         if (l == 0) {
+    1546           7 :                 for (i = 0; i < 6; ++i)
+    1547           6 :                         memcpy(v[1 + i], v[0], size);
+    1548      533273 :                 return;
+    1549             :         }
+    1550             : 
+    1551             :         raid_sse_begin();
+    1552             : 
+    1553             :         /* generic case with at least two data disks */
+    1554    34072935 :         for (i = 0; i < size; i += 16) {
+    1555             :                 /* last disk without the by two multiplication */
+    1556    33539664 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[l][i]));
+    1557             : 
+    1558    33539664 :                 asm volatile ("movdqa %%xmm4,%0" : "=m" (pd[0]));
+    1559    33539664 :                 asm volatile ("movdqa %%xmm4,%0" : "=m" (pd[16]));
+    1560             : 
+    1561    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    1562    33539664 :                 asm volatile ("movdqa %xmm4,%xmm5");
+    1563    33539664 :                 asm volatile ("psrlw  $4,%xmm5");
+    1564    33539664 :                 asm volatile ("pand   %xmm7,%xmm4");
+    1565    33539664 :                 asm volatile ("pand   %xmm7,%xmm5");
+    1566             : 
+    1567    33539664 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (gfgenpshufb[l][0][0][0]));
+    1568    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][0][1][0]));
+    1569    33539664 :                 asm volatile ("pshufb %xmm4,%xmm0");
+    1570    33539664 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1571    33539664 :                 asm volatile ("pxor   %xmm7,%xmm0");
+    1572             : 
+    1573    33539664 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (gfgenpshufb[l][1][0][0]));
+    1574    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][1][1][0]));
+    1575    33539664 :                 asm volatile ("pshufb %xmm4,%xmm1");
+    1576    33539664 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1577    33539664 :                 asm volatile ("pxor   %xmm7,%xmm1");
+    1578             : 
+    1579    33539664 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][2][0][0]));
+    1580    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][2][1][0]));
+    1581    33539664 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    1582    33539664 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1583    33539664 :                 asm volatile ("pxor   %xmm7,%xmm2");
+    1584             : 
+    1585    33539664 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][3][0][0]));
+    1586    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[l][3][1][0]));
+    1587    33539664 :                 asm volatile ("pshufb %xmm4,%xmm3");
+    1588    33539664 :                 asm volatile ("pshufb %xmm5,%xmm7");
+    1589    33539664 :                 asm volatile ("pxor   %xmm7,%xmm3");
+    1590             : 
+    1591             :                 /* intermediate disks */
+    1592   173670448 :                 for (d = l - 1; d > 0; --d) {
+    1593   140130784 :                         asm volatile ("movdqa %0,%%xmm5" : : "m" (pd[0]));
+    1594   140130784 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (pd[16]));
+    1595   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+    1596             : 
+    1597   140130784 :                         asm volatile ("pxor %xmm4,%xmm4");
+    1598   140130784 :                         asm volatile ("pcmpgtb %xmm6,%xmm4");
+    1599   140130784 :                         asm volatile ("paddb %xmm6,%xmm6");
+    1600   140130784 :                         asm volatile ("pand %xmm7,%xmm4");
+    1601   140130784 :                         asm volatile ("pxor %xmm4,%xmm6");
+    1602             : 
+    1603   140130784 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+    1604             : 
+    1605   140130784 :                         asm volatile ("pxor %xmm4,%xmm5");
+    1606   140130784 :                         asm volatile ("pxor %xmm4,%xmm6");
+    1607   140130784 :                         asm volatile ("movdqa %%xmm5,%0" : "=m" (pd[0]));
+    1608   140130784 :                         asm volatile ("movdqa %%xmm6,%0" : "=m" (pd[16]));
+    1609             : 
+    1610   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    1611   140130784 :                         asm volatile ("movdqa %xmm4,%xmm5");
+    1612   140130784 :                         asm volatile ("psrlw  $4,%xmm5");
+    1613   140130784 :                         asm volatile ("pand   %xmm7,%xmm4");
+    1614   140130784 :                         asm volatile ("pand   %xmm7,%xmm5");
+    1615             : 
+    1616   140130784 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][0][0][0]));
+    1617   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][0][1][0]));
+    1618   140130784 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1619   140130784 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1620   140130784 :                         asm volatile ("pxor   %xmm6,%xmm0");
+    1621   140130784 :                         asm volatile ("pxor   %xmm7,%xmm0");
+    1622             : 
+    1623   140130784 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][1][0][0]));
+    1624   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][1][1][0]));
+    1625   140130784 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1626   140130784 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1627   140130784 :                         asm volatile ("pxor   %xmm6,%xmm1");
+    1628   140130784 :                         asm volatile ("pxor   %xmm7,%xmm1");
+    1629             : 
+    1630   140130784 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][2][0][0]));
+    1631   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][2][1][0]));
+    1632   140130784 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1633   140130784 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1634   140130784 :                         asm volatile ("pxor   %xmm6,%xmm2");
+    1635   140130784 :                         asm volatile ("pxor   %xmm7,%xmm2");
+    1636             : 
+    1637   140130784 :                         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfgenpshufb[d][3][0][0]));
+    1638   140130784 :                         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfgenpshufb[d][3][1][0]));
+    1639   140130784 :                         asm volatile ("pshufb %xmm4,%xmm6");
+    1640   140130784 :                         asm volatile ("pshufb %xmm5,%xmm7");
+    1641   140130784 :                         asm volatile ("pxor   %xmm6,%xmm3");
+    1642   140130784 :                         asm volatile ("pxor   %xmm7,%xmm3");
+    1643             :                 }
+    1644             : 
+    1645             :                 /* first disk with all coefficients at 1 */
+    1646    33539664 :                 asm volatile ("movdqa %0,%%xmm5" : : "m" (pd[0]));
+    1647    33539664 :                 asm volatile ("movdqa %0,%%xmm6" : : "m" (pd[16]));
+    1648    33539664 :                 asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.poly[0]));
+    1649             : 
+    1650    33539664 :                 asm volatile ("pxor %xmm4,%xmm4");
+    1651    33539664 :                 asm volatile ("pcmpgtb %xmm6,%xmm4");
+    1652    33539664 :                 asm volatile ("paddb %xmm6,%xmm6");
+    1653    33539664 :                 asm volatile ("pand %xmm7,%xmm4");
+    1654    33539664 :                 asm volatile ("pxor %xmm4,%xmm6");
+    1655             : 
+    1656    33539664 :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (v[0][i]));
+    1657    33539664 :                 asm volatile ("pxor %xmm4,%xmm0");
+    1658    33539664 :                 asm volatile ("pxor %xmm4,%xmm1");
+    1659    33539664 :                 asm volatile ("pxor %xmm4,%xmm2");
+    1660    33539664 :                 asm volatile ("pxor %xmm4,%xmm3");
+    1661    33539664 :                 asm volatile ("pxor %xmm4,%xmm5");
+    1662    33539664 :                 asm volatile ("pxor %xmm4,%xmm6");
+    1663             : 
+    1664    33539664 :                 asm volatile ("movntdq %%xmm5,%0" : "=m" (p[i]));
+    1665    33539664 :                 asm volatile ("movntdq %%xmm6,%0" : "=m" (q[i]));
+    1666    33539664 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (r[i]));
+    1667    33539664 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (s[i]));
+    1668    33539664 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (t[i]));
+    1669    33539664 :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (u[i]));
+    1670             :         }
+    1671             : 
+    1672             :         raid_sse_end();
+    1673             : }
+    1674             : #endif
+    1675             : 
+    1676             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSSE3)
+    1677             : /*
+    1678             :  * GEN6 (hexa parity with Cauchy matrix) SSSE3 implementation
+    1679             :  *
+    1680             :  * Note that it uses 16 registers, meaning that x64 is required.
+    1681             :  */
+    1682             : void raid_gen6_ssse3ext(int nd, size_t size, void **vv)
+    1683             : {
+    1684             :         uint8_t **v = (uint8_t **)vv;
+    1685             :         uint8_t *p;
+    1686             :         uint8_t *q;
+    1687             :         uint8_t *r;
+    1688             :         uint8_t *s;
+    1689             :         uint8_t *t;
+    1690             :         uint8_t *u;
+    1691             :         int d, l;
+    1692             :         size_t i;
+    1693             : 
+    1694             :         l = nd - 1;
+    1695             :         p = v[nd];
+    1696             :         q = v[nd + 1];
+    1697             :         r = v[nd + 2];
+    1698             :         s = v[nd + 3];
+    1699             :         t = v[nd + 4];
+    1700             :         u = v[nd + 5];
+    1701             : 
+    1702             :         /* special case with only one data disk */
+    1703             :         if (l == 0) {
+    1704             :                 for (i = 0; i < 6; ++i)
+    1705             :                         memcpy(v[1 + i], v[0], size);
+    1706             :                 return;
+    1707             :         }
+    1708             : 
+    1709             :         raid_sse_begin();
+    1710             : 
+    1711             :         /* generic case with at least two data disks */
+    1712             :         asm volatile ("movdqa %0,%%xmm14" : : "m" (gfconst16.poly[0]));
+    1713             :         asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0]));
+    1714             : 
+    1715             :         for (i = 0; i < size; i += 16) {
+    1716             :                 /* last disk without the by two multiplication */
+    1717             :                 asm volatile ("movdqa %0,%%xmm10" : : "m" (v[l][i]));
+    1718             : 
+    1719             :                 asm volatile ("movdqa %xmm10,%xmm0");
+    1720             :                 asm volatile ("movdqa %xmm10,%xmm1");
+    1721             : 
+    1722             :                 asm volatile ("movdqa %xmm10,%xmm11");
+    1723             :                 asm volatile ("psrlw  $4,%xmm11");
+    1724             :                 asm volatile ("pand   %xmm15,%xmm10");
+    1725             :                 asm volatile ("pand   %xmm15,%xmm11");
+    1726             : 
+    1727             :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfgenpshufb[l][0][0][0]));
+    1728             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][0][1][0]));
+    1729             :                 asm volatile ("pshufb %xmm10,%xmm2");
+    1730             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1731             :                 asm volatile ("pxor   %xmm13,%xmm2");
+    1732             : 
+    1733             :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfgenpshufb[l][1][0][0]));
+    1734             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][1][1][0]));
+    1735             :                 asm volatile ("pshufb %xmm10,%xmm3");
+    1736             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1737             :                 asm volatile ("pxor   %xmm13,%xmm3");
+    1738             : 
+    1739             :                 asm volatile ("movdqa %0,%%xmm4" : : "m" (gfgenpshufb[l][2][0][0]));
+    1740             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][2][1][0]));
+    1741             :                 asm volatile ("pshufb %xmm10,%xmm4");
+    1742             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1743             :                 asm volatile ("pxor   %xmm13,%xmm4");
+    1744             : 
+    1745             :                 asm volatile ("movdqa %0,%%xmm5" : : "m" (gfgenpshufb[l][3][0][0]));
+    1746             :                 asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[l][3][1][0]));
+    1747             :                 asm volatile ("pshufb %xmm10,%xmm5");
+    1748             :                 asm volatile ("pshufb %xmm11,%xmm13");
+    1749             :                 asm volatile ("pxor   %xmm13,%xmm5");
+    1750             : 
+    1751             :                 /* intermediate disks */
+    1752             :                 for (d = l - 1; d > 0; --d) {
+    1753             :                         asm volatile ("movdqa %0,%%xmm10" : : "m" (v[d][i]));
+    1754             : 
+    1755             :                         asm volatile ("pxor %xmm11,%xmm11");
+    1756             :                         asm volatile ("pcmpgtb %xmm1,%xmm11");
+    1757             :                         asm volatile ("paddb %xmm1,%xmm1");
+    1758             :                         asm volatile ("pand %xmm14,%xmm11");
+    1759             :                         asm volatile ("pxor %xmm11,%xmm1");
+    1760             : 
+    1761             :                         asm volatile ("pxor %xmm10,%xmm0");
+    1762             :                         asm volatile ("pxor %xmm10,%xmm1");
+    1763             : 
+    1764             :                         asm volatile ("movdqa %xmm10,%xmm11");
+    1765             :                         asm volatile ("psrlw  $4,%xmm11");
+    1766             :                         asm volatile ("pand   %xmm15,%xmm10");
+    1767             :                         asm volatile ("pand   %xmm15,%xmm11");
+    1768             : 
+    1769             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][0][0][0]));
+    1770             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][0][1][0]));
+    1771             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1772             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1773             :                         asm volatile ("pxor   %xmm12,%xmm2");
+    1774             :                         asm volatile ("pxor   %xmm13,%xmm2");
+    1775             : 
+    1776             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][1][0][0]));
+    1777             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][1][1][0]));
+    1778             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1779             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1780             :                         asm volatile ("pxor   %xmm12,%xmm3");
+    1781             :                         asm volatile ("pxor   %xmm13,%xmm3");
+    1782             : 
+    1783             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][2][0][0]));
+    1784             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][2][1][0]));
+    1785             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1786             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1787             :                         asm volatile ("pxor   %xmm12,%xmm4");
+    1788             :                         asm volatile ("pxor   %xmm13,%xmm4");
+    1789             : 
+    1790             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (gfgenpshufb[d][3][0][0]));
+    1791             :                         asm volatile ("movdqa %0,%%xmm13" : : "m" (gfgenpshufb[d][3][1][0]));
+    1792             :                         asm volatile ("pshufb %xmm10,%xmm12");
+    1793             :                         asm volatile ("pshufb %xmm11,%xmm13");
+    1794             :                         asm volatile ("pxor   %xmm12,%xmm5");
+    1795             :                         asm volatile ("pxor   %xmm13,%xmm5");
+    1796             :                 }
+    1797             : 
+    1798             :                 /* first disk with all coefficients at 1 */
+    1799             :                 asm volatile ("movdqa %0,%%xmm10" : : "m" (v[0][i]));
+    1800             : 
+    1801             :                 asm volatile ("pxor %xmm11,%xmm11");
+    1802             :                 asm volatile ("pcmpgtb %xmm1,%xmm11");
+    1803             :                 asm volatile ("paddb %xmm1,%xmm1");
+    1804             :                 asm volatile ("pand %xmm14,%xmm11");
+    1805             :                 asm volatile ("pxor %xmm11,%xmm1");
+    1806             : 
+    1807             :                 asm volatile ("pxor %xmm10,%xmm0");
+    1808             :                 asm volatile ("pxor %xmm10,%xmm1");
+    1809             :                 asm volatile ("pxor %xmm10,%xmm2");
+    1810             :                 asm volatile ("pxor %xmm10,%xmm3");
+    1811             :                 asm volatile ("pxor %xmm10,%xmm4");
+    1812             :                 asm volatile ("pxor %xmm10,%xmm5");
+    1813             : 
+    1814             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+    1815             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+    1816             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+    1817             :                 asm volatile ("movntdq %%xmm3,%0" : "=m" (s[i]));
+    1818             :                 asm volatile ("movntdq %%xmm4,%0" : "=m" (t[i]));
+    1819             :                 asm volatile ("movntdq %%xmm5,%0" : "=m" (u[i]));
+    1820             :         }
+    1821             : 
+    1822             :         raid_sse_end();
+    1823             : }
+    1824             : #endif
+    1825             : 
+    1826             : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
+    1827             : /*
+    1828             :  * GEN6 (hexa parity with Cauchy matrix) AVX2 implementation
+    1829             :  *
+    1830             :  * Note that it uses 16 registers, meaning that x64 is required.
+    1831             :  */
+    1832             : void raid_gen6_avx2ext(int nd, size_t size, void **vv)
+    1833             : {
+    1834             :         uint8_t **v = (uint8_t **)vv;
+    1835             :         uint8_t *p;
+    1836             :         uint8_t *q;
+    1837             :         uint8_t *r;
+    1838             :         uint8_t *s;
+    1839             :         uint8_t *t;
+    1840             :         uint8_t *u;
+    1841             :         int d, l;
+    1842             :         size_t i;
+    1843             : 
+    1844             :         l = nd - 1;
+    1845             :         p = v[nd];
+    1846             :         q = v[nd + 1];
+    1847             :         r = v[nd + 2];
+    1848             :         s = v[nd + 3];
+    1849             :         t = v[nd + 4];
+    1850             :         u = v[nd + 5];
+    1851             : 
+    1852             :         /* special case with only one data disk */
+    1853             :         if (l == 0) {
+    1854             :                 for (i = 0; i < 6; ++i)
+    1855             :                         memcpy(v[1 + i], v[0], size);
+    1856             :                 return;
+    1857             :         }
+    1858             : 
+    1859             :         raid_avx_begin();
+    1860             : 
+    1861             :         /* generic case with at least two data disks */
+    1862             :         asm volatile ("vpxor %ymm8,%ymm8,%ymm8");
+    1863             :         asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (gfconst16.poly[0]));
+    1864             :         asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (gfconst16.low4[0]));
+    1865             : 
+    1866             :         for (i = 0; i < size; i += 32) {
+    1867             :                 /* last disk without the by two multiplication */
+    1868             :                 asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[l][i]));
+    1869             : 
+    1870             :                 asm volatile ("vmovdqa %ymm10,%ymm0");
+    1871             :                 asm volatile ("vmovdqa %ymm10,%ymm1");
+    1872             : 
+    1873             :                 asm volatile ("vpsrlw  $4,%ymm10,%ymm11");
+    1874             :                 asm volatile ("vpand   %ymm15,%ymm10,%ymm10");
+    1875             :                 asm volatile ("vpand   %ymm15,%ymm11,%ymm11");
+    1876             : 
+    1877             :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfgenpshufb[l][0][0][0]));
+    1878             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][0][1][0]));
+    1879             :                 asm volatile ("vpshufb %ymm10,%ymm2,%ymm2");
+    1880             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1881             :                 asm volatile ("vpxor   %ymm13,%ymm2,%ymm2");
+    1882             : 
+    1883             :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfgenpshufb[l][1][0][0]));
+    1884             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][1][1][0]));
+    1885             :                 asm volatile ("vpshufb %ymm10,%ymm3,%ymm3");
+    1886             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1887             :                 asm volatile ("vpxor   %ymm13,%ymm3,%ymm3");
+    1888             : 
+    1889             :                 asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (gfgenpshufb[l][2][0][0]));
+    1890             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][2][1][0]));
+    1891             :                 asm volatile ("vpshufb %ymm10,%ymm4,%ymm4");
+    1892             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1893             :                 asm volatile ("vpxor   %ymm13,%ymm4,%ymm4");
+    1894             : 
+    1895             :                 asm volatile ("vbroadcasti128 %0,%%ymm5" : : "m" (gfgenpshufb[l][3][0][0]));
+    1896             :                 asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[l][3][1][0]));
+    1897             :                 asm volatile ("vpshufb %ymm10,%ymm5,%ymm5");
+    1898             :                 asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1899             :                 asm volatile ("vpxor   %ymm13,%ymm5,%ymm5");
+    1900             : 
+    1901             :                 /* intermediate disks */
+    1902             :                 for (d = l - 1; d > 0; --d) {
+    1903             :                         asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[d][i]));
+    1904             : 
+    1905             :                         asm volatile ("vpcmpgtb %ymm1,%ymm8,%ymm11");
+    1906             :                         asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1907             :                         asm volatile ("vpand %ymm14,%ymm11,%ymm11");
+    1908             :                         asm volatile ("vpxor %ymm11,%ymm1,%ymm1");
+    1909             : 
+    1910             :                         asm volatile ("vpxor %ymm10,%ymm0,%ymm0");
+    1911             :                         asm volatile ("vpxor %ymm10,%ymm1,%ymm1");
+    1912             : 
+    1913             :                         asm volatile ("vpsrlw  $4,%ymm10,%ymm11");
+    1914             :                         asm volatile ("vpand   %ymm15,%ymm10,%ymm10");
+    1915             :                         asm volatile ("vpand   %ymm15,%ymm11,%ymm11");
+    1916             : 
+    1917             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][0][0][0]));
+    1918             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][0][1][0]));
+    1919             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1920             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1921             :                         asm volatile ("vpxor   %ymm12,%ymm2,%ymm2");
+    1922             :                         asm volatile ("vpxor   %ymm13,%ymm2,%ymm2");
+    1923             : 
+    1924             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][1][0][0]));
+    1925             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][1][1][0]));
+    1926             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1927             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1928             :                         asm volatile ("vpxor   %ymm12,%ymm3,%ymm3");
+    1929             :                         asm volatile ("vpxor   %ymm13,%ymm3,%ymm3");
+    1930             : 
+    1931             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][2][0][0]));
+    1932             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][2][1][0]));
+    1933             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1934             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1935             :                         asm volatile ("vpxor   %ymm12,%ymm4,%ymm4");
+    1936             :                         asm volatile ("vpxor   %ymm13,%ymm4,%ymm4");
+    1937             : 
+    1938             :                         asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (gfgenpshufb[d][3][0][0]));
+    1939             :                         asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (gfgenpshufb[d][3][1][0]));
+    1940             :                         asm volatile ("vpshufb %ymm10,%ymm12,%ymm12");
+    1941             :                         asm volatile ("vpshufb %ymm11,%ymm13,%ymm13");
+    1942             :                         asm volatile ("vpxor   %ymm12,%ymm5,%ymm5");
+    1943             :                         asm volatile ("vpxor   %ymm13,%ymm5,%ymm5");
+    1944             :                 }
+    1945             : 
+    1946             :                 /* first disk with all coefficients at 1 */
+    1947             :                 asm volatile ("vmovdqa %0,%%ymm10" : : "m" (v[0][i]));
+    1948             : 
+    1949             :                 asm volatile ("vpcmpgtb %ymm1,%ymm8,%ymm11");
+    1950             :                 asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+    1951             :                 asm volatile ("vpand %ymm14,%ymm11,%ymm11");
+    1952             :                 asm volatile ("vpxor %ymm11,%ymm1,%ymm1");
+    1953             : 
+    1954             :                 asm volatile ("vpxor %ymm10,%ymm0,%ymm0");
+    1955             :                 asm volatile ("vpxor %ymm10,%ymm1,%ymm1");
+    1956             :                 asm volatile ("vpxor %ymm10,%ymm2,%ymm2");
+    1957             :                 asm volatile ("vpxor %ymm10,%ymm3,%ymm3");
+    1958             :                 asm volatile ("vpxor %ymm10,%ymm4,%ymm4");
+    1959             :                 asm volatile ("vpxor %ymm10,%ymm5,%ymm5");
+    1960             : 
+    1961             :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+    1962             :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
+    1963             :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
+    1964             :                 asm volatile ("vmovntdq %%ymm3,%0" : "=m" (s[i]));
+    1965             :                 asm volatile ("vmovntdq %%ymm4,%0" : "=m" (t[i]));
+    1966             :                 asm volatile ("vmovntdq %%ymm5,%0" : "=m" (u[i]));
+    1967             :         }
+    1968             : 
+    1969             :         raid_avx_end();
+    1970             : }
+    1971             : #endif
+    1972             : 
+    1973             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+    1974             : /*
+    1975             :  * RAID recovering for one disk SSSE3 implementation
+    1976             :  */
+    1977      110047 : void raid_rec1_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    1978             : {
+    1979      110047 :         uint8_t **v = (uint8_t **)vv;
+    1980             :         uint8_t *p;
+    1981             :         uint8_t *pa;
+    1982             :         uint8_t G;
+    1983             :         uint8_t V;
+    1984             :         size_t i;
+    1985             : 
+    1986             :         (void)nr; /* unused, it's always 1 */
+    1987             : 
+    1988             :         /* if it's RAID5 uses the faster function */
+    1989      110047 :         if (ip[0] == 0) {
+    1990      100498 :                 raid_rec1of1(id, nd, size, vv);
+    1991      210545 :                 return;
+    1992             :         }
+    1993             : 
+    1994             :         /* setup the coefficients matrix */
+    1995       19098 :         G = A(ip[0], id[0]);
+    1996             : 
+    1997             :         /* invert it to solve the system of linear equations */
+    1998       19098 :         V = inv(G);
+    1999             : 
+    2000             :         /* compute delta parity */
+    2001        9549 :         raid_delta_gen(1, id, ip, nd, size, vv);
+    2002             : 
+    2003        9549 :         p = v[nd + ip[0]];
+    2004        9549 :         pa = v[id[0]];
+    2005             : 
+    2006             :         raid_sse_begin();
+    2007             : 
+    2008        9549 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    2009        9549 :         asm volatile ("movdqa %0,%%xmm4" : : "m" (gfmulpshufb[V][0][0]));
+    2010        9549 :         asm volatile ("movdqa %0,%%xmm5" : : "m" (gfmulpshufb[V][1][0]));
+    2011             : 
+    2012     1530573 :         for (i = 0; i < size; i += 16) {
+    2013     1521024 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (p[i]));
+    2014     1521024 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (pa[i]));
+    2015     1521024 :                 asm volatile ("movdqa %xmm4,%xmm2");
+    2016     1521024 :                 asm volatile ("movdqa %xmm5,%xmm3");
+    2017     1521024 :                 asm volatile ("pxor   %xmm0,%xmm1");
+    2018     1521024 :                 asm volatile ("movdqa %xmm1,%xmm0");
+    2019     1521024 :                 asm volatile ("psrlw  $4,%xmm1");
+    2020     1521024 :                 asm volatile ("pand   %xmm7,%xmm0");
+    2021     1521024 :                 asm volatile ("pand   %xmm7,%xmm1");
+    2022     1521024 :                 asm volatile ("pshufb %xmm0,%xmm2");
+    2023     1521024 :                 asm volatile ("pshufb %xmm1,%xmm3");
+    2024     1521024 :                 asm volatile ("pxor   %xmm3,%xmm2");
+    2025     1521024 :                 asm volatile ("movdqa %%xmm2,%0" : "=m" (pa[i]));
+    2026             :         }
+    2027             : 
+    2028             :         raid_sse_end();
+    2029             : }
+    2030             : #endif
+    2031             : 
+    2032             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+    2033             : /*
+    2034             :  * RAID recovering for two disks SSSE3 implementation
+    2035             :  */
+    2036       44029 : void raid_rec2_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    2037             : {
+    2038       44029 :         uint8_t **v = (uint8_t **)vv;
+    2039       44029 :         const int N = 2;
+    2040       44029 :         uint8_t *p[N];
+    2041       44029 :         uint8_t *pa[N];
+    2042       44029 :         uint8_t G[N * N];
+    2043       44029 :         uint8_t V[N * N];
+    2044             :         size_t i;
+    2045             :         int j, k;
+    2046             : 
+    2047             :         (void)nr; /* unused, it's always 2 */
+    2048             : 
+    2049             :         /* setup the coefficients matrix */
+    2050      132087 :         for (j = 0; j < N; ++j)
+    2051      264174 :                 for (k = 0; k < N; ++k)
+    2052      352232 :                         G[j * N + k] = A(ip[j], id[k]);
+    2053             : 
+    2054             :         /* invert it to solve the system of linear equations */
+    2055       44029 :         raid_invert(G, V, N);
+    2056             : 
+    2057             :         /* compute delta parity */
+    2058       44029 :         raid_delta_gen(N, id, ip, nd, size, vv);
+    2059             : 
+    2060      132087 :         for (j = 0; j < N; ++j) {
+    2061       88058 :                 p[j] = v[nd + ip[j]];
+    2062       88058 :                 pa[j] = v[id[j]];
+    2063             :         }
+    2064             : 
+    2065             :         raid_sse_begin();
+    2066             : 
+    2067       44029 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    2068             : 
+    2069     3588221 :         for (i = 0; i < size; i += 16) {
+    2070     3544192 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (p[0][i]));
+    2071     3544192 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (pa[0][i]));
+    2072     3544192 :                 asm volatile ("movdqa %0,%%xmm1" : : "m" (p[1][i]));
+    2073     3544192 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (pa[1][i]));
+    2074     3544192 :                 asm volatile ("pxor   %xmm2,%xmm0");
+    2075     3544192 :                 asm volatile ("pxor   %xmm3,%xmm1");
+    2076             : 
+    2077     3544192 :                 asm volatile ("pxor %xmm6,%xmm6");
+    2078             : 
+    2079     3544192 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfmulpshufb[V[0]][0][0]));
+    2080     3544192 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfmulpshufb[V[0]][1][0]));
+    2081     3544192 :                 asm volatile ("movdqa %xmm0,%xmm4");
+    2082     3544192 :                 asm volatile ("movdqa %xmm0,%xmm5");
+    2083     3544192 :                 asm volatile ("psrlw  $4,%xmm5");
+    2084     3544192 :                 asm volatile ("pand   %xmm7,%xmm4");
+    2085     3544192 :                 asm volatile ("pand   %xmm7,%xmm5");
+    2086     3544192 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    2087     3544192 :                 asm volatile ("pshufb %xmm5,%xmm3");
+    2088     3544192 :                 asm volatile ("pxor   %xmm2,%xmm6");
+    2089     3544192 :                 asm volatile ("pxor   %xmm3,%xmm6");
+    2090             : 
+    2091     3544192 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfmulpshufb[V[1]][0][0]));
+    2092     3544192 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfmulpshufb[V[1]][1][0]));
+    2093     3544192 :                 asm volatile ("movdqa %xmm1,%xmm4");
+    2094     3544192 :                 asm volatile ("movdqa %xmm1,%xmm5");
+    2095     3544192 :                 asm volatile ("psrlw  $4,%xmm5");
+    2096     3544192 :                 asm volatile ("pand   %xmm7,%xmm4");
+    2097     3544192 :                 asm volatile ("pand   %xmm7,%xmm5");
+    2098     3544192 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    2099     3544192 :                 asm volatile ("pshufb %xmm5,%xmm3");
+    2100     3544192 :                 asm volatile ("pxor   %xmm2,%xmm6");
+    2101     3544192 :                 asm volatile ("pxor   %xmm3,%xmm6");
+    2102             : 
+    2103     3544192 :                 asm volatile ("movdqa %%xmm6,%0" : "=m" (pa[0][i]));
+    2104             : 
+    2105     3544192 :                 asm volatile ("pxor %xmm6,%xmm6");
+    2106             : 
+    2107     3544192 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfmulpshufb[V[2]][0][0]));
+    2108     3544192 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfmulpshufb[V[2]][1][0]));
+    2109     3544192 :                 asm volatile ("movdqa %xmm0,%xmm4");
+    2110     3544192 :                 asm volatile ("movdqa %xmm0,%xmm5");
+    2111     3544192 :                 asm volatile ("psrlw  $4,%xmm5");
+    2112     3544192 :                 asm volatile ("pand   %xmm7,%xmm4");
+    2113     3544192 :                 asm volatile ("pand   %xmm7,%xmm5");
+    2114     3544192 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    2115     3544192 :                 asm volatile ("pshufb %xmm5,%xmm3");
+    2116     3544192 :                 asm volatile ("pxor   %xmm2,%xmm6");
+    2117     3544192 :                 asm volatile ("pxor   %xmm3,%xmm6");
+    2118             : 
+    2119     3544192 :                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfmulpshufb[V[3]][0][0]));
+    2120     3544192 :                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfmulpshufb[V[3]][1][0]));
+    2121     3544192 :                 asm volatile ("movdqa %xmm1,%xmm4");
+    2122     3544192 :                 asm volatile ("movdqa %xmm1,%xmm5");
+    2123     3544192 :                 asm volatile ("psrlw  $4,%xmm5");
+    2124     3544192 :                 asm volatile ("pand   %xmm7,%xmm4");
+    2125     3544192 :                 asm volatile ("pand   %xmm7,%xmm5");
+    2126     3544192 :                 asm volatile ("pshufb %xmm4,%xmm2");
+    2127     3544192 :                 asm volatile ("pshufb %xmm5,%xmm3");
+    2128     3544192 :                 asm volatile ("pxor   %xmm2,%xmm6");
+    2129     3544192 :                 asm volatile ("pxor   %xmm3,%xmm6");
+    2130             : 
+    2131     3544192 :                 asm volatile ("movdqa %%xmm6,%0" : "=m" (pa[1][i]));
+    2132             :         }
+    2133             : 
+    2134             :         raid_sse_end();
+    2135       44029 : }
+    2136             : #endif
+    2137             : 
+    2138             : #if defined(CONFIG_X86) && defined(CONFIG_SSSE3)
+    2139             : /*
+    2140             :  * RAID recovering SSSE3 implementation
+    2141             :  */
+    2142       79300 : void raid_recX_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    2143             : {
+    2144       79300 :         uint8_t **v = (uint8_t **)vv;
+    2145       79300 :         int N = nr;
+    2146             :         uint8_t *p[RAID_PARITY_MAX];
+    2147             :         uint8_t *pa[RAID_PARITY_MAX];
+    2148             :         uint8_t G[RAID_PARITY_MAX * RAID_PARITY_MAX];
+    2149             :         uint8_t V[RAID_PARITY_MAX * RAID_PARITY_MAX];
+    2150             :         uint8_t buffer[RAID_PARITY_MAX*16+16];
+    2151       79300 :         uint8_t *pd = __align_ptr(buffer, 16);
+    2152             :         size_t i;
+    2153             :         int j, k;
+    2154             : 
+    2155             :         /* setup the coefficients matrix */
+    2156      435250 :         for (j = 0; j < N; ++j)
+    2157     2047732 :                 for (k = 0; k < N; ++k)
+    2158     3383564 :                         G[j * N + k] = A(ip[j], id[k]);
+    2159             : 
+    2160             :         /* invert it to solve the system of linear equations */
+    2161       79300 :         raid_invert(G, V, N);
+    2162             : 
+    2163             :         /* compute delta parity */
+    2164       79300 :         raid_delta_gen(N, id, ip, nd, size, vv);
+    2165             : 
+    2166      435250 :         for (j = 0; j < N; ++j) {
+    2167      355950 :                 p[j] = v[nd + ip[j]];
+    2168      355950 :                 pa[j] = v[id[j]];
+    2169             :         }
+    2170             : 
+    2171             :         raid_sse_begin();
+    2172             : 
+    2173       79300 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0]));
+    2174             : 
+    2175     5870612 :         for (i = 0; i < size; i += 16) {
+    2176             :                 /* delta */
+    2177    32124880 :                 for (j = 0; j < N; ++j) {
+    2178    26333568 :                         asm volatile ("movdqa %0,%%xmm0" : : "m" (p[j][i]));
+    2179    26333568 :                         asm volatile ("movdqa %0,%%xmm1" : : "m" (pa[j][i]));
+    2180    26333568 :                         asm volatile ("pxor   %xmm1,%xmm0");
+    2181    26333568 :                         asm volatile ("movdqa %%xmm0,%0" : "=m" (pd[j*16]));
+    2182             :                 }
+    2183             : 
+    2184             :                 /* reconstruct */
+    2185    32124880 :                 for (j = 0; j < N; ++j) {
+    2186    26333568 :                         asm volatile ("pxor %xmm0,%xmm0");
+    2187    26333568 :                         asm volatile ("pxor %xmm1,%xmm1");
+    2188             : 
+    2189   153294784 :                         for (k = 0; k < N; ++k) {
+    2190   126961216 :                                 uint8_t m = V[j * N + k];
+    2191             : 
+    2192   126961216 :                                 asm volatile ("movdqa %0,%%xmm2" : : "m" (gfmulpshufb[m][0][0]));
+    2193   126961216 :                                 asm volatile ("movdqa %0,%%xmm3" : : "m" (gfmulpshufb[m][1][0]));
+    2194   126961216 :                                 asm volatile ("movdqa %0,%%xmm4" : : "m" (pd[k*16]));
+    2195   126961216 :                                 asm volatile ("movdqa %xmm4,%xmm5");
+    2196   126961216 :                                 asm volatile ("psrlw  $4,%xmm5");
+    2197   126961216 :                                 asm volatile ("pand   %xmm7,%xmm4");
+    2198   126961216 :                                 asm volatile ("pand   %xmm7,%xmm5");
+    2199   126961216 :                                 asm volatile ("pshufb %xmm4,%xmm2");
+    2200   126961216 :                                 asm volatile ("pshufb %xmm5,%xmm3");
+    2201   126961216 :                                 asm volatile ("pxor   %xmm2,%xmm0");
+    2202   126961216 :                                 asm volatile ("pxor   %xmm3,%xmm1");
+    2203             :                         }
+    2204             : 
+    2205    26333568 :                         asm volatile ("pxor %xmm1,%xmm0");
+    2206    26333568 :                         asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[j][i]));
+    2207             :                 }
+    2208             :         }
+    2209             : 
+    2210             :         raid_sse_end();
+    2211       79300 : }
+    2212             : #endif
+    2213             : 
+    2214             : #if defined(CONFIG_X86) && defined(CONFIG_AVX2)
+    2215             : /*
+    2216             :  * RAID recovering for one disk AVX2 implementation
+    2217             :  */
+    2218         126 : void raid_rec1_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    2219             : {
+    2220         126 :         uint8_t **v = (uint8_t **)vv;
+    2221             :         uint8_t *p;
+    2222             :         uint8_t *pa;
+    2223             :         uint8_t G;
+    2224             :         uint8_t V;
+    2225             :         size_t i;
+    2226             : 
+    2227             :         (void)nr; /* unused, it's always 1 */
+    2228             : 
+    2229             :         /* if it's RAID5 uses the faster function */
+    2230         126 :         if (ip[0] == 0) {
+    2231          30 :                 raid_rec1of1(id, nd, size, vv);
+    2232         156 :                 return;
+    2233             :         }
+    2234             : 
+    2235             :         /* setup the coefficients matrix */
+    2236         192 :         G = A(ip[0], id[0]);
+    2237             : 
+    2238             :         /* invert it to solve the system of linear equations */
+    2239         192 :         V = inv(G);
+    2240             : 
+    2241             :         /* compute delta parity */
+    2242          96 :         raid_delta_gen(1, id, ip, nd, size, vv);
+    2243             : 
+    2244          96 :         p = v[nd + ip[0]];
+    2245          96 :         pa = v[id[0]];
+    2246             : 
+    2247             :         raid_avx_begin();
+    2248             : 
+    2249          96 :         asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfconst16.low4[0]));
+    2250          96 :         asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (gfmulpshufb[V][0][0]));
+    2251          96 :         asm volatile ("vbroadcasti128 %0,%%ymm5" : : "m" (gfmulpshufb[V][1][0]));
+    2252             : 
+    2253       66816 :         for (i = 0; i < size; i += 32) {
+    2254       66720 :                 asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[i]));
+    2255       66720 :                 asm volatile ("vmovdqa %0,%%ymm1" : : "m" (pa[i]));
+    2256       66720 :                 asm volatile ("vpxor   %ymm1,%ymm0,%ymm0");
+    2257       66720 :                 asm volatile ("vpsrlw  $4,%ymm0,%ymm1");
+    2258       66720 :                 asm volatile ("vpand   %ymm7,%ymm0,%ymm0");
+    2259       66720 :                 asm volatile ("vpand   %ymm7,%ymm1,%ymm1");
+    2260       66720 :                 asm volatile ("vpshufb %ymm0,%ymm4,%ymm2");
+    2261       66720 :                 asm volatile ("vpshufb %ymm1,%ymm5,%ymm3");
+    2262       66720 :                 asm volatile ("vpxor   %ymm3,%ymm2,%ymm2");
+    2263       66720 :                 asm volatile ("vmovdqa %%ymm2,%0" : "=m" (pa[i]));
+    2264             :         }
+    2265             : 
+    2266             :         raid_avx_end();
+    2267             : }
+    2268             : #endif
+    2269             : 
+    2270             : #if defined(CONFIG_X86) && defined(CONFIG_AVX2)
+    2271             : /*
+    2272             :  * RAID recovering for two disks AVX2 implementation
+    2273             :  */
+    2274        1206 : void raid_rec2_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    2275             : {
+    2276        1206 :         uint8_t **v = (uint8_t **)vv;
+    2277        1206 :         const int N = 2;
+    2278        1206 :         uint8_t *p[N];
+    2279        1206 :         uint8_t *pa[N];
+    2280        1206 :         uint8_t G[N * N];
+    2281        1206 :         uint8_t V[N * N];
+    2282             :         size_t i;
+    2283             :         int j, k;
+    2284             : 
+    2285             :         (void)nr; /* unused, it's always 2 */
+    2286             : 
+    2287             :         /* setup the coefficients matrix */
+    2288        3618 :         for (j = 0; j < N; ++j)
+    2289        7236 :                 for (k = 0; k < N; ++k)
+    2290        9648 :                         G[j * N + k] = A(ip[j], id[k]);
+    2291             : 
+    2292             :         /* invert it to solve the system of linear equations */
+    2293        1206 :         raid_invert(G, V, N);
+    2294             : 
+    2295             :         /* compute delta parity */
+    2296        1206 :         raid_delta_gen(N, id, ip, nd, size, vv);
+    2297             : 
+    2298        3618 :         for (j = 0; j < N; ++j) {
+    2299        2412 :                 p[j] = v[nd + ip[j]];
+    2300        2412 :                 pa[j] = v[id[j]];
+    2301             :         }
+    2302             : 
+    2303             :         raid_avx_begin();
+    2304             : 
+    2305        1206 :         asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfconst16.low4[0]));
+    2306             : 
+    2307       77526 :         for (i = 0; i < size; i += 32) {
+    2308       76320 :                 asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[0][i]));
+    2309       76320 :                 asm volatile ("vmovdqa %0,%%ymm2" : : "m" (pa[0][i]));
+    2310       76320 :                 asm volatile ("vmovdqa %0,%%ymm1" : : "m" (p[1][i]));
+    2311       76320 :                 asm volatile ("vmovdqa %0,%%ymm3" : : "m" (pa[1][i]));
+    2312       76320 :                 asm volatile ("vpxor   %ymm2,%ymm0,%ymm0");
+    2313       76320 :                 asm volatile ("vpxor   %ymm3,%ymm1,%ymm1");
+    2314             : 
+    2315       76320 :                 asm volatile ("vpxor %ymm6,%ymm6,%ymm6");
+    2316             : 
+    2317       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfmulpshufb[V[0]][0][0]));
+    2318       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfmulpshufb[V[0]][1][0]));
+    2319       76320 :                 asm volatile ("vpsrlw  $4,%ymm0,%ymm5");
+    2320       76320 :                 asm volatile ("vpand   %ymm7,%ymm0,%ymm4");
+    2321       76320 :                 asm volatile ("vpand   %ymm7,%ymm5,%ymm5");
+    2322       76320 :                 asm volatile ("vpshufb %ymm4,%ymm2,%ymm2");
+    2323       76320 :                 asm volatile ("vpshufb %ymm5,%ymm3,%ymm3");
+    2324       76320 :                 asm volatile ("vpxor   %ymm2,%ymm6,%ymm6");
+    2325       76320 :                 asm volatile ("vpxor   %ymm3,%ymm6,%ymm6");
+    2326             : 
+    2327       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfmulpshufb[V[1]][0][0]));
+    2328       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfmulpshufb[V[1]][1][0]));
+    2329       76320 :                 asm volatile ("vpsrlw  $4,%ymm1,%ymm5");
+    2330       76320 :                 asm volatile ("vpand   %ymm7,%ymm1,%ymm4");
+    2331       76320 :                 asm volatile ("vpand   %ymm7,%ymm5,%ymm5");
+    2332       76320 :                 asm volatile ("vpshufb %ymm4,%ymm2,%ymm2");
+    2333       76320 :                 asm volatile ("vpshufb %ymm5,%ymm3,%ymm3");
+    2334       76320 :                 asm volatile ("vpxor   %ymm2,%ymm6,%ymm6");
+    2335       76320 :                 asm volatile ("vpxor   %ymm3,%ymm6,%ymm6");
+    2336             : 
+    2337       76320 :                 asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[0][i]));
+    2338             : 
+    2339       76320 :                 asm volatile ("vpxor %ymm6,%ymm6,%ymm6");
+    2340             : 
+    2341       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfmulpshufb[V[2]][0][0]));
+    2342       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfmulpshufb[V[2]][1][0]));
+    2343       76320 :                 asm volatile ("vpsrlw  $4,%ymm0,%ymm5");
+    2344       76320 :                 asm volatile ("vpand   %ymm7,%ymm0,%ymm4");
+    2345       76320 :                 asm volatile ("vpand   %ymm7,%ymm5,%ymm5");
+    2346       76320 :                 asm volatile ("vpshufb %ymm4,%ymm2,%ymm2");
+    2347       76320 :                 asm volatile ("vpshufb %ymm5,%ymm3,%ymm3");
+    2348       76320 :                 asm volatile ("vpxor   %ymm2,%ymm6,%ymm6");
+    2349       76320 :                 asm volatile ("vpxor   %ymm3,%ymm6,%ymm6");
+    2350             : 
+    2351       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfmulpshufb[V[3]][0][0]));
+    2352       76320 :                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfmulpshufb[V[3]][1][0]));
+    2353       76320 :                 asm volatile ("vpsrlw  $4,%ymm1,%ymm5");
+    2354       76320 :                 asm volatile ("vpand   %ymm7,%ymm1,%ymm4");
+    2355       76320 :                 asm volatile ("vpand   %ymm7,%ymm5,%ymm5");
+    2356       76320 :                 asm volatile ("vpshufb %ymm4,%ymm2,%ymm2");
+    2357       76320 :                 asm volatile ("vpshufb %ymm5,%ymm3,%ymm3");
+    2358       76320 :                 asm volatile ("vpxor   %ymm2,%ymm6,%ymm6");
+    2359       76320 :                 asm volatile ("vpxor   %ymm3,%ymm6,%ymm6");
+    2360             : 
+    2361       76320 :                 asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[1][i]));
+    2362             :         }
+    2363             : 
+    2364             :         raid_avx_end();
+    2365        1206 : }
+    2366             : #endif
+    2367             : 
+    2368             : #if defined(CONFIG_X86) && defined(CONFIG_AVX2)
+    2369             : /*
+    2370             :  * RAID recovering AVX2 implementation
+    2371             :  */
+    2372       17765 : void raid_recX_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv)
+    2373             : {
+    2374       17765 :         uint8_t **v = (uint8_t **)vv;
+    2375       17765 :         int N = nr;
+    2376             :         uint8_t *p[RAID_PARITY_MAX];
+    2377             :         uint8_t *pa[RAID_PARITY_MAX];
+    2378             :         uint8_t G[RAID_PARITY_MAX * RAID_PARITY_MAX];
+    2379             :         uint8_t V[RAID_PARITY_MAX * RAID_PARITY_MAX];
+    2380             :         uint8_t buffer[RAID_PARITY_MAX*32+32];
+    2381       17765 :         uint8_t *pd = __align_ptr(buffer, 32);
+    2382             :         size_t i;
+    2383             :         int j, k;
+    2384             : 
+    2385             :         /* setup the coefficients matrix */
+    2386       90821 :         for (j = 0; j < N; ++j)
+    2387      386396 :                 for (k = 0; k < N; ++k)
+    2388      626680 :                         G[j * N + k] = A(ip[j], id[k]);
+    2389             : 
+    2390             :         /* invert it to solve the system of linear equations */
+    2391       17765 :         raid_invert(G, V, N);
+    2392             : 
+    2393             :         /* compute delta parity */
+    2394       17765 :         raid_delta_gen(N, id, ip, nd, size, vv);
+    2395             : 
+    2396       90821 :         for (j = 0; j < N; ++j) {
+    2397       73056 :                 p[j] = v[nd + ip[j]];
+    2398       73056 :                 pa[j] = v[id[j]];
+    2399             :         }
+    2400             : 
+    2401             :         raid_avx_begin();
+    2402             : 
+    2403       17765 :         asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfconst16.low4[0]));
+    2404             : 
+    2405      423213 :         for (i = 0; i < size; i += 32) {
+    2406             :                 /* delta */
+    2407     2174152 :                 for (j = 0; j < N; ++j) {
+    2408     1768704 :                         asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[j][i]));
+    2409     1768704 :                         asm volatile ("vmovdqa %0,%%ymm1" : : "m" (pa[j][i]));
+    2410     1768704 :                         asm volatile ("vpxor   %ymm1,%ymm0,%ymm0");
+    2411     1768704 :                         asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pd[j*32]));
+    2412             :                 }
+    2413             : 
+    2414             :                 /* reconstruct */
+    2415     2174152 :                 for (j = 0; j < N; ++j) {
+    2416     1768704 :                         asm volatile ("vpxor %ymm0,%ymm0,%ymm0");
+    2417     1768704 :                         asm volatile ("vpxor %ymm1,%ymm1,%ymm1");
+    2418             : 
+    2419     9930976 :                         for (k = 0; k < N; ++k) {
+    2420     8162272 :                                 uint8_t m = V[j * N + k];
+    2421             : 
+    2422     8162272 :                                 asm volatile ("vbroadcasti128 %0,%%ymm2" : : "m" (gfmulpshufb[m][0][0]));
+    2423     8162272 :                                 asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfmulpshufb[m][1][0]));
+    2424     8162272 :                                 asm volatile ("vmovdqa %0,%%ymm4" : : "m" (pd[k*32]));
+    2425     8162272 :                                 asm volatile ("vpsrlw  $4,%ymm4,%ymm5");
+    2426     8162272 :                                 asm volatile ("vpand   %ymm7,%ymm4,%ymm4");
+    2427     8162272 :                                 asm volatile ("vpand   %ymm7,%ymm5,%ymm5");
+    2428     8162272 :                                 asm volatile ("vpshufb %ymm4,%ymm2,%ymm2");
+    2429     8162272 :                                 asm volatile ("vpshufb %ymm5,%ymm3,%ymm3");
+    2430     8162272 :                                 asm volatile ("vpxor   %ymm2,%ymm0,%ymm0");
+    2431     8162272 :                                 asm volatile ("vpxor   %ymm3,%ymm1,%ymm1");
+    2432             :                         }
+    2433             : 
+    2434     1768704 :                         asm volatile ("vpxor %ymm1,%ymm0,%ymm0");
+    2435     1768704 :                         asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[j][i]));
+    2436             :                 }
+    2437             :         }
+    2438             : 
+    2439             :         raid_avx_end();
+    2440       17765 : }
+    2441             : #endif
+    2442             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86z.c.func-sort-c.html b/cov/raid/x86z.c.func-sort-c.html new file mode 100644 index 00000000..cd3a9a96 --- /dev/null +++ b/cov/raid/x86z.c.func-sort-c.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - raid/x86z.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86z.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:3535100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_genz_sse21175
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86z.c.func.html b/cov/raid/x86z.c.func.html new file mode 100644 index 00000000..2c452573 --- /dev/null +++ b/cov/raid/x86z.c.func.html @@ -0,0 +1,76 @@ + + + + + + + LCOV - lcov.info - raid/x86z.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86z.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:3535100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
raid_genz_sse21175
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/raid/x86z.c.gcov.html b/cov/raid/x86z.c.gcov.html new file mode 100644 index 00000000..a11f7378 --- /dev/null +++ b/cov/raid/x86z.c.gcov.html @@ -0,0 +1,331 @@ + + + + + + + LCOV - lcov.info - raid/x86z.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - raid - x86z.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:3535100.0 %
Date:2015-05-12Functions:11100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (C) 2013 Andrea Mazzoleni
+       3             :  *
+       4             :  * This program is free software: you can redistribute it and/or modify
+       5             :  * it under the terms of the GNU General Public License as published by
+       6             :  * the Free Software Foundation, either version 2 of the License, or
+       7             :  * (at your option) any later version.
+       8             :  *
+       9             :  * This program is distributed in the hope that it will be useful,
+      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      12             :  * GNU General Public License for more details.
+      13             :  */
+      14             : 
+      15             : #include "internal.h"
+      16             : 
+      17             : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
+      18             : static const struct gfzconst16 {
+      19             :         uint8_t poly[16];
+      20             :         uint8_t half[16];
+      21             :         uint8_t low7[16];
+      22             : } gfzconst16 __aligned(64) =
+      23             : {
+      24             :         {
+      25             :                 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
+      26             :                 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d
+      27             :         },
+      28             :         {
+      29             :                 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e,
+      30             :                 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e
+      31             :         },
+      32             :         {
+      33             :                 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
+      34             :                 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
+      35             :         }
+      36             : };
+      37             : #endif
+      38             : 
+      39             : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
+      40             : /*
+      41             :  * GENz (triple parity with powers of 2^-1) SSE2 implementation
+      42             :  */
+      43        1175 : void raid_genz_sse2(int nd, size_t size, void **vv)
+      44             : {
+      45        1175 :         uint8_t **v = (uint8_t**)vv;
+      46             :         uint8_t *p;
+      47             :         uint8_t *q;
+      48             :         uint8_t *r;
+      49             :         int d, l;
+      50             :         size_t i;
+      51             : 
+      52        1175 :         l = nd - 1;
+      53        1175 :         p = v[nd];
+      54        1175 :         q = v[nd + 1];
+      55        1175 :         r = v[nd + 2];
+      56             : 
+      57             :         raid_sse_begin();
+      58             : 
+      59        1175 :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfzconst16.poly[0]));
+      60        1175 :         asm volatile ("movdqa %0,%%xmm3" : : "m" (gfzconst16.half[0]));
+      61        1175 :         asm volatile ("movdqa %0,%%xmm6" : : "m" (gfzconst16.low7[0]));
+      62             : 
+      63     1362151 :         for (i = 0; i < size; i += 16) {
+      64     1360976 :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
+      65     1360976 :                 asm volatile ("movdqa %xmm0,%xmm1");
+      66     1360976 :                 asm volatile ("movdqa %xmm0,%xmm2");
+      67    10958080 :                 for (d = l - 1; d >= 0; --d) {
+      68     9597104 :                         asm volatile ("pxor %xmm4,%xmm4");
+      69     9597104 :                         asm volatile ("pcmpgtb %xmm1,%xmm4");
+      70     9597104 :                         asm volatile ("paddb %xmm1,%xmm1");
+      71     9597104 :                         asm volatile ("pand %xmm7,%xmm4");
+      72     9597104 :                         asm volatile ("pxor %xmm4,%xmm1");
+      73             : 
+      74     9597104 :                         asm volatile ("movdqa %xmm2,%xmm4");
+      75     9597104 :                         asm volatile ("pxor %xmm5,%xmm5");
+      76     9597104 :                         asm volatile ("psllw $7,%xmm4");
+      77     9597104 :                         asm volatile ("psrlw $1,%xmm2");
+      78     9597104 :                         asm volatile ("pcmpgtb %xmm4,%xmm5");
+      79     9597104 :                         asm volatile ("pand %xmm6,%xmm2");
+      80     9597104 :                         asm volatile ("pand %xmm3,%xmm5");
+      81     9597104 :                         asm volatile ("pxor %xmm5,%xmm2");
+      82             : 
+      83     9597104 :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+      84     9597104 :                         asm volatile ("pxor %xmm4,%xmm0");
+      85     9597104 :                         asm volatile ("pxor %xmm4,%xmm1");
+      86     9597104 :                         asm volatile ("pxor %xmm4,%xmm2");
+      87             :                 }
+      88     1360976 :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+      89     1360976 :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+      90     1360976 :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+      91             :         }
+      92             : 
+      93             :         raid_sse_end();
+      94        1175 : }
+      95             : #endif
+      96             : 
+      97             : #if defined(CONFIG_X86_64) && defined(CONFIG_SSE2)
+      98             : /*
+      99             :  * GENz (triple parity with powers of 2^-1) SSE2 implementation
+     100             :  *
+     101             :  * Note that it uses 16 registers, meaning that x64 is required.
+     102             :  */
+     103             : void raid_genz_sse2ext(int nd, size_t size, void **vv)
+     104             : {
+     105             :         uint8_t **v = (uint8_t**)vv;
+     106             :         uint8_t *p;
+     107             :         uint8_t *q;
+     108             :         uint8_t *r;
+     109             :         int d, l;
+     110             :         size_t i;
+     111             : 
+     112             :         l = nd - 1;
+     113             :         p = v[nd];
+     114             :         q = v[nd + 1];
+     115             :         r = v[nd + 2];
+     116             : 
+     117             :         raid_sse_begin();
+     118             : 
+     119             :         asm volatile ("movdqa %0,%%xmm7" : : "m" (gfzconst16.poly[0]));
+     120             :         asm volatile ("movdqa %0,%%xmm3" : : "m" (gfzconst16.half[0]));
+     121             :         asm volatile ("movdqa %0,%%xmm11" : : "m" (gfzconst16.low7[0]));
+     122             : 
+     123             :         for (i = 0; i < size; i += 32) {
+     124             :                 asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
+     125             :                 asm volatile ("movdqa %0,%%xmm8" : : "m" (v[l][i + 16]));
+     126             :                 asm volatile ("movdqa %xmm0,%xmm1");
+     127             :                 asm volatile ("movdqa %xmm8,%xmm9");
+     128             :                 asm volatile ("movdqa %xmm0,%xmm2");
+     129             :                 asm volatile ("movdqa %xmm8,%xmm10");
+     130             :                 for (d = l - 1; d >= 0; --d) {
+     131             :                         asm volatile ("movdqa %xmm2,%xmm6");
+     132             :                         asm volatile ("movdqa %xmm10,%xmm14");
+     133             :                         asm volatile ("pxor %xmm4,%xmm4");
+     134             :                         asm volatile ("pxor %xmm12,%xmm12");
+     135             :                         asm volatile ("pxor %xmm5,%xmm5");
+     136             :                         asm volatile ("pxor %xmm13,%xmm13");
+     137             :                         asm volatile ("psllw $7,%xmm6");
+     138             :                         asm volatile ("psllw $7,%xmm14");
+     139             :                         asm volatile ("psrlw $1,%xmm2");
+     140             :                         asm volatile ("psrlw $1,%xmm10");
+     141             :                         asm volatile ("pcmpgtb %xmm1,%xmm4");
+     142             :                         asm volatile ("pcmpgtb %xmm9,%xmm12");
+     143             :                         asm volatile ("pcmpgtb %xmm6,%xmm5");
+     144             :                         asm volatile ("pcmpgtb %xmm14,%xmm13");
+     145             :                         asm volatile ("paddb %xmm1,%xmm1");
+     146             :                         asm volatile ("paddb %xmm9,%xmm9");
+     147             :                         asm volatile ("pand %xmm11,%xmm2");
+     148             :                         asm volatile ("pand %xmm11,%xmm10");
+     149             :                         asm volatile ("pand %xmm7,%xmm4");
+     150             :                         asm volatile ("pand %xmm7,%xmm12");
+     151             :                         asm volatile ("pand %xmm3,%xmm5");
+     152             :                         asm volatile ("pand %xmm3,%xmm13");
+     153             :                         asm volatile ("pxor %xmm4,%xmm1");
+     154             :                         asm volatile ("pxor %xmm12,%xmm9");
+     155             :                         asm volatile ("pxor %xmm5,%xmm2");
+     156             :                         asm volatile ("pxor %xmm13,%xmm10");
+     157             : 
+     158             :                         asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
+     159             :                         asm volatile ("movdqa %0,%%xmm12" : : "m" (v[d][i + 16]));
+     160             :                         asm volatile ("pxor %xmm4,%xmm0");
+     161             :                         asm volatile ("pxor %xmm4,%xmm1");
+     162             :                         asm volatile ("pxor %xmm4,%xmm2");
+     163             :                         asm volatile ("pxor %xmm12,%xmm8");
+     164             :                         asm volatile ("pxor %xmm12,%xmm9");
+     165             :                         asm volatile ("pxor %xmm12,%xmm10");
+     166             :                 }
+     167             :                 asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
+     168             :                 asm volatile ("movntdq %%xmm8,%0" : "=m" (p[i + 16]));
+     169             :                 asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
+     170             :                 asm volatile ("movntdq %%xmm9,%0" : "=m" (q[i + 16]));
+     171             :                 asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
+     172             :                 asm volatile ("movntdq %%xmm10,%0" : "=m" (r[i + 16]));
+     173             :         }
+     174             : 
+     175             :         raid_sse_end();
+     176             : }
+     177             : #endif
+     178             : 
+     179             : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
+     180             : /*
+     181             :  * GENz (triple parity with powers of 2^-1) AVX2 implementation
+     182             :  *
+     183             :  * Note that it uses 16 registers, meaning that x64 is required.
+     184             :  */
+     185             : void raid_genz_avx2ext(int nd, size_t size, void **vv)
+     186             : {
+     187             :         uint8_t **v = (uint8_t**)vv;
+     188             :         uint8_t *p;
+     189             :         uint8_t *q;
+     190             :         uint8_t *r;
+     191             :         int d, l;
+     192             :         size_t i;
+     193             : 
+     194             :         l = nd - 1;
+     195             :         p = v[nd];
+     196             :         q = v[nd + 1];
+     197             :         r = v[nd + 2];
+     198             : 
+     199             :         raid_avx_begin();
+     200             : 
+     201             :         asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfzconst16.poly[0]));
+     202             :         asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfzconst16.half[0]));
+     203             :         asm volatile ("vbroadcasti128 %0,%%ymm11" : : "m" (gfzconst16.low7[0]));
+     204             :         asm volatile ("vpxor %ymm15,%ymm15,%ymm15");
+     205             : 
+     206             :         for (i = 0; i < size; i += 64) {
+     207             :                 asm volatile ("vmovdqa %0,%%ymm0" : : "m" (v[l][i]));
+     208             :                 asm volatile ("vmovdqa %0,%%ymm8" : : "m" (v[l][i + 32]));
+     209             :                 asm volatile ("vmovdqa %ymm0,%ymm1");
+     210             :                 asm volatile ("vmovdqa %ymm8,%ymm9");
+     211             :                 asm volatile ("vmovdqa %ymm0,%ymm2");
+     212             :                 asm volatile ("vmovdqa %ymm8,%ymm10");
+     213             :                 for (d = l - 1; d >= 0; --d) {
+     214             :                         asm volatile ("vpsllw $7,%ymm2,%ymm6");
+     215             :                         asm volatile ("vpsllw $7,%ymm10,%ymm14");
+     216             :                         asm volatile ("vpsrlw $1,%ymm2,%ymm2");
+     217             :                         asm volatile ("vpsrlw $1,%ymm10,%ymm10");
+     218             :                         asm volatile ("vpcmpgtb %ymm1,%ymm15,%ymm4");
+     219             :                         asm volatile ("vpcmpgtb %ymm9,%ymm15,%ymm12");
+     220             :                         asm volatile ("vpcmpgtb %ymm6,%ymm15,%ymm5");
+     221             :                         asm volatile ("vpcmpgtb %ymm14,%ymm15,%ymm13");
+     222             :                         asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
+     223             :                         asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
+     224             :                         asm volatile ("vpand %ymm11,%ymm2,%ymm2");
+     225             :                         asm volatile ("vpand %ymm11,%ymm10,%ymm10");
+     226             :                         asm volatile ("vpand %ymm7,%ymm4,%ymm4");
+     227             :                         asm volatile ("vpand %ymm7,%ymm12,%ymm12");
+     228             :                         asm volatile ("vpand %ymm3,%ymm5,%ymm5");
+     229             :                         asm volatile ("vpand %ymm3,%ymm13,%ymm13");
+     230             :                         asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+     231             :                         asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+     232             :                         asm volatile ("vpxor %ymm5,%ymm2,%ymm2");
+     233             :                         asm volatile ("vpxor %ymm13,%ymm10,%ymm10");
+     234             : 
+     235             :                         asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[d][i]));
+     236             :                         asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[d][i + 32]));
+     237             :                         asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
+     238             :                         asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
+     239             :                         asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
+     240             :                         asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
+     241             :                         asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
+     242             :                         asm volatile ("vpxor %ymm12,%ymm10,%ymm10");
+     243             :                 }
+     244             :                 asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
+     245             :                 asm volatile ("vmovntdq %%ymm8,%0" : "=m" (p[i + 32]));
+     246             :                 asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
+     247             :                 asm volatile ("vmovntdq %%ymm9,%0" : "=m" (q[i + 32]));
+     248             :                 asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
+     249             :                 asm volatile ("vmovntdq %%ymm10,%0" : "=m" (r[i + 32]));
+     250             :         }
+     251             : 
+     252             :         raid_avx_end();
+     253             : }
+     254             : #endif
+     255             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/ruby.png b/cov/ruby.png new file mode 100644 index 00000000..991b6d4e Binary files /dev/null and b/cov/ruby.png differ diff --git a/cov/snow.png b/cov/snow.png new file mode 100644 index 00000000..2cdae107 Binary files /dev/null and b/cov/snow.png differ diff --git a/cov/tommyds/index-sort-f.html b/cov/tommyds/index-sort-f.html new file mode 100644 index 00000000..98589a48 --- /dev/null +++ b/cov/tommyds/index-sort-f.html @@ -0,0 +1,223 @@ + + + + + + + LCOV - lcov.info - tommyds + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommydsHitTotalCoverage
Test:lcov.infoLines:450450100.0 %
Date:2015-05-12Functions:6363100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
tommytypes.h +
100.0%
+
100.0 %4 / 4100.0 %2 / 2
tommyarrayblkof.h +
100.0%
+
100.0 %6 / 6100.0 %2 / 2
tommyhash.h +
100.0%
+
100.0 %18 / 18100.0 %2 / 2
tommylist.c +
100.0%
+
100.0 %25 / 25100.0 %3 / 3
tommyhashdyn.h +
100.0%
+
100.0 %11 / 11100.0 %3 / 3
tommyhash.c +
100.0%
+
100.0 %67 / 67100.0 %3 / 3
tommyarray.c +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
tommyarrayblk.c +
100.0%
+
100.0 %23 / 23100.0 %4 / 4
tommyarrayblkof.c +
100.0%
+
100.0 %24 / 24100.0 %4 / 4
tommyarrayblk.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommychain.h +
100.0%
+
100.0 %70 / 70100.0 %5 / 5
tommyarray.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommylist.h +
100.0%
+
100.0 %53 / 53100.0 %10 / 10
tommyhashdyn.c +
100.0%
+
100.0 %92 / 92100.0 %11 / 11
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/index-sort-l.html b/cov/tommyds/index-sort-l.html new file mode 100644 index 00000000..a5624292 --- /dev/null +++ b/cov/tommyds/index-sort-l.html @@ -0,0 +1,223 @@ + + + + + + + LCOV - lcov.info - tommyds + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommydsHitTotalCoverage
Test:lcov.infoLines:450450100.0 %
Date:2015-05-12Functions:6363100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
tommytypes.h +
100.0%
+
100.0 %4 / 4100.0 %2 / 2
tommyarrayblkof.h +
100.0%
+
100.0 %6 / 6100.0 %2 / 2
tommyhashdyn.h +
100.0%
+
100.0 %11 / 11100.0 %3 / 3
tommyarrayblk.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommyarray.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommyhash.h +
100.0%
+
100.0 %18 / 18100.0 %2 / 2
tommyarrayblk.c +
100.0%
+
100.0 %23 / 23100.0 %4 / 4
tommyarrayblkof.c +
100.0%
+
100.0 %24 / 24100.0 %4 / 4
tommylist.c +
100.0%
+
100.0 %25 / 25100.0 %3 / 3
tommyarray.c +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
tommylist.h +
100.0%
+
100.0 %53 / 53100.0 %10 / 10
tommyhash.c +
100.0%
+
100.0 %67 / 67100.0 %3 / 3
tommychain.h +
100.0%
+
100.0 %70 / 70100.0 %5 / 5
tommyhashdyn.c +
100.0%
+
100.0 %92 / 92100.0 %11 / 11
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/index.html b/cov/tommyds/index.html new file mode 100644 index 00000000..47da5333 --- /dev/null +++ b/cov/tommyds/index.html @@ -0,0 +1,223 @@ + + + + + + + LCOV - lcov.info - tommyds + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommydsHitTotalCoverage
Test:lcov.infoLines:450450100.0 %
Date:2015-05-12Functions:6363100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverage
tommyarray.c +
100.0%
+
100.0 %25 / 25100.0 %4 / 4
tommyarray.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommyarrayblk.c +
100.0%
+
100.0 %23 / 23100.0 %4 / 4
tommyarrayblk.h +
100.0%
+
100.0 %16 / 16100.0 %5 / 5
tommyarrayblkof.c +
100.0%
+
100.0 %24 / 24100.0 %4 / 4
tommyarrayblkof.h +
100.0%
+
100.0 %6 / 6100.0 %2 / 2
tommychain.h +
100.0%
+
100.0 %70 / 70100.0 %5 / 5
tommyhash.c +
100.0%
+
100.0 %67 / 67100.0 %3 / 3
tommyhash.h +
100.0%
+
100.0 %18 / 18100.0 %2 / 2
tommyhashdyn.c +
100.0%
+
100.0 %92 / 92100.0 %11 / 11
tommyhashdyn.h +
100.0%
+
100.0 %11 / 11100.0 %3 / 3
tommylist.c +
100.0%
+
100.0 %25 / 25100.0 %3 / 3
tommylist.h +
100.0%
+
100.0 %53 / 53100.0 %10 / 10
tommytypes.h +
100.0%
+
100.0 %4 / 4100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.c.func-sort-c.html b/cov/tommyds/tommyarray.c.func-sort-c.html new file mode 100644 index 00000000..beb4ce31 --- /dev/null +++ b/cov/tommyds/tommyarray.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_array_grow5052
tommy_array_init1869
tommy_array_done1742
tommy_array_memory_usage3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.c.func.html b/cov/tommyds/tommyarray.c.func.html new file mode 100644 index 00000000..81fba0ce --- /dev/null +++ b/cov/tommyds/tommyarray.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_array_done1742
tommy_array_grow5052
tommy_array_init1869
tommy_array_memory_usage3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.c.gcov.html b/cov/tommyds/tommyarray.c.gcov.html new file mode 100644 index 00000000..ca63ce27 --- /dev/null +++ b/cov/tommyds/tommyarray.c.gcov.html @@ -0,0 +1,159 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2011, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommyarray.h"
+      29             : 
+      30             : /******************************************************************************/
+      31             : /* array */
+      32             : 
+      33        1869 : void tommy_array_init(tommy_array* array)
+      34             : {
+      35             :         tommy_uint_t i;
+      36             : 
+      37             :         /* fixed initial size */
+      38        1869 :         array->bucket_bit = TOMMY_ARRAY_BIT;
+      39        1869 :         array->bucket_max = 1 << array->bucket_bit;
+      40        1869 :         array->bucket[0] = tommy_cast(void**, tommy_calloc(array->bucket_max, sizeof(void*)));
+      41       11214 :         for (i = 1; i < TOMMY_ARRAY_BIT; ++i)
+      42        9345 :                 array->bucket[i] = array->bucket[0];
+      43             : 
+      44        1869 :         array->count = 0;
+      45        1869 : }
+      46             : 
+      47        1742 : void tommy_array_done(tommy_array* array)
+      48             : {
+      49             :         tommy_uint_t i;
+      50             : 
+      51        1742 :         tommy_free(array->bucket[0]);
+      52        1744 :         for (i = TOMMY_ARRAY_BIT; i < array->bucket_bit; ++i) {
+      53           2 :                 void** segment = array->bucket[i];
+      54           2 :                 tommy_free(&segment[((tommy_ptrdiff_t)1) << i]);
+      55             :         }
+      56        1742 : }
+      57             : 
+      58        5052 : void tommy_array_grow(tommy_array* array, tommy_count_t count)
+      59             : {
+      60        5052 :         if (array->count >= count)
+      61        5052 :                 return;
+      62        5052 :         array->count = count;
+      63             : 
+      64       10106 :         while (count > array->bucket_max) {
+      65             :                 void** segment;
+      66             : 
+      67             :                 /* allocate one more segment */
+      68           2 :                 segment = tommy_cast(void**, tommy_calloc(array->bucket_max, sizeof(void*)));
+      69             : 
+      70             :                 /* store it adjusting the offset */
+      71             :                 /* cast to ptrdiff_t to ensure to get a negative value */
+      72           2 :                 array->bucket[array->bucket_bit] = &segment[-(tommy_ptrdiff_t)array->bucket_max];
+      73             : 
+      74           2 :                 ++array->bucket_bit;
+      75           2 :                 array->bucket_max = 1 << array->bucket_bit;
+      76             :         }
+      77             : }
+      78             : 
+      79           3 : tommy_size_t tommy_array_memory_usage(tommy_array* array)
+      80             : {
+      81           3 :         return array->bucket_max * (tommy_size_t)sizeof(void*);
+      82             : }
+      83             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.h.func-sort-c.html b/cov/tommyds/tommyarray.h.func-sort-c.html new file mode 100644 index 00000000..3771c386 --- /dev/null +++ b/cov/tommyds/tommyarray.h.func-sort-c.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_array_ref58148940
tommy_array_get58143888
tommy_array_size5121788
tommy_array_set5052
tommy_array_insert256
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.h.func.html b/cov/tommyds/tommyarray.h.func.html new file mode 100644 index 00000000..74277a5b --- /dev/null +++ b/cov/tommyds/tommyarray.h.func.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_array_get58143888
tommy_array_insert256
tommy_array_ref58148940
tommy_array_set5052
tommy_array_size5121788
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarray.h.gcov.html b/cov/tommyds/tommyarray.h.gcov.html new file mode 100644 index 00000000..369ff421 --- /dev/null +++ b/cov/tommyds/tommyarray.h.gcov.html @@ -0,0 +1,227 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarray.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarray.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2011, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Dynamic array based on segments of exponential growing size.
+      30             :  *
+      31             :  * This array is able to grow dynamically upon request, without any reallocation.
+      32             :  *
+      33             :  * The grow operation involves an allocation of a new array segment, without reallocating
+      34             :  * the already used memory, and then not increasing the heap fragmentation.
+      35             :  * This also implies that the address of the stored elements never change.
+      36             :  *
+      37             :  * Allocated segments grow in size exponentially.
+      38             :  */
+      39             : 
+      40             : #ifndef __TOMMYARRAY_H
+      41             : #define __TOMMYARRAY_H
+      42             : 
+      43             : #include "tommytypes.h"
+      44             : 
+      45             : #include <assert.h> /* for assert */
+      46             : 
+      47             : /******************************************************************************/
+      48             : /* array */
+      49             : 
+      50             : /**
+      51             :  * Initial and minimal size of the array expressed as a power of 2.
+      52             :  * The initial size is 2^TOMMY_ARRAY_BIT.
+      53             :  */
+      54             : #define TOMMY_ARRAY_BIT 6
+      55             : 
+      56             : /** \internal
+      57             :  * Max number of elements as a power of 2.
+      58             :  */
+      59             : #define TOMMY_ARRAY_BIT_MAX 32
+      60             : 
+      61             : /**
+      62             :  * Array container type.
+      63             :  * \note Don't use internal fields directly, but access the container only using functions.
+      64             :  */
+      65             : typedef struct tommy_array_struct {
+      66             :         void** bucket[TOMMY_ARRAY_BIT_MAX]; /**< Dynamic array of buckets. */
+      67             :         tommy_uint_t bucket_bit; /**< Bits used in the bit mask. */
+      68             :         tommy_count_t bucket_max; /**< Number of buckets. */
+      69             :         tommy_count_t count; /**< Number of initialized elements in the array. */
+      70             : } tommy_array;
+      71             : 
+      72             : /**
+      73             :  * Initializes the array.
+      74             :  */
+      75             : void tommy_array_init(tommy_array* array);
+      76             : 
+      77             : /**
+      78             :  * Deinitializes the array.
+      79             :  */
+      80             : void tommy_array_done(tommy_array* array);
+      81             : 
+      82             : /**
+      83             :  * Grows the size up to the specified value.
+      84             :  * All the new elements in the array are initialized with the 0 value.
+      85             :  */
+      86             : void tommy_array_grow(tommy_array* array, tommy_count_t size);
+      87             : 
+      88             : /**
+      89             :  * Gets a reference of the element at the specified position.
+      90             :  * You must be sure that space for this position is already
+      91             :  * allocated calling tommy_array_grow().
+      92             :  */
+      93    58148940 : tommy_inline void** tommy_array_ref(tommy_array* array, tommy_count_t pos)
+      94             : {
+      95             :         tommy_uint_t bsr;
+      96             : 
+      97    58148940 :         assert(pos < array->count);
+      98             : 
+      99             :         /* get the highest bit set, in case of all 0, return 0 */
+     100    58148940 :         bsr = tommy_ilog2_u32(pos | 1);
+     101             : 
+     102    58148940 :         return &array->bucket[bsr][pos];
+     103             : }
+     104             : 
+     105             : /**
+     106             :  * Sets the element at the specified position.
+     107             :  * You must be sure that space for this position is already
+     108             :  * allocated calling tommy_array_grow().
+     109             :  */
+     110        5052 : tommy_inline void tommy_array_set(tommy_array* array, tommy_count_t pos, void* element)
+     111             : {
+     112        5052 :         *tommy_array_ref(array, pos) = element;
+     113        5052 : }
+     114             : 
+     115             : /**
+     116             :  * Gets the element at the specified position.
+     117             :  * You must be sure that space for this position is already
+     118             :  * allocated calling tommy_array_grow().
+     119             :  */
+     120    58143888 : tommy_inline void* tommy_array_get(tommy_array* array, tommy_count_t pos)
+     121             : {
+     122    58143888 :         return *tommy_array_ref(array, pos);
+     123             : }
+     124             : 
+     125             : /**
+     126             :  * Grows and inserts a new element at the end of the array.
+     127             :  */
+     128         256 : tommy_inline void tommy_array_insert(tommy_array* array, void* element)
+     129             : {
+     130         256 :         tommy_count_t pos = array->count;
+     131             : 
+     132         256 :         tommy_array_grow(array, pos + 1);
+     133             : 
+     134         256 :         tommy_array_set(array, pos, element);
+     135         256 : }
+     136             : 
+     137             : /**
+     138             :  * Gets the initialized size of the array.
+     139             :  */
+     140     5121788 : tommy_inline tommy_count_t tommy_array_size(tommy_array* array)
+     141             : {
+     142     5121788 :         return array->count;
+     143             : }
+     144             : 
+     145             : /**
+     146             :  * Gets the size of allocated memory.
+     147             :  */
+     148             : tommy_size_t tommy_array_memory_usage(tommy_array* array);
+     149             : 
+     150             : #endif
+     151             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.c.func-sort-c.html b/cov/tommyds/tommyarrayblk.c.func-sort-c.html new file mode 100644 index 00000000..da124e52 --- /dev/null +++ b/cov/tommyds/tommyarrayblk.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2323100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblk_grow3814742
tommy_arrayblk_init1412
tommy_arrayblk_done1304
tommy_arrayblk_memory_usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.c.func.html b/cov/tommyds/tommyarrayblk.c.func.html new file mode 100644 index 00000000..869a04fd --- /dev/null +++ b/cov/tommyds/tommyarrayblk.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2323100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblk_done1304
tommy_arrayblk_grow3814742
tommy_arrayblk_init1412
tommy_arrayblk_memory_usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.c.gcov.html b/cov/tommyds/tommyarrayblk.c.gcov.html new file mode 100644 index 00000000..34c0d650 --- /dev/null +++ b/cov/tommyds/tommyarrayblk.c.gcov.html @@ -0,0 +1,158 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2323100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommyarrayblk.h"
+      29             : 
+      30             : /******************************************************************************/
+      31             : /* array */
+      32             : 
+      33        1412 : void tommy_arrayblk_init(tommy_arrayblk* array)
+      34             : {
+      35        1412 :         tommy_array_init(&array->block);
+      36             : 
+      37        1412 :         array->count = 0;
+      38        1412 : }
+      39             : 
+      40        1304 : void tommy_arrayblk_done(tommy_arrayblk* array)
+      41             : {
+      42             :         tommy_count_t i;
+      43             : 
+      44        4177 :         for (i = 0; i < tommy_array_size(&array->block); ++i)
+      45        2873 :                 tommy_free(tommy_array_get(&array->block, i));
+      46             : 
+      47        1304 :         tommy_array_done(&array->block);
+      48        1304 : }
+      49             : 
+      50     3814742 : void tommy_arrayblk_grow(tommy_arrayblk* array, tommy_count_t count)
+      51             : {
+      52             :         tommy_count_t block_max;
+      53             :         tommy_count_t block_mac;
+      54             : 
+      55     3814742 :         if (array->count >= count)
+      56     4033192 :                 return;
+      57     3596292 :         array->count = count;
+      58             : 
+      59     3596292 :         block_max = (count + TOMMY_ARRAYBLK_SIZE - 1) / TOMMY_ARRAYBLK_SIZE;
+      60     3596292 :         block_mac = tommy_array_size(&array->block);
+      61             : 
+      62     3596292 :         if (block_mac < block_max) {
+      63             :                 /* grow the block array */
+      64        3036 :                 tommy_array_grow(&array->block, block_max);
+      65             : 
+      66             :                 /* allocate new blocks */
+      67        9108 :                 while (block_mac < block_max) {
+      68        3036 :                         void** ptr = tommy_cast(void**, tommy_calloc(TOMMY_ARRAYBLK_SIZE, sizeof(void*)));
+      69             : 
+      70             :                         /* set the new block */
+      71        3036 :                         tommy_array_set(&array->block, block_mac, ptr);
+      72             : 
+      73        3036 :                         ++block_mac;
+      74             :                 }
+      75             :         }
+      76             : }
+      77             : 
+      78           1 : tommy_size_t tommy_arrayblk_memory_usage(tommy_arrayblk* array)
+      79             : {
+      80           1 :         return tommy_array_memory_usage(&array->block) + tommy_array_size(&array->block) * TOMMY_ARRAYBLK_SIZE * sizeof(void*);
+      81             : }
+      82             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.h.func-sort-c.html b/cov/tommyds/tommyarrayblk.h.func-sort-c.html new file mode 100644 index 00000000..726b38ed --- /dev/null +++ b/cov/tommyds/tommyarrayblk.h.func-sort-c.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblk_ref48145942
tommy_arrayblk_size39574015
tommy_arrayblk_get39113393
tommy_arrayblk_set9032549
tommy_arrayblk_insert256
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.h.func.html b/cov/tommyds/tommyarrayblk.h.func.html new file mode 100644 index 00000000..5cc21076 --- /dev/null +++ b/cov/tommyds/tommyarrayblk.h.func.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblk_get39113393
tommy_arrayblk_insert256
tommy_arrayblk_ref48145942
tommy_arrayblk_set9032549
tommy_arrayblk_size39574015
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblk.h.gcov.html b/cov/tommyds/tommyarrayblk.h.gcov.html new file mode 100644 index 00000000..a5e45191 --- /dev/null +++ b/cov/tommyds/tommyarrayblk.h.gcov.html @@ -0,0 +1,220 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblk.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblk.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1616100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Dynamic array based on blocks of fixed size.
+      30             :  *
+      31             :  * This array is able to grow dynamically upon request, without any reallocation.
+      32             :  *
+      33             :  * The grow operation involves an allocation of a new array block, without reallocating
+      34             :  * the already used memory, and then not increasing the heap fragmentation,
+      35             :  * and minimize the space occupation.
+      36             :  * This also implies that the address of the stored elements never change.
+      37             :  *
+      38             :  * Allocated blocks are always of the same fixed size of 4 Ki pointers.
+      39             :  */
+      40             : 
+      41             : #ifndef __TOMMYARRAYBLK_H
+      42             : #define __TOMMYARRAYBLK_H
+      43             : 
+      44             : #include "tommytypes.h"
+      45             : #include "tommyarray.h"
+      46             : 
+      47             : #include <assert.h> /* for assert */
+      48             : 
+      49             : /******************************************************************************/
+      50             : /* array */
+      51             : 
+      52             : /**
+      53             :  * Elements for each block.
+      54             :  */
+      55             : #define TOMMY_ARRAYBLK_SIZE (4 * 1024)
+      56             : 
+      57             : /**
+      58             :  * Array container type.
+      59             :  * \note Don't use internal fields directly, but access the container only using functions.
+      60             :  */
+      61             : typedef struct tommy_arrayblk_struct {
+      62             :         tommy_array block; /**< Array of blocks. */
+      63             :         tommy_count_t count; /**< Number of initialized elements in the array. */
+      64             : } tommy_arrayblk;
+      65             : 
+      66             : /**
+      67             :  * Initializes the array.
+      68             :  */
+      69             : void tommy_arrayblk_init(tommy_arrayblk* array);
+      70             : 
+      71             : /**
+      72             :  * Deinitializes the array.
+      73             :  */
+      74             : void tommy_arrayblk_done(tommy_arrayblk* array);
+      75             : 
+      76             : /**
+      77             :  * Grows the size up to the specified value.
+      78             :  * All the new elements in the array are initialized with the 0 value.
+      79             :  */
+      80             : void tommy_arrayblk_grow(tommy_arrayblk* array, tommy_count_t size);
+      81             : 
+      82             : /**
+      83             :  * Gets a reference of the element at the specified position.
+      84             :  * You must be sure that space for this position is already
+      85             :  * allocated calling tommy_arrayblk_grow().
+      86             :  */
+      87    48145942 : tommy_inline void** tommy_arrayblk_ref(tommy_arrayblk* array, tommy_count_t pos)
+      88             : {
+      89             :         void** ptr;
+      90             : 
+      91    48145942 :         assert(pos < array->count);
+      92             : 
+      93    48145942 :         ptr = tommy_cast(void**, tommy_array_get(&array->block, pos / TOMMY_ARRAYBLK_SIZE));
+      94             : 
+      95    48145942 :         return &ptr[pos % TOMMY_ARRAYBLK_SIZE];
+      96             : }
+      97             : 
+      98             : /**
+      99             :  * Sets the element at the specified position.
+     100             :  * You must be sure that space for this position is already
+     101             :  * allocated calling tommy_arrayblk_grow().
+     102             :  */
+     103     9032549 : tommy_inline void tommy_arrayblk_set(tommy_arrayblk* array, tommy_count_t pos, void* element)
+     104             : {
+     105     9032549 :         *tommy_arrayblk_ref(array, pos) = element;
+     106     9032549 : }
+     107             : 
+     108             : /**
+     109             :  * Gets the element at the specified position.
+     110             :  * You must be sure that space for this position is already
+     111             :  * allocated calling tommy_arrayblk_grow().
+     112             :  */
+     113    39113393 : tommy_inline void* tommy_arrayblk_get(tommy_arrayblk* array, tommy_count_t pos)
+     114             : {
+     115    39113393 :         return *tommy_arrayblk_ref(array, pos);
+     116             : }
+     117             : 
+     118             : /**
+     119             :  * Grows and inserts a new element at the end of the array.
+     120             :  */
+     121         256 : tommy_inline void tommy_arrayblk_insert(tommy_arrayblk* array, void* element)
+     122             : {
+     123         256 :         tommy_count_t pos = array->count;
+     124             : 
+     125         256 :         tommy_arrayblk_grow(array, pos + 1);
+     126             : 
+     127         256 :         tommy_arrayblk_set(array, pos, element);
+     128         256 : }
+     129             : 
+     130             : /**
+     131             :  * Gets the initialized size of the array.
+     132             :  */
+     133    39574015 : tommy_inline tommy_count_t tommy_arrayblk_size(tommy_arrayblk* array)
+     134             : {
+     135    39574015 :         return array->count;
+     136             : }
+     137             : 
+     138             : /**
+     139             :  * Gets the size of allocated memory.
+     140             :  */
+     141             : tommy_size_t tommy_arrayblk_memory_usage(tommy_arrayblk* array);
+     142             : 
+     143             : #endif
+     144             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.c.func-sort-c.html b/cov/tommyds/tommyarrayblkof.c.func-sort-c.html new file mode 100644 index 00000000..11661933 --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.c.func-sort-c.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2424100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblkof_grow1599399
tommy_arrayblkof_init237
tommy_arrayblkof_done219
tommy_arrayblkof_memory_usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.c.func.html b/cov/tommyds/tommyarrayblkof.c.func.html new file mode 100644 index 00000000..e5de916b --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.c.func.html @@ -0,0 +1,88 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2424100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblkof_done219
tommy_arrayblkof_grow1599399
tommy_arrayblkof_init237
tommy_arrayblkof_memory_usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.c.gcov.html b/cov/tommyds/tommyarrayblkof.c.gcov.html new file mode 100644 index 00000000..63b94c8e --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.c.gcov.html @@ -0,0 +1,159 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2424100.0 %
Date:2015-05-12Functions:44100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommyarrayblkof.h"
+      29             : 
+      30             : /******************************************************************************/
+      31             : /* array */
+      32             : 
+      33         237 : void tommy_arrayblkof_init(tommy_arrayblkof* array, tommy_size_t element_size)
+      34             : {
+      35         237 :         tommy_array_init(&array->block);
+      36             : 
+      37         237 :         array->element_size = element_size;
+      38         237 :         array->count = 0;
+      39         237 : }
+      40             : 
+      41         219 : void tommy_arrayblkof_done(tommy_arrayblkof* array)
+      42             : {
+      43             :         tommy_count_t i;
+      44             : 
+      45         708 :         for (i = 0; i < tommy_array_size(&array->block); ++i)
+      46         489 :                 tommy_free(tommy_array_get(&array->block, i));
+      47             : 
+      48         219 :         tommy_array_done(&array->block);
+      49         219 : }
+      50             : 
+      51     1599399 : void tommy_arrayblkof_grow(tommy_arrayblkof* array, tommy_count_t count)
+      52             : {
+      53             :         tommy_count_t block_max;
+      54             :         tommy_count_t block_mac;
+      55             : 
+      56     1599399 :         if (array->count >= count)
+      57     1678189 :                 return;
+      58     1520609 :         array->count = count;
+      59             : 
+      60     1520609 :         block_max = (count + TOMMY_ARRAYBLK_SIZE - 1) / TOMMY_ARRAYBLK_SIZE;
+      61     1520609 :         block_mac = tommy_array_size(&array->block);
+      62             : 
+      63     1520609 :         if (block_mac < block_max) {
+      64             :                 /* grow the block array */
+      65         513 :                 tommy_array_grow(&array->block, block_max);
+      66             : 
+      67             :                 /* allocate new blocks */
+      68        1539 :                 while (block_mac < block_max) {
+      69         513 :                         void** ptr = tommy_cast(void**, tommy_calloc(TOMMY_ARRAYBLK_SIZE, array->element_size));
+      70             : 
+      71             :                         /* set the new block */
+      72         513 :                         tommy_array_set(&array->block, block_mac, ptr);
+      73             : 
+      74         513 :                         ++block_mac;
+      75             :                 }
+      76             :         }
+      77             : }
+      78             : 
+      79           1 : tommy_size_t tommy_arrayblkof_memory_usage(tommy_arrayblkof* array)
+      80             : {
+      81           1 :         return tommy_array_memory_usage(&array->block) + tommy_array_size(&array->block) * TOMMY_ARRAYBLKOF_SIZE * array->element_size;
+      82             : }
+      83             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.h.func-sort-c.html b/cov/tommyds/tommyarrayblkof.h.func-sort-c.html new file mode 100644 index 00000000..326771ba --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.h.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:66100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblkof_ref6475035
tommy_arrayblkof_size5183926
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.h.func.html b/cov/tommyds/tommyarrayblkof.h.func.html new file mode 100644 index 00000000..33348d2d --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.h.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:66100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_arrayblkof_ref6475035
tommy_arrayblkof_size5183926
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyarrayblkof.h.gcov.html b/cov/tommyds/tommyarrayblkof.h.gcov.html new file mode 100644 index 00000000..e4e7721b --- /dev/null +++ b/cov/tommyds/tommyarrayblkof.h.gcov.html @@ -0,0 +1,190 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyarrayblkof.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyarrayblkof.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:66100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Dynamic array based on blocks of fixed size.
+      30             :  *
+      31             :  * This array is able to grow dynamically upon request, without any reallocation.
+      32             :  *
+      33             :  * This is very similar at ::tommy_arrayblk, but it allows to store elements of any
+      34             :  * size and not just pointers.
+      35             :  *
+      36             :  * Note that in this case tommy_arrayblkof_ref() returns a pointer at the element,
+      37             :  * that should be used for getting and setting elements in the array,
+      38             :  * as generic getter and setter are not available.
+      39             :  */
+      40             : 
+      41             : #ifndef __TOMMYARRAYBLKOF_H
+      42             : #define __TOMMYARRAYBLKOF_H
+      43             : 
+      44             : #include "tommytypes.h"
+      45             : #include "tommyarray.h"
+      46             : 
+      47             : #include <assert.h> /* for assert */
+      48             : 
+      49             : /******************************************************************************/
+      50             : /* array */
+      51             : 
+      52             : /**
+      53             :  * Elements for each block.
+      54             :  */
+      55             : #define TOMMY_ARRAYBLKOF_SIZE (4 * 1024)
+      56             : 
+      57             : /**
+      58             :  * Array container type.
+      59             :  * \note Don't use internal fields directly, but access the container only using functions.
+      60             :  */
+      61             : typedef struct tommy_arrayblkof_struct {
+      62             :         tommy_array block; /**< Array of blocks. */
+      63             :         tommy_size_t element_size; /**< Size of the stored element in bytes. */
+      64             :         tommy_count_t count; /**< Number of initialized elements in the array. */
+      65             : } tommy_arrayblkof;
+      66             : 
+      67             : /**
+      68             :  * Initializes the array.
+      69             :  * \param element_size Size in byte of the element to store in the array.
+      70             :  */
+      71             : void tommy_arrayblkof_init(tommy_arrayblkof* array, tommy_size_t element_size);
+      72             : 
+      73             : /**
+      74             :  * Deinitializes the array.
+      75             :  */
+      76             : void tommy_arrayblkof_done(tommy_arrayblkof* array);
+      77             : 
+      78             : /**
+      79             :  * Grows the size up to the specified value.
+      80             :  * All the new elements in the array are initialized with the 0 value.
+      81             :  */
+      82             : void tommy_arrayblkof_grow(tommy_arrayblkof* array, tommy_count_t size);
+      83             : 
+      84             : /**
+      85             :  * Gets a reference of the element at the specified position.
+      86             :  * You must be sure that space for this position is already
+      87             :  * allocated calling tommy_arrayblkof_grow().
+      88             :  */
+      89     6475035 : tommy_inline void* tommy_arrayblkof_ref(tommy_arrayblkof* array, tommy_count_t pos)
+      90             : {
+      91             :         unsigned char* base;
+      92             : 
+      93     6475035 :         assert(pos < array->count);
+      94             : 
+      95     6475035 :         base = tommy_cast(unsigned char*, tommy_array_get(&array->block, pos / TOMMY_ARRAYBLKOF_SIZE));
+      96             : 
+      97     6475035 :         return base + (pos % TOMMY_ARRAYBLKOF_SIZE) * array->element_size;
+      98             : }
+      99             : 
+     100             : /**
+     101             :  * Gets the initialized size of the array.
+     102             :  */
+     103     5183926 : tommy_inline tommy_count_t tommy_arrayblkof_size(tommy_arrayblkof* array)
+     104             : {
+     105     5183926 :         return array->count;
+     106             : }
+     107             : 
+     108             : /**
+     109             :  * Gets the size of allocated memory.
+     110             :  */
+     111             : tommy_size_t tommy_arrayblkof_memory_usage(tommy_arrayblkof* array);
+     112             : 
+     113             : #endif
+     114             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommychain.h.func-sort-c.html b/cov/tommyds/tommychain.h.func-sort-c.html new file mode 100644 index 00000000..0f137c2f --- /dev/null +++ b/cov/tommyds/tommychain.h.func-sort-c.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommychain.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommychain.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_chain_splice3977755
tommy_chain_merge_degenerated1123802
tommy_chain_concat1117866
tommy_chain_merge415391
tommy_chain_mergesort1403
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommychain.h.func.html b/cov/tommyds/tommychain.h.func.html new file mode 100644 index 00000000..824cc63d --- /dev/null +++ b/cov/tommyds/tommychain.h.func.html @@ -0,0 +1,92 @@ + + + + + + + LCOV - lcov.info - tommyds/tommychain.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommychain.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_chain_concat1117866
tommy_chain_merge415391
tommy_chain_merge_degenerated1123802
tommy_chain_mergesort1403
tommy_chain_splice3977755
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommychain.h.gcov.html b/cov/tommyds/tommychain.h.gcov.html new file mode 100644 index 00000000..4cd8ddd7 --- /dev/null +++ b/cov/tommyds/tommychain.h.gcov.html @@ -0,0 +1,300 @@ + + + + + + + LCOV - lcov.info - tommyds/tommychain.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommychain.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:7070100.0 %
Date:2015-05-12Functions:55100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Chain of nodes.
+      30             :  * A chain of nodes is an abstraction used to implements complex list operations
+      31             :  * like sorting.
+      32             :  *
+      33             :  * Do not use this directly. Use lists instead.
+      34             :  */
+      35             : 
+      36             : #ifndef __TOMMYCHAIN_H
+      37             : #define __TOMMYCHAIN_H
+      38             : 
+      39             : #include "tommytypes.h"
+      40             : 
+      41             : /******************************************************************************/
+      42             : /* chain */
+      43             : 
+      44             : /**
+      45             :  * Chain of nodes.
+      46             :  * A chain of nodes is a sequence of nodes with the following properties:
+      47             :  * - It contains at least one node. A chains of zero nodes cannot exist.
+      48             :  * - The next field of the tail is of *undefined* value.
+      49             :  * - The prev field of the head is of *undefined* value.
+      50             :  * - All the other inner prev and next fields are correctly set.
+      51             :  */
+      52             : typedef struct tommy_chain_struct {
+      53             :         tommy_node* head; /**< Pointer at the head of the chain. */
+      54             :         tommy_node* tail; /**< Pointer at the tail of the chain. */
+      55             : } tommy_chain;
+      56             : 
+      57             : /**
+      58             :  * Splices a chain in the middle of another chain.
+      59             :  */
+      60     3977755 : tommy_inline void tommy_chain_splice(tommy_node* first_before, tommy_node* first_after, tommy_node* second_head, tommy_node* second_tail)
+      61             : {
+      62             :         /* set the prev list */
+      63     3977755 :         first_after->prev = second_tail;
+      64     3977755 :         second_head->prev = first_before;
+      65             : 
+      66             :         /* set the next list */
+      67     3977755 :         first_before->next = second_head;
+      68     3977755 :         second_tail->next = first_after;
+      69     3977755 : }
+      70             : 
+      71             : /**
+      72             :  * Concats two chains.
+      73             :  */
+      74     1117866 : tommy_inline void tommy_chain_concat(tommy_node* first_tail, tommy_node* second_head)
+      75             : {
+      76             :         /* set the prev list */
+      77     1117866 :         second_head->prev = first_tail;
+      78             : 
+      79             :         /* set the next list */
+      80     1117866 :         first_tail->next = second_head;
+      81     1117866 : }
+      82             : 
+      83             : /**
+      84             :  * Merges two chains.
+      85             :  */
+      86      415391 : tommy_inline void tommy_chain_merge(tommy_chain* first, tommy_chain* second, tommy_compare_func* cmp)
+      87             : {
+      88      415391 :         tommy_node* first_i = first->head;
+      89      415391 :         tommy_node* second_i = second->head;
+      90             : 
+      91             :         /* merge */
+      92             :         while (1) {
+      93     8655135 :                 if (cmp(first_i->data, second_i->data) > 0) {
+      94     4182716 :                         tommy_node* next = second_i->next;
+      95     4182716 :                         if (first_i == first->head) {
+      96      204961 :                                 tommy_chain_concat(second_i, first_i);
+      97      204961 :                                 first->head = second_i;
+      98             :                         } else {
+      99     3977755 :                                 tommy_chain_splice(first_i->prev, first_i, second_i, second_i);
+     100             :                         }
+     101     4182716 :                         if (second_i == second->tail)
+     102      210897 :                                 break;
+     103     3971819 :                         second_i = next;
+     104             :                 } else {
+     105     4472419 :                         if (first_i == first->tail) {
+     106      204494 :                                 tommy_chain_concat(first_i, second_i);
+     107      204494 :                                 first->tail = second->tail;
+     108      204494 :                                 break;
+     109             :                         }
+     110     4267925 :                         first_i = first_i->next;
+     111             :                 }
+     112     8239744 :         }
+     113      415391 : }
+     114             : 
+     115             : /**
+     116             :  * Merges two chains managing special degenerated cases.
+     117             :  * It's funtionally equivalent at tommy_chain_merge() but faster with already ordered chains.
+     118             :  */
+     119     1123802 : tommy_inline void tommy_chain_merge_degenerated(tommy_chain* first, tommy_chain* second, tommy_compare_func* cmp)
+     120             : {
+     121             :         /* identify the condition first <= second */
+     122     1123802 :         if (cmp(first->tail->data, second->head->data) <= 0) {
+     123      413221 :                 tommy_chain_concat(first->tail, second->head);
+     124      413221 :                 first->tail = second->tail;
+     125      413221 :                 return;
+     126             :         }
+     127             : 
+     128             :         /* identify the condition second < first */
+     129             :         /* here we must be strict on comparison to keep the sort stable */
+     130      710581 :         if (cmp(second->tail->data, first->head->data) < 0) {
+     131      295190 :                 tommy_chain_concat(second->tail, first->head);
+     132      295190 :                 first->head = second->head;
+     133      295190 :                 return;
+     134             :         }
+     135             : 
+     136      415391 :         tommy_chain_merge(first, second, cmp);
+     137             : }
+     138             : 
+     139             : /**
+     140             :  * Max number of elements as a power of 2.
+     141             :  */
+     142             : #define TOMMY_CHAIN_BIT_MAX 32
+     143             : 
+     144             : /**
+     145             :  * Sorts a chain.
+     146             :  * It's a stable merge sort using power of 2 buckets, with O(N*log(N)) complexity,
+     147             :  * similar at the one used in the SGI STL libraries and in the Linux Kernel,
+     148             :  * but faster on degenerated cases like already ordered lists.
+     149             :  *
+     150             :  * SGI STL stl_list.h
+     151             :  * http://www.sgi.com/tech/stl/stl_list.h
+     152             :  *
+     153             :  * Linux Kernel lib/list_sort.c
+     154             :  * http://lxr.linux.no/#linux+v2.6.36/lib/list_sort.c
+     155             :  */
+     156        1403 : tommy_inline void tommy_chain_mergesort(tommy_chain* chain, tommy_compare_func* cmp)
+     157             : {
+     158             :         /*
+     159             :          * Bit buckets of chains.
+     160             :          * Each bucket contains 2^i nodes or it's empty.
+     161             :          * The chain at address TOMMY_CHAIN_BIT_MAX is an independet variable operating as "carry".
+     162             :          * We keep it in the same "bit" vector to avoid reports from the valgrind tool sgcheck.
+     163             :          */
+     164             :         tommy_chain bit[TOMMY_CHAIN_BIT_MAX + 1];
+     165             : 
+     166             :         /**
+     167             :          * Value stored inside the bit bucket.
+     168             :          * It's used to know which bucket is empty of full.
+     169             :          */
+     170             :         tommy_count_t counter;
+     171        1403 :         tommy_node* node = chain->head;
+     172        1403 :         tommy_node* tail = chain->tail;
+     173             :         tommy_count_t mask;
+     174             :         tommy_count_t i;
+     175             : 
+     176        1403 :         counter = 0;
+     177             :         while (1) {
+     178             :                 tommy_node* next;
+     179             :                 tommy_chain* last;
+     180             : 
+     181             :                 /* carry bit to add */
+     182     1125205 :                 last = &bit[TOMMY_CHAIN_BIT_MAX];
+     183     1125205 :                 bit[TOMMY_CHAIN_BIT_MAX].head = node;
+     184     1125205 :                 bit[TOMMY_CHAIN_BIT_MAX].tail = node;
+     185     1125205 :                 next = node->next;
+     186             : 
+     187             :                 /* add the bit, propagating the carry */
+     188     1125205 :                 i = 0;
+     189     1125205 :                 mask = counter;
+     190     3368992 :                 while ((mask & 1) != 0) {
+     191     1118582 :                         tommy_chain_merge_degenerated(&bit[i], last, cmp);
+     192     1118582 :                         mask >>= 1;
+     193     1118582 :                         last = &bit[i];
+     194     1118582 :                         ++i;
+     195             :                 }
+     196             : 
+     197             :                 /* copy the carry in the first empty bit */
+     198     1125205 :                 bit[i] = *last;
+     199             : 
+     200             :                 /* add the carry in the counter */
+     201     1125205 :                 ++counter;
+     202             : 
+     203     1125205 :                 if (node == tail)
+     204        1403 :                         break;
+     205     1123802 :                 node = next;
+     206     1123802 :         }
+     207             : 
+     208             :         /* merge the buckets */
+     209        1403 :         i = tommy_ctz_u32(counter);
+     210        1403 :         mask = counter >> i;
+     211       10496 :         while (mask != 1) {
+     212        7690 :                 mask >>= 1;
+     213        7690 :                 if (mask & 1)
+     214        5220 :                         tommy_chain_merge_degenerated(&bit[i + 1], &bit[i], cmp);
+     215             :                 else
+     216        2470 :                         bit[i + 1] = bit[i];
+     217        7690 :                 ++i;
+     218             :         }
+     219             : 
+     220        1403 :         *chain = bit[i];
+     221        1403 : }
+     222             : 
+     223             : #endif
+     224             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.c.func-sort-c.html b/cov/tommyds/tommyhash.c.func-sort-c.html new file mode 100644 index 00000000..41273bf7 --- /dev/null +++ b/cov/tommyds/tommyhash.c.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6767100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_le_uint32_read11198492
tommy_hash_u323917679
tommy_hash_u6419
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.c.func.html b/cov/tommyds/tommyhash.c.func.html new file mode 100644 index 00000000..19e1dc03 --- /dev/null +++ b/cov/tommyds/tommyhash.c.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6767100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_hash_u323917679
tommy_hash_u6419
tommy_le_uint32_read11198492
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.c.gcov.html b/cov/tommyds/tommyhash.c.gcov.html new file mode 100644 index 00000000..018852da --- /dev/null +++ b/cov/tommyds/tommyhash.c.gcov.html @@ -0,0 +1,243 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:6767100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommyhash.h"
+      29             : 
+      30             : /******************************************************************************/
+      31             : /* hash */
+      32             : 
+      33    11198492 : tommy_inline tommy_uint32_t tommy_le_uint32_read(const void* ptr)
+      34             : {
+      35             :         /* allow unaligned read on Intel x86 and x86_64 platforms */
+      36             : #if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__x86_64__) || defined(_M_X64)
+      37             :         /* defines from http://predef.sourceforge.net/ */
+      38    11198492 :         return *(const tommy_uint32_t*)ptr;
+      39             : #else
+      40             :         const unsigned char* ptr8 = tommy_cast(const unsigned char*, ptr);
+      41             :         return ptr8[0] + ((tommy_uint32_t)ptr8[1] << 8) + ((tommy_uint32_t)ptr8[2] << 16) + ((tommy_uint32_t)ptr8[3] << 24);
+      42             : #endif
+      43             : }
+      44             : 
+      45             : #define tommy_rot(x, k) \
+      46             :         (((x) << (k)) | ((x) >> (32 - (k))))
+      47             : 
+      48             : #define tommy_mix(a, b, c) \
+      49             :         do { \
+      50             :                 a -= c;  a ^= tommy_rot(c, 4);  c += b; \
+      51             :                 b -= a;  b ^= tommy_rot(a, 6);  a += c; \
+      52             :                 c -= b;  c ^= tommy_rot(b, 8);  b += a; \
+      53             :                 a -= c;  a ^= tommy_rot(c, 16);  c += b; \
+      54             :                 b -= a;  b ^= tommy_rot(a, 19);  a += c; \
+      55             :                 c -= b;  c ^= tommy_rot(b, 4);  b += a; \
+      56             :         } while (0)
+      57             : 
+      58             : #define tommy_final(a, b, c) \
+      59             :         do { \
+      60             :                 c ^= b; c -= tommy_rot(b, 14); \
+      61             :                 a ^= c; a -= tommy_rot(c, 11); \
+      62             :                 b ^= a; b -= tommy_rot(a, 25); \
+      63             :                 c ^= b; c -= tommy_rot(b, 16); \
+      64             :                 a ^= c; a -= tommy_rot(c, 4);  \
+      65             :                 b ^= a; b -= tommy_rot(a, 14); \
+      66             :                 c ^= b; c -= tommy_rot(b, 24); \
+      67             :         } while (0)
+      68             : 
+      69     3917679 : tommy_uint32_t tommy_hash_u32(tommy_uint32_t init_val, const void* void_key, tommy_size_t key_len)
+      70             : {
+      71     3917679 :         const unsigned char* key = tommy_cast(const unsigned char*, void_key);
+      72             :         tommy_uint32_t a, b, c;
+      73             : 
+      74     3917679 :         a = b = c = 0xdeadbeef + ((tommy_uint32_t)key_len) + init_val;
+      75             : 
+      76     9885766 :         while (key_len > 12) {
+      77     2050408 :                 a += tommy_le_uint32_read(key + 0);
+      78     2050408 :                 b += tommy_le_uint32_read(key + 4);
+      79     2050408 :                 c += tommy_le_uint32_read(key + 8);
+      80             : 
+      81     2050408 :                 tommy_mix(a, b, c);
+      82             : 
+      83     2050408 :                 key_len -= 12;
+      84     2050408 :                 key += 12;
+      85             :         }
+      86             : 
+      87     3917679 :         switch (key_len) {
+      88             :         case 0 :
+      89           1 :                 return c; /* used only when called with a zero length */
+      90             :         case 12 :
+      91      201264 :                 c += tommy_le_uint32_read(key + 8);
+      92      201264 :                 b += tommy_le_uint32_read(key + 4);
+      93      201264 :                 a += tommy_le_uint32_read(key + 0);
+      94      201264 :                 break;
+      95      210286 :         case 11 : c += ((tommy_uint32_t)key[10]) << 16;
+      96      618619 :         case 10 : c += ((tommy_uint32_t)key[9]) << 8;
+      97     1024267 :         case 9 : c += key[8];
+      98             :         case 8 :
+      99     1420790 :                 b += tommy_le_uint32_read(key + 4);
+     100     1420790 :                 a += tommy_le_uint32_read(key + 0);
+     101     1420790 :                 break;
+     102      397996 :         case 7 : b += ((tommy_uint32_t)key[6]) << 16;
+     103      783847 :         case 6 : b += ((tommy_uint32_t)key[5]) << 8;
+     104     1184551 :         case 5 : b += key[4];
+     105             :         case 4 :
+     106     1601847 :                 a += tommy_le_uint32_read(key + 0);
+     107     1601847 :                 break;
+     108      289691 :         case 3 : a += ((tommy_uint32_t)key[2]) << 16;
+     109      491696 :         case 2 : a += ((tommy_uint32_t)key[1]) << 8;
+     110      693777 :         case 1 : a += key[0];
+     111             :         }
+     112             : 
+     113     3917678 :         tommy_final(a, b, c);
+     114             : 
+     115     3917678 :         return c;
+     116             : }
+     117             : 
+     118          19 : tommy_uint64_t tommy_hash_u64(tommy_uint64_t init_val, const void* void_key, tommy_size_t key_len)
+     119             : {
+     120          19 :         const unsigned char* key = tommy_cast(const unsigned char*, void_key);
+     121             :         tommy_uint32_t a, b, c;
+     122             : 
+     123          19 :         a = b = c = 0xdeadbeef + ((tommy_uint32_t)key_len) + (init_val & 0xffffffff);
+     124          19 :         c += init_val >> 32;
+     125             : 
+     126          49 :         while (key_len > 12) {
+     127          11 :                 a += tommy_le_uint32_read(key + 0);
+     128          11 :                 b += tommy_le_uint32_read(key + 4);
+     129          11 :                 c += tommy_le_uint32_read(key + 8);
+     130             : 
+     131          11 :                 tommy_mix(a, b, c);
+     132             : 
+     133          11 :                 key_len -= 12;
+     134          11 :                 key += 12;
+     135             :         }
+     136             : 
+     137          19 :         switch (key_len) {
+     138             :         case 0 :
+     139           1 :                 return c + ((tommy_uint64_t)b << 32); /* used only when called with a zero length */
+     140             :         case 12 :
+     141           1 :                 c += tommy_le_uint32_read(key + 8);
+     142           1 :                 b += tommy_le_uint32_read(key + 4);
+     143           1 :                 a += tommy_le_uint32_read(key + 0);
+     144           1 :                 break;
+     145           1 :         case 11 : c += ((tommy_uint32_t)key[10]) << 16;
+     146           2 :         case 10 : c += ((tommy_uint32_t)key[9]) << 8;
+     147           3 :         case 9 : c += key[8];
+     148             :         case 8 :
+     149           4 :                 b += tommy_le_uint32_read(key + 4);
+     150           4 :                 a += tommy_le_uint32_read(key + 0);
+     151           4 :                 break;
+     152           2 :         case 7 : b += ((tommy_uint32_t)key[6]) << 16;
+     153           3 :         case 6 : b += ((tommy_uint32_t)key[5]) << 8;
+     154           4 :         case 5 : b += key[4];
+     155             :         case 4 :
+     156           5 :                 a += tommy_le_uint32_read(key + 0);
+     157           5 :                 break;
+     158           2 :         case 3 : a += ((tommy_uint32_t)key[2]) << 16;
+     159           6 :         case 2 : a += ((tommy_uint32_t)key[1]) << 8;
+     160           8 :         case 1 : a += key[0];
+     161             :         }
+     162             : 
+     163          18 :         tommy_final(a, b, c);
+     164             : 
+     165          18 :         return c + ((tommy_uint64_t)b << 32);
+     166             : }
+     167             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.h.func-sort-c.html b/cov/tommyds/tommyhash.h.func-sort-c.html new file mode 100644 index 00000000..b6cb1283 --- /dev/null +++ b/cov/tommyds/tommyhash.h.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1818100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_inthash_u3218378633
tommy_inthash_u644779013
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.h.func.html b/cov/tommyds/tommyhash.h.func.html new file mode 100644 index 00000000..7de9102b --- /dev/null +++ b/cov/tommyds/tommyhash.h.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1818100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_inthash_u3218378633
tommy_inthash_u644779013
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhash.h.gcov.html b/cov/tommyds/tommyhash.h.gcov.html new file mode 100644 index 00000000..4e5ea1f3 --- /dev/null +++ b/cov/tommyds/tommyhash.h.gcov.html @@ -0,0 +1,188 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhash.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhash.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1818100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Hash functions for the use with ::tommy_hashtable, ::tommy_hashdyn and ::tommy_hashlin.
+      30             :  */
+      31             : 
+      32             : #ifndef __TOMMYHASH_H
+      33             : #define __TOMMYHASH_H
+      34             : 
+      35             : #include "tommytypes.h"
+      36             : 
+      37             : /******************************************************************************/
+      38             : /* hash */
+      39             : 
+      40             : /**
+      41             :  * Hash type used in hashtables.
+      42             :  */
+      43             : typedef tommy_key_t tommy_hash_t;
+      44             : 
+      45             : /**
+      46             :  * Hash function with a 32 bits result.
+      47             :  * Implementation of the Robert Jenkins "lookup3" hash 32 bits version,
+      48             :  * from http://www.burtleburtle.net/bob/hash/doobs.html, function hashlittle().
+      49             :  * \param init_val Initialization value.
+      50             :  * Using a different initialization value, you can generate a completely different set of hash values.
+      51             :  * Use 0 if not relevant.
+      52             :  * \param void_key Pointer at the data to hash.
+      53             :  * \param key_len Size of the data to hash.
+      54             :  * \note
+      55             :  * This function is endianess independent.
+      56             :  * \return The hash value of 32 bits.
+      57             :  */
+      58             : tommy_uint32_t tommy_hash_u32(tommy_uint32_t init_val, const void* void_key, tommy_size_t key_len);
+      59             : 
+      60             : /**
+      61             :  * Hash function with a 64 bits result.
+      62             :  * Implementation of the Robert Jenkins "lookup3" hash 64 bits versions,
+      63             :  * from http://www.burtleburtle.net/bob/hash/doobs.html, function hashlittle2().
+      64             :  * \param init_val Initialization value.
+      65             :  * Using a different initialization value, you can generate a completely different set of hash values.
+      66             :  * Use 0 if not relevant.
+      67             :  * \param void_key Pointer at the data to hash.
+      68             :  * \param key_len Size of the data to hash.
+      69             :  * \note
+      70             :  * This function is endianess independent.
+      71             :  * \return The hash value of 64 bits.
+      72             :  */
+      73             : tommy_uint64_t tommy_hash_u64(tommy_uint64_t init_val, const void* void_key, tommy_size_t key_len);
+      74             : 
+      75             : /**
+      76             :  * Integer hash of 32 bits.
+      77             :  * Implementation of the Robert Jenkins "4-byte Integer Hashing",
+      78             :  * from http://burtleburtle.net/bob/hash/integer.html
+      79             :  */
+      80    18378633 : tommy_inline tommy_uint32_t tommy_inthash_u32(tommy_uint32_t key)
+      81             : {
+      82    18378633 :         key -= key << 6;
+      83    18378633 :         key ^= key >> 17;
+      84    18378633 :         key -= key << 9;
+      85    18378633 :         key ^= key << 4;
+      86    18378633 :         key -= key << 3;
+      87    18378633 :         key ^= key << 10;
+      88    18378633 :         key ^= key >> 15;
+      89             : 
+      90    18378633 :         return key;
+      91             : }
+      92             : 
+      93             : /**
+      94             :  * Integer hash of 64 bits.
+      95             :  * Implementation of the Thomas Wang "Integer Hash Function",
+      96             :  * from http://www.cris.com/~Ttwang/tech/inthash.htm
+      97             :  */
+      98     4779013 : tommy_inline tommy_uint64_t tommy_inthash_u64(tommy_uint64_t key)
+      99             : {
+     100     4779013 :         key = ~key + (key << 21);
+     101     4779013 :         key = key ^ (key >> 24);
+     102     4779013 :         key = key + (key << 3) + (key << 8);
+     103     4779013 :         key = key ^ (key >> 14);
+     104     4779013 :         key = key + (key << 2) + (key << 4);
+     105     4779013 :         key = key ^ (key >> 28);
+     106     4779013 :         key = key + (key << 31);
+     107             : 
+     108     4779013 :         return key;
+     109             : }
+     110             : 
+     111             : #endif
+     112             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.c.func-sort-c.html b/cov/tommyds/tommyhashdyn.c.func-sort-c.html new file mode 100644 index 00000000..c3e93a4e --- /dev/null +++ b/cov/tommyds/tommyhashdyn.c.func-sort-c.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:9292100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hashdyn_grow_step12829179
tommy_hashdyn_insert12829179
hashdyn_shrink_step204903
tommy_hashdyn_remove_existing204775
tommy_hashdyn_resize39523
tommy_hashdyn_init7767
tommy_hashdyn_done7173
tommy_hashdyn_remove256
tommy_hashdyn_foreach222
tommy_hashdyn_foreach_arg1
tommy_hashdyn_memory_usage1
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.c.func.html b/cov/tommyds/tommyhashdyn.c.func.html new file mode 100644 index 00000000..e85f24ff --- /dev/null +++ b/cov/tommyds/tommyhashdyn.c.func.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:9292100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hashdyn_grow_step12829179
hashdyn_shrink_step204903
tommy_hashdyn_done7173
tommy_hashdyn_foreach222
tommy_hashdyn_foreach_arg1
tommy_hashdyn_init7767
tommy_hashdyn_insert12829179
tommy_hashdyn_memory_usage1
tommy_hashdyn_remove256
tommy_hashdyn_remove_existing204775
tommy_hashdyn_resize39523
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.c.gcov.html b/cov/tommyds/tommyhashdyn.c.gcov.html new file mode 100644 index 00000000..35115c61 --- /dev/null +++ b/cov/tommyds/tommyhashdyn.c.gcov.html @@ -0,0 +1,300 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:9292100.0 %
Date:2015-05-12Functions:1111100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommyhashdyn.h"
+      29             : #include "tommylist.h"
+      30             : 
+      31             : /******************************************************************************/
+      32             : /* hashdyn */
+      33             : 
+      34        7767 : void tommy_hashdyn_init(tommy_hashdyn* hashdyn)
+      35             : {
+      36             :         /* fixed initial size */
+      37        7767 :         hashdyn->bucket_bit = TOMMY_HASHDYN_BIT;
+      38        7767 :         hashdyn->bucket_max = 1 << hashdyn->bucket_bit;
+      39        7767 :         hashdyn->bucket_mask = hashdyn->bucket_max - 1;
+      40        7767 :         hashdyn->bucket = tommy_cast(tommy_hashdyn_node**, tommy_calloc(hashdyn->bucket_max, sizeof(tommy_hashdyn_node*)));
+      41             : 
+      42        7767 :         hashdyn->count = 0;
+      43        7767 : }
+      44             : 
+      45        7173 : void tommy_hashdyn_done(tommy_hashdyn* hashdyn)
+      46             : {
+      47        7173 :         tommy_free(hashdyn->bucket);
+      48        7173 : }
+      49             : 
+      50             : /**
+      51             :  * Resize the bucket vector.
+      52             :  */
+      53       39523 : static void tommy_hashdyn_resize(tommy_hashdyn* hashdyn, tommy_count_t new_bucket_bit)
+      54             : {
+      55             :         tommy_count_t bucket_bit;
+      56             :         tommy_count_t bucket_max;
+      57             :         tommy_count_t new_bucket_max;
+      58             :         tommy_count_t new_bucket_mask;
+      59             :         tommy_hashdyn_node** new_bucket;
+      60             : 
+      61       39523 :         bucket_bit = hashdyn->bucket_bit;
+      62       39523 :         bucket_max = hashdyn->bucket_max;
+      63             : 
+      64       39523 :         new_bucket_max = 1 << new_bucket_bit;
+      65       39523 :         new_bucket_mask = new_bucket_max - 1;
+      66             : 
+      67             :         /* allocate the new vector using malloc() and not calloc() */
+      68             :         /* because data is fully initialized in the update process */
+      69       39523 :         new_bucket = tommy_cast(tommy_hashdyn_node**, tommy_malloc(new_bucket_max * sizeof(tommy_hashdyn_node*)));
+      70             : 
+      71             :         /* reinsert all the elements */
+      72       39523 :         if (new_bucket_bit > bucket_bit) {
+      73             :                 tommy_count_t i;
+      74             : 
+      75             :                 /* grow */
+      76    31575965 :                 for (i = 0; i < bucket_max; ++i) {
+      77             :                         tommy_hashdyn_node* j;
+      78             : 
+      79             :                         /* setup the new two buckets */
+      80    31536496 :                         new_bucket[i] = 0;
+      81    31536496 :                         new_bucket[i + bucket_max] = 0;
+      82             : 
+      83             :                         /* reinsert the bucket */
+      84    31536496 :                         j = hashdyn->bucket[i];
+      85    78841240 :                         while (j) {
+      86    15768248 :                                 tommy_hashdyn_node* j_next = j->next;
+      87    15768248 :                                 tommy_count_t pos = j->key & new_bucket_mask;
+      88    15768248 :                                 if (new_bucket[pos])
+      89     1852547 :                                         tommy_list_insert_tail_not_empty(new_bucket[pos], j);
+      90             :                                 else
+      91    13915701 :                                         tommy_list_insert_first(&new_bucket[pos], j);
+      92    15768248 :                                 j = j_next;
+      93             :                         }
+      94             :                 }
+      95             :         } else {
+      96             :                 tommy_count_t i;
+      97             : 
+      98             :                 /* shrink */
+      99       63398 :                 for (i = 0; i < new_bucket_max; ++i) {
+     100             :                         /* setup the new bucket with the lower bucket*/
+     101       63344 :                         new_bucket[i] = hashdyn->bucket[i];
+     102             : 
+     103             :                         /* concat the upper bucket */
+     104       63344 :                         tommy_list_concat(&new_bucket[i], &hashdyn->bucket[i + new_bucket_max]);
+     105             :                 }
+     106             :         }
+     107             : 
+     108       39523 :         tommy_free(hashdyn->bucket);
+     109             : 
+     110             :         /* setup */
+     111       39523 :         hashdyn->bucket_bit = new_bucket_bit;
+     112       39523 :         hashdyn->bucket_max = new_bucket_max;
+     113       39523 :         hashdyn->bucket_mask = new_bucket_mask;
+     114       39523 :         hashdyn->bucket = new_bucket;
+     115       39523 : }
+     116             : 
+     117             : /**
+     118             :  * Grow.
+     119             :  */
+     120    12829179 : tommy_inline void hashdyn_grow_step(tommy_hashdyn* hashdyn)
+     121             : {
+     122             :         /* grow if more than 50% full */
+     123    12829179 :         if (hashdyn->count >= hashdyn->bucket_max / 2)
+     124       39469 :                 tommy_hashdyn_resize(hashdyn, hashdyn->bucket_bit + 1);
+     125    12829179 : }
+     126             : 
+     127             : /**
+     128             :  * Shrink.
+     129             :  */
+     130      204903 : tommy_inline void hashdyn_shrink_step(tommy_hashdyn* hashdyn)
+     131             : {
+     132             :         /* shrink if less than 12.5% full */
+     133      204903 :         if (hashdyn->count <= hashdyn->bucket_max / 8 && hashdyn->bucket_bit > TOMMY_HASHDYN_BIT)
+     134          54 :                 tommy_hashdyn_resize(hashdyn, hashdyn->bucket_bit - 1);
+     135      204903 : }
+     136             : 
+     137    12829179 : void tommy_hashdyn_insert(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node, void* data, tommy_hash_t hash)
+     138             : {
+     139    12829179 :         tommy_count_t pos = hash & hashdyn->bucket_mask;
+     140             : 
+     141    12829179 :         tommy_list_insert_tail(&hashdyn->bucket[pos], node, data);
+     142             : 
+     143    12829179 :         node->key = hash;
+     144             : 
+     145    12829179 :         ++hashdyn->count;
+     146             : 
+     147    12829179 :         hashdyn_grow_step(hashdyn);
+     148    12829179 : }
+     149             : 
+     150      204775 : void* tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node)
+     151             : {
+     152      204775 :         tommy_count_t pos = node->key & hashdyn->bucket_mask;
+     153             : 
+     154      204775 :         tommy_list_remove_existing(&hashdyn->bucket[pos], node);
+     155             : 
+     156      204775 :         --hashdyn->count;
+     157             : 
+     158      204775 :         hashdyn_shrink_step(hashdyn);
+     159             : 
+     160      204775 :         return node->data;
+     161             : }
+     162             : 
+     163         256 : void* tommy_hashdyn_remove(tommy_hashdyn* hashdyn, tommy_search_func* cmp, const void* cmp_arg, tommy_hash_t hash)
+     164             : {
+     165         256 :         tommy_count_t pos = hash & hashdyn->bucket_mask;
+     166         256 :         tommy_hashdyn_node* node = hashdyn->bucket[pos];
+     167             : 
+     168         768 :         while (node) {
+     169             :                 /* we first check if the hash matches, as in the same bucket we may have multiples hash values */
+     170         384 :                 if (node->key == hash && cmp(cmp_arg, node->data) == 0) {
+     171         128 :                         tommy_list_remove_existing(&hashdyn->bucket[pos], node);
+     172             : 
+     173         128 :                         --hashdyn->count;
+     174             : 
+     175         128 :                         hashdyn_shrink_step(hashdyn);
+     176             : 
+     177         128 :                         return node->data;
+     178             :                 }
+     179         256 :                 node = node->next;
+     180             :         }
+     181             : 
+     182         128 :         return 0;
+     183             : }
+     184             : 
+     185         222 : void tommy_hashdyn_foreach(tommy_hashdyn* hashdyn, tommy_foreach_func* func)
+     186             : {
+     187         222 :         tommy_count_t bucket_max = hashdyn->bucket_max;
+     188         222 :         tommy_hashdyn_node** bucket = hashdyn->bucket;
+     189             :         tommy_count_t pos;
+     190             : 
+     191     5812110 :         for (pos = 0; pos < bucket_max; ++pos) {
+     192     5811888 :                 tommy_hashdyn_node* node = bucket[pos];
+     193             : 
+     194    13485857 :                 while (node) {
+     195     1862081 :                         void* data = node->data;
+     196     1862081 :                         node = node->next;
+     197     1862081 :                         func(data);
+     198             :                 }
+     199             :         }
+     200         222 : }
+     201             : 
+     202           1 : void tommy_hashdyn_foreach_arg(tommy_hashdyn* hashdyn, tommy_foreach_arg_func* func, void* arg)
+     203             : {
+     204           1 :         tommy_count_t bucket_max = hashdyn->bucket_max;
+     205           1 :         tommy_hashdyn_node** bucket = hashdyn->bucket;
+     206             :         tommy_count_t pos;
+     207             : 
+     208        1025 :         for (pos = 0; pos < bucket_max; ++pos) {
+     209        1024 :                 tommy_hashdyn_node* node = bucket[pos];
+     210             : 
+     211        2304 :                 while (node) {
+     212         256 :                         void* data = node->data;
+     213         256 :                         node = node->next;
+     214         256 :                         func(arg, data);
+     215             :                 }
+     216             :         }
+     217           1 : }
+     218             : 
+     219           1 : tommy_size_t tommy_hashdyn_memory_usage(tommy_hashdyn* hashdyn)
+     220             : {
+     221           2 :         return hashdyn->bucket_max * (tommy_size_t)sizeof(hashdyn->bucket[0])
+     222           1 :                + tommy_hashdyn_count(hashdyn) * (tommy_size_t)sizeof(tommy_hashdyn_node);
+     223             : }
+     224             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.h.func-sort-c.html b/cov/tommyds/tommyhashdyn.h.func-sort-c.html new file mode 100644 index 00000000..87460489 --- /dev/null +++ b/cov/tommyds/tommyhashdyn.h.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1111100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_hashdyn_bucket3016498
tommy_hashdyn_search3016498
tommy_hashdyn_count3
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.h.func.html b/cov/tommyds/tommyhashdyn.h.func.html new file mode 100644 index 00000000..d697c40a --- /dev/null +++ b/cov/tommyds/tommyhashdyn.h.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1111100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_hashdyn_bucket3016498
tommy_hashdyn_count3
tommy_hashdyn_search3016498
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommyhashdyn.h.gcov.html b/cov/tommyds/tommyhashdyn.h.gcov.html new file mode 100644 index 00000000..512f5f92 --- /dev/null +++ b/cov/tommyds/tommyhashdyn.h.gcov.html @@ -0,0 +1,371 @@ + + + + + + + LCOV - lcov.info - tommyds/tommyhashdyn.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommyhashdyn.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:1111100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Dynamic chained hashtable.
+      30             :  *
+      31             :  * This hashtable resizes dynamically. It starts with the minimal size of 16 buckets, it doubles
+      32             :  * the size then it reaches a load factor greater than 0.5 and it halves the size with a load
+      33             :  * factor lower than 0.125.
+      34             :  *
+      35             :  * All the elements are reallocated in a single resize operation done inside
+      36             :  * tommy_hashdyn_insert() or tommy_hashdyn_remove().
+      37             :  *
+      38             :  * Note that the resize operation takes approximatively 100 [ms] with 1 million of elements,
+      39             :  * and 1 [second] with 10 millions. This could be a problem in real-time applications.
+      40             :  *
+      41             :  * The resize also fragment the heap, as it involves allocating a double-sized table, copy elements,
+      42             :  * and deallocating the older table. Leaving a big hole in the heap.
+      43             :  *
+      44             :  * The ::tommy_hashlin hashtable fixes both problems.
+      45             :  *
+      46             :  * To initialize the hashtable you have to call tommy_hashdyn_init().
+      47             :  *
+      48             :  * \code
+      49             :  * tommy_hashslin hashdyn;
+      50             :  *
+      51             :  * tommy_hashdyn_init(&hashdyn);
+      52             :  * \endcode
+      53             :  *
+      54             :  * To insert elements in the hashtable you have to call tommy_hashdyn_insert() for
+      55             :  * each element.
+      56             :  * In the insertion call you have to specify the address of the node, the
+      57             :  * address of the object, and the hash value of the key to use.
+      58             :  * The address of the object is used to initialize the tommy_node::data field
+      59             :  * of the node, and the hash to initialize the tommy_node::key field.
+      60             :  *
+      61             :  * \code
+      62             :  * struct object {
+      63             :  *     tommy_node node;
+      64             :  *     // other fields
+      65             :  *     int value;
+      66             :  * };
+      67             :  *
+      68             :  * struct object* obj = malloc(sizeof(struct object)); // creates the object
+      69             :  *
+      70             :  * obj->value = ...; // initializes the object
+      71             :  *
+      72             :  * tommy_hashdyn_insert(&hashdyn, &obj->node, obj, tommy_inthash_u32(obj->value)); // inserts the object
+      73             :  * \endcode
+      74             :  *
+      75             :  * To find and element in the hashtable you have to call tommy_hashtable_search()
+      76             :  * providing a comparison function, its argument, and the hash of the key to search.
+      77             :  *
+      78             :  * \code
+      79             :  * int compare(const void* arg, const void* obj)
+      80             :  * {
+      81             :  *     return *(const int*)arg != ((const struct object*)obj)->value;
+      82             :  * }
+      83             :  *
+      84             :  * int value_to_find = 1;
+      85             :  * struct object* obj = tommy_hashdyn_search(&hashdyn, compare, &value_to_find, tommy_inthash_u32(value_to_find));
+      86             :  * if (!obj) {
+      87             :  *     // not found
+      88             :  * } else {
+      89             :  *     // found
+      90             :  * }
+      91             :  * \endcode
+      92             :  *
+      93             :  * To iterate over all the elements in the hashtable with the same key, you have to
+      94             :  * use tommy_hashdyn_bucket() and follow the tommy_node::next pointer until NULL.
+      95             :  * You have also to check explicitely for the key, as the bucket may contains
+      96             :  * different keys.
+      97             :  *
+      98             :  * \code
+      99             :  * int value_to_find = 1;
+     100             :  * tommy_node* i = tommy_hashdyn_bucket(&hashdyn, tommy_inthash_u32(value_to_find));
+     101             :  * while (i) {
+     102             :  *     struct object* obj = i->data; // gets the object pointer
+     103             :  *
+     104             :  *     if (obj->value == value_to_find) {
+     105             :  *         printf("%d\n", obj->value); // process the object
+     106             :  *     }
+     107             :  *
+     108             :  *     i = i->next; // goes to the next element
+     109             :  * }
+     110             :  * \endcode
+     111             :  *
+     112             :  * To remove an element from the hashtable you have to call tommy_hashdyn_remove()
+     113             :  * providing a comparison function, its argument, and the hash of the key to search
+     114             :  * and remove.
+     115             :  *
+     116             :  * \code
+     117             :  * struct object* obj = tommy_hashdyn_remove(&hashdyn, compare, &value_to_remove, tommy_inthash_u32(value_to_remove));
+     118             :  * if (obj) {
+     119             :  *     free(obj); // frees the object allocated memory
+     120             :  * }
+     121             :  * \endcode
+     122             :  *
+     123             :  * To destroy the hashtable you have to remove all the elements, and deinitialize
+     124             :  * the hashtable calling tommy_hashdyn_done().
+     125             :  *
+     126             :  * \code
+     127             :  * tommy_hashdyn_done(&hashdyn);
+     128             :  * \endcode
+     129             :  *
+     130             :  * If you need to iterate over all the elements in the hashtable, you can use
+     131             :  * tommy_hashdyn_foreach() or tommy_hashdyn_foreach_arg().
+     132             :  * If you need a more precise control with a real iteration, you have to insert
+     133             :  * all the elements also in a ::tommy_list, and use the list to iterate.
+     134             :  * See the \ref multiindex example for more detail.
+     135             :  */
+     136             : 
+     137             : #ifndef __TOMMYHASHDYN_H
+     138             : #define __TOMMYHASHDYN_H
+     139             : 
+     140             : #include "tommyhash.h"
+     141             : 
+     142             : /******************************************************************************/
+     143             : /* hashdyn */
+     144             : 
+     145             : /** \internal
+     146             :  * Initial and minimal size of the hashtable expressed as a power of 2.
+     147             :  * The initial size is 2^TOMMY_HASHDYN_BIT.
+     148             :  */
+     149             : #define TOMMY_HASHDYN_BIT 4
+     150             : 
+     151             : /**
+     152             :  * Hashtable node.
+     153             :  * This is the node that you have to include inside your objects.
+     154             :  */
+     155             : typedef tommy_node tommy_hashdyn_node;
+     156             : 
+     157             : /**
+     158             :  * Hashtable container type.
+     159             :  * \note Don't use internal fields directly, but access the container only using functions.
+     160             :  */
+     161             : typedef struct tommy_hashdyn_struct {
+     162             :         tommy_hashdyn_node** bucket; /**< Hash buckets. One list for each hash modulus. */
+     163             :         tommy_uint_t bucket_bit; /**< Bits used in the bit mask. */
+     164             :         tommy_count_t bucket_max; /**< Number of buckets. */
+     165             :         tommy_count_t bucket_mask; /**< Bit mask to access the buckets. */
+     166             :         tommy_count_t count; /**< Number of elements. */
+     167             : } tommy_hashdyn;
+     168             : 
+     169             : /**
+     170             :  * Initializes the hashtable.
+     171             :  */
+     172             : void tommy_hashdyn_init(tommy_hashdyn* hashdyn);
+     173             : 
+     174             : /**
+     175             :  * Deinitializes the hashtable.
+     176             :  *
+     177             :  * You can call this function with elements still contained,
+     178             :  * but such elements are not going to be freed by this call.
+     179             :  */
+     180             : void tommy_hashdyn_done(tommy_hashdyn* hashdyn);
+     181             : 
+     182             : /**
+     183             :  * Inserts an element in the hashtable.
+     184             :  */
+     185             : void tommy_hashdyn_insert(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node, void* data, tommy_hash_t hash);
+     186             : 
+     187             : /**
+     188             :  * Searches and removes an element from the hashtable.
+     189             :  * You have to provide a compare function and the hash of the element you want to remove.
+     190             :  * If the element is not found, 0 is returned.
+     191             :  * If more equal elements are present, the first one is removed.
+     192             :  * \param cmp Compare function called with cmp_arg as first argument and with the element to compare as a second one.
+     193             :  * The function should return 0 for equal elements, anything other for different elements.
+     194             :  * \param cmp_arg Compare argument passed as first argument of the compare function.
+     195             :  * \param hash Hash of the element to find and remove.
+     196             :  * \return The removed element, or 0 if not found.
+     197             :  */
+     198             : void* tommy_hashdyn_remove(tommy_hashdyn* hashdyn, tommy_search_func* cmp, const void* cmp_arg, tommy_hash_t hash);
+     199             : 
+     200             : /**
+     201             :  * Gets the bucket of the specified hash.
+     202             :  * The bucket is guaranteed to contain ALL the elements with the specified hash,
+     203             :  * but it can contain also others.
+     204             :  * You can access elements in the bucket following the ::next pointer until 0.
+     205             :  * \param hash Hash of the element to find.
+     206             :  * \return The head of the bucket, or 0 if empty.
+     207             :  */
+     208     3016498 : tommy_inline tommy_hashdyn_node* tommy_hashdyn_bucket(tommy_hashdyn* hashdyn, tommy_hash_t hash)
+     209             : {
+     210     3016498 :         return hashdyn->bucket[hash & hashdyn->bucket_mask];
+     211             : }
+     212             : 
+     213             : /**
+     214             :  * Searches an element in the hashtable.
+     215             :  * You have to provide a compare function and the hash of the element you want to find.
+     216             :  * If more equal elements are present, the first one is returned.
+     217             :  * \param cmp Compare function called with cmp_arg as first argument and with the element to compare as a second one.
+     218             :  * The function should return 0 for equal elements, anything other for different elements.
+     219             :  * \param cmp_arg Compare argument passed as first argument of the compare function.
+     220             :  * \param hash Hash of the element to find.
+     221             :  * \return The first element found, or 0 if none.
+     222             :  */
+     223     3016498 : tommy_inline void* tommy_hashdyn_search(tommy_hashdyn* hashdyn, tommy_search_func* cmp, const void* cmp_arg, tommy_hash_t hash)
+     224             : {
+     225     3016498 :         tommy_hashdyn_node* i = tommy_hashdyn_bucket(hashdyn, hash);
+     226             : 
+     227     6702222 :         while (i) {
+     228             :                 /* we first check if the hash matches, as in the same bucket we may have multiples hash values */
+     229     1684040 :                 if (i->key == hash && cmp(cmp_arg, i->data) == 0)
+     230     1014814 :                         return i->data;
+     231      669226 :                 i = i->next;
+     232             :         }
+     233     2001684 :         return 0;
+     234             : }
+     235             : 
+     236             : /**
+     237             :  * Removes an element from the hashtable.
+     238             :  * You must already have the address of the element to remove.
+     239             :  * \return The tommy_node::data field of the node removed.
+     240             :  */
+     241             : void* tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node);
+     242             : 
+     243             : /**
+     244             :  * Calls the specified function for each element in the hashtable.
+     245             :  *
+     246             :  * You can use this function to deallocate all the elements inserted.
+     247             :  *
+     248             :  * \code
+     249             :  * tommy_hashdyn hashdyn;
+     250             :  *
+     251             :  * // initializes the hashtable
+     252             :  * tommy_hashdyn_init(&hashdyn);
+     253             :  *
+     254             :  * ...
+     255             :  *
+     256             :  * // creates an object
+     257             :  * struct object* obj = malloc(sizeof(struct object));
+     258             :  *
+     259             :  * ...
+     260             :  *
+     261             :  * // insert it in the hashtable
+     262             :  * tommy_hashdyn_insert(&hashdyn, &obj->node, obj, tommy_inthash_u32(obj->value));
+     263             :  *
+     264             :  * ...
+     265             :  *
+     266             :  * // deallocates all the objects iterating the hashtable
+     267             :  * tommy_hashdyn_foreach(&hashdyn, free);
+     268             :  *
+     269             :  * // deallocates the hashtable
+     270             :  * tommy_hashdyn_done(&hashdyn);
+     271             :  * \endcode
+     272             :  */
+     273             : void tommy_hashdyn_foreach(tommy_hashdyn* hashdyn, tommy_foreach_func* func);
+     274             : 
+     275             : /**
+     276             :  * Calls the specified function with an argument for each element in the hashtable.
+     277             :  */
+     278             : void tommy_hashdyn_foreach_arg(tommy_hashdyn* hashdyn, tommy_foreach_arg_func* func, void* arg);
+     279             : 
+     280             : /**
+     281             :  * Gets the number of elements.
+     282             :  */
+     283           3 : tommy_inline tommy_count_t tommy_hashdyn_count(tommy_hashdyn* hashdyn)
+     284             : {
+     285           3 :         return hashdyn->count;
+     286             : }
+     287             : 
+     288             : /**
+     289             :  * Gets the size of allocated memory.
+     290             :  * It includes the size of the ::tommy_hashdyn_node of the stored elements.
+     291             :  */
+     292             : tommy_size_t tommy_hashdyn_memory_usage(tommy_hashdyn* hashdyn);
+     293             : 
+     294             : #endif
+     295             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.c.func-sort-c.html b/cov/tommyds/tommylist.c.func-sort-c.html new file mode 100644 index 00000000..8d71488c --- /dev/null +++ b/cov/tommyds/tommylist.c.func-sort-c.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_list_concat63344
tommy_list_sort1951
tommy_list_set1403
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.c.func.html b/cov/tommyds/tommylist.c.func.html new file mode 100644 index 00000000..4a434d56 --- /dev/null +++ b/cov/tommyds/tommylist.c.func.html @@ -0,0 +1,84 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_list_concat63344
tommy_list_set1403
tommy_list_sort1951
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.c.gcov.html b/cov/tommyds/tommylist.c.gcov.html new file mode 100644 index 00000000..c0b2001d --- /dev/null +++ b/cov/tommyds/tommylist.c.gcov.html @@ -0,0 +1,162 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.c (source / functions)HitTotalCoverage
Test:lcov.infoLines:2525100.0 %
Date:2015-05-12Functions:33100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : #include "tommylist.h"
+      29             : #include "tommychain.h"
+      30             : 
+      31       63344 : void tommy_list_concat(tommy_list* first, tommy_list* second)
+      32             : {
+      33             :         tommy_node* first_head;
+      34             :         tommy_node* first_tail;
+      35             :         tommy_node* second_head;
+      36             : 
+      37       63344 :         if (tommy_list_empty(second))
+      38       56041 :                 return;
+      39             : 
+      40        7303 :         if (tommy_list_empty(first)) {
+      41        6462 :                 *first = *second;
+      42        6462 :                 return;
+      43             :         }
+      44             : 
+      45         841 :         first_head = tommy_list_head(first);
+      46         841 :         second_head = tommy_list_head(second);
+      47         841 :         first_tail = tommy_list_tail(first);
+      48             : 
+      49             :         /* set the "circular" prev list */
+      50         841 :         first_head->prev = second_head->prev;
+      51         841 :         second_head->prev = first_tail;
+      52             : 
+      53             :         /* set the "0 terminated" next list */
+      54         841 :         first_tail->next = second_head;
+      55             : }
+      56             : 
+      57             : /** \internal
+      58             :  * Setup a list.
+      59             :  */
+      60        1403 : tommy_inline void tommy_list_set(tommy_list* list, tommy_node* head, tommy_node* tail)
+      61             : {
+      62        1403 :         head->prev = tail;
+      63        1403 :         tail->next = 0;
+      64        1403 :         *list = head;
+      65        1403 : }
+      66             : 
+      67        1951 : void tommy_list_sort(tommy_list* list, tommy_compare_func* cmp)
+      68             : {
+      69             :         tommy_chain chain;
+      70             :         tommy_node* head;
+      71             : 
+      72        1951 :         if (tommy_list_empty(list))
+      73        2499 :                 return;
+      74             : 
+      75        1403 :         head = tommy_list_head(list);
+      76             : 
+      77             :         /* create a chain from the list */
+      78        1403 :         chain.head = head;
+      79        1403 :         chain.tail = head->prev;
+      80             : 
+      81        1403 :         tommy_chain_mergesort(&chain, cmp);
+      82             : 
+      83             :         /* restore the list */
+      84        1403 :         tommy_list_set(list, chain.head, chain.tail);
+      85             : }
+      86             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.h.func-sort-c.html b/cov/tommyds/tommylist.h.func-sort-c.html new file mode 100644 index 00000000..6dbca9c1 --- /dev/null +++ b/cov/tommyds/tommylist.h.func-sort-c.html @@ -0,0 +1,112 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:5353100.0 %
Date:2015-05-12Functions:1010100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_list_head24404254
tommy_list_insert_first22854581
tommy_list_insert_tail17828444
tommy_list_insert_tail_not_empty10742111
tommy_list_remove_existing261068
tommy_list_empty75392
tommy_list_init10129
tommy_list_foreach6813
tommy_list_tail842
tommy_list_count230
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.h.func.html b/cov/tommyds/tommylist.h.func.html new file mode 100644 index 00000000..e2332433 --- /dev/null +++ b/cov/tommyds/tommylist.h.func.html @@ -0,0 +1,112 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:5353100.0 %
Date:2015-05-12Functions:1010100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_list_count230
tommy_list_empty75392
tommy_list_foreach6813
tommy_list_head24404254
tommy_list_init10129
tommy_list_insert_first22854581
tommy_list_insert_tail17828444
tommy_list_insert_tail_not_empty10742111
tommy_list_remove_existing261068
tommy_list_tail842
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommylist.h.gcov.html b/cov/tommyds/tommylist.h.gcov.html new file mode 100644 index 00000000..e84b5655 --- /dev/null +++ b/cov/tommyds/tommylist.h.gcov.html @@ -0,0 +1,448 @@ + + + + + + + LCOV - lcov.info - tommyds/tommylist.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommylist.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:5353100.0 %
Date:2015-05-12Functions:1010100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Double linked list for collisions into hashtables.
+      30             :  *
+      31             :  * This list is a double linked list mainly targetted for handling collisions
+      32             :  * into an hashtables, but useable also as a generic list.
+      33             :  *
+      34             :  * The main feature of this list is to require only one pointer to represent the
+      35             :  * list, compared to a classic implementation requiring a head an a tail pointers.
+      36             :  * This reduces the memory usage in hashtables.
+      37             :  *
+      38             :  * Another feature is to support the insertion at the end of the list. This allow to store
+      39             :  * collisions in a stable order. Where for stable order we mean that equal elements keep
+      40             :  * their insertion order.
+      41             :  *
+      42             :  * To initialize the list, you have to call tommy_list_init(), or to simply assign
+      43             :  * to it NULL, as an empty list is represented by the NULL value.
+      44             :  *
+      45             :  * \code
+      46             :  * tommy_list list;
+      47             :  *
+      48             :  * tommy_list_init(&list); // initializes the list
+      49             :  * \endcode
+      50             :  *
+      51             :  * To insert elements in the list you have to call tommy_list_insert_tail()
+      52             :  * or tommy_list_insert_head() for each element.
+      53             :  * In the insertion call you have to specify the address of the node and the
+      54             :  * address of the object.
+      55             :  * The address of the object is used to initialize the tommy_node::data field
+      56             :  * of the node.
+      57             :  *
+      58             :  * \code
+      59             :  * struct object {
+      60             :  *     tommy_node node;
+      61             :  *     // other fields
+      62             :  *     int value;
+      63             :  * };
+      64             :  *
+      65             :  * struct object* obj = malloc(sizeof(struct object)); // creates the object
+      66             :  *
+      67             :  * obj->value = ...; // initializes the object
+      68             :  *
+      69             :  * tommy_list_insert_tail(&list, &obj->node, obj); // inserts the object
+      70             :  * \endcode
+      71             :  *
+      72             :  * To iterate over all the elements in the list you have to call
+      73             :  * tommy_list_head() to get the head of the list and follow the
+      74             :  * tommy_node::next pointer until NULL.
+      75             :  *
+      76             :  * \code
+      77             :  * tommy_node* i = tommy_list_head(&list);
+      78             :  * while (i) {
+      79             :  *     struct object* obj = i->data; // gets the object pointer
+      80             :  *
+      81             :  *     printf("%d\n", obj->value); // process the object
+      82             :  *
+      83             :  *     i = i->next; // go to the next element
+      84             :  * }
+      85             :  * \endcode
+      86             :  *
+      87             :  * To destroy the list you have to remove all the elements,
+      88             :  * as the list is completely inplace and it doesn't allocate memory.
+      89             :  * This can be done with the tommy_list_foreach() function.
+      90             :  *
+      91             :  * \code
+      92             :  * // deallocates all the objects iterating the list
+      93             :  * tommy_list_foreach(&list, free);
+      94             :  * \endcode
+      95             :  */
+      96             : 
+      97             : #ifndef __TOMMYLIST_H
+      98             : #define __TOMMYLIST_H
+      99             : 
+     100             : #include "tommytypes.h"
+     101             : 
+     102             : /******************************************************************************/
+     103             : /* list */
+     104             : 
+     105             : /**
+     106             :  * Double linked list type.
+     107             :  */
+     108             : typedef tommy_node* tommy_list;
+     109             : 
+     110             : /**
+     111             :  * Initializes the list.
+     112             :  * The list is completely inplace, so it doesn't need to be deinitialized.
+     113             :  */
+     114       10129 : tommy_inline void tommy_list_init(tommy_list* list)
+     115             : {
+     116       10129 :         *list = 0;
+     117       10129 : }
+     118             : 
+     119             : /**
+     120             :  * Gets the head of the list.
+     121             :  * \return The head node. For empty lists 0 is returned.
+     122             :  */
+     123    24404254 : tommy_inline tommy_node* tommy_list_head(tommy_list* list)
+     124             : {
+     125    24404254 :         return *list;
+     126             : }
+     127             : 
+     128             : /**
+     129             :  * Gets the tail of the list.
+     130             :  * \return The tail node. For empty lists 0 is returned.
+     131             :  */
+     132         842 : tommy_inline tommy_node* tommy_list_tail(tommy_list* list)
+     133             : {
+     134         842 :         tommy_node* head = tommy_list_head(list);
+     135             : 
+     136         842 :         if (!head)
+     137           1 :                 return 0;
+     138             : 
+     139         841 :         return head->prev;
+     140             : }
+     141             : 
+     142             : /** \internal
+     143             :  * Creates a new list with a single element.
+     144             :  * \param list The list to initialize.
+     145             :  * \param node The node to insert.
+     146             :  */
+     147    22854581 : tommy_inline void tommy_list_insert_first(tommy_list* list, tommy_node* node)
+     148             : {
+     149             :         /* one element "circular" prev list */
+     150    22854581 :         node->prev = node;
+     151             : 
+     152             :         /* one element "0 terminated" next list */
+     153    22854581 :         node->next = 0;
+     154             : 
+     155    22854581 :         *list = node;
+     156    22854581 : }
+     157             : 
+     158             : /** \internal
+     159             :  * Inserts an element at the head of a not empty list.
+     160             :  * The element is inserted at the head of the list. The list cannot be empty.
+     161             :  * \param list The list. The list cannot be empty.
+     162             :  * \param node The node to insert.
+     163             :  */
+     164             : tommy_inline void tommy_list_insert_head_not_empty(tommy_list* list, tommy_node* node)
+     165             : {
+     166             :         tommy_node* head = tommy_list_head(list);
+     167             : 
+     168             :         /* insert in the "circular" prev list */
+     169             :         node->prev = head->prev;
+     170             :         head->prev = node;
+     171             : 
+     172             :         /* insert in the "0 terminated" next list */
+     173             :         node->next = head;
+     174             : 
+     175             :         *list = node;
+     176             : }
+     177             : 
+     178             : /** \internal
+     179             :  * Inserts an element at the tail of a not empty list.
+     180             :  * The element is inserted at the tail of the list. The list cannot be empty.
+     181             :  * \param head The node at the list head. It cannot be 0.
+     182             :  * \param node The node to insert.
+     183             :  */
+     184    10742111 : tommy_inline void tommy_list_insert_tail_not_empty(tommy_node* head, tommy_node* node)
+     185             : {
+     186             :         /* insert in the "circular" prev list */
+     187    10742111 :         node->prev = head->prev;
+     188    10742111 :         head->prev = node;
+     189             : 
+     190             :         /* insert in the "0 terminated" next list */
+     191    10742111 :         node->next = 0;
+     192    10742111 :         node->prev->next = node;
+     193    10742111 : }
+     194             : 
+     195             : /**
+     196             :  * Inserts an element at the head of a list.
+     197             :  * \param node The node to insert.
+     198             :  * \param data The object containing the node. It's used to set the tommy_node::data field of the node.
+     199             :  */
+     200             : tommy_inline void tommy_list_insert_head(tommy_list* list, tommy_node* node, void* data)
+     201             : {
+     202             :         tommy_node* head = tommy_list_head(list);
+     203             : 
+     204             :         if (head)
+     205             :                 tommy_list_insert_head_not_empty(list, node);
+     206             :         else
+     207             :                 tommy_list_insert_first(list, node);
+     208             : 
+     209             :         node->data = data;
+     210             : }
+     211             : 
+     212             : /**
+     213             :  * Inserts an element at the tail of a list.
+     214             :  * \param node The node to insert.
+     215             :  * \param data The object containing the node. It's used to set the tommy_node::data field of the node.
+     216             :  */
+     217    17828444 : tommy_inline void tommy_list_insert_tail(tommy_list* list, tommy_node* node, void* data)
+     218             : {
+     219    17828444 :         tommy_node* head = tommy_list_head(list);
+     220             : 
+     221    17828444 :         if (head)
+     222     8889564 :                 tommy_list_insert_tail_not_empty(head, node);
+     223             :         else
+     224     8938880 :                 tommy_list_insert_first(list, node);
+     225             : 
+     226    17828444 :         node->data = data;
+     227    17828444 : }
+     228             : 
+     229             : /** \internal
+     230             :  * Removes an element from the head of a not empty list.
+     231             :  * \param list The list. The list cannot be empty.
+     232             :  * \return The node removed.
+     233             :  */
+     234             : tommy_inline tommy_node* tommy_list_remove_head_not_empty(tommy_list* list)
+     235             : {
+     236             :         tommy_node* head = tommy_list_head(list);
+     237             : 
+     238             :         /* remove from the "circular" prev list */
+     239             :         head->next->prev = head->prev;
+     240             : 
+     241             :         /* remove from the "0 terminated" next list */
+     242             :         *list = head->next; /* the new head, in case 0 */
+     243             : 
+     244             :         return head;
+     245             : }
+     246             : 
+     247             : /**
+     248             :  * Removes an element from the list.
+     249             :  * You must already have the address of the element to remove.
+     250             :  * \note The node content is left unchanged, including the tommy_node::next
+     251             :  * and tommy_node::prev fields that still contain pointers at the list.
+     252             :  * \param node The node to remove. The node must be in the list.
+     253             :  * \return The tommy_node::data field of the node removed.
+     254             :  */
+     255      261068 : tommy_inline void* tommy_list_remove_existing(tommy_list* list, tommy_node* node)
+     256             : {
+     257      261068 :         tommy_node* head = tommy_list_head(list);
+     258             : 
+     259             :         /* remove from the "circular" prev list */
+     260      261068 :         if (node->next)
+     261      100364 :                 node->next->prev = node->prev;
+     262             :         else
+     263      160704 :                 head->prev = node->prev; /* the last */
+     264             : 
+     265             :         /* remove from the "0 terminated" next list */
+     266      261068 :         if (head == node)
+     267      176052 :                 *list = node->next; /* the new head, in case 0 */
+     268             :         else
+     269       85016 :                 node->prev->next = node->next;
+     270             : 
+     271      261068 :         return node->data;
+     272             : }
+     273             : 
+     274             : /**
+     275             :  * Concats two lists.
+     276             :  * The second list is concatenated at the first list.
+     277             :  * \param first The first list.
+     278             :  * \param second The second list. After this call the list content is undefined,
+     279             :  * and you should not use it anymore.
+     280             :  */
+     281             : void tommy_list_concat(tommy_list* first, tommy_list* second);
+     282             : 
+     283             : /**
+     284             :  * Sorts a list.
+     285             :  * It's a stable merge sort with O(N*log(N)) worst complexity.
+     286             :  * It's faster on degenerated cases like partially ordered lists.
+     287             :  * \param cmp Compare function called with two elements.
+     288             :  * The function should return <0 if the first element is less than the second, ==0 if equal, and >0 if greather.
+     289             :  */
+     290             : void tommy_list_sort(tommy_list* list, tommy_compare_func* cmp);
+     291             : 
+     292             : /**
+     293             :  * Checks if empty.
+     294             :  * \return If the list is empty.
+     295             :  */
+     296       75392 : tommy_inline tommy_bool_t tommy_list_empty(tommy_list* list)
+     297             : {
+     298       75392 :         return tommy_list_head(list) == 0;
+     299             : }
+     300             : 
+     301             : /**
+     302             :  * Gets the number of elements.
+     303             :  * \note This operation is O(n).
+     304             :  */
+     305         230 : tommy_inline tommy_count_t tommy_list_count(tommy_list* list)
+     306             : {
+     307         230 :         tommy_count_t count = 0;
+     308         230 :         tommy_node* i = tommy_list_head(list);
+     309             : 
+     310        1835 :         while (i) {
+     311        1375 :                 ++count;
+     312        1375 :                 i = i->next;
+     313             :         }
+     314             : 
+     315         230 :         return count;
+     316             : }
+     317             : 
+     318             : /**
+     319             :  * Calls the specified function for each element in the list.
+     320             :  *
+     321             :  * You can use this function to deallocate all the elements
+     322             :  * inserted in a list.
+     323             :  *
+     324             :  * \code
+     325             :  * tommy_list list;
+     326             :  *
+     327             :  * // initializes the list
+     328             :  * tommy_list_init(&list);
+     329             :  *
+     330             :  * ...
+     331             :  *
+     332             :  * // creates an object
+     333             :  * struct object* obj = malloc(sizeof(struct object));
+     334             :  *
+     335             :  * ...
+     336             :  *
+     337             :  * // insert it in the list
+     338             :  * tommy_list_insert_tail(&list, &obj->node, obj);
+     339             :  *
+     340             :  * ...
+     341             :  *
+     342             :  * // deallocates all the objects iterating the list
+     343             :  * tommy_list_foreach(&list, free);
+     344             :  * \endcode
+     345             :  */
+     346        6813 : tommy_inline void tommy_list_foreach(tommy_list* list, tommy_foreach_func* func)
+     347             : {
+     348        6813 :         tommy_node* node = tommy_list_head(list);
+     349             : 
+     350     3687976 :         while (node) {
+     351     3674350 :                 void* data = node->data;
+     352     3674350 :                 node = node->next;
+     353     3674350 :                 func(data);
+     354             :         }
+     355        6813 : }
+     356             : 
+     357             : /**
+     358             :  * Calls the specified function with an argument for each element in the list.
+     359             :  */
+     360             : tommy_inline void tommy_list_foreach_arg(tommy_list* list, tommy_foreach_arg_func* func, void* arg)
+     361             : {
+     362             :         tommy_node* node = tommy_list_head(list);
+     363             : 
+     364             :         while (node) {
+     365             :                 void* data = node->data;
+     366             :                 node = node->next;
+     367             :                 func(arg, data);
+     368             :         }
+     369             : }
+     370             : 
+     371             : #endif
+     372             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommytypes.h.func-sort-c.html b/cov/tommyds/tommytypes.h.func-sort-c.html new file mode 100644 index 00000000..d6f9615e --- /dev/null +++ b/cov/tommyds/tommytypes.h.func-sort-c.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommytypes.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommytypes.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:44100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_ilog2_u3258148940
tommy_ctz_u321403
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommytypes.h.func.html b/cov/tommyds/tommytypes.h.func.html new file mode 100644 index 00000000..ac3428be --- /dev/null +++ b/cov/tommyds/tommytypes.h.func.html @@ -0,0 +1,80 @@ + + + + + + + LCOV - lcov.info - tommyds/tommytypes.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommytypes.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:44100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
tommy_ctz_u321403
tommy_ilog2_u3258148940
+
+
+ + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/tommyds/tommytypes.h.gcov.html b/cov/tommyds/tommytypes.h.gcov.html new file mode 100644 index 00000000..0dec834b --- /dev/null +++ b/cov/tommyds/tommytypes.h.gcov.html @@ -0,0 +1,486 @@ + + + + + + + LCOV - lcov.info - tommyds/tommytypes.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - tommyds - tommytypes.h (source / functions)HitTotalCoverage
Test:lcov.infoLines:44100.0 %
Date:2015-05-12Functions:22100.0 %
+
+ + + + + + + + +

+
          Line data    Source code
+
+       1             : /*
+       2             :  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
+       3             :  *
+       4             :  * Redistribution and use in source and binary forms, with or without
+       5             :  * modification, are permitted provided that the following conditions
+       6             :  * are met:
+       7             :  *
+       8             :  * 1. Redistributions of source code must retain the above copyright
+       9             :  *    notice, this list of conditions and the following disclaimer.
+      10             :  *
+      11             :  * 2. Redistributions in binary form must reproduce the above copyright
+      12             :  *    notice, this list of conditions and the following disclaimer in the
+      13             :  *    documentation and/or other materials provided with the distribution.
+      14             :  *
+      15             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+      16             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+      17             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+      18             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+      19             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+      20             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+      21             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+      22             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+      23             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+      24             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+      25             :  * POSSIBILITY OF SUCH DAMAGE.
+      26             :  */
+      27             : 
+      28             : /** \file
+      29             :  * Generic types.
+      30             :  */
+      31             : 
+      32             : #ifndef __TOMMYTYPES_H
+      33             : #define __TOMMYTYPES_H
+      34             : 
+      35             : /******************************************************************************/
+      36             : /* types */
+      37             : 
+      38             : #include <stddef.h>
+      39             : 
+      40             : #if defined(_MSC_VER)
+      41             : typedef unsigned tommy_uint32_t; /**< Generic uint32_t type. */
+      42             : typedef unsigned _int64 tommy_uint64_t; /**< Generic uint64_t type. */
+      43             : typedef size_t tommy_uintptr_t; /**< Generic uintptr_t type. */
+      44             : #else
+      45             : #include <stdint.h>
+      46             : typedef uint32_t tommy_uint32_t; /**< Generic uint32_t type. */
+      47             : typedef uint64_t tommy_uint64_t; /**< Generic uint64_t type. */
+      48             : typedef uintptr_t tommy_uintptr_t; /**< Generic uintptr_t type. */
+      49             : #endif
+      50             : typedef size_t tommy_size_t; /**< Generic size_t type. */
+      51             : typedef ptrdiff_t tommy_ptrdiff_t; /**< Generic ptrdiff_t type. */
+      52             : typedef int tommy_bool_t; /**< Generic boolean type. */
+      53             : 
+      54             : /**
+      55             :  * Generic unsigned integer type.
+      56             :  *
+      57             :  * It has no specific size, as is used to store only small values.
+      58             :  * To make the code more efficient, a full 32 bit integer is used.
+      59             :  */
+      60             : typedef tommy_uint32_t tommy_uint_t;
+      61             : 
+      62             : /**
+      63             :  * Generic unsigned integer for counting objects.
+      64             :  *
+      65             :  * TommyDS doesn't support more than 2^32-1 objects.
+      66             :  */
+      67             : typedef tommy_uint32_t tommy_count_t;
+      68             : 
+      69             : /** \internal
+      70             :  * Type cast required for the C++ compilation.
+      71             :  * When compiling in C++ we cannot convert a void* pointer to another pointer.
+      72             :  * In such case we need an explicit cast.
+      73             :  */
+      74             : #ifdef __cplusplus
+      75             : #define tommy_cast(type, value) static_cast<type>(value)
+      76             : #else
+      77             : #define tommy_cast(type, value) (value)
+      78             : #endif
+      79             : 
+      80             : /******************************************************************************/
+      81             : /* heap */
+      82             : 
+      83             : /* by default uses malloc/calloc/realloc/free */
+      84             : 
+      85             : /**
+      86             :  * Generic malloc(), calloc(), realloc() and free() functions.
+      87             :  * Redefine them to what you need. By default they map to the C malloc(), calloc(), realloc() and free().
+      88             :  */
+      89             : #if !defined(tommy_malloc) || !defined(tommy_calloc) || !defined(tommy_realloc) || !defined(tommy_free)
+      90             : #include <stdlib.h>
+      91             : #endif
+      92             : #if !defined(tommy_malloc)
+      93             : #define tommy_malloc malloc
+      94             : #endif
+      95             : #if !defined(tommy_calloc)
+      96             : #define tommy_calloc calloc
+      97             : #endif
+      98             : #if !defined(tommy_realloc)
+      99             : #define tommy_realloc realloc
+     100             : #endif
+     101             : #if !defined(tommy_free)
+     102             : #define tommy_free free
+     103             : #endif
+     104             : 
+     105             : /******************************************************************************/
+     106             : /* modificators */
+     107             : 
+     108             : /** \internal
+     109             :  * Definition of the inline keyword if available.
+     110             :  */
+     111             : #if !defined(tommy_inline)
+     112             : #if defined(_MSC_VER) || defined(__GNUC__)
+     113             : #define tommy_inline static __inline
+     114             : #else
+     115             : #define tommy_inline static
+     116             : #endif
+     117             : #endif
+     118             : 
+     119             : /** \internal
+     120             :  * Definition of the restrict keyword if available.
+     121             :  */
+     122             : #if !defined(tommy_restrict)
+     123             : #if __STDC_VERSION__ >= 199901L
+     124             : #define tommy_restrict restrict
+     125             : #elif defined(_MSC_VER) || defined(__GNUC__)
+     126             : #define tommy_restrict __restrict
+     127             : #else
+     128             : #define tommy_restrict
+     129             : #endif
+     130             : #endif
+     131             : 
+     132             : /** \internal
+     133             :  * Hints the compiler that a condition is likely true.
+     134             :  */
+     135             : #if !defined(tommy_likely)
+     136             : #if defined(__GNUC__)
+     137             : #define tommy_likely(x) __builtin_expect(!!(x), 1)
+     138             : #else
+     139             : #define tommy_likely(x) (x)
+     140             : #endif
+     141             : #endif
+     142             : 
+     143             : /** \internal
+     144             :  * Hints the compiler that a condition is likely false.
+     145             :  */
+     146             : #if !defined(tommy_unlikely)
+     147             : #if defined(__GNUC__)
+     148             : #define tommy_unlikely(x) __builtin_expect(!!(x), 0)
+     149             : #else
+     150             : #define tommy_unlikely(x) (x)
+     151             : #endif
+     152             : #endif
+     153             : 
+     154             : /******************************************************************************/
+     155             : /* key */
+     156             : 
+     157             : /**
+     158             :  * Key type used in indexed data structures to store the key or the hash value.
+     159             :  */
+     160             : typedef tommy_uint32_t tommy_key_t;
+     161             : 
+     162             : /**
+     163             :  * Bits into the ::tommy_key_t type.
+     164             :  */
+     165             : #define TOMMY_KEY_BIT (sizeof(tommy_key_t) * 8)
+     166             : 
+     167             : /******************************************************************************/
+     168             : /* node */
+     169             : 
+     170             : /**
+     171             :  * Data structure node.
+     172             :  * This node type is shared between all the data structures and used to store some
+     173             :  * info directly into the objects you want to store.
+     174             :  *
+     175             :  * A typical declaration is:
+     176             :  * \code
+     177             :  * struct object {
+     178             :  *     tommy_node node;
+     179             :  *     // other fields
+     180             :  * };
+     181             :  * \endcode
+     182             :  */
+     183             : typedef struct tommy_node_struct {
+     184             :         /**
+     185             :          * Next node.
+     186             :          * The tail node has it at 0, like a 0 terminated list.
+     187             :          */
+     188             :         struct tommy_node_struct* next;
+     189             : 
+     190             :         /**
+     191             :          * Previous node.
+     192             :          * The head node points to the tail node, like a circular list.
+     193             :          */
+     194             :         struct tommy_node_struct* prev;
+     195             : 
+     196             :         /**
+     197             :          * Pointer at the object containing the node.
+     198             :          * This field is initialized when inserting nodes into a data structure.
+     199             :          */
+     200             :         void* data;
+     201             : 
+     202             :         /**
+     203             :          * Key used to store the node.
+     204             :          * With hashtables this field is used to store the hash value.
+     205             :          * With lists this field is not used.
+     206             :          */
+     207             :         tommy_key_t key;
+     208             : } tommy_node;
+     209             : 
+     210             : /******************************************************************************/
+     211             : /* compare */
+     212             : 
+     213             : /**
+     214             :  * Compare function for elements.
+     215             :  * \param obj_a Pointer at the first object to compare.
+     216             :  * \param obj_b Pointer at the second object to compare.
+     217             :  * \return <0 if the first element is less than the second, ==0 equal, >0 if greather.
+     218             :  *
+     219             :  * This function is like the C strcmp().
+     220             :  *
+     221             :  * \code
+     222             :  * struct object {
+     223             :  *     tommy_node node;
+     224             :  *     int value;
+     225             :  * };
+     226             :  *
+     227             :  * int compare(const void* obj_a, const void* obj_b)
+     228             :  * {
+     229             :  *     if (((const struct object*)obj_a)->value < ((const struct object*)obj_b)->value)
+     230             :  *         return -1;
+     231             :  *     if (((const struct object*)obj_a)->value > ((const struct object*)obj_b)->value)
+     232             :  *         return 1;
+     233             :  *     return 0;
+     234             :  * }
+     235             :  *
+     236             :  * tommy_list_sort(&list, compare);
+     237             :  * \endcode
+     238             :  *
+     239             :  */
+     240             : typedef int tommy_compare_func(const void* obj_a, const void* obj_b);
+     241             : 
+     242             : /**
+     243             :  * Search function for elements.
+     244             :  * \param arg Pointer at the value to search.
+     245             :  * \param obj Pointer at the object to compare to.
+     246             :  * \return ==0 if the value matches the element. !=0 if different.
+     247             :  *
+     248             :  * Note that the first argument is a pointer to the value to search and
+     249             :  * the second one is a pointer to the object to compare.
+     250             :  * They are pointers of two different types.
+     251             :  *
+     252             :  * \code
+     253             :  * struct object {
+     254             :  *     tommy_node node;
+     255             :  *     int value;
+     256             :  * };
+     257             :  *
+     258             :  * int compare(const void* arg, const void* obj)
+     259             :  * {
+     260             :  *     return *(const int*)arg != ((const struct object*)obj)->value;
+     261             :  * }
+     262             :  *
+     263             :  * int value_to_find = 1;
+     264             :  * struct object* obj = tommy_hashtable_search(&hashtable, compare, &value_to_find, tommy_inthash_u32(value_to_find));
+     265             :  * if (!obj) {
+     266             :  *     // not found
+     267             :  * } else {
+     268             :  *     // found
+     269             :  * }
+     270             :  * \endcode
+     271             :  *
+     272             :  */
+     273             : typedef int tommy_search_func(const void* arg, const void* obj);
+     274             : 
+     275             : /**
+     276             :  * Foreach function.
+     277             :  * \param obj Pointer at the object to iterate.
+     278             :  *
+     279             :  * A typical example is to use free() to deallocate all the objects in a list.
+     280             :  * \code
+     281             :  * tommy_list_foreach(&list, (tommy_foreach_func*)free);
+     282             :  * \endcode
+     283             :  */
+     284             : typedef void tommy_foreach_func(void* obj);
+     285             : 
+     286             : /**
+     287             :  * Foreach function with an argument.
+     288             :  * \param arg Pointer at a generic argument.
+     289             :  * \param obj Pointer at the object to iterate.
+     290             :  */
+     291             : typedef void tommy_foreach_arg_func(void* arg, void* obj);
+     292             : 
+     293             : /******************************************************************************/
+     294             : /* bit hacks */
+     295             : 
+     296             : #if defined(_MSC_VER) && !defined(__cplusplus)
+     297             : #include <intrin.h>
+     298             : #pragma intrinsic(_BitScanReverse)
+     299             : #pragma intrinsic(_BitScanForward)
+     300             : #endif
+     301             : 
+     302             : /** \internal
+     303             :  * Integer log2 for constants.
+     304             :  * You can use it only for exact power of 2 up to 256.
+     305             :  */
+     306             : #define TOMMY_ILOG2(value) ((value) == 256 ? 8 : (value) == 128 ? 7 : (value) == 64 ? 6 : (value) == 32 ? 5 : (value) == 16 ? 4 : (value) == 8 ? 3 : (value) == 4 ? 2 : (value) == 2 ? 1 : 0)
+     307             : 
+     308             : /**
+     309             :  * Bit scan reverse or integer log2.
+     310             :  * Return the bit index of the most significant 1 bit.
+     311             :  *
+     312             :  * If no bit is set, the result is undefined.
+     313             :  * To force a return 0 in this case, you can use tommy_ilog2_u32(value | 1).
+     314             :  *
+     315             :  * Other interesting ways for bitscan are at:
+     316             :  *
+     317             :  * Bit Twiddling Hacks
+     318             :  * http://graphics.stanford.edu/~seander/bithacks.html
+     319             :  *
+     320             :  * Chess Programming BitScan
+     321             :  * http://chessprogramming.wikispaces.com/BitScan
+     322             :  *
+     323             :  * \param value Value to scan. 0 is not allowed.
+     324             :  * \return The index of the most significant bit set.
+     325             :  */
+     326    58148940 : tommy_inline tommy_uint_t tommy_ilog2_u32(tommy_uint32_t value)
+     327             : {
+     328             : #if defined(_MSC_VER)
+     329             :         unsigned long count;
+     330             :         _BitScanReverse(&count, value);
+     331             :         return count;
+     332             : #elif defined(__GNUC__)
+     333             :         /*
+     334             :          * GCC implements __builtin_clz(x) as "__builtin_clz(x) = bsr(x) ^ 31"
+     335             :          *
+     336             :          * Where "x ^ 31 = 31 - x", but gcc does not optimize "31 - __builtin_clz(x)" to bsr(x),
+     337             :          * but generates 31 - (bsr(x) xor 31).
+     338             :          *
+     339             :          * So we write "__builtin_clz(x) ^ 31" instead of "31 - __builtin_clz(x)",
+     340             :          * to allow the double xor to be optimized out.
+     341             :          */
+     342    58148940 :         return __builtin_clz(value) ^ 31;
+     343             : #else
+     344             :         /* Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup */
+     345             :         /* from http://graphics.stanford.edu/~seander/bithacks.html */
+     346             :         static unsigned char TOMMY_DE_BRUIJN_INDEX_ILOG2[32] = {
+     347             :                 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
+     348             :                 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
+     349             :         };
+     350             : 
+     351             :         value |= value >> 1;
+     352             :         value |= value >> 2;
+     353             :         value |= value >> 4;
+     354             :         value |= value >> 8;
+     355             :         value |= value >> 16;
+     356             : 
+     357             :         return TOMMY_DE_BRUIJN_INDEX_ILOG2[(tommy_uint32_t)(value * 0x07C4ACDDU) >> 27];
+     358             : #endif
+     359             : }
+     360             : 
+     361             : /**
+     362             :  * Bit scan forward or trailing zero count.
+     363             :  * Return the bit index of the least significant 1 bit.
+     364             :  *
+     365             :  * If no bit is set, the result is undefined.
+     366             :  * \param value Value to scan. 0 is not allowed.
+     367             :  * \return The index of the least significant bit set.
+     368             :  */
+     369        1403 : tommy_inline tommy_uint_t tommy_ctz_u32(tommy_uint32_t value)
+     370             : {
+     371             : #if defined(_MSC_VER)
+     372             :         unsigned long count;
+     373             :         _BitScanForward(&count, value);
+     374             :         return count;
+     375             : #elif defined(__GNUC__)
+     376        1403 :         return __builtin_ctz(value);
+     377             : #else
+     378             :         /* Count the consecutive zero bits (trailing) on the right with multiply and lookup */
+     379             :         /* from http://graphics.stanford.edu/~seander/bithacks.html */
+     380             :         static const unsigned char TOMMY_DE_BRUIJN_INDEX_CTZ[32] = {
+     381             :                 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+     382             :                 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+     383             :         };
+     384             : 
+     385             :         return TOMMY_DE_BRUIJN_INDEX_CTZ[(tommy_uint32_t)(((value & - value) * 0x077CB531U)) >> 27];
+     386             : #endif
+     387             : }
+     388             : 
+     389             : /**
+     390             :  * Rounds up to the next power of 2.
+     391             :  * For the value 0, the result is undefined.
+     392             :  * \return The smallest power of 2 not less than the specified value.
+     393             :  */
+     394             : tommy_inline tommy_uint32_t tommy_roundup_pow2_u32(tommy_uint32_t value)
+     395             : {
+     396             :         /* Round up to the next highest power of 2 */
+     397             :         /* from http://www-graphics.stanford.edu/~seander/bithacks.html */
+     398             : 
+     399             :         --value;
+     400             :         value |= value >> 1;
+     401             :         value |= value >> 2;
+     402             :         value |= value >> 4;
+     403             :         value |= value >> 8;
+     404             :         value |= value >> 16;
+     405             :         ++value;
+     406             : 
+     407             :         return value;
+     408             : }
+     409             : #endif
+     410             : 
+
+
+
+ + + + +
Generated by: LCOV version 1.10
+
+ + + diff --git a/cov/updown.png b/cov/updown.png new file mode 100644 index 00000000..aa56a238 Binary files /dev/null and b/cov/updown.png differ diff --git a/design.html b/design.html new file mode 100644 index 00000000..332e77e6 --- /dev/null +++ b/design.html @@ -0,0 +1,113 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+SnapRAID was created following the Unix philosophy: +Write programs that do one thing and do it well. +

+ +

+The first design principle was reliability. +The result is a simple architecture and an easy to understand implementation, +following the Dijkstra +quote Simplicity is prerequisite for reliability. +

+

+Extensive and automated tests with the runtime checker valgrind and +the static analyzer clang are done to ensure the correctness of the final application. +The test has a code coverage of over 90%, measured with lcov. +

+ +

+The second design principle was robustness. +It supports any kind of problem. Even on kernel panics, power-downs +or any other hard failure at runtime, your redundancy data is in safe hands. +
+It uses all the possible storage techniques to ensure to always keep consistent +redundancy even after critical interruptions. +

+ +

+The third design principle was efficiency. +It's a native C application highly optimized using all the +possible OS services to ensure the maximum throughput of you disk array. +

+

+For integrity checks is used the highly efficient murmur3 +and SpookyHash hashes at 128 bits. +For the redundancy computations we use a +RAID library +written from scratch that supports up to six levels of parity delivering top-notch performance. +The library design is originally based, and also binary compatible, +with the Linux Kernel RAID +library made by H. Peter Anvin. +As internal data base it's used the TommyDS library of data structures. +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/download.html b/download.html new file mode 100644 index 00000000..c0b21ec5 --- /dev/null +++ b/download.html @@ -0,0 +1,119 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + + +

+Here you can download SnapRAID. +Take care that it's a command line program, without any GUI interface. +If you like to use a GUI, you can try Elucidate. +

+ + + + + + +
FileDescription
+ +snapraid-8.1.tar.gz + +Sources for Linux, Mac OS X, BSD, Solaris, OpenIndiana and any other Unix +
+ +snapraid-8.1-windows-x64.zip + +Binaries for Windows x64 (the most recent Windows versions) +
+ +snapraid-8.1-windows-x86.zip + +Binaries for Windows x86 +
+ +

+See the ChangeLog for the detailed list of changes. +

+ +

+There are also Ubuntu packages in lauchpad. +

+ +

+SnapRAID is a Free Software +application released with the GPLv3 license. +

+ +

+If you want to show your appreciation, +you can Donate, +or you can star it on GitHub. +Donations are spent on stuffs related to SnapRAID development like to buy new hardware for my PC and internet bills. +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/email.png b/email.png new file mode 100644 index 00000000..2c7284be Binary files /dev/null and b/email.png differ diff --git a/faq.html b/faq.html new file mode 100644 index 00000000..d9075da4 --- /dev/null +++ b/faq.html @@ -0,0 +1,1080 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+Frequently Asked Questions for SnapRAID. +

+ + + +

General

+ + + +

Setup

+ + + +

Configuration

+ + + +

Use

+ + + +

Recover

+ + + +

Tech

+ + + +

Performance

+ + + +

Know Problems

+ + + + +

General

+ +

What's SnapRAID?

+

+SnapRAID is an application able to make a partial backup of your disk array. +If some of the disks of your array fail, even if they are completely broken, you will be able to recover their content. +It's only a partial backup, because it doesn't allow to recover from a failure of the whole array, +but only if the number of failed disks are under a predefined limit. +

+ +

How is it different than RAID?

+

+RAIDs are mirroring solutions that propagate changes immediately to the parity data. +In this sense, RAIDs are not backups, because they don't allow to restore an old state of the array. +

+

+SnapRAID is instead more similar at a backup solution, and you can restore the state of the last backup made. +For example, with SnapRAID, if you delete by accident a file, you can easily restore it. +

+ +

How is it different than ZFS/Btrfs snapshots and NTFS Shadow Copy?

+

+SnapRAID creates a filesystem snapshot conceptually similar at other snapshot solutions. +The difference is that the purpose of SnapRAID is to be able to recover a disk to the saved state +after a complete disk failure. +

+ +

How is it different than other backup solutions?

+

+With a normal backup solution you always need as much space as the full disk array for the backup. +With SnapRAID you need only one additional parity disk to be able to recover the most common case of a single disk failure. +Adding more parity disks, you can recover from more disk failures. +

+

+Note anyway, that only a full backup allows to recover from a complete failure of the disk array and +it's surely the preferred solution if you can afford it. +SnapRAID is a good option only if a full backup is not a possible solution. +

+ +

What are the advantages of SnapRAID compared to similar solutions like unRAID/FlexRAID/Windows Storage Spaces?

+

+You can see the Compare page to see it compared to other similar solutions. +In short, SnapRAID is reliable, OpenSource, multi-platform and free. +

+ +

How much does it cost?

+

+Nothing. It's a FreeSoftware application released with the GPLv3 license. +

+ +

How to get support?

+

+Go to the Forum. +

+ +

Has SnapRAID a GUI?

+

+No. SnapRAID is a command line application. +But there is the Elucidate external GUI, +and a plugin for OpenMediaVault. +

+ +

Does SnapRAID provide encryption, virtual views/storage pooling, SMART monitoring and Power control?

+

+SnapRAID provides a basic virtual views/storage pooling solution, but it's also compatible +with any other pooling solutions. +

+

+For encryption, SMART monitoring, Power control and Data Recovery you can use other tools. +Here some suggestions: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LinuxWindowsMac OS X
Encryption +dmcrypt/LUKS
+(tutorial)
+ +FreeOTFE + +
Virtual views/storage poolingmhddfs +(tutorial), +aufs, +Greyhole + +Liquesce (free, BETA), +DrivePool ($$), + +PoolHD ($$), +DriveBender ($$) + + +
SMART monitorsmartmontools, +GSmartControl +smartmontools, +GSmartControl, +CrystalDiskInfo +smartmontools, +GSmartControl, +SMARTReporter +
Power Controlhdparmhdparm
Data recovering +ddrescue, +safecopy, +dd_rescue +
+

+ +

Is SnapRAID suitable to backup the home/My Documents directory?

+

+No. If you have a limited amount of data that can be easily saved in an external USB HD, +or in online backup services, it doesn't make sense to use SnapRAID. +SnapRAID should be used when you have to backup a very large amount of data, +many Tera bytes, and a full backup copy of a such amount of data is not possible +in any other way. +

+ +

Is SnapRAID suitable to backup the boot OS disk?

+

+No. For the disk used for booting your machine and containing the OS files, +it's better to use another solution, like RAID1 or a mirror copy. +SnapRAID needs an OS to run, and then it cannot recover the OS if the OS is missing. +

+ +

Setup

+ +For a setup example in Ubuntu 14.04 you can check the SnapRAID Zack's tutorial. + +

Do I need one or more parity disks?

+

+As a rule of thumb you can stay with one parity disk (RAID5) with up to four data disks, +and then using one parity disk for each group of seven data disks, like in the table: + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
ParitiesData disks
1/Single Parity/RAID52 - 4
2/Double Parity/RAID65 - 14
3/Triple Parity15 - 21
4/Quad Parity22 - 28
5/Penta Parity29 - 35
6/Hexa Parity36 - 42
+

+ +

+This table takes into account that more parity levels also help to recover from unsynced array, +and that likely you are running all the disks in the same box and environment, meaning that +their failures could be correlated. +

+ +

+Take care that multiple failures happen. At now the worst case reported in the SnapRAID history, +is a four disks failure, succesfully recovered using four parities. +

+ +

+Some interesting articles about number of parity levels and failure rate of disks are: +Why RAID 5 stops working in 2009, +Why RAID 6 stops working in 2019, +Does RAID 6 stop working in 2019?, +Triple-Parity RAID and Beyond, +How long do disk drives last?. +

+ +

Which filesystem is recommended for SnapRAID ?

+For the data disks, you can use whatever filesystem you like. +For the parity disks, follow these suggestions: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileSystemResult
ext4OK
ext3No. It doesn't support the fallocate() command needed to allocated the parity files. +You can anyway use it if you limit the use of the parity disk to contain only the parity file. +
XFSOK
JFSNo. It doesn't support the fallocate() command needed to allocated the parity files. +
+It also doesn't seem to implement at the best the posix_fadvise() command.
ReiserFSUnsure. Where are user reports reporting speed increase when switching from ReiserFS to other filesystem. +
NTFSOK in Windows. No in Linux, as it doesn't support fallocate() command needed to allocated the parity files. +You can anyway use it if you limit the use of the parity disk to contain only the parity file. +
FATNo. You cannot store files bigger than 4 GB. It's also not journaled. Use NTFS instead.
HFS+OK
+

+

+In Linux, to get more space for the parity, it's recommended to format the parity filesystem with the -m 0 -T largefile4 options. +Like:

mkfs.ext4 -m 0 -T largefile4 DEVICE
+

+ +

Which hardware configuration is recommended?

+

+For best performance it's recommended to have all the disks connected with SATA and not with USB. +

+

+Check Raj's Prototype Builds +for some examples of hardware setups. +

+

+For choosing harddisk, you can check Backblaze's What Hard Drive Should I Buy?, +and Backblaze's Enterprise Drives: Fact or Fiction?. +

+ +

Is a multi-core CPU recommended?

+

+No. SnapRAID is usually not CPU bound. The limiting factor is the read performance from disks. +So, also a single core CPU should be enough.
+For example, in my system I get a combined read speed of 400 MiB/s, +but SnapRAID is able to hash at 12000 MiB/s in a single core. +

+ +

Is a 64 bit operating system recommended?

+

+Yes. SnapRAID works better in a 64 bit operating system. It can access more than 4 GiB of memory, +and use faster hashing and parity algorithms. +Anyway, if you have less than 30 TB of data, it performs very well also using a 32 bit +operating system. +

+ +

How much memory SnapRAID requires to run?

+

+Approximatively, the 32 bits version of SnapRAID requires 1 GiB of memory for 9 TB of data. +The 64 bits version requires 1 GiB of memory for 7 TB of data. +

+

+If you have less memory than required, the recommended option is to install more memory in the machine. +

+

+Otherwise you have to increase the block_size option in the configuration file. +The memory occupation is inversely proportional at the select block_size. +For example, using "block_size 512", instead of the default 256, halves the memory occupation. +But take care that using a bigger block size will also increase the amount of wasted space +in the parity files. +

+

+Note that running with memory swapped to disk is not recommended because it will be a huge slowdown. +

+ +

Do I have to check the SMART attributes of my disks?

+

+Yes! 20% of the disks die before 4 years of life, as +reported by Backblaze's How long do disk drives last?. +Monitoring SMART attributes you can anticipate the failures and avoid to lose data! +

+

+If you see one of the SMART attributes +Reallocated_Sector_Ct (5), +Reported_Uncorrect (187), +Command_Timeout (188), +Current_Pending_Sector (197), +and Offline_Uncorrectable (198) +different than zero, replace the disk as recommended by +Backblaze's Hard Drive SMART Stats. +

+

+Check also Google's Failure trends in a large disk drive population +where is found that: +

after the first reallocation, drives are
+over 14 times more likely to fail within
+60 days than drives without reallocation
+counts.
+
after the first probational event, drives
+are 16 times more likely to fail within
+60 days than drives with zero probational
+counts.
+
after the first offline reallocation, drives have over
+21 times higher chances of failure within 60 days than
+drives without offline reallocations.
+

+that also recommens to replace the disk after the first error in the SMART attributes Reallocated_Sector_Ct (5), +Current_Pending_Sector (197) and Offline_Uncorrectable (198). + +

Is it possible to use SnapRAID in a dual boot configuration, like Windows and Linux?

+

+Yes. It's possible to use SnapRAID in a dual boot configuration. Doesn't matter the OS combination used. +

+

+In such case it's recommended to run SnapRAID only from one OS. +In theory, it should also work if run in both OS. +But it's a scenario not really tested, and there is always the risk to mess-up things, +like using different SnapRAID version, configuration, content files, and so on. +

+ +

Configuration

+ +

What's the SnapRAID 'content' file?

+

+It's the file used by SnapRAID to save the list of all files present in your array with +all the checksum, timestamp and any other information needed. +

+

+These file will be of about few GiB depending of how big is your array. +Approximatively for 10 TB of data, you'll need 500 MiB of content file. +

+ +

What are the SnapRAID 'parity' and 'N-parity' files?

+

+They are the files used by SnapRAID to store the parity data used in recovering. +

+

+These files will grow in size as the biggest amount of data stored in a single disk +of the array. +

+ +

How to configure SAMBA to share the Pool directory

+

+To configure SAMBA to share the pool directory, for example /pool, you should add to +your /etc/samba/smb.conf the following options: +

+
+# In the global section of smb.conf
+unix extensions = no
+
+# In the share section of smb.conf
+[pool]
+comment = Pool
+path = /pool
+read only = yes
+guest ok = yes
+wide links = yes
+
+ +

How to use more disks than drive letters in Windows?

+

+You can use Volume Mount points. You can mount a disk in a directory without +using a drive letter. Just like in Linux. +

+ +

Use

+ +

What are the most important things to do to prevent damages?

+

+If you want to minimize the probability to lose data, do this: +

+

+ +

How can I add an additional data disk to an existing array?

+

+To add a new data disk at the array, add the new "disk" option in the configuration file, +and then run a "sync" command. +

+snapraid sync
+
+

+ +

How can I remove a data disk from an existing array?

+

+To remove a data disk from the array do: +

+ +

+Your array is now without any reference to the removed disk. +

+ +

How can I add an additional parity disk to an existing array?

+

+To add a new parity level, add the proper "N-parity" option in the configuration file, and then run the "sync" command, +using the "F, --force-full" option: +

+snapraid -F sync
+
+The "-F" option tells at SnapRAID to recompute the full parity. +

+

+Note that in the process, you will be always protected, because the existing parity is not modified. +

+

+If you wish to remove a parity, you can simply remove the highest +"N-parity" option from the configuration and then delete the parity file. +

+

+Take care that after removing a parity file, you cannot reuse it anymore, +because it gets outdated after the next "sync" command. +

+ +

How can I replace a data disk?

+

+If you lost the disk, see the recovering section in the manual. +Otherwise, copy all the files in the new disk, +maintaining the same directory structure and names. +

+

+Then change the SnapRAID configuration to point the disk at the new mount point and run a "diff" +command to ensure that everything is placed correctly. +

+snapraid diff
+
+If "diff" reports some "added" or "removed" files likely you have copied files +with a different directory structure. +In such case you have to fix it, until "diff" reports only "equal", "restored" or "copied" files. +

+

+Now you can check that the files were really copied correctly, you can run a "check" audit command +limited to the replaced disk to check the checksum of all the files. +

+snapraid check -a -d DISK_NAME
+
+

+

+Finally you can run "sync" to update the SnapRAID state. This command will be almost immediate. +

+snapraid sync
+
+

+ +

How can I replace a parity disk?

+

+If the disk is still accessible, first ensure to have a synched array running a sync command: +

+snapraid sync
+
+

+

+Then you can copy the big parity file to the new disk, +and configure the new parity location in the configuration file. +

+

+In Linux a good copy command is ddrescue. +You can use: +

+ddrescue /OLD_DISK/parity /NEW_DISK/parity /tmp/copy.log
+
+This will copy the parity file from the old to new location, and in case of errors, +it will continue copying what can be copied. +To retry to copy the problematic sections, you can just retry the same copy +command. +

+

+Having a partial parity file, is still beneficial, as it will still allow to recover +data as long it uses the valid part. To restore it to full functionality, +just run a "fix" command. +

+

+If instead you completely lost the parity file, you can run the "fix" command to recreate it. +

+snapraid fix
+
+

+

Can I defragment the data and parity disks?

+

+Yes, you can defragment data and parity disks. Defragmentation doesn't invalidate the SnapRAID data. +

+ +

How can I upgrade to a newer version of SnapRAID ?

+

+To upgrade SnapRAID to a new version, just replace the old SnapRAID executable with the new one. +The new SnapRAID will use your existing configuration, content and parity files. +

+

+By time to time the format of the content file changes, but a newer SnapRAID +is always able to read all old formats. So, it's always possible to upgrade. +If necessary, the content file format is updated the next time it's written. +

+

+Instead, it's in general not possible to downgrade to an old SnapRAID. +You can anyway try, and if the old SnapRAID is not able to read the new content file, +you will be advised by a proper message. +

+ +

Why TrueCrypt containers are never saved by SnapRAID?

+

+TrueCrypt by default has enabled the option Preserve modification timestamp of file containers +that makes impossible to SnapRAID, and other backup programs, to detect that a file container is changed. +Ensure to disable this option in TrueCrypt. +

+ +

Recover

+ +

How can I undelete a just deleted file?

+

+Simply run the "fix" command using a filter for the specified file. Like: +

+snapraid fix -f my_just_deleted_file
+
+To undelete a directory use: +
+snapraid fix -f my_just_deleted_dir/
+
+To undelete all the missing files use: +
+snapraid fix -m
+
+

+ +

What happen if I add files and a disk breaks before I have updated the parity with "sync"?

+

+All the files added in the broken disk after the last "sync" command are lost. +All the other data is safe and it can be recovered. +

+ +

What happen if I delete files and a disk breaks before I have updated the parity with "sync"?

+

+In the worst case, any file deleted or modified in not broken disks may prevent to recover the same amount of data in the broken disk. +For example, if you deleted 10GB of data, you may not be able to recover 10GB of data from the broken disk. +The exact amount of data lost depends on how much the deleted and broken data overlaps in the parity. +

+

+To reduce this problem you can use two parity disks. This improves a lot the chances to recover the data. +

+

+A way to be always safe, is to don't delete files, but move them to another directory in the same disk, +but outside the directory tree checked by SnapRAID. Then you can run the "sync" command and only after +its completion really delete the files. +In case you get a disk failure during the "sync", you have to just run the "fix" command specifying where +the deleted files are stored: +

+snapraid fix -i dir_of_deleted_files
+
+

+ +

What happen if a disk breaks during a "sync" ?

+

+You are still able to recover data. In the worst case, you will be able to recover as much data as if the +disk would have broken before the "sync". +But if the "sync" process already run for some time, SnapRAID is able to use the partially synced data +to recover more. +To improve the recovering you can also use the "autosave" configuration option to save the intermediate +content file during the sync process. +

+ +

What are and how to fix "Data errors" in "sync"?

+
+Syncing...
+309505: Data error for file d4/data/index.db at position 40960
+WARNING! Unexpected data error in a data disk! The block is now marked as bad!
+Try with 'snapraid -e fix' to recover!
+
+

+Data errors happen when SnapRAID detects that the content of a file changed but the write time of the file didn't. +This is a condition that normally should never happen and it may be the result of a silent error in the disk, +or the signal that something got wrong at the filesystem level, like when you poweroff the machine without a +proper shutdown. +

+

If a data error is found, the "sync" process continues, and erroneous blocks are marked as bad +and fixed at the next "fix" command. +To just fix the silent errors and not the whole array, you can use the "-e fix" command +that usually takes only few seconds. +

+

+If you have errors in more than on file, it's also possible that something is not working at hardware level. +The first thing to try is to check your PC memory with an automated tool like memtest86. +Another thing to check is the disk cabling and the CPU heat. +

+

+Another possibility is that you are using programs that change files without modifying the time-stamp of the file itself. +
+In Linux this is almost guaranteed by the operating system. The only exception is for memory mapped files +not yet closed. +
+In Windows it's a bit trickier. Even using normal writes, you have the guarantee of an updated time-stamp +only after closing it. +See the MSDN WriteFile(): +

+When writing to a file, the last write time is not fully updated until
+all handles used for writing have been closed. Therefore, to ensure an
+accurate last write time, close the file handle immediately after writing
+to the file.
+
+When using memory mapped file, the program must ensure to update the time-stamp manually, +because Windows doesn't do it automatically. +See the MSDN CreateFileMapping(): +
+When modifying a file through a mapped view, the last modification timestamp
+may not be updated automatically. If required, the caller should use SetFileTime
+to set the timestamp.
+
+To avoid all these Windows problems, simply ensure to run "sync" when no program is using the files into the array. +

+ +

How can I store in a file all the messages from a check and fix command

+

+To generate a log file you can use the "-l" option. +

+snapraid check -l mylog.log
+
+

+ +

How can I recover the snapraid.conf file

+

+There is the dedicated -C, --gen-conf command that writes a template configuration file +compatible with your content file. +Note that this configuration requires some manual adjustments to set the disk mount points, +but in the comments you'll find the required information to do so. +

+snapraid -C snapraid.content > snapraid.conf.new
+
+

+ +

Tech

+ +

If the SnapRAID "check" command says it's all OK. Is it really OK?

+Yes. SnapRAID checks all your files with a 128 bit checksum. +If it says that they are correct, they really are. + +

What integrity checksum is used?

+SnapRAID uses Murmur3 and SpookyHash 128 bit hashes. +Murmur3 is the default in 32 bit platforms, SpookyHash in the default for 64 bit ones. + +

Why integrity checksum are important?

+Integrity checksum are important to detect silent errors, +when the HD is returning garbage without reporting any error. + +

+An introduction to this problem is in this article: +Data corruption is worse than you know +

+

+A good analysis of this risk is in the paper: +An Analysis of Data Corruption in the Storage Stack +

+A significant number (8% on average) of corruptions
+are detected during RAID reconstruction, creating the
+possibility of data loss. In this case, protection against
+double disk failures is necessary to prevent data loss.
+
+

+ +

Is SnapRAID multithread?

+

+No. SnapRAID is a single thread application. Considering that SnapRAID is usually not CPU bound, +there is no need to have a multithread application. +Take care that that being singlethread doesn't mean that SnapRAID has to wait when reading data from the disks. +The read-ahead functionality of modern operating systems, ensures that SnapRAID never has to wait for data. +

+ +

How can SnapRAID recover also if a disk break during a 'sync'?

+

+Before the sync process start, SnapRAID saves a special content file that contains +a description of both the states before and after the sync. +This allows SnapRAID to try two different recovery strategies. +

+

+For each block to recover, it first assumes that the parity was correctly computed, +just like if "sync" was completed successfully. +If this recovering fails, it then assumes that parity was not yet updated, +ignoring any new file added in the array. +

+

+Also in this case, using a double parity helps to recover when there are overlapping changes in the array. +

+ +

Does SnapRAID allow to access data disks during a 'sync'?

+

+Yes. You can safely read from data disks while a 'sync' is running. +

+

+You can also write, and if this interferes with the SnapRAID 'sync', +the process will continue anyway, just skipping that written part. +

+

+This obviously could affect a potential recovery, but it's just like if you wrote +just after the 'sync' completed. +

+ +

Does SnapRAID retry reads or writes if a disk is not working?

+

+No. SnapRAID never retries disk operations. At the first reported Input/Output error, +it just stops the execution. +

+

+In these conditions, it's better to allow the user to try to save manually as much as data possible +before the disk dies definitively. +Trying an automatic long sequence of retries, will likely kill the disk. +

+

+If after a such error, you want to retry, you have to just repeat the command. +
+In the case of "fix" and "check" commands you can restart from the interrupted point using the "-s, --start" +option specifying the block number that generated the error. +
+In the case of "sync" command, the latest state is anyway saved before termination. +So, just restarting it will continue where stopped. +

+ +

What's the snapraid.content.lock file?

+

+It's a file used by SnapRAID to check if another SnapRAID instance is already running. +It's created where the first content file is placed. +

+ +

Performance

+ +

Which is the optimal hardware configuration to get the best performance?

+The most important factor is to connect all the disks using (E)SATA connections, +to avoid slowdown caused by the controller. Avoid any kind of USB disks. +
+The second important factor is use disks with similar performance, because the read/write +speed is limited by the slowest disk of the array. +After a sync operation, it's printed a short stats with the wait times for each disk, +that could help to identify a bottleneck caused by a slow disk. +
+As last, a fast CPU could improve the speed when having a lot of disks. +You can detect if the CPU is a limiting factor, checking the CPU usage during sync operations. +
+ +

Which is the optimal blocksize to get the best performance?

+The default blocksize should be already the best one. +
+Note that increasing it doesn't necessarely improve the performance. +In some cases, it could decrease it. + +

Which is the optimal Linux read-ahead size to get the best performance?

+The default Linux read-ahead size of 128 KiB already ensures the best performance +for the default SnapRAID block size of 256 KiB. +If you use a bigger block size, you should configure the read-ahead size to be at least equal +to half of the SnapRAID block size. +
+For example, if you want to use a SnapRAID block size of 512 KiB, +it's recommended to configure a read-ahead size of 256 KiB for sdX using: +
+echo 256 > /sys/block/sdX/queue/read_ahead_kb
+
+Note that if you want to use a SnapRAID block size smaller than 256 KiB, it's recommended to don't configure a specific +read-ahead size, and just use the default value. + +

How fast are the hash and parity computation?

+

+Murmur3 hash is very fast on 32 bits, SpookyHash is even faster on 64 bits. +The speed of parity computation is always good up to double parity, +even in architectures without SSE support. +Beyond double parity having a CPU with SSSE3 support is recommended. +For low end CPUs without SSE, there is a special, but incompatible, triple parity +support working well also without SSE. +See 'z-parity' in the manual for more info. +

+

+The following are the result on a Core i5-4670K @ 3.4 GHz. +You can check your values with the -T option. +

+
+root@redstar:/root# snapraid  -T
+snapraid v7.0 by Andrea Mazzoleni, http://www.snapraid.it
+Compiler gcc 4.8.1
+CPU GenuineIntel, family 6, model 60, flags mmx sse2 ssse3 sse42 avx2
+Memory is little-endian 64-bit
+Support nanosecond timestamps with futimens()
+
+Speed test using 8 data buffers of 262144 bytes, for a total of 2048 KiB.
+Memory blocks have a displacement of 1792 bytes to improve cache performance.
+The reported values are the aggregate bandwidth of all data blocks in MiB/s,
+not counting parity blocks.
+
+Memory write speed using the C memset() function:
+  memset   22233
+
+CRC used to check the content file integrity:
+   table    1261
+   intel    9306
+
+Hash used to check the data blocks integrity:
+            best murmur3 spooky2
+    hash spooky2    4715   14684
+
+RAID functions used for computing the parity with 'sync':
+            best    int8   int32   int64    sse2   sse2e   ssse3  ssse3e    avx2   avx2e
+    gen1    avx2           13339   25438   45438                           50588
+    gen2    avx2            4115    6514   19441   21840                   32201
+    genz   avx2e            2337    2874    9803   10920                           18944
+    gen3   avx2e     814                                    8934   10154           18613
+    gen4   avx2e     620                                    6204    7569           14229
+    gen5   avx2e     496                                    4777    5149           10051
+    gen6   avx2e     413                                    3846    4239            8190
+
+RAID functions used for recovering with 'fix':
+            best    int8   ssse3    avx2
+    rec1    avx2    1158    2916    3019
+    rec2    avx2     517    1220    1633
+    rec3    avx2     110     611     951
+    rec4    avx2      71     395     631
+    rec5    avx2      49     264     421
+    rec6    avx2      36     194     316
+
+ +

Know Problems

+ +

In Linux SnapRAID aborts without any error message

+

+Likely you have too few free memory, and the Linux out-of-memory OOM killer terminates SnapRAID +because it's using too much memory. +You can use the free command to check how much free memory you have. +

+free -m
+
+If it's too small, you have to install more memory in the machine. +

+ +

Running 'sync' I get the error 'Failed to grow parity file 'xxx' to size xxx due lack of space.'

+

+This means that SnapRAID needs to grow the parity file to a size that cannot be contained in the +parity disk. +

+

+The first thing to check is to ensure that no other data is stored in the parity disk. +Leave if only for the parity file. +Otherwise you have to move the files mentioned in the output to another data disk +to reduce the size of the needed parity. +

+

+If you are using Linux, an alternate approach is to reformat the parity disk using +specific options to increase the available space, like: +

+mkfs.ext4 -m 0 -T largefile4 DEVICE
+
+The '-T largefile4' and '-m 0' options should give more space available for the parity file. +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/github.png b/github.png new file mode 100644 index 00000000..8cb2612a Binary files /dev/null and b/github.png differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..422dc6d2 --- /dev/null +++ b/index.html @@ -0,0 +1,116 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+SnapRAID is a backup program for disk arrays. +It stores parity information of your data and it recovers from up to +six disk failures. +

+ +

+SnapRAID is mainly targeted for a home media center, +with a lot of big files that rarely change. +

+ +

+Beside the ability to recover from disk failures, other +features of SnapRAID are: +

+

+ +

+SnapRAID has also a +SourceForge +and a +GitHub page. +If you need support, ask it in the Forum. +

+ +

+Now go to Download. +

+ +

+News! Version 8.1 RELEASED! +

+ + +
+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + + diff --git a/index.png b/index.png new file mode 100644 index 00000000..f0f7677e Binary files /dev/null and b/index.png differ diff --git a/manual.html b/manual.html new file mode 100644 index 00000000..da164a14 --- /dev/null +++ b/manual.html @@ -0,0 +1,1653 @@ + + + + +SnapRAID + + + + + + + + +
+
+
+About +Download +Design +Compare +FAQ +Manual +Forum +Authors +
+
+ + + + +

+Manual for SnapRAID. +

+ +

1 +Synopsis +

+
+snapraid [-c, --conf CONFIG]
+    [-f, --filter PATTERN] [-d, --filter-disk NAME]
+    [-m, --filter-missing] [-e, --filter-error]
+    [-a, --audit-only] [-h, --pre-hash] [-i, --import DIR]
+    [-p, --percentage PERC] [-o, --older-than DAYS]
+    [-l, --log FILE]
+    [-Z, --force-zero] [-E, --force-empty]
+    [-U, --force-uuid] [-D, --force-device]
+    [-N, --force-nocopy] [-F, --force-full]
+    [-S, --start BLKSTART] [-B, --count BLKCOUNT]
+    [-L, --error-limit NUMBER]
+    [-v, --verbose] [-q, --quiet]
+    status|smart|up|down|diff|sync|scrub|fix|check|list|dup
+    |up|down|pool|devices|rehash
+
+

+

+snapraid [-V, --version] [-H, --help] [-C, --gen-conf CONTENT]
+
+

2 +Description +

+SnapRAID is a backup program for disk arrays. It stores parity +information of your data and it recovers from up to six disk +failures. +

+SnapRAID is mainly targeted for a home media center, with a lot of +big files that rarely change. +

+Beside the ability to recover from disk failures, other +features of SnapRAID are: +

+

+The official site of SnapRAID is: +

+
+
+http://www.snapraid.it/
+
+
+

3 +Limitations +

+SnapRAID is in between a RAID and a Backup program trying to get the best +benefits of them. Although it also has some limitations that you should +consider before using it. +

+The main one is that if a disk fails, and you haven't recently synced, +you may be unable to do a complete recover. +More specifically, you may be unable to recover up to the size of the +amount of the changed or deleted files from the last sync operation. +This happens even if the files changed or deleted are not in the +failed disk. This is the reason because SnapRAID is better suited for +data that rarely change. +

+Instead the new added files don't prevent the recovering of the already +existing files. You may only lose the just added files, if they are on +the failed disk. +

+Other limitations are: +

+

4 +Getting Started +

+To use SnapRAID you need to first select one disk of your disk array +to dedicate at the "parity" information. With one disk for parity you +will be able to recover from a single disk failure, like RAID5. +

+If you want to be able to recover from more disk failures, like RAID6, +you must reserve additional disks for parity. Any additional parity +disk allow to recover from one more disk failure. +

+As parity disks, you have to pick the biggest disks in the array, +as the parity information may grow in size as the biggest data +disk in the array. +

+These disks will be dedicated to store the "parity" files. +You should not store your data in them. +

+Then you have to define the "data" disks that you want to protect +with SnapRAID. The protection is more effective if these disks +contain data that rarely change. For this reason it's better to +DO NOT include the Windows C:\ disk, or the Unix /home, /var and /tmp +disks. +

+The list of files is saved in the "content" files, usually +stored in the data, parity or boot disks. +These files contain the details of your backup, with all the +checksums to verify its integrity. +The "content" file is stored in multiple copies, and each one must +be in a different disk, to ensure that in even in case of multiple +disk failures at least one copy is available. +

+For example, suppose that you are interested only at one parity level +of protection, and that your disks are present in: +

+
+
+/mnt/diskp <- selected disk for parity
+/mnt/disk1 <- first disk to protect
+/mnt/disk2 <- second disk to protect
+/mnt/disk3 <- third disk to protect
+
+
+

+you have to create the configuration file /etc/snapraid.conf with +the following options: +

+
+
+parity /mnt/diskp/snapraid.parity
+content /var/snapraid/snapraid.content
+content /mnt/disk1/snapraid.content
+content /mnt/disk2/snapraid.content
+disk d1 /mnt/disk1/
+disk d2 /mnt/disk2/
+disk d3 /mnt/disk3/
+
+
+

+If you are in Windows, you should use the Windows path format, with drive +letters and backslashes instead of slashes. +

+
+
+parity E:\snapraid.parity
+content C:\snapraid\snapraid.content
+content F:\array\snapraid.content
+content G:\array\snapraid.content
+disk d1 F:\array\
+disk d2 G:\array\
+disk d3 H:\array\
+
+
+

+If you have many disks, and you run out of drive letters, you can mount +disks directly in sub folders. See: +

+
+
+https://www.google.com/search?q=Windows+mount+point
+
+
+

+At this point you are ready to start the "sync" command to build the +parity information. +

+
+
+snapraid sync
+
+
+

+This process may take some hours the first time, depending on the size +of the data already present in the disks. If the disks are empty +the process is immediate. +

+You can stop it at any time pressing Ctrl+C, and at the next run it +will start where interrupted. +

+When this command completes, your data is SAFE. +

+Now you can start using your array as you like, and periodically +update the parity information running the "sync" command. +

4.1 +Scrubbing +

+To periodically check the data and parity for errors, you can +run the "scrub" command. +

+
+
+snapraid scrub
+
+
+

+This command verifies the data in your array comparing it with +the hash computed in the "sync" command. +

+Every run of the command checks about 12% of the array, but not data newer +than 10 days. +You can use the -p, --percentage option to specify a different amount, +and the -o, --older-than option to specify a different age in days. +For example, to check 5% of the array older than 20 days use: +

+
+
+snapraid -p 5 -o 20 scrub
+
+
+

+If during the process, silent or input/output errors are found, +the corresponding blocks are marked as bad in the "content" file, +and listed in the "status" command. +

+
+
+snapraid status
+
+
+

+To fix them, you can use the "fix" command filtering for bad blocks with +the -e, --filter-error options: +

+
+
+snapraid -e fix
+
+
+

+At the next "scrub" the errors will disappear from the "status" report +if really fixed. To make it fast, you can use -p 0 to scrub only blocks +marked as bad. +

+
+
+snapraid -p 0 scrub
+
+
+

+Take care that running "scrub" on a not synced array may result in +errors caused by removed or modified files. These errors are reported +in the "scrub" result, but related blocks are not marked as bad. +

4.2 +Pooling +

+To have all the files in your array shown in the same directory tree, +you can enable "pooling", that consists in creating a virtual view of all +the files in your array using symbolic links. +

+You can configure the "pooling" directory in the configuration file with: +

+
+
+pool /pool
+
+
+

+or, if you are in Windows, with: +

+
+
+pool C:\pool
+
+
+

+and then run the "pool" command to create or update the virtual view. +

+
+
+snapraid pool
+
+
+

+If you are using a Unix platform and you want to share such directory +in the network to either Windows or Unix machines, you should add +to your /etc/samba/smb.conf the following options: +

+
+
+# In the global section of smb.conf
+unix extensions = no
+
+
+

+
+
+# In the share section of smb.conf
+[pool]
+comment = Pool
+path = /pool
+read only = yes
+guest ok = yes
+wide links = yes
+follow symlinks = yes
+
+
+

+In Windows the same sharing operation is not so straightforward, +because Windows shares the symbolic links as they are, and that +requires the network clients to resolve them remotely. +

+To make it working, besides sharing in the network the pool directory, +you must also share all the disks independently, using as share points +the disk names as defined in the config file. You must also specify in +the "share" option of the configure file, the Windows UNC path that remote +clients needs to use to access such shared disks. +

+For example, operating from a server named "darkstar", you can use +the options: +

+
+
+disk d1 F:\array\
+disk d2 G:\array\
+disk d3 H:\array\
+pool C:\pool
+share \\darkstar
+
+
+

+and share the following dirs in the network: +

+
+
+\\darkstar\pool -> C:\pool
+\\darkstar\d1 -> F:\array
+\\darkstar\d2 -> G:\array
+\\darkstar\d3 -> H:\array
+
+
+

+to allow remote clients to access all the files at \\darkstar\\pool. +

+You may also need to configure remote clients, to enable the access at +remote symlinks with the command: +

+
+
+fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1
+
+
+

4.3 +Undeleting +

+SnapRAID is more like a backup program than a RAID system, and it +can be used to restore or undelete files to their previous state using +the -f, --filter option : +

+
+
+snapraid fix -f FILE
+
+
+

+or for a directory: +

+
+
+snapraid fix -f DIR/
+
+
+

+You can also use it to recover only accidentally deleted files inside +a directory using the -m, --filter-missing option, that restores +only missing files, leaving untouched all the others. +

+
+
+snapraid fix -m -f DIR/
+
+
+

+Or to recover all the deleted files in all the drives with: +

+
+
+snapraid fix -m
+
+
+

4.4 +Recovering +

+The worst happened, and you lost a disk! +

+DO NOT PANIC! You will be able to recover it! +

+The first thing you have to do is to avoid further changes at you disk array. +Disable any remote connection to it, any scheduled process, including any +scheduled SnapRAID nightly sync or scrub. +

+Then proceed with the following steps. +

4.4.1 +STEP 1 -> Reconfigure +

+You need some space to recover, even better if you already have an additional +disk, but in case, also an external USB or remote disk is enough. +

+Change the SnapRAID configuration file to make the "disk" option +of the failed disk to point to the place where you have enough empty +space to recover the files. +

+For example, if you have that disk "d1" failed, you can change from: +

+
+
+disk d1 /mnt/disk1/
+
+
+

+to: +

+
+
+disk d1 /mnt/new_spare_disk/
+
+
+

4.4.2 +STEP 2 -> Fix +

+Run the fix command, storing the log in an external file with: +

+
+
+snapraid -d NAME -l fix.log fix
+
+
+

+Where NAME is the name of the disk, like "d1" as in our previous example. +

+This command will take a long time. +

+Take care that you need also few gigabytes free to store the fix.log file. +Run it from a disk with some free space. +

+Now you have recovered all the recoverable. If some file is partially or totally +unrecoverable, it will be renamed adding the ".unrecoverable" extension. +

+You can get a detailed list of all the unrecoverable blocks in the fix.log file +checking all the lines starting with "unrecoverable:" +

+If you are not satisfied of the recovering, you can retry it as many +time you wish. +

+For example, if you have removed files from the array after the last +"sync", this may result in some other files not recovered. +In this case, you can retry the "fix" using the -i, --import option, +specifying where these files are now, to include them again in the +recovering process. +

+If you are satisfied of the recovering, you can now proceed further, +but take care that after syncing you cannot retry the "fix" command +anymore! +

4.4.3 +STEP 3 -> Check +

+As paranoid check, you can now run a "check" command to ensure that +everything is OK on the recovered disk. +

+
+
+snapraid -d NAME -a check
+
+
+

+Where NAME is the name of the disk, like "d1" as in our previous example. +

+The options -d and -a tell SnapRAID to check only the specified disk, +and ignore all the parity data. +

+This command will take a long time, but if you are not paranoid, +you can skip it. +

4.4.4 +STEP 4 -> Sync +

+Run the "sync" command to resynchronize the array with the new disk. +

+
+
+snapraid sync
+
+
+

+If everything is recovered, this command is immediate. +

5 +Commands +

+SnapRAID provides a few simple commands that allow to: + +

+Take care that the commands have to be written in lower case. +

5.1 +status +

+Prints a summary of the state of the disk array. +

+It includes information about the parity fragmentation, how old +are the blocks without checking, and all the recorded silent +errors encountered while scrubbing. +

+Note that the information presented refers at the latest time you +run "sync". Later modifications are not taken into account. +

+If bad blocks were detected, their block numbers are listed. +To fix them, you can use the "fix -e" command. +

+Nothing is modified. +

5.2 +smart +

+Prints a SMART report of all the disks of the array. +

+It includes an estimation of the probability of failure in the next +year allowing to plan maintenance replacements of the disks that show +suspicious attributes. +

+This probability estimation obtained correlating the SMART attributes +of the disks, with the Backblaze data available at: +

+
+
+https://www.backblaze.com/hard-drive-test-data.html
+
+
+

+If SMART reports that a disk is failing, "FAIL" or "PREFAIL" is printed +for that disk, and SnapRAID returns with an error. +In this case an immediate replacement of the disk is highly recommended. +

+Other possible strings are: + + + + +
+logfail + +In the past some attributes were lower than +the threshold. +
+logerr + +The device error log contains errors. +
+selferr + +The device self-test log contains errors. +
+

+If the -v, --verbose option is specified a deeper statistical analysis +is provided. This analysis can help you to decide if you need more +or less parity. +

+This command uses the "smartctl" tool, and it's equivalent to run +"smartctl -a" on all the devices. +

+If your devices are not autodetected correctly, you can configure +a custom command using the "smartctl" option in the configuration +file. +

+Nothing is modified. +

5.3 +up +

+Spins up all the disks of the array. +

+Nothing is modified. +

5.4 +down +

+Spins down all the disks of the array. +

+This command uses the "smartctl" tool, and it's equivalent to run +"smartctl -s standby,now" on all the devices. +

+Nothing is modified. +

5.5 +diff +

+Lists all the files modified from the last "sync" that need to have +their parity data recomputed. +

+This command doesn't check the file data, but only the file timestamp +size and inode. +

+If a "sync" is required, the process return code is 2, instead of the +default 0. The return code 1 is instead for a generic error condition. +

+Nothing is modified. +

5.6 +sync +

+Updates the parity information. All the modified files +in the disk array are read, and the corresponding parity +data is updated. +

+You can stop this process at any time pressing Ctrl+C, +without losing the work already done. +At the next run the "sync" process will start where +interrupted. +

+If during the process, silent or input/output errors are found, +the corresponding blocks are marked as bad. +

+Files are identified by path and/or inode and checked by +size and timestamp. +If the file size or timestamp are different, the parity data +is recomputed for the whole file. +If the file is moved or renamed in the same disk, keeping the +same inode, the parity is no recomputed. +If the file is moved to another disk, the parity is recomputed, +but the previously compute hash information is kept. +

+The "content" and "parity" files are modified if necessary. +The files in the array are NOT modified. +

5.7 +scrub +

+Scrubs the array, checking for silent or input/output errors in data +and parity disks. +

+For each command invocation, the 12% of the array is checked, but +nothing that it's more recent than 10 days. +This means that scrubbing once a week, every bit of data is checked +at least one time every two months. +

+You can use the -p, --percentage option to specify a different amount, +and the -o, --older-than option to specify a different age in days. +You can have a full scrub with "-p 100 -o 0". +

+The oldest blocks are scrubbed first ensuring an optimal check. +

+For any silent or input/output error found the corresponding blocks +are marked as bad in the "content" file. +These bad blocks are listed in "status", and can be fixed with "fix -e". +After the fix, at the next scrub they will be rechecked, and if found +corrected, the bad mark will be removed. +To scrub only the bad blocks, you can use the "scrub -p 0" command. +

+It's recommended to run "scrub" on a synced array, to avoid to have +reported error caused by unsynced data. These errors are recognized +as not being silent errors, and the blocks are not marked as bad, +but such errors are reported in the output of the command. +

+Files are identified only by path, and not by inode. +

+The "content" file is modified to update the time of the last check +of each block, and to mark bad blocks. +The "parity" files are NOT modified. +The files in the array are NOT modified. +

5.8 +fix +

+Fix all the files and the parity data. +

+All the files and the parity data are compared with the snapshot +state saved in the last "sync". +If a difference is found, it's reverted to the stored snapshot. +

+Note that "fix" doesn't differentiate between errors and intentional +modifications. It unconditionally reverts the file state at the last "sync". +

+If no other option is specified the full array is processed. +Use the filter options to select a subset of files or disks to operate on. +

+To only fix the blocks marked bad during "sync" and "scrub", +use the -e, --filter-error option. +As difference from other filter options, with this one fixes are +applied only to files that are not modified from the the latest "sync". +

+All the files that cannot be fixed are renamed adding +the ".unrecoverable" extension. +

+Files are identified only by path, and not by inode. +

+The "content" file is NOT modified. +The "parity" files are modified if necessary. +The files in the array are modified if necessary. +

5.9 +check +

+Verify all the files and the parity data. +

+It works like "fix", but it only simulates a recovery and no change +is written in the array. +

+This command is mostly intended for manual verifications, +like after a recovery process or in other special conditions. +For periodic and scheduled checks uses "scrub". +

+If you use the -a, --audit-only option, only the file +data is checked, and the parity data is ignored for a +faster run. +

+Files are identified only by path, and not by inode. +

+Nothing is modified. +

5.10 +list +

+Lists all the files contained in the array at the time of the +last "sync". +

+Nothing is modified. +

5.11 +dup +

+Lists all the duplicate files. Two files are assumed equal if their +hashes are matching. The file data is not read, but only the +precomputed hashes are used. +

+Nothing is modified. +

5.12 +up +

+Spins up all the disks of the array. +

+Nothing is modified. +

5.13 +down +

+Spins down all the disks of the array. +

+Nothing is modified. +

5.14 +pool +

+Creates or updates in the "pooling" directory a virtual view of all +the files of your disk array. +

+The files are not really copied here, but just linked using +symbolic links. +

+When updating, all the present symbolic links and empty +subdirectories are deleted and replaced with the new +view of the array. Any other regular file is left in place. +

+Nothing is modified outside the pool directory. +

5.15 +devices +

+Prints the low level devices used by the array. +

+This command prints the devices associations in place in the array, +and it's mainly intended as a script interface. +

+The first two columns are the low level device id and path. +The next two columns are the high level device id and path. +The latest column if the disk name in the array. +

+In most cases you have one low level device for each disk in the +array, but in some more complex configurations, you may have multiple +low level devices used by a single disk in the array. +

+Nothing is modified. +

5.16 +rehash +

+Schedules a rehash of the whole array. +

+This command changes the hash kind used, typically when upgrading +from a 32 bits system to a 64 bits one, to switch from +MurmurHash3 to the faster SpookyHash. +

+If you are already using the optimal hash, this command +does nothing and tells you that nothing has to be done. +

+The rehash isn't done immediately, but it takes place +progressively during "sync" and "scrub". +

+You can get the rehash state using "status". +

+During the rehash, SnapRAID maintains full functionality, +with the only exception of "dup" not able to detect duplicated +files using a different hash. +

6 +Options +

+SnapRAID provides the following options: + + +
+-c, --conf CONFIG +
+Selects the configuration file. If not specified it's assumed +the file "/etc/snapraid.conf" in Unix, and "snapraid.conf" in +the current directory in Windows. +
+ + +
+-f, --filter PATTERN +
+Filters the files to process in "check" and "fix". +Only the files matching the entered pattern are processed. +This option can be used many times. +See the PATTERN section for more details in the +pattern specifications. +In Unix, ensure to quote globbing chars if used. +This option can be used only with "check" and "fix". +Note that it cannot be used with "sync" and "scrub", because they always +process the whole array. +
+ + +
+-d, --filter-disk NAME +
+Filters the files to process in "check" and "fix". +Only the files present in the specified disk are processed. +You must specify a disk name as named in the configuration +file. +In "check", you can make it faster, specifying also -a, --audit-only +option, to avoid to access other disks to check parity data. +If you combine more --filter, --filter-disk and --filter-missing options, +only files matching all the set of filters are selected. +This option can be used many times. +This option can be used only with "check" and "fix". +Note that it cannot be used with "sync" and "scrub", because they always +process the whole array. +
+ + +
+-m, --filter-missing +
+Filters the files to process in "check" and "fix". +Only the files missing/deleted from the array are processed. +When used with "fix", this is a kind of "undelete" command. +If you combine more --filter, --filter-disk and --filter-missing options, +only files matching all the set of filters are selected. +This option can be used only with "check" and "fix". +Note that it cannot be used with "sync" and "scrub", because they always +process the whole array. +
+ + +
+-e, --filter-error +
+Filters the blocks to process in "check" and "fix". +It processes only the blocks marked with silent or input/output +errors during "sync" and "scrub", and listed in "status". +This option can be used only with "check" and "fix". +
+ + +
+-p, --percentage PERC +
+Selects the part of the array to process in "scrub". +PERC is a numeric value from 0 to 100, default is 12. +When specifying 0, only the blocks marked as bad are scrubbed. +This option can be used only with "scrub". +
+ + +
+-o, --older-than DAYS +
+Selects the older the part of the array to process in "scrub". +DAYS is the minimum age in days for a block to be scrubbed, +default is 10. +Blocks marked as bad are always scrubbed despite this option. +This option can be used only with "scrub". +
+ + +
+-a, --audit-only +
+In "check" verifies the hash of the files without +doing any kind of check on the parity data. +If you are interested in checking only the file data this +option can speedup a lot the checking process. +This option can be used only with "check". +
+ + +
+-h, --pre-hash +
+In "sync" runs a preliminary hashing phase of all +the new data to verify the data used in the parity computation. +Usually in "sync" no preliminary hashing is done, and the new +data is hashed just before the parity computation when it's read +for the first time, +Unfortunately, this process happens when the system is under +heavy load, with all disks spinning and a busy CPU. +This is an extreme condition for your machine, and if it has a +latent hardware problem, it's possible to encounter silent errors +what cannot be detected because the data is not yet hashed. +To avoid this risk, you can enable the "pre-hash" mode and have +all the data hashed two times to ensure its integrity. +This option can be used only with "sync". +
+ + +
+-i, --import DIR +
+Imports from the specified directory any file that you deleted +from the array after the last "sync". +If you still have such files, they could be used by "check" +and "fix" to improve the recover process. +The files are read also in subdirectories and they are +identified regardless of their name. +This option can be used only with "check" and "fix". +
+ + +
+-Z, --force-zero +
+Forces the insecure operation of syncing a file with zero +size that before was not. +If SnapRAID detects a such condition, it stops proceeding +unless you specify this option. +This allows to easily detect when after a system crash, +some accessed files were truncated. +This is a possible condition in Linux with the ext3/ext4 +filesystems. +This option can be used only with "sync". +
+ + +
+-E, --force-empty +
+Forces the insecure operation of syncing a disk with all +the original files missing. +If SnapRAID detects that all the files originally present +in the disk are missing or rewritten, it stops proceeding +unless you specify this option. +This allows to easily detect when a data file-system is not +mounted. +This option can be used only with "sync". +
+ + +
+-U, --force-uuid +
+Forces the insecure operation of syncing, checking and fixing +with disks that have changed their UUID. +If SnapRAID detects that some disks have changed UUID, +it stops proceeding unless you specify this option. +This allows to detect when your disks are mounted in the +wrong mount points. +It's anyway allowed to have a single UUID change with +single parity, and more with multiple parity, because it's +the normal case of replacing disks after a recovery. +This option can be used only with "sync", "check" or +"fix". +
+ + +
+-D, --force-device +
+Forces the insecure operation of fixing with disks on the same +physical device. +If SnapRAID detects that some disks have the same device ID, +it stops proceeding, because it's not a supported configuration. +But it could happen that you want to temporarily restore a lost +disk in the free space left in an already used disk. and this +option allows you to continue anyway. +This option can be used only with "fix". +
+ + +
+-N, --force-nocopy +
+In "sync", "check and "fix", disables the copy detection heuristic. +Without this option SnapRAID assumes that files with same +attributes, like name, size and timestamp are copies with the +same data. +This allows to identify copied or moved files from one disk +to another, and to reuse the already computed hash information +to detect silent errors or to recover missing files. +This behavior, in some rare cases, may result in false positives, +or in a slow process due the many hash verifications, and this +option allows to resolve them. +This option can be used only with "sync", "check" and "fix". +
+ + +
+-F, --force-full +
+In "sync" forces a full rebuild of the parity. +This option can be used when you reverted back to an old content +file, but using a more recent parity data. +Instead of recomputing the parity from scratch, this allows +to reuse the hashes present in the content file to validate data, +and to maintain data protection during the "sync" process using +the old content file and the parity data you have. +This option can be used only with "sync". +
+ + +
+-l, --log FILE +
+Write a detailed log in the specified file. +If this option is not specified, unexpected errors are printed +on the screen, likely resulting in too much output in case of +many errors. When -l, --log is specified, on the screen, go only +fatal errors that makes SnapRAID to stop progress. +If the path starts with '>>' the file is opened +in append mode. Occurrences of '%D' and '%T' in the name are +replaced with the date and time in the format YYYYMMDD and +HHMMSS. Note that in Windows batch files, you'll have to double +the '%' char, like result-%%D.log. And to use '>>' you'll have +to enclose the name in ", like ">>result.log". +To output the log to standard output or standard error, +you can use respectively ">&1" and ">&2". +
+ + +
+-L, --error-limit +
+Sets a new error limit before stopping execution. +By default SnapRAID stops if it encounters more than 100 +Input/Output errors, meaning that likely a disk is going to +die. +This options affects "sync" and "scrub", that are allowed +to continue after the first bunch of disk errors, to try +to complete at most their operations. +Instead, "check" and "fix" always stop at the first error. +
+ + +
+-S, --start BLKSTART +
+Starts the processing from the specified +block number. It could be useful to retry to check +or fix some specific block, in case of a damaged disk. +It's present mainly for advanced manual recovering. +
+ + +
+-B, --count BLKCOUNT +
+Processes only the specified number of blocks. +It's present mainly for advanced manual recovering. +
+ + +
+-C, --gen-conf CONTENT_FILE +
+Generates a dummy configuration file from an existing +content file. +The configuration file is written in the standard output, +and it doesn't overwrite an existing one. +This configuration file also contains the information +needed to reconstruct the disk mount points, in case you +lose the entire system. +
+ + +
+-v, --verbose +
+Prints more information on the screen. +If specified one time, it prints excluded files +and more stats. +This option has no effect on the log files. +
+ + +
+-q, --quiet +
+Prints less information on the screen. +If specified one time, removes the progress bar, if two +times, the running operations, three times, the info +messages, four times the status messages. +Fatal errors are always printed on the screen. +This option has no effect on the log files. +
+ + +
+-H, --help +
+Prints a short help screen. +
+ + +
+-V, --version +
+Prints the program version. +
+

7 +Configuration +

+SnapRAID requires a configuration file to know where your disk array +is located, and where storing the parity information. +

+This configuration file is located in /etc/snapraid.conf in Unix or +in the execution directory in Windows. +

+It should contain the following options (case sensitive): +

7.1 +parity FILE +

+Defines the file to use to store the parity information. +The parity enables the protection from a single disk +failure, like RAID5. +

+It must be placed in a disk dedicated for this purpose with +as much free space as the biggest disk in the array. +Leaving the parity disk reserved for only this file ensures that +it doesn't get fragmented, improving the performance. +

+This option is mandatory and it can be used only one time. +

7.2 +[2,3,4,5,6]-parity FILE +

+Defines the files to use to store extra parity information. +For each parity file specified, one additional level of protection +is enabled: + +

+Each parity level requires also all the files of the previous levels. +

+Each file must be placed in a disk dedicated for this purpose with +as much free space as the biggest disk in the array. +Leaving the parity disks reserved for only these files ensures that +they doesn't get fragmented, improving the performance. +

+These options are optional and they can be used only one time. +

7.3 +z-parity FILE +

+Defines an alternate file and format to store the triple parity. +

+This option is an alternative at '3-parity' mainly intended for +low-end CPUs like ARM or AMD Phenom, Athlon and Opteron that don't +support the SSSE3 instructions set, and in such case it provides +a better performance. +

+This format is similar, but faster, at the one used by the ZFS RAIDZ3, +but it doesn't work beyond triple parity. +

+When using '3-parity' you will be warned if it's recommended to use +the 'z-parity' format for a performance improvement. +

+It's possible to convert from one format to another, adjusting +the configuration file with the wanted z-parity or 3-parity file, +and using 'fix' to recreate it. +

7.4 +content FILE +

+Defines the file to use to store the list and checksums of all the +files present in your disk array. +

+It can be placed in the disk used to store data, parity, or +any other disk available. +If you use a data disk, this file is automatically excluded +from the "sync" process. +

+This option is mandatory and it can be used more times to save +more copies of the same files. +

+You have to store at least one copy for each parity disk used +plus one. Using some more doesn't hurt. +

7.5 +disk NAME DIR +

+Defines the name and the mount point of the disks of the array. +NAME is used to identify the disk, and it must be unique. +DIR is the mount point of the disk in the filesystem. +

+You can change the mount point as you like, as long you +keep the NAME fixed. +

+You should use one option for each disk of the array. +

7.6 +nohidden +

+Excludes all the hidden files and directory. +In Unix hidden files are the ones starting with ".". +In Windows they are the ones with the hidden attribute. +

7.7 +exclude/include PATTERN +

+Defines the file or directory patterns to exclude and include +in the sync process. +All the patterns are processed in the specified order. +

+If the first pattern that matches is an "exclude" one, the file +is excluded. If it's an "include" one, the file is included. +If no pattern matches, the file is excluded if the last pattern +specified is an "include", or included if the last pattern +specified is an "exclude". +

+See the PATTERN section for more details in the pattern +specifications. +

+This option can be used many times. +

7.8 +blocksize SIZE_IN_KIBIBYTES +

+Defines the basic block size in kibi bytes of the parity. +One kibi bytes is 1024 bytes. The default blocksize is 256 +and it should work for most cases. +

+A reason to use a different blocksize is if your system has less +than 4 GiB of memory. As a rule of thumb, with 4 GiB or more memory +use the default 256, with 2 GiB use 512, and with 1 GiB use 1024. +

+In more details SnapRAID requires about TS*28/BS bytes +of RAM memory to run in the 32 bits version, and TS*36/BS +in the 64 bits one. Where TS is the total size in bytes of +your disk array, and BS is the block size in bytes. +

+For example with 8 disk of 4 TB and a block size of 256 KiB +(1 KiB = 1024 bytes) you have: +

+

+RAM = (8 * 4 * 10^12) * 28 / (256 * 2^10) = 3.2 GiB
+
+

+Another reason to use a different blocksize is if you have a lot of +small files. In the order of many millions. +

+For each file, even of few bytes, a whole block of parity is allocated, +and with many files this may result in a lot of unused parity space. +And when you completely fill the parity disk, you are not +allowed to add more files in the data disks. +Anyway, the wasted parity doesn't sum between data disks. Wasted space +resulting from a high number of files in a data disk, limits only +the amount of data in such data disk and not in others. +

+As approximation, you can assume that half of the block size is +wasted for each file. For example, with 100000 files and a 256 KiB +block size, you are going to waste 13 GB of parity, that may result +in 13 GB less space available in the data disk. +

+You can get the amount of wasted space in each disk using "status". +This is the amount of space that you must leave free in the data +disks, or use for files not included in the array. +If this value is negative, it means that your are near to fill +the parity, and it represents the space you can still waste. +

+To avoid the problem, you can use a bigger partition for parity. +For example, if you have the parity partition bigger than 13 GB +than data disks, you have enough extra space to handle up to 100000 +files in each data disk. +

+A trick to get a bigger parity partition in Linux, is to format it +with the command: +

+
+
+mkfs.ext4 -m 0 -T largefile4 DEVICE
+
+
+

+This results in about 1.5% of extra space. Meaning about 60 GB for +a 4 TB disk, that allows about 460000 files in each data disk without +any wasted space. +

7.9 +autosave SIZE_IN_GIGABYTES +

+Automatically save the state when syncing after the specified amount +of GB processed. +This option is useful to avoid to restart from scratch long "sync" +commands interrupted by a machine crash, or any other event that +may interrupt SnapRAID. +

7.10 +pool DIR +

+Defines the pooling directory where the virtual view of the disk +array is created using the "pool" command. +

+The directory must already exist. +

7.11 +share UNC_DIR +

+Defines the Windows UNC path required to access the disks remotely. +

+If this option is specified, the symbolic links created in the pool +directory use this UNC path to access the disks. +Without this option the symbolic links generated use only local paths, +not allowing to share the pool directory in the network. +

+The symbolic links are formed using the specified UNC path, adding the +disk name as specified in the "disk" option, and finally adding the +file dir and name. +

+This option is only required for Windows. +

7.12 +smartctl DISK/PARITY OPTIONS... +

+Defines a custom smartctl command to obtain the SMART attributes +for each disk. This may be required for RAID controllers and for +some USB disk that cannot be autodetected. +

+DISK is the same disk name specified in the "disk" option. +PARITY is one of the parity name as "parity,[1,2,3,4,5,6,z]-parity". +

+In the specified OPTIONS, the "%s" string is replaced by the +device name. Note that in case of RAID controllers the device is likely +fixed, and you don't have to use "%s". +

+Refers at the smartmontools documentation about the possible options: +

+
+
+https://www.smartmontools.org/wiki/Supported_RAID-Controllers
+https://www.smartmontools.org/wiki/Supported_USB-Devices
+
+
+

7.13 +Examples +

+An example of a typical configuration for Unix is: +

+
+
+parity /mnt/diskp/snapraid.parity
+content /mnt/diskp/snapraid.content
+content /var/snapraid/snapraid.content
+disk d1 /mnt/disk1/
+disk d2 /mnt/disk2/
+disk d3 /mnt/disk3/
+exclude /lost+found/
+exclude /tmp/
+smartctl d1 -d sat %s
+smartctl d2 -d usbjmicron %s
+smartctl parity -d areca,1/1 /dev/sg0
+smartctl 2-parity -d areca,2/1 /dev/sg0
+
+
+

+An example of a typical configuration for Windows is: +

+
+
+parity E:\snapraid.parity
+content E:\snapraid.content
+content C:\snapraid\snapraid.content
+disk d1 G:\array\
+disk d2 H:\array\
+disk d3 I:\array\
+exclude Thumbs.db
+exclude \$RECYCLE.BIN
+exclude \System Volume Information
+smartctl d1 -d sat %s
+smartctl d2 -d usbjmicron %s
+smartctl parity -d areca,1/1 /dev/arcmsr0
+smartctl 2-parity -d areca,2/1 /dev/arcmsr0
+
+
+

8 +Pattern +

+Patterns are used to select a subset of files to exclude or include in +the process. +

+There are four different types of patterns: + + +
+FILE +
+Selects any file named as FILE. You can use any globbing +character like * and ?. +This pattern is applied only to files and not to directories. +
+ + +
+DIR/ +
+Selects any directory named DIR and everything inside. +You can use any globbing character like * and ?. +This pattern is applied only to directories and not to files. +
+ + +
+/PATH/FILE +
+Selects the exact specified file path. You can use any +globbing character like * and ? but they never match a +directory slash. +This pattern is applied only to files and not to directories. +
+ + +
+/PATH/DIR/ +
+Selects the exact specified directory path and everything +inside. You can use any globbing character like * and ? but +they never match a directory slash. +This pattern is applied only to directories and not to files. +
+

+Note that when you specify an absolute path starting with /, it's +applied at the array root dir and not at the local filesystem root dir. +

+In Windows you can use the backslash \ instead of the forward slash /. +Note that Windows system directories, junctions, mount points, and any +other Windows special directory are treated just as files, meaning that +to exclude them you must use a file rule, and not a directory one. +

+In the configuration file, you can use different strategies to filter +the files to process. +The simplest one is to use only "exclude" rules to remove all the +files and directories you do not want to process. For example: +

+
+
+# Excludes any file named "*.unrecoverable"
+exclude *.unrecoverable
+# Excludes the root directory "/lost+found"
+exclude /lost+found/
+# Excludes any sub-directory named "tmp"
+exclude tmp/
+
+
+

+The opposite way is to define only the file you want to process, using +only "include" rules. For example: +

+
+
+# Includes only some directories
+include /movies/
+include /musics/
+include /pictures/
+
+
+

+The final way, is to mix "exclude" and "include" rules. In this case take +care that the order of rules is important. Previous rules have the +precedence over the later ones. +To get things simpler you can first have all the "exclude" rules and then +all the "include" ones. For example: +

+
+
+# Excludes any file named "*.unrecoverable"
+exclude *.unrecoverable
+# Excludes any sub-directory named "tmp"
+exclude tmp/
+# Includes only some directories
+include /movies/
+include /musics/
+include /pictures/
+
+
+

+On the command line, using the -f option, you can only use "include" +patterns. For example: +

+
+
+# Checks only the .mp3 files.
+# Note the "" use to avoid globbing expansion by the shell in Unix.
+snapraid -f "*.mp3" check
+
+
+

+In Unix, when using globbing chars in the command line, you have to +quote them. Otherwise the shell will try to expand them. +

9 +Content +

+SnapRAID stores the list and checksums of your files in the content file. +

+It's a binary file, listing all the files present in your disk array, +with all the checksums to verify their integrity. +

+This file is read and written by the "sync" and "scrub" commands, and +read by "fix", "check" and "status". +

10 +Parity +

+SnapRAID stores the parity information of your array in the parity +files. +

+They are binary files, containing the computed parity of all the +blocks defined in the "content" file. +

+These files are read and written by the "sync" and "fix" commands, and +only read by "scrub" and "check". +

11 +Encoding +

+SnapRAID in Unix ignores any encoding. It reads and stores the +file names with the same encoding used by the filesystem. +

+In Windows all the names read from the filesystem are converted and +processed in the UTF-8 format. +

+To have the file names printed correctly you have to set the Windows +console in the UTF-8 mode, with the command "chcp 65001", and use +a TrueType font like "Lucida Console" as console font. +Note that it has effect only on the printed file names, if you +redirect the console output to a file, the resulting file is always +in the UTF-8 format. + + + +

+ +
+ +
+Donate with +
+ + + + +
+ +
+Find other resources at +
+ + + +
+ +
+ + + + diff --git a/paypal.png b/paypal.png new file mode 100644 index 00000000..88ac9e2a Binary files /dev/null and b/paypal.png differ diff --git a/sourceforge.png b/sourceforge.png new file mode 100644 index 00000000..50191bf9 Binary files /dev/null and b/sourceforge.png differ diff --git a/style.css b/style.css new file mode 100644 index 00000000..4a66647d --- /dev/null +++ b/style.css @@ -0,0 +1,196 @@ +/* Reset all white-space to 0 for consistency across browsers */ +{ + margin:0px; + padding:0px; +} + +/* Get some padding between paragraphs and some line spacing */ +p { + line-height:1.4em; +} + +/* Bye bye ugly blue border */ +a img { + border:0px; +} + +/* No dots around clicked links */ +a, a:active { + outline: none; +} + +/* Class to any floated elements */ +.clear { + clear:both; +} + +/* styles */ + +a { + text-decoration:none; +} + +a:link { + color:#0c5da5; +} + +a:visited { + color:#0c5da5; +} + +a:hover { + color:#679fd2; + text-decoration:underline; +} + +hr { + color:#B0B0B0; +} + +h1, h2, h3 { + color:#0c5da5; + margin-left:-1em; +} + +table, td +{ + border:0px; + border-style:none; +} + +.bold { + color:#0c5da5; + font-weight:bold; +} + +.highlight { + color:#408dd2; + font-weight:bold; + font-size:150%; +} + +.sg { + color:#B00000; +} + +.nw { + white-space:nowrap; +} + +/* structure */ + +body { + background-color:#ffffff; + margin:0px; + padding:0px; +} + +/* title */ + +#title { + min-height: 200px; + background: #0a64a4 url(index.png) 0 0 no-repeat; + padding:0px; +} + +/* bar */ + +#bar { + background-color:#bacad9; + padding:8px; + padding-left:4em; + padding-right:4em; +} + +#bar a { + color:#0c5da5; + font-family:sans-serif; + padding-left:1em; + font-weight:bold; +} + +#bar .bold { + color:#0c5da5; +} + +/* bottombar */ + +#bottombar { + background-color:#bacad9; + min-height: 90px; + padding-top:16px; + padding-bottom:16px; + padding-left:4em; + padding-right:4em; +} + +#bottombar a { + color:#0c5da5; + font-family:sans-serif; + padding-left:1em; +} + +#bottombar .bold { + color:#0c5da5; +} + +/* main */ + +#main { + padding:2px; + padding-left:4em; + padding-right:4em; + max-width:1024px; +/* + margin-left:auto; + margin-right:auto; +*/ +} + +.text { + margin:16px; + margin-left:32px +} + +/* table download */ + +.download +{ + border-collapse:collapse; +} +.download td +{ + border: 2px solid black; + text-align:left; + padding:5px; +} +.download th +{ + border: 2px solid black; + font-size:1.1em; + text-align:left; + padding:5px; + background-color:#bacad9; + color:#0c5da5; +} + +/* table compare */ + +.compare +{ + border-collapse:collapse; +} +.compare td +{ + border: 2px solid black; + text-align:center; +} +.compare th +{ + border: 2px solid black; + font-size:1.1em; + padding:5px; + background-color:#bacad9; + color:#0c5da5; +} + diff --git a/travisci.png b/travisci.png new file mode 100644 index 00000000..457b76c8 Binary files /dev/null and b/travisci.png differ