# Trung tâm xử lý sự cố > Hỏi-Đáp Source Code >  hỏi về viết giả ngôn ngữ

## haibang510

chào các bạn. ai có thể giúp mình viết giả ngôn ngữ cho đoạn code này với. chân thành cảm ơn!
int check_ntfs(disk_t *disk_car,partition_t *partition,const int verbose,const int dump_ind)
{
unsigned char *buffer=(unsigned char*)malloc(default_sector_size);
/* log_trace("check_ntfs part_offset=%llu
",(long long unsigned)partition->part_offset); */
if(disk_car->pread(disk_car, buffer, default_sector_size, partition->part_offset) != default_sector_size)
{
free(buffer);
return 1;
}
if(test_ntfs(disk_car,(struct ntfs_boot_sector*)buffer,partition,verbose,dump_in  d)!=0)
{
free(buffer);
return 1;
}
set_ntfs_info(disk_car, (struct ntfs_boot_sector*)buffer, partition, verbose);
free(buffer);
return 0;
}

int recover_ntfs(disk_t *disk_car, const struct ntfs_boot_sector*ntfs_header,partition_t *partition,const int verbose, const int dump_ind, const int backup)
{
uint64_t part_size;
if(test_ntfs(disk_car,ntfs_header,partition,verbos  e,dump_ind)!=0)
return 1;
if(verbose>0)
{
log_ntfs_info(ntfs_header);
}
part_size=(uint64_t)(le64(ntfs_header->sectors_nbr)+1)*ntfs_sector_size(ntfs_header);
partition->sborg_offset=0;
partition->sb_size=512;
if(backup>0)
{
if(partition->part_offset+disk_car->sector_size<part_size)
{
log_warning("ntfs part_offset=%llu, part_size=%llu, sector_size=%u
",
(long long unsigned)partition->part_offset, (long long unsigned)part_size,
disk_car->sector_size);
log_warning("ntfs partition cannot be added (part_offset<part_size).
");
return 1;
}
if(verbose>1)
log_info("ntfs part_offset=%llu, part_size=%llu, sector_size=%u
",
(long long unsigned)partition->part_offset, (long long unsigned)part_size,
disk_car->sector_size);
partition->sb_offset=part_size-disk_car->sector_size;
partition->part_offset-=partition->sb_offset;
if(verbose>1)
log_info("part_offset=%llu
",(long long unsigned)partition->part_offset);
}
partition->part_size=part_size;
partition->part_type_i386=p_ntfs;
partition->part_type_gpt=gpt_ent_type_ms_basic_data;
set_ntfs_info(disk_car, ntfs_header, partition, verbose);
return 0;
}

static int set_ntfs_info(disk_t *disk_car, const struct ntfs_boot_sector*ntfs_header,partition_t *partition,const int verbose)
{
partition->fsname[0]='\0';
if(partition->sb_offset==0)
strncpy(partition->info, "ntfs", sizeof(partition->info));
else
strncpy(partition->info, "ntfs found using backup sector!", sizeof(partition->info));
return ntfs_read_mft(disk_car, partition, ntfs_header, 0x60, verbose);
}

int test_ntfs(const disk_t *disk_car,const struct ntfs_boot_sector*ntfs_header, partition_t *partition,const int verbose, const int dump_ind)
{
if(le16(ntfs_header->marker)!=0xaa55 ||
le16(ntfs_header->reserved)>0 ||
ntfs_header->fats>0 ||
ntfs_header->dir_entries[0]!=0 || ntfs_header->dir_entries[1]!=0 ||
ntfs_header->sectors[0]!=0 || ntfs_header->sectors[1]!=0 ||
le16(ntfs_header->fat_length)!=0 || le32(ntfs_header->total_sect)!=0 ||
memcmp(ntfs_header->system_id,"ntfs",4)!=0 ||
le64(ntfs_header->sectors_nbr)==0)
return 1;
switch(ntfs_header->sectors_per_cluster)
{
case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128:
break;
default:
return 1;
}
if(verbose>0 || dump_ind!=0)
{
log_info("ntfs at %u/%u/%u
", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
}
if(le16(ntfs_header->heads)!=disk_car->geom.heads_per_cylinder)
{
screen_buffer_add("warning: incorrect number of heads/cylinder %u (ntfs) != %u (hd)
",
le16(ntfs_header->heads), disk_car->geom.heads_per_cylinder);
log_warning("heads/cylinder %u (ntfs) != %u (hd)
",
le16(ntfs_header->heads), disk_car->geom.heads_per_cylinder);
}
if(le16(ntfs_header->secs_track)!=disk_car->geom.sectors_per_head)
{
screen_buffer_add("warning: incorrect number of sectors per track %u (ntfs) != %u (hd)
",
le16(ntfs_header->secs_track), disk_car->geom.sectors_per_head);
log_warning("sect/track %u (ntfs) != %u (hd)
",
le16(ntfs_header->secs_track), disk_car->geom.sectors_per_head);
}
if(ntfs_sector_size(ntfs_header)!=disk_car->sector_size)
{
screen_buffer_add("warning: incorrect number of bytes per sector %u (ntfs) != %u (hd)
",
ntfs_sector_size(ntfs_header), disk_car->sector_size);
log_warning("warning: incorrect number of bytes per sector %u (ntfs) != %u (hd)
",
ntfs_sector_size(ntfs_header), disk_car->sector_size);
}

if(partition->part_size>0)
{
uint64_t part_size;
part_size=le64(ntfs_header->sectors_nbr)+1;

if(part_size*ntfs_sector_size(ntfs_header)>partiti  on->part_size)
{
screen_buffer_add("error: size boot_sector %lu > partition %lu
",(long unsigned)part_size,(long unsigned)(partition->part_size/disk_car->sector_size));
log_error("error: size boot_sector %lu > partition %lu
",(long unsigned)part_size,(long unsigned)(partition->part_size/disk_car->sector_size));
return 1;
}
if(verbose>0 && (part_size!=partition->part_size/disk_car->sector_size))
{
log_info("info: size boot_sector %lu, partition %lu
",(long unsigned)part_size,(long unsigned)(partition->part_size/disk_car->sector_size));
}
}
partition->upart_type=up_ntfs;
return 0;
}

----------

