head	1.9;
access;
symbols
	netbsd-11-0-RC4:1.9
	netbsd-11-0-RC3:1.9
	netbsd-11-0-RC2:1.9
	netbsd-11-0-RC1:1.9
	perseant-exfatfs-base-20250801:1.9
	netbsd-11:1.9.0.98
	netbsd-11-base:1.9
	netbsd-10-1-RELEASE:1.9
	perseant-exfatfs-base-20240630:1.9
	perseant-exfatfs:1.9.0.96
	perseant-exfatfs-base:1.9
	netbsd-8-3-RELEASE:1.9
	netbsd-9-4-RELEASE:1.9
	netbsd-10-0-RELEASE:1.9
	netbsd-10-0-RC6:1.9
	netbsd-10-0-RC5:1.9
	netbsd-10-0-RC4:1.9
	netbsd-10-0-RC3:1.9
	netbsd-10-0-RC2:1.9
	thorpej-ifq:1.9.0.94
	thorpej-ifq-base:1.9
	thorpej-altq-separation:1.9.0.92
	thorpej-altq-separation-base:1.9
	netbsd-10-0-RC1:1.9
	netbsd-10:1.9.0.90
	netbsd-10-base:1.9
	bouyer-sunxi-drm:1.9.0.88
	bouyer-sunxi-drm-base:1.9
	netbsd-9-3-RELEASE:1.9
	thorpej-i2c-spi-conf2:1.9.0.86
	thorpej-i2c-spi-conf2-base:1.9
	thorpej-futex2:1.9.0.84
	thorpej-futex2-base:1.9
	thorpej-cfargs2:1.9.0.82
	thorpej-cfargs2-base:1.9
	cjep_sun2x-base1:1.9
	cjep_sun2x:1.9.0.80
	cjep_sun2x-base:1.9
	cjep_staticlib_x-base1:1.9
	netbsd-9-2-RELEASE:1.9
	cjep_staticlib_x:1.9.0.78
	cjep_staticlib_x-base:1.9
	thorpej-i2c-spi-conf:1.9.0.76
	thorpej-i2c-spi-conf-base:1.9
	thorpej-cfargs:1.9.0.74
	thorpej-cfargs-base:1.9
	thorpej-futex:1.9.0.72
	thorpej-futex-base:1.9
	netbsd-9-1-RELEASE:1.9
	bouyer-xenpvh-base2:1.9
	phil-wifi-20200421:1.9
	bouyer-xenpvh-base1:1.9
	phil-wifi-20200411:1.9
	bouyer-xenpvh:1.9.0.70
	bouyer-xenpvh-base:1.9
	is-mlppp:1.9.0.68
	is-mlppp-base:1.9
	phil-wifi-20200406:1.9
	netbsd-8-2-RELEASE:1.9
	ad-namecache-base3:1.9
	netbsd-9-0-RELEASE:1.9
	netbsd-9-0-RC2:1.9
	ad-namecache-base2:1.9
	ad-namecache-base1:1.9
	ad-namecache:1.9.0.66
	ad-namecache-base:1.9
	netbsd-9-0-RC1:1.9
	phil-wifi-20191119:1.9
	netbsd-9:1.9.0.64
	netbsd-9-base:1.9
	phil-wifi-20190609:1.9
	netbsd-8-1-RELEASE:1.9
	netbsd-8-1-RC1:1.9
	isaki-audio2:1.9.0.62
	isaki-audio2-base:1.9
	pgoyette-compat-merge-20190127:1.9
	pgoyette-compat-20190127:1.9
	pgoyette-compat-20190118:1.9
	pgoyette-compat-1226:1.9
	pgoyette-compat-1126:1.9
	pgoyette-compat-1020:1.9
	pgoyette-compat-0930:1.9
	pgoyette-compat-0906:1.9
	netbsd-7-2-RELEASE:1.9
	pgoyette-compat-0728:1.9
	netbsd-8-0-RELEASE:1.9
	phil-wifi:1.9.0.60
	phil-wifi-base:1.9
	pgoyette-compat-0625:1.9
	netbsd-8-0-RC2:1.9
	pgoyette-compat-0521:1.9
	pgoyette-compat-0502:1.9
	pgoyette-compat-0422:1.9
	netbsd-8-0-RC1:1.9
	pgoyette-compat-0415:1.9
	pgoyette-compat-0407:1.9
	pgoyette-compat-0330:1.9
	pgoyette-compat-0322:1.9
	pgoyette-compat-0315:1.9
	netbsd-7-1-2-RELEASE:1.9
	pgoyette-compat:1.9.0.58
	pgoyette-compat-base:1.9
	netbsd-7-1-1-RELEASE:1.9
	tls-maxphys-base-20171202:1.9
	matt-nb8-mediatek:1.9.0.56
	matt-nb8-mediatek-base:1.9
	nick-nhusb-base-20170825:1.9
	perseant-stdc-iso10646:1.9.0.54
	perseant-stdc-iso10646-base:1.9
	netbsd-8:1.9.0.52
	netbsd-8-base:1.9
	prg-localcount2-base3:1.9
	prg-localcount2-base2:1.9
	prg-localcount2-base1:1.9
	prg-localcount2:1.9.0.50
	prg-localcount2-base:1.9
	pgoyette-localcount-20170426:1.9
	bouyer-socketcan-base1:1.9
	jdolecek-ncq:1.9.0.48
	jdolecek-ncq-base:1.9
	pgoyette-localcount-20170320:1.9
	netbsd-7-1:1.9.0.46
	netbsd-7-1-RELEASE:1.9
	netbsd-7-1-RC2:1.9
	nick-nhusb-base-20170204:1.9
	netbsd-7-nhusb-base-20170116:1.9
	bouyer-socketcan:1.9.0.44
	bouyer-socketcan-base:1.9
	pgoyette-localcount-20170107:1.9
	netbsd-7-1-RC1:1.9
	nick-nhusb-base-20161204:1.9
	pgoyette-localcount-20161104:1.9
	netbsd-7-0-2-RELEASE:1.9
	nick-nhusb-base-20161004:1.9
	localcount-20160914:1.9
	netbsd-7-nhusb:1.9.0.42
	netbsd-7-nhusb-base:1.9
	pgoyette-localcount-20160806:1.9
	pgoyette-localcount-20160726:1.9
	pgoyette-localcount:1.9.0.40
	pgoyette-localcount-base:1.9
	nick-nhusb-base-20160907:1.9
	nick-nhusb-base-20160529:1.9
	netbsd-7-0-1-RELEASE:1.9
	nick-nhusb-base-20160422:1.9
	nick-nhusb-base-20160319:1.9
	nick-nhusb-base-20151226:1.9
	netbsd-7-0:1.9.0.38
	netbsd-7-0-RELEASE:1.9
	nick-nhusb-base-20150921:1.9
	netbsd-7-0-RC3:1.9
	netbsd-7-0-RC2:1.9
	netbsd-7-0-RC1:1.9
	nick-nhusb-base-20150606:1.9
	nick-nhusb-base-20150406:1.9
	nick-nhusb:1.9.0.36
	nick-nhusb-base:1.9
	netbsd-5-2-3-RELEASE:1.8
	netbsd-5-1-5-RELEASE:1.8
	netbsd-6-0-6-RELEASE:1.9
	netbsd-6-1-5-RELEASE:1.9
	netbsd-7:1.9.0.34
	netbsd-7-base:1.9
	yamt-pagecache-base9:1.9
	yamt-pagecache-tag8:1.9
	netbsd-6-1-4-RELEASE:1.9
	netbsd-6-0-5-RELEASE:1.9
	tls-earlyentropy:1.9.0.32
	tls-earlyentropy-base:1.9
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.9
	riastradh-drm2-base3:1.9
	netbsd-6-1-3-RELEASE:1.9
	netbsd-6-0-4-RELEASE:1.9
	netbsd-5-2-2-RELEASE:1.8
	netbsd-5-1-4-RELEASE:1.8
	netbsd-6-1-2-RELEASE:1.9
	netbsd-6-0-3-RELEASE:1.9
	netbsd-5-2-1-RELEASE:1.8
	netbsd-5-1-3-RELEASE:1.8
	rmind-smpnet-nbase:1.9
	netbsd-6-1-1-RELEASE:1.9
	riastradh-drm2-base2:1.9
	riastradh-drm2-base1:1.9
	riastradh-drm2:1.9.0.30
	riastradh-drm2-base:1.9
	rmind-smpnet:1.9.0.22
	rmind-smpnet-base:1.9
	netbsd-6-1:1.9.0.28
	netbsd-6-0-2-RELEASE:1.9
	netbsd-6-1-RELEASE:1.9
	khorben-n900:1.9.0.26
	netbsd-6-1-RC4:1.9
	netbsd-6-1-RC3:1.9
	agc-symver:1.9.0.24
	agc-symver-base:1.9
	netbsd-6-1-RC2:1.9
	netbsd-6-1-RC1:1.9
	yamt-pagecache-base8:1.9
	netbsd-5-2:1.8.0.28
	netbsd-6-0-1-RELEASE:1.9
	yamt-pagecache-base7:1.9
	netbsd-5-2-RELEASE:1.8
	netbsd-5-2-RC1:1.8
	matt-nb6-plus-nbase:1.9
	yamt-pagecache-base6:1.9
	netbsd-6-0:1.9.0.20
	netbsd-6-0-RELEASE:1.9
	netbsd-6-0-RC2:1.9
	tls-maxphys:1.9.0.18
	tls-maxphys-base:1.9
	matt-nb6-plus:1.9.0.16
	matt-nb6-plus-base:1.9
	netbsd-6-0-RC1:1.9
	jmcneill-usbmp-base10:1.9
	yamt-pagecache-base5:1.9
	jmcneill-usbmp-base9:1.9
	yamt-pagecache-base4:1.9
	jmcneill-usbmp-base8:1.9
	jmcneill-usbmp-base7:1.9
	jmcneill-usbmp-base6:1.9
	jmcneill-usbmp-base5:1.9
	jmcneill-usbmp-base4:1.9
	jmcneill-usbmp-base3:1.9
	jmcneill-usbmp-pre-base2:1.9
	jmcneill-usbmp-base2:1.9
	netbsd-6:1.9.0.14
	netbsd-6-base:1.9
	netbsd-5-1-2-RELEASE:1.8
	netbsd-5-1-1-RELEASE:1.8
	jmcneill-usbmp:1.9.0.12
	jmcneill-usbmp-base:1.9
	jmcneill-audiomp3:1.9.0.10
	jmcneill-audiomp3-base:1.9
	yamt-pagecache-base3:1.9
	yamt-pagecache-base2:1.9
	yamt-pagecache:1.9.0.8
	yamt-pagecache-base:1.9
	rmind-uvmplock-nbase:1.9
	cherry-xenmp:1.9.0.6
	cherry-xenmp-base:1.9
	jym-xensuspend-nbase:1.9
	uebayasi-xip-base7:1.9
	bouyer-quota2-nbase:1.9
	bouyer-quota2:1.9.0.4
	bouyer-quota2-base:1.9
	jruoho-x86intr:1.9.0.2
	jruoho-x86intr-base:1.9
	matt-mips64-premerge-20101231:1.9
	matt-nb5-mips64-premerge-20101231:1.8
	matt-nb5-pq3:1.8.0.26
	matt-nb5-pq3-base:1.8
	netbsd-5-1:1.8.0.24
	uebayasi-xip-base6:1.9
	uebayasi-xip-base5:1.9
	netbsd-5-1-RELEASE:1.8
	uebayasi-xip-base4:1.9
	uebayasi-xip-base3:1.9
	yamt-nfs-mp-base11:1.9
	netbsd-5-1-RC4:1.8
	matt-nb5-mips64-k15:1.8
	uebayasi-xip-base2:1.9
	yamt-nfs-mp-base10:1.9
	netbsd-5-1-RC3:1.8
	netbsd-5-1-RC2:1.8
	uebayasi-xip-base1:1.9
	netbsd-5-1-RC1:1.8
	rmind-uvmplock:1.8.0.22
	rmind-uvmplock-base:1.9
	yamt-nfs-mp-base9:1.8
	uebayasi-xip:1.8.0.20
	uebayasi-xip-base:1.8
	netbsd-5-0-2-RELEASE:1.8
	matt-nb5-mips64-premerge-20091211:1.8
	matt-premerge-20091211:1.8
	yamt-nfs-mp-base8:1.8
	matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.8
	matt-nb4-mips64-k7-u2a-k9b:1.8
	matt-nb5-mips64-u1-k1-k5:1.8
	yamt-nfs-mp-base7:1.8
	matt-nb5-mips64:1.8.0.18
	netbsd-5-0-1-RELEASE:1.8
	jymxensuspend-base:1.8
	yamt-nfs-mp-base6:1.8
	yamt-nfs-mp-base5:1.8
	yamt-nfs-mp-base4:1.8
	yamt-nfs-mp-base3:1.8
	nick-hppapmap-base4:1.8
	nick-hppapmap-base3:1.8
	netbsd-5-0:1.8.0.16
	netbsd-5-0-RELEASE:1.8
	netbsd-5-0-RC4:1.8
	netbsd-5-0-RC3:1.8
	nick-hppapmap-base2:1.8
	netbsd-5-0-RC2:1.8
	jym-xensuspend:1.8.0.14
	jym-xensuspend-base:1.9
	netbsd-5-0-RC1:1.8
	haad-dm-base2:1.8
	haad-nbase2:1.8
	ad-audiomp2:1.8.0.12
	ad-audiomp2-base:1.8
	netbsd-5:1.8.0.10
	netbsd-5-base:1.8
	nick-hppapmap:1.8.0.8
	nick-hppapmap-base:1.8
	matt-mips64-base2:1.8
	haad-dm-base1:1.8
	wrstuden-revivesa-base-4:1.8
	netbsd-4-0-1-RELEASE:1.7
	wrstuden-revivesa-base-3:1.8
	wrstuden-revivesa-base-2:1.8
	wrstuden-fixsa-newbase:1.7
	nick-csl-alignment-base5:1.7
	haad-dm:1.8.0.6
	haad-dm-base:1.8
	wrstuden-revivesa-base-1:1.8
	simonb-wapbl-nbase:1.8
	yamt-pf42-base4:1.8
	simonb-wapbl:1.8.0.4
	simonb-wapbl-base:1.8
	yamt-pf42-base3:1.8
	hpcarm-cleanup-nbase:1.8
	yamt-pf42-baseX:1.7
	yamt-pf42-base2:1.8
	yamt-nfs-mp-base2:1.8
	wrstuden-revivesa:1.8.0.2
	wrstuden-revivesa-base:1.8
	yamt-nfs-mp:1.7.0.72
	yamt-nfs-mp-base:1.7
	yamt-pf42:1.7.0.70
	yamt-pf42-base:1.7
	ad-socklock-base1:1.7
	yamt-lazymbuf-base15:1.7
	yamt-lazymbuf-base14:1.7
	keiichi-mipv6-nbase:1.7
	mjf-devfs2:1.7.0.68
	mjf-devfs2-base:1.8
	nick-net80211-sync:1.7.0.66
	nick-net80211-sync-base:1.7
	keiichi-mipv6:1.7.0.64
	keiichi-mipv6-base:1.7
	bouyer-xeni386-merge1:1.7
	matt-armv6-prevmlocking:1.7
	wrstuden-fixsa-base-1:1.7
	vmlocking2-base3:1.7
	netbsd-4-0:1.7.0.62
	netbsd-4-0-RELEASE:1.7
	bouyer-xeni386-nbase:1.7
	yamt-kmem-base3:1.7
	cube-autoconf:1.7.0.60
	cube-autoconf-base:1.7
	yamt-kmem-base2:1.7
	bouyer-xeni386:1.7.0.58
	bouyer-xeni386-base:1.7
	yamt-kmem:1.7.0.56
	yamt-kmem-base:1.7
	vmlocking2-base2:1.7
	reinoud-bufcleanup-nbase:1.7
	vmlocking2:1.7.0.54
	vmlocking2-base1:1.7
	netbsd-4-0-RC5:1.7
	matt-nb4-arm:1.7.0.52
	matt-nb4-arm-base:1.7
	matt-armv6-nbase:1.7
	jmcneill-base:1.7
	netbsd-4-0-RC4:1.7
	mjf-devfs:1.7.0.50
	mjf-devfs-base:1.7
	bouyer-xenamd64-base2:1.7
	vmlocking-nbase:1.7
	yamt-x86pmap-base4:1.7
	bouyer-xenamd64:1.7.0.48
	bouyer-xenamd64-base:1.7
	netbsd-4-0-RC3:1.7
	yamt-x86pmap-base3:1.7
	yamt-x86pmap-base2:1.7
	netbsd-4-0-RC2:1.7
	yamt-x86pmap:1.7.0.46
	yamt-x86pmap-base:1.7
	netbsd-4-0-RC1:1.7
	matt-armv6:1.7.0.44
	matt-armv6-base:1.7
	jmcneill-pm:1.7.0.42
	jmcneill-pm-base:1.7
	hpcarm-cleanup:1.7.0.40
	hpcarm-cleanup-base:1.7
	nick-csl-alignment:1.7.0.38
	nick-csl-alignment-base:1.7
	matt-mips64:1.7.0.36
	matt-mips64-base:1.7
	netbsd-3-1-1-RELEASE:1.5
	netbsd-3-0-3-RELEASE:1.5
	yamt-idlelwp-base8:1.7
	wrstuden-fixsa:1.7.0.34
	wrstuden-fixsa-base:1.7
	ppcoea-renovation:1.7.0.32
	ppcoea-renovation-base:1.7
	thorpej-atomic:1.7.0.30
	thorpej-atomic-base:1.7
	reinoud-bufcleanup:1.7.0.28
	reinoud-bufcleanup-base:1.7
	mjf-ufs-trans:1.7.0.26
	mjf-ufs-trans-base:1.7
	vmlocking:1.7.0.24
	vmlocking-base:1.7
	ad-audiomp:1.7.0.22
	ad-audiomp-base:1.7
	yamt-idlelwp:1.7.0.20
	post-newlock2-merge:1.7
	newlock2-nbase:1.7
	yamt-splraiseipl-base5:1.7
	yamt-splraiseipl-base4:1.7
	yamt-splraiseipl-base3:1.7
	abandoned-netbsd-4-base:1.7
	abandoned-netbsd-4:1.7.0.12
	netbsd-3-1:1.5.0.22
	netbsd-3-1-RELEASE:1.5
	netbsd-3-0-2-RELEASE:1.5
	yamt-splraiseipl-base2:1.7
	netbsd-3-1-RC4:1.5
	yamt-splraiseipl:1.7.0.16
	yamt-splraiseipl-base:1.7
	netbsd-3-1-RC3:1.5
	yamt-pdpolicy-base9:1.7
	newlock2:1.7.0.14
	newlock2-base:1.7
	yamt-pdpolicy-base8:1.7
	netbsd-3-1-RC2:1.5
	netbsd-3-1-RC1:1.5
	yamt-pdpolicy-base7:1.7
	netbsd-4:1.7.0.18
	netbsd-4-base:1.7
	yamt-pdpolicy-base6:1.7
	chap-midi-nbase:1.7
	netbsd-3-0-1-RELEASE:1.5
	gdamore-uart:1.7.0.10
	gdamore-uart-base:1.7
	simonb-timcounters-final:1.6.6.1
	yamt-pdpolicy-base5:1.7
	chap-midi:1.7.0.8
	chap-midi-base:1.7
	yamt-pdpolicy-base4:1.7
	yamt-pdpolicy-base3:1.7
	peter-altq-base:1.7
	peter-altq:1.7.0.6
	yamt-pdpolicy-base2:1.7
	elad-kernelauth-base:1.7
	elad-kernelauth:1.7.0.4
	yamt-pdpolicy:1.7.0.2
	yamt-pdpolicy-base:1.7
	yamt-uio_vmspace-base5:1.6
	simonb-timecounters:1.6.0.6
	simonb-timecounters-base:1.7
	rpaulo-netinet-merge-pcb:1.6.0.4
	rpaulo-netinet-merge-pcb-base:1.7
	yamt-uio_vmspace:1.6.0.2
	netbsd-3-0:1.5.0.20
	netbsd-3-0-RELEASE:1.5
	netbsd-3-0-RC6:1.5
	yamt-readahead-base3:1.5
	netbsd-3-0-RC5:1.5
	netbsd-3-0-RC4:1.5
	netbsd-3-0-RC3:1.5
	yamt-readahead-base2:1.5
	netbsd-3-0-RC2:1.5
	yamt-readahead-pervnode:1.5
	yamt-readahead-perfile:1.5
	yamt-readahead:1.5.0.18
	yamt-readahead-base:1.5
	netbsd-3-0-RC1:1.5
	yamt-vop-base3:1.5
	netbsd-2-0-3-RELEASE:1.3
	netbsd-2-1:1.3.0.6
	yamt-vop-base2:1.5
	thorpej-vnode-attr:1.5.0.16
	thorpej-vnode-attr-base:1.5
	netbsd-2-1-RELEASE:1.3
	yamt-vop:1.5.0.14
	yamt-vop-base:1.5
	netbsd-2-1-RC6:1.3
	netbsd-2-1-RC5:1.3
	netbsd-2-1-RC4:1.3
	netbsd-2-1-RC3:1.3
	netbsd-2-1-RC2:1.3
	netbsd-2-1-RC1:1.3
	yamt-lazymbuf:1.5.0.12
	yamt-km-base4:1.5
	netbsd-2-0-2-RELEASE:1.3
	yamt-km-base3:1.5
	netbsd-3:1.5.0.10
	netbsd-3-base:1.5
	yamt-km-base2:1.5
	yamt-km:1.5.0.6
	yamt-km-base:1.5
	kent-audio2:1.5.0.4
	kent-audio2-base:1.5
	netbsd-2-0-1-RELEASE:1.3
	kent-audio1-beforemerge:1.5
	netbsd-2:1.3.0.4
	netbsd-2-base:1.3
	kent-audio1:1.5.0.2
	kent-audio1-base:1.5
	netbsd-2-0-RELEASE:1.3
	netbsd-2-0-RC5:1.3
	netbsd-2-0-RC4:1.3
	netbsd-2-0-RC3:1.3
	netbsd-2-0-RC2:1.3
	netbsd-2-0-RC1:1.3
	netbsd-2-0:1.3.0.2
	netbsd-2-0-base:1.3
	netbsd-1-6-PATCH002-RELEASE:1.2
	netbsd-1-6-PATCH002:1.2
	netbsd-1-6-PATCH002-RC4:1.2
	netbsd-1-6-PATCH002-RC3:1.2
	netbsd-1-6-PATCH002-RC2:1.2
	netbsd-1-6-PATCH002-RC1:1.2
	ktrace-lwp:1.2.0.24
	ktrace-lwp-base:1.5
	netbsd-1-6-PATCH001:1.2
	netbsd-1-6-PATCH001-RELEASE:1.2
	netbsd-1-6-PATCH001-RC3:1.2
	netbsd-1-6-PATCH001-RC2:1.2
	netbsd-1-6-PATCH001-RC1:1.2
	nathanw_sa_end:1.2
	nathanw_sa_before_merge:1.2
	fvdl_fs64_base:1.2
	gmcgarry_ctxsw:1.2.0.22
	gmcgarry_ctxsw_base:1.2
	gmcgarry_ucred:1.2.0.20
	gmcgarry_ucred_base:1.2
	nathanw_sa_base:1.2
	kqueue-aftermerge:1.2
	kqueue-beforemerge:1.2
	netbsd-1-6-RELEASE:1.2
	netbsd-1-6-RC3:1.2
	netbsd-1-6-RC2:1.2
	netbsd-1-6-RC1:1.2
	netbsd-1-6:1.2.0.18
	netbsd-1-6-base:1.2
	gehenna-devsw:1.2.0.16
	gehenna-devsw-base:1.2
	eeh-devprop:1.2.0.14
	eeh-devprop-base:1.2
	newlock:1.2.0.12
	newlock-base:1.2
	ifpoll-base:1.2
	nathanw_sa:1.2.0.8
	thorpej-mips-cache:1.2.0.6
	thorpej-mips-cache-base:1.2
	thorpej-devvp-base3:1.2
	thorpej-devvp-base2:1.2
	post-chs-ubcperf:1.2
	pre-chs-ubcperf:1.2
	thorpej-devvp:1.2.0.4
	thorpej-devvp-base:1.2
	kqueue:1.2.0.2
	kqueue-base:1.2
	thorpej_scsipi_beforemerge:1.1
	thorpej_scsipi_base:1.1
	thorpej_scsipi:1.1.0.2
	thorpej_scsipi_nbase:1.1;
