Re: OT: why no file copy() libc/syscall ??

From: Jesse Pollard (jesse_at_cats-chateau.net)
Date: 11/10/03

  • Next message: Stan Benoit: "sparc 20 problem ver test9"
    To: "Ihar 'Philips' Filipau" <filia@softhome.net>, Davide Rossetti <davide.rossetti@roma1.infn.it>
    Date:	Mon, 10 Nov 2003 07:29:15 -0600
    
    

    On Monday 10 November 2003 06:08, Ihar 'Philips' Filipau wrote:
    > sendfile(2) - ?
    I don't think that is what he was referring to.. The sample
    code is strictly user mode file->file copying.
    > Davide Rossetti wrote:
    > > it may be orribly RTFM... but writing a simple framework I realized
    > > there is no libc/POSIX/whoknows
    > > copy(const char* dest_file_name, const char* src_file_name)
    > >
    > > What is the technical reason???

    It isn't an application for the kernel.

    > > I understand that there may be little space for kernel side
    > > optimizations in this area but anyway I'm surprised I have to write
    > >
    > > < the bits to clone the metadata of src_file_name on opening
    > > dest_file_name >
    > > const int BUFSIZE = 1<<12;
    > > char buffer[BUFSIZE];
    > > int nrb;
    > > while((nrb = read(infd, buffer, BUFSIZE) != -1) {
    > > ret = write(outfd, buffer, nrb);
    > > if(ret != nrb) {...}
    > > }
    > >
    > > instead of something similar to:
    > > sys_fscopy(...)

    It is too simple to implement in user mode.

    There are some other issues too:

    The security context of the output depends on the user process.
    If it is a privileged process (ie, may change the context of the
    result) then the user process has to setup that context before
    the file is copied.

    There are also some issues with mandatory security controls. If it
    is copied in kernel mode, then the previous labels could be automatically
    carried over to the resulting file... But that may not be what you
    want (and frequently, it isn't).

    Now back to the copy.. You don't have to use a read/write loop- mmap
    is faster. And this is the other reason for not doing it in Kernel mode.
    Buffer management of this type is much easier in user space since the
    copy procedure doesn't have to deal with memory limitations, cache flushes
    page faulting of processes unrelated to the copy, but is related to cache
    pressure.
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Stan Benoit: "sparc 20 problem ver test9"

    Relevant Pages

    • User mode/Kernel Mode context question
      ... in the correct user mode context, you can call a user mode function from ... the kernel mode and to be sure of the context. ... The OSR article was probably written in the era of INT 2E. ...
      (microsoft.public.development.device.drivers)
    • Re: How to check kernel or user mode
      ... > kernel or user mode on x86/Linux? ... you asking whether it's a kernel process or a user process? ... asking, assuming it's a normal user process, how to tell which mode it's in ...
      (comp.os.linux.development.system)
    • Re: OT: why no file copy() libc/syscall ??
      ... engineer did not add the spec a user-mode API to do copy file to file ??? ... > The security context of the output depends on the user process. ... And this is the other reason for not doing it in Kernel mode. ...
      (Linux-Kernel)
    • Re: SpinLock/Mutex : Difference ?
      ... Doing spinlocks from a user mode is UTTERLY out of the wall idea. ... and that is the separation of user and kernel mode. ... Need to have strong "communication skills" ... spinlock owner is guaranteed to never get preempted by another thread. ...
      (microsoft.public.win32.programmer.kernel)
    • Memory Access Violation
      ... Note - Times include both user mode and kernel mode for each thread Thread ... Time spent in kernel mode 0 Days 0:0:0.93 ... Function Source ...
      (microsoft.public.inetserver.iis)