Lines Matching refs:data
79 static void update_progress(struct encryptGroupsData* data, int is_used) in update_progress() argument
81 data->blocks_already_done++; in update_progress()
84 data->used_blocks_already_done++; in update_progress()
86 if (data->tot_used_blocks) { in update_progress()
87 data->new_pct = data->used_blocks_already_done / data->one_pct; in update_progress()
89 data->new_pct = data->blocks_already_done / data->one_pct; in update_progress()
92 if (!data->set_progress_properties) return; in update_progress()
94 if (data->new_pct > data->cur_pct) { in update_progress()
96 data->cur_pct = data->new_pct; in update_progress()
97 snprintf(buf, sizeof(buf), "%" PRId64, data->cur_pct); in update_progress()
101 if (data->cur_pct >= 5) { in update_progress()
106 double elapsed_time = difftime(time_now.tv_sec, data->time_started); in update_progress()
107 off64_t remaining_blocks = data->tot_used_blocks in update_progress()
108 - data->used_blocks_already_done; in update_progress()
110 / data->used_blocks_already_done); in update_progress()
114 if (data->remaining_time == -1 in update_progress()
115 || remaining_time < data->remaining_time in update_progress()
116 || remaining_time > data->remaining_time + 60) { in update_progress()
120 data->remaining_time = remaining_time; in update_progress()
126 static void log_progress(struct encryptGroupsData const* data, bool completed) in log_progress() argument
134 if (completed || (offset != -1 && data->offset != offset)) { in log_progress()
140 if (!completed && offset != data->offset) { in log_progress()
141 … LOG(INFO) << "Encrypting from sector " << data->offset / info.block_size * CRYPT_SECTOR_SIZE; in log_progress()
146 offset = data->offset + (off64_t)data->count * info.block_size; in log_progress()
150 static int flush_outstanding_data(struct encryptGroupsData* data) in flush_outstanding_data() argument
152 if (data->count == 0) { in flush_outstanding_data()
156 LOG(VERBOSE) << "Copying " << data->count << " blocks at offset " << data->offset; in flush_outstanding_data()
158 if (pread64(data->realfd, data->buffer, info.block_size * data->count, data->offset) <= 0) { in flush_outstanding_data()
159 LOG(ERROR) << "Error reading real_blkdev " << data->real_blkdev << " for inplace encrypt"; in flush_outstanding_data()
163 if (pwrite64(data->cryptofd, data->buffer, info.block_size * data->count, data->offset) <= 0) { in flush_outstanding_data()
164 LOG(ERROR) << "Error writing crypto_blkdev " << data->crypto_blkdev in flush_outstanding_data()
168 log_progress(data, false); in flush_outstanding_data()
171 data->count = 0; in flush_outstanding_data()
172 data->last_written_sector = (data->offset + data->count) in flush_outstanding_data()
177 static int encrypt_groups(struct encryptGroupsData* data) in encrypt_groups() argument
185 data->buffer = (char*) malloc(info.block_size * BLOCKS_AT_A_TIME); in encrypt_groups()
186 if (!data->buffer) { in encrypt_groups()
207 ret = pread64(data->realfd, block_bitmap, info.block_size, offset); in encrypt_groups()
215 data->count = 0; in encrypt_groups()
220 update_progress(data, used); in encrypt_groups()
222 if (data->count == 0) { in encrypt_groups()
223 data->offset = offset; in encrypt_groups()
225 data->count++; in encrypt_groups()
227 if (flush_outstanding_data(data)) { in encrypt_groups()
236 || data->count == BLOCKS_AT_A_TIME) { in encrypt_groups()
237 if (flush_outstanding_data(data)) { in encrypt_groups()
242 if (flush_outstanding_data(data)) { in encrypt_groups()
247 data->completed = 1; in encrypt_groups()
252 free(data->buffer); in encrypt_groups()
262 struct encryptGroupsData data; in cryptfs_enable_inplace_ext4() local
272 memset(&data, 0, sizeof(data)); in cryptfs_enable_inplace_ext4()
273 data.real_blkdev = real_blkdev; in cryptfs_enable_inplace_ext4()
274 data.crypto_blkdev = crypto_blkdev; in cryptfs_enable_inplace_ext4()
275 data.set_progress_properties = set_progress_properties; in cryptfs_enable_inplace_ext4()
278 if ( (data.realfd = open(real_blkdev, O_RDWR|O_CLOEXEC)) < 0) { in cryptfs_enable_inplace_ext4()
286 while ((data.cryptofd = open(crypto_blkdev, O_WRONLY|O_CLOEXEC)) < 0) { in cryptfs_enable_inplace_ext4()
305 if (read_ext(data.realfd, 0) != 0) { in cryptfs_enable_inplace_ext4()
311 data.numblocks = size / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_ext4()
312 data.tot_numblocks = tot_size / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_ext4()
313 data.blocks_already_done = *size_already_done / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_ext4()
317 data.tot_used_blocks = data.numblocks; in cryptfs_enable_inplace_ext4()
319 data.tot_used_blocks -= aux_info.bg_desc[i].bg_free_blocks_count; in cryptfs_enable_inplace_ext4()
322 data.one_pct = data.tot_used_blocks / 100; in cryptfs_enable_inplace_ext4()
323 data.cur_pct = 0; in cryptfs_enable_inplace_ext4()
329 data.time_started = time_started.tv_sec; in cryptfs_enable_inplace_ext4()
330 data.remaining_time = -1; in cryptfs_enable_inplace_ext4()
332 rc = encrypt_groups(&data); in cryptfs_enable_inplace_ext4()
338 *size_already_done += data.completed ? size : data.last_written_sector; in cryptfs_enable_inplace_ext4()
342 close(data.realfd); in cryptfs_enable_inplace_ext4()
343 close(data.cryptofd); in cryptfs_enable_inplace_ext4()
372 static int encrypt_one_block_f2fs(u64 pos, void *data) in encrypt_one_block_f2fs() argument
374 struct encryptGroupsData *priv_dat = (struct encryptGroupsData *)data; in encrypt_one_block_f2fs()
402 struct encryptGroupsData data; in cryptfs_enable_inplace_f2fs() local
409 memset(&data, 0, sizeof(data)); in cryptfs_enable_inplace_f2fs()
410 data.real_blkdev = real_blkdev; in cryptfs_enable_inplace_f2fs()
411 data.crypto_blkdev = crypto_blkdev; in cryptfs_enable_inplace_f2fs()
412 data.set_progress_properties = set_progress_properties; in cryptfs_enable_inplace_f2fs()
413 data.realfd = -1; in cryptfs_enable_inplace_f2fs()
414 data.cryptofd = -1; in cryptfs_enable_inplace_f2fs()
415 if ( (data.realfd = open64(real_blkdev, O_RDWR|O_CLOEXEC)) < 0) { in cryptfs_enable_inplace_f2fs()
419 if ( (data.cryptofd = open64(crypto_blkdev, O_WRONLY|O_CLOEXEC)) < 0) { in cryptfs_enable_inplace_f2fs()
426 f2fs_info = generate_f2fs_info(data.realfd); in cryptfs_enable_inplace_f2fs()
430 data.numblocks = size / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_f2fs()
431 data.tot_numblocks = tot_size / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_f2fs()
432 data.blocks_already_done = *size_already_done / CRYPT_SECTORS_PER_BUFSIZE; in cryptfs_enable_inplace_f2fs()
434 data.tot_used_blocks = get_num_blocks_used(f2fs_info); in cryptfs_enable_inplace_f2fs()
436 data.one_pct = data.tot_used_blocks / 100; in cryptfs_enable_inplace_f2fs()
437 data.cur_pct = 0; in cryptfs_enable_inplace_f2fs()
438 data.time_started = time(NULL); in cryptfs_enable_inplace_f2fs()
439 data.remaining_time = -1; in cryptfs_enable_inplace_f2fs()
441 data.buffer = (char*) malloc(f2fs_info->block_size); in cryptfs_enable_inplace_f2fs()
442 if (!data.buffer) { in cryptfs_enable_inplace_f2fs()
447 data.count = 0; in cryptfs_enable_inplace_f2fs()
450 rc = run_on_used_blocks(data.blocks_already_done, f2fs_info, &encrypt_one_block_f2fs, &data); in cryptfs_enable_inplace_f2fs()
466 free(data.buffer); in cryptfs_enable_inplace_f2fs()
467 close(data.realfd); in cryptfs_enable_inplace_f2fs()
468 close(data.cryptofd); in cryptfs_enable_inplace_f2fs()