locks; strict;
comment	@// @;


1.9
date	2010.04.06.16.20.27;	author nonaka;	state Exp;
branches;
next	1.8;

1.8
date	2008.05.03.23.52.19;	author martin;	state Exp;
branches
	1.8.20.1
	1.8.22.1;
next	1.7;

1.7
date	2006.03.05.04.05.39;	author uwe;	state Exp;
branches
	1.7.2.1
	1.7.68.1
	1.7.70.1
	1.7.72.1;
next	1.6;

1.6
date	2005.12.11.12.17.28;	author christos;	state Exp;
branches
	1.6.4.1
	1.6.6.1;
next	1.5;

1.5
date	2004.08.06.18.33.09;	author uch;	state Exp;
branches
	1.5.12.1;
next	1.4;

1.4
date	2004.08.06.17.21.28;	author uch;	state Exp;
branches;
next	1.3;

1.3
date	2004.02.27.02.00.32;	author uwe;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.08.18.51.22;	author uch;	state Exp;
branches
	1.2.8.1
	1.2.24.1;
next	1.1;

1.1
date	2001.02.09.18.34.39;	author uch;	state Exp;
branches
	1.1.2.1
	1.1.4.1;
next	;

1.8.20.1
date	2010.04.30.14.39.24;	author uebayasi;	state Exp;
branches;
next	;

