| 290 | } |
| 291 | |
| 292 | static copy_file_t ext2_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file) |
| 293 | { |
| 294 | copy_file_t error=CP_OK; |
| 295 | FILE *f_out; |
| 296 | const struct ext2_dir_struct *ls = (const struct ext2_dir_struct *)dir_data->private_dir_data; |
| 297 | char *new_file; |
| 298 | f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory); |
| 299 | if(!f_out) |
| 300 | { |
| 301 | log_critical("Can't create file %s: %s\n", new_file, strerror(errno)); |
| 302 | free(new_file); |
| 303 | return CP_CREATE_FAILED; |
| 304 | } |
| 305 | { |
| 306 | errcode_t retval; |
| 307 | struct ext2_inode inode; |
| 308 | char buffer[8192]; |
| 309 | ext2_file_t e2_file; |
| 310 | |
| 311 | if (ext2fs_read_inode(ls->current_fs, file->st_ino, &inode)!=0) |
| 312 | { |
| 313 | free(new_file); |
| 314 | fclose(f_out); |
| 315 | return CP_STAT_FAILED; |
| 316 | } |
| 317 | |
| 318 | retval = ext2fs_file_open(ls->current_fs, file->st_ino, 0, &e2_file); |
| 319 | if (retval) { |
| 320 | log_error("Error while opening ext2 file %s\n", dir_data->current_directory); |
| 321 | free(new_file); |
| 322 | fclose(f_out); |
| 323 | return CP_OPEN_FAILED; |
| 324 | } |
| 325 | while (error!=CP_NOSPACE) |
| 326 | { |
| 327 | int nbytes; |
| 328 | unsigned int got; |
| 329 | retval = ext2fs_file_read(e2_file, buffer, sizeof(buffer), &got); |
| 330 | if (retval) |
| 331 | { |
| 332 | log_error("Error while reading ext2 file %s\n", dir_data->current_directory); |
| 333 | error = CP_READ_FAILED; |
| 334 | } |
| 335 | if (got == 0) |
| 336 | break; |
| 337 | nbytes = fwrite(buffer, 1, got, f_out); |
| 338 | if ((unsigned) nbytes != got) |
| 339 | { |
| 340 | log_error("Error while writing file %s\n", new_file); |
| 341 | error = CP_NOSPACE; |
| 342 | } |
| 343 | } |
| 344 | retval = ext2fs_file_close(e2_file); |
| 345 | if (retval) |
| 346 | { |
| 347 | log_error("Error while closing ext2 file\n"); |
| 348 | error = CP_CLOSE_FAILED; |
| 349 | } |
nothing calls this directly
no test coverage detected