Windows: workaround for NTFS Alternate Data Stream creation

fopen() creates normal files instead of ADS with ':' replaced by an UTF char
replace ':' by '_' instead
This commit is contained in:
Christophe Grenier 2012-12-08 18:01:42 +01:00
parent 4ab4b39067
commit da6fe469c4
3 changed files with 23 additions and 11 deletions

View file

@ -180,9 +180,8 @@ static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name
const int name_len, const int name_type, const s64 pos,
const MFT_REF mref, const unsigned dt_type)
{
char *filename = NULL;
int result = 0;
filename = (char *)calloc (1, MAX_PATH);
char *filename = (char *)calloc (1, MAX_PATH);
if (!filename)
{
log_critical("ntfs_td_list_entry calloc failed\n");
@ -369,7 +368,7 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
FILE *f_out;
s64 offset;
u32 block_size;
const char *stream_name=NULL;
char *stream_name;
buffer = (char *)MALLOC(bufsize);
if (!buffer)
{
@ -407,7 +406,20 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
block_size = index_get_size(inode);
else
block_size = 0;
#if defined(__CYGWIN__) || defined(__MINGW32__)
if(stream_name)
{
/* fopen() create normal files instead of ADS with ':' replaced by an UTF char
* replace ':' by '_' instead */
stream_name--;
*stream_name='_';
f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
}
else
f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
#else
f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
#endif
if(!f_out)
{
log_critical("Can't create file %s: %s\n",new_file, strerror(errno));

View file

@ -253,7 +253,7 @@ int photorec_bf(struct ph_param *params, const struct ph_options *options, alloc
{
if(fwrite(buffer,blocksize,1,file_recovery.handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery.filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery.filename, strerror(errno));
ind_stop=3;
}
}
@ -386,7 +386,7 @@ static int photorec_bf_pad(struct ph_param *params, file_recovery_t *file_recove
}
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@ -413,7 +413,7 @@ static int photorec_bf_pad(struct ph_param *params, file_recovery_t *file_recove
params->disk->pread(params->disk, block_buffer, blocksize, *offset);
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@ -544,7 +544,7 @@ static int photorec_bf_frag_fast(struct ph_param *params, file_recovery_t *file_
}
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@ -811,7 +811,7 @@ static int photorec_bf_aux(struct ph_param *params, file_recovery_t *file_recove
/* FIXME: Handle ext2/ext3 */
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
free(buffer);

View file

@ -363,7 +363,7 @@ static int photorec_aux(struct ph_param *params, const struct ph_options *option
{
if(fwrite(buffer,blocksize,1,file_recovery.handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery.filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery.filename, strerror(errno));
if(errno==EFBIG)
{
/* File is too big for the destination filesystem */
@ -619,7 +619,7 @@ static void gen_image(const char *filename, disk_t *disk, const alloc_data_t *li
disk->pread(disk, buffer, read_size, offset);
if(fwrite(buffer, read_size, 1, out)<1)
{
log_critical("Cannot write to file %s:%s\n", filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", filename, strerror(errno));
free(buffer);
fclose(out);
return ;
@ -699,7 +699,7 @@ static void test_files_aux(file_recovery_t *file_recovery, struct ph_param *para
}
if(fwrite(buffer, datasize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
free(buffer);