1.8.22.1
date	2010.05.30.05.16.50;	author rmind;	state Exp;
branches;
next	;

1.7.2.1
date	2006.03.05.04.05.39;	author uwe;	state dead;
branches;
next	1.7.2.2;

1.7.2.2
date	2006.03.05.04.05.40;	author uwe;	state Exp;
branches;
next	;

1.7.68.1
date	2008.06.02.13.22.08;	author mjf;	state Exp;
branches;
next	;

1.7.70.1
date	2008.05.18.12.31.59;	author yamt;	state Exp;
branches;
next	;

1.7.72.1
date	2008.05.16.02.22.24;	author yamt;	state Exp;
branches;
next	1.7.72.2;

1.7.72.2
date	2010.08.11.22.52.03;	author yamt;	state Exp;
branches;
next	;

1.6.4.1
date	2006.09.09.02.39.27;	author rpaulo;	state Exp;
branches;
next	;

1.6.6.1
date	2006.04.22.11.37.28;	author simonb;	state Exp;
branches;
next	;

1.5.12.1
date	2006.06.21.14.51.38;	author yamt;	state Exp;
branches;
next	;

1.2.8.1
date	2001.05.08.18.51.22;	author uch;	state dead;
branches;
next	1.2.8.2;

1.2.8.2
date	2001.05.08.18.51.23;	author uch;	state Exp;
branches;
next	;

