Skip to content

Commit

Permalink
file: fix clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeSpotRun committed May 28, 2021
1 parent e43972c commit 0032f5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ static RmOff rm_file_start_seek(RmFile *file) {
}
}

static RmOff rm_file_end_seek(RmFile *file) {
RmOff rm_file_end_seek(RmFile *file) {
RmCfg *cfg = file->session->cfg;
RmOff end_seek = file->actual_file_size;
RmOff file_size = file->actual_file_size;

if(cfg->use_absolute_end_offset) {
return end_seek - MIN(cfg->skip_end_offset, end_seek);
return MIN(cfg->skip_end_offset, file_size);
} else {
return end_seek * cfg->skip_end_factor;
return MIN(file_size, file_size * cfg->skip_end_factor);
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,9 @@ static inline dev_t rm_file_parent_dev(const RmFile *file) {
*/
RmOff rm_file_clamped_size(RmFile *file);

/**
* @brief file end position after clamping end offset.
*/
RmOff rm_file_end_seek(RmFile *file);

#endif /* end of include guard */
8 changes: 4 additions & 4 deletions lib/shredder.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static RmShredGroup *rm_shred_group_new(RmFile *file) {
}

self->held_files = g_queue_new();
self->file_size = rm_file_clamped_size(file);
self->file_size = rm_file_end_seek(file);
self->hash_offset = file->hash_offset;

self->session = file->session;
Expand Down Expand Up @@ -718,7 +718,7 @@ static void rm_shred_discard_file(RmFile *file, _UNUSED gpointer user_data) {
rm_mds_device_ref(rm_shred_disk(file, session), -1);
file->has_disk_ref = FALSE;
rm_shred_adjust_counters(tag, -1,
-(gint64)(rm_file_clamped_size(file) - file->hash_offset));
-(gint64)(rm_file_end_seek(file) - file->hash_offset));
}

/* toss the file (and any embedded hardlinks)*/
Expand Down Expand Up @@ -1109,7 +1109,7 @@ static void rm_shred_file_preprocess(RmFile *file, RmShredGroup **group) {
rm_mds_device_ref(device, 1);
file->has_disk_ref = TRUE;

rm_shred_adjust_counters(shredder, 1, rm_file_clamped_size(file) - file->hash_offset);
rm_shred_adjust_counters(shredder, 1, rm_file_end_seek(file) - file->hash_offset);

rm_shred_group_push_file(*group, file, true);
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ static gint rm_shred_process_file(RmFile *file, RmSession *session) {
RmOff bytes_to_read = rm_shred_get_read_size(file, tag);

gboolean shredder_waiting =
(file->shred_group->next_offset != rm_file_clamped_size(file)) &&
(file->shred_group->next_offset != rm_file_end_seek(file)) &&
(cfg->shred_always_wait ||
(!cfg->shred_never_wait && file->is_on_rotational_disk &&
bytes_to_read < SHRED_TOO_MANY_BYTES_TO_WAIT));
Expand Down

0 comments on commit 0032f5e

Please sign in to comment.