[TriLUG] cp and a new fs, eg ntfs
Kevin Hunter
hunteke at earlham.edu
Fri Jul 30 23:04:31 EDT 2010
At 3:34pm -0600 Fri, 30 Jul 2010, Joseph Mack NA3T wrote:
> I'm wondering how cp on linux works. I have ntfs-3g mounting windows
> disks. Does cp have to be ntfs-3g (or fs) aware?
No. This is handled by the wonders of the kernel. Deep in the
internals of cp code, there is something to effect of
src = open('source_filename', 'read only')
dst = open('new_filename', 'write only, create if needed')
while (! done ) {
data = read(src, bufsize)
done = write(dst, data)
}
Please forgive my pseudo code as there is quite a bit more surrounding
code and logic and the call signatures are a bit more complex, but the
point is that through the system calls of open, read, and write,* the cp
source code need not know /how/ it's getting data from a file, just that
it is. Similarly, it need know /how/ it's writing to some destination,
just that it is.
By virtue of the path filename working out to be on an NTFS mounted
filesystem, the kernel automatically handles "NTFS driver: create this
file" and "NTFS driver: write this data to that file."
As with most commands, cp is little more than a (very important!)
wrapper around a set of system calls.
> If I cp ntfs to ntfs, will the permissions (or whatever is unique to
> ntfs) get copied correctly?
As long as the NTFS driver understands the permissions, and they map to
something reasonable in Unix permissions, yes. If they don't map to
Unix permissions, I believe it still works because the cp command will
treat them as just bits that it doesn't understand and copy them anyway.
Kevin
* I promise that I also have the semantics and names of the system calls
wrong. The point is that everything goes through the kernel via system
calls, and that's where the FS drivers plug in.
More information about the TriLUG
mailing list