1.2.24.1
date	2004.08.03.10.34.58;	author skrll;	state Exp;
branches;
next	1.2.24.2;

1.2.24.2
date	2004.08.12.11.41.05;	author skrll;	state Exp;
branches;
next	1.2.24.3;

1.2.24.3
date	2004.09.18.14.34.39;	author skrll;	state Exp;
branches;
next	1.2.24.4;

1.2.24.4
date	2004.09.21.13.15.48;	author skrll;	state Exp;
branches;
next	1.2.24.5;

1.2.24.5
date	2005.02.24.08.11.15;	author skrll;	state Exp;
branches;
next	;

1.1.2.1
date	2001.02.09.18.34.39;	author bouyer;	state dead;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.02.11.19.09.51;	author bouyer;	state Exp;
branches;
next	;

1.1.4.1
date	2001.06.21.19.22.43;	author nathanw;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Added support PXA270.
@
text
@/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.8 2008/05/03 23:52:19 martin Exp $	*/

/*-
 * Copyright(c) 1996, 2001, 2004 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Matthias Drochner. and UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <console.h>
#include <file.h>
#include <limits.h>

__BEGIN_DECLS
#include <string.h>
#include <zlib.h>
uLong crc32(uLong crc, const Bytef *buf, uInt len);
__END_DECLS

static struct z_stream_s __stream;	// XXX for namespace.

void
FileManager::_reset()
{
	_stream = &__stream;
	memset(_stream, 0, sizeof(struct z_stream_s));
	_z_err = 0;
	_z_eof = 0;
	_crc = 0;
	_compressed = 0;
}

FileManager::~FileManager()
{
	delete _file;
}

BOOL
FileManager::setRoot(TCHAR *drive)
{
	return _file->setRoot(drive);
}

BOOL
FileManager::open(const TCHAR *name, uint32_t flags)
{
	if (!_file->open(name, flags))
		return FALSE;

	_reset();

	if (inflateInit2(_stream, -15) != Z_OK)
		goto errout;
	_stream->next_in = _inbuf;

	_check_header(); // skip the .gz header

	return TRUE;
 errout:
	_file->close();
	return FALSE;
}

size_t
FileManager::read(void *buf, size_t len, off_t ofs)
{
	if (ofs != -1)
		seek(ofs);

	return _read(buf, len);
}

size_t
FileManager::_read(void *buf, size_t len)
{
	// starting point for crc computation
	uint8_t *start = reinterpret_cast<uint8_t *>(buf);

	if (_z_err == Z_DATA_ERROR || _z_err == Z_ERRNO) {
		return -1;
	}
	if (_z_err == Z_STREAM_END) {
		return 0;  // EOF
	}
	_stream->next_out = reinterpret_cast<uint8_t *>(buf);
	_stream->avail_out = len;

	int got;
	while (_stream->avail_out != 0) {
		if (!_compressed) {
			// Copy first the lookahead bytes
			uint32_t n = _stream->avail_in;
			if (n > _stream->avail_out)
				n = _stream->avail_out;
			if (n > 0) {
				memcpy(_stream->next_out, _stream->next_in, n);
				_stream->next_out  += n;
				_stream->next_in   += n;
				_stream->avail_out -= n;
				_stream->avail_in  -= n;
			}
			if (_stream->avail_out > 0) {
				got = _file->read(_stream->next_out,
				    _stream->avail_out);
				if (got == -1) {
					return(got);
				}
				_stream->avail_out -= got;
			}
			return(int)(len - _stream->avail_out);
		}

		if (_stream->avail_in == 0 && !_z_eof) {
			got = _file->read(_inbuf, Z_BUFSIZE);
			if (got <= 0)
				_z_eof = 1;

			_stream->avail_in = got;
			_stream->next_in = _inbuf;
		}

		_z_err = inflate(_stream, Z_NO_FLUSH);

		if (_z_err == Z_STREAM_END) {
			/* Check CRC and original size */
			_crc = crc32(_crc, start,(unsigned int)
			    (_stream->next_out - start));
			start = _stream->next_out;

			if (_get_long() != _crc ||
			    _get_long() != _stream->total_out) {
				_z_err = Z_DATA_ERROR;
			} else {
				/* Check for concatenated .gz files: */
				_check_header();
				if (_z_err == Z_OK) {
					inflateReset(_stream);
					_crc = crc32(0L, Z_NULL, 0);
				}
			}
		}
		if (_z_err != Z_OK || _z_eof)
			break;
	}

	_crc = crc32(_crc, start,(unsigned int)(_stream->next_out - start));

	return(int)(len - _stream->avail_out);
}

size_t
FileManager::write(const void *buf, size_t bytes, off_t ofs)
{
	return _file->write(buf, bytes, ofs);
}

size_t
FileManager::size()
{
	return _file->size();
}

BOOL
FileManager::close()
{
	inflateEnd(_stream);

	return _file->close();
}

size_t
FileManager::_skip_compressed(off_t toskip)
{
#define	DUMMYBUFSIZE 256
	char dummybuf[DUMMYBUFSIZE];

	size_t skipped = 0;

	while (toskip > 0) {
		size_t toread = toskip;
		if (toread > DUMMYBUFSIZE)
			toread = DUMMYBUFSIZE;

		size_t nread = _read(dummybuf, toread);
		if ((int)nread < 0)
			return nread;

		toskip  -= nread;
		skipped += nread;

		if (nread != toread)
			break;
	}

	return skipped;
}

size_t
FileManager::realsize()
{
	if (!_compressed)
		return size();

	off_t pos = _stream->total_out;
	size_t sz = _skip_compressed(INT_MAX);
	seek(pos);

	return sz;
}

BOOL
FileManager::seek(off_t offset)
{

	if (!_compressed) {
		_file->seek(offset);
		_stream->avail_in = 0;

		return TRUE;
	}
	/* if seek backwards, simply start from the beginning */
	if (offset < _stream->total_out) {
		_file->seek(0);

		inflateEnd(_stream);
		_reset(); /* this resets total_out to 0! */
		inflateInit2(_stream, -15);
		_stream->next_in = _inbuf;

		_check_header(); /* skip the .gz header */
	}

	/* to seek forwards, throw away data */
	if (offset > _stream->total_out) {
		off_t toskip = offset - _stream->total_out;
		size_t skipped = _skip_compressed(toskip);

		if (skipped != toskip)
			return FALSE;
	}

	return TRUE;
}

//
// GZIP util.
//
int
FileManager::_get_byte()
{

	if (_z_eof)
		return(EOF);

	if (_stream->avail_in == 0) {
		int got;

		got = _file->read(_inbuf, Z_BUFSIZE);
		if (got <= 0) {
			_z_eof = 1;
			return EOF;
		}
		_stream->avail_in = got;
		_stream->next_in = _inbuf;
	}
	_stream->avail_in--;
	return *(_stream->next_in)++;
}

uint32_t
FileManager::_get_long()
{
	uint32_t x = static_cast<uint32_t>(_get_byte());
	int c;

	x +=(static_cast<uint32_t>(_get_byte())) << 8;
	x +=(static_cast<uint32_t>(_get_byte())) << 16;
	c = _get_byte();
	if (c == EOF)
		_z_err = Z_DATA_ERROR;
	x +=(static_cast<uint32_t>(c)) << 24;

	return x;
}

