PROBLEM: fstat(2) returns st_size==0 for non-empty FIFO.

From: John Wenker
Date: Tue Sep 09 2008 - 19:34:13 EST


A colleague has run into a problem. We assume it's a kernel issue. Here
is the pertinent bug report data.

[1.] One line summary of the problem:
fstat(2) returns st_size == 0 for a FIFO that is known to have data in it.

[2.] Full description of the problem/report:
When using a FIFO, fstat(2) (and stat(2)) returns a 'struct stat' with the
st_size field equal to zero, at a time when the FIFO is known to have data
in it. Problem occurs with Linux 2.6.16 kernel (see more below), but does
not occur on 2.4.20.

[3.] Keywords (i.e., modules, networking, kernel):
stat, fstat, FIFO, struct stat, st_size, system call, write

[4.] Kernel version (from /proc/version):
Linux version 2.6.16.13-4-default (geeko@buildhost) (gcc version 4.1.0
(SUSE Linux)) #1 Wed May 3 04:53:23 UTC 2006

Note: Problem does _not_ occur on Linux version 2.4.20-8
(bhcompile@xxxxxxxxxxxxxxxxxxxxxx) (gcc version 3.2.2 2003022 (Red Hat
Linux 3.2.2-5)) #1 Thu Mar 13 17:54:28 EST 2003

[5.] Output of Oops.. message (if applicable) with symbolic information
resolved (see Documentation/oops-tracing.txt)
No oops. Problem doesn't cause system crash, only affects behavior of
user applications.

[6.] A small shell script or example program which triggers the
problem (if possible)
I don't know if this qualifies as "small", but there is a 'C' program
attached that will reproduce the problem (fifo.c).



[7.] Environment
[7.1.] Software (add the output of the ver_linux script here)
See attached file (ver-linux.out).



[7.2.] Processor information (from /proc/cpuinfo):
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 79
model name : AMD Athlon(tm) 64 Processor 3500+
stepping : 2
cpu MHz : 1000.000
cache size : 512 KB
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm
3dnowext 3dnow pni cx16 lahf_lm svm cr8_legacy
bogomips : 2007.28
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc


[7.3.] Module information (from /proc/modules):
nfs 210744 4 - Live 0xffffffff8826f000
lockd 70256 2 nfs, Live 0xffffffff8825c000
nfs_acl 4096 1 nfs, Live 0xffffffff8814a000
sunrpc 152392 4 nfs,lockd,nfs_acl, Live 0xffffffff88235000
af_packet 22028 0 - Live 0xffffffff8822e000
ipv6 252000 12 - Live 0xffffffff881ef000
cpufreq_ondemand 6956 1 - Live 0xffffffff881ec000
cpufreq_userspace 4500 0 - Live 0xffffffff881e9000
cpufreq_powersave 2176 0 - Live 0xffffffff88075000
powernow_k8 10512 0 - Live 0xffffffff881e5000
freq_table 5128 1 powernow_k8, Live 0xffffffff881e2000
edd 10504 0 - Live 0xffffffff881de000
snd_pcm_oss 49024 0 - Live 0xffffffff881d1000
snd_mixer_oss 18304 1 snd_pcm_oss, Live 0xffffffff881cb000
snd_seq 55712 0 - Live 0xffffffff881bc000
snd_seq_device 9360 1 snd_seq, Live 0xffffffff881b8000
button 7968 0 - Live 0xffffffff881b5000
battery 11016 0 - Live 0xffffffff881b1000
ac 5896 0 - Live 0xffffffff881ae000
apparmor 53540 0 - Live 0xffffffff8819f000
aamatch_pcre 14464 1 apparmor, Live 0xffffffff8819a000
loop 16016 0 - Live 0xffffffff88195000
dm_mod 59976 0 - Live 0xffffffff88185000
ohci_hcd 19460 0 - Live 0xffffffff8817f000
ehci_hcd 30216 0 - Live 0xffffffff88174000
usbcore 130600 3 ohci_hcd,ehci_hcd, Live 0xffffffff88153000
forcedeth 23684 0 - Live 0xffffffff8814c000
snd_hda_intel 19228 0 - Live 0xffffffff88144000
snd_hda_codec 172800 1 snd_hda_intel, Live 0xffffffff88118000
ide_cd 40480 0 - Live 0xffffffff8810d000
cdrom 36008 1 ide_cd, Live 0xffffffff88103000
snd_pcm 97292 3 snd_pcm_oss,snd_hda_intel,snd_hda_codec, Live
0xffffffff880ea000
snd_timer 24968 2 snd_seq,snd_pcm, Live 0xffffffff880e2000
snd 65192 8
snd_pcm_oss,snd_mixer_oss,snd_seq,snd_seq_device,snd_hda_intel,snd_hda_codec,snd_pcm,snd_timer,
Live 0xffffffff880d1000
soundcore 10656 1 snd, Live 0xffffffff880cd000
snd_page_alloc 10640 2 snd_hda_intel,snd_pcm, Live 0xffffffff880c9000
reiserfs 222464 2 - Live 0xffffffff88091000
fan 5640 0 - Live 0xffffffff8808e000
thermal 15888 0 - Live 0xffffffff88089000
processor 26068 2 powernow_k8,thermal, Live 0xffffffff88081000
sg 35240 0 - Live 0xffffffff88077000
sata_nv 10628 3 - Live 0xffffffff88071000
libata 74136 1 sata_nv, Live 0xffffffff8805d000
amd74xx 15024 0 [permanent], Live 0xffffffff88058000
sd_mod 17688 4 - Live 0xffffffff88052000
scsi_mod 145328 3 sg,libata,sd_mod, Live 0xffffffff8802d000
ide_disk 16512 0 - Live 0xffffffff88027000
ide_core 145380 3 ide_cd,amd74xx,ide_disk, Live 0xffffffff88002000

