Added file under /proc, when FDB entries are larger, system crashes

Added file under /proc, when FDB entries are larger, system crashes

Post by Sant » Sun, 04 Apr 2004 08:25:04



I added a file under /proc for Proc file system. When our FDB mac
entries are higher (around 1K entries) it crashes, I couldn't able to
figureout the problem. This is working for 256 entries, if the MAC
entries are more than 1K then crashes. Appreciated for help.

static int proc_read_arlentry(char *page, char **start,
                            off_t off, int count,
                            int *eof, void *data)
{
        int len =0;
        arl_entry_t arl_entry;
        u32 first = 1;

        do{
                if(get_arl_entry (&arl_entry, first) == 0){ //valid MAC
                        len += sprintf(page+len, "MAC Addr:\t
%02x:%02x:%02x:%02x:%02x:%02x\n",
                                                        arl_entry.mac[0],
                                                        arl_entry.mac[1],
                                                        arl_entry.mac[2],
                                                        arl_entry.mac[3],
                                                        arl_entry.mac[4],
                                                        arl_entry.mac[5]);
                        len += sprintf(page+len, "ARL Flag:\t 0x%lx\n", arl_entry.flag);

                }
                first = 0;
        }while(!(arl_entry.flag & 0x01)); // end of table

        //*eof = 1;

        *start = page+off;
        len -= off;
        if (len < count) {
                *eof = 1;
                if(len <= 0)
                        return 0;
        } else
                len = count;

        return len;

Quote:}

 
 
 

1. reading /proc files larger than one buffer

If you follow the directions in Documentation/DocBook/procfs-guide.tmpl
then your file read will not work correctly unless the whole file is
read in one call.

After examining (and experimenting with) fs/proc/generic.c I now see
what you have to do: in addition to writing bytes in the page
parameter, setting eof as appropriate and returning the number of
bytes written, you also need to do:
 *start = page;
At minimum the documentation should be corrected.

Actually I think this is a bug in proc_file_read.
The problem seems to be in this code, executed after the read function:

               if (!start) {
                        /*
                         * For proc files that are less than 4k
                         */
                        start = page + *ppos;
                        n -= *ppos;
                        if (n <= 0)
                                break;
                        if (n > count)
                                n = count;
                }

Can anyone explain what it's supposed to do?
What does it have to do with files < 4k ?

The addition of "*start = page;" both sets start to the correct value
and avoids executing the problematic code above.
[Note: The "start" in your read function is actually the address of
the "start" in proc_file_read.]

Therefore I think that code should be

               if (!start) start=page;

The current code normally works for the first read because *ppos is 0.
Otherwise:
- start is given the wrong value (should be page)
- n is the number of bytes read, and it makes no sense to reduce that
 by ppos, which is the file position at which you were supposed to
 start reading.  

The behavior I saw was that on the second buffer count and ppos were
both 512 (asked to read bytes 512-1023).  My function returned 512,
so n was set to 0, which was then interpreted as eof.

Please cc me on replies.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Porting DevGuide-Applications to Linux

3. add buddyinfo /proc entry

4. HELP: Name server, loopback

5. Adding /proc entry - how hard?

6. XFree86 3.9.17 on RH6.1 compilation errors

7. [RFCA] Sound: adding /proc/driver/{vendor}/{dev_pci}/ac97 entry for es1371 driver

8. Firefox 1.5 for solaris available on mozilla.org

9. System is crashing if I am using more then one disk on scsi controler :(

10. how to remove entry from any file in /proc

11. kernel: Cannot read proc file system: 9 - Bad file descriptor

12. Enhanced Filing system - file system like DEC Advanced File system for Linux

13. root file system full - how do I delete the files in /proc