void
FileManager::_check_header()
{
	int method; /* method byte */
	int flags;  /* flags byte */
	unsigned int len;
	int c;

	/* Check the gzip magic header */
	for (len = 0; len < 2; len++) {
		c = _get_byte();
		if (c == _gz_magic[len])
			continue;
		if ((c == EOF) &&(len == 0))  {
			/*
			 * We must not change _compressed if we are at EOF;
			 * we may have come to the end of a gzipped file and be
			 * check to see if another gzipped file is concatenated
			 * to this one. If one isn't, we still need to be able
			 * to lseek on this file as a compressed file.
			 */
			return;
		}
		_compressed = 0;
		if (c != EOF) {
			_stream->avail_in++;
			_stream->next_in--;
		}
		_z_err = _stream->avail_in != 0 ? Z_OK : Z_STREAM_END;
		return;
	}
	_compressed = 1;
	method = _get_byte();
	flags = _get_byte();
	if (method != Z_DEFLATED ||(flags & RESERVED) != 0) {
		_z_err = Z_DATA_ERROR;
		return;
	}

	/* Discard time, xflags and OS code: */
	for (len = 0; len < 6; len++)
		(void)_get_byte();

	if ((flags & EXTRA_FIELD) != 0) {
		/* skip the extra field */
		len  = (unsigned int)_get_byte();
		len +=((unsigned int)_get_byte()) << 8;
		/* len is garbage if EOF but the loop below will quit anyway */
		while (len-- != 0 && _get_byte() != EOF) /*void*/;
	}
	if ((flags & ORIG_NAME) != 0) {
		/* skip the original file name */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & COMMENT) != 0) {
		/* skip the .gz file comment */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
		for (len = 0; len < 2; len++)
			(void)_get_byte();
	}
	_z_err = _z_eof ? Z_DATA_ERROR : Z_OK;
}
@


1.8
log
@Move to standard 2 clause TNF license
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/
d38 2
a39 1
#include <zlib.h>
@


1.8.22.1
log
@sync with head
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.8 2008/05/03 23:52:19 martin Exp $	*/
d38 1
a38 2
#include <zlib.h>
uLong crc32(uLong crc, const Bytef *buf, uInt len);
@


1.8.20.1
log
@Sync with HEAD.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD$	*/
d38 1
a38 2
#include <zlib.h>
uLong crc32(uLong crc, const Bytef *buf, uInt len);
@


1.7
log
@s/u_intN_t/uintN_t/
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.6 2005/12/11 12:17:28 christos Exp $	*/
a17 7
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
d24 1
a24 1
 * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d27 1
a27 1
 * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
@


1.7.2.1
log
@file file_manager.cpp was added on branch yamt-pdpolicy on 2006-03-05 04:05:40 +0000
@
text
@d1 377
@


1.7.2.2
log
@s/u_intN_t/uintN_t/
@
text
@a0 377
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/

/*-
 * Copyright(c) 1996, 2001, 2004 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Matthias Drochner. and UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <console.h>
#include <file.h>
#include <limits.h>

__BEGIN_DECLS
#include <string.h>
#include <zlib.h>
__END_DECLS

static struct z_stream_s __stream;	// XXX for namespace.

void
FileManager::_reset()
{
	_stream = &__stream;
	memset(_stream, 0, sizeof(struct z_stream_s));
	_z_err = 0;
	_z_eof = 0;
	_crc = 0;
	_compressed = 0;
}

FileManager::~FileManager()
{
	delete _file;
}

BOOL
FileManager::setRoot(TCHAR *drive)
{
	return _file->setRoot(drive);
}

BOOL
FileManager::open(const TCHAR *name, uint32_t flags)
{
	if (!_file->open(name, flags))
		return FALSE;

	_reset();

	if (inflateInit2(_stream, -15) != Z_OK)
		goto errout;
	_stream->next_in = _inbuf;

	_check_header(); // skip the .gz header

	return TRUE;
 errout:
	_file->close();
	return FALSE;
}

size_t
FileManager::read(void *buf, size_t len, off_t ofs)
{
	if (ofs != -1)
		seek(ofs);

	return _read(buf, len);
}

size_t
FileManager::_read(void *buf, size_t len)
{
	// starting point for crc computation
	uint8_t *start = reinterpret_cast<uint8_t *>(buf);

	if (_z_err == Z_DATA_ERROR || _z_err == Z_ERRNO) {
		return -1;
	}
	if (_z_err == Z_STREAM_END) {
		return 0;  // EOF
	}
	_stream->next_out = reinterpret_cast<uint8_t *>(buf);
	_stream->avail_out = len;

	int got;
	while (_stream->avail_out != 0) {
		if (!_compressed) {
			// Copy first the lookahead bytes
			uint32_t n = _stream->avail_in;
			if (n > _stream->avail_out)
				n = _stream->avail_out;
			if (n > 0) {
				memcpy(_stream->next_out, _stream->next_in, n);
				_stream->next_out  += n;
				_stream->next_in   += n;
				_stream->avail_out -= n;
				_stream->avail_in  -= n;
			}
			if (_stream->avail_out > 0) {
				got = _file->read(_stream->next_out,
				    _stream->avail_out);
				if (got == -1) {
					return(got);
				}
				_stream->avail_out -= got;
			}
			return(int)(len - _stream->avail_out);
		}

		if (_stream->avail_in == 0 && !_z_eof) {
			got = _file->read(_inbuf, Z_BUFSIZE);
			if (got <= 0)
				_z_eof = 1;

			_stream->avail_in = got;
			_stream->next_in = _inbuf;
		}

		_z_err = inflate(_stream, Z_NO_FLUSH);

		if (_z_err == Z_STREAM_END) {
			/* Check CRC and original size */
			_crc = crc32(_crc, start,(unsigned int)
			    (_stream->next_out - start));
			start = _stream->next_out;

			if (_get_long() != _crc ||
			    _get_long() != _stream->total_out) {
				_z_err = Z_DATA_ERROR;
			} else {
				/* Check for concatenated .gz files: */
				_check_header();
				if (_z_err == Z_OK) {
					inflateReset(_stream);
					_crc = crc32(0L, Z_NULL, 0);
				}
			}
		}
		if (_z_err != Z_OK || _z_eof)
			break;
	}

	_crc = crc32(_crc, start,(unsigned int)(_stream->next_out - start));

	return(int)(len - _stream->avail_out);
}

size_t
FileManager::write(const void *buf, size_t bytes, off_t ofs)
{
	return _file->write(buf, bytes, ofs);
}

size_t
FileManager::size()
{
	return _file->size();
}

BOOL
FileManager::close()
{
	inflateEnd(_stream);

	return _file->close();
}

size_t
FileManager::_skip_compressed(off_t toskip)
{
#define	DUMMYBUFSIZE 256
	char dummybuf[DUMMYBUFSIZE];

	size_t skipped = 0;

	while (toskip > 0) {
		size_t toread = toskip;
		if (toread > DUMMYBUFSIZE)
			toread = DUMMYBUFSIZE;

		size_t nread = _read(dummybuf, toread);
		if ((int)nread < 0)
			return nread;

		toskip  -= nread;
		skipped += nread;

		if (nread != toread)
			break;
	}

	return skipped;
}

size_t
FileManager::realsize()
{
	if (!_compressed)
		return size();

	off_t pos = _stream->total_out;
	size_t sz = _skip_compressed(INT_MAX);
	seek(pos);

	return sz;
}

BOOL
FileManager::seek(off_t offset)
{

	if (!_compressed) {
		_file->seek(offset);
		_stream->avail_in = 0;

		return TRUE;
	}
	/* if seek backwards, simply start from the beginning */
	if (offset < _stream->total_out) {
		_file->seek(0);

		inflateEnd(_stream);
		_reset(); /* this resets total_out to 0! */
		inflateInit2(_stream, -15);
		_stream->next_in = _inbuf;

		_check_header(); /* skip the .gz header */
	}

	/* to seek forwards, throw away data */
	if (offset > _stream->total_out) {
		off_t toskip = offset - _stream->total_out;
		size_t skipped = _skip_compressed(toskip);

		if (skipped != toskip)
			return FALSE;
	}

	return TRUE;
}

//
// GZIP util.
//
int
FileManager::_get_byte()
{

	if (_z_eof)
		return(EOF);

	if (_stream->avail_in == 0) {
		int got;

		got = _file->read(_inbuf, Z_BUFSIZE);
		if (got <= 0) {
			_z_eof = 1;
			return EOF;
		}
		_stream->avail_in = got;
		_stream->next_in = _inbuf;
	}
	_stream->avail_in--;
	return *(_stream->next_in)++;
}