[7.4.] Loaded driver and hardware information (/proc/ioports, /proc/iomem)
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
0060-006f : keyboard
0070-0077 : rtc
0080-008f : dma page reg
00a0-00a1 : pic2
00c0-00df : dma2
00f0-00ff : fpu
0170-0177 : ide1
0376-0376 : ide1
03c0-03df : vesafb
0960-0967 : 0000:00:0f.0
0960-0967 : sata_nv
0970-0977 : 0000:00:0e.0
0970-0977 : sata_nv
09e0-09e7 : 0000:00:0f.0
09e0-09e7 : sata_nv
09f0-09f7 : 0000:00:0e.0
09f0-09f7 : sata_nv
0b60-0b63 : 0000:00:0f.0
0b60-0b63 : sata_nv
0b70-0b73 : 0000:00:0e.0
0b70-0b73 : sata_nv
0be0-0be3 : 0000:00:0f.0
0be0-0be3 : sata_nv
0bf0-0bf3 : 0000:00:0e.0
0bf0-0bf3 : sata_nv
0cf8-0cff : PCI conf1
2000-207f : motherboard
2080-20ff : motherboard
4000-407f : motherboard
4000-4003 : PM1a_EVT_BLK
4004-4005 : PM1a_CNT_BLK
4008-400b : PM_TMR
401c-401c : PM2_CNT_BLK
4020-4027 : GPE0_BLK
4080-40ff : motherboard
4400-447f : motherboard
4480-44ff : motherboard
44a0-44af : GPE1_BLK
4800-487f : motherboard
4880-48ff : motherboard
4c00-4c3f : 0000:00:0a.1
4c40-4c7f : 0000:00:0a.1
9000-9fff : PCI Bus #02
a000-afff : PCI Bus #03
ac00-acff : 0000:03:08.0
b000-bfff : PCI Bus #01
c800-c807 : 0000:00:14.0
c800-c807 : forcedeth
cc00-cc0f : 0000:00:0f.0
cc00-cc0f : sata_nv
e000-e00f : 0000:00:0e.0
e000-e00f : sata_nv
f400-f40f : 0000:00:0d.0
f400-f407 : ide0
f408-f40f : ide1

00000000-0009f7ff : System RAM
00000000-00000000 : Crash kernel
0009f800-0009ffff : reserved
000a0000-000bffff : Video RAM area
000c0000-000cebff : Video ROM
000f0000-000fffff : System ROM
00100000-1beeffff : System RAM
00100000-002b0381 : Kernel code
002b0382-0037020f : Kernel data
1bef0000-1bef2fff : ACPI Non-volatile Storage
1bef3000-1befffff : ACPI Tables
1c000000-1fffffff : reserved
30000000-3001ffff : 0000:00:05.0
e0000000-efffffff : 0000:00:05.0
e0000000-e3ffffff : vesafb
f0000000-f3ffffff : reserved
fa000000-faffffff : 0000:00:05.0
fb000000-fbffffff : 0000:00:05.0
fc800000-fd7fffff : PCI Bus #03
fc800000-fcffffff : 0000:03:08.0
fd7ff000-fd7ff1ff : 0000:03:08.0
fda00000-fdafffff : PCI Bus #02
fdb00000-fdbfffff : PCI Bus #02
fdc00000-fdcfffff : PCI Bus #01
fdd00000-fddfffff : PCI Bus #03
fde00000-fdefffff : PCI Bus #01
fe024000-fe027fff : 0000:00:10.1
fe024000-fe027fff : ICH HD audio
fe02b000-fe02bfff : 0000:00:14.0
fe02b000-fe02bfff : forcedeth
fe02c000-fe02cfff : 0000:00:0f.0
fe02c000-fe02cfff : sata_nv
fe02d000-fe02dfff : 0000:00:0e.0
fe02d000-fe02dfff : sata_nv
fe02e000-fe02e0ff : 0000:00:0b.1
fe02e000-fe02e0ff : ehci_hcd
fe02f000-fe02ffff : 0000:00:0b.0
fe02f000-fe02ffff : ohci_hcd
fec00000-ffffffff : reserved

[7.5.] PCI information ('lspci -vvv' as root)
See attached file (lspci.out).



[7.6.] SCSI information (from /proc/scsi/scsi)
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: ST3160812AS Rev: 3.AH
Type: Direct-Access ANSI SCSI revision: 05

[7.7.] Other information that might be relevant to the problem
(please look in /proc and include all information that you
think to be relevant):
None.

[X.] Other notes, patches, fixes, workarounds:
None.

Thank you!

John Wenker
jjw@xxxxxx

Attachment: fifo.c
Description: Binary data

Attachment: ver_linux.out
Description: Binary data

Attachment: lspci.out
Description: Binary data