summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sqfs/block.h10
-rw-r--r--lib/sqfs/block_processor/common.c14
-rw-r--r--lib/sqfs/block_writer.c10
3 files changed, 23 insertions, 11 deletions
diff --git a/include/sqfs/block.h b/include/sqfs/block.h
index b4860ac..5e79ff7 100644
--- a/include/sqfs/block.h
+++ b/include/sqfs/block.h
@@ -89,6 +89,14 @@ typedef enum {
SQFS_BLK_DONT_FRAGMENT = 0x0004,
/**
+ * @brief Surpress deduplication.
+ *
+ * If set on fragments or the last block of a file, it is always
+ * written to disk, even if a duplicate copy already exists.
+ */
+ SQFS_BLK_DONT_DEDUPLICATE = 0x0008,
+
+ /**
* @brief Set by the @ref sqfs_block_processor_t if it determines a
* block of a file to be sparse, i.e. only zero bytes.
*/
@@ -127,7 +135,7 @@ typedef enum {
/**
* @brief The combination of all flags that are user settable.
*/
- SQFS_BLK_USER_SETTABLE_FLAGS = 0x0007,
+ SQFS_BLK_USER_SETTABLE_FLAGS = 0x000F,
} E_SQFS_BLK_FLAGS;
#endif /* SQFS_BLOCK_H */
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index ab83b5d..2c6e59e 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -142,11 +142,15 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
proc->stats.total_frag_count += 1;
- err = sqfs_frag_table_find_tail_end(proc->frag_tbl, frag->checksum,
- frag->size, &index, &offset);
- if (err == 0) {
- sqfs_inode_set_frag_location(*(frag->inode), index, offset);
- return 0;
+ if (!(frag->flags & SQFS_BLK_DONT_DEDUPLICATE)) {
+ err = sqfs_frag_table_find_tail_end(proc->frag_tbl,
+ frag->checksum, frag->size,
+ &index, &offset);
+ if (err == 0) {
+ sqfs_inode_set_frag_location(*(frag->inode),
+ index, offset);
+ return 0;
+ }
}
if (proc->frag_block != NULL) {
diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c
index 73dcb14..e252c89 100644
--- a/lib/sqfs/block_writer.c
+++ b/lib/sqfs/block_writer.c
@@ -229,7 +229,7 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_u32 size,
if (count == 0) {
*location = 0;
- } else {
+ } else if (!(flags & SQFS_BLK_DONT_DEDUPLICATE)) {
start = deduplicate_blocks(wr, count);
offset = wr->blocks[start].offset;
@@ -244,11 +244,11 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_u32 size,
} else {
wr->num_blocks = wr->file_start;
}
- }
- err = wr->file->truncate(wr->file, wr->start);
- if (err)
- return err;
+ err = wr->file->truncate(wr->file, wr->start);
+ if (err)
+ return err;
+ }
wr->stats.blocks_written = wr->num_blocks;
wr->stats.bytes_written = wr->start - wr->data_area_start;