uint32_t
FileManager::_get_long()
{
	uint32_t x = static_cast<uint32_t>(_get_byte());
	int c;

	x +=(static_cast<uint32_t>(_get_byte())) << 8;
	x +=(static_cast<uint32_t>(_get_byte())) << 16;
	c = _get_byte();
	if (c == EOF)
		_z_err = Z_DATA_ERROR;
	x +=(static_cast<uint32_t>(c)) << 24;

	return x;
}

void
FileManager::_check_header()
{
	int method; /* method byte */
	int flags;  /* flags byte */
	unsigned int len;
	int c;

	/* Check the gzip magic header */
	for (len = 0; len < 2; len++) {
		c = _get_byte();
		if (c == _gz_magic[len])
			continue;
		if ((c == EOF) &&(len == 0))  {
			/*
			 * We must not change _compressed if we are at EOF;
			 * we may have come to the end of a gzipped file and be
			 * check to see if another gzipped file is concatenated
			 * to this one. If one isn't, we still need to be able
			 * to lseek on this file as a compressed file.
			 */
			return;
		}
		_compressed = 0;
		if (c != EOF) {
			_stream->avail_in++;
			_stream->next_in--;
		}
		_z_err = _stream->avail_in != 0 ? Z_OK : Z_STREAM_END;
		return;
	}
	_compressed = 1;
	method = _get_byte();
	flags = _get_byte();
	if (method != Z_DEFLATED ||(flags & RESERVED) != 0) {
		_z_err = Z_DATA_ERROR;
		return;
	}

	/* Discard time, xflags and OS code: */
	for (len = 0; len < 6; len++)
		(void)_get_byte();

	if ((flags & EXTRA_FIELD) != 0) {
		/* skip the extra field */
		len  = (unsigned int)_get_byte();
		len +=((unsigned int)_get_byte()) << 8;
		/* len is garbage if EOF but the loop below will quit anyway */
		while (len-- != 0 && _get_byte() != EOF) /*void*/;
	}
	if ((flags & ORIG_NAME) != 0) {
		/* skip the original file name */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & COMMENT) != 0) {
		/* skip the .gz file comment */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
		for (len = 0; len < 2; len++)
			(void)_get_byte();
	}
	_z_err = _z_eof ? Z_DATA_ERROR : Z_OK;
}
@


1.7.68.1
log
@Sync with HEAD.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD$	*/
d18 7
d31 1
a31 1
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d34 1
a34 1
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@


1.7.70.1
log
@sync with head.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/
d18 7
d31 1
a31 1
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d34 1
a34 1
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@


1.7.72.1
log
@sync with head.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/
d18 7
d31 1
a31 1
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d34 1
a34 1
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@


1.7.72.2
log
@sync with head.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7.72.1 2008/05/16 02:22:24 yamt Exp $	*/
d38 1
a38 2
#include <zlib.h>
uLong crc32(uLong crc, const Bytef *buf, uInt len);
@


1.6
log
@merge ktrace-lwp.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2.24.5 2005/02/24 08:11:15 skrll Exp $	*/
d73 1
a73 1
FileManager::open(const TCHAR *name, u_int32_t flags)
d105 1
a105 1
	u_int8_t *start = reinterpret_cast<u_int8_t *>(buf);
d113 1
a113 1
	_stream->next_out = reinterpret_cast<u_int8_t *>(buf);
d120 1
a120 1
			u_int32_t n = _stream->avail_in;
d298 1
a298 1
u_int32_t
d301 1
a301 1
	u_int32_t x = static_cast<u_int32_t>(_get_byte());
d304 2
a305 2
	x +=(static_cast<u_int32_t>(_get_byte())) << 8;
	x +=(static_cast<u_int32_t>(_get_byte())) << 16;
d309 1
a309 1
	x +=(static_cast<u_int32_t>(c)) << 24;
@


1.6.4.1
log
@sync with head
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/
d73 1
a73 1
FileManager::open(const TCHAR *name, uint32_t flags)
d105 1
a105 1
	uint8_t *start = reinterpret_cast<uint8_t *>(buf);
d113 1
a113 1
	_stream->next_out = reinterpret_cast<uint8_t *>(buf);
d120 1
a120 1
			uint32_t n = _stream->avail_in;
d298 1
a298 1
uint32_t
d301 1
a301 1
	uint32_t x = static_cast<uint32_t>(_get_byte());
d304 2
a305 2
	x +=(static_cast<uint32_t>(_get_byte())) << 8;
	x +=(static_cast<uint32_t>(_get_byte())) << 16;
d309 1
a309 1
	x +=(static_cast<uint32_t>(c)) << 24;
@


1.6.6.1
log
@Sync with head.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.7 2006/03/05 04:05:39 uwe Exp $	*/
d73 1
a73 1
FileManager::open(const TCHAR *name, uint32_t flags)
d105 1
a105 1
	uint8_t *start = reinterpret_cast<uint8_t *>(buf);
d113 1
a113 1
	_stream->next_out = reinterpret_cast<uint8_t *>(buf);
d120 1
a120 1
			uint32_t n = _stream->avail_in;
d298 1
a298 1
uint32_t
d301 1
a301 1
	uint32_t x = static_cast<uint32_t>(_get_byte());
d304 2
a305 2
	x +=(static_cast<uint32_t>(_get_byte())) << 8;
	x +=(static_cast<uint32_t>(_get_byte())) << 16;
d309 1
a309 1
	x +=(static_cast<uint32_t>(c)) << 24;
@


1.5
log
@clean up whitespace.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.4 2004/08/06 17:21:28 uch Exp $	*/
@


1.5.12.1
log
@sync with head.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.5 2004/08/06 18:33:09 uch Exp $	*/
d73 1
a73 1
FileManager::open(const TCHAR *name, uint32_t flags)
d105 1
a105 1
	uint8_t *start = reinterpret_cast<uint8_t *>(buf);
d113 1
a113 1
	_stream->next_out = reinterpret_cast<uint8_t *>(buf);
d120 1
a120 1
			uint32_t n = _stream->avail_in;
d298 1
a298 1
uint32_t
d301 1
a301 1
	uint32_t x = static_cast<uint32_t>(_get_byte());
d304 2
a305 2
	x +=(static_cast<uint32_t>(_get_byte())) << 8;
	x +=(static_cast<uint32_t>(_get_byte())) << 16;
d309 1
a309 1
	x +=(static_cast<uint32_t>(c)) << 24;
@


1.4
log
@make hpcboot.exe compile on VC5 (H/PC Ver.1.01 for MIPS, H/PC Ver.2.00 for SH).
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.3 2004/02/27 02:00:32 uwe Exp $	*/
d104 2
a105 2
	// starting point for crc computation 
	u_int8_t *start = reinterpret_cast<u_int8_t *>(buf); 
d151 1
a151 1
		
a159 1
				
d202 1
a202 1
#define DUMMYBUFSIZE 256
d242 1
a248 1
	
d279 1
@


1.3
log
@Implement realsize() method.  For gzipped files it reports the
uncompressed file size.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2 2001/05/08 18:51:22 uch Exp $	*/
d4 1
a4 1
 * Copyright(c) 1996, 2001 The NetBSD Foundation, Inc.
d41 1
d79 1
a79 1
	
@


1.2
log
@KNF.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.1 2001/02/09 18:34:39 uch Exp $	*/
d199 40
d264 1
d266 2
a267 10
		while (toskip > 0) {
#define DUMMYBUFSIZE 256
			char dummybuf[DUMMYBUFSIZE];
			off_t len = toskip;
			if (len > DUMMYBUFSIZE)
				len = DUMMYBUFSIZE;
			if (_read(dummybuf, len) != len)
				return FALSE;
			toskip -= len;
		}
@


1.2.8.1
log
@file file_manager.cpp was added on branch nathanw_sa on 2001-05-08 18:51:23 +0000
@
text
@d1 343
@


1.2.8.2
log
@KNF.
@
text
@a0 343
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2 2001/05/08 18:51:22 uch Exp $	*/

