On Tue, 11 Mar 2003, Russ Christensen wrote:
> Thank you for creating and releasing the NTFS user libraries. It is much
> appreciated.
You are welcome. (-:
> I would like to ask a question on why the API for dealing with runlists is
> setup the way it is.
>
> I have a file that is fragmented ~2000 times. I am trying to find out what
> clusters this file is using. When dealing with runlists one much check to
> see if the runlist element is mapped and if not then call
> ntfs_attr_map_runlist(). I have found that for my file that is fragmented
> 2000 times I must call ntfs_attr_map_runlist()12 times to get the complete
> runlist.
>
> I think I am missing something. What advantage does this method have over
> just getting the entire runlist to start with?
Files are not necessarily read from start to finish in one go. Many files
are read in a random access patern or only parts of files are read and
other parts are never touched. Getting the whole run list at once can be
very slow if multiple extent mft records have to be read, the attribute
record looked up in each and each mapping pairs array decompressed and the
run lists created. If this was done at ntfs_attr_open() time or at the
first ntfs_attr_pread() time, it could potentially cause a delay, i.e. the
function could take a few seconds to complete. That kind of delay would be
very noticeable even if it occurs only on some files and only the first
time the file is accessed.
By reading the various run list pieces on demand the delay is split into
several small delays which are not noticable and interactive performance
is improved. Also we don't end up reading parts of the run list which
never would have been read otherwise (because the user only read a small
portion of the file or whatever).
> [Sample Code showing what I am talking about:]
[snip]
Instead of your sample code, you could instead use
ntfs_attr_vcn_to_lcn(na, vcn) like this:
for (vcn = 0; vcn < end_of_file_vcn; vcn++) {
cluster = ntfs_attr_vcn_to_lcn(na, vcn);
if (cluster < 0)
error_exit();
< do something with the cluster >
}
This is slower and not as efficient but makes for easier to read code.
Alternatively we could provide a function in the library that would just
go and read in the whole run list. Would you like to see such a function?
If so I will add it as a TODO.libntfs item...
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cantab.net> (replace at with @)
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
|