P
P
psiklop2022-02-11 02:11:33
linux
psiklop, 2022-02-11 02:11:33

How to write a file to a specific location in hdd?

Is it possible to specify an indent in bytes when creating a file?

I want to try to write the file directly to badblock, the list was given by the badblocks command in Ubuntu, there are not many of them, but the necessary program crashes.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Z
Zettabyte, 2022-02-11
@psiklop

Under Windows, this unusual trick can be done in your own code using FSCTL_MOVE_FILE . Those. not creating a file, but moving an existing one.
Either by throwing a bunch of files on the disk, and then using nfi.exe (NTFS File Sector Information Utility) , or DiskView , or fsutil querycluster to see what exactly lies in the sectors you are interested in.
The same can be done in a hex editor, but this requires some understanding of file systems.
Under Linux, take a look at the sources dd(as a potential source of ideas) and look --write-sectorat hdparm .
You can also use debugfs:

debugfs:  testb 100500
Block 100500 marked in use
debugfs:  icheck 100500
Block   Inode number
100500  1488
debugfs:  ncheck 1488
Inode   Pathname
1488    /home/psiklop/hentai.mkv

In addition, there was DiskExplorer at one time , but RunTime, in my opinion, has not updated their tools for a very long time, so I don’t know how it works now.
the required program crashes

Generally speaking, such an idea in itself is not very good. You have already started crashing, and in the future the disk will not become healthier, it will only continue to be covered with bads.
So writing files, creating partitions around, healing (remap) and other tricks regarding bad blocks is a patch on a dying horse.
Back up the contents of the entire disk and try to return it under warranty if it has not ended. If it's over, then use it as a dump for what you don't mind losing.

S
Saboteur, 2022-02-11
@saboteur_kiev

Is it possible to specify an indent in bytes when creating a file?

No.
I want to try to write the file directly to badblock, the list was given by the badblocks command in Ubuntu, there are not many of them, but the necessary program crashes.

This is not possible due to the fact that the block is not part of the file system.
In addition, you apparently do not understand well how a modern disk works, and that it has not been repaired by such methods for a long time.
True, if you have a 25-year-old computer, maybe you can.

P
Puma Thailand, 2022-02-11
@opium

Of course not

R
rPman, 2022-02-11
@rPman

sudo fsck -vck /dev/sda1
where sda1 is the partition with the file system where you need to check and mark bad blocks

-c This option causes e2fsck to use badblocks(8) program to do a read-only scan of the device in order to find any bad blocks. If any bad blocks are found, they are added to the bad block inode to prevent them from
being allocated to a file or directory. If this option is specified twice, then the bad block scan will be done using a non-destructive read-write test.

if you have a list of bad blocks in the format issued by badblocks, then you can format the file system immediately by specifying the necessary sectors:
mke2fs switch -l
ps this is about the ext3 / ext4 file system
, as the answerers here already said, doing it on modern (10 years old) can be meaningless, the number of bad sectors will increase, since the classic example of their appearance is the exfoliated part of the disk surface - this flake will fly inside the disk and leave more and more bad blocks.

P
psiklop, 2022-02-11
@psiklop

I forgot to write that this is a SAS disk.
The bad block did not want to remap, but the badblocks team always found them in the same place.
The team helped sg_format --format /dev/sdb, all 8 bads were repaired and the team smartctl -a /dev/sdbconfirmed this.
Later I launched badblocks and it did not find bads, let's see how long the disk will live.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question