/*-
 * Copyright(c) 1996, 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Matthias Drochner. and UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <console.h>
#include <file.h>

__BEGIN_DECLS
#include <string.h>
#include <zlib.h>
__END_DECLS

static struct z_stream_s __stream;	// XXX for namespace.

void
FileManager::_reset()
{
	_stream = &__stream;
	memset(_stream, 0, sizeof(struct z_stream_s));
	_z_err = 0;
	_z_eof = 0;
	_crc = 0;
	_compressed = 0;
}

FileManager::~FileManager()
{
	delete _file;
}

BOOL
FileManager::setRoot(TCHAR *drive)
{
	return _file->setRoot(drive);
}

BOOL
FileManager::open(const TCHAR *name, u_int32_t flags)
{
	if (!_file->open(name, flags))
		return FALSE;

	_reset();
	
	if (inflateInit2(_stream, -15) != Z_OK)
		goto errout;
	_stream->next_in = _inbuf;

	_check_header(); // skip the .gz header

	return TRUE;
 errout:
	_file->close();
	return FALSE;
}

size_t
FileManager::read(void *buf, size_t len, off_t ofs)
{
	if (ofs != -1)
		seek(ofs);

	return _read(buf, len);
}

size_t
FileManager::_read(void *buf, size_t len)
{
	// starting point for crc computation 
	u_int8_t *start = reinterpret_cast<u_int8_t *>(buf); 

	if (_z_err == Z_DATA_ERROR || _z_err == Z_ERRNO) {
		return -1;
	}
	if (_z_err == Z_STREAM_END) {
		return 0;  // EOF
	}
	_stream->next_out = reinterpret_cast<u_int8_t *>(buf);
	_stream->avail_out = len;

	int got;
	while (_stream->avail_out != 0) {
		if (!_compressed) {
			// Copy first the lookahead bytes
			u_int32_t n = _stream->avail_in;
			if (n > _stream->avail_out)
				n = _stream->avail_out;
			if (n > 0) {
				memcpy(_stream->next_out, _stream->next_in, n);
				_stream->next_out  += n;
				_stream->next_in   += n;
				_stream->avail_out -= n;
				_stream->avail_in  -= n;
			}
			if (_stream->avail_out > 0) {
				got = _file->read(_stream->next_out,
				    _stream->avail_out);
				if (got == -1) {
					return(got);
				}
				_stream->avail_out -= got;
			}
			return(int)(len - _stream->avail_out);
		}

		if (_stream->avail_in == 0 && !_z_eof) {
			got = _file->read(_inbuf, Z_BUFSIZE);
			if (got <= 0)
				_z_eof = 1;

			_stream->avail_in = got;
			_stream->next_in = _inbuf;
		}

		_z_err = inflate(_stream, Z_NO_FLUSH);
		
		if (_z_err == Z_STREAM_END) {
			/* Check CRC and original size */
			_crc = crc32(_crc, start,(unsigned int)
			    (_stream->next_out - start));
			start = _stream->next_out;

			if (_get_long() != _crc ||
			    _get_long() != _stream->total_out) {
				
				_z_err = Z_DATA_ERROR;
			} else {
				/* Check for concatenated .gz files: */
				_check_header();
				if (_z_err == Z_OK) {
					inflateReset(_stream);
					_crc = crc32(0L, Z_NULL, 0);
				}
			}
		}
		if (_z_err != Z_OK || _z_eof)
			break;
	}

	_crc = crc32(_crc, start,(unsigned int)(_stream->next_out - start));

	return(int)(len - _stream->avail_out);
}

size_t
FileManager::write(const void *buf, size_t bytes, off_t ofs)
{
	return _file->write(buf, bytes, ofs);
}

size_t
FileManager::size()
{
	return _file->size();
}

BOOL
FileManager::close()
{
	inflateEnd(_stream);

	return _file->close();
}

BOOL
FileManager::seek(off_t offset)
{
	if (!_compressed) {
		_file->seek(offset);
		_stream->avail_in = 0;

		return TRUE;
	}
	
	/* if seek backwards, simply start from the beginning */
	if (offset < _stream->total_out) {
		_file->seek(0);

		inflateEnd(_stream);
		_reset(); /* this resets total_out to 0! */
		inflateInit2(_stream, -15);
		_stream->next_in = _inbuf;

		_check_header(); /* skip the .gz header */
	}

	/* to seek forwards, throw away data */
	if (offset > _stream->total_out) {
		off_t toskip = offset - _stream->total_out;

		while (toskip > 0) {
#define DUMMYBUFSIZE 256
			char dummybuf[DUMMYBUFSIZE];
			off_t len = toskip;
			if (len > DUMMYBUFSIZE)
				len = DUMMYBUFSIZE;
			if (_read(dummybuf, len) != len)
				return FALSE;
			toskip -= len;
		}
	}

	return TRUE;
}

//
// GZIP util.
//
int
FileManager::_get_byte()
{
	if (_z_eof)
		return(EOF);

	if (_stream->avail_in == 0) {
		int got;

		got = _file->read(_inbuf, Z_BUFSIZE);
		if (got <= 0) {
			_z_eof = 1;
			return EOF;
		}
		_stream->avail_in = got;
		_stream->next_in = _inbuf;
	}
	_stream->avail_in--;
	return *(_stream->next_in)++;
}

u_int32_t
FileManager::_get_long()
{
	u_int32_t x = static_cast<u_int32_t>(_get_byte());
	int c;

	x +=(static_cast<u_int32_t>(_get_byte())) << 8;
	x +=(static_cast<u_int32_t>(_get_byte())) << 16;
	c = _get_byte();
	if (c == EOF)
		_z_err = Z_DATA_ERROR;
	x +=(static_cast<u_int32_t>(c)) << 24;

	return x;
}

void
FileManager::_check_header()
{
	int method; /* method byte */
	int flags;  /* flags byte */
	unsigned int len;
	int c;

	/* Check the gzip magic header */
	for (len = 0; len < 2; len++) {
		c = _get_byte();
		if (c == _gz_magic[len])
			continue;
		if ((c == EOF) &&(len == 0))  {
			/*
			 * We must not change _compressed if we are at EOF;
			 * we may have come to the end of a gzipped file and be
			 * check to see if another gzipped file is concatenated
			 * to this one. If one isn't, we still need to be able
			 * to lseek on this file as a compressed file.
			 */
			return;
		}
		_compressed = 0;
		if (c != EOF) {
			_stream->avail_in++;
			_stream->next_in--;
		}
		_z_err = _stream->avail_in != 0 ? Z_OK : Z_STREAM_END;
		return;
	}
	_compressed = 1;
	method = _get_byte();
	flags = _get_byte();
	if (method != Z_DEFLATED ||(flags & RESERVED) != 0) {
		_z_err = Z_DATA_ERROR;
		return;
	}

	/* Discard time, xflags and OS code: */
	for (len = 0; len < 6; len++)
		(void)_get_byte();

	if ((flags & EXTRA_FIELD) != 0) {
		/* skip the extra field */
		len  = (unsigned int)_get_byte();
		len +=((unsigned int)_get_byte()) << 8;
		/* len is garbage if EOF but the loop below will quit anyway */
		while (len-- != 0 && _get_byte() != EOF) /*void*/;
	}
	if ((flags & ORIG_NAME) != 0) {
		/* skip the original file name */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & COMMENT) != 0) {
		/* skip the .gz file comment */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
		for (len = 0; len < 2; len++)
			(void)_get_byte();
	}
	_z_err = _z_eof ? Z_DATA_ERROR : Z_OK;
}
@


1.2.24.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.3 2004/02/27 02:00:32 uwe Exp $	*/
a198 40
size_t
FileManager::_skip_compressed(off_t toskip)
{
#define DUMMYBUFSIZE 256
	char dummybuf[DUMMYBUFSIZE];

	size_t skipped = 0;

	while (toskip > 0) {
		size_t toread = toskip;
		if (toread > DUMMYBUFSIZE)
			toread = DUMMYBUFSIZE;

		size_t nread = _read(dummybuf, toread);
		if ((int)nread < 0)
			return nread;

		toskip  -= nread;
		skipped += nread;

		if (nread != toread)
			break;
	}

	return skipped;
}

size_t
FileManager::realsize()
{
	if (!_compressed)
		return size();

	off_t pos = _stream->total_out;
	size_t sz = _skip_compressed(INT_MAX);
	seek(pos);

	return sz;
}

a223 1
		size_t skipped = _skip_compressed(toskip);
d225 10
a234 2
		if (skipped != toskip)
			return FALSE;
@


1.2.24.2
log
@Sync with HEAD.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2.24.1 2004/08/03 10:34:58 skrll Exp $	*/
a40 1
#include <limits.h>
d78 1
a78 1

d103 2
a104 2
	// starting point for crc computation
	u_int8_t *start = reinterpret_cast<u_int8_t *>(buf);
d150 1
a150 1

d159 1
d202 1
a202 1
#define	DUMMYBUFSIZE 256
a241 1

d248 1
a278 1

@


1.2.24.3
log
@Sync with HEAD.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.5 2004/08/06 18:33:09 uch Exp $	*/
d4 1
a4 1
 * Copyright(c) 1996, 2001, 2004 The NetBSD Foundation, Inc.
@


1.2.24.4
log
@Fix the sync with head I botched.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2.24.2 2004/08/12 11:41:05 skrll Exp $	*/
d4 1
a4 1
 * Copyright(c) 1996, 2001 The NetBSD Foundation, Inc.
@


1.2.24.5
log
@Fix merge botches that lost copyright updates.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.2.24.4 2004/09/21 13:15:48 skrll Exp $	*/
d4 1
a4 1
 * Copyright(c) 1996, 2001, 2004 The NetBSD Foundation, Inc.
@


1.1
log
@bootloader for SH3, SA-1100, TX39, VR41 based Windows CE(2.00 or later)
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD$	*/
d86 1
a86 1
errout:
d131 1
a131 1
						  _stream->avail_out);
d154 1
a154 1
				     (_stream->next_out - start));
@


1.1.2.1
log
@file file_manager.cpp was added on branch thorpej_scsipi on 2001-02-11 19:09:51 +0000
@
text
@d1 343
@


1.1.2.2
log
@Sync with HEAD.
@
text
@a0 343
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.1.2.1 2001/02/11 19:09:51 bouyer Exp $	*/

/*-
 * Copyright(c) 1996, 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Matthias Drochner. and UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <console.h>
#include <file.h>

__BEGIN_DECLS
#include <string.h>
#include <zlib.h>
__END_DECLS

static struct z_stream_s __stream;	// XXX for namespace.

void
FileManager::_reset()
{
	_stream = &__stream;
	memset(_stream, 0, sizeof(struct z_stream_s));
	_z_err = 0;
	_z_eof = 0;
	_crc = 0;
	_compressed = 0;
}

FileManager::~FileManager()
{
	delete _file;
}

BOOL
FileManager::setRoot(TCHAR *drive)
{
	return _file->setRoot(drive);
}

BOOL
FileManager::open(const TCHAR *name, u_int32_t flags)
{
	if (!_file->open(name, flags))
		return FALSE;

	_reset();
	
	if (inflateInit2(_stream, -15) != Z_OK)
		goto errout;
	_stream->next_in = _inbuf;

	_check_header(); // skip the .gz header

	return TRUE;
errout:
	_file->close();
	return FALSE;
}

size_t
FileManager::read(void *buf, size_t len, off_t ofs)
{
	if (ofs != -1)
		seek(ofs);

	return _read(buf, len);
}

size_t
FileManager::_read(void *buf, size_t len)
{
	// starting point for crc computation 
	u_int8_t *start = reinterpret_cast<u_int8_t *>(buf); 

	if (_z_err == Z_DATA_ERROR || _z_err == Z_ERRNO) {
		return -1;
	}
	if (_z_err == Z_STREAM_END) {
		return 0;  // EOF
	}
	_stream->next_out = reinterpret_cast<u_int8_t *>(buf);
	_stream->avail_out = len;

	int got;
	while (_stream->avail_out != 0) {
		if (!_compressed) {
			// Copy first the lookahead bytes
			u_int32_t n = _stream->avail_in;
			if (n > _stream->avail_out)
				n = _stream->avail_out;
			if (n > 0) {
				memcpy(_stream->next_out, _stream->next_in, n);
				_stream->next_out  += n;
				_stream->next_in   += n;
				_stream->avail_out -= n;
				_stream->avail_in  -= n;
			}
			if (_stream->avail_out > 0) {
				got = _file->read(_stream->next_out,
						  _stream->avail_out);
				if (got == -1) {
					return(got);
				}
				_stream->avail_out -= got;
			}
			return(int)(len - _stream->avail_out);
		}

		if (_stream->avail_in == 0 && !_z_eof) {
			got = _file->read(_inbuf, Z_BUFSIZE);
			if (got <= 0)
				_z_eof = 1;

			_stream->avail_in = got;
			_stream->next_in = _inbuf;
		}

		_z_err = inflate(_stream, Z_NO_FLUSH);
		
		if (_z_err == Z_STREAM_END) {
			/* Check CRC and original size */
			_crc = crc32(_crc, start,(unsigned int)
				     (_stream->next_out - start));
			start = _stream->next_out;

			if (_get_long() != _crc ||
			    _get_long() != _stream->total_out) {
				
				_z_err = Z_DATA_ERROR;
			} else {
				/* Check for concatenated .gz files: */
				_check_header();
				if (_z_err == Z_OK) {
					inflateReset(_stream);
					_crc = crc32(0L, Z_NULL, 0);
				}
			}
		}
		if (_z_err != Z_OK || _z_eof)
			break;
	}

	_crc = crc32(_crc, start,(unsigned int)(_stream->next_out - start));

	return(int)(len - _stream->avail_out);
}

size_t
FileManager::write(const void *buf, size_t bytes, off_t ofs)
{
	return _file->write(buf, bytes, ofs);
}

size_t
FileManager::size()
{
	return _file->size();
}

BOOL
FileManager::close()
{
	inflateEnd(_stream);

	return _file->close();
}

BOOL
FileManager::seek(off_t offset)
{
	if (!_compressed) {
		_file->seek(offset);
		_stream->avail_in = 0;

		return TRUE;
	}
	
	/* if seek backwards, simply start from the beginning */
	if (offset < _stream->total_out) {
		_file->seek(0);

		inflateEnd(_stream);
		_reset(); /* this resets total_out to 0! */
		inflateInit2(_stream, -15);
		_stream->next_in = _inbuf;

		_check_header(); /* skip the .gz header */
	}

	/* to seek forwards, throw away data */
	if (offset > _stream->total_out) {
		off_t toskip = offset - _stream->total_out;

		while (toskip > 0) {
#define DUMMYBUFSIZE 256
			char dummybuf[DUMMYBUFSIZE];
			off_t len = toskip;
			if (len > DUMMYBUFSIZE)
				len = DUMMYBUFSIZE;
			if (_read(dummybuf, len) != len)
				return FALSE;
			toskip -= len;
		}
	}

	return TRUE;
}

//
// GZIP util.
//
int
FileManager::_get_byte()
{
	if (_z_eof)
		return(EOF);

	if (_stream->avail_in == 0) {
		int got;

		got = _file->read(_inbuf, Z_BUFSIZE);
		if (got <= 0) {
			_z_eof = 1;
			return EOF;
		}
		_stream->avail_in = got;
		_stream->next_in = _inbuf;
	}
	_stream->avail_in--;
	return *(_stream->next_in)++;
}

u_int32_t
FileManager::_get_long()
{
	u_int32_t x = static_cast<u_int32_t>(_get_byte());
	int c;

	x +=(static_cast<u_int32_t>(_get_byte())) << 8;
	x +=(static_cast<u_int32_t>(_get_byte())) << 16;
	c = _get_byte();
	if (c == EOF)
		_z_err = Z_DATA_ERROR;
	x +=(static_cast<u_int32_t>(c)) << 24;

	return x;
}

void
FileManager::_check_header()
{
	int method; /* method byte */
	int flags;  /* flags byte */
	unsigned int len;
	int c;

	/* Check the gzip magic header */
	for (len = 0; len < 2; len++) {
		c = _get_byte();
		if (c == _gz_magic[len])
			continue;
		if ((c == EOF) &&(len == 0))  {
			/*
			 * We must not change _compressed if we are at EOF;
			 * we may have come to the end of a gzipped file and be
			 * check to see if another gzipped file is concatenated
			 * to this one. If one isn't, we still need to be able
			 * to lseek on this file as a compressed file.
			 */
			return;
		}
		_compressed = 0;
		if (c != EOF) {
			_stream->avail_in++;
			_stream->next_in--;
		}
		_z_err = _stream->avail_in != 0 ? Z_OK : Z_STREAM_END;
		return;
	}
	_compressed = 1;
	method = _get_byte();
	flags = _get_byte();
	if (method != Z_DEFLATED ||(flags & RESERVED) != 0) {
		_z_err = Z_DATA_ERROR;
		return;
	}

	/* Discard time, xflags and OS code: */
	for (len = 0; len < 6; len++)
		(void)_get_byte();

	if ((flags & EXTRA_FIELD) != 0) {
		/* skip the extra field */
		len  = (unsigned int)_get_byte();
		len +=((unsigned int)_get_byte()) << 8;
		/* len is garbage if EOF but the loop below will quit anyway */
		while (len-- != 0 && _get_byte() != EOF) /*void*/;
	}
	if ((flags & ORIG_NAME) != 0) {
		/* skip the original file name */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & COMMENT) != 0) {
		/* skip the .gz file comment */
		while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
	}
	if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
		for (len = 0; len < 2; len++)
			(void)_get_byte();
	}
	_z_err = _z_eof ? Z_DATA_ERROR : Z_OK;
}
@


1.1.4.1
log
@Catch up to -current.
@
text
@d1 1
a1 1
/* -*-C++-*-	$NetBSD: file_manager.cpp,v 1.1 2001/02/09 18:34:39 uch Exp $	*/
d86 1
a86 1
 errout:
d131 1
a131 1
				    _stream->avail_out);
d154 1
a154 1
			    (_stream->next_out - start));
@
