On Thu, 12 Dec 2002, Szakacsits Szabolcs wrote:
> On Thu, 12 Dec 2002, Anton Altaparmakov wrote:
> > applied, thanks. well spotted again. I had actually fixed this exactly
> > same bug ages ago in the NTFS kernel driver but I obviously had forgotten
> > to port the fix to the library. A very annoying oversight on my part!
>
> BTW, I wanted to ask for long but actually how much code is shared
> between the user and kernel "drivers"? I'm afraid zero. I know it's
> not trivial but there are codes (filesystems) that has this very
> nice feature.
The code is simillar (especially in functionality) but there are varying
amounts of differences between kernel and library code. Differences are
based on completely different amounts of caching and lack thereof in the
kernel and library, respectively. Basically the kernel code's entry points
are the VFS and the page cache/MM code while the library entry points are
from applications which do completely different things so the driver and
the library are naturally very different. Further the header file includes
are different as the kernel gets things from include/linux while userspace
is not allowed to do so. So basically it becomes a much bigger nightmare
to share code between the two then to have them separate...
Also the driver is in the kernel so there is no way to keep the code
shared now. It would have been possible when the code was outside the
kernel but now it would just make a huge PITA.
> > > 3. ntfs_extent_inode_open: extents are copied to a newly
> > > allocated memory. Before using just the pointer equality the
> > > memory was freed by the extent and the base inode happily used
> > > the unfreed memory => severe memory corruptions.
> >
> > I don't understand this description and I don't understand why you are
> > doing the copying.
>
> You allocate an ntfs_inode for an extent then attach it *also* to the
> extents of it's base inode,
Wrong. We don't *also* attach it to its base inode. We *only* attach it to
its base inode. Extent inodes are illegal and cannot exist/be open without
their base inode being open, too.
You cannot use the extent inode after you have used the base inode. That
is against the whole concept of extent inodes.
To use an extent inode you *must* do:
ntfs_inode_open(base inode);
ctx = ntfs_attr_get_search_ctx(base inode);
ntfs_attr_lookup(base inode, ctx);
make use of ctx->ntfs_ino (which can be base or extent inode, it doesn't
matter);
ntfs_attr_put_search_ctx(ctx); --> this destroys the extent inode
ntfs_inode_close(base_inode); --> this destroys the base inode
Any other use of extent inodes is illegal and not allowed.
> after you free ntfs_inode => the attached
> extents live in the freed memory and the next time malloc gives
> it away and will be nicely overwritten it.
I don't understand this. When the ntfs inode is closed, all attached
extent inodes are freed automatically. No memory is wasted.
I really don't understand where you see memory being leaked or corrupted.
> > corruptions? - Your fix 2. from above should cure everything. The memory
>
> No, just use a memory debugger or printf the pointer.
I don't see that being necessary unless you can show me the lines of code
that cause the corruption. AFAICS the libntfs code is logically consistent
and does not leak memory anywhere.
I suspect that what you are talking about is simply incorrect use of the
library as opposed to a library bug and obviously this needs to be fixed
not in the library but at the point where it is used.
> > allocations and copying are already done in the if clause fixed by point
> > 2 so I don't see why you repeat them again here. What am I missing?
>
> The if clause copies the extent pointers. Afterwards the ntfs_inode
> are copied to a newly allocated area (because the ntfs_inode in
> question will be freed by ntfs_inode_close but the base inode still
> needs it later on).
You never close extent inodes.
Ah, oops, we do close extent inodes when we do ntfs_attr_put_search_ctx().
Ok, I apologize. There is a bug in the library. It is just that your fix
is completely wrong. I will think about it and fix it properly. At initial
thought, the fix will simply be either to 1) remove the
ntfs_inode_close() call from ntfs_attr_put_search_ctx() and just let the
main call of ntfs_inode_close(base inode) get rid of all the extents, or
2) make ntfs_inode_close(extent inode) remove the inode from the base
inode's list of extent inodes. Either of 1) and 2) would work but I need
to think a little about which we actually want to have. I strongly suspect
we want 1) so we get the extents cached in memory at all times so we don't
have to keep re-reading them.
Ok, I have now done 1) and pushed to the bkbits repository. Also there is
now a new snapshot available in usualy place
(http://linux-ntfs.sf.net/snapshots).
Can people try and let me know if it fixes everything?
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/
|