Subject: mmap() bug when mapping files on ccd's?
To: None <current-users@NetBSD.ORG, port-amiga@NetBSD.ORG>
From: Per Bojsen <pb@delta.dk>
List: current-users
Date: 03/18/1996 16:13:31
Hi!

Yesterday I experienced very strange behavior from mmap().  I'm
running NetBSD/Amiga 1.1 and the problem showed up when mmap()'ing
files on FFS filesystems created on ccd partitions (but not on normal
disk partitions).  The bug can be demonstrated and reproduced by doing
the following:

	% echo foo > bar
        % vi bar
	:q
        % echo error > bar
        % vi bar
	:q

If the file `bar' is created on a ccd partition, the second invocation
of vi will show bar as containing the previous contents padded to the
new size of `bar' with NULs!  But cat'ing `bar' shows that it does
contain what was echo'ed to it.

Another way to demonstrate the problem is the following (which was how
I discovered the bug) (again, the x.c file should be created on a ccd
partition):

	% echo 1.1 > x.c
	% ci -tx.c -mm x.c
	% co -l x.c
	% echo 1.2 > x.c
	% ci -l -mm x.c
	% echo error > x.c
	% ci -mm x.c
	% co x.c
	% cat x.c
	1.2
	%

The x.c file actually includes two NULs at the end.

That the problem is related to mmap() may be verified by running the
enclosed program:

	moria% echo foo > bar  
	moria% mmaptest bar
	mmap(): 0x08022000, 4
	mmap(): foo

	moria% echo error > bar
	moria% mmaptest bar
	mmap(): 0x08022000, 6
	mmap():   foo

	moria% od -cx bar
	0000000   e   r   r   o   r  \n
		6572 726f 720a
	0000006

Is this a known problem?  Does anybody else see this?

begin 644 mmaptest.c.gz
M'XL(`*Z13#$"`VU374_;,!1]3G[%&8,IJ;*T?=@''47K"FA(,%#@9=I0E29.
MXRVQ(]ME[5#_^ZZ=E%5`'QKGW'/NN1].O^?W>KAEVD`6,"5#7:=-$")+JPI&
M(F>U%-JHU##,EPNBI`9<@ZU*/N>&Y9BO;8J,!\,0A9(UDND-WL4?8H)M9"J;
MM>*+TB"8AA@>'K['-5/X(G]I)F)@0D:)C6LD3#-US_*M=/\\W^^.DZ4II1KM
M2''4S#_GK#)IG/\^MIPS7K&1:\!00W'V6$!=,V%2M1YU"'!;4@^-D@N5UK!L
MO6U<"A241^,/-Z6;R.7EY'IV\W62G)Z@J-(%5=?W_==<9-4R9SC2:]TWZX;I
MN#Q^`A>9,-5SF*S$<U2;U#Q!3<ZEA7PNC%^G7`1T0*H6682L3!5Z=+[_<1?Z
M#S[`"P0VAF,,0WJW&*&D*'*,(1LF`L<?WD6XFB4G5]\NOH>?_)9&XB(/W;D5
M`K3W969@"W-_2]V1.[K%2!3A31L-,1YC$':4!]]K:[3S/!>7K":U9X7!(T)E
MN;D/(@2:_V4S$W9.L38SBT2X3JYN9\GIY"3R/<]K<]N5G)U?G$:P]H,PQ*LQ
M@M8NQ%MJWR-[T(JI_2+8:Y<[PF!U,/A8K2(<5/E/L1?AL1(JH))B\=2>QO-"
MFH.>=NH7)3M)[7"]=ECU4ECQKM_+#;LAN@YLHPU32BIR=O(]6\[&]UBEF:MK
M&^UB[7`VW=.QT/VV5+>T_]SND552,[O_%F\S[.BW:GN'6O'&W@2VXB88T/L&
1_1[L!05]&_\`H+%B_U4$``#N
`
end

-- 
Per Bojsen                                   Email: pb@delta.dk
DELTA IC Design                                     bojsen@moria.home.id.dtu.dk
Venlighedsvej 4, Hoersholm, Denmark