Re: confusion on fopen()/falloc()

From: John-Mark Gurney (gurney_j_at_resnet.uoregon.edu)
Date: 02/26/05

  • Next message: ALeine: "Re: Sharing data between user space and kernel"
    Date: Sat, 26 Feb 2005 01:47:20 -0800
    To: Yan Yu <yanyu@CS.UCLA.EDU>
    
    

    Yan Yu wrote this message on Sat, Feb 26, 2005 at 01:10 -0800:
    > Hello, all,
    > I have a user program as below:
    > FILE *fd;
    > while (1)
    > {
    > fd= fopen( "tmp", "r" );
    > if ( fd == NULL )
    > break;
    > }
    >
    > from my understanding, since i open the same file to read, my process
    > should create a new file descriptor each time when fopen is called.
    > Therefore, inside the kernel, fdalloc() should be called, NOT falloc()
    > (since falloc() allocates a new FILE * struct in addition to a new file
    > descriptor),
    > BUT based on what i observed (i instrumented falloc() function), it seems
    > that falloc() is called each time when fopen() is called.
    > I am wondering where i missed?

    first off, if you are looking at this code, you probably want to be
    calling open instead of fopen... fopen is stdio and is implemented in
    src/lib/libc/stdio/fopen.c... There it'll do an open system call, but
    you don't have as direct control over it... Also, the kernel is not
    responsible for FILE * allocations, that is purely a userland
    implementation detail.. it will end up getting mapped to a file
    descriptor opened via open...

    if you look in src/sys/kern/vfs_syscalls.c at open, it calls kern_open
    (in the same file) which calls falloc... falloc by it's comment does
    more than just allocate a file descriptor, it also allocates a new file
    structure, but then it does call fdalloc to get the file descriptor..

    Again, make sure you don't confuse the userland FILE * with the kernel..

    -- 
      John-Mark Gurney				Voice: +1 415 225 5579
         "All that I will do, has been done, All that I have, has not."
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: ALeine: "Re: Sharing data between user space and kernel"

    Relevant Pages

    • Re: [Query] regarding sock_ioctl in linux kernel
      ... It seems that whenever socket is allocated it is also mapped with its ... no ommission in new type of socket allocations in future. ... > I found that the kernel is handling the socket pointer ... > init module and map it to file descriptor using ...
      (Linux-Kernel)
    • Sarge Installation: partman fails with SATA378 TX2Plus
      ... I'm trying to install Debian on a new Sager 9880 notebook, ... The 2.4 kernel successfully configures my network, ... controller is recognized as a "Promise Technology, ... File descriptor 3 left open ...
      (Debian-User)
    • Re: Writing a plain text file to disk from kernel space
      ... Attached is a fully self contained kernel module and associated makefile that demonstrates the problem I'm having. ... writes a line of text to the opened file descriptor ... static int testfd = 0; ... return err; ...
      (freebsd-hackers)
    • Re: DRb connection error with more than 250+ DRb services
      ... > for a flaw in UNIX design that introduces possible DoS by exhausting ... > kernel memory/structures. ... means is that the system resources consumed by the file descriptor (which is ... resources consumed by an actual open file or network connection, ...
      (comp.lang.ruby)
    • Re: process file descriptor limit handling
      ... > will allow the current kernel behavior to continue to exist. ... functions that allocate a file descriptor shall fail with errno set ... Anyway, here's a simple patch that would fail the second setrlimit, as you ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)