Hi,
On Wed, 21 Apr 2004 fa...@pa... wrote:
> I know that you are busy but in order to finish my project I need one little
> hint. What I am gonna finish is to expand the utility ntfsfix that check for
> the consistency of the disk. I have creat a code that store the current
> $Bitmap in an array and now I am creating my own bitmap exploring the disk.
>
> For the first task I have used and changed the code you have develop in
> order to check if one cluster is in use or not ( utils_cluster_in_use ). So
> I have stored the $Bitmap in an array.
>
> In order to build my own Bitmap I found in the code of ntfscluster.c the
> function dump_file where for each node give you the number and the lenght of
> the clusters used from the "non_resident" attribute. I loop from the first
> MFT to the last (vol->nr_mft_record) and for each cluster used I marked the
> corresponded bit to one.
>
> Now the problem that as newbie I cannot resolve is that I don't know in
> which cluster is stored each MFT record. So when I access to an MFT I cannot
> mark the bit of the cluster where that MFT reside because I don't know.
That is very easy. The $MFT (i.e. the file with mft record number 0) has
a $DATA attribute (non-resident). This attribute contains all the MFT
records themselves. So the mft record for $MFT itself is at offset zero
in this attribute. Then the mft record 1 ($MFTMirr) is at offset 1024 in
the attribute. The n-th mft record is at offset n * 1024 (== n *
vol->mft_record_size).
> I was wondering that this number could be the number of MFT multiplied for
> the size of the MFT divided per the cluster lenght.
>
> I catch this information reading this code in mft.c :
>
> int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref,
> const s64 count, MFT_RECORD *b)
> {
> s64 br;
> VCN m;
>
> Dprintf("%s(): Entering for inode 0x%llx.\n", __FUNCTION__, MREF(mref));
> if (!vol || !vol->mft_na || !b || count < 0) {
> errno = EINVAL;
> return -1;
> }
> m = MREF(mref);
> if (m + count > vol->nr_mft_records) {
> errno = ESPIPE;
> return -1;
> }
> br = ntfs_attr_mst_pread(vol->mft_na, m << vol->mft_record_size_bits,
> count, vol->mft_record_size, b);
> ........
With what I explained above you should now understand this code. It reads
from the $MFT/$DATA attribute at the offset m * vol->mft_record_size to
get the m-th mft